nginx-proxy-manager-v4.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #!/usr/bin/env bash
  2. echo -e "Loading..."
  3. APP="Nginx Proxy Manager"
  4. var_disk="4"
  5. var_cpu="1"
  6. var_ram="1024"
  7. var_os="debian"
  8. var_version="11"
  9. NSAPP=$(echo ${APP,,} | tr -d ' ')
  10. var_install="${NSAPP}-install"
  11. NEXTID=$(pvesh get /cluster/nextid)
  12. INTEGER='^[0-9]+$'
  13. YW=$(echo "\033[33m")
  14. BL=$(echo "\033[36m")
  15. RD=$(echo "\033[01;31m")
  16. BGN=$(echo "\033[4;92m")
  17. GN=$(echo "\033[1;92m")
  18. DGN=$(echo "\033[32m")
  19. CL=$(echo "\033[m")
  20. BFR="\\r\\033[K"
  21. HOLD="-"
  22. CM="${GN}✓${CL}"
  23. set -o errexit
  24. set -o errtrace
  25. set -o nounset
  26. set -o pipefail
  27. shopt -s expand_aliases
  28. alias die='EXIT=$? LINE=$LINENO error_exit'
  29. trap die ERR
  30. function error_exit() {
  31. trap - ERR
  32. local reason="Unknown failure occurred."
  33. local msg="${1:-$reason}"
  34. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  35. echo -e "$flag $msg" 1>&2
  36. exit $EXIT
  37. }
  38. if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
  39. echo "User selected Yes"
  40. else
  41. clear
  42. echo -e "⚠ User exited script \n"
  43. exit
  44. fi
  45. function header_info {
  46. echo -e "${RD}
  47. _ __ _ ____ __ ___
  48. / | / /___ _(_)___ _ __ / __ \_________ _ ____ __ / |/ /___ _____ ____ _____ ____ _____
  49. / |/ / __ / / __ \| |/_/ / /_/ / ___/ __ \| |/_/ / / / / /|_/ / __ / __ \/ __ / __ / _ \/ ___/
  50. / /| / /_/ / / / / /> < / ____/ / / /_/ /> </ /_/ / / / / / /_/ / / / / /_/ / /_/ / __/ /
  51. /_/ |_/\__, /_/_/ /_/_/|_| /_/ /_/ \____/_/|_|\__, / /_/ /_/\__,_/_/ /_/\__,_/\__, /\___/_/
  52. /____/ v4 /____/ /____/
  53. ${CL}"
  54. }
  55. function msg_info() {
  56. local msg="$1"
  57. echo -ne " ${HOLD} ${YW}${msg}..."
  58. }
  59. function msg_ok() {
  60. local msg="$1"
  61. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  62. }
  63. function PVE_CHECK() {
  64. PVE=$(pveversion | grep "pve-manager/7" | wc -l)
  65. if [[ $PVE != 1 ]]; then
  66. echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}"
  67. echo -e "Exiting..."
  68. sleep 2
  69. exit
  70. fi
  71. }
  72. function ARCH_CHECK() {
  73. ARCH=$(dpkg --print-architecture)
  74. if [[ "$ARCH" != "amd64" ]]; then
  75. echo -e "\n ❌ This script will not work with PiMox! \n"
  76. echo -e "Exiting..."
  77. sleep 2
  78. exit
  79. fi
  80. }
  81. function default_settings() {
  82. echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}"
  83. CT_TYPE="1"
  84. echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}"
  85. PW=""
  86. echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}"
  87. CT_ID=$NEXTID
  88. echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}"
  89. HN=$NSAPP
  90. echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}"
  91. DISK_SIZE="$var_disk"
  92. echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}"
  93. CORE_COUNT="$var_cpu"
  94. echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}"
  95. RAM_SIZE="$var_ram"
  96. echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}"
  97. BRG="vmbr0"
  98. echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}"
  99. NET=dhcp
  100. echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}"
  101. GATE=""
  102. echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}"
  103. SD=""
  104. echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}"
  105. NS=""
  106. echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}"
  107. MAC=""
  108. echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}"
  109. VLAN=""
  110. echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}"
  111. SSH="no"
  112. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  113. VERB="no"
  114. echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
  115. }
  116. function advanced_settings() {
  117. CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \
  118. "1" "Unprivileged" ON \
  119. "0" "Privileged" OFF \
  120. 3>&1 1>&2 2>&3)
  121. exitstatus=$?
  122. if [ $exitstatus = 0 ]; then
  123. echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  124. fi
  125. PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  126. exitstatus=$?
  127. if [ $exitstatus = 0 ]; then
  128. if [ -z $PW1 ]; then
  129. PW1="Automatic Login" PW=" "
  130. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  131. else
  132. PW="-password $PW1"
  133. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  134. fi
  135. fi
  136. CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  137. exitstatus=$?
  138. if [ -z $CT_ID ]; then
  139. CT_ID="$NEXTID"
  140. echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}"
  141. else
  142. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi
  143. fi
  144. CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  145. exitstatus=$?
  146. if [ -z $CT_NAME ]; then
  147. HN="$NSAPP"
  148. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  149. else
  150. if [ $exitstatus = 0 ]; then
  151. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  152. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  153. fi
  154. fi
  155. DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  156. exitstatus=$?
  157. if [ -z $DISK_SIZE ]; then
  158. DISK_SIZE="$var_disk"
  159. echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  160. else
  161. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi
  162. if ! [[ $DISK_SIZE =~ $INTEGER ]]; then
  163. echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}"
  164. advanced_settings
  165. fi
  166. fi
  167. CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  168. exitstatus=$?
  169. if [ -z $CORE_COUNT ]; then
  170. CORE_COUNT="$var_cpu"
  171. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  172. else
  173. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi
  174. fi
  175. RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  176. exitstatus=$?
  177. if [ -z $RAM_SIZE ]; then
  178. RAM_SIZE="$var_ram"
  179. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  180. else
  181. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi
  182. fi
  183. BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  184. exitstatus=$?
  185. if [ -z $BRG ]; then
  186. BRG="vmbr0"
  187. echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  188. else
  189. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi
  190. fi
  191. NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  192. exitstatus=$?
  193. if [ -z $NET ]; then
  194. NET="dhcp"
  195. echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  196. else
  197. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi
  198. fi
  199. GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  200. exitstatus=$?
  201. if [ $exitstatus = 0 ]; then
  202. if [ -z $GATE1 ]; then
  203. GATE1="Default" GATE=""
  204. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  205. else
  206. GATE=",gw=$GATE1"
  207. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  208. fi
  209. fi
  210. SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  211. exitstatus=$?
  212. if [ $exitstatus = 0 ]; then
  213. if [ -z $SD ]; then
  214. SD=""
  215. echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}"
  216. else
  217. SX=$SD
  218. SD="-searchdomain=$SD"
  219. echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}"
  220. fi
  221. fi
  222. NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  223. exitstatus=$?
  224. if [ $exitstatus = 0 ]; then
  225. if [ -z $NS ]; then
  226. NS=""
  227. echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}"
  228. else
  229. NX=$NS
  230. NS="-nameserver=$NS"
  231. echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}"
  232. fi
  233. fi
  234. MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  235. exitstatus=$?
  236. if [ $exitstatus = 0 ]; then
  237. if [ -z $MAC1 ]; then
  238. MAC1="Default" MAC=""
  239. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  240. else
  241. MAC=",hwaddr=$MAC1"
  242. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  243. fi
  244. fi
  245. VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  246. exitstatus=$?
  247. if [ $exitstatus = 0 ]; then
  248. if [ -z $VLAN1 ]; then
  249. VLAN1="Default" VLAN=""
  250. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  251. else
  252. VLAN=",tag=$VLAN1"
  253. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  254. fi
  255. fi
  256. if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then
  257. echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}"
  258. SSH="yes"
  259. else
  260. echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}"
  261. SSH="no"
  262. fi
  263. if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then
  264. echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}"
  265. VERB="yes"
  266. else
  267. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  268. VERB="no"
  269. fi
  270. if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then
  271. echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}"
  272. else
  273. clear
  274. header_info
  275. echo -e "${RD}Using Advanced Settings${CL}"
  276. advanced_settings
  277. fi
  278. }
  279. function start_script() {
  280. if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  281. header_info
  282. echo -e "${BL}Using Default Settings${CL}"
  283. default_settings
  284. else
  285. header_info
  286. echo -e "${RD}Using Advanced Settings${CL}"
  287. advanced_settings
  288. fi
  289. }
  290. clear
  291. start_script
  292. if [ "$VERB" == "yes" ]; then set -x; fi
  293. if [ "$CT_TYPE" == "1" ]; then
  294. FEATURES="nesting=1,keyctl=1"
  295. else
  296. FEATURES="nesting=1"
  297. fi
  298. TEMP_DIR=$(mktemp -d)
  299. pushd $TEMP_DIR >/dev/null
  300. export VERBOSE=$VERB
  301. export SSH_ROOT=${SSH}
  302. export CTID=$CT_ID
  303. export PCT_OSTYPE=$var_os
  304. export PCT_OSVERSION=$var_version
  305. export PCT_DISK_SIZE=$DISK_SIZE
  306. export PCT_OPTIONS="
  307. -features $FEATURES
  308. -hostname $HN
  309. $SD
  310. $NS
  311. -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN
  312. -onboot 1
  313. -cores $CORE_COUNT
  314. -memory $RAM_SIZE
  315. -unprivileged $CT_TYPE
  316. $PW
  317. "
  318. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  319. msg_info "Starting LXC Container"
  320. pct start $CTID
  321. msg_ok "Started LXC Container"
  322. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/nginx-proxy-manager-install.sh)" || exit
  323. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  324. pct set $CTID -description "# ${APP} LXC
  325. ### https://tteck.github.io/Proxmox/
  326. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/☕-Buy me a coffee-red' /></a>"
  327. msg_ok "Completed Successfully!\n"
  328. echo -e "${APP} should be reachable by going to the following URL.
  329. ${BL}http://${IP}:81${CL} \n"