2024-08-20 12:10:44 +02:00
|
|
|
#!/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..."
|
2024-08-20 12:23:45 +02:00
|
|
|
sudo -u admin666 ssh -o ConnectTimeout=60 ${vm} "echo Connected!"
|
2024-08-20 12:10:44 +02:00
|
|
|
|
|
|
|
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..."
|
2024-08-20 12:23:45 +02:00
|
|
|
sudo -u admin666 ssh -o ConnectTimeout=60 ${vm} "echo Connected!"
|
2024-08-20 12:10:44 +02:00
|
|
|
|
|
|
|
echo "Updating packages..."
|
2024-08-20 12:12:00 +02:00
|
|
|
sudo -u admin666 ssh -4 ${vm} "sudo apt-get update"
|
2024-08-20 12:23:45 +02:00
|
|
|
sudo -u admin666 ssh -4 ${vm} 'sudo apt-get full-upgrade -y -o Dpkg::Options::="--force-confdef"'
|
2024-08-20 12:12:00 +02:00
|
|
|
sudo -u admin666 ssh -4 ${vm} "sudo apt-get autoremove -y"
|
2024-08-20 12:10:44 +02:00
|
|
|
|
|
|
|
echo "Installing base packages..."
|
2024-08-20 12:12:00 +02:00
|
|
|
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"
|
2024-08-20 12:10:44 +02:00
|
|
|
|
|
|
|
echo -e "\e[36m${vm} successfully set up\e[0m"
|
|
|
|
exit 0
|