nginx-proxy-manager-v3.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. #!/usr/bin/env bash -ex
  2. set -euo pipefail
  3. shopt -s inherit_errexit nullglob
  4. NEXTID=$(pvesh get /cluster/nextid)
  5. INTEGER='^[0-9]+$'
  6. YW=`echo "\033[33m"`
  7. BL=`echo "\033[36m"`
  8. RD=`echo "\033[01;31m"`
  9. BGN=`echo "\033[4;92m"`
  10. GN=`echo "\033[1;92m"`
  11. DGN=`echo "\033[32m"`
  12. CL=`echo "\033[m"`
  13. BFR="\\r\\033[K"
  14. HOLD="-"
  15. CM="${GN}✓${CL}"
  16. APP="Nginx Proxy Manager"
  17. NSAPP=$(echo ${APP,,} | tr -d ' ')
  18. while true; do
  19. read -p "This will create a New ${APP} LXC. Proceed(y/n)?" yn
  20. case $yn in
  21. [Yy]* ) break;;
  22. [Nn]* ) exit;;
  23. * ) echo "Please answer yes or no.";;
  24. esac
  25. done
  26. clear
  27. function header_info {
  28. echo -e "${RD}
  29. _ _ _____ __ __
  30. | \ | | __ \| \/ |
  31. | \| | |__) | \ / |
  32. | | ___/| |\/| |
  33. | |\ | | | | | |
  34. |_| \_|_| v3 |_| |_|
  35. ${CL}"
  36. }
  37. header_info
  38. function msg_info() {
  39. local msg="$1"
  40. echo -ne " ${HOLD} ${YW}${msg}..."
  41. }
  42. function msg_ok() {
  43. local msg="$1"
  44. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  45. }
  46. function PVE_CHECK() {
  47. PVE=$(pveversion | grep "pve-manager/7" | wc -l)
  48. if [[ $PVE != 1 ]]; then
  49. echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}"
  50. echo -e "Exiting..."
  51. sleep 2
  52. exit
  53. fi
  54. }
  55. function default_settings() {
  56. clear
  57. header_info
  58. echo -e "${BL}Using Default Settings${CL}"
  59. echo -e "${DGN}Using CT Type ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}"
  60. CT_TYPE="1"
  61. echo -e "${DGN}Using CT Password ${BGN}Automatic Login${CL}"
  62. PW=" "
  63. echo -e "${DGN}Using CT ID ${BGN}$NEXTID${CL}"
  64. CT_ID=$NEXTID
  65. echo -e "${DGN}Using CT Name ${BGN}$NSAPP${CL}"
  66. HN=$NSAPP
  67. echo -e "${DGN}Using Disk Size ${BGN}3GB${CL}"
  68. DISK_SIZE="3"
  69. echo -e "${DGN}Using ${BGN}1vCPU${CL}"
  70. CORE_COUNT="1"
  71. echo -e "${DGN}Using ${BGN}1024MiB${CL}${DGN} RAM${CL}"
  72. RAM_SIZE="1024"
  73. echo -e "${DGN}Using Bridge ${BGN}vmbr0${CL}"
  74. BRG="vmbr0"
  75. echo -e "${DGN}Using Static IP Address ${BGN}DHCP${CL}"
  76. NET=dhcp
  77. echo -e "${DGN}Using Gateway Address ${BGN}NONE${CL}"
  78. GATE=""
  79. echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}"
  80. VLAN=""
  81. }
  82. function advanced_settings() {
  83. clear
  84. header_info
  85. echo -e "${RD}Using Advanced Settings${CL}"
  86. echo -e "${YW}Type Privileged, or Press [ENTER] for Default: Unprivileged (${RD}NO DEVICE PASSTHROUGH${CL}${YW})"
  87. read CT_TYPE1
  88. if [ -z $CT_TYPE1 ]; then CT_TYPE1="Unprivileged" CT_TYPE="1";
  89. echo -en "${DGN}Set CT Type ${BL}$CT_TYPE1${CL}"
  90. else
  91. CT_TYPE1="Privileged"
  92. CT_TYPE="0"
  93. echo -en "${DGN}Set CT Type ${BL}Privileged${CL}"
  94. fi;
  95. echo -e " ${CM}${CL} \r"
  96. sleep 1
  97. clear
  98. header_info
  99. echo -e "${RD}Using Advanced Settings${CL}"
  100. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  101. echo -e "${YW}Set Password, or Press [ENTER] for Default: Automatic Login "
  102. read PW1
  103. if [ -z $PW1 ]; then PW1="Automatic Login" PW=" ";
  104. echo -en "${DGN}Set CT ${BL}$PW1${CL}"
  105. else
  106. PW="-password $PW1"
  107. echo -en "${DGN}Set CT Password ${BL}$PW1${CL}"
  108. fi;
  109. echo -e " ${CM}${CL} \r"
  110. sleep 1
  111. clear
  112. header_info
  113. echo -e "${RD}Using Advanced Settings${CL}"
  114. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  115. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  116. echo -e "${YW}Enter the CT ID, or Press [ENTER] to automatically generate (${NEXTID}) "
  117. read CT_ID
  118. if [ -z $CT_ID ]; then CT_ID=$NEXTID; fi;
  119. echo -en "${DGN}Set CT ID To ${BL}$CT_ID${CL}"
  120. echo -e " ${CM}${CL} \r"
  121. sleep 1
  122. clear
  123. header_info
  124. echo -e "${RD}Using Advanced Settings${CL}"
  125. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  126. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  127. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  128. echo -e "${YW}Enter CT Name (no-spaces), or Press [ENTER] for Default: $NSAPP "
  129. read CT_NAME
  130. if [ -z $CT_NAME ]; then
  131. HN=$NSAPP
  132. else
  133. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  134. fi
  135. echo -en "${DGN}Set CT Name To ${BL}$HN${CL}"
  136. echo -e " ${CM}${CL} \r"
  137. sleep 1
  138. clear
  139. header_info
  140. echo -e "${RD}Using Advanced Settings${CL}"
  141. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  142. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  143. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  144. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  145. echo -e "${YW}Enter a Disk Size, or Press [ENTER] for Default: 3Gb "
  146. read DISK_SIZE
  147. if [ -z $DISK_SIZE ]; then DISK_SIZE="3"; fi;
  148. if ! [[ $DISK_SIZE =~ $INTEGER ]] ; then echo "ERROR! DISK SIZE MUST HAVE INTEGER NUMBER!"; exit; fi;
  149. echo -en "${DGN}Set Disk Size To ${BL}$DISK_SIZE${CL}"
  150. echo -e " ${CM}${CL} \r"
  151. sleep 1
  152. clear
  153. header_info
  154. echo -e "${RD}Using Advanced Settings${CL}"
  155. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  156. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  157. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  158. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  159. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  160. echo -e "${YW}Allocate CPU cores, or Press [ENTER] for Default: 1 "
  161. read CORE_COUNT
  162. if [ -z $CORE_COUNT ]; then CORE_COUNT="1"; fi;
  163. echo -en "${DGN}Set Cores To ${BL}$CORE_COUNT${CL}"
  164. echo -e " ${CM}${CL} \r"
  165. sleep 1
  166. clear
  167. header_info
  168. echo -e "${RD}Using Advanced Settings${CL}"
  169. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  170. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  171. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  172. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  173. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  174. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  175. echo -e "${YW}Allocate RAM in MiB, or Press [ENTER] for Default: 1024 "
  176. read RAM_SIZE
  177. if [ -z $RAM_SIZE ]; then RAM_SIZE="1024"; fi;
  178. echo -en "${DGN}Set RAM To ${BL}$RAM_SIZE${CL}"
  179. echo -e " ${CM}${CL} \n"
  180. sleep 1
  181. clear
  182. header_info
  183. echo -e "${RD}Using Advanced Settings${CL}"
  184. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  185. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  186. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  187. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  188. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  189. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  190. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  191. echo -e "${YW}Enter a Bridge, or Press [ENTER] for Default: vmbr0 "
  192. read BRG
  193. if [ -z $BRG ]; then BRG="vmbr0"; fi;
  194. echo -en "${DGN}Set Bridge To ${BL}$BRG${CL}"
  195. echo -e " ${CM}${CL} \n"
  196. sleep 1
  197. clear
  198. header_info
  199. echo -e "${RD}Using Advanced Settings${CL}"
  200. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  201. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  202. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  203. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  204. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  205. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  206. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  207. echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}"
  208. echo -e "${YW}Enter a Static IP Address, or Press [ENTER] for Default: DHCP "
  209. read NET
  210. if [ -z $NET ]; then NET="dhcp"; fi;
  211. echo -en "${DGN}Set Static IP Address To ${BL}$NET${CL}"
  212. echo -e " ${CM}${CL} \n"
  213. sleep 1
  214. clear
  215. header_info
  216. echo -e "${RD}Using Advanced Settings${CL}"
  217. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  218. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  219. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  220. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  221. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  222. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  223. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  224. echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}"
  225. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  226. echo -e "${YW}Enter a Gateway IP, or Press [ENTER] for Default: NONE "
  227. read GATE1
  228. if [ -z $GATE1 ]; then GATE1="NONE" GATE="";
  229. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  230. else
  231. GATE=",gw=$GATE1"
  232. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  233. fi;
  234. echo -e " ${CM}${CL} \n"
  235. sleep 1
  236. clear
  237. header_info
  238. echo -e "${RD}Using Advanced Settings${CL}"
  239. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  240. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  241. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  242. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  243. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  244. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  245. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  246. echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}"
  247. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  248. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  249. echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE "
  250. read VLAN1
  251. if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN="";
  252. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  253. else
  254. VLAN=",tag=$VLAN1"
  255. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  256. fi;
  257. echo -e " ${CM}${CL} \n"
  258. sleep 1
  259. clear
  260. header_info
  261. echo -e "${RD}Using Advanced Settings${CL}"
  262. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  263. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  264. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  265. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  266. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  267. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  268. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  269. echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}"
  270. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  271. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  272. echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}"
  273. read -p "Are these settings correct(y/n)? " -n 1 -r
  274. echo
  275. if [[ ! $REPLY =~ ^[Yy]$ ]]
  276. then
  277. advanced_settings
  278. fi
  279. }
  280. function start_script() {
  281. echo -e "${YW}Type Advanced, or Press [ENTER] for Default Settings "
  282. read SETTINGS
  283. if [ -z $SETTINGS ]; then default_settings;
  284. else
  285. advanced_settings
  286. fi;
  287. }
  288. start_script
  289. if [ "$CT_TYPE" == "1" ]; then
  290. FEATURES="nesting=1,keyctl=1"
  291. else
  292. FEATURES="nesting=1"
  293. fi
  294. TEMP_DIR=$(mktemp -d)
  295. pushd $TEMP_DIR >/dev/null
  296. export CTID=$CT_ID
  297. export PCT_OSTYPE=debian
  298. export PCT_OSVERSION=11
  299. export PCT_DISK_SIZE=$DISK_SIZE
  300. export PCT_OPTIONS="
  301. -features $FEATURES
  302. -hostname $HN
  303. -net0 name=eth0,bridge=$BRG,ip=$NET$GATE$VLAN
  304. -onboot 1
  305. -cores $CORE_COUNT
  306. -memory $RAM_SIZE
  307. -unprivileged $CT_TYPE
  308. $PW
  309. "
  310. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  311. msg_info "Starting LXC Container"
  312. pct start $CTID
  313. msg_ok "Started LXC Container"
  314. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/nginx-proxy-manager-install.sh)" || exit
  315. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  316. msg_ok "Completed Successfully!\n"
  317. echo -e "${APP} should be reachable by going to the following URL.
  318. ${BL}http://${IP}:81${CL} \n"