diff --git a/scripts/image/backup.sh b/scripts/image/backup.sh index 33f086d..c59e480 100644 --- a/scripts/image/backup.sh +++ b/scripts/image/backup.sh @@ -5,17 +5,7 @@ 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:" -echo -ls -lasi /dev/ | grep -E "sd|mm" -echo -while [ ! -b "$ifi" ] - do - info "Please select the correct device." - question "/dev/:" - read -r device - ifi="/dev/$device" -done +set_device_path while [ "$path" == "" ] do echo "Bitte Backupimagepfad+Namen zu $PWD eingeben:" @@ -27,12 +17,12 @@ while [ "$path" == "" ] ofi="$PWD/$path.img" fi done -info "Input file: $ifi" +info "Input file: $device_path" info "Output file: $ofi" question "Please confirm by pushing \"Enter\". To cancel use \"Ctrl + Alt + C\"" read -r bestaetigung && echo "$bestaetigung"; info "Imagetransfer starts. This can take a while..." && -dd if="$ifi" of="$ofi" bs=1M status=progress || error "\"dd\" failed."; +dd if="$device_path" of="$ofi" bs=1M status=progress || error "\"dd\" failed."; success "Imagetransfer successfull." && exit 0; diff --git a/scripts/image/base.sh b/scripts/image/base.sh index 32561f7..fb1f8d4 100644 --- a/scripts/image/base.sh +++ b/scripts/image/base.sh @@ -35,3 +35,41 @@ set_device_path(){ error "$device_path is not valid device." fi } + +make_mount_folders(){ + info "Preparing mount paths..." && + boot_mount_path="$working_folder_path""boot/" && + root_mount_path="$working_folder_path""root/" && + mkdir -v "$boot_mount_path" && + mkdir -v "$root_mount_path" || + error +} + +make_working_folder(){ + working_folder_path="/tmp/raspberry-pi-tools-$(date +%s)/" && + info "Create temporary working folder in $working_folder_path" && + mkdir -v "$working_folder_path" || + error +} + +mount_partitions(){ + info "Mount boot and root partition..." && + mount "$boot_partition_path" "$boot_mount_path" && + mount "$root_partition_path" "$root_mount_path" && + info "The following mounts refering this setup exist:" && mount | grep "$working_folder_path" || + error +} + +mount_binds(){ + info "Mount chroot environments..." && + chroot_sys_mount_path="$root_mount_path""sys/" && + chroot_proc_mount_path="$root_mount_path""proc/" && + chroot_dev_mount_path="$root_mount_path""dev/" && + chroot_dev_pts_mount_path="$root_mount_path""dev/pts" && + mount --bind "$boot_mount_path" "$root_mount_path""/boot" && + mount --bind /dev "$chroot_dev_mount_path" && + mount --bind /sys "$chroot_sys_mount_path" && + mount --bind /proc "$chroot_proc_mount_path" && + mount --bind /dev/pts "$chroot_dev_pts_mount_path" || + error +} diff --git a/scripts/image/chroot.sh b/scripts/image/chroot.sh index 9d9202f..7122169 100644 --- a/scripts/image/chroot.sh +++ b/scripts/image/chroot.sh @@ -7,26 +7,15 @@ info "Starting chroot..." set_device_path -info "Making mount dir..." && -mkdir -p /mnt/raspbian || -error +make_working_folder +make_mount_folders -root_mount_path="/mnt/raspbian" -boot_mount_path="/mnt/raspbian/boot" set_partition_paths -info "Mount partitions..." -mount -o rw "$boot_partition_path" "$boot_mount_path" || -mount -o rw "$root_partition_path" "$root_mount_path" && -error +mount_partitions -info "Mount binds..." && -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 +mount_binds info "ld.so.preload fix" && sed -i 's/^/#CHROOT /g' "$root_mount_path/etc/ld.so.preload" || diff --git a/scripts/image/setup.sh b/scripts/image/setup.sh index d4da1d4..49f0951 100644 --- a/scripts/image/setup.sh +++ b/scripts/image/setup.sh @@ -18,19 +18,15 @@ destructor(){ umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!" rmdir -v "$root_mount_path" || warning "Removing $root_mount_path failed!" rmdir -v "$boot_mount_path" || warning "Removing $boot_mount_path failed!" - rmdir -v "$working_folder" || warning "Removing $working_folder failed!" + rmdir -v "$working_folder_path" || warning "Removing $working_folder_path failed!" } -info "Define variables..." -working_folder="/tmp/raspberry-pi-tools-$(date +%s)/"; - info "Checking if root..." if [ "$(id -u)" != "0" ];then error "This script must be executed as root!" fi -info "Create temporary working folder in $working_folder"; -mkdir -v "$working_folder" +make_working_folder info "Configure user..." question "Please type in a valid username from which the SSH-Key should be copied:" && read -r origin_username; @@ -151,21 +147,10 @@ if [[ -v image_checksum ]] warning "Verification is not possible. No checksum is defined." fi -info "Preparing mount paths..." -boot_mount_path="$working_folder""boot/" -root_mount_path="$working_folder""root/" -mkdir -v "$boot_mount_path" -mkdir -v "$root_mount_path" +make_mount_folders set_partition_paths -mount_partitions(){ - info "Mount boot and root partition..." - mount "$boot_partition_path" "$boot_mount_path" || error "Mount from $boot_partition_path to $boot_mount_path failed..." - mount "$root_partition_path" "$root_mount_path" || error "Mount from $root_partition_path to $root_mount_path failed..." - info "The following mounts refering this setup exist:" && mount | grep "$working_folder" -} - question "Should the image be transfered to $device_path?(y/n)" && read -r transfer_image if [ "$transfer_image" = "y" ] then @@ -263,16 +248,8 @@ if [ -f "$origin_user_rsa_pub" ] fi info "Start chroot procedures..." -info "Mount chroot environments..." -chroot_sys_mount_path="$root_mount_path""sys/" -chroot_proc_mount_path="$root_mount_path""proc/" -chroot_dev_mount_path="$root_mount_path""dev/" -chroot_dev_pts_mount_path="$root_mount_path""dev/pts" -mount --bind "$boot_mount_path" "$root_mount_path""/boot" || error "Mounting $chroot_dev_mount_path failed." -mount --bind /dev "$chroot_dev_mount_path" || error "Mounting $chroot_dev_mount_path failed." -mount --bind /sys "$chroot_sys_mount_path" || error "Mounting $chroot_sys_mount_path failed." -mount --bind /proc "$chroot_proc_mount_path" || error "Mounting $chroot_proc_mount_path failed." -mount --bind /dev/pts "$chroot_dev_pts_mount_path" || error "Mounting $chroot_dev_pts_mount_path failed." + +mount_binds sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" cp -v /usr/bin/qemu-arm-static "$root_mount_path""/usr/bin/" || error "Copy qemu-arm-static failed. The following packages are neccessary: qemu qemu-user-static binfmt-support."