diff --git a/scripts/base.sh b/scripts/base.sh index 450499d..e03332d 100644 --- a/scripts/base.sh +++ b/scripts/base.sh @@ -1,7 +1,6 @@ #!/bin/bash # # This script contains the global program variables and functions -# @author Kevin Veen-Birkenbach [aka. Frantz] # # shellcheck disable=SC2034 #Deactivate checking of unused variables diff --git a/scripts/image/backup.sh b/scripts/image/backup.sh index 3a5c4fb..33f086d 100644 --- a/scripts/image/backup.sh +++ b/scripts/image/backup.sh @@ -1,6 +1,8 @@ #!/bin/bash # shellcheck disable=SC2010 # shellcheck disable=SC2015 # Deactivating bool hint +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1) info "Backupscript for memory devices started..." echo info "Actual mounted devices:" diff --git a/scripts/image/base.sh b/scripts/image/base.sh new file mode 100644 index 0000000..b34f5a3 --- /dev/null +++ b/scripts/image/base.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Offers base functions for the image management +# +# shellcheck disable=SC2034 #Deactivate checking of unused variables +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1) + +# Writes the full partition name +# @parameter $1 is device path +# @parameter $2 is the partition number +echo_partition_name(){ + if [ "${1:5:1}" != "s" ] + then + echo "$1""p""$2" + else + echo "$1$2" + fi +} diff --git a/scripts/image/chroot.sh b/scripts/image/chroot.sh index bc83a5f..1230273 100644 --- a/scripts/image/chroot.sh +++ b/scripts/image/chroot.sh @@ -1,44 +1,49 @@ #!/bin/bash # 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) +source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1) info "Making mount dir..." && mkdir -p /mnt/raspbian || error +root_mount_path="/mnt/raspbian" +boot_mount_path="/mnt/raspbian/boot" +root_partition_path=$(echo_partition_name $1 "2") +boot_partition_path=$(echo_partition_name $1 "1") + info "Mount partitions..." -mount -o rw "$1""2" /mnt/raspbian && -mount -o rw "$1""1" /mnt/raspbian/boot || +mount -o rw "$boot_partition_path" "$boot_mount_path" || +mount -o rw "$root_partition_path" "$root_mount_path" && error info "Mount binds..." && -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 || +mount --bind /dev "$root_mount_path/dev/" && +mount --bind /sys "$root_mount_path/sys/" && +mount --bind /proc "$root_mount_path/proc/" && +mount --bind /dev/pts "$root_mount_path/dev/pts" || error info "ld.so.preload fix" && -sed -i 's/^/#CHROOT /g' /mnt/raspbian/etc/ld.so.preload || +sed -i 's/^/#CHROOT /g' "$root_mount_path/etc/ld.so.preload" || error info "copy qemu binary" && -cp -v /usr/bin/qemu-arm-static /mnt/raspbian/usr/bin/ || +cp -v /usr/bin/qemu-arm-static "$root_mount_path/usr/bin/" || error info "You will be transferred to the bash shell now." && 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 || +chroot "$root_mount_path" /bin/bash || error info "Clean up" && info "revert ld.so.preload fix" && -sed -i 's/^#CHROOT //g' /mnt/raspbian/etc/ld.so.preload || +sed -i 's/^#CHROOT //g' "$root_mount_path/etc/ld.so.preload" || error info "unmount everything" && -umount /mnt/raspbian/{dev/pts,dev,sys,proc,boot,} || +umount "$root_mount_path"/{dev/pts,dev,sys,proc,boot,} || error diff --git a/scripts/image/setup.sh b/scripts/image/setup.sh index 95c3e38..4e2b9af 100644 --- a/scripts/image/setup.sh +++ b/scripts/image/setup.sh @@ -1,7 +1,7 @@ #!/bin/bash # 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..." @@ -167,15 +167,8 @@ root_mount_path="$working_folder""root/" mkdir -v "$boot_mount_path" mkdir -v "$root_mount_path" -info "Defining partition paths..." -if [ "${sd_card_path:5:1}" != "s" ] - then - partion="p" - else - partion="" -fi -boot_partition_path=$sd_card_path$partion"1" -root_partition_path=$sd_card_path$partion"2" +boot_partition_path=$(echo_partition_name $sd_card_path "1") +root_partition_path=$(echo_partition_name $sd_card_path "2") mount_partitions(){ info "Mount boot and root partition..."