diff --git a/.includes/convert-to-server.sh b/.includes/convert-to-server.sh index b7e4693..fe246a7 100755 --- a/.includes/convert-to-server.sh +++ b/.includes/convert-to-server.sh @@ -12,10 +12,17 @@ dialog --backtitle "Configure Stormux" \ exit 1 fi +sudoFlags=("${sudoFlags[@]}") dialog --backtitle "Configure Stormux" \ --yesno "This will make catastrophic changes to your system. If you are not sure you want to do this, select no by pressing the letter n on your keyboard. Afterwards, you will only be able to login with an ssh key and there will be no screen reader.\nNote, configure-stormux will no longer be available." -1 -1 --stdout || exit 0 +if [[ -e /opt/configure-server ]]; then + dialog --backtitle "Configure Stormux" \ + --msgbox "/opt/configure-server already exists. Conversion has been cancelled because the system is no longer in a clean enough state for this process." -1 -1 --stdout + exit 1 +fi + dialog --backtitle "Configure Stormux" \ --msgbox "Now let's upload your ssh key. It is a good idea to go ahead and connect via ssh now, in case something goes wrong you will have a chance to fix it manually. This will be used to login to your server, so whatever you do, don't lose it. If you have not yet created an ssh key, you can do so with the ssh-keygen command. Magic-wormhole can be used to upload the key. If you are doing this from a Windows based ssh session, you can install magic-wormhole with scoop: https://github.com/ScoopInstaller/Scoop" -1 -1 --stdout mkdir -p ~/.ssh @@ -34,8 +41,8 @@ if [[ -n "$sshPortInput" && "$sshPortInput" =~ ^[0-9]+$ ]]; then sshPort="$sshPortInput" fi fi -sudo mkdir -p /etc/ssh/sshd_config.d -sudo tee /etc/ssh/sshd_config.d/99-stormux-server.conf > /dev/null << EOF +sudo "${sudoFlags[@]}" mkdir -p /etc/ssh/sshd_config.d +sudo "${sudoFlags[@]}" tee /etc/ssh/sshd_config.d/99-stormux-server.conf > /dev/null << EOF Port ${sshPort} PermitRootLogin no PasswordAuthentication no @@ -73,7 +80,7 @@ for packageName in \ wireplumber \ xdg-user-dirs \ xdg-utils ; do - yay -Runcds --noconfirm "$packageName" @> /dev/null + yay -Runcds --noconfirm "$packageName" &> /dev/null done rm -rfv ~/.config @@ -82,12 +89,33 @@ rm -rfv ~/Desktop rm -rfv ~/Downloads rm -rfv ~/Music rm -rfv ~/Pictures -rm -rfv ~/Public rm -rfv ~/Templates rm -rfv ~/Videos -sudo rm -rf /opt/configure-stormux -sudo rm -fv /local/bin/configure-stormux +sudo "${sudoFlags[@]}" rm -rf /opt/configure-stormux +sudo "${sudoFlags[@]}" rm -fv /usr/local/bin/configure-stormux + +if ! sudo "${sudoFlags[@]}" git clone https://git.stormux.org/storm/configure-server /opt/configure-server; then + dialog --backtitle "Configure Stormux" \ + --msgbox "The system conversion completed, but cloning configure-server into /opt failed. Please fix that before rebooting." -1 -1 --stdout + exit 1 +fi + +if ! sudo "${sudoFlags[@]}" tee /usr/local/bin/configure-server > /dev/null << 'EOF' +#!/usr/bin/env bash +exec /opt/configure-server/configure-server.sh "$@" +EOF +then + dialog --backtitle "Configure Stormux" \ + --msgbox "configure-server was cloned, but creating /usr/local/bin/configure-server failed. Please fix that before rebooting." -1 -1 --stdout + exit 1 +fi + +if ! sudo "${sudoFlags[@]}" chmod 755 /usr/local/bin/configure-server; then + dialog --backtitle "Configure Stormux" \ + --msgbox "configure-server was cloned, but setting executable permissions on /usr/local/bin/configure-server failed. Please fix that before rebooting." -1 -1 --stdout + exit 1 +fi dialog --backtitle "Configure Stormux" \ - --msgbox "Hopefully everything went well and your server is ready to go, if not, see you on the other side of the reimage. Reboot for changes to ssh to be applied." -1 -1 --stdout + --msgbox "Hopefully everything went well and your server is ready to go. Reboot for the SSH changes to be applied. Afterwards, you can run configure-server with /usr/local/bin/configure-server." -1 -1 --stdout exit 0