nginx-proxy-manager-v3.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 Bridge, or Press [ENTER] for Default: vmbr0 "
  190. read BRG
  191. if [ -z $BRG ]; then BRG="vmbr0"; fi;
  192. echo -en "${DGN}Set Bridge To ${BL}$BRG${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 Bridge ${BGN}${BRG}${CL}"
  206. echo -e "${YW}Enter a Static IP Address, or Press [ENTER] for Default: DHCP "
  207. read NET
  208. if [ -z $NET ]; then NET="dhcp"; fi;
  209. echo -en "${DGN}Set Static IP Address To ${BL}$NET${CL}"
  210. echo -e " ${CM}${CL} \n"
  211. sleep 1
  212. clear
  213. header_info
  214. echo -e "${RD}Using Advanced Settings${CL}"
  215. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  216. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  217. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  218. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  219. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  220. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  221. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  222. echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}"
  223. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  224. echo -e "${YW}Enter a Gateway IP, or Press [ENTER] for Default: NONE "
  225. read GATE1
  226. if [ -z $GATE1 ]; then GATE1="NONE" GATE="";
  227. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  228. else
  229. GATE=",gw=$GATE1"
  230. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  231. fi;
  232. echo -e " ${CM}${CL} \n"
  233. sleep 1
  234. clear
  235. header_info
  236. echo -e "${RD}Using Advanced Settings${CL}"
  237. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  238. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  239. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  240. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  241. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  242. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  243. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  244. echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}"
  245. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  246. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  247. echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE "
  248. read VLAN1
  249. if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN="";
  250. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  251. else
  252. VLAN=",tag=$VLAN1"
  253. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  254. fi;
  255. echo -e " ${CM}${CL} \n"
  256. sleep 1
  257. clear
  258. header_info
  259. echo -e "${RD}Using Advanced Settings${CL}"
  260. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  261. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  262. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  263. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  264. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  265. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  266. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  267. echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}"
  268. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  269. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  270. echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}"
  271. read -p "Are these settings correct(y/n)? " -n 1 -r
  272. echo
  273. if [[ ! $REPLY =~ ^[Yy]$ ]]
  274. then
  275. advanced_settings
  276. fi
  277. }
  278. function start_script() {
  279. echo -e "${YW}Type Advanced, or Press [ENTER] for Default Settings "
  280. read SETTINGS
  281. if [ -z $SETTINGS ]; then default_settings;
  282. else
  283. advanced_settings
  284. fi;
  285. }
  286. start_script
  287. if [ "$CT_TYPE" == "1" ]; then
  288. FEATURES="nesting=1,keyctl=1"
  289. else
  290. FEATURES="nesting=1"
  291. fi
  292. TEMP_DIR=$(mktemp -d)
  293. pushd $TEMP_DIR >/dev/null
  294. export CTID=$CT_ID
  295. export PCT_OSTYPE=debian
  296. export PCT_OSVERSION=11
  297. export PCT_DISK_SIZE=$DISK_SIZE
  298. export PCT_OPTIONS="
  299. -features $FEATURES
  300. -hostname $HN
  301. -net0 name=eth0,bridge=$BRG,ip=$NET$GATE$VLAN
  302. -onboot 1
  303. -cores $CORE_COUNT
  304. -memory $RAM_SIZE
  305. -unprivileged $CT_TYPE
  306. $PW
  307. "
  308. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  309. msg_info "Starting LXC Container"
  310. pct start $CTID
  311. msg_ok "Started LXC Container"
  312. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/nginx-proxy-manager-install.sh)" || exit
  313. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  314. msg_ok "Completed Successfully!\n"
  315. echo -e "${APP} should be reachable by going to the following URL.
  316. ${BL}http://${IP}:81${CL} \n"