nginx-proxy-manager.sh 5.3 KB

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