Refactored code

This commit is contained in:
Kevin Veen-Birkenbach 2020-05-15 10:41:44 +02:00
parent 473de735de
commit e8f23beb33
2 changed files with 36 additions and 24 deletions

View File

@ -35,35 +35,46 @@
# https://gist.github.com/htruong/0271d84ae81ee1d301293d126a5ad716 # https://gist.github.com/htruong/0271d84ae81ee1d301293d126a5ad716
# so it's better just to let the pi resize the partitions # so it's better just to let the pi resize the partitions
mkdir -p /mnt/raspbian # shellcheck source=/dev/null # Deactivate SC1090
# shellcheck disable=SC2015 # Deactivating bool hint
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
# mount partition info "Making mount dir..." &&
mount -o rw "$1""2" /mnt/raspbian mkdir -p /mnt/raspbian ||
mount -o rw "$1""1" /mnt/raspbian/boot error "Failed."
# mount binds info "Mount partitions..."
mount --bind /dev /mnt/raspbian/dev/ mount -o rw "$1""2" /mnt/raspbian &&
mount --bind /sys /mnt/raspbian/sys/ mount -o rw "$1""1" /mnt/raspbian/boot ||
mount --bind /proc /mnt/raspbian/proc/ error "Failed."
mount --bind /dev/pts /mnt/raspbian/dev/pts
# ld.so.preload fix info "Mount binds..." &&
sed -i 's/^/#CHROOT /g' /mnt/raspbian/etc/ld.so.preload mount --bind /dev /mnt/raspbian/dev/ &&
mount --bind /sys /mnt/raspbian/sys/ &&
mount --bind /proc /mnt/raspbian/proc/ &&
mount --bind /dev/pts /mnt/raspbian/dev/pts &&
error "Failed."
# copy qemu binary info "ld.so.preload fix" &&
cp /usr/bin/qemu-arm-static /mnt/raspbian/usr/bin/ sed -i 's/^/#CHROOT /g' /mnt/raspbian/etc/ld.so.preload ||
error "Failed."
echo "You will be transferred to the bash shell now." info "copy qemu binary" &&
echo "Issue 'exit' when you are done." cp -v /usr/bin/qemu-arm-static /mnt/raspbian/usr/bin/ ||
echo "Issue 'su pi' if you need to work as the user pi." error "Failed."
# chroot to raspbian info "You will be transferred to the bash shell now." &&
chroot /mnt/raspbian /bin/bash info "Issue 'exit' when you are done." &&
info "Issue 'su pi' if you need to work as the user pi." &&
info "chroot to raspbian" &&
chroot /mnt/raspbian /bin/bash ||
error "Failed."
# ---------------------------- info "Clean up" &&
# Clean up info "revert ld.so.preload fix" &&
# revert ld.so.preload fix sed -i 's/^#CHROOT //g' /mnt/raspbian/etc/ld.so.preload ||
sed -i 's/^#CHROOT //g' /mnt/raspbian/etc/ld.so.preload error "Failed."
# unmount everything info "unmount everything" &&
umount /mnt/raspbian/{dev/pts,dev,sys,proc,boot,} umount /mnt/raspbian/{dev/pts,dev,sys,proc,boot,} ||
error "Failed."

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC2010 # ls | grep allowed # shellcheck disable=SC2010 # ls | grep allowed
# shellcheck source=/dev/null # Deactivate SC1090
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1) source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
info "Setupscript for images started..." info "Setupscript for images started..."