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