nginxproxymanager.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/env bash
  2. source <(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/build.func)
  3. # Copyright (c) 2021-2023 tteck
  4. # Author: tteck (tteckster)
  5. # License: MIT
  6. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  7. function header_info {
  8. clear
  9. cat <<"EOF"
  10. _ __ _ ____ __ ___
  11. / | / /___ _(_)___ _ __ / __ \_________ __ ____ __ / |/ /___ _____ ____ _____ ____ _____
  12. / |/ / __ / / __ \| |/_/ / /_/ / ___/ __ \| |/_/ / / / / /|_/ / __ / __ \/ __ / __ / _ \/ ___/
  13. / /| / /_/ / / / / /> < / ____/ / / /_/ /> </ /_/ / / / / / /_/ / / / / /_/ / /_/ / __/ /
  14. /_/ |_/\__, /_/_/ /_/_/|_| /_/ /_/ \____/_/|_|\__, / /_/ /_/\__,_/_/ /_/\__,_/\__, /\___/_/
  15. /____/ /____/ /____/
  16. EOF
  17. }
  18. header_info
  19. echo -e "Loading..."
  20. APP="Nginx Proxy Manager"
  21. var_disk="4"
  22. var_cpu="1"
  23. var_ram="1024"
  24. var_os="debian"
  25. var_version="12"
  26. variables
  27. color
  28. catch_errors
  29. function default_settings() {
  30. CT_TYPE="1"
  31. PW=""
  32. CT_ID=$NEXTID
  33. HN=$NSAPP
  34. DISK_SIZE="$var_disk"
  35. CORE_COUNT="$var_cpu"
  36. RAM_SIZE="$var_ram"
  37. BRG="vmbr0"
  38. NET="dhcp"
  39. GATE=""
  40. DISABLEIP6="no"
  41. MTU=""
  42. SD=""
  43. NS=""
  44. MAC=""
  45. VLAN=""
  46. SSH="no"
  47. VERB="no"
  48. echo_default
  49. }
  50. function update_script() {
  51. header_info
  52. if [[ ! -f /lib/systemd/system/npm.service ]]; then
  53. msg_error "No ${APP} Installation Found!"
  54. exit
  55. fi
  56. RELEASE=$(curl -s https://api.github.com/repos/NginxProxyManager/nginx-proxy-manager/releases/latest |
  57. grep "tag_name" |
  58. awk '{print substr($2, 3, length($2)-4) }')
  59. msg_info "Stopping Services"
  60. systemctl stop openresty
  61. systemctl stop npm
  62. msg_ok "Stopped Services"
  63. msg_info "Cleaning Old Files"
  64. rm -rf /app \
  65. /var/www/html \
  66. /etc/nginx \
  67. /var/log/nginx \
  68. /var/lib/nginx \
  69. /var/cache/nginx &>/dev/null
  70. msg_ok "Cleaned Old Files"
  71. msg_info "Downloading NPM v${RELEASE}"
  72. wget -q https://codeload.github.com/NginxProxyManager/nginx-proxy-manager/tar.gz/v${RELEASE} -O - | tar -xz &>/dev/null
  73. cd nginx-proxy-manager-${RELEASE}
  74. msg_ok "Downloaded NPM v${RELEASE}"
  75. msg_info "Setting up Enviroment"
  76. ln -sf /usr/bin/python3 /usr/bin/python
  77. ln -sf /usr/bin/certbot /opt/certbot/bin/certbot
  78. ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
  79. ln -sf /usr/local/openresty/nginx/ /etc/nginx
  80. sed -i "s+0.0.0+${RELEASE}+g" backend/package.json
  81. sed -i "s+0.0.0+${RELEASE}+g" frontend/package.json
  82. sed -i 's+^daemon+#daemon+g' docker/rootfs/etc/nginx/nginx.conf
  83. NGINX_CONFS=$(find "$(pwd)" -type f -name "*.conf")
  84. for NGINX_CONF in $NGINX_CONFS; do
  85. sed -i 's+include conf.d+include /etc/nginx/conf.d+g' "$NGINX_CONF"
  86. done
  87. mkdir -p /var/www/html /etc/nginx/logs
  88. cp -r docker/rootfs/var/www/html/* /var/www/html/
  89. cp -r docker/rootfs/etc/nginx/* /etc/nginx/
  90. cp docker/rootfs/etc/letsencrypt.ini /etc/letsencrypt.ini
  91. cp docker/rootfs/etc/logrotate.d/nginx-proxy-manager /etc/logrotate.d/nginx-proxy-manager
  92. ln -sf /etc/nginx/nginx.conf /etc/nginx/conf/nginx.conf
  93. rm -f /etc/nginx/conf.d/dev.conf
  94. mkdir -p /tmp/nginx/body \
  95. /run/nginx \
  96. /data/nginx \
  97. /data/custom_ssl \
  98. /data/logs \
  99. /data/access \
  100. /data/nginx/default_host \
  101. /data/nginx/default_www \
  102. /data/nginx/proxy_host \
  103. /data/nginx/redirection_host \
  104. /data/nginx/stream \
  105. /data/nginx/dead_host \
  106. /data/nginx/temp \
  107. /var/lib/nginx/cache/public \
  108. /var/lib/nginx/cache/private \
  109. /var/cache/nginx/proxy_temp
  110. chmod -R 777 /var/cache/nginx
  111. chown root /tmp/nginx
  112. echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print ($2 ~ ":")? "["$2"]": $2}' /etc/resolv.conf);" >/etc/nginx/conf.d/include/resolvers.conf
  113. if [ ! -f /data/nginx/dummycert.pem ] || [ ! -f /data/nginx/dummykey.pem ]; then
  114. echo -e "${CHECKMARK} \e[1;92m Generating dummy SSL Certificate... \e[0m"
  115. openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj "/O=Nginx Proxy Manager/OU=Dummy Certificate/CN=localhost" -keyout /data/nginx/dummykey.pem -out /data/nginx/dummycert.pem &>/dev/null
  116. fi
  117. mkdir -p /app/global /app/frontend/images
  118. cp -r backend/* /app
  119. cp -r global/* /app/global
  120. wget -q "https://github.com/just-containers/s6-overlay/releases/download/v3.1.5.0/s6-overlay-noarch.tar.xz"
  121. wget -q "https://github.com/just-containers/s6-overlay/releases/download/v3.1.5.0/s6-overlay-x86_64.tar.xz"
  122. tar -C / -Jxpf s6-overlay-noarch.tar.xz
  123. tar -C / -Jxpf s6-overlay-x86_64.tar.xz
  124. python3 -m pip install --no-cache-dir certbot-dns-cloudflare &>/dev/null
  125. msg_ok "Setup Enviroment"
  126. msg_info "Building Frontend"
  127. cd ./frontend
  128. export NODE_ENV=development
  129. yarn install --network-timeout=30000 &>/dev/null
  130. yarn build &>/dev/null
  131. cp -r dist/* /app/frontend
  132. cp -r app-images/* /app/frontend/images
  133. msg_ok "Built Frontend"
  134. msg_info "Initializing Backend"
  135. rm -rf /app/config/default.json &>/dev/null
  136. if [ ! -f /app/config/production.json ]; then
  137. cat <<'EOF' >/app/config/production.json
  138. {
  139. "database": {
  140. "engine": "knex-native",
  141. "knex": {
  142. "client": "sqlite3",
  143. "connection": {
  144. "filename": "/data/database.sqlite"
  145. }
  146. }
  147. }
  148. }
  149. EOF
  150. fi
  151. cd /app
  152. export NODE_ENV=development
  153. yarn install --network-timeout=30000 &>/dev/null
  154. msg_ok "Initialized Backend"
  155. msg_info "Starting Services"
  156. sed -i 's/user npm/user root/g; s/^pid/#pid/g' /usr/local/openresty/nginx/conf/nginx.conf
  157. sed -i 's/include-system-site-packages = false/include-system-site-packages = true/g' /opt/certbot/pyvenv.cfg
  158. systemctl enable -q --now openresty
  159. systemctl enable -q --now npm
  160. msg_ok "Started Services"
  161. msg_info "Cleaning up"
  162. rm -rf ~/nginx-proxy-manager-* s6-overlay-noarch.tar.xz s6-overlay-x86_64.tar.xz
  163. msg_ok "Cleaned"
  164. msg_ok "Updated Successfully"
  165. exit
  166. }
  167. start
  168. build_container
  169. description
  170. msg_ok "Completed Successfully!\n"
  171. echo -e "${APP} should be reachable by going to the following URL.
  172. ${BL}http://${IP}:81${CL} \n"