#!/bin/bash # Inspired by https://github.com/whiskerz007/proxmox_tuya-convert_container/blob/master/create_container.sh # Arguments # # 1 - LXC_STORAGE (local-lvm by default) # 2 - DISK_SIZE (1G by default) can be a number and must be followed # by either a G or a M # 3 - TEMPLATE (local:vztmpl/openwrt-18.06-openwrt_18.06.4_amd64.tar.gz by default) # 4 - CORES (1 by default) # 5 - SWAP (512 by default) # 6 - MEMORY (512 by default) # 7 - PASSWORD (123456789 by default) # 8 - HOSTNAME (openwrt by default) # 9 - OSTYPE (unmanaged by default) # 10 - POOL (Others by default) # 11 - ONBOOT (1 by default) 1 to enable, 0 to disble # 12 - NET_NAME (eth0 by default) the name of the interface # 13 - BRIDGE (vmbr0 by default) the name of the bridge # 14 - IP (dhcp by default) the IP to assogn on NET_NAME # 15 - SIMULATE (0 by default) only print commands, do not execute # 16 - DEBUG (0 by default) print debug info # Setup script set -o pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR function error_exit() { REASON=$1 MSG="\e[91mERROR: \e[93m$EXIT@" if [ -z "$REASON" ]; then MSG="$MSG$LINE:" REASON="A failure has occured." else MSG="$MSG`echo $(( $LINE - 1 ))`:" fi echo -e "$MSG \e[97m$REASON\e[39m\e[49m" exit $EXIT } function debug() { MSG=$1 if [ "$DEBUG" == "1" ] ; then echo "$MSG" fi } # Verify valid storage location; use local-lvm by default. LXC_STORAGE=${1:-local-lvm} SIMULATE=${15:-0} DEBUG=${16:-1} pvesm list $LXC_STORAGE >&/dev/null || die "'$LXC_STORAGE' is not a valid storage ID.\n\n\n" pvesm status -content images -storage $LXC_STORAGE >&/dev/null || die "'$LXC_STORAGE' does not allow 'Disk image' to be stored." debug "LXC_STORAGE = ${LXC_STORAGE}" # Get storage type STORAGE_TYPE=`pvesm status -storage $LXC_STORAGE | awk 'NR>1 {print $2}'` debug "STORAGE_TYPE = ${STORAGE_TYPE}" # Get the next guest VM/LXC ID CTID=$(cat<> /etc/pve/lxc/${CTID}.conf lxc.include: /usr/share/lxc/config/openwrt.common.conf lxc.include: /usr/share/lxc/config/common.conf lxc.cap.drop: sys_admin lxc.mount.entry: tmp tmp tmpfs rw,nodev,relatime,mode=1777 0 0 EOF echo -e "\n\n\n" \ "******************************\n" \ "* Successfully Create New CT *\n" \ "* CT ID is $CTID *\n" \ "******************************\n\n" fi