build.func 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  115. echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
  116. }
  117. # This function is called when the user decides to exit the script. It clears the screen and displays an exit message.
  118. exit-script() {
  119. clear
  120. echo -e "⚠ User exited script \n"
  121. exit
  122. }
  123. # This function allows the user to configure advanced settings for the script.
  124. advanced_settings() {
  125. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58
  126. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Default distribution for $APP" "${var_os} ${var_version} \n \nIf the default Linux distribution is not adhered to, script support will be discontinued. \n" 10 58
  127. if [ "$var_os" != "alpine" ]; then
  128. var_os=""
  129. while [ -z "$var_os" ]; do
  130. if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution:" 10 58 2 \
  131. "debian" "" OFF \
  132. "ubuntu" "" OFF \
  133. 3>&1 1>&2 2>&3); then
  134. if [ -n "$var_os" ]; then
  135. echo -e "${DGN}Using Distribution: ${BGN}$var_os${CL}"
  136. fi
  137. else
  138. exit-script
  139. fi
  140. done
  141. fi
  142. if [ "$var_os" == "debian" ]; then
  143. var_version=""
  144. while [ -z "$var_version" ]; do
  145. if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DEBIAN VERSION" --radiolist "Choose Version" 10 58 2 \
  146. "11" "Bullseye" OFF \
  147. "12" "Bookworm" OFF \
  148. 3>&1 1>&2 2>&3); then
  149. if [ -n "$var_version" ]; then
  150. echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}"
  151. fi
  152. else
  153. exit-script
  154. fi
  155. done
  156. fi
  157. if [ "$var_os" == "ubuntu" ]; then
  158. var_version=""
  159. while [ -z "$var_version" ]; do
  160. if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 3 \
  161. "20.04" "Focal" OFF \
  162. "22.04" "Jammy" OFF \
  163. "23.04" "Lunar" OFF \
  164. 3>&1 1>&2 2>&3); then
  165. if [ -n "$var_version" ]; then
  166. echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}"
  167. fi
  168. else
  169. exit-script
  170. fi
  171. done
  172. fi
  173. CT_TYPE=""
  174. while [ -z "$CT_TYPE" ]; do
  175. if CT_TYPE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \
  176. "1" "Unprivileged" OFF \
  177. "0" "Privileged" OFF \
  178. 3>&1 1>&2 2>&3); then
  179. if [ -n "$CT_TYPE" ]; then
  180. echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  181. fi
  182. else
  183. exit-script
  184. fi
  185. done
  186. 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
  187. if [ -z $PW1 ]; then
  188. PW1="Automatic Login"
  189. PW=""
  190. else
  191. PW="-password $PW1"
  192. fi
  193. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  194. else
  195. exit-script
  196. fi
  197. 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
  198. if [ -z "$CT_ID" ]; then
  199. CT_ID="$NEXTID"
  200. echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"
  201. else
  202. echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}"
  203. fi
  204. else
  205. exit
  206. fi
  207. if CT_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" 3>&1 1>&2 2>&3); then
  208. if [ -z "$CT_NAME" ]; then
  209. HN="$NSAPP"
  210. else
  211. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  212. fi
  213. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  214. else
  215. exit-script
  216. fi
  217. 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
  218. if [ -z "$DISK_SIZE" ]; then
  219. DISK_SIZE="$var_disk"
  220. echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  221. else
  222. if ! [[ $DISK_SIZE =~ $INTEGER ]]; then
  223. echo -e "${RD}⚠ DISK SIZE MUST BE AN INTEGER NUMBER!${CL}"
  224. advanced_settings
  225. fi
  226. echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  227. fi
  228. else
  229. exit-script
  230. fi
  231. 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
  232. if [ -z "$CORE_COUNT" ]; then
  233. CORE_COUNT="$var_cpu"
  234. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  235. else
  236. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  237. fi
  238. else
  239. exit-script
  240. fi
  241. 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
  242. if [ -z "$RAM_SIZE" ]; then
  243. RAM_SIZE="$var_ram"
  244. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  245. else
  246. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  247. fi
  248. else
  249. exit-script
  250. fi
  251. if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3); then
  252. if [ -z "$BRG" ]; then
  253. BRG="vmbr0"
  254. echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  255. else
  256. echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  257. fi
  258. else
  259. exit-script
  260. fi
  261. while true; do
  262. 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)
  263. exit_status=$?
  264. if [ $exit_status -eq 0 ]; then
  265. if [ "$NET" = "dhcp" ]; then
  266. echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  267. break
  268. else
  269. if [[ "$NET" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/([0-9]|[1-2][0-9]|3[0-2])$ ]]; then
  270. echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  271. break
  272. else
  273. 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
  274. fi
  275. fi
  276. else
  277. exit-script
  278. fi
  279. done
  280. if [ "$NET" != "dhcp" ]; then
  281. while true; do
  282. GATE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Enter gateway IP address" 8 58 --title "Gateway IP" 3>&1 1>&2 2>&3)
  283. if [ -z "$GATE1" ]; then
  284. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Gateway IP address cannot be empty" 8 58
  285. elif [[ ! "$GATE1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
  286. whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Invalid IP address format" 8 58
  287. else
  288. GATE=",gw=$GATE1"
  289. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  290. break
  291. fi
  292. done
  293. else
  294. GATE=""
  295. echo -e "${DGN}Using Gateway IP Address: ${BGN}Default${CL}"
  296. fi
  297. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then
  298. DISABLEIP6="yes"
  299. else
  300. DISABLEIP6="no"
  301. fi
  302. echo -e "${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}"
  303. 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
  304. if [ -z $MTU1 ]; then
  305. MTU1="Default"
  306. MTU=""
  307. else
  308. MTU=",mtu=$MTU1"
  309. fi
  310. echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
  311. else
  312. exit-script
  313. fi
  314. 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
  315. if [ -z $SD ]; then
  316. SX=Host
  317. SD=""
  318. else
  319. SX=$SD
  320. SD="-searchdomain=$SD"
  321. fi
  322. echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}"
  323. else
  324. exit-script
  325. fi
  326. 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
  327. if [ -z $NX ]; then
  328. NX=Host
  329. NS=""
  330. else
  331. NS="-nameserver=$NX"
  332. fi
  333. echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}"
  334. else
  335. exit-script
  336. fi
  337. 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
  338. if [ -z $MAC1 ]; then
  339. MAC1="Default"
  340. MAC=""
  341. else
  342. MAC=",hwaddr=$MAC1"
  343. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  344. fi
  345. else
  346. exit-script
  347. fi
  348. 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
  349. if [ -z $VLAN1 ]; then
  350. VLAN1="Default"
  351. VLAN=""
  352. else
  353. VLAN=",tag=$VLAN1"
  354. fi
  355. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  356. else
  357. exit-script
  358. fi
  359. if [[ "$PW" == -password* ]]; then
  360. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then
  361. SSH="yes"
  362. else
  363. SSH="no"
  364. fi
  365. echo -e "${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}"
  366. else
  367. SSH="no"
  368. echo -e "${DGN}Enable Root SSH Access: ${BGN}$SSH${CL}"
  369. fi
  370. if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then
  371. VERB="yes"
  372. else
  373. VERB="no"
  374. fi
  375. echo -e "${DGN}Enable Verbose Mode: ${BGN}$VERB${CL}"
  376. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" 10 58); then
  377. echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}"
  378. else
  379. clear
  380. header_info
  381. echo -e "${RD}Using Advanced Settings${CL}"
  382. advanced_settings
  383. fi
  384. }
  385. install_script() {
  386. check_root
  387. ssh_check
  388. arch_check
  389. pve_check
  390. if systemctl is-active -q ping-instances.service; then
  391. systemctl -q stop ping-instances.service
  392. fi
  393. NEXTID=$(pvesh get /cluster/nextid)
  394. timezone=$(cat /etc/timezone)
  395. header_info
  396. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  397. header_info
  398. echo -e "${BL}Using Default Settings${CL}"
  399. default_settings
  400. else
  401. header_info
  402. echo -e "${RD}Using Advanced Settings${CL}"
  403. advanced_settings
  404. fi
  405. }
  406. start() {
  407. if command -v pveversion >/dev/null 2>&1; then
  408. if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
  409. clear
  410. echo -e "⚠ User exited script \n"
  411. exit
  412. fi
  413. install_script
  414. fi
  415. if ! command -v pveversion >/dev/null 2>&1; then
  416. if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC UPDATE" --yesno "Support/Update functions for ${APP} LXC. Proceed?" 10 58); then
  417. clear
  418. echo -e "⚠ User exited script \n"
  419. exit
  420. fi
  421. update_script
  422. fi
  423. }
  424. # This function collects user settings and integrates all the collected information.
  425. build_container() {
  426. if [ "$VERB" == "yes" ]; then set -x; fi
  427. if [ "$CT_TYPE" == "1" ]; then
  428. FEATURES="keyctl=1,nesting=1"
  429. else
  430. FEATURES="nesting=1"
  431. fi
  432. TEMP_DIR=$(mktemp -d)
  433. pushd $TEMP_DIR >/dev/null
  434. if [ "$var_os" == "alpine" ]; then
  435. export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/alpine-install.func)"
  436. else
  437. export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/install.func)"
  438. fi
  439. export tz="$timezone"
  440. export DISABLEIPV6="$DISABLEIP6"
  441. export APPLICATION="$APP"
  442. export app="$NSAPP"
  443. export PASSWORD="$PW"
  444. export VERBOSE="$VERB"
  445. export SSH_ROOT="${SSH}"
  446. export CTID="$CT_ID"
  447. export CTTYPE="$CT_TYPE"
  448. export PCT_OSTYPE="$var_os"
  449. export PCT_OSVERSION="$var_version"
  450. export PCT_DISK_SIZE="$DISK_SIZE"
  451. export PCT_OPTIONS="
  452. -features $FEATURES
  453. -hostname $HN
  454. -tags proxmox-helper-scripts
  455. $SD
  456. $NS
  457. -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN$MTU
  458. -onboot 1
  459. -cores $CORE_COUNT
  460. -memory $RAM_SIZE
  461. -unprivileged $CT_TYPE
  462. $PW
  463. "
  464. # This executes create_lxc.sh and creates the container and .conf file
  465. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  466. LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
  467. if [ "$CT_TYPE" == "0" ]; then
  468. cat <<EOF >>$LXC_CONFIG
  469. # USB passthrough
  470. lxc.cgroup2.devices.allow: a
  471. lxc.cap.drop:
  472. lxc.cgroup2.devices.allow: c 188:* rwm
  473. lxc.cgroup2.devices.allow: c 189:* rwm
  474. lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir
  475. lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file
  476. lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file
  477. lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file
  478. lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file
  479. EOF
  480. fi
  481. if [ "$CT_TYPE" == "0" ]; then
  482. if [[ "$APP" == "Emby" || "$APP" == "Jellyfin" || "$APP" == "Plex" || "$APP" == "Scrypted" || "$APP" == "Tdarr" || "$APP" == "Unmanic" ]]; then
  483. cat <<EOF >>$LXC_CONFIG
  484. # VAAPI hardware transcoding
  485. lxc.cgroup2.devices.allow: c 226:0 rwm
  486. lxc.cgroup2.devices.allow: c 226:128 rwm
  487. lxc.cgroup2.devices.allow: c 29:0 rwm
  488. lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file
  489. lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir
  490. lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
  491. EOF
  492. fi
  493. fi
  494. # This starts the container and executes <app>-install.sh
  495. msg_info "Starting LXC Container"
  496. pct start "$CTID"
  497. msg_ok "Started LXC Container"
  498. if [ "$var_os" == "alpine" ]; then
  499. sleep 2
  500. pct exec "$CTID" -- ash -c "apk add bash >/dev/null"
  501. fi
  502. lxc-attach -n "$CTID" -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit
  503. }
  504. # This function sets the description of the container.
  505. description() {
  506. IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
  507. pct set "$CTID" -description "<div align='center'><a href='https://Helper-Scripts.com'><img src='https://raw.githubusercontent.com/tteck/Proxmox/main/misc/images/logo-81x112.png'/></a>
  508. # ${APP} LXC
  509. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/&#x2615;-Buy me a coffee-blue' /></a>
  510. </div>"
  511. if [[ -f /etc/systemd/system/ping-instances.service ]]; then
  512. systemctl start ping-instances.service
  513. fi
  514. }