functions.sh
81 lines
| 2.3 KiB
| application/x-sh
|
BashLexer
drtyhlpr
|
r94 | # This file contains utility functions used by rpi23-gen-image.sh | ||
Jan Wagner
|
r67 | |||
Filip Pytloun
|
r56 | cleanup (){ | ||
set +x | ||||
set +e | ||||
Jan Wagner
|
r67 | |||
# Identify and kill all processes still using files | ||||
Filip Pytloun
|
r59 | echo "killing processes using mount point ..." | ||
Jan Wagner
|
r82 | fuser -k "${R}" | ||
Filip Pytloun
|
r59 | sleep 3 | ||
Jan Wagner
|
r82 | fuser -9 -k -v "${R}" | ||
Jan Wagner
|
r67 | |||
Jan Wagner
|
r78 | # Clean up temporary .password file | ||
if [ -r ".password" ] ; then | ||||
shred -zu .password | ||||
fi | ||||
Jan Wagner
|
r67 | # Clean up all temporary mount points | ||
Filip Pytloun
|
r56 | echo "removing temporary mount points ..." | ||
Jan Wagner
|
r82 | umount -l "${R}/proc" 2> /dev/null | ||
umount -l "${R}/sys" 2> /dev/null | ||||
umount -l "${R}/dev/pts" 2> /dev/null | ||||
Filip Pytloun
|
r56 | umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null | ||
umount "$BUILDDIR/mount" 2> /dev/null | ||||
Jan Wagner
|
r77 | cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null | ||
Vincent Knecht
|
r66 | losetup -d "$ROOT_LOOP" 2> /dev/null | ||
losetup -d "$FRMW_LOOP" 2> /dev/null | ||||
Filip Pytloun
|
r56 | trap - 0 1 2 3 6 | ||
} | ||||
chroot_exec() { | ||||
# Exec command in chroot | ||||
Jan Wagner
|
r82 | LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $* | ||
Filip Pytloun
|
r56 | } | ||
Jan Wagner
|
r67 | |||
Petter Reinholdtsen
|
r174 | as_nobody() { | ||
# Exec command as user nobody | ||||
drtyhlpr
|
r178 | sudo -E -u nobody LANG=C LC_ALL=C $* | ||
Petter Reinholdtsen
|
r174 | } | ||
Jan Wagner
|
r67 | install_readonly() { | ||
# Install file with user read-only permissions | ||||
install -o root -g root -m 644 $* | ||||
} | ||||
install_exec() { | ||||
# Install file with root exec permissions | ||||
install -o root -g root -m 744 $* | ||||
} | ||||
drtyhlpr
|
r117 | |||
use_template () { | ||||
# Test if configuration template file exists | ||||
if [ ! -r "./templates/${CONFIG_TEMPLATE}" ] ; then | ||||
echo "error: configuration template ${CONFIG_TEMPLATE} not found" | ||||
exit 1 | ||||
fi | ||||
# Load template configuration parameters | ||||
. "./templates/${CONFIG_TEMPLATE}" | ||||
} | ||||
drtyhlpr
|
r142 | |||
chroot_install_cc() { | ||||
# Install c/c++ build environment inside the chroot | ||||
if [ -z "${COMPILER_PACKAGES}" ] ; then | ||||
COMPILER_PACKAGES=$(chroot_exec apt-get -s install g++ make bc | grep "^Inst " | awk -v ORS=" " '{ print $2 }') | ||||
r156 | if [ "$RELEASE" = "jessie" ] || [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then | |||
drtyhlpr
|
r142 | chroot_exec apt-get -q -y --no-install-recommends install ${COMPILER_PACKAGES} | ||
r219 | elif [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then | |||
chroot_exec apt-get -q -y --allow-unauthenticated --no-install-recommends install ${COMPILER_PACKAGES} | ||||
drtyhlpr
|
r142 | fi | ||
fi | ||||
} | ||||
chroot_remove_cc() { | ||||
# Remove c/c++ build environment from the chroot | ||||
if [ ! -z "${COMPILER_PACKAGES}" ] ; then | ||||
chroot_exec apt-get -qq -y --auto-remove purge ${COMPILER_PACKAGES} | ||||
COMPILER_PACKAGES="" | ||||
fi | ||||
} | ||||