From f562bae1ba83ec1d5e13731073e41145c79b053e Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Wed, 5 Jan 2022 16:45:14 -0300 Subject: [PATCH] Add generic loadVar() and saveVar() --- all.txt | 2 ++ install.sh | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 all.txt diff --git a/all.txt b/all.txt new file mode 100644 index 0000000..5f4c9c7 --- /dev/null +++ b/all.txt @@ -0,0 +1,2 @@ +username=marianito +bootPath=boot/efi diff --git a/install.sh b/install.sh index c5f827b..f9e45ce 100755 --- a/install.sh +++ b/install.sh @@ -185,12 +185,14 @@ mountPart() { fi mount "$bootPart" "/mnt/$bootPath" 2>&1 | debug else - mkdir -p /mnt/boot/efi - mount "$bootPart" /mnt/boot/efi 2>&1 | debug + bootPath="boot/efi" + mkdir -p /mnt/$bootPath + mount "$bootPart" /mnt/$bootPath 2>&1 | debug fi printWaitBox [ -n "$swapPart" ] && swapon "$swapPart" 2>&1 | debug [ -n "$swapfile" ] && createSwapfile + saveVar "bootPath" "/$bootPath" } debug() { @@ -394,21 +396,32 @@ updateMirrors() { } grubSetUp() { - # TODO: Prompt user for efi-directory printWaitBox - runInChroot "grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB; grub-mkconfig -o /boot/grub/grub.cfg" 2>&1 | debug + [ -z $bootPath ] && loadVar "bootPath" + runInChroot "grub-install --target=x86_64-efi --efi-directory=${bootPath} --bootloader-id=GRUB; grub-mkconfig -o /boot/grub/grub.cfg" 2>&1 | debug } -saveUsername() { - echo $username > CocoASAIS.vars +saveVar() { + [ ! -f "CocoASAIS.vars" ] && touch CocoASAIS.vars + if [ -z "$(grep "$1" CocoASAIS.vars)" ]; then + echo "$1=$2" >> CocoASAIS.vars + else + sed -i "s|$1=.*|$1=$2|" CocoASAIS.vars + fi } -loadUsername() { - username=$(cat CocoASAIS.vars) +loadVar() { + var=$(grep "$1=" CocoASAIS.vars | cut -d= -f2) + if [ -z $var ]; then + echo "Couldn't load '$1'. Try to run the script again." 1>&2 + rm -f CocoASAIS.log CocoASAIS.vars + exit 1 + fi + export $1=$var } userSetUp() { - username=$(whiptail --inputbox "Enter the new username." 0 0 3>&1 1>&2 2>&3) && saveUsername + username=$(whiptail --inputbox "Enter the new username." 0 0 3>&1 1>&2 2>&3) && saveVar "username" "$username" exitIfCancel "You must enter an username." "userSetUp" askForPassword "${username}" "userSetUp" runInChroot "useradd -m ${username};echo \"${username}:${password}\" | chpasswd; sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers; usermod -aG wheel ${username}" @@ -426,7 +439,7 @@ EOF installOtherPackages() { calcHeightAndRun "whiptail --msgbox \"Now, we will install a few more packages (in the background). Press OK and wait (it may take some time).\" HEIGHT 60 3>&1 1>&2 2>&3" - [ -z $username ] && loadUsername + [ -z $username ] && loadVar "username" getThePackages "S" "installOtherPackages" checkForParu getThePackages "N" "installOtherPackages" @@ -437,7 +450,7 @@ installOtherPackages() { finishInstallation() { cp CocoASAIS /mnt/usr/bin/CocoASAIS echo "sh /usr/bin/CocoASAIS && logout" >> /mnt/home/slococo/.bashrc - rm /mnt/cocoScript + rm -f /mnt/cocoScript umount -R /mnt whiptail --yesno "Finally, the PC needs to restart, would you like to restart now?" 0 0 if [ $? -eq 0 ]; then @@ -486,6 +499,10 @@ checkForSystemdUnit() { trap - INT } +# createVarsFile() { +# echo "" +# } + steps=( checkUefi updateSystemClock @@ -548,6 +565,7 @@ runScript() { fi whiptail --title "CocoASAIS" --msgbox "${welcomeMsg}" 0 0 + createVarsFile while [ $i -le "${#steps[@]}" ]; do ${steps[$i]}