Bash installatiescript
#!/bin/bash
set -e
# =========================
# CONFIGURATIE
# =========================
HOSTNAME="<HOSTNAAM>"
IP_ADDRESS="<IP_ADRES>"
NETMASK="<NETMASK>"
GATEWAY="<GATEWAY>"
DNS1="8.8.8.8"
DNS2="1.1.1.1"
INSTALL_URL="<INSTALLATIE_URL>"
# =========================
# CHECK ROOT
# =========================
if [ "$EUID" -ne 0 ]; then
echo "Voer dit script uit als root of met sudo."
exit 1
fi
echo "Start VPS configuratie..."
# =========================
# SYSTEEM UPDATE
# =========================
apt update
apt upgrade -y
# =========================
# HOSTNAME INSTELLEN
# =========================
echo "$HOSTNAME" > /etc/hostname
hostnamectl set-hostname "$HOSTNAME"
# =========================
# /etc/hosts BIJWERKEN
# =========================
cp /etc/hosts /etc/hosts.backup
cat > /etc/hosts <<EOF
127.0.0.1 localhost
$IP_ADDRESS $HOSTNAME
EOF
# =========================
# NETWERK CONFIGUREREN
# =========================
cp /etc/network/interfaces /etc/network/interfaces.backup
cat > /etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address $IP_ADDRESS
netmask $NETMASK
gateway $GATEWAY
dns-nameservers $DNS1 $DNS2
EOF
# =========================
# INSTALLATIEBESTAND DOWNLOADEN
# =========================
cd /root
wget -O install.sh "$INSTALL_URL"
chmod +x install.sh
# =========================
# INSTALLATIE STARTEN
# =========================
bash install.sh
# =========================
# AFRONDING
# =========================
echo "Installatie afgerond."
echo "Controleer netwerk en hostname na reboot."
read -p "Wil je nu rebooten? ja/nee: " REBOOT
if [ "$REBOOT" = "ja" ]; then
reboot
fi
Opslaan als:
nano install-vps.sh
Uitvoerbaar maken:
chmod +x install-vps.sh
Starten:
sudo ./install-vps.sh