infra-generale/setup.sh

61 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# Script to create a virtual machine
#
# Copyright (C) 2024 Adrien 'neox' Bourmault <neox@a-lec.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Exit on error
set -e
#set -v
vm=$1
if [[ $# < 1 ]]
then
echo "ERROR: 1 parameter required : vm domain"
exit 1
fi
echo "Starting vm..."
virsh start ${vm}
echo "Waiting for ${vm} to boot..."
sudo -u admin666 ssh -o ConnectTimeout=60 ${vm} "echo Connected!"
echo "Setting up hostname..."
sudo -u admin666 ssh -4 ${vm} "sudo hostnamectl set-hostname ${vm}"
echo "Reloading postfix configuration..."
sudo -u admin666 ssh -4 ${vm} "sudo postmap /etc/postfix/virtual"
echo "Reloading postfix..."
sudo -u admin666 ssh -4 ${vm} "sudo postfix reload"
echo "Rebooting..."
sudo -u admin666 ssh -4 ${vm} "sudo reboot"
echo "Waiting for ${vm} to boot..."
sudo -u admin666 ssh -o ConnectTimeout=60 ${vm} "echo Connected!"
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"
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"
echo -e "\e[36m${vm} successfully set up\e[0m"
exit 0