build.func 18 KB

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