From 49f5bddbea4155819cc6436e19d4a3152f4588b0 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Thu, 21 May 2020 19:22:14 +0200 Subject: [PATCH] Optimized chroot procedures --- README.md | 12 ++++++------ scripts/image/base.sh | 14 +++++++++++++- scripts/image/chroot.sh | 24 ++++-------------------- scripts/image/setup.sh | 14 +++++++++----- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 6d67b99..cfec90c 100644 --- a/README.md +++ b/README.md @@ -84,15 +84,15 @@ To pase the configuration to the program use this syntax: ```bash ( echo "$USER" # | The username - echo "sdX" # | The device - echo "64_bit" # | The architecture type; arm or 64_bit - echo "manjaro" # | The operation system - echo "gnome" # | The version + echo "mmcblk1" # | The device + echo "arm" # | The architecture type; arm or 64_bit + echo "arch" # | The operation system + echo "3" # | The version #echo "n" # ├── If arch: Should a encrypted setup be used? (y/n) echo "n" # | Should the image download be forced?(y/n) - echo "y" # | Should the image be transfered to $device_path?(y/n) + echo "n" # | Should the image be transfered to $device_path?(y/n) echo "n" # ├── Overwrite device before copying? (y/n) - echo "n" # | Should the ssh-key be copied to the image?(y/N) + echo "n" # | Should the password be changed?(y/N) #echo "test12345" # ├── The user password_1 #echo "test12345" # ├── The user password_2 echo "n" # | Should the ssh-key be copied to the image?(y/N) diff --git a/scripts/image/base.sh b/scripts/image/base.sh index f3be809..fede976 100644 --- a/scripts/image/base.sh +++ b/scripts/image/base.sh @@ -50,7 +50,7 @@ mount_partitions(){ error } -mount_binds(){ +mount_chroot_binds(){ info "Mount chroot environments..." && chroot_sys_mount_path="$root_mount_path""sys/" && chroot_proc_mount_path="$root_mount_path""proc/" && @@ -63,3 +63,15 @@ mount_binds(){ mount --bind /dev/pts "$chroot_dev_pts_mount_path" || error } + +copy_qemu(){ + info "Copy qemu binary..." && + cp -v /usr/bin/qemu-arm-static "$root_mount_path""usr/bin/" || + error +} + +copy_resolve_conf(){ + info "Copy resolve.conf..." && + cp -v /etc/resolv.conf "$root_mount_path""etc/" || + warning "Failed. Propably there is no internet connection available." +} diff --git a/scripts/image/chroot.sh b/scripts/image/chroot.sh index 8a4e9ff..f0c83a1 100644 --- a/scripts/image/chroot.sh +++ b/scripts/image/chroot.sh @@ -16,32 +16,16 @@ set_partition_paths mount_partitions -mount_binds +mount_chroot_binds -info "ld.so.preload fix" && -sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" || -warning "Failed." +copy_qemu -info "Copy qemu binary..." && -cp -v /usr/bin/qemu-arm-static "$root_mount_path""usr/bin/" || -error +copy_resolve_conf -info "Copy resolve.conf..." -cp -v /etc/resolv.conf "$root_mount_path""etc/" && -warning "Failed. Propably there is no internet connection available." - -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" && +info "Bash shell starts..." && chroot "$root_mount_path" /bin/bash || error -info "Clean up" && -info "revert ld.so.preload fix" && -sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload" || -warning "Failed." - info "unmount everything" && umount "$root_mount_path"/{dev/pts,dev,sys,proc,boot,} || error diff --git a/scripts/image/setup.sh b/scripts/image/setup.sh index babc033..6cccc9a 100644 --- a/scripts/image/setup.sh +++ b/scripts/image/setup.sh @@ -10,7 +10,6 @@ info "Setupscript for images started..." info "Define functions..." destructor(){ info "Cleaning up..." - sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload" || warning "sed failed." umount -v "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!" umount -v "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!" umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!" @@ -110,9 +109,12 @@ case "$os" in "1") imagename="ArchLinuxARM-rpi-latest.tar.gz" ;; - "2" | "3") + "2") imagename="ArchLinuxARM-rpi-2-latest.tar.gz" ;; + "3") + imagename="ArchLinuxARM-rpi-3-latest.tar.gz" + ;; "4") imagename="ArchLinuxARM-rpi-4-latest.tar.gz" ;; @@ -314,12 +316,14 @@ if [ "$copy_ssh_key" == "y" ] else info "Skipped SSH-key copying.." fi + info "Start chroot procedures..." -mount_binds +mount_chroot_binds -sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" || warning "sed failed." -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." +copy_qemu + +copy_resolve_conf question "Should the image password of the standart user \"$target_username\" be changed?(y/N)" && read -r change_password if [ "$change_password" == "y" ]