build.func 18 KB

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