summaryrefslogtreecommitdiff
path: root/docs/example_script
blob: d7f407f7c716cebd4f0626435921614a9365aff0 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh

#
# This script is run inside of the initramfs environment during the
# system boot process.  It is installed there by 'mkinitramfs'.  The
# package that owns it may opt to install it in either an appropriate
# location under "/usr/share/initramfs-tools/scripts/", or a similar
# location under "/etc/mkinitramfs/scripts/", depending upon whether
# it should be considered to be a user modifiable conffile or not.
#
# TODO: How do we deal with the case where the package that installed
#	this has been removed but not purged, if we always arbitrarily
#	copy all of these scripts into the initramfs?
#
#  * The available toolset is limited inside this environment...
#
#	TODO: document that toolset in the man page.
#
#  * /dev, /proc, and /sys are already mounted.  / is a ?? ro/rw
#	filesystem... etc. more documentation.
#
#  * It is expected that /proc and /sys will be umounted before
#	changing over to the real root file system, so you must not keep
#	any files open on them beyond these scripts.
#
#  * You may like to strip these documentation comments from this
#	example if you take it for a template, to save a little space in
#	the initramfs, since nobody will ever read it from inside of
#	there anyhow.
#

#
# The environment contains at least the following variables:
#
# TODO: Decide what environment variables are meaningful and defined
#	in this context, then document them as part of the interface.
#
# Because this script will be run as a full separate process, rather
# than sourced inside the context of the driver script, if it needs to
# pass information to another script that may run after it, it must do
# so by writing data to a file location known to both scripts.  Simply
# setting an environment variable will not work.
#

#
# List the soft prerequisites here.  This is a space separated list of
# names, of scripts that are in the same directory as this one, that
# must be run before this one can be.
#
PREREQ=""

prereqs()
{
	echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
esac

# Do the work here.

echo "Got here!"

# Handle an error:

if [ -n "$an_error_occured" ];
then
	#
	# TODO: Do we need 'warn()', 'error()', and/or 'fatal()' for this?
	# I think we ultimately do, and that they need to be in their own
	# well-documented location so that an overlay can override them.
	# Think 'usplash' progress updates.
	#
	echo "An error occured in $0: $an_error_occured" >&2
	exit 1
	#
	# TODO: Decide if different error codes are meaningful, what they
	#	mean, and what the semantics of them are wrt 'init' pass
	#	or panic.  Consider naming the error values with mnemonic
	#	symbols rather than magic numbers.
	#
fi

exit 0