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