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