@@ -1,81 +1,81 | |||||
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 -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 |
|
66 | |||
67 | if [ "$RELEASE" = "jessie" ] ; then |
|
67 | if [ "$RELEASE" = "jessie" ] ; then | |
68 | chroot_exec apt-get -q -y --no-install-recommends install ${COMPILER_PACKAGES} |
|
68 | chroot_exec apt-get -q -y --no-install-recommends install ${COMPILER_PACKAGES} | |
69 | elif [ "$RELEASE" = "stretch" ] ; then |
|
69 | elif [ "$RELEASE" = "stretch" ] ; then | |
70 | chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES} |
|
70 | chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES} | |
71 | fi |
|
71 | fi | |
72 | fi |
|
72 | fi | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | chroot_remove_cc() { |
|
75 | chroot_remove_cc() { | |
76 | # Remove c/c++ build environment from the chroot |
|
76 | # Remove c/c++ build environment from the chroot | |
77 | if [ ! -z "${COMPILER_PACKAGES}" ] ; then |
|
77 | if [ ! -z "${COMPILER_PACKAGES}" ] ; then | |
78 | chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES} |
|
78 | chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES} | |
79 | COMPILER_PACKAGES="" |
|
79 | COMPILER_PACKAGES="" | |
80 | fi |
|
80 | fi | |
81 | } |
|
81 | } |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant