Added parameters to install.sh

This commit is contained in:
thorstenspille 2021-04-25 18:02:35 +02:00
parent d5a56268df
commit 54648ffec2

View File

@ -15,40 +15,83 @@
# Please adjust th settings in 'zamba.conf' to your needs before running the script # Please adjust th settings in 'zamba.conf' to your needs before running the script
############### ZAMBA INSTALL SCRIPT ############### ############### ZAMBA INSTALL SCRIPT ###############
prog="$(basename "$0")"
if [[ "$2" == *".conf" ]]; then usage() {
CONF=$2 cat >&2 <<-EOF
else usage: $prog [-h] [-i CTID] [-s SERVICE] [-c CFGFILE]
CONF=zamba.conf installs a preconfigured lxc container on your proxmox server
fi -h displays this help text
-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'
---------------------------------------------------------------------------
(C) 2021 zamba-lxc-toolbox by bashclub (https://github.con/bashclub)
---------------------------------------------------------------------------
EOF
exit $1
}
ctid=0
service=ask
config=$PWD/zamba.conf
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))
# Load configuration file # Load configuration file
source $PWD/$CONF echo "Loading config file '$config'..."
source $config
OPTS=$(ls -d $PWD/src/*/ | grep -v __ | xargs basename -a) OPTS=$(ls -d $PWD/src/*/ | grep -v __ | xargs basename -a)
if [ -z ${1+x} ]; then echo 0 > $PWD/VALIDATION
if [[ $opt in $OPTS ]]; then if [[ "$service" == "ask" ]]; then
echo "Configuring '$opt' container..." select svc in $OPTS quit; do
else if [[ "$svc" != "quit" ]]; then
echo "Invalid option: '$opt', exiting..." echo -e "$OPTS" | while read line; do
exit 1 if [[ "$svc" == "$line" ]]; then
service=$svc
echo "Installation of $service selected."
echo 1 > $PWD/VALIDATION
break
fi fi
else done
select opt in $OPTS quit; do
if [[ $opt in $OPTS ]]; then
echo "Configuring '$opt' container..."
elif [[ "$opt" == "quit" ]]; then
echo "'quit' selected, exiting..."
exit 0
else else
echo "Invalid option, exiting..." echo "Selected 'quit' exiting without action..."
exit 1 exit 0
fi
if [[ "$(cat $PWD/VALIDATION)" == "1" ]]; then
break
fi
done
else
echo -e "$OPTS" | while read line; do
if [[ "$service" == "$line" ]]; then
echo "Installation of $service selected."
echo 1 > $PWD/VALIDATION
break
fi fi
done done
fi fi
source $PWD/src/$opt/constants-service.conf if [[ "$(cat $PWD/VALIDATION)" != "1" ]]; then
echo "Invalid option, exiting..."
usage 1
fi
rm -f $PWD/VALIDATION
source $PWD/src/$service/constants-service.conf
# CHeck is the newest template available, else download it. # CHeck is the newest template available, else download it.
DEB_LOC=$(pveam list $LXC_TEMPLATE_STORAGE | grep debian-10-standard | cut -d'_' -f2) DEB_LOC=$(pveam list $LXC_TEMPLATE_STORAGE | grep debian-10-standard | cut -d'_' -f2)
@ -62,9 +105,13 @@ else
pveam download $LXC_TEMPLATE_STORAGE debian-10-standard_$DEB_REP\_amd64.tar.gz pveam download $LXC_TEMPLATE_STORAGE debian-10-standard_$DEB_REP\_amd64.tar.gz
fi fi
# Get next free LXC-number if [ $ctid -gt 99 ]; then
LXC_LST=$( lxc-ls -1 | tail -1 ) LXC_CHK=$ctid
LXC_CHK=$((LXC_LST+1)); else
# Get next free LXC-number
LXC_LST=$( lxc-ls -1 | tail -1 )
LXC_CHK=$((LXC_LST+1));
fi
if [ $LXC_CHK -lt 100 ] || [ -f /etc/pve/qemu-server/$LXC_CHK.conf ]; then if [ $LXC_CHK -lt 100 ] || [ -f /etc/pve/qemu-server/$LXC_CHK.conf ]; then
LXC_NBR=$(pvesh get /cluster/nextid); LXC_NBR=$(pvesh get /cluster/nextid);
@ -103,21 +150,21 @@ pct start $LXC_NBR;
sleep 5; sleep 5;
# Set the root password and key # Set the root password and key
echo -e "$LXC_PWD\n$LXC_PWD" | lxc-attach -n$LXC_NBR passwd; echo -e "$LXC_PWD\n$LXC_PWD" | lxc-attach -n$LXC_NBR passwd;
lxc-attach -n$LXC_NBR mkdir -p /root/.ssh; lxc-attach -n$LXC_NBR mkdir /root/.ssh;
pct push $LXC_AUTHORIZED_KEY /root/.ssh/authorized_keys pct push $LXC_NBR $LXC_AUTHORIZED_KEY /root/.ssh/authorized_keys
pct push $LXC_NBR $PWD/src/sources.list /etc/apt/sources.list pct push $LXC_NBR $PWD/src/sources.list /etc/apt/sources.list
pct push $LXC_NBR $PWD/$CONF /root/zamba.conf pct push $LXC_NBR $config /root/zamba.conf
pct push $LXC_NBR $PWD/src/constants.conf /root/constants.conf pct push $LXC_NBR $PWD/src/constants.conf /root/constants.conf
pct push $LXC_NBR $PWD/src/lxc-base.sh /root/lxc-base.sh pct push $LXC_NBR $PWD/src/lxc-base.sh /root/lxc-base.sh
pct push $LXC_NBR $PWD/src/$opt/install-service.sh /root/install-service.sh pct push $LXC_NBR $PWD/src/$service/install-service.sh /root/install-service.sh
pct push $LXC_NBR $PWD/src/$opt/constants-service.conf /root/constants-service.conf pct push $LXC_NBR $PWD/src/$service/constants-service.conf /root/constants-service.conf
echo "Installing basic container setup..." echo "Installing basic container setup..."
pct push $LXC_NBR $PWD/src/lxc-base.sh /root/lxc-base.sh pct push $LXC_NBR $PWD/src/lxc-base.sh /root/lxc-base.sh
echo "Install '$opt'!" echo "Install '$service'!"
lxc-attach -n$LXC_NBR bash /root/install-service.sh lxc-attach -n$LXC_NBR bash /root/install-service.sh
if [[ $opt == "zmb-ad" ]]; then if [[ $service == "zmb-ad" ]]; then
pct stop $LXC_NBR pct stop $LXC_NBR
pct set $LXC_NBR \-nameserver $(echo $LXC_IP | cut -d'/' -f 1) pct set $LXC_NBR \-nameserver $(echo $LXC_IP | cut -d'/' -f 1)
pct start $LXC_NBR pct start $LXC_NBR