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.
|
# 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() {
|
help() {
|
||||||
echo -e "Usage:\n"
|
echo -e "Usage:\n"
|
||||||
@ -116,6 +129,8 @@ mkfs.ext4 -F ${loopdev}p2
|
|||||||
mount ${loopdev}p2 /mnt
|
mount ${loopdev}p2 /mnt
|
||||||
mkdir /mnt/boot
|
mkdir /mnt/boot
|
||||||
mount ${loopdev}p1 /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
|
wget "${url[$imageVersion]}" -O- | bsdtar -xpf - -C /mnt
|
||||||
arch-chroot /mnt << EOF
|
arch-chroot /mnt << EOF
|
||||||
# set up pacman
|
# set up pacman
|
||||||
@ -148,6 +163,5 @@ systemctl enable cronie.service fenrirscreenreader.service
|
|||||||
# Update fstab for Raspberry Pi 4.
|
# Update fstab for Raspberry Pi 4.
|
||||||
[[ $imageVersion -eq 4 ]] && sed -i 's/mmcblk0/mmcblk1/g' /etc/fstab
|
[[ $imageVersion -eq 4 ]] && sed -i 's/mmcblk0/mmcblk1/g' /etc/fstab
|
||||||
EOF
|
EOF
|
||||||
umount -R /mnt
|
|
||||||
partx -d ${loopdev}
|
exit 0
|
||||||
losetup --detach ${loopdev}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user