Files
DynastyRevolution-Scripts/core/build.func

493 lines
22 KiB
Bash

#!/usr/bin/env bash
variables() {
NSAPP=$(echo "$APP" | tr '[:upper:]' '[:lower:]' | tr -d ' ')
var_install="${NSAPP}-install"
INTEGER='^[0-9]+([.][0-9]+)?$'
PVEHOST_NAME=$(hostname)
METHOD="${METHOD:-default}"
WHIPTITLE="Dynasty Revolution Provisioning"
if [[ "$OSTYPE" == "darwin"* ]]; then
RANDOM_UUID="$(uuidgen | tr '[:upper:]' '[:lower:]')"
else
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
fi
EXECUTION_ID="${RANDOM_UUID}"
SESSION_ID="${RANDOM_UUID:0:8}"
if [[ "$OSTYPE" == "darwin"* ]]; then
INSTALL_LOG="/tmp/DYNR/INSTALL_LOG_${NSAPP}.log"
mkdir -p /tmp/DYNR 2>/dev/null
else
INSTALL_LOG="/opt/DYNR/INSTALL_LOG_${NSAPP}.log"
mkdir -p /opt/DYNR 2>/dev/null
fi
CTTYPE="${CTTYPE:-${CT_TYPE:-1}}"
parse_dev_mode
if [[ "${DEV_MODE_LOGS:-false}" == "true" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
mkdir -p /tmp/DYNR
BUILD_LOG="/tmp/DYNR/create-lxc-${SESSION_ID}-$(date +%Y%m%d_%H%M%S).log"
else
mkdir -p /var/log/DYNR
BUILD_LOG="/var/log/DYNR/create-lxc-${SESSION_ID}-$(date +%Y%m%d_%H%M%S).log"
fi
fi
if command -v pveversion >/dev/null 2>&1; then
PVEVERSION="$(pveversion | awk -F'/' '{print $2}' | awk -F'-' '{print $1}')"
else
PVEVERSION="N/A"
fi
KERNEL_VERSION=$(uname -r)
if [[ -n "${var_cpu:-}" ]] && [[ "${var_cpu}" =~ ^[0-9]+$ ]]; then
export APP_DEFAULT_CPU="${var_cpu}"
fi
if [[ -n "${var_ram:-}" ]] && [[ "${var_ram}" =~ ^[0-9]+$ ]]; then
export APP_DEFAULT_RAM="${var_ram}"
fi
if [[ -n "${var_disk:-}" ]] && [[ "${var_disk}" =~ ^[0-9]+$ ]]; then
export APP_DEFAULT_DISK="${var_disk}"
fi
}
DYNR_CORE="https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main/core"
DYNR_REPO="https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main"
eval "$(curl -fsSL ${DYNR_CORE}/api.func)"
eval "$(curl -fsSL ${DYNR_CORE}/core.func)"
eval "$(curl -fsSL ${DYNR_CORE}/error_handler.func)"
fetch_wotd() {
local wotd_html=$(curl -s --connect-timeout 3 https://www.merriam-webster.com/word-of-the-day)
local word=$(echo "$wotd_html" | grep -oP '(?<=Word of the Day: ).*?(?= \|)' | head -n1)
local def=$(echo "$wotd_html" | grep -A 1 "<h2>What It Means</h2>" | tail -n1 | sed 's/<[^>]*>//g' | xargs)
if [ -n "$word" ]; then
echo -e "${BG}Word of the Day: ${BB}${word}${BC}"
echo -e "${TAB}${def}"
fi
}
network_check() {
msg_info "Checking Network Connectivity (1.1.1.1 / 1.0.0.1)..."
if ping -c 1 -W 2 1.1.1.1 &>/dev/null || ping -c 1 -W 2 1.0.0.1 &>/dev/null; then
msg_ok "Network OK."
else
msg_error "Network Unreachable. Provision Aborted."
exit 1
fi
}
network_verify() {
local target_id=$1
local type=$2
msg_info "⌚️ Checking Network Connectivity...."
fetch_wotd
local IP_ADDRESSv4="localhost"
local IP_ADDRESSv6=""
local ITER=0
while [ $ITER -lt 15 ]; do
if [[ "$type" == "vm" ]]; then
if qm guest exec $target_id -- ping -c 1 -W 2 1.1.1.1 &>/dev/null; then
IP_ADDRESSv4=$(qm guest network-get-interfaces $target_id --output-format json 2>/dev/null | jq -r '.[] | select(.name=="eth0") | .["ip-addresses"][] | select(.["ip-address-type"]=="ipv4") | .["ip-address"]' | cut -d/ -f1 | head -n 1)
IP_ADDRESSv6=$(qm guest network-get-interfaces $target_id --output-format json 2>/dev/null | jq -r '.[] | select(.name=="eth0") | .["ip-addresses"][] | select(.["ip-address-type"]=="ipv6") | .["ip-address"]' | cut -d/ -f1 | head -n 1)
break
fi
else
if pct exec $target_id -- ping -c 1 -W 2 1.1.1.1 &>/dev/null; then
IP_ADDRESSv4=$(pct exec $target_id -- ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1)
IP_ADDRESSv6=$(pct exec $target_id -- ip -6 addr show eth0 | grep -oP '(?<=inet6\s)[0-9a-fA-F:]+' | head -n1)
break
fi
fi
sleep 10
ITER=$((ITER+1))
done
if [[ "$IP_ADDRESSv4" != "localhost" ]]; then
msg_ok "✅ Network Connection Succeeded"
echo -e "${TAB}IP Address of ${NSAPP}: ${IP_ADDRESSv4} v4 / ${IP_ADDRESSv6} v6"
else
msg_error "❌ Network Connection Failed"
fi
}
github_api_check() {
msg_info "Checking Github API Token..."
local api_response=$(curl -s https://api.github.com/rate_limit)
local remaining=$(echo "$api_response" | grep -A 2 '"core"' | grep '"remaining"' | tr -dc '0-9')
if [[ -n "$remaining" ]]; then
msg_ok "Github: Tokens Remaining: ${GOLD}${remaining}${NC}"
else
msg_warn "Github: API Limit Unreachable. Proceeding with caution."
fi
}
check_manifest_updates() {
local remote_script="${DYNR_REPO}/${MODULE_PATH}"
local remote_ver=$(curl -fsSL --connect-timeout 2 "$remote_script" | grep -m 1 "VERSION=" | cut -d'"' -f2 || echo "0")
if [[ "$remote_ver" > "$VERSION" ]]; then
msg_warn "A New update has Dawned: v$remote_ver is available."
msg_info "Current Version: v$VERSION"
echo -e "${GOLD}Recommendation: Re-sync with latest version.${NC}"
echo ""
sleep 2
fi
}
remote_provisioning_ui() {
local title="Dynasty Remote Provisioning"
local prompt="$1"
local default="$2"
if command -v osascript &>/dev/null && [[ "$OSTYPE" == "darwin"* ]]; then
osascript -e "display dialog \"$prompt\" default answer \"$default\" with title \"$title\" buttons {\"Cancel\", \"Next\"} default button \"Next\"" -e "text returned of result" 2>/dev/null
elif command -v whiptail &>/dev/null; then
whiptail --backtitle "$title" --title "INPUT" --inputbox "$prompt" 10 58 "$default" 3>&1 1>&2 2>&3
else
read -p "$prompt [$default]: " val </dev/tty
echo "${val:-$default}"
fi
}
Beginning_Remote_Provisioning() {
local target_host=$(remote_provisioning_ui "Enter Proxmox IP/FQDN:" "")
if [[ -z "$target_host" ]]; then
exit_script
fi
local target_user=$(remote_provisioning_ui "Enter SSH User:" "root")
if [[ -z "$target_user" ]]; then
exit_script
fi
local deploy_mode
if [[ "$OSTYPE" == "darwin"* ]]; then
deploy_mode=$(osascript -e 'choose from list {"advanced", "default"} with title "Dynasty Remote Provisioning" with prompt "Select Deployment Mode:" default items {"advanced"}' 2>/dev/null)
else
deploy_mode=$(whiptail --backtitle "Dynasty Remote Provisioning" --title "STANCE" --radiolist "Select Deployment Mode:" 12 58 2 "advanced" "" ON "default" "" OFF 3>&1 1>&2 2>&3)
fi
if [[ -z "$deploy_mode" || "$deploy_mode" == "false" ]]; then
deploy_mode="default"
fi
local script_home="${DYNR_REPO}/${MODULE_PATH}"
clear
echo -e "${PURPLE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e " ${GOLD}INITIATING REMOTE PROVISIONING${NC}"
echo -e "${PURPLE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}Target Host: ${NC} $target_host"
echo -e "${BLUE}User: ${NC} $target_user"
echo -e "${BLUE}Mode: ${NC} $deploy_mode"
echo -e "${BLUE}Script: ${GOLD}${APP}${NC}"
echo -e "${PURPLE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
if ssh -tt "${target_user}@${target_host}" "TERM=xterm-256color bash -c '
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
target_hostname=\$(hostname 2>/dev/null)
clear
echo -e \"${PURPLE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\"
echo -e \" ${GOLD}REMOTE PROVISIONING CONNECTED${NC}\"
echo -e \"${PURPLE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\"
echo -e \"${BLUE}Target Host: ${NC} $target_host (\$target_hostname)\"
echo -e \"${BLUE}User: ${NC} $target_user\"
echo -e \"${BLUE}Mode: ${NC} $deploy_mode\"
echo -e \"${BLUE}Script: ${GOLD}${APP}${NC}\"
echo -e \"${PURPLE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\"
echo \"\"
read -p \"Proceed with Host \$target_hostname (y/n)? \" proceed
if [[ \"\$proceed\" =~ ^[Yy] ]]; then
METHOD=\"$deploy_mode\" bash -c \"\$(curl -fsSL $script_home)\"
else
echo -e \"\n${RED}Provision Aborted by User.${NC}\"
exit 1
fi
'" < /dev/tty; then
msg_ok "Provision Successful."
else
msg_error "Provision Failure. (User Aborted or Connection Lost)"
fi
exit 0
}
maxkeys_check() {
local per_user_maxkeys=$(cat /proc/sys/kernel/keys/maxkeys 2>/dev/null || echo 0)
if [[ "$per_user_maxkeys" -eq 0 ]]; then
msg_error "Kernel parameter read failure."
exit 107
fi
}
validate_container_id() {
local ctid="$1"
if ! [[ "$ctid" =~ ^[0-9]+$ ]]; then
return 1
fi
if command -v pvesh &>/dev/null; then
local cluster_ids=$(pvesh get /cluster/resources --type vm --output-format json 2>/dev/null | grep -oP '"vmid":\s*\K[0-9]+' 2>/dev/null || true)
if [[ -n "$cluster_ids" ]] && echo "$cluster_ids" | grep -qw "$ctid"; then
return 1
fi
fi
if [[ -f "/etc/pve/lxc/${ctid}.conf" ]] || [[ -f "/etc/pve/qemu-server/${ctid}.conf" ]]; then
return 1
fi
return 0
}
get_valid_container_id() {
local suggested_id="${1:-$(pvesh get /cluster/nextid 2>/dev/null || echo 100)}"
while ! validate_container_id "$suggested_id"; do
suggested_id=$((suggested_id + 1))
done
echo "$suggested_id"
}
select_storage() {
local CLASS=$1
local CONTENT='rootdir'
if [[ "$CLASS" == "template" ]]; then
CONTENT='vztmpl'
fi
declare -A STORAGE_MAP
local -a MENU=()
while read -r TAG TYPE _ TOTAL USED FREE _; do
if [[ -z "$TAG" ]] || [[ -z "$TYPE" ]]; then continue; fi
if [[ "$TYPE" == "pbs" ]] && [[ "$CLASS" == "container" ]]; then continue; fi
local DISPLAY="${TAG} (${TYPE})"
local FREE_FMT=$(numfmt --to=iec --from-unit=1024 --format %.1f <<<"$FREE")
STORAGE_MAP["$DISPLAY"]="$TAG"
MENU+=("$DISPLAY" "Free: ${FREE_FMT}B" "OFF")
done < <(pvesm status -content "$CONTENT" | awk 'NR>1')
if [[ $((${#MENU[@]} / 3)) -eq 0 ]]; then
msg_error "No valid storage found. (Note: PBS is for backups only)"
exit 1
fi
if [[ $((${#MENU[@]} / 3)) -eq 1 ]]; then
STORAGE_RESULT="${STORAGE_MAP[${MENU[0]}]}"
return 0
fi
local selected_display=$(whiptail --backtitle "$WHIPTITLE" --title "STORAGE" --radiolist "Select Storage Pool:" 16 60 6 "${MENU[@]}" 3>&1 1>&2 2>&3)
STORAGE_RESULT="${STORAGE_MAP[$selected_display]}"
}
base_settings() {
CT_TYPE=${var_unprivileged:-"1"}
DISK_SIZE="${var_disk:-8}"
CORE_COUNT="${var_cpu:-1}"
RAM_SIZE="${var_ram:-1024}"
CT_ID=$(get_valid_container_id "${var_ctid:-$NEXTID}")
HN="${var_hostname:-$NSAPP}"
BRG=${var_brg:-"vmbr0"}
NET=${var_net:-"dhcp"}
TAGS="dynasty-script,${var_tags:-}"
VLAN_TAG=""
ENABLE_TUN="0"
ENABLE_SSH="0"
SSH_KEY=""
OS_CHOICE="${var_os:-debian}"
OS_VERSION="${var_version:-12}"
TZ="${var_tz:-host}"
}
advanced_settings() {
tput smcup 2>/dev/null || true
trap 'tput rmcup 2>/dev/null || true' RETURN
local deb12_st="OFF" deb13_st="OFF" alp_st="OFF" ubu_st="OFF" fed_st="OFF" cen_st="OFF" arch_st="OFF"
if [[ "$var_os" == "debian" && "$var_version" == "12" ]]; then deb12_st="ON"; fi
if [[ "$var_os" == "debian" && "$var_version" == "13" ]]; then deb13_st="ON"; fi
if [[ "$var_os" == "alpine" ]]; then alp_st="ON"; fi
if [[ "$var_os" == "archlinux" || "$var_os" == "arch" ]]; then arch_st="ON"; fi
if [[ "$var_os" == "ubuntu" ]]; then ubu_st="ON"; fi
if [[ "$var_os" == "fedora" ]]; then fed_st="ON"; fi
if [[ "$var_os" == "centos" ]]; then cen_st="ON"; fi
if [[ "$deb12_st" == "OFF" && "$deb13_st" == "OFF" && "$alp_st" == "OFF" && "$ubu_st" == "OFF" && "$fed_st" == "OFF" && "$cen_st" == "OFF" && "$arch_st" == "OFF" ]]; then deb12_st="ON"; fi
local STEP=1
local MAX_STEP=16
while [[ $STEP -le $MAX_STEP ]]; do
case $STEP in
1) if result=$(whiptail --backtitle "$WHIPTITLE" --title "PRIVILEGES" --radiolist "Select Container Type:" 12 58 2 "1" "LXC (Unprivileged)" ON "0" "LXC (Privileged)" OFF 3>&1 1>&2 2>&3); then CT_TYPE="$result"; STEP=$((STEP + 1)); else exit_script; fi ;;
2) if result=$(whiptail --backtitle "$WHIPTITLE" --title "OS SELECTION" --radiolist "Select OS:" 14 65 7 "debian" "Debian 12 $([ "$deb12_st" == "ON" ] && echo "(Recommended)")" $deb12_st "debian13" "Debian 13 $([ "$deb13_st" == "ON" ] && echo "(Recommended)")" $deb13_st "alpine" "Alpine 3.20 $([ "$alp_st" == "ON" ] && echo "(Recommended)")" $alp_st "archlinux" "Arch Linux $([ "$arch_st" == "ON" ] && echo "(Recommended)")" $arch_st "ubuntu" "Ubuntu 24.04 $([ "$ubu_st" == "ON" ] && echo "(Recommended)")" $ubu_st "fedora" "Fedora 40 $([ "$fed_st" == "ON" ] && echo "(Recommended)")" $fed_st "centos" "CentOS Stream 9 $([ "$cen_st" == "ON" ] && echo "(Recommended)")" $cen_st 3>&1 1>&2 2>&3); then OS_CHOICE="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
3) if result=$(whiptail --backtitle "$WHIPTITLE" --title "VERSION SELECTION" --inputbox "Set OS Version (Digit):" 10 58 "$OS_VERSION" 3>&1 1>&2 2>&3); then OS_VERSION="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
4) if result=$(whiptail --backtitle "$WHIPTITLE" --title "PASSWORD" --passwordbox "Root Password (Blank for Auto-Auth):" 12 58 3>&1 1>&2 2>&3); then if [[ -n "$result" ]]; then PW="--password $result"; else PW=""; fi; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
5) if whiptail --backtitle "$WHIPTITLE" --title "VPN CAPABILITY" --yesno "Enable TUN/TAP (/dev/net/tun) for VPN interfaces?" 10 58; then ENABLE_TUN="1"; else ENABLE_TUN="0"; fi; STEP=$((STEP + 1)) ;;
6) if whiptail --backtitle "$WHIPTITLE" --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58; then ENABLE_SSH="1"; else ENABLE_SSH="0"; fi; STEP=$((STEP + 1)) ;;
7) if [[ "$ENABLE_SSH" == "1" ]]; then if result=$(whiptail --backtitle "$WHIPTITLE" --title "SSH KEY" --inputbox "Paste SSH Public Key (Leave blank to skip):" 10 58 3>&1 1>&2 2>&3); then SSH_KEY="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi; else STEP=$((STEP + 1)); fi ;;
8) if result=$(whiptail --backtitle "$WHIPTITLE" --title "ID" --inputbox "Confirm ID:" 10 58 "$CT_ID" 3>&1 1>&2 2>&3); then CT_ID="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
9) if result=$(whiptail --backtitle "$WHIPTITLE" --title "HOSTNAME" --inputbox "Set Hostname:" 10 58 "$HN" 3>&1 1>&2 2>&3); then HN="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
10) if result=$(whiptail --backtitle "$WHIPTITLE" --title "CAPACITY" --inputbox "Storage (GB):" 10 58 "$DISK_SIZE" 3>&1 1>&2 2>&3); then DISK_SIZE="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
11) if result=$(whiptail --backtitle "$WHIPTITLE" --title "CORES" --inputbox "CPU Allocation:" 10 58 "$CORE_COUNT" 3>&1 1>&2 2>&3); then CORE_COUNT="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
12) if result=$(whiptail --backtitle "$WHIPTITLE" --title "MEMORY" --inputbox "RAM (MiB):" 10 58 "$RAM_SIZE" 3>&1 1>&2 2>&3); then RAM_SIZE="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
13) if result=$(whiptail --backtitle "$WHIPTITLE" --title "NETWORK" --inputbox "VLAN Tag (Leave blank for none):" 10 58 "${VLAN_TAG:-}" 3>&1 1>&2 2>&3); then VLAN_TAG="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
14) if select_storage container; then CONTAINER_STORAGE="$STORAGE_RESULT"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
15) if result=$(whiptail --backtitle "$WHIPTITLE" --title "TIMEZONE" --inputbox "Set Timezone (e.g., America/New_York, or 'host'):" 10 58 "$TZ" 3>&1 1>&2 2>&3); then TZ="$result"; STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
16) if whiptail --backtitle "$WHIPTITLE" --title "CONFIRMATION" --yesno "Create $APP?" 10 58; then STEP=$((STEP + 1)); else STEP=$((STEP - 1)); fi ;;
esac
done
tput rmcup 2>/dev/null || true
trap - RETURN
}
build_container() {
if [[ "$METHOD" != "advanced" ]]; then
if [[ "$OS_CHOICE" == "debian" ]]; then OS_VERSION="12"; fi
if [[ "$OS_CHOICE" == "debian13" ]]; then OS_CHOICE="debian"; OS_VERSION="13"; fi
if [[ "$OS_CHOICE" == "alpine" ]]; then OS_VERSION="3.20"; fi
if [[ "$OS_CHOICE" == "archlinux" ]]; then OS_VERSION="base"; fi
if [[ "$OS_CHOICE" == "ubuntu" ]]; then OS_VERSION="24.04"; fi
if [[ "$OS_CHOICE" == "fedora" ]]; then OS_VERSION="40"; fi
if [[ "$OS_CHOICE" == "centos" ]]; then OS_VERSION="9"; fi
else
if [[ "$OS_CHOICE" == "debian13" ]]; then OS_CHOICE="debian"; fi
fi
msg_info "Locating Files for $OS_CHOICE"
if [[ "$OS_CHOICE" == "archlinux" ]]; then
pveam update >/dev/null 2>&1
local template_search="archlinux"
else
local template_search="${OS_CHOICE}-${OS_VERSION}"
fi
local template=$(pveam available -section system | grep "$template_search" | awk '{print $2}' | sort -V | tail -n1)
if [[ -z "$template" ]]; then
if [[ "$OS_CHOICE" == "archlinux" ]]; then
template="system/archlinux-base_20240911-1_amd64.tar.zst"
else
msg_error "Template not found in system storage."
exit 1
fi
fi
local template_filename="${template##*/}"
local TEMPLATE_STORAGE=""
local existing_storage=""
while read -r st; do
if pveam list "$st" 2>/dev/null | grep -q "$template_filename"; then
existing_storage="$st"
break
fi
done < <(pvesm status -content vztmpl | awk 'NR>1 {print $1}')
if [[ -n "$existing_storage" ]]; then
TEMPLATE_STORAGE="$existing_storage"
else
select_storage "template"
TEMPLATE_STORAGE="$STORAGE_RESULT"
pveam download "$TEMPLATE_STORAGE" "$template" $STD
fi
msg_info "Welding OS into LXC $CT_ID...."
local VLAN_OPT=""
if [[ -n "$VLAN_TAG" ]]; then
VLAN_OPT=",tag=$VLAN_TAG"
fi
if ! pct create "$CT_ID" "${TEMPLATE_STORAGE}:vztmpl/${template_filename}" \
-hostname "$HN" \
-net0 name=eth0,bridge="$BRG",ip="$NET"${VLAN_OPT} \
-cores "$CORE_COUNT" \
-memory "$RAM_SIZE" \
-rootfs "${CONTAINER_STORAGE:-local}":"$DISK_SIZE" \
-unprivileged "$CT_TYPE" \
-features nesting=1 \
-onboot 1 \
${PW:-} \
$STD; then
msg_error "Provision Failure: Proxmox rejected the build. Verify storage capabilities."
exit 1
fi
if [[ "$ENABLE_TUN" == "1" ]]; then
echo "lxc.cgroup2.devices.allow: c 10:200 rwm" >> /etc/pve/lxc/${CT_ID}.conf
echo "lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file" >> /etc/pve/lxc/${CT_ID}.conf
fi
pct set "$CT_ID" -timezone "$TZ"
pct start "$CT_ID"
if [[ -n "$SSH_KEY" ]]; then
msg_info "Spraying SSH Authorized Keys...."
pct exec "$CT_ID" -- sh -c "mkdir -p /root/.ssh && chmod 700 /root/.ssh && echo '$SSH_KEY' >> /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys"
fi
network_verify "$CT_ID" "lxc"
if [[ "$ENABLE_SSH" == "1" ]]; then
msg_info "Enabling Secure Shell (SSH)..."
if [[ "$OS_CHOICE" == "alpine" ]]; then
pct exec "$CT_ID" -- sh -c "apk add openssh && rc-update add sshd && service sshd start && sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config && service sshd restart" >/dev/null 2>&1
elif [[ "$OS_CHOICE" == "fedora" || "$OS_CHOICE" == "centos" ]]; then
pct exec "$CT_ID" -- sh -c "dnf install -y openssh-server && systemctl enable sshd && systemctl start sshd && sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config && systemctl restart sshd" >/dev/null 2>&1
elif [[ "$OS_CHOICE" == "archlinux" || "$OS_CHOICE" == "arch" ]]; then
pct exec "$CT_ID" -- sh -c "pacman -Sy --noconfirm openssh && systemctl enable sshd && systemctl start sshd && sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config && systemctl restart sshd" >/dev/null 2>&1
else
pct exec "$CT_ID" -- sh -c "apt-get update >/dev/null 2>&1 && apt-get install -y openssh-server >/dev/null 2>&1 && sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config && systemctl restart sshd" >/dev/null 2>&1
fi
fi
}
echo_default() {
msg_info "Provisioning with Defaults for ${GOLD}${APP}${NC}:"
echo -e " ${BLUE}OS Version:${NC} ${GOLD}${OS_CHOICE} ${OS_VERSION}${NC}"
echo -e " ${BLUE}Resources:${NC} ${GOLD}${CORE_COUNT} Cores, ${RAM_SIZE}MB RAM, ${DISK_SIZE}GB Storage${NC}"
echo -e " ${BLUE}Network:${NC} ${GOLD}${NET} on ${BRG}${NC}"
echo -e " ${BLUE}ID & Name:${NC} ${GOLD}LXC ${CT_ID} (${HN})${NC}"
echo ""
sleep 2
}
description() {
local portal="http://${IP_ADDRESSv4}:${PORT:-0000}"
local DESCRIPTION="<div align='center'><h2 style='color: #af8700;'>DYNASTY REVOLUTION</h2><p style='color: #1fd9f0;'>${APP} PROVISIONED</p></div>"
pct set "$CT_ID" -description "$DESCRIPTION" >/dev/null 2>&1
echo -e "\n${GOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e " ${GOLD}${BOLD}PROVISION COMPLETE${NC}"
echo -e " ${BLUE}Access: ${NC} ${GOLD}${portal}${NC}"
if [[ "$ENABLE_SSH" == "1" ]]; then
echo -e " ${BLUE}SSH :${NC} ${GOLD}ssh root@${IP_ADDRESSv4}${NC}"
fi
echo -e " ${BLUE}ID & Name:${NC} ${GOLD}LXC ${CT_ID} (${HN})${NC}"
echo -e " ${BLUE}Log Path:${NC} ${GOLD}${INSTALL_LOG}${NC}"
echo -e "${GOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
}
start() {
variables
if command -v pveversion >/dev/null 2>&1; then
header_info
network_check
github_api_check
check_manifest_updates
NEXTID=$(pvesh get /cluster/nextid)
base_settings
if [[ "$METHOD" == "advanced" ]]; then advanced_settings; else echo_default; fi
build_container
else
Beginning_Remote_Provisioning
fi
}