Added cleanup code for if the script exits unexpectedly.
This commit is contained in:
parent
e16e23a835
commit
b578c2031a
@ -18,8 +18,21 @@
|
||||
# 02110-1301, USA.
|
||||
#
|
||||
|
||||
set -e # Don't want to destroy stuff if this goes majorly wrong.
|
||||
# keep track of mounted status for exit function
|
||||
mounted=1
|
||||
|
||||
set -e # Don't want to destroy stuff if this goes majorly wrong.
|
||||
trap cleanup EXIT # make sure the script cleans up after itself before closing.
|
||||
|
||||
|
||||
cleanup() {
|
||||
if [[ $mounted -eq 0 ]]; then
|
||||
umount -R /mnt
|
||||
partx -d ${loopdev}
|
||||
losetup --detach ${loopdev}
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
help() {
|
||||
echo -e "Usage:\n"
|
||||
@ -116,6 +129,8 @@ mkfs.ext4 -F ${loopdev}p2
|
||||
mount ${loopdev}p2 /mnt
|
||||
mkdir /mnt/boot
|
||||
mount ${loopdev}p1 /mnt/boot
|
||||
# Things are mounted now, so set mounted to 0 (bash true)
|
||||
mounted=0
|
||||
wget "${url[$imageVersion]}" -O- | bsdtar -xpf - -C /mnt
|
||||
arch-chroot /mnt << EOF
|
||||
# set up pacman
|
||||
@ -148,6 +163,5 @@ systemctl enable cronie.service fenrirscreenreader.service
|
||||
# Update fstab for Raspberry Pi 4.
|
||||
[[ $imageVersion -eq 4 ]] && sed -i 's/mmcblk0/mmcblk1/g' /etc/fstab
|
||||
EOF
|
||||
umount -R /mnt
|
||||
partx -d ${loopdev}
|
||||
losetup --detach ${loopdev}
|
||||
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user