summaryrefslogtreecommitdiff
path: root/functions/stagefile.sh
blob: a570ea2618a892f8d6d2d620a5e9808c750ca82e (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
59
#!/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 ()
{
	FILE="${1}"
	NAME="`basename ${1}`"

	# Checking stage file
	if [ -f "${FILE}" ]
	then
		if [ "${LH_FORCE}" != "enabled" ]
		then
			# Skipping execution
			Echo_warning "skipping ${NAME}"
			exit 0
		else
			# Forcing execution
			Echo_message "forcing ${NAME}"
			rm -f "${FILE}"
		fi
	fi
}

Create_stagefile ()
{
	FILE="${1}"
	DIRECTORY="`dirname ${1}`"

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

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

Require_stagefile ()
{
	FILE="${1}"
	NAME="`basename ${1}`"

	# Checking stage file
	if [ ! -f "${FILE}" ]
	then
		Echo_error "${NAME} missing"
		exit 1
	fi
}