##// END OF EJS Templates
Fix: preserve user environment when using sudo (function as_nobody)
drtyhlpr -
r178:fc1f49f4b604
parent child
Show More
@@ -1,81 +1,81
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 # Identify and kill all processes still using files
8 8 echo "killing processes using mount point ..."
9 9 fuser -k "${R}"
10 10 sleep 3
11 11 fuser -9 -k -v "${R}"
12 12
13 13 # Clean up temporary .password file
14 14 if [ -r ".password" ] ; then
15 15 shred -zu .password
16 16 fi
17 17
18 18 # Clean up all temporary mount points
19 19 echo "removing temporary mount points ..."
20 20 umount -l "${R}/proc" 2> /dev/null
21 21 umount -l "${R}/sys" 2> /dev/null
22 22 umount -l "${R}/dev/pts" 2> /dev/null
23 23 umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null
24 24 umount "$BUILDDIR/mount" 2> /dev/null
25 25 cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null
26 26 losetup -d "$ROOT_LOOP" 2> /dev/null
27 27 losetup -d "$FRMW_LOOP" 2> /dev/null
28 28 trap - 0 1 2 3 6
29 29 }
30 30
31 31 chroot_exec() {
32 32 # Exec command in chroot
33 33 LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $*
34 34 }
35 35
36 36 as_nobody() {
37 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 41 install_readonly() {
42 42 # Install file with user read-only permissions
43 43 install -o root -g root -m 644 $*
44 44 }
45 45
46 46 install_exec() {
47 47 # Install file with root exec permissions
48 48 install -o root -g root -m 744 $*
49 49 }
50 50
51 51 use_template () {
52 52 # Test if configuration template file exists
53 53 if [ ! -r "./templates/${CONFIG_TEMPLATE}" ] ; then
54 54 echo "error: configuration template ${CONFIG_TEMPLATE} not found"
55 55 exit 1
56 56 fi
57 57
58 58 # Load template configuration parameters
59 59 . "./templates/${CONFIG_TEMPLATE}"
60 60 }
61 61
62 62 chroot_install_cc() {
63 63 # Install c/c++ build environment inside the chroot
64 64 if [ -z "${COMPILER_PACKAGES}" ] ; then
65 65 COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }')
66 66
67 67 if [ "$RELEASE" = "jessie" ] ; then
68 68 chroot_exec apt-get -q -y --no-install-recommends install ${COMPILER_PACKAGES}
69 69 elif [ "$RELEASE" = "stretch" ] ; then
70 70 chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES}
71 71 fi
72 72 fi
73 73 }
74 74
75 75 chroot_remove_cc() {
76 76 # Remove c/c++ build environment from the chroot
77 77 if [ ! -z "${COMPILER_PACKAGES}" ] ; then
78 78 chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES}
79 79 COMPILER_PACKAGES=""
80 80 fi
81 81 }
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant