nginx-proxy-manager-v3.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 Static IP Address ${BGN}DHCP${CL}"
  74. NET=dhcp
  75. echo -e "${DGN}Using Gateway Address ${BGN}NONE${CL}"
  76. GATE=""
  77. echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}"
  78. VLAN=""
  79. }
  80. function advanced_settings() {
  81. clear
  82. header_info
  83. echo -e "${RD}Using Advanced Settings${CL}"
  84. echo -e "${YW}Type Privileged, or Press [ENTER] for Default: Unprivileged (${RD}NO DEVICE PASSTHROUGH${CL}${YW})"
  85. read CT_TYPE1
  86. if [ -z $CT_TYPE1 ]; then CT_TYPE1="Unprivileged" CT_TYPE="1";
  87. echo -en "${DGN}Set CT Type ${BL}$CT_TYPE1${CL}"
  88. else
  89. CT_TYPE1="Privileged"
  90. CT_TYPE="0"
  91. echo -en "${DGN}Set CT Type ${BL}Privileged${CL}"
  92. fi;
  93. echo -e " ${CM}${CL} \r"
  94. sleep 1
  95. clear
  96. header_info
  97. echo -e "${RD}Using Advanced Settings${CL}"
  98. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  99. echo -e "${YW}Set Password, or Press [ENTER] for Default: Automatic Login "
  100. read PW1
  101. if [ -z $PW1 ]; then PW1="Automatic Login" PW=" ";
  102. echo -en "${DGN}Set CT ${BL}$PW1${CL}"
  103. else
  104. PW="-password $PW1"
  105. echo -en "${DGN}Set CT Password ${BL}$PW1${CL}"
  106. fi;
  107. echo -e " ${CM}${CL} \r"
  108. sleep 1
  109. clear
  110. header_info
  111. echo -e "${RD}Using Advanced Settings${CL}"
  112. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  113. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  114. echo -e "${YW}Enter the CT ID, or Press [ENTER] to automatically generate (${NEXTID}) "
  115. read CT_ID
  116. if [ -z $CT_ID ]; then CT_ID=$NEXTID; fi;
  117. echo -en "${DGN}Set CT ID To ${BL}$CT_ID${CL}"
  118. echo -e " ${CM}${CL} \r"
  119. sleep 1
  120. clear
  121. header_info
  122. echo -e "${RD}Using Advanced Settings${CL}"
  123. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  124. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  125. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  126. echo -e "${YW}Enter CT Name (no-spaces), or Press [ENTER] for Default: $NSAPP "
  127. read CT_NAME
  128. if [ -z $CT_NAME ]; then
  129. HN=$NSAPP
  130. else
  131. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  132. fi
  133. echo -en "${DGN}Set CT Name To ${BL}$HN${CL}"
  134. echo -e " ${CM}${CL} \r"
  135. sleep 1
  136. clear
  137. header_info
  138. echo -e "${RD}Using Advanced Settings${CL}"
  139. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  140. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  141. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  142. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  143. echo -e "${YW}Enter a Disk Size, or Press [ENTER] for Default: 3Gb "
  144. read DISK_SIZE
  145. if [ -z $DISK_SIZE ]; then DISK_SIZE="3"; fi;
  146. if ! [[ $DISK_SIZE =~ $INTEGER ]] ; then echo "ERROR! DISK SIZE MUST HAVE INTEGER NUMBER!"; exit; fi;
  147. echo -en "${DGN}Set Disk Size To ${BL}$DISK_SIZE${CL}"
  148. echo -e " ${CM}${CL} \r"
  149. sleep 1
  150. clear
  151. header_info
  152. echo -e "${RD}Using Advanced Settings${CL}"
  153. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  154. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  155. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  156. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  157. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  158. echo -e "${YW}Allocate CPU cores, or Press [ENTER] for Default: 1 "
  159. read CORE_COUNT
  160. if [ -z $CORE_COUNT ]; then CORE_COUNT="1"; fi;
  161. echo -en "${DGN}Set Cores To ${BL}$CORE_COUNT${CL}"
  162. echo -e " ${CM}${CL} \r"
  163. sleep 1
  164. clear
  165. header_info
  166. echo -e "${RD}Using Advanced Settings${CL}"
  167. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  168. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  169. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  170. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  171. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  172. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  173. echo -e "${YW}Allocate RAM in MiB, or Press [ENTER] for Default: 1024 "
  174. read RAM_SIZE
  175. if [ -z $RAM_SIZE ]; then RAM_SIZE="1024"; fi;
  176. echo -en "${DGN}Set RAM To ${BL}$RAM_SIZE${CL}"
  177. echo -e " ${CM}${CL} \n"
  178. sleep 1
  179. clear
  180. header_info
  181. echo -e "${RD}Using Advanced Settings${CL}"
  182. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  183. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  184. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  185. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  186. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  187. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  188. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  189. echo -e "${YW}Enter a Static IP Address, or Press [ENTER] for Default: DHCP "
  190. read NET
  191. if [ -z $NET ]; then NET="dhcp"; fi;
  192. echo -en "${DGN}Set Static IP Address To ${BL}$NET${CL}"
  193. echo -e " ${CM}${CL} \n"
  194. sleep 1
  195. clear
  196. header_info
  197. echo -e "${RD}Using Advanced Settings${CL}"
  198. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  199. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  200. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  201. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  202. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  203. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  204. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  205. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  206. echo -e "${YW}Enter a Gateway IP, or Press [ENTER] for Default: NONE "
  207. read GATE1
  208. if [ -z $GATE1 ]; then GATE1="NONE" GATE="";
  209. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  210. else
  211. GATE=",gw=$GATE1"
  212. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  213. fi;
  214. echo -e " ${CM}${CL} \n"
  215. sleep 1
  216. clear
  217. header_info
  218. echo -e "${RD}Using Advanced Settings${CL}"
  219. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  220. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  221. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  222. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  223. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  224. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  225. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  226. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  227. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  228. echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE "
  229. read VLAN1
  230. if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN="";
  231. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  232. else
  233. VLAN=",tag=$VLAN1"
  234. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  235. fi;
  236. echo -e " ${CM}${CL} \n"
  237. sleep 1
  238. clear
  239. header_info
  240. echo -e "${RD}Using Advanced Settings${CL}"
  241. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  242. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  243. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  244. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  245. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  246. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  247. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  248. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  249. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  250. echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}"
  251. read -p "Are these settings correct(y/n)? " -n 1 -r
  252. echo
  253. if [[ ! $REPLY =~ ^[Yy]$ ]]
  254. then
  255. advanced_settings
  256. fi
  257. }
  258. function start_script() {
  259. echo -e "${YW}Type Advanced, or Press [ENTER] for Default Settings "
  260. read SETTINGS
  261. if [ -z $SETTINGS ]; then default_settings;
  262. else
  263. advanced_settings
  264. fi;
  265. }
  266. start_script
  267. if [ "$CT_TYPE" == "1" ]; then
  268. FEATURES="nesting=1,keyctl=1"
  269. else
  270. FEATURES="nesting=1"
  271. fi
  272. TEMP_DIR=$(mktemp -d)
  273. pushd $TEMP_DIR >/dev/null
  274. export CTID=$CT_ID
  275. export PCT_OSTYPE=debian
  276. export PCT_OSVERSION=11
  277. export PCT_DISK_SIZE=$DISK_SIZE
  278. export PCT_OPTIONS="
  279. -features $FEATURES
  280. -hostname $HN
  281. -net0 name=eth0,bridge=vmbr0,ip=$NET$GATE$VLAN
  282. -onboot 1
  283. -cores $CORE_COUNT
  284. -memory $RAM_SIZE
  285. -unprivileged $CT_TYPE
  286. $PW
  287. "
  288. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  289. msg_info "Starting LXC Container"
  290. pct start $CTID
  291. msg_ok "Started LXC Container"
  292. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/nginx-proxy-manager-install.sh)" || exit
  293. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  294. msg_ok "Completed Successfully!\n"
  295. echo -e "${APP} should be reachable by going to the following URL.
  296. ${BL}http://${IP}:81${CL} \n"