From 456d5bf593078b74de9167c86bb51849e470431c Mon Sep 17 00:00:00 2001 From: admin666 Date: Tue, 20 Aug 2024 11:02:03 +0000 Subject: [PATCH] setup.sh: enhance waiting, error detection and correct initial packages --- setup.sh | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/setup.sh b/setup.sh index 62cf1d0..c390412 100755 --- a/setup.sh +++ b/setup.sh @@ -28,33 +28,42 @@ then fi echo "Starting vm..." -virsh start ${vm} +virsh start ${vm} || (echo -e "\e[1m\e[31mFail to start...(perhaps already done?)\e[0m") +sleep 5 echo "Waiting for ${vm} to boot..." -sudo -u admin666 ssh -o ConnectTimeout=60 ${vm} "echo Connected!" +sudo -u admin666 ssh -4 -o ConnectTimeout=60 ${vm} "echo Connected!" || (echo -e "\e[1m\e[31mFail to wait...\e[0m" ; exit 1) echo "Setting up hostname..." -sudo -u admin666 ssh -4 ${vm} "sudo hostnamectl set-hostname ${vm}" +sudo -u admin666 ssh -4 ${vm} "sudo hostnamectl set-hostname ${vm}" || (echo -e "\e[1m\e[31mFail to set up...\e[0m" ; exit 1) echo "Reloading postfix configuration..." -sudo -u admin666 ssh -4 ${vm} "sudo postmap /etc/postfix/virtual" +sudo -u admin666 ssh -4 ${vm} "sudo postmap /etc/postfix/virtual" || (echo -e "\e[1m\e[31mFail to reload...\e[0m" ; exit 1) -echo "Reloading postfix..." -sudo -u admin666 ssh -4 ${vm} "sudo postfix reload" +#echo "Reloading postfix..." +#sudo -u admin666 ssh -4 ${vm} "sudo postfix reload" || (echo -e "\e[1m\e[31mFail to reload ($?)...\e[0m" ; exit 1) echo "Rebooting..." -sudo -u admin666 ssh -4 ${vm} "sudo reboot" +sudo -u admin666 ssh -4 ${vm} "sudo reboot" || echo "(rebooted quickly)" +sleep 5 echo "Waiting for ${vm} to boot..." -sudo -u admin666 ssh -o ConnectTimeout=60 ${vm} "echo Connected!" +sudo -u admin666 ssh -4 -o ConnectTimeout=60 ${vm} "echo Connected!" || (echo -e "\e[1m\e[31mFail to wait...\e[0m" ; exit 1) echo "Updating packages..." -sudo -u admin666 ssh -4 ${vm} "sudo apt-get update" -sudo -u admin666 ssh -4 ${vm} 'sudo apt-get full-upgrade -y -o Dpkg::Options::="--force-confdef"' -sudo -u admin666 ssh -4 ${vm} "sudo apt-get autoremove -y" +sudo -u admin666 ssh -4 ${vm} "sudo apt-get update" || (echo -e "\e[1m\e[31mFail to update...\e[0m" ; exit 1) +sudo -u admin666 ssh -4 ${vm} 'sudo DEBIAN_FRONTEND=noninteractive apt-get full-upgrade -y -o Dpkg::Options::="--force-confdef"' || (echo -e "\e[1m\e[31mFail to upgrade...\e[0m" ; exit 1) +sudo -u admin666 ssh -4 ${vm} "sudo apt-get autoremove -y" || (echo -e "\e[1m\e[31mFail to remove...\e[0m" ; exit 1) + +echo "Rebooting..." +sudo -u admin666 ssh -4 ${vm} "sudo reboot" || echo "(rebooted quickly)" +sleep 5 + +echo "Waiting for ${vm} to boot..." +sudo -u admin666 ssh -4 -o ConnectTimeout=60 ${vm} "echo Connected!" || (echo -e "\e[1m\e[31mFail to wait...\e[0m" ; exit 1) echo "Installing base packages..." -sudo -u admin666 ssh -4 ${vm} "sudo apt-get install -y etckeeper molly-guard tig lm-sensors fancontrol screen emacs-nox vrms needrestart iotop htop curl ncdu iptraf tig unzip" +sudo -u admin666 ssh -4 ${vm} "sudo apt-get install -y etckeeper molly-guard tig lm-sensors fancontrol screen emacs-nox needrestart iotop htop curl ncdu iptraf tig unzip" || (echo -e "\e[1m\e[31mFail to install...\e[0m" ; exit 1) echo -e "\e[36m${vm} successfully set up\e[0m" exit 0