From 2144c06fcf4cdb730fc1ba50676e56aece6327c1 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Sat, 2 Sep 2023 17:06:12 +0200 Subject: [PATCH] nginx update --- webtop_kde/config.json | 4 +- .../etc/cont-init.d/00-data_location.sh | 68 ------------------ .../rootfs/etc/cont-init.d/20-folders.sh | 70 +++++++++++++++++-- .../rootfs/etc/cont-init.d/90-ingress.sh | 29 ++------ webtop_kde/rootfs/etc/nginx/nginx.conf | 53 -------------- webtop_kde/rootfs/etc/services.d/nginx/finish | 8 --- webtop_kde/rootfs/etc/services.d/nginx/run | 10 --- 7 files changed, 72 insertions(+), 170 deletions(-) delete mode 100755 webtop_kde/rootfs/etc/cont-init.d/00-data_location.sh delete mode 100644 webtop_kde/rootfs/etc/nginx/nginx.conf delete mode 100644 webtop_kde/rootfs/etc/services.d/nginx/finish delete mode 100644 webtop_kde/rootfs/etc/services.d/nginx/run diff --git a/webtop_kde/config.json b/webtop_kde/config.json index d75eab5db..ee629cdba 100644 --- a/webtop_kde/config.json +++ b/webtop_kde/config.json @@ -117,6 +117,6 @@ }, "slug": "webtop-kde", "url": "https://github.com/alexbelgium/hassio-addons", - "version": "4.16-r0-ls89-test10", + "version": "4.16-r0-ls89-test11", "video": true -} +} \ No newline at end of file diff --git a/webtop_kde/rootfs/etc/cont-init.d/00-data_location.sh b/webtop_kde/rootfs/etc/cont-init.d/00-data_location.sh deleted file mode 100755 index 1597218c0..000000000 --- a/webtop_kde/rootfs/etc/cont-init.d/00-data_location.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash -# shellcheck disable=SC2046 - -# Define user -PUID=$(bashio::config "PUID") -PGID=$(bashio::config "PGID") - -# Check data location -LOCATION=$(bashio::config 'data_location') - -if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then - # Default location - LOCATION="/share/webtop_kde" -else - bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually" - - # Check if config is located in an acceptable location - LOCATIONOK="" - for location in "/share" "/config" "/data" "/mnt"; do - if [[ "$LOCATION" == "$location"* ]]; then - LOCATIONOK=true - fi - done - - if [ -z "$LOCATIONOK" ]; then - LOCATION="/share/webtop_kde" - bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION" - fi - -fi - -# Set data location -bashio::log.info "Setting data location to $LOCATION" - -# Correct home locations -for file in /etc/s6-overlay/s6-rc.d/*/run; do - if [ "$(sed -n '1{/bash/p};q' "$file")" ]; then - sed -i "1a export HOME=$LOCATION" "$file" - sed -i "1a export FM_HOME=$LOCATION" "$file" - fi -done - -# Correct home location -for folders in /defaults /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d; do - if [ -d "$folders" ]; then - sed -i "s|/share/webtop_kde|$LOCATION|g" $(find "$folders" -type f) - fi -done - -# Change user home -usermod --home "$LOCATION" abc - -# Add environment variables -if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/HOME; fi -if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/FM_HOME; fi -{ - printf "%s" "HOME=\"$LOCATION\"" - printf "%s" "FM_HOME=\"$LOCATION\"" -} >> ~/.bashrc - -# Create folder -echo "Creating $LOCATION" -mkdir -p "$LOCATION" - -# Set ownership -bashio::log.info "Setting ownership to $PUID:$PGID" -chown -R "$PUID":"$PGID" "$LOCATION" diff --git a/webtop_kde/rootfs/etc/cont-init.d/20-folders.sh b/webtop_kde/rootfs/etc/cont-init.d/20-folders.sh index 1dd6488e4..402bc252a 100755 --- a/webtop_kde/rootfs/etc/cont-init.d/20-folders.sh +++ b/webtop_kde/rootfs/etc/cont-init.d/20-folders.sh @@ -1,10 +1,68 @@ #!/usr/bin/with-contenv bashio # shellcheck shell=bash +# shellcheck disable=SC2046 -# Define home -HOME="/share/webtop_kde" -mkdir -p $HOME -chown -R abc:abc $HOME +# Define user +PUID=$(bashio::config "PUID") +PGID=$(bashio::config "PGID") -#adduser USERNAME -#useradd -m abc -p abc +# Check data location +LOCATION=$(bashio::config 'data_location') + +if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then + # Default location + LOCATION="/share/webtop_kde" +else + bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually" + + # Check if config is located in an acceptable location + LOCATIONOK="" + for location in "/share" "/config" "/data" "/mnt"; do + if [[ "$LOCATION" == "$location"* ]]; then + LOCATIONOK=true + fi + done + + if [ -z "$LOCATIONOK" ]; then + LOCATION="/share/webtop_kde" + bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION" + fi + +fi + +# Set data location +bashio::log.info "Setting data location to $LOCATION" + +# Correct home locations +for file in /etc/s6-overlay/s6-rc.d/*/run; do + if [ "$(sed -n '1{/bash/p};q' "$file")" ]; then + sed -i "1a export HOME=$LOCATION" "$file" + sed -i "1a export FM_HOME=$LOCATION" "$file" + fi +done + +# Correct home location +for folders in /defaults /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d; do + if [ -d "$folders" ]; then + sed -i "s|/share/webtop_kde|$LOCATION|g" $(find "$folders" -type f) + fi +done + +# Change user home +usermod --home "$LOCATION" abc + +# Add environment variables +if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/HOME; fi +if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/FM_HOME; fi +{ + printf "%s" "HOME=\"$LOCATION\"" + printf "%s" "FM_HOME=\"$LOCATION\"" +} >> ~/.bashrc + +# Create folder +echo "Creating $LOCATION" +mkdir -p "$LOCATION" + +# Set ownership +bashio::log.info "Setting ownership to $PUID:$PGID" +chown -R "$PUID":"$PGID" "$LOCATION" diff --git a/webtop_kde/rootfs/etc/cont-init.d/90-ingress.sh b/webtop_kde/rootfs/etc/cont-init.d/90-ingress.sh index d84fe80db..dce771666 100755 --- a/webtop_kde/rootfs/etc/cont-init.d/90-ingress.sh +++ b/webtop_kde/rootfs/etc/cont-init.d/90-ingress.sh @@ -2,41 +2,24 @@ # shellcheck shell=bash # nginx Path -NGINX_CONFIG=/etc/nginx/http.d/ingress.conf +NGINX_CONFIG=/etc/nginx/sites-available/ingress.conf # user passed env vars CPORT="${CUSTOM_PORT:-3000}" CHPORT="${CUSTOM_HTTPS_PORT:-3001}" CUSER="${CUSTOM_USER:-abc}" -# create self signed cert -if [ ! -f "/config/ssl/cert.pem" ]; then - mkdir -p /config/ssl - openssl req -new -x509 \ - -days 3650 -nodes \ - -out /config/ssl/cert.pem \ - -keyout /config/ssl/cert.key \ - -subj "/C=US/ST=CA/L=Carlsbad/O=Linuxserver.io/OU=LSIO Server/CN=*" - chmod 600 /config/ssl/cert.key - chown -R abc:abc /config/ssl -fi - # modify nginx config cp /defaults/default.conf ${NGINX_CONFIG} -sed -i "s/3000/$CPORT/g" ${NGINX_CONFIG} -sed -i "s/3001/$CHPORT/g" ${NGINX_CONFIG} -if [ ! -z ${DISABLE_IPV6+x} ]; then - sed -i '/listen \[::\]/d' ${NGINX_CONFIG} -fi -if [ ! -z ${PASSWORD+x} ]; then - printf "${CUSER}:$(openssl passwd -apr1 ${PASSWORD})\n" > /etc/nginx/.htpasswd - sed -i 's/#//g' ${NGINX_CONFIG} -fi +sed -i '/listen \[::\]/d' ${NGINX_CONFIG} # Add ingress parameters sed -i '/server {/a include /etc/nginx/includes/server_params.conf;' ${NGINX_CONFIG} sed -i '/server {/a include /etc/nginx/includes/proxy_params.conf;;' ${NGINX_CONFIG} -sed -i 's|3000 default_server;|%%interface%%:%%port%% default_server;|g' ${NGINX_CONFIG} +sed -i 's|3000 default_server;|%%port%% default_server;|g' ${NGINX_CONFIG} # Implement SUBFOLDER value sed -i "1a SUBFOLDER=$(bashio::addon.ingress_url)" /etc/s6-overlay/s6-rc.d/svc-autostart/run || true + +# Enable ingress +cp /etc/nginx/sites-available/ingress.conf /etc/nginx/sites-enabled diff --git a/webtop_kde/rootfs/etc/nginx/nginx.conf b/webtop_kde/rootfs/etc/nginx/nginx.conf deleted file mode 100644 index b79994692..000000000 --- a/webtop_kde/rootfs/etc/nginx/nginx.conf +++ /dev/null @@ -1,53 +0,0 @@ -# This is run inside Docker. -user root; - -# Pid storage location. -pid /var/run/nginx.pid; - -# Set number of worker processes. -worker_processes 1; - -# Enables the use of JIT for regular expressions to speed-up their processing. -pcre_jit on; - -# Write error log to Hass.io add-on log. -error_log /proc/1/fd/1 error; - -# Load allowed environment vars -env HASSIO_TOKEN; - -# Load dynamic modules. -include /etc/nginx/modules/*.conf; - -# Max num of simultaneous connections by a worker process. -events { - worker_connections 512; -} - -http { - include /etc/nginx/includes/mime.types; - - log_format hassio '[$time_local] $status ' - '$http_x_forwarded_for($remote_addr) ' - '$request ($http_user_agent)'; - - access_log /proc/1/fd/1 hassio; - client_max_body_size 4G; - default_type application/octet-stream; - gzip on; - keepalive_timeout 65; - sendfile on; - server_tokens off; - tcp_nodelay on; - tcp_nopush on; - - map $http_upgrade $connection_upgrade { - default upgrade; - '' close; - } - - include /etc/nginx/includes/resolver.conf; - include /etc/nginx/includes/upstream.conf; - - include /etc/nginx/servers/*.conf; -} diff --git a/webtop_kde/rootfs/etc/services.d/nginx/finish b/webtop_kde/rootfs/etc/services.d/nginx/finish deleted file mode 100644 index 444240135..000000000 --- a/webtop_kde/rootfs/etc/services.d/nginx/finish +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/execlineb -S0 -# ============================================================================== -# Take down the S6 supervision tree when Nginx fails -# ============================================================================== -if { s6-test ${1} -ne 0 } -if { s6-test ${1} -ne 256 } - -s6-svscanctl -t /var/run/s6/services diff --git a/webtop_kde/rootfs/etc/services.d/nginx/run b/webtop_kde/rootfs/etc/services.d/nginx/run deleted file mode 100644 index 7e55c9ca6..000000000 --- a/webtop_kde/rootfs/etc/services.d/nginx/run +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash -# ============================================================================== - -# Wait for transmission to become available -bashio::net.wait_for 3000 localhost 900 - -bashio::log.info "Starting NGinx..." - -exec nginx