build.func 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. variables() {
  2. NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces.
  3. var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP.
  4. INTEGER='^[0-9]+([.][0-9]+)?$' # it defines the INTEGER regular expression pattern.
  5. }
  6. # This function sets various color variables using ANSI escape codes for formatting text in the terminal.
  7. color() {
  8. YW=$(echo "\033[33m")
  9. BL=$(echo "\033[36m")
  10. RD=$(echo "\033[01;31m")
  11. BGN=$(echo "\033[4;92m")
  12. GN=$(echo "\033[1;92m")
  13. DGN=$(echo "\033[32m")
  14. CL=$(echo "\033[m")
  15. CM="${GN}✓${CL}"
  16. CROSS="${RD}✗${CL}"
  17. BFR="\\r\\033[K"
  18. HOLD="-"
  19. }
  20. # This function enables error handling in the script by setting options and defining a trap for the ERR signal.
  21. catch_errors() {
  22. set -Eeuo pipefail
  23. trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
  24. }
  25. # This function is called when an error occurs. It receives the exit code, line number, and command that caused the error, and displays an error message.
  26. error_handler() {
  27. local exit_code="$?"
  28. local line_number="$1"
  29. local command="$2"
  30. local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
  31. echo -e "\n$error_message\n"
  32. }
  33. # This function displays an informational message with a yellow color.
  34. msg_info() {
  35. local msg="$1"
  36. echo -ne " ${HOLD} ${YW}${msg}..."
  37. }
  38. # This function displays a success message with a green color.
  39. msg_ok() {
  40. local msg="$1"
  41. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  42. }
  43. # This function displays an error message with a red color.
  44. msg_error() {
  45. local msg="$1"
  46. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  47. }
  48. # Run as root only
  49. check_root() {
  50. if [[ "$(id -u)" -ne 0 || $(ps -o comm= -p $PPID) == "sudo" ]]; then
  51. clear
  52. msg_error "Please run this script as root."
  53. echo -e "\nExiting..."
  54. sleep 2
  55. exit
  56. fi
  57. }
  58. # This function checks the version of Proxmox Virtual Environment (PVE) and exits if the version is not supported.
  59. pve_check() {
  60. if [ $(pveversion | grep "pve-manager/8" | wc -l) -ne 1 ]; then
  61. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Proxmox VE 7 Detected" "You are currently using Proxmox VE 7, refrain from creating Debian 12 LXCs due to differences in locale parameters. \n Default distribution for $APP LXC is ${var_os} ${var_version}" 10 58
  62. fi
  63. if ! pveversion | grep -Eq "pve-manager/(7\.[0-9]|8\.[0-9])"; then
  64. echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported"
  65. echo -e "Requires PVE Version 7.0 or higher"
  66. echo -e "Exiting..."
  67. sleep 2
  68. exit
  69. fi
  70. }
  71. # This function checks the system architecture and exits if it's not "amd64".
  72. arch_check() {
  73. if [ "$(dpkg --print-architecture)" != "amd64" ]; then
  74. echo -e "\n ${CROSS} This script will not work with PiMox! \n"
  75. echo -e "Exiting..."
  76. sleep 2
  77. exit
  78. fi
  79. }
  80. # This function checks if the script is running through SSH and prompts the user to confirm if they want to proceed or exit.
  81. ssh_check() {
  82. if command -v pveversion >/dev/null 2>&1; then
  83. if [ -n "${SSH_CLIENT:+x}" ]; then
  84. if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's suggested to use the Proxmox shell instead of SSH, since SSH can create issues while gathering variables. Would you like to proceed with using SSH?" 10 62; then
  85. echo "you've been warned"
  86. else
  87. clear
  88. exit
  89. fi
  90. fi
  91. fi
  92. }
  93. # This function displays the default values for various settings.
  94. echo_default() {
  95. echo -e "${DGN}Using Distribution: ${BGN}$var_os${CL}"
  96. echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}"
  97. echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  98. echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}"
  99. echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}"
  100. echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}"
  101. echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}"
  102. echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}"
  103. echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}"
  104. echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}"
  105. echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}"
  106. echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}"
  107. echo -e "${DGN}Disable IPv6: ${BGN}No${CL}"
  108. echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}"
  109. echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}"
  110. echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}"
  111. echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}"
  112. echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}"
  113. echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}"
  114. if [[ "$APP" == "Docker" || "$APP" == "Umbrel" || "$APP" == "CasaOS" || "$APP" == "Home Assistant" ]]; then
  115. echo -e "${DGN}Enable Fuse Overlayfs (ZFS): ${BGN}No${CL}"
  116. fi
  117. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  118. echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
  119. }
  120. # This function is called when the user decides to exit the script. It clears the screen and displays an exit message.
  121. exit-script() {
  122. clear
  123. echo -e "⚠ User exited script \n"
  124. exit
  125. }
  126. # This function allows the user to configure advanced settings for the script.
  127. advanced_settings() {
  128. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58
  129. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Default distribution for $APP" "${var_os} \n${var_version} \n" 8 58
  130. if [ "$var_os" != "alpine" ]; then
  131. var_os=""
  132. while [ -z "$var_os" ]; do
  133. if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution:" 10 58 2 \
  134. "debian" "" OFF \
  135. "ubuntu" "" OFF \
  136. 3>&1 1>&2 2>&3); then
  137. if [ -n "$var_os" ]; then
  138. echo -e "${DGN}Using Distribution: ${BGN}$var_os${CL}"
  139. fi
  140. else
  141. exit-script
  142. fi
  143. done
  144. fi
  145. if [ "$var_os" == "debian" ]; then
  146. var_version=""
  147. while [ -z "$var_version" ]; do
  148. if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DEBIAN VERSION" --radiolist "Choose Version" 10 58 2 \
  149. "11" "Bullseye" OFF \
  150. "12" "Bookworm" OFF \
  151. 3>&1 1>&2 2>&3); then
  152. if [ -n "$var_version" ]; then
  153. echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}"
  154. fi
  155. else
  156. exit-script
  157. fi
  158. done
  159. fi
  160. if [ "$var_os" == "ubuntu" ]; then
  161. var_version=""
  162. while [ -z "$var_version" ]; do
  163. if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 3 \
  164. "20.04" "Focal" OFF \
  165. "22.04" "Jammy" OFF \
  166. "23.04" "Lunar" OFF \
  167. 3>&1 1>&2 2>&3); then
  168. if [ -n "$var_version" ]; then
  169. echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}"
  170. fi
  171. else
  172. exit-script
  173. fi
  174. done
  175. fi
  176. CT_TYPE=""
  177. while [ -z "$CT_TYPE" ]; do
  178. if CT_TYPE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \
  179. "1" "Unprivileged" OFF \
  180. "0" "Privileged" OFF \
  181. 3>&1 1>&2 2>&3); then
  182. if [ -n "$CT_TYPE" ]; then
  183. echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  184. fi
  185. else
  186. exit-script
  187. fi
  188. done
  189. if PW1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "\nSet Root Password (needed for root ssh access)" 9 58 --title "PASSWORD(leave blank for automatic login)" 3>&1 1>&2 2>&3); then
  190. if [ -z $PW1 ]; then
  191. PW1="Automatic Login"
  192. PW=""
  193. else
  194. PW="-password $PW1"
  195. fi
  196. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  197. else
  198. exit-script
  199. fi
  200. if CT_ID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" 3>&1 1>&2 2>&3); then
  201. if [ -z "$CT_ID" ]; then
  202. CT_ID="$NEXTID"
  203. echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"
  204. else
  205. echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}"
  206. fi
  207. else
  208. exit
  209. fi
  210. if CT_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" 3>&1 1>&2 2>&3); then
  211. if [ -z "$CT_NAME" ]; then
  212. HN="$NSAPP"
  213. else
  214. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  215. fi
  216. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  217. else
  218. exit-script
  219. fi
  220. if DISK_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" 3>&1 1>&2 2>&3); then
  221. if [ -z "$DISK_SIZE" ]; then
  222. DISK_SIZE="$var_disk"
  223. echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  224. else
  225. if ! [[ $DISK_SIZE =~ $INTEGER ]]; then
  226. echo -e "${RD}⚠ DISK SIZE MUST BE AN INTEGER NUMBER!${CL}"
  227. advanced_settings
  228. fi
  229. echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  230. fi
  231. else
  232. exit-script
  233. fi
  234. if CORE_COUNT=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" 3>&1 1>&2 2>&3); then
  235. if [ -z "$CORE_COUNT" ]; then
  236. CORE_COUNT="$var_cpu"
  237. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  238. else
  239. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  240. fi
  241. else
  242. exit-script
  243. fi
  244. if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" 3>&1 1>&2 2>&3); then
  245. if [ -z "$RAM_SIZE" ]; then
  246. RAM_SIZE="$var_ram"
  247. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  248. else
  249. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  250. fi
  251. else
  252. exit-script
  253. fi
  254. if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3); then
  255. if [ -z "$BRG" ]; then
  256. BRG="vmbr0"
  257. echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  258. else
  259. echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  260. fi
  261. else
  262. exit-script
  263. fi
  264. while true; do
  265. NET=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Static IPv4 CIDR Address (/24)" 8 58 dhcp --title "IP ADDRESS" 3>&1 1>&2 2>&3)
  266. exit_status=$?
  267. if [ $exit_status -eq 0 ]; then
  268. if [ "$NET" = "dhcp" ]; then
  269. echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  270. break
  271. else
  272. if [[ "$NET" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/([0-9]|[1-2][0-9]|3[0-2])$ ]]; then
  273. echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  274. break
  275. else
  276. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "$NET is an invalid IPv4 CIDR address. Please enter a valid IPv4 CIDR address or 'dhcp'" 8 58
  277. fi
  278. fi
  279. else
  280. exit-script
  281. fi
  282. done
  283. if [ "$NET" != "dhcp" ]; then
  284. while true; do
  285. GATE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Enter gateway IP address" 8 58 --title "Gateway IP" 3>&1 1>&2 2>&3)
  286. if [ -z "$GATE1" ]; then
  287. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Gateway IP address cannot be empty" 8 58
  288. elif [[ ! "$GATE1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
  289. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Invalid IP address format" 8 58
  290. else
  291. GATE=",gw=$GATE1"
  292. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  293. break
  294. fi
  295. done
  296. else
  297. GATE=""
  298. echo -e "${DGN}Using Gateway IP Address: ${BGN}Default${CL}"
  299. fi
  300. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then
  301. DISABLEIP6="yes"
  302. else
  303. DISABLEIP6="no"
  304. fi
  305. echo -e "${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}"
  306. if MTU1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" 3>&1 1>&2 2>&3); then
  307. if [ -z $MTU1 ]; then
  308. MTU1="Default"
  309. MTU=""
  310. else
  311. MTU=",mtu=$MTU1"
  312. fi
  313. echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
  314. else
  315. exit-script
  316. fi
  317. if SD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" 3>&1 1>&2 2>&3); then
  318. if [ -z $SD ]; then
  319. SX=Host
  320. SD=""
  321. else
  322. SX=$SD
  323. SD="-searchdomain=$SD"
  324. fi
  325. echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}"
  326. else
  327. exit-script
  328. fi
  329. if NX=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" 3>&1 1>&2 2>&3); then
  330. if [ -z $NX ]; then
  331. NX=Host
  332. NS=""
  333. else
  334. NS="-nameserver=$NX"
  335. fi
  336. echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}"
  337. else
  338. exit-script
  339. fi
  340. if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" 3>&1 1>&2 2>&3); then
  341. if [ -z $MAC1 ]; then
  342. MAC1="Default"
  343. MAC=""
  344. else
  345. MAC=",hwaddr=$MAC1"
  346. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  347. fi
  348. else
  349. exit-script
  350. fi
  351. if VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3); then
  352. if [ -z $VLAN1 ]; then
  353. VLAN1="Default"
  354. VLAN=""
  355. else
  356. VLAN=",tag=$VLAN1"
  357. fi
  358. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  359. else
  360. exit-script
  361. fi
  362. if [[ "$PW" == -password* ]]; then
  363. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then
  364. SSH="yes"
  365. else
  366. SSH="no"
  367. fi
  368. echo -e "${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}"
  369. else
  370. SSH="no"
  371. echo -e "${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}"
  372. fi
  373. if [[ "$APP" == "Docker" || "$APP" == "Umbrel" || "$APP" == "CasaOS" || "$APP" == "Home Assistant" ]]; then
  374. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "FUSE OVERLAYFS" --yesno "(ZFS) Enable Fuse Overlayfs?" 10 58); then
  375. FUSE="yes"
  376. else
  377. FUSE="no"
  378. fi
  379. echo -e "${DGN}Enable Fuse Overlayfs (ZFS): ${BGN}$FUSE${CL}"
  380. fi
  381. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then
  382. VERB="yes"
  383. else
  384. VERB="no"
  385. fi
  386. echo -e "${DGN}Enable Verbose Mode: ${BGN}$VERB${CL}"
  387. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then
  388. echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}"
  389. else
  390. clear
  391. header_info
  392. echo -e "${RD}Using Advanced Settings${CL}"
  393. advanced_settings
  394. fi
  395. }
  396. install_script() {
  397. check_root
  398. ssh_check
  399. arch_check
  400. pve_check
  401. if systemctl is-active -q ping-instances.service; then
  402. systemctl -q stop ping-instances.service
  403. fi
  404. NEXTID=$(pvesh get /cluster/nextid)
  405. timezone=$(cat /etc/timezone)
  406. header_info
  407. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  408. header_info
  409. echo -e "${BL}Using Default Settings${CL}"
  410. default_settings
  411. else
  412. header_info
  413. echo -e "${RD}Using Advanced Settings${CL}"
  414. advanced_settings
  415. fi
  416. }
  417. start() {
  418. if command -v pveversion >/dev/null 2>&1; then
  419. if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
  420. clear
  421. echo -e "⚠ User exited script \n"
  422. exit
  423. fi
  424. install_script
  425. fi
  426. if ! command -v pveversion >/dev/null 2>&1; then
  427. if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC UPDATE" --yesno "Support/Update functions for ${APP} LXC. Proceed?" 10 58); then
  428. clear
  429. echo -e "⚠ User exited script \n"
  430. exit
  431. fi
  432. update_script
  433. fi
  434. }
  435. # This function collects user settings and integrates all the collected information.
  436. build_container() {
  437. if [ "$VERB" == "yes" ]; then set -x; fi
  438. if [[ "$APP" == "Docker" || "$APP" == "Umbrel" || "$APP" == "CasaOS" || "$APP" == "Home Assistant" ]]; then
  439. if [ "$FUSE" == "yes" ]; then
  440. FEATURES="fuse=1,keyctl=1,nesting=1"
  441. else
  442. FEATURES="keyctl=1,nesting=1"
  443. fi
  444. fi
  445. if [[ "$APP" != "Docker" && "$APP" != "Umbrel" && "$APP" != "CasaOS" && "$APP" != "Home Assistant" ]]; then
  446. if [ "$CT_TYPE" == "1" ]; then
  447. FEATURES="keyctl=1,nesting=1"
  448. else
  449. FEATURES="nesting=1"
  450. fi
  451. fi
  452. TEMP_DIR=$(mktemp -d)
  453. pushd $TEMP_DIR >/dev/null
  454. if [ "$var_os" == "alpine" ]; then
  455. export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/alpine-install.func)"
  456. else
  457. export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/install.func)"
  458. fi
  459. export tz="$timezone"
  460. if [[ "$APP" == "Docker" || "$APP" == "Umbrel" || "$APP" == "CasaOS" || "$APP" == "Home Assistant" ]]; then
  461. export ST="$FUSE"
  462. fi
  463. export DISABLEIPV6="$DISABLEIP6"
  464. export APPLICATION="$APP"
  465. export app="$NSAPP"
  466. export PASSWORD="$PW"
  467. export VERBOSE="$VERB"
  468. export SSH_ROOT="${SSH}"
  469. export CTID="$CT_ID"
  470. export CTTYPE="$CT_TYPE"
  471. export PCT_OSTYPE="$var_os"
  472. export PCT_OSVERSION="$var_version"
  473. export PCT_DISK_SIZE="$DISK_SIZE"
  474. export PCT_OPTIONS="
  475. -features $FEATURES
  476. -hostname $HN
  477. -tags proxmox-helper-scripts
  478. $SD
  479. $NS
  480. -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN$MTU
  481. -onboot 1
  482. -cores $CORE_COUNT
  483. -memory $RAM_SIZE
  484. -unprivileged $CT_TYPE
  485. $PW
  486. "
  487. # This executes create_lxc.sh and creates the container and .conf file
  488. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  489. LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
  490. if [ "$CT_TYPE" == "0" ]; then
  491. cat <<EOF >>$LXC_CONFIG
  492. # USB passthrough
  493. lxc.cgroup2.devices.allow: a
  494. lxc.cap.drop:
  495. lxc.cgroup2.devices.allow: c 188:* rwm
  496. lxc.cgroup2.devices.allow: c 189:* rwm
  497. lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir
  498. lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file
  499. lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file
  500. lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file
  501. lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file
  502. EOF
  503. fi
  504. if [ "$CT_TYPE" == "0" ]; then
  505. if [[ "$APP" == "Emby" || "$APP" == "Jellyfin" || "$APP" == "Plex" || "$APP" == "Scrypted" || "$APP" == "Tdarr" || "$APP" == "Unmanic" ]]; then
  506. cat <<EOF >>$LXC_CONFIG
  507. # VAAPI hardware transcoding
  508. lxc.cgroup2.devices.allow: c 226:0 rwm
  509. lxc.cgroup2.devices.allow: c 226:128 rwm
  510. lxc.cgroup2.devices.allow: c 29:0 rwm
  511. lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file
  512. lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir
  513. lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
  514. EOF
  515. fi
  516. fi
  517. # This starts the container and executes <app>-install.sh
  518. msg_info "Starting LXC Container"
  519. pct start "$CTID"
  520. msg_ok "Started LXC Container"
  521. if [ "$var_os" == "alpine" ]; then
  522. sleep 2
  523. pct exec "$CTID" -- ash -c "apk add bash >/dev/null"
  524. fi
  525. lxc-attach -n "$CTID" -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit
  526. }
  527. # This function sets the description of the container.
  528. description() {
  529. IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
  530. pct set "$CTID" -description "# ${APP} LXC
  531. ### https://tteck.github.io/Proxmox/
  532. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/☕-Buy me a coffee-red' /></a>"
  533. if [[ -f /etc/systemd/system/ping-instances.service ]]; then
  534. systemctl start ping-instances.service
  535. fi
  536. }