From a248b3721b735df07f8b7f11c34530ed5647ea6d Mon Sep 17 00:00:00 2001 From: lulzette Date: Thu, 14 Jan 2021 12:53:10 +0300 Subject: [PATCH 01/10] fix syntax error at "get swap size" --- restore.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restore.sh b/restore.sh index a7e1b4c..a7550ef 100644 --- a/restore.sh +++ b/restore.sh @@ -54,7 +54,7 @@ done #get swap size swapSize=$(free -m | grep "Mem" | awk '{print $2}') read -p "Enter extra amount of swap (empty == 512):" swapExtra -if [ -z "$swapExtra" ] && swapExtra=512 +[[ -z "$swapExtra" ]] && swapExtra=512 let "swapSize += swapExtra" #add 512 mbs to swap for swap, not only hibernation swapSize=$swapSize"M" -- 2.34.1 From 9d369e8b0d79fe10a76380f3323f8de5bf25f816 Mon Sep 17 00:00:00 2001 From: lulzette Date: Thu, 14 Jan 2021 12:55:00 +0300 Subject: [PATCH 02/10] readme --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c796e18..c7e13b4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,4 @@ -# This is... +# Что это? -Script that can install OS from previously rsynced backup on NAS +Это скрипт, который восстанавливает систему из бекапа, расположенного на rsync сервере, оптимизирован под ArchLinux -# TODO - -* some checks -* config file support -- 2.34.1 From fb856ac8d562bbd33561fc67dc5526e90263d548 Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 11:49:44 +0300 Subject: [PATCH 03/10] changed location --- restore.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/restore.sh b/restore.sh index a7550ef..e790a34 100644 --- a/restore.sh +++ b/restore.sh @@ -1,8 +1,8 @@ #not working encrypted setup #vars -IP="192.168.100.16" -source="rsync@"$IP"/rsync/" +IP="192.168.100.100" +source="rsync@"$IP"/mnt/" bootSize=256M #prepare @@ -187,4 +187,4 @@ echo "==> Syncing..." sync echo "==> Unmounting..." umount -R /mnt -echo "==> Done!" \ No newline at end of file +echo "==> Done!" -- 2.34.1 From 3d8327112d4325c1f397b18b71338e1cfad4ec5b Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 13:41:30 +0300 Subject: [PATCH 04/10] fix "encrypted" question --- restore.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/restore.sh b/restore.sh index e790a34..59febdf 100644 --- a/restore.sh +++ b/restore.sh @@ -42,8 +42,8 @@ do read -p "Target drive is " targetDrive targetDrive=/dev/$targetDrive done -echo "Encrypted?" -while read -r -n 1 -s answer ; do +echo "Encrypted? (Y/n) " +while read -r -n 1 answer ; do if [[ $answer = [YyNn] ]]; then [[ $answer = [Yy] ]] && encryptedDevice=true && echo "WARNING You will be asked for password later" #read -p "Password: " encryptedPassword [[ $answer = [Nn] ]] && encryptedDevice=false -- 2.34.1 From 70b0087b895a2d14afcc7e3e8fdb241d7c84354b Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 13:45:30 +0300 Subject: [PATCH 05/10] backup selector changed --- restore.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/restore.sh b/restore.sh index 59febdf..a4239d1 100644 --- a/restore.sh +++ b/restore.sh @@ -26,13 +26,15 @@ rsync_dir_list=($(rsync --password-file=rsync_pass rsync://$source | awk '{print ##choose backup echo "==>" ${#rsync_dir_list[@]} backups: ${rsync_dir_list[@]} -read -p "Input backup number:" backupNum +read -p "Input backup name:" backupName -until [ $backupNum -le ${#rsync_dir_list[@]} ] -do -read -p "Input backup number:" backupNum -done -let "backupNum -= 1" +echo "Selected: " $backupName + +#until [ $backupNum -le ${#rsync_dir_list[@]} ] +#do +#read -p "Input backup name:" backupName +#done +#let "backupNum -= 1" ##set target drive @@ -138,7 +140,8 @@ mount $targetDrive"2" /mnt/boot ##rsync echo "==> Copying from NAS..." -rsync --archive --password-file=rsync_pass rsync://$source${rsync_dir_list[$backupNum]}/ /mnt/ +#rsync --archive --password-file=rsync_pass rsync://$source${rsync_dir_list[$backupNum]}/ /mnt/ +rsync --archive --password-file=rsync_pass rsync://$source$backupName/ /mnt/ retVal=$? if [ $retVal -ne 0 ]; then exit 1 -- 2.34.1 From b571133f3fd6638a62a7e021193e0ba10508cba0 Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 13:47:29 +0300 Subject: [PATCH 06/10] fix swap selector --- restore.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/restore.sh b/restore.sh index a4239d1..48d2451 100644 --- a/restore.sh +++ b/restore.sh @@ -55,6 +55,7 @@ done #get swap size swapSize=$(free -m | grep "Mem" | awk '{print $2}') +echo "" read -p "Enter extra amount of swap (empty == 512):" swapExtra [[ -z "$swapExtra" ]] && swapExtra=512 let "swapSize += swapExtra" #add 512 mbs to swap for swap, not only hibernation -- 2.34.1 From 55514aca5bf53f2e1d9ae7d62de79f7d1b73bcdd Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 14:03:29 +0300 Subject: [PATCH 07/10] fix error, fix msgs --- restore.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/restore.sh b/restore.sh index 48d2451..c3c1be0 100644 --- a/restore.sh +++ b/restore.sh @@ -101,19 +101,18 @@ echo w ##mkfs's echo "==> Making filesystems..." -echo "mkswap" +echo "=> swap" mkswap $targetDrive"1" -echo "mkfs.vfat" +echo "=> /boot" mkfs.vfat $targetDrive"2" -echo "mkfs.ext4" -if $encryptedDevice -then +echo "=> rootfs" +if $encryptedDevice then cryptsetup luksFormat -v $targetDrive"3" cryptsetup open $targetDrive"3" targetLuks -mkfs.ext4 /dev/mapper/targetLuks +mkfs.ext4 -q /dev/mapper/targetLuks else -mkfs.ext4 $targetDrive"3" +mkfs.ext4 -q $targetDrive"3" fi sleep 15 @@ -121,16 +120,14 @@ sleep 15 ##get disk's uuid echo "==> Got UUIDs!" UUIDS=($(blkid $targetDrive"1" $targetDrive"2" $targetDrive"3" -o value -s UUID)) -if $encryptedDevice -then +if $encryptedDevice then UUIDS[3]=UUIDS[2] UUIDS[2]=`blkid /dev/mapper/targetLuks -o value -s UUID` fi ##mount disks echo "==> Mounting..." -if $encryptedDevice -then +if $encryptedDevice then mount /dev/mapper/targetLuks /mnt else mount $targetDrive"3" /mnt @@ -159,10 +156,10 @@ rm /mnt/etc/fstab.orig #TODO OFC we need to check mountpoint, not only type of F echo "==> Result:" cat /mnt/etc/fstab ##update grub linux options -if $encryptedDevice -cat /mnt/etc/default/grub | sed 's/cryptdevice=UUID=[A-Fa-f0-9-]*:cryptroot /cryptdevice=UUID='${UUIDS[3]}':cryptroot/' > /mnt/etc/default/grub +if $encryptedDevice then + cat /mnt/etc/default/grub | sed 's/cryptdevice=UUID=[A-Fa-f0-9-]*:cryptroot /cryptdevice=UUID='${UUIDS[3]}':cryptroot/' > /mnt/etc/default/grub else -cat /mnt/etc/default/grub | sed 's/cryptdevice=UUID=[A-Fa-f0-9-]*:cryptroot //' > /mnt/etc/default/grub + cat /mnt/etc/default/grub | sed 's/cryptdevice=UUID=[A-Fa-f0-9-]*:cryptroot //' > /mnt/etc/default/grub fi cat /mnt/etc/default/grub | sed 's/resume=UUID=[A-Fa-f0-9-]*/resume=UUID='${UUIDS[0]}'/' > /mnt/etc/default/grub -- 2.34.1 From 31649a6948b48d6e38c07cbfad835495b0669743 Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 17:56:08 +0300 Subject: [PATCH 08/10] i'm too stupid for bash... --- restore.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/restore.sh b/restore.sh index c3c1be0..3609788 100644 --- a/restore.sh +++ b/restore.sh @@ -107,7 +107,7 @@ echo "=> /boot" mkfs.vfat $targetDrive"2" echo "=> rootfs" -if $encryptedDevice then +if $encryptedDevice ; then cryptsetup luksFormat -v $targetDrive"3" cryptsetup open $targetDrive"3" targetLuks mkfs.ext4 -q /dev/mapper/targetLuks @@ -120,14 +120,14 @@ sleep 15 ##get disk's uuid echo "==> Got UUIDs!" UUIDS=($(blkid $targetDrive"1" $targetDrive"2" $targetDrive"3" -o value -s UUID)) -if $encryptedDevice then +if $encryptedDevice ; then UUIDS[3]=UUIDS[2] UUIDS[2]=`blkid /dev/mapper/targetLuks -o value -s UUID` fi ##mount disks echo "==> Mounting..." -if $encryptedDevice then +if $encryptedDevice ; then mount /dev/mapper/targetLuks /mnt else mount $targetDrive"3" /mnt @@ -156,7 +156,7 @@ rm /mnt/etc/fstab.orig #TODO OFC we need to check mountpoint, not only type of F echo "==> Result:" cat /mnt/etc/fstab ##update grub linux options -if $encryptedDevice then +if $encryptedDevice ; then cat /mnt/etc/default/grub | sed 's/cryptdevice=UUID=[A-Fa-f0-9-]*:cryptroot /cryptdevice=UUID='${UUIDS[3]}':cryptroot/' > /mnt/etc/default/grub else cat /mnt/etc/default/grub | sed 's/cryptdevice=UUID=[A-Fa-f0-9-]*:cryptroot //' > /mnt/etc/default/grub -- 2.34.1 From 4a08cb45d4ee2f5aedc3515751fcb50c3039fa27 Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 18:52:30 +0300 Subject: [PATCH 09/10] fix chroot+fix question encrypted --- restore.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/restore.sh b/restore.sh index 3609788..5846c02 100644 --- a/restore.sh +++ b/restore.sh @@ -44,8 +44,8 @@ do read -p "Target drive is " targetDrive targetDrive=/dev/$targetDrive done -echo "Encrypted? (Y/n) " -while read -r -n 1 answer ; do +#encrypted? +while read -r -n 1 answer -p "Encrypted? (Y/N)" ; do if [[ $answer = [YyNn] ]]; then [[ $answer = [Yy] ]] && encryptedDevice=true && echo "WARNING You will be asked for password later" #read -p "Password: " encryptedPassword [[ $answer = [Nn] ]] && encryptedDevice=false @@ -176,7 +176,7 @@ echo "==> mkinitcpio and update grub..." #cat /mnt/etc/mkinitcpio.conf | sed 's/encrypt //' > /mnt/etc/mkinitcpio.conf #remove cryptdevice, no encrypted fs today :c #chroot env -cat << EOF | chroot /mnt +cat << EOF | chroot /mnt /bin/sh mkinitcpio -P grub-mkconfig -o /boot/grub/grub.cfg grub-install $targetDrive -- 2.34.1 From 3111605ce154650c5338ba414b43df61f8207e25 Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 24 Jan 2021 19:19:08 +0300 Subject: [PATCH 10/10] fix question --- restore.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/restore.sh b/restore.sh index 5846c02..deff217 100644 --- a/restore.sh +++ b/restore.sh @@ -45,7 +45,8 @@ read -p "Target drive is " targetDrive targetDrive=/dev/$targetDrive done #encrypted? -while read -r -n 1 answer -p "Encrypted? (Y/N)" ; do +echo "Encrypted? (Y/N)" +while read -r -n 1 answer ; do if [[ $answer = [YyNn] ]]; then [[ $answer = [Yy] ]] && encryptedDevice=true && echo "WARNING You will be asked for password later" #read -p "Password: " encryptedPassword [[ $answer = [Nn] ]] && encryptedDevice=false -- 2.34.1