nginx-proxy-manager.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #!/usr/bin/env bash
  2. YW=`echo "\033[33m"`
  3. BL=`echo "\033[36m"`
  4. RD=`echo "\033[01;31m"`
  5. CM='\xE2\x9C\x94\033'
  6. GN=`echo "\033[1;92m"`
  7. CL=`echo "\033[m"`
  8. while true; do
  9. read -p "This will create a New Nginx Proxy Manager LXC. Proceed(y/n)?" yn
  10. case $yn in
  11. [Yy]* ) break;;
  12. [Nn]* ) exit;;
  13. * ) echo "Please answer yes or no.";;
  14. esac
  15. done
  16. clear
  17. function header_info {
  18. echo -e "${RD}
  19. _ _ _____ __ __
  20. | \ | | __ \| \/ |
  21. | \| | |__) | \ / |
  22. | | ___/| |\/| |
  23. | |\ | | | | | |
  24. |_| \_|_| |_| |_|
  25. ${CL}"
  26. }
  27. header_info
  28. show_menu(){
  29. printf " ${YW} 1)${YW} Privileged ${CL}\n"
  30. printf " ${YW} 2)${GN} Unprivileged ${CL}\n"
  31. printf "Please choose a Install Method and hit enter or ${RD}x${CL} to exit."
  32. read opt
  33. }
  34. option_picked(){
  35. message1=${@:-"${CL}Error: No message passed"}
  36. printf " ${YW}${message1}${CL}\n"
  37. }
  38. show_menu
  39. while [ $opt != '' ]
  40. do
  41. if [ $opt = '' ]; then
  42. exit;
  43. else
  44. case $opt in
  45. 1) clear;
  46. header_info;
  47. option_picked "Using Privileged Install";
  48. IM=0
  49. break;
  50. ;;
  51. 2) clear;
  52. header_info;
  53. option_picked "Using Unprivileged Install";
  54. IM=1
  55. break;
  56. ;;
  57. x)exit;
  58. ;;
  59. \n)exit;
  60. ;;
  61. *)clear;
  62. option_picked "Please choose a Install Method from the menu";
  63. show_menu;
  64. ;;
  65. esac
  66. fi
  67. done
  68. show_menu2(){
  69. printf " ${YW} 1)${GN} Use Automatic Login ${CL}\n"
  70. printf " ${YW} 2)${GN} Use Password (changeme) ${CL}\n"
  71. printf "Please choose a Password Type and hit enter or ${RD}x${CL} to exit."
  72. read opt
  73. }
  74. option_picked(){
  75. message=${@:-"${CL}Error: No message passed"}
  76. printf " ${YW}${message1}${CL}\n"
  77. printf " ${YW}${message}${CL}\n"
  78. }
  79. show_menu2
  80. while [ $opt != '' ]
  81. do
  82. if [ $opt = '' ]; then
  83. exit;
  84. else
  85. case $opt in
  86. 1) clear;
  87. header_info;
  88. option_picked "Using Automatic Login";
  89. PW=" "
  90. break;
  91. ;;
  92. 2) clear;
  93. header_info;
  94. option_picked "Using Password (changeme)";
  95. PW="-password changeme"
  96. break;
  97. ;;
  98. x)exit;
  99. ;;
  100. \n)exit;
  101. ;;
  102. *)clear;
  103. option_picked "Please choose a Password Type from the menu";
  104. show_menu2;
  105. ;;
  106. esac
  107. fi
  108. done
  109. set -o errexit
  110. set -o errtrace
  111. set -o nounset
  112. set -o pipefail
  113. shopt -s expand_aliases
  114. alias die='EXIT=$? LINE=$LINENO error_exit'
  115. trap die ERR
  116. trap cleanup EXIT
  117. function error_exit() {
  118. trap - ERR
  119. local DEFAULT='Unknown failure occured.'
  120. local REASON="\e[97m${1:-$DEFAULT}\e[39m"
  121. local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE"
  122. msg "$FLAG $REASON"
  123. [ ! -z ${CTID-} ] && cleanup_ctid
  124. exit $EXIT
  125. }
  126. function warn() {
  127. local REASON="\e[97m$1\e[39m"
  128. local FLAG="\e[93m[WARNING]\e[39m"
  129. msg "$FLAG $REASON"
  130. }
  131. function info() {
  132. local REASON="$1"
  133. local FLAG="\e[36m[INFO]\e[39m"
  134. msg "$FLAG $REASON"
  135. }
  136. function msg() {
  137. local TEXT="$1"
  138. echo -e "$TEXT"
  139. }
  140. function cleanup_ctid() {
  141. if $(pct status $CTID &>/dev/null); then
  142. if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then
  143. pct stop $CTID
  144. fi
  145. pct destroy $CTID
  146. elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then
  147. pvesm free $ROOTFS
  148. fi
  149. }
  150. function cleanup() {
  151. popd >/dev/null
  152. rm -rf $TEMP_DIR
  153. }
  154. if [ "$IM" == "1" ]; then
  155. FEATURES="nesting=1,keyctl=1"
  156. else
  157. FEATURES="nesting=1"
  158. fi
  159. TEMP_DIR=$(mktemp -d)
  160. pushd $TEMP_DIR >/dev/null
  161. export CTID=$(pvesh get /cluster/nextid)
  162. export PCT_OSTYPE=debian
  163. export PCT_OSVERSION=11
  164. export PCT_DISK_SIZE=3
  165. export PCT_OPTIONS="
  166. -features $FEATURES
  167. -hostname npm
  168. -net0 name=eth0,bridge=vmbr0,ip=dhcp
  169. -onboot 1
  170. -cores 1
  171. -memory 1024
  172. -unprivileged ${IM}
  173. ${PW}
  174. "
  175. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  176. STORAGE_TYPE=$(pvesm status -storage $(pct config $CTID | grep rootfs | awk -F ":" '{print $2}') | awk 'NR>1 {print $2}')
  177. if [ "$STORAGE_TYPE" == "zfspool" ]; then
  178. warn "Some addons may not work due to ZFS not supporting 'fallocate'."
  179. fi
  180. echo -en "${GN} Starting LXC Container... "
  181. pct start $CTID
  182. echo -e "${CM}${CL} \r"
  183. alias lxc-cmd="lxc-attach -n $CTID --"
  184. lxc-cmd bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/nginx-proxy-manager-install.sh)" || exit
  185. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  186. echo -e "${GN}Successfully created Nginx Proxy Manager LXC to${CL} ${BL}$CTID${CL}.
  187. Nginx Proxy Manager should be reachable by going to the following URL.
  188. ${BL}http://${IP}:81${CL} \n"