| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | #!/usr/bin/bash | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-30 16:26:13 +03:00
										 |  |  | CT_DIR=${CT_DIR:=/etc/pve/lxc/} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 22:40:29 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | #---------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2023-07-04 23:15:23 +03:00
										 |  |  | # XXX this is quite generic, might be a good idea to move this to a  | 
					
						
							|  |  |  | # 		seporate lib/file... | 
					
						
							| 
									
										
										
										
											2023-07-02 23:31:03 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-11 02:22:08 +03:00
										 |  |  | # Execute (optionally) and print a command. | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | #QUIET= | 
					
						
							|  |  |  | #DRY_RUN= | 
					
						
							| 
									
										
										
										
											2023-12-28 14:23:09 +03:00
										 |  |  | ECHO_PREFIX="### " | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | @(){ | 
					
						
							|  |  |  | 	if [ -z $DRY_RUN ] ; then | 
					
						
							|  |  |  | 		! [ $QUIET ] \ | 
					
						
							| 
									
										
										
										
											2023-12-28 14:23:09 +03:00
										 |  |  | 			&& echo "${ECHO_PREFIX}$@" | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | 		$@ | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		echo $@ | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2023-12-28 14:23:09 +03:00
										 |  |  | 	return $? | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2023-07-05 22:40:29 +03:00
										 |  |  | # Fill section... | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2023-07-07 23:07:07 +03:00
										 |  |  | # XXX this is quite generic -- move to a more logical place... | 
					
						
							| 
									
										
										
										
											2023-07-05 22:40:29 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | fillsection(){ ( | 
					
						
							|  |  |  | 	usage(){ | 
					
						
							|  |  |  | 		echo "Usage:" | 
					
						
							|  |  |  | 		echo "    ${FUNCNAME[0]} [-h]" | 
					
						
							|  |  |  | 		echo "    ${FUNCNAME[0]} [-r] NAME FILE [CONTENT]" | 
					
						
							|  |  |  | 		echo | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	while true ; do | 
					
						
							|  |  |  | 		case $1 in | 
					
						
							|  |  |  | 			-h|--help) | 
					
						
							|  |  |  | 				usage | 
					
						
							|  |  |  | 				echo "Options:" | 
					
						
							|  |  |  | 				#	  .	  .					. | 
					
						
							|  |  |  | 				echo "    -h | --help       print this help message and exit." | 
					
						
							|  |  |  | 				echo "    -r | --return     replace section markers with CONTENT." | 
					
						
							|  |  |  | 				echo | 
					
						
							|  |  |  | 				return 0 | 
					
						
							|  |  |  | 				;; | 
					
						
							|  |  |  | 			-r|--replace) | 
					
						
							|  |  |  | 				local replace=1 | 
					
						
							|  |  |  | 				shift | 
					
						
							|  |  |  | 				;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			*) | 
					
						
							|  |  |  | 				break | 
					
						
							|  |  |  | 				;; | 
					
						
							|  |  |  | 		esac | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | 	if [[ $# < 2 ]] ; then | 
					
						
							|  |  |  | 		usage | 
					
						
							|  |  |  | 		return 1 | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	name=$1 | 
					
						
							|  |  |  | 	file=$2 | 
					
						
							|  |  |  | 	content=$3 | 
					
						
							|  |  |  | 	content=${content:=/dev/stdin} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# print file upto section marker... | 
					
						
							|  |  |  | 	if [ $replace ] ; then | 
					
						
							|  |  |  | 		sed "/${name^^} BEGIN/q" "$file" | sed '$d' | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		sed "/${name^^} BEGIN/q" "$file" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	# print content... | 
					
						
							|  |  |  | 	cat $content | 
					
						
							|  |  |  | 	# print file from section end marker... | 
					
						
							|  |  |  | 	if [ $replace ] ; then | 
					
						
							|  |  |  | 		sed -ne "/${name^^} END/,$ p" "$file" | sed '1d'  | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		sed -ne "/${name^^} END/,$ p" "$file" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | ) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 22:40:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							|  |  |  | # CT hostname <-> CT id... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ct2hostname(){ | 
					
						
							|  |  |  | 	local ct=${CT_DIR}/${1}.conf | 
					
						
							|  |  |  | 	local host=$(cat $ct | grep hostname | head -1) | 
					
						
							|  |  |  | 	echo ${host/hostname: /} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | hostname2ct(){ | 
					
						
							|  |  |  | 	if [ -e "${CT_DIR}/${1}.conf" ] ; then | 
					
						
							|  |  |  | 		echo $1 | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	local running=$2 | 
					
						
							|  |  |  | 	running=${running:=any} | 
					
						
							|  |  |  | 	local ct | 
					
						
							|  |  |  | 	local host | 
					
						
							|  |  |  | 	for ct in "${CT_DIR}"/*.conf ; do | 
					
						
							|  |  |  | 		host=$(cat $ct | grep hostname | head -1) | 
					
						
							|  |  |  | 		host=${host/hostname: /} | 
					
						
							|  |  |  | 		if [ "$host" = $1 ] ; then | 
					
						
							|  |  |  | 			ct=${ct#${CT_DIR}} | 
					
						
							|  |  |  | 			ct=${ct%.conf} | 
					
						
							|  |  |  | 			ct=${ct#\/} | 
					
						
							|  |  |  | 			# filter results if needed... | 
					
						
							|  |  |  | 			if [ $running = "any" ] ; then | 
					
						
							|  |  |  | 				echo $ct | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				local status=`pct status $ct` | 
					
						
							|  |  |  | 				if [ "$running" = "${status/status: /}" ] ; then | 
					
						
							|  |  |  | 					echo $ct | 
					
						
							|  |  |  | 				fi | 
					
						
							|  |  |  | 			fi | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-30 18:37:35 +03:00
										 |  |  | #---------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | normpath(){ | 
					
						
							|  |  |  | 	echo $1 \ | 
					
						
							|  |  |  | 		| sed \ | 
					
						
							|  |  |  | 			-e 's/\/\+/\//g' \ | 
					
						
							|  |  |  | 			-e 's/\/.\//\//g' \ | 
					
						
							|  |  |  | 			-e 's/[^\/]\+\/\.\.//g' \ | 
					
						
							|  |  |  | 			-e 's/\/\+/\//g' \ | 
					
						
							|  |  |  | 			-e 's/\/\.$/\//g' | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 14:23:09 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | #---------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-04 16:15:12 +03:00
										 |  |  | # | 
					
						
							|  |  |  | #	getLatestTemplate PATTERN [VAR] | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2024-01-05 02:26:45 +03:00
										 |  |  | # see: | 
					
						
							|  |  |  | #	https://pve.proxmox.com/wiki/Linux_Container | 
					
						
							| 
									
										
										
										
											2024-01-04 16:15:12 +03:00
										 |  |  | getLatestTemplate(){ | 
					
						
							| 
									
										
										
										
											2024-01-05 03:05:06 +03:00
										 |  |  | 	#IFS=$'\n' | 
					
						
							| 
									
										
										
										
											2024-01-07 16:34:47 +03:00
										 |  |  | 	@ pveam update  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-05 02:18:15 +03:00
										 |  |  | 	local templates=($(pveam available | grep -o ''${1}'.*$')) | 
					
						
							| 
									
										
										
										
											2024-01-04 16:15:12 +03:00
										 |  |  | 	local latest=${templates[-1]} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-05 02:26:45 +03:00
										 |  |  | 	@ pveam download local ${latest} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-05 03:05:06 +03:00
										 |  |  | 	latest=$(pveam list local | grep -o "^.*$latest") | 
					
						
							|  |  |  | 	#latest=($(ls /var/lib/vz/template/cache/${1}*)) | 
					
						
							| 
									
										
										
										
											2024-01-04 16:15:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	[ -z $2 ] \ | 
					
						
							|  |  |  | 		|| eval "$2=${latest}" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2024-01-03 19:27:52 +03:00
										 |  |  | #	xread [-n] MSG VAR | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | # | 
					
						
							|  |  |  | xread(){ | 
					
						
							|  |  |  | 	local non_empty= | 
					
						
							|  |  |  | 	if [[ $1 == '-n' ]] ; then | 
					
						
							|  |  |  | 		shift | 
					
						
							|  |  |  | 		local non_empty=1 | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	[ -z ${!2} ] \ | 
					
						
							|  |  |  | 		&& eval 'read -ep "'$1'" -i "$DFL_'$2'" '${2}'' | 
					
						
							|  |  |  | 	if [ -z $non_empty ] ; then | 
					
						
							|  |  |  | 		eval ''$2'=${'$2':=$DFL_'$2'}' | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2024-01-03 19:27:52 +03:00
										 |  |  | 	[ $SCRIPTING ] \ | 
					
						
							|  |  |  | 		&& echo "$2=${!2}" | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-06 01:49:27 +03:00
										 |  |  | # | 
					
						
							|  |  |  | #	xreadpass VAR | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | xreadpass(){ | 
					
						
							|  |  |  | 	local PASS1 | 
					
						
							|  |  |  | 	local PASS2 | 
					
						
							|  |  |  | 	read -sep "password (Enter to skip): " PASS1 | 
					
						
							|  |  |  | 	echo | 
					
						
							|  |  |  | 	if [ $PASS1 ] ; then | 
					
						
							|  |  |  | 		read -sep "retype password: " PASS2 | 
					
						
							|  |  |  | 		echo | 
					
						
							|  |  |  | 		if [[ $PASS1 != $PASS2 ]] ; then | 
					
						
							|  |  |  | 			echo "ERR: passwords do not match." | 
					
						
							|  |  |  | 			return 1 | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 		eval ''$1'='${PASS1}'' | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 16:18:27 +03:00
										 |  |  | #  | 
					
						
							|  |  |  | # 	readConfig | 
					
						
							|  |  |  | #  | 
					
						
							|  |  |  | readConfig(){ | 
					
						
							|  |  |  | 	if [ -z $NO_DEFAULTS ] ; then | 
					
						
							|  |  |  | 		[ -e ../config.global ] \ | 
					
						
							|  |  |  | 			&& source ../config.global | 
					
						
							|  |  |  | 		[ -e ./config ] \ | 
					
						
							|  |  |  | 			&& source ./config | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 20:13:51 +03:00
										 |  |  | # | 
					
						
							|  |  |  | #	readVars | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | # | 
					
						
							|  |  |  | # Variables this handles: | 
					
						
							|  |  |  | #	EMAIL | 
					
						
							|  |  |  | #	DOMAIN | 
					
						
							|  |  |  | #	ID | 
					
						
							|  |  |  | #	CTHOSTNAME | 
					
						
							|  |  |  | #	WAN_BRIDGE | 
					
						
							|  |  |  | #	LAN_BRIDGE | 
					
						
							|  |  |  | #	ADMIN_BRIDGE | 
					
						
							|  |  |  | #	WAN_IP | 
					
						
							|  |  |  | #	WAN_GATE | 
					
						
							|  |  |  | #	LAN_IP | 
					
						
							|  |  |  | #	LAN_GATE | 
					
						
							|  |  |  | #	ADMIN_IP | 
					
						
							|  |  |  | #	ADMIN_GATE | 
					
						
							|  |  |  | #	ROOTPASS | 
					
						
							|  |  |  | #	PCT_EXTRA | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Variables this sets: | 
					
						
							|  |  |  | #	PASS | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Variables used: | 
					
						
							|  |  |  | # 	TMP_PASS_LEN | 
					
						
							|  |  |  | # 	ROOTPASS | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | readVars(){ | 
					
						
							|  |  |  | 	xread -n "Email: " EMAIL | 
					
						
							|  |  |  | 	xread -n "Domain: " DOMAIN | 
					
						
							|  |  |  | 	xread "ID: " ID | 
					
						
							|  |  |  | 	xread "Hostname: " CTHOSTNAME | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-05 22:59:42 +03:00
										 |  |  | 	# hardware... | 
					
						
							| 
									
										
										
										
											2024-01-07 16:34:47 +03:00
										 |  |  | 	xread "CPU cores: " CORES | 
					
						
							| 
									
										
										
										
											2024-01-05 22:59:42 +03:00
										 |  |  | 	xread "RAM (MB): " RAM | 
					
						
							|  |  |  | 	xread "SWAP (MB): " SWAP | 
					
						
							|  |  |  | 	xread "DRIVE (GB): " DRIVE | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | 	# bridge config... | 
					
						
							|  |  |  | 	xread "WAN bridge: vmbr" WAN_BRIDGE | 
					
						
							|  |  |  | 	xread "LAN bridge: vmbr" LAN_BRIDGE | 
					
						
							|  |  |  | 	xread "ADMIN bridge: vmbr" ADMIN_BRIDGE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# gateway... | 
					
						
							| 
									
										
										
										
											2024-01-03 19:27:52 +03:00
										 |  |  | 	# IPs can be: | 
					
						
							|  |  |  | 	#	<empty> | 
					
						
							|  |  |  | 	#	<IP>/<mask> | 
					
						
							|  |  |  | 	#	dhcp | 
					
						
							|  |  |  | 	# Gateways can be: | 
					
						
							|  |  |  | 	#	<empty> | 
					
						
							|  |  |  | 	#	<IP> | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | 	xread "WAN ip: " WAN_IP | 
					
						
							|  |  |  | 	xread "WAN gateway: " WAN_GATE | 
					
						
							|  |  |  | 	xread "LAN ip: " LAN_IP | 
					
						
							|  |  |  | 	xread "LAN gateway: " LAN_GATE | 
					
						
							|  |  |  | 	xread "ADMIN ip: " ADMIN_IP | 
					
						
							|  |  |  | 	xread "ADMIN gateway: " ADMIN_GATE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# root password... | 
					
						
							|  |  |  | 	if [ -z $ROOTPASS ] ; then | 
					
						
							| 
									
										
										
										
											2024-01-06 01:49:27 +03:00
										 |  |  | 		xreadpass PASS \ | 
					
						
							|  |  |  | 			|| exit 1 | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		PASS=$ROOTPASS | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# extra stuff... | 
					
						
							|  |  |  | 	xread "pct extra options: " PCT_EXTRA | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 20:13:51 +03:00
										 |  |  | # | 
					
						
							|  |  |  | #	buildAssets [TEMPLATES [ASSETS]] | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | buildAssets(){ | 
					
						
							|  |  |  | 	local TEMPLATE_DIR=$1 | 
					
						
							|  |  |  | 	TEMPLATE_DIR=${TEMPLATE_DIR:=templates} | 
					
						
							|  |  |  | 	local ASSETS_DIR=$2 | 
					
						
							| 
									
										
										
										
											2024-01-04 00:51:56 +03:00
										 |  |  | 	ASSETS_DIR=${ASSETS_DIR:=assets} | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	local TEMPLATES=($(find "$TEMPLATE_DIR" -type f)) | 
					
						
							|  |  |  | 	for file in "${TEMPLATES[@]}" ; do | 
					
						
							|  |  |  | 		file=${file#${TEMPLATE_DIR}} | 
					
						
							|  |  |  | 		echo Generating: ${file}... | 
					
						
							|  |  |  | 		[ $DRY_RUN ] \ | 
					
						
							|  |  |  | 			&& continue | 
					
						
							|  |  |  | 		# ensure the directory exists... | 
					
						
							|  |  |  | 		mkdir -p "$(dirname "${ASSETS_DIR}/${file}")" | 
					
						
							|  |  |  | 		cat "${TEMPLATE_DIR}/${file}" \ | 
					
						
							|  |  |  | 			| sed \ | 
					
						
							| 
									
										
										
										
											2024-01-04 01:21:31 +03:00
										 |  |  | 				-e 's/\${EMAIL}/'${EMAIL/\//\\/}'/g' \ | 
					
						
							|  |  |  | 				-e 's/\${DOMAIN}/'${DOMAIN/\//\\/}'/g' \ | 
					
						
							|  |  |  | 				-e 's/\${CTHOSTNAME}/'${CTHOSTNAME/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:25:20 +03:00
										 |  |  | 				-e 's/\${GATE_HOSTNAME}/'${GATE_HOSTNAME/\//\\/}'/g' \ | 
					
						
							|  |  |  | 				-e 's/\${NS_HOSTNAME}/'${NS_HOSTNAME/\//\\/}'/g' \ | 
					
						
							|  |  |  | 				-e 's/\${GATE_LAN_IP}/'${GATE_LAN_IP/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:52:44 +03:00
										 |  |  | 				-e 's/\${GATE_LAN_IPn}/'${GATE_LAN_IP/\/*}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:25:20 +03:00
										 |  |  | 				-e 's/\${GATE_ADMIN_IP}/'${GATE_ADMIN_IP/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:52:44 +03:00
										 |  |  | 				-e 's/\${GATE_ADMIN_IPn}/'${GATE_ADMIN_IP/\/*}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:25:20 +03:00
										 |  |  | 				-e 's/\${NS_LAN_IP}/'${NS_LAN_IP/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:52:44 +03:00
										 |  |  | 				-e 's/\${NS_LAN_IPn}/'${NS_LAN_IP/\/*}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:25:20 +03:00
										 |  |  | 				-e 's/\${NS_ADMIN_IP}/'${NS_ADMIN_IP/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:52:44 +03:00
										 |  |  | 				-e 's/\${NS_ADMIN_IPn}/'${NS_ADMIN_IP/\/*}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 00:51:56 +03:00
										 |  |  | 				-e 's/\${WAN_IP}/'${WAN_IP/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:25:20 +03:00
										 |  |  | 				-e 's/\${WAN_IPn}/'${WAN_IP/\/*}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 01:21:31 +03:00
										 |  |  | 				-e 's/\${WAN_GATE}/'${WAN_GATE/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 00:51:56 +03:00
										 |  |  | 				-e 's/\${LAN_IP}/'${LAN_IP/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:25:20 +03:00
										 |  |  | 				-e 's/\${LAN_IPn}/'${LAN_IP/\/*}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 01:21:31 +03:00
										 |  |  | 				-e 's/\${LAN_GATE}/'${LAN_GATE/\//\\/}'/' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 00:51:56 +03:00
										 |  |  | 				-e 's/\${ADMIN_IP}/'${ADMIN_IP/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 02:25:20 +03:00
										 |  |  | 				-e 's/\${ADMIN_IPn}/'${ADMIN_IP/\/*}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-04 01:21:31 +03:00
										 |  |  | 				-e 's/\${ADMIN_GATE}/'${ADMIN_GATE/\//\\/}'/g' \ | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | 			> "${ASSETS_DIR}/${file}" | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 20:13:51 +03:00
										 |  |  | # | 
					
						
							|  |  |  | #	pctCreate ID TEMPLATE ARGS [PASS] | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | pctCreate(){ | 
					
						
							|  |  |  | 	local TMP_PASS=$(cat /dev/urandom | base64 | head -c ${TMP_PASS_LEN:=32}) | 
					
						
							|  |  |  | 	# NOTE: we are not setting the password here to avoid printing it to the terminal... | 
					
						
							|  |  |  | 	@ pct create $1 \ | 
					
						
							|  |  |  | 		${2} \ | 
					
						
							|  |  |  | 		${3} \ | 
					
						
							|  |  |  | 		--password="$TMP_PASS" \ | 
					
						
							|  |  |  | 		--start 1 \ | 
					
						
							|  |  |  | 	|| exit 1 | 
					
						
							|  |  |  | 	# set actual root password... | 
					
						
							|  |  |  | 	if [ "$4" ] ; then | 
					
						
							|  |  |  | 		echo "root:$4" \ | 
					
						
							|  |  |  | 			| @ lxc-attach $1 chpasswd | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 20:13:51 +03:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2024-01-05 22:52:36 +03:00
										 |  |  | #	pctCreate<distro> ID ARGS [PASS] | 
					
						
							| 
									
										
										
										
											2024-01-03 20:13:51 +03:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | pctCreateAlpine(){ | 
					
						
							| 
									
										
										
										
											2024-01-05 02:26:45 +03:00
										 |  |  | 	local TEMPLATE | 
					
						
							|  |  |  | 	getLatestTemplate alpine TEMPLATE | 
					
						
							| 
									
										
										
										
											2024-01-03 20:13:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-05 03:05:06 +03:00
										 |  |  | 	pctCreate $1 "$TEMPLATE" "$2" "$3" | 
					
						
							| 
									
										
										
										
											2024-01-03 19:27:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-05 22:52:36 +03:00
										 |  |  | 	sleep ${TIMEOUT:=5} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 19:30:09 +03:00
										 |  |  | 	@ lxc-attach $1 apk update | 
					
						
							|  |  |  | 	@ lxc-attach $1 apk upgrade | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-05 22:52:36 +03:00
										 |  |  | pctCreateDebian(){ | 
					
						
							|  |  |  | 	local TEMPLATE | 
					
						
							| 
									
										
										
										
											2024-01-06 01:55:42 +03:00
										 |  |  | 	getLatestTemplate 'debian-12-standard' TEMPLATE | 
					
						
							| 
									
										
										
										
											2024-01-05 22:52:36 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pctCreate $1 "$TEMPLATE" "$2" "$3" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sleep ${TIMEOUT:=5} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	@ lxc-attach $1 apt update | 
					
						
							| 
									
										
										
										
											2024-01-06 01:49:27 +03:00
										 |  |  | 	@ lxc-attach $1 -- apt upgrade -y | 
					
						
							| 
									
										
										
										
											2024-01-05 22:52:36 +03:00
										 |  |  | } | 
					
						
							|  |  |  | pctCreateUbuntu(){ | 
					
						
							|  |  |  | 	local TEMPLATE | 
					
						
							|  |  |  | 	getLatestTemplate ubuntu TEMPLATE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pctCreate $1 "$TEMPLATE" "$2" "$3" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sleep ${TIMEOUT:=5} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	@ lxc-attach $1 apt update | 
					
						
							| 
									
										
										
										
											2024-01-06 01:49:27 +03:00
										 |  |  | 	@ lxc-attach $1 -- apt upgrade -y | 
					
						
							| 
									
										
										
										
											2024-01-05 22:52:36 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 20:13:51 +03:00
										 |  |  | # | 
					
						
							|  |  |  | #	pctSet ID [ARGS [REBOOT]] | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2024-01-03 18:51:22 +03:00
										 |  |  | pctSet(){ | 
					
						
							|  |  |  | 	[ "$2" ] \ | 
					
						
							|  |  |  | 		&& @ pct set $1 \ | 
					
						
							|  |  |  | 			${2} | 
					
						
							|  |  |  | 	[ "$3" ] \ | 
					
						
							|  |  |  | 		&& @ pct reboot $1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | #---------------------------------------------------------------------- | 
					
						
							|  |  |  | # vim:set ts=4 sw=4 nowrap : |