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>
|
2021-04-16 16:58:46 +02:00
|
|
|
# (C) 2021 Script design and prototype by Markus Helmke <m.helmke@nettwarker.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-25 18:02:35 +02:00
|
|
|
prog="$(basename "$0")"
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat >&2 <<-EOF
|
|
|
|
usage: $prog [-h] [-i CTID] [-s SERVICE] [-c CFGFILE]
|
|
|
|
installs a preconfigured lxc container on your proxmox server
|
|
|
|
-i CTID provide a container id instead of auto detection
|
|
|
|
-s SERVICE provide the service name and skip the selection dialog
|
|
|
|
-c CFGFILE use a different config file than 'zamba.conf'
|
2021-04-27 20:30:28 +02:00
|
|
|
-h displays this help text
|
2021-04-25 18:02:35 +02:00
|
|
|
---------------------------------------------------------------------------
|
2021-05-03 09:02:16 +02:00
|
|
|
(C) 2021 zamba-lxc-toolbox by bashclub (https://github.com/bashclub)
|
2021-04-25 18:02:35 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
EOF
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
ctid=0
|
|
|
|
service=ask
|
2021-04-27 20:30:28 +02:00
|
|
|
config=$PWD/conf/zamba.conf
|
|
|
|
verbose=0
|
2021-04-25 18:02:35 +02:00
|
|
|
|
|
|
|
while getopts "hi:s:c:" opt; do
|
|
|
|
case $opt in
|
|
|
|
h) usage 0 ;;
|
|
|
|
i) ctid=$OPTARG ;;
|
|
|
|
s) service=$OPTARG ;;
|
|
|
|
c) config=$OPTARG ;;
|
|
|
|
*) usage 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
2021-04-24 00:00:27 +02:00
|
|
|
|
2021-04-08 18:59:26 +02:00
|
|
|
# Load configuration file
|
2021-04-25 18:02:35 +02:00
|
|
|
echo "Loading config file '$config'..."
|
|
|
|
source $config
|
2021-04-24 00:00:27 +02:00
|
|
|
|
2021-08-06 22:00:09 +02:00
|
|
|
# Check config Settings
|
|
|
|
echo "Check Setting 'Timezone'"
|
|
|
|
if [[ $LXC_TIMEZONE != $(timedatectl list-timezones | grep $LXC_TIMEZONE) ]]; then
|
|
|
|
echo "Unknown LXC_TIMEZONE setting (list available Timezones 'timedatectl list-timezones')"; exit 0
|
|
|
|
fi
|
|
|
|
echo "Check Setting 'Template Storage'"
|
|
|
|
pvstorage=$(pvesh get storage --noborder --noheader);
|
|
|
|
if [[ $LXC_TEMPLATE_STORAGE != $(echo "$pvstorage" | grep $LXC_TEMPLATE_STORAGE$) ]]; then
|
|
|
|
echo "Unknown LXC_TEMPLATE_STORAGE, please check your storage name"; exit 0
|
|
|
|
fi
|
|
|
|
echo "Check Setting 'Rootfs Storage'"
|
|
|
|
if [[ $LXC_ROOTFS_STORAGE != $(echo "$pvstorage" | grep $LXC_ROOTFS_STORAGE$) ]]; then
|
|
|
|
echo "Unknown LXC_ROOTFS_STORAGE, please check your storage name"; exit 0
|
|
|
|
fi
|
|
|
|
echo "Check Setting 'Sharefs Storage'"
|
|
|
|
if [[ $LXC_SHAREFS_STORAGE != $(echo "$pvstorage" | grep $LXC_SHAREFS_STORAGE$) ]]; then
|
|
|
|
echo "Unknown LXC_SHAREFS_STORAGE, please check your storage name"; exit 0
|
|
|
|
fi
|
|
|
|
echo -e "Settings \e[0;92mOK\e[0m"
|
|
|
|
|
|
|
|
|
2021-04-24 00:00:27 +02:00
|
|
|
OPTS=$(ls -d $PWD/src/*/ | grep -v __ | xargs basename -a)
|
|
|
|
|
2021-04-27 20:30:28 +02:00
|
|
|
valid=0
|
2021-04-25 18:02:35 +02:00
|
|
|
if [[ "$service" == "ask" ]]; then
|
|
|
|
select svc in $OPTS quit; do
|
|
|
|
if [[ "$svc" != "quit" ]]; then
|
2021-04-27 20:30:28 +02:00
|
|
|
for line in $(echo $OPTS); do
|
2021-04-25 18:02:35 +02:00
|
|
|
if [[ "$svc" == "$line" ]]; then
|
|
|
|
service=$svc
|
|
|
|
echo "Installation of $service selected."
|
2021-04-27 20:30:28 +02:00
|
|
|
valid=1
|
2021-04-25 18:02:35 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2021-04-24 00:00:27 +02:00
|
|
|
else
|
2021-04-25 18:02:35 +02:00
|
|
|
echo "Selected 'quit' exiting without action..."
|
|
|
|
exit 0
|
|
|
|
fi
|
2021-04-27 20:30:28 +02:00
|
|
|
if [[ "$valid" == "1" ]]; then
|
2021-04-25 18:02:35 +02:00
|
|
|
break
|
2021-04-24 00:00:27 +02:00
|
|
|
fi
|
|
|
|
done
|
2021-04-25 18:02:35 +02:00
|
|
|
else
|
2021-04-27 20:30:28 +02:00
|
|
|
for line in $(echo $OPTS); do
|
2021-04-25 18:02:35 +02:00
|
|
|
if [[ "$service" == "$line" ]]; then
|
|
|
|
echo "Installation of $service selected."
|
2021-04-27 20:30:28 +02:00
|
|
|
valid=1
|
2021-04-25 18:02:35 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2021-04-27 20:30:28 +02:00
|
|
|
if [[ "$valid" != "1" ]]; then
|
2021-04-25 18:02:35 +02:00
|
|
|
echo "Invalid option, exiting..."
|
|
|
|
usage 1
|
2021-04-24 00:00:27 +02:00
|
|
|
fi
|
2021-04-17 10:13:49 +02:00
|
|
|
|
2021-08-06 22:00:09 +02:00
|
|
|
source $config
|
2021-04-25 18:02:35 +02:00
|
|
|
source $PWD/src/$service/constants-service.conf
|
2021-08-06 22:00:09 +02:00
|
|
|
LXC_HOSTNAME="${LXC_HOSTNAME/-/}"
|
2021-04-23 19:39:58 +02:00
|
|
|
|
2021-08-06 22:00:09 +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
|
|
|
|
|
2021-04-25 18:02:35 +02:00
|
|
|
if [ $ctid -gt 99 ]; then
|
|
|
|
LXC_CHK=$ctid
|
|
|
|
else
|
|
|
|
# Get next free LXC-number
|
|
|
|
LXC_LST=$( lxc-ls -1 | tail -1 )
|
|
|
|
LXC_CHK=$((LXC_LST+1));
|
|
|
|
fi
|
2021-04-07 22:20:10 +02:00
|
|
|
|
|
|
|
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-08-06 22:00:09 +02:00
|
|
|
if [[ $LXC_VLAN != "" ]];then VLAN=",tag=$LXC_VLAN"; else VLAN=""; fi
|
2021-04-08 20:34:40 +02:00
|
|
|
# Reconfigure conatiner
|
2021-08-06 22:00:09 +02:00
|
|
|
PVE_VER=$(pveversion | grep 'pve-manager' | cut -d'/' -f2 | sed 's/[^0-9]//g')
|
|
|
|
pct set $LXC_NBR -memory $LXC_MEM -swap $LXC_SWAP -hostname $LXC_HOSTNAME -onboot 1 -features nesting=$LXC_NESTING;
|
|
|
|
# timezone switch added in Version 6.3
|
|
|
|
if [ $PVE_VER -gt 630 ];then pct set $LXC_NBR -timezone $LXC_TIMEZONE;fi
|
2021-04-22 19:37:46 +02:00
|
|
|
if [ $LXC_DHCP == true ]; then
|
2021-04-22 21:18:11 +02:00
|
|
|
pct set $LXC_NBR -net0 name=eth0,bridge=$LXC_BRIDGE,ip=dhcp,type=veth$VLAN;
|
2021-04-22 19:37:46 +02:00
|
|
|
else
|
|
|
|
pct set $LXC_NBR -net0 name=eth0,bridge=$LXC_BRIDGE,firewall=1,gw=$LXC_GW,ip=$LXC_IP,type=veth$VLAN -nameserver $LXC_DNS -searchdomain $LXC_DOMAIN;
|
|
|
|
fi
|
2021-04-17 10:13:49 +02:00
|
|
|
sleep 2
|
|
|
|
|
|
|
|
if [ $LXC_MP -gt 0 ]; then
|
|
|
|
pct set $LXC_NBR -mp0 $LXC_SHAREFS_STORAGE:$LXC_SHAREFS_SIZE,mp=/$LXC_SHAREFS_MOUNTPOINT
|
|
|
|
fi
|
2021-04-07 22:20:10 +02:00
|
|
|
sleep 2;
|
|
|
|
|
|
|
|
PS3="Select the Server-Function: "
|
|
|
|
|
2021-04-13 23:40:43 +02:00
|
|
|
pct start $LXC_NBR;
|
2021-04-08 20:34:40 +02:00
|
|
|
sleep 5;
|
|
|
|
# Set the root password and key
|
|
|
|
echo -e "$LXC_PWD\n$LXC_PWD" | lxc-attach -n$LXC_NBR passwd;
|
2021-04-25 18:02:35 +02:00
|
|
|
lxc-attach -n$LXC_NBR mkdir /root/.ssh;
|
|
|
|
pct push $LXC_NBR $LXC_AUTHORIZED_KEY /root/.ssh/authorized_keys
|
2021-04-23 19:39:58 +02:00
|
|
|
pct push $LXC_NBR $PWD/src/sources.list /etc/apt/sources.list
|
2021-04-25 18:02:35 +02:00
|
|
|
pct push $LXC_NBR $config /root/zamba.conf
|
2021-04-23 19:39:58 +02:00
|
|
|
pct push $LXC_NBR $PWD/src/constants.conf /root/constants.conf
|
|
|
|
pct push $LXC_NBR $PWD/src/lxc-base.sh /root/lxc-base.sh
|
2021-04-25 18:02:35 +02:00
|
|
|
pct push $LXC_NBR $PWD/src/$service/install-service.sh /root/install-service.sh
|
|
|
|
pct push $LXC_NBR $PWD/src/$service/constants-service.conf /root/constants-service.conf
|
2021-04-23 19:39:58 +02:00
|
|
|
|
|
|
|
echo "Installing basic container setup..."
|
2021-04-25 18:18:30 +02:00
|
|
|
lxc-attach -n$LXC_NBR bash /root/lxc-base.sh
|
2021-04-25 18:02:35 +02:00
|
|
|
echo "Install '$service'!"
|
2021-04-23 19:39:58 +02:00
|
|
|
lxc-attach -n$LXC_NBR bash /root/install-service.sh
|
2021-04-12 01:49:10 +02:00
|
|
|
|
2021-08-06 22:00:09 +02:00
|
|
|
summary=$(pct exec $LXC_NBR -- bash -c '[ -f /root/summary ] && cat /root/summary')
|
|
|
|
if [[ $summary != "" ]];then pct set $LXC_NBR --description="$(echo -e "$summary")"; fi
|
|
|
|
|
2021-04-25 18:02:35 +02:00
|
|
|
if [[ $service == "zmb-ad" ]]; then
|
2021-04-12 01:49:10 +02:00
|
|
|
pct stop $LXC_NBR
|
|
|
|
pct set $LXC_NBR \-nameserver $(echo $LXC_IP | cut -d'/' -f 1)
|
|
|
|
pct start $LXC_NBR
|
2021-04-16 16:58:46 +02:00
|
|
|
fi
|
2021-08-06 22:00:09 +02:00
|
|
|
|
|
|
|
# timezone switch added in Version 6.3
|
|
|
|
if [ $PVE_VER -lt 630 ]; then echo "echo "$LXC_TIMEZONE" > /etc/timezone" | pct enter $LXC_NBR; fi
|