2021-04-07 22:20:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-04-08 00:27:47 +02:00
|
|
|
# This script will create and fire up a standard debian buster lxc container on your Proxmox VE.
|
|
|
|
# On a Proxmox cluster, the script will create the container on the local node, where it's executed.
|
|
|
|
# The container ID will be automatically assigned by increasing (+1) the highest number of
|
|
|
|
# existing LXC containers in your environment. If the assigned ID is already taken by a VM
|
|
|
|
# or no containers exist yet, the script falls back to the ID 100.
|
2021-04-07 22:20:10 +02:00
|
|
|
|
2021-04-08 00:27:47 +02:00
|
|
|
# Authors:
|
|
|
|
# (C) 2021 Idea an concept by Christian Zengel <christian@sysops.de>
|
|
|
|
# (C) 2021 Script design and prototype by Markus Helmke <helmke@cloudistboese.de>
|
2021-04-09 18:10:07 +02:00
|
|
|
# (C) 2021 Script rework and documentation by Thorsten Spille <thorsten@spille-edv.de>
|
2021-04-07 22:20:10 +02:00
|
|
|
|
2021-04-08 18:59:26 +02:00
|
|
|
# IMPORTANT NOTE:
|
|
|
|
# Please adjust th settings in 'zamba.conf' to your needs before running the script
|
2021-04-07 22:20:10 +02:00
|
|
|
|
2021-04-08 18:59:26 +02:00
|
|
|
############### ZAMBA INSTALL SCRIPT ###############
|
2021-04-07 22:20:10 +02:00
|
|
|
|
2021-04-08 18:59:26 +02:00
|
|
|
# Load configuration file
|
|
|
|
source ./zamba.conf
|
2021-04-07 22:20:10 +02:00
|
|
|
|
|
|
|
# CHeck is the newest template available, else download it.
|
2021-04-08 00:27:47 +02:00
|
|
|
DEB_LOC=$(pveam list $LXC_TEMPLATE_STORAGE | grep debian-10-standard | cut -d'_' -f2)
|
2021-04-07 22:20:10 +02:00
|
|
|
DEB_REP=$(pveam available --section system | grep debian-10-standard | cut -d'_' -f2)
|
|
|
|
|
|
|
|
if [[ $DEB_LOC == $DEB_REP ]];
|
|
|
|
then
|
|
|
|
echo "Newest Version of Debian 10 Standard $DEP_REP exists.";
|
|
|
|
else
|
|
|
|
echo "Will now download newest Debian 10 Standard $DEP_REP.";
|
2021-04-08 00:27:47 +02:00
|
|
|
pveam download $LXC_TEMPLATE_STORAGE debian-10-standard_$DEB_REP\_amd64.tar.gz
|
2021-04-07 22:20:10 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Get next free LXC-number
|
|
|
|
LXC_LST=$( lxc-ls | egrep -o '.{1,5}$' )
|
|
|
|
LXC_CHK=$((LXC_LST+1));
|
|
|
|
|
|
|
|
if [ $LXC_CHK -lt 100 ] || [ -f /etc/pve/qemu-server/$LXC_CHK.conf ]; then
|
|
|
|
LXC_NBR=$(pvesh get /cluster/nextid);
|
|
|
|
else
|
|
|
|
LXC_NBR=$LXC_CHK;
|
|
|
|
fi
|
|
|
|
echo "Will now create LXC Container $LXC_NBR!";
|
|
|
|
|
|
|
|
# Create the container
|
2021-04-08 00:27:47 +02:00
|
|
|
pct create $LXC_NBR -unprivileged $LXC_UNPRIVILEGED $LXC_TEMPLATE_STORAGE:vztmpl/debian-10-standard_$DEB_REP\_amd64.tar.gz -rootfs $LXC_ROOTFS_STORAGE:$LXC_ROOTFS_SIZE;
|
2021-04-07 22:20:10 +02:00
|
|
|
sleep 2;
|
|
|
|
|
2021-04-08 20:34:40 +02:00
|
|
|
# Check vlan configuration
|
2021-04-08 00:27:47 +02:00
|
|
|
if [[ $LXC_VLAN != "" ]];then
|
2021-04-11 23:36:16 +02:00
|
|
|
VLAN=",tag=$LXC_VLAN"
|
2021-04-08 00:27:47 +02:00
|
|
|
else
|
|
|
|
VLAN=""
|
|
|
|
fi
|
2021-04-08 20:34:40 +02:00
|
|
|
# Reconfigure conatiner
|
2021-04-08 00:27:47 +02:00
|
|
|
pct set $LXC_NBR -memory $LXC_MEM -swap $LXC_SWAP -hostname $LXC_HOSTNAME \-nameserver $LXC_DNS -searchdomain $LXC_DOMAIN -onboot 1 -timezone Europe/Berlin -net0 name=eth0,bridge=$LXC_BRIDGE,firewall=1,gw=$LXC_GW,ip=$LXC_IP,type=veth$VLAN;
|
2021-04-07 22:20:10 +02:00
|
|
|
sleep 2;
|
|
|
|
|
|
|
|
PS3="Select the Server-Function: "
|
|
|
|
|
|
|
|
select opt in just_lxc zmb-standalone zmb-member zmb-pdc mailpiler matrix quit; do
|
|
|
|
case $opt in
|
|
|
|
just_lxc)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Debian-only LXC container selected"
|
2021-04-07 22:20:10 +02:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
zmb-standalone)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Selected Zamba standalone"
|
|
|
|
echo "This function is not implemented yet! Exiting..."
|
2021-04-09 16:39:51 +02:00
|
|
|
# TODO: write script for Zamba Standalone
|
2021-04-08 20:34:40 +02:00
|
|
|
exit 1
|
2021-04-07 22:20:10 +02:00
|
|
|
;;
|
|
|
|
zmb-member)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Configuring LXC container '$opt'!"
|
2021-04-09 16:42:27 +02:00
|
|
|
pct set $LXC_NBR -mp0 $LXC_SHAREFS_STORAGE:$LXC_SHAREFS_SIZE,mp=/$LXC_SHAREFS_MOUNTPOINT
|
2021-04-07 22:20:10 +02:00
|
|
|
sleep 2;
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
zmb-pdc)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Selected Zamba AD DC"
|
2021-04-09 16:39:51 +02:00
|
|
|
# TODO: write script for Zamba AD DC
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "This function is not implemented yet! Exiting..."
|
|
|
|
exit 1
|
2021-04-07 22:20:10 +02:00
|
|
|
;;
|
|
|
|
mailpiler)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Configuring LXC container for '$opt'!"
|
2021-04-07 22:20:10 +02:00
|
|
|
pct set $LXC_NBR -features nesting=1
|
|
|
|
sleep 2;
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
matrix)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Install Matrix chat server and element web service"
|
2021-04-07 22:20:10 +02:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
quit)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Script aborted by user interaction."
|
|
|
|
exit 0
|
2021-04-07 22:20:10 +02:00
|
|
|
;;
|
|
|
|
*)
|
2021-04-08 20:34:40 +02:00
|
|
|
echo "Invalid option! Exiting..."
|
|
|
|
exit 1
|
2021-04-07 22:20:10 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-04-08 20:34:40 +02:00
|
|
|
|
|
|
|
lxc-start $LXC_NBR;
|
|
|
|
sleep 5;
|
|
|
|
# Set the root password and key
|
|
|
|
echo -e "$LXC_PWD\n$LXC_PWD" | lxc-attach -n$LXC_NBR passwd;
|
|
|
|
lxc-attach -n$LXC_NBR mkdir /root/.ssh;
|
|
|
|
echo -e "$LXC_AUTHORIZED_KEY" | lxc-attach -n$LXC_NBR tee /root/.ssh/authorized_keys;
|
|
|
|
# usually not needed after adding authorized_keys:
|
|
|
|
# lxc-attach -n$LXC_NBR systemctl restart ssh.service
|
|
|
|
pct push $LXC_NBR ./zamba.conf /root/zamba.conf
|
|
|
|
pct push $LXC_NBR ./$opt.sh /root/$opt.sh
|
|
|
|
echo "Install '$opt'!"
|
|
|
|
lxc-attach -n$LXC_NBR bash /root/$opt.sh
|