blob: 45b6b1aaa48c0aa63cb4cca7ef9d4da755cb2451 (
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
#!/bin/sh
# mkinitcpio - modular tool for building an init ramfs cpio image
#
# IMPORTANT: We need to keep a common base syntax here
# because some of these hooks/scripts need to run under
# the klibc shell or even busybox's ash - therefore, the
# following constraints should be enforced:
# variables should be quoted and bracketed "${SOMEVAR}"
# inline execution should be done with $() instead of backticks
# use "x${var}" = "x" to test for nulls/empty strings
# incase of embedded spaces, quote all path names and string comarpisons
#
# Settings
BASEDIR=""
FILELIST="/tmp/.tmpfilelist"
KERNELVERSION="$(uname -r)"
FUNCTIONS="functions" #/lib/initramfs/functions
CONFIG="mkinitcpio.conf"
HOOKDIR="hooks"
INSTDIR="install"
MODULE_FILE=""
SAVELIST=""
GENIMG=""
APPEND=""
QUIET="y"
SHOW_AUTOMODS="n"
APPNAME=$(basename "${0}")
usage ()
{
echo "${APPNAME}: usage"
echo " -c CONFIG Use CONFIG file. default: /etc/mkinitcpio.conf"
echo " -k KERNELVERSION Use KERNELVERSION. default: $(uname -r)"
echo " -s NAME Save filelist. default: no"
echo " -b BASEDIR Use BASEDIR. default: /"
echo " -g IMAGE Generate a cpio image as IMAGE. default: no"
echo " -a NAME Append to an existing filelist. default: no"
echo " -v Verbose output. Default: no"
echo " -M Display modules found via autodetection."
echo " -L List all available hooks."
echo " -H HOOKNAME Output help for hook 'HOOKNAME'."
echo " -h This message."
exit 1
}
while getopts 'c:k:s:b:g:a:vH:LMh' arg; do
case "$arg" in
c) CONFIG="$OPTARG" ;;
k) KERNELVERSION="$OPTARG" ;;
s) SAVELIST="y"; FILELIST="$OPTARG" ;;
b) BASEDIR="$OPTARG" ;;
g) GENIMG="$OPTARG" ;;
a) APPEND="y" FILELIST="$OPTARG" ;;
v) QUIET="n" ;;
H) source "${INSTDIR}/${OPTARG}";
echo "Help for hook '${OPTARG}':"
help
exit 0 ;;
L) echo "Available hooks: "
for h in ${INSTDIR}/*; do
echo " $(basename ${h})"
done
exit 0 ;;
M) SHOW_AUTOMODS="y" ;;
h|?) usage ;;
*) echo "invalid argument '$arg'"; usage ;;
esac
done
shift $(($OPTIND - 1))
# append a trailing / if needed
if [ "${BASEDIR:${#BASEDIR}}" == "/" ]; then
BASEDIR="${BASEDIR:0:${#BASEDIR}-1}"
fi
MODULEDIR="${BASEDIR}/lib/modules/${KERNELVERSION}"
if [ "x${BASEDIR}" != "x" ]; then
if [ "${BASEDIR:0:1}" != "/" ]; then
echo "base directory '${BASEDIR}' must be an absolute path"
exit 1
elif [ ! -d "${BASEDIR}" ]; then
echo "base directory '${BASEDIR}' does not exist or is not a directory"
exit 1
fi
fi
if [ ! -f "${CONFIG}" ]; then
echo "config file '${CONFIG}' cannot be found, aborting..."
exit 1
fi
source "${CONFIG}"
if [ -f "${FILELIST}" -a "x${APPEND}" == "x" ]; then
if [ "x${SAVELIST}" == "x" ]; then
rm ${FILELIST}
touch "${FILELIST}"
else
echo "destination file list '${FILELIST}' exists - remove before running"
exit 1
fi
elif [ -f "${DESTIMG}" ]; then
echo "destination image '${DESTIMG}' exists - remove before running"
exit 1
else
touch "${FILELIST}"
fi
source "${FUNCTIONS}"
if [ "${SHOW_AUTOMODS}" = "y" ]; then
echo "Modules autodetected:"
source "${INSTDIR}/autodetect"
install
cat "${MODULE_FILE}"
exit 0
fi
echo ":: Begin build"
#parse 'global' hook, as defined in ${CONFIG}
parse_hook
for hook in $HOOKS; do
unset MODULES
unset BINARIES
unset FILES
install () { msg "${hook}: no install function..."; }
if grep "install" "${INSTDIR}/${hook}" >/dev/null 2>&1; then
source "${INSTDIR}/${hook}"
echo ":: Parsing hook [${hook}]"
install
parse_hook
fi
done
if [ "${HAS_MODULES}" == "y" ]; then
echo ":: Generating module dependancies"
[ -e /tmp/lib/modules/${KERNELVERSION}/ ] && rm -r /tmp/lib/modules/${KERNELVERSION}/
cp -r --parents $(grep "file /lib/modules" ${FILELIST} | awk '{print $2}') /tmp/
depmod -b /tmp ${KERNELVERSION}
add_file /tmp/lib/modules/${KERNELVERSION}/modules.dep ${MODULEDIR}/modules.dep
add_file /tmp/lib/modules/${KERNELVERSION}/modules.alias ${MODULEDIR}/modules.alias
add_file /tmp/lib/modules/${KERNELVERSION}/modules.symbols ${MODULEDIR}/modules.symbols
fi
if [ "x$GENIMG" != "x" ]; then
echo -n "::Generating image '${GENIMG}'..."
if ! gen_init_cpio ${FILELIST} | gzip -9 > "${GENIMG}"; then
echo "FAILED"
else
echo "SUCCESS"
fi
if [ "x${SAVELIST}" == "x" ]; then
rm ${FILELIST}
fi
else
echo ":: Dry run complete, use -g IMAGE to generate a real image"
fi
[ -e "${MODULE_FILE}" ] && rm "${MODULE_FILE}"
[ -e "/tmp${MODULEDIR}/" ] && rm -rf /tmp${MODULEDIR}/
#vim:set ft=sh ts=4 sw=4 noet:
|