@@ -1,98 +1,97 | |||
|
1 | 1 | #!/bin/sh |
|
2 | 2 | # This file contains utility functions used by rpi23-gen-image.sh |
|
3 | 3 | |
|
4 | 4 | cleanup (){ |
|
5 | 5 | set +x |
|
6 | 6 | set +e |
|
7 | 7 | |
|
8 | 8 | # Identify and kill all processes still using files |
|
9 | 9 | echo "killing processes using mount point ..." |
|
10 | 10 | fuser -k "${R}" |
|
11 | 11 | sleep 3 |
|
12 | 12 | fuser -9 -k -v "${R}" |
|
13 | 13 | |
|
14 | 14 | # Clean up temporary .password file |
|
15 | 15 | if [ -r ".password" ] ; then |
|
16 | 16 | shred -zu .password |
|
17 | 17 | fi |
|
18 | 18 | |
|
19 | 19 | # Clean up all temporary mount points |
|
20 | 20 | echo "removing temporary mount points ..." |
|
21 | 21 | umount -l "${R}/proc" 2> /dev/null |
|
22 | 22 | umount -l "${R}/sys" 2> /dev/null |
|
23 | 23 | umount -l "${R}/dev/pts" 2> /dev/null |
|
24 | 24 | umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null |
|
25 | 25 | umount "$BUILDDIR/mount" 2> /dev/null |
|
26 | 26 | cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null |
|
27 | 27 | losetup -d "$ROOT_LOOP" 2> /dev/null |
|
28 | 28 | losetup -d "$FRMW_LOOP" 2> /dev/null |
|
29 | 29 | trap - 0 1 2 3 6 |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | chroot_exec() { |
|
33 | 33 | # Exec command in chroot |
|
34 | LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $* | |
|
34 | LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot "${R}" "$*" | |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | as_nobody() { |
|
38 | 38 | # Exec command as user nobody |
|
39 | sudo -E -u nobody LANG=C LC_ALL=C $* | |
|
39 | sudo -E -u nobody LANG=C LC_ALL=C "$*" | |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | install_readonly() { |
|
43 | 43 | # Install file with user read-only permissions |
|
44 | install -o root -g root -m 644 $* | |
|
44 | install -o root -g root -m 644 "$*" | |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | install_exec() { |
|
48 | 48 | # Install file with root exec permissions |
|
49 | install -o root -g root -m 744 $* | |
|
49 | install -o root -g root -m 744 "$*" | |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | use_template () { |
|
53 | 53 | # Test if configuration template file exists |
|
54 | 54 | if [ ! -r "./templates/${CONFIG_TEMPLATE}" ] ; then |
|
55 | 55 | echo "error: configuration template ${CONFIG_TEMPLATE} not found" |
|
56 | 56 | exit 1 |
|
57 | 57 | fi |
|
58 | 58 | |
|
59 | 59 | # Load template configuration parameters |
|
60 | 60 | . "./templates/${CONFIG_TEMPLATE}" |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | chroot_install_cc() { |
|
64 | 64 | # Install c/c++ build environment inside the chroot |
|
65 | 65 | if [ -z "${COMPILER_PACKAGES}" ] ; then |
|
66 | 66 | COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }') |
|
67 | 67 | # Install COMPILER_PACKAGES in chroot |
|
68 | chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES} | |
|
68 | chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install "${COMPILER_PACKAGES}" | |
|
69 | 69 | fi |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | chroot_remove_cc() { |
|
73 | 73 | # Remove c/c++ build environment from the chroot |
|
74 |
if [ |
|
|
75 | chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES} | |
|
74 | if [ -n "${COMPILER_PACKAGES}" ] ; then | |
|
75 | chroot_exec apt-get -qq -y --auto-remove purge "${COMPILER_PACKAGES}" | |
|
76 | 76 | COMPILER_PACKAGES="" |
|
77 | 77 | fi |
|
78 | 78 | } |
|
79 | 79 | #GPL v2.0 |
|
80 | 80 | #https://github.com/sakaki-/bcmrpi3-kernel-bis/blob/master/conform_config.sh |
|
81 | 81 | set_kernel_config() { |
|
82 | 82 | # flag as $1, value to set as $2, config must exist at "./.config" |
|
83 | 83 | TGT="CONFIG_${1#CONFIG_}" |
|
84 | 84 | REP="${2}" |
|
85 | 85 | if grep -q "^${TGT}[^_]" .config; then |
|
86 | 86 | sed -i "s/^\(${TGT}=.*\|# ${TGT} is not set\)/${TGT}=${REP}/" .config |
|
87 | 87 | else |
|
88 | 88 | echo "${TGT}=${2}" >> .config |
|
89 | 89 | fi |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | unset_kernel_config() { |
|
93 | 93 | # unsets flag with the value of $1, config must exist at "./.config" |
|
94 |
|
|
|
94 | TGT="CONFIG_${1#CONFIG_}" | |
|
95 | 95 | sed -i "s/^${TGT}=.*/# ${TGT} is not set/" .config |
|
96 | 96 | } |
|
97 | 97 | # |
|
No newline at end of file | ||
|
98 |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant