Refactoring

This commit is contained in:
Kevin Veen-Birkenbach 2020-05-15 12:00:03 +02:00
parent cb427d1e00
commit df1fcfff63
5 changed files with 41 additions and 23 deletions

View File

@ -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

View File

@ -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:"

19
scripts/image/base.sh Normal file
View File

@ -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
}

View File

@ -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

View File

@ -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..."