mirror of
https://github.com/kevinveenbirkenbach/linux-image-manager.git
synced 2024-11-14 03:21:03 +01:00
In between commit Refactoring
This commit is contained in:
parent
871646bc64
commit
1bd5d5f255
@ -5,17 +5,7 @@
|
|||||||
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 "Backupscript for memory devices started..."
|
info "Backupscript for memory devices started..."
|
||||||
echo
|
echo
|
||||||
info "Actual mounted devices:"
|
set_device_path
|
||||||
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
|
|
||||||
while [ "$path" == "" ]
|
while [ "$path" == "" ]
|
||||||
do
|
do
|
||||||
echo "Bitte Backupimagepfad+Namen zu $PWD eingeben:"
|
echo "Bitte Backupimagepfad+Namen zu $PWD eingeben:"
|
||||||
@ -27,12 +17,12 @@ while [ "$path" == "" ]
|
|||||||
ofi="$PWD/$path.img"
|
ofi="$PWD/$path.img"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
info "Input file: $ifi"
|
info "Input file: $device_path"
|
||||||
info "Output file: $ofi"
|
info "Output file: $ofi"
|
||||||
question "Please confirm by pushing \"Enter\". To cancel use \"Ctrl + Alt + C\""
|
question "Please confirm by pushing \"Enter\". To cancel use \"Ctrl + Alt + C\""
|
||||||
read -r bestaetigung && echo "$bestaetigung";
|
read -r bestaetigung && echo "$bestaetigung";
|
||||||
|
|
||||||
info "Imagetransfer starts. This can take a while..." &&
|
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;
|
success "Imagetransfer successfull." && exit 0;
|
||||||
|
@ -35,3 +35,41 @@ set_device_path(){
|
|||||||
error "$device_path is not valid device."
|
error "$device_path is not valid device."
|
||||||
fi
|
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
|
||||||
|
}
|
||||||
|
@ -7,26 +7,15 @@ info "Starting chroot..."
|
|||||||
|
|
||||||
set_device_path
|
set_device_path
|
||||||
|
|
||||||
info "Making mount dir..." &&
|
make_working_folder
|
||||||
mkdir -p /mnt/raspbian ||
|
|
||||||
error
|
|
||||||
|
|
||||||
|
make_mount_folders
|
||||||
|
|
||||||
root_mount_path="/mnt/raspbian"
|
|
||||||
boot_mount_path="/mnt/raspbian/boot"
|
|
||||||
set_partition_paths
|
set_partition_paths
|
||||||
|
|
||||||
info "Mount partitions..."
|
mount_partitions
|
||||||
mount -o rw "$boot_partition_path" "$boot_mount_path" ||
|
|
||||||
mount -o rw "$root_partition_path" "$root_mount_path" &&
|
|
||||||
error
|
|
||||||
|
|
||||||
info "Mount binds..." &&
|
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
|
|
||||||
|
|
||||||
info "ld.so.preload fix" &&
|
info "ld.so.preload fix" &&
|
||||||
sed -i 's/^/#CHROOT /g' "$root_mount_path/etc/ld.so.preload" ||
|
sed -i 's/^/#CHROOT /g' "$root_mount_path/etc/ld.so.preload" ||
|
||||||
|
@ -18,19 +18,15 @@ destructor(){
|
|||||||
umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!"
|
umount -v "$boot_mount_path" || warning "Umounting $boot_mount_path failed!"
|
||||||
rmdir -v "$root_mount_path" || warning "Removing $root_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 "$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..."
|
info "Checking if root..."
|
||||||
if [ "$(id -u)" != "0" ];then
|
if [ "$(id -u)" != "0" ];then
|
||||||
error "This script must be executed as root!"
|
error "This script must be executed as root!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Create temporary working folder in $working_folder";
|
make_working_folder
|
||||||
mkdir -v "$working_folder"
|
|
||||||
|
|
||||||
info "Configure user..."
|
info "Configure user..."
|
||||||
question "Please type in a valid username from which the SSH-Key should be copied:" && read -r origin_username;
|
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."
|
warning "Verification is not possible. No checksum is defined."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Preparing mount paths..."
|
make_mount_folders
|
||||||
boot_mount_path="$working_folder""boot/"
|
|
||||||
root_mount_path="$working_folder""root/"
|
|
||||||
mkdir -v "$boot_mount_path"
|
|
||||||
mkdir -v "$root_mount_path"
|
|
||||||
|
|
||||||
set_partition_paths
|
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
|
question "Should the image be transfered to $device_path?(y/n)" && read -r transfer_image
|
||||||
if [ "$transfer_image" = "y" ]
|
if [ "$transfer_image" = "y" ]
|
||||||
then
|
then
|
||||||
@ -263,16 +248,8 @@ if [ -f "$origin_user_rsa_pub" ]
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
info "Start chroot procedures..."
|
info "Start chroot procedures..."
|
||||||
info "Mount chroot environments..."
|
|
||||||
chroot_sys_mount_path="$root_mount_path""sys/"
|
mount_binds
|
||||||
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."
|
|
||||||
|
|
||||||
sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload"
|
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."
|
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."
|
||||||
|
Loading…
Reference in New Issue
Block a user