nginx-proxy-manager-v3.sh 12 KB

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