summaryrefslogtreecommitdiff
path: root/functions/stagefile.sh
blob: d9d65033340087d9f1f53dc0b45ad102087b6d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

# stagefile.sh - handle stage files
# Copyright (C) 2006-2007 Daniel Baumann <daniel@debian.org>
#
# live-helper comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see COPYING for details.

set -e

Check_stagefile ()
{
	STAGEFILE="${1}"
	STAGENAME="`basename ${1}`"

	# Checking stage file
	if [ -f "${STAGEFILE}" ]
	then
		if [ "${FORCE}" = "true" ]
		then
			# Forcing execution
			rm -f "${STAGEFILE}"
		else
			# Skipping execution
			echo "W: skipping ${STAGENAME}"
			exit 0
		fi
	fi
}

Create_stagefile ()
{
	STAGEFILE="${1}"
	STAGEDIRECTORY="`dirname ${1}`"

	# Creating stage directory
	if [ ! -d "${STAGEDIRECTORY}" ]
	then
		mkdir -p "${STAGEDIRECTORY}"
	fi

	# Creating stage file
	touch "${STAGEFILE}"
}

Require_stagefile ()
{
	STAGEFILE="${1}"
	STAGENAME="`basename ${1}`"

	# Checking stage file
	if [ ! -f "${STAGEFILE}" ]
	then
		echo "E: ${STAGENAME} missing"
		exit 1
	fi
}