nginx-proxy-manager.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. message=${@:-"${CL}Error: No message passed"}
  38. printf " ${YW}${message}${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. set -o errexit
  71. set -o errtrace
  72. set -o nounset
  73. set -o pipefail
  74. shopt -s expand_aliases
  75. alias die='EXIT=$? LINE=$LINENO error_exit'
  76. trap die ERR
  77. trap cleanup EXIT
  78. function error_exit() {
  79. trap - ERR
  80. local DEFAULT='Unknown failure occured.'
  81. local REASON="\e[97m${1:-$DEFAULT}\e[39m"
  82. local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE"
  83. msg "$FLAG $REASON"
  84. [ ! -z ${CTID-} ] && cleanup_ctid
  85. exit $EXIT
  86. }
  87. function warn() {
  88. local REASON="\e[97m$1\e[39m"
  89. local FLAG="\e[93m[WARNING]\e[39m"
  90. msg "$FLAG $REASON"
  91. }
  92. function info() {
  93. local REASON="$1"
  94. local FLAG="\e[36m[INFO]\e[39m"
  95. msg "$FLAG $REASON"
  96. }
  97. function msg() {
  98. local TEXT="$1"
  99. echo -e "$TEXT"
  100. }
  101. function cleanup_ctid() {
  102. if $(pct status $CTID &>/dev/null); then
  103. if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then
  104. pct stop $CTID
  105. fi
  106. pct destroy $CTID
  107. elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then
  108. pvesm free $ROOTFS
  109. fi
  110. }
  111. function cleanup() {
  112. popd >/dev/null
  113. rm -rf $TEMP_DIR
  114. }
  115. if [ "$IM" == "1" ]; then
  116. FEATURES="nesting=1,keyctl=1,mknod=1"
  117. else
  118. FEATURES="nesting=1"
  119. fi
  120. TEMP_DIR=$(mktemp -d)
  121. pushd $TEMP_DIR >/dev/null
  122. export CTID=$(pvesh get /cluster/nextid)
  123. export PCT_OSTYPE=debian
  124. export PCT_OSVERSION=11
  125. export PCT_DISK_SIZE=3
  126. export PCT_OPTIONS="
  127. -features $FEATURES
  128. -hostname npm
  129. -net0 name=eth0,bridge=vmbr0,ip=dhcp
  130. -onboot 1
  131. -cores 1
  132. -memory 1024
  133. -unprivileged ${IM}
  134. "
  135. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  136. STORAGE_TYPE=$(pvesm status -storage $(pct config $CTID | grep rootfs | awk -F ":" '{print $2}') | awk 'NR>1 {print $2}')
  137. if [ "$STORAGE_TYPE" == "zfspool" ]; then
  138. warn "Some addons may not work due to ZFS not supporting 'fallocate'."
  139. fi
  140. echo -en "${GN} Starting LXC Container... "
  141. pct start $CTID
  142. echo -e "${CM}${CL} \r"
  143. alias lxc-cmd="lxc-attach -n $CTID --"
  144. lxc-cmd bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/nginx-proxy-manager-install.sh)" || exit
  145. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  146. echo -e "${GN}Successfully created Nginx Proxy Manager LXC to${CL} ${BL}$CTID${CL}.
  147. Nginx Proxy Manager should be reachable by going to the following URL.
  148. ${BL}http://${IP}:81${CL} \n"