61 lines
1.8 KiB
Bash
61 lines
1.8 KiB
Bash
|
#!/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..."
|
||
|
sleep 20
|
||
|
|
||
|
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..."
|
||
|
sleep 20
|
||
|
|
||
|
echo "Updating packages..."
|
||
|
sudo -u admin666 ssh -4 ${vm} "sudo apt update"
|
||
|
sudo -u admin666 ssh -4 ${vm} 'sudo apt full-upgrade -y -o Dpkg::Options::="--force-confold"'
|
||
|
sudo -u admin666 ssh -4 ${vm} "sudo apt autoremove -y"
|
||
|
|
||
|
echo "Installing base packages..."
|
||
|
sudo -u admin666 ssh -4 ${vm} "sudo apt 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
|