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