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