diff --git a/.templates/00-aaa_dockerfile_backup.sh b/.templates/00-aaa_dockerfile_backup.sh index 576120b69..46e0bd828 100755 --- a/.templates/00-aaa_dockerfile_backup.sh +++ b/.templates/00-aaa_dockerfile_backup.sh @@ -7,41 +7,41 @@ set -e # Automatic modules download # ############################## if [ -e "/MODULESFILE" ]; then - MODULES=$(/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi && - if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi && - apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates >/dev/null || true && - mkdir -p /etc/cont-init.d && - for scripts in $MODULES; do echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || (echo "script failed to install $scripts" && exit 1); done && - chmod -R 755 /etc/cont-init.d + if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi && + if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi && + apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates >/dev/null || true && + mkdir -p /etc/cont-init.d && + for scripts in $MODULES; do echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || (echo "script failed to install $scripts" && exit 1); done && + chmod -R 755 /etc/cont-init.d fi ####################### # Automatic installer # ####################### if [ -e "/ENVFILE" ]; then - PACKAGES=$(/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi && - if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi && - curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_automatic_packages.sh" --output /ha_automatic_packages.sh && - chmod 777 /ha_automatic_packages.sh && - eval /./ha_automatic_packages.sh "${PACKAGES:-}" && - rm /ha_automatic_packages.sh + if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi && + if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi && + curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_automatic_packages.sh" --output /ha_automatic_packages.sh && + chmod 777 /ha_automatic_packages.sh && + eval /./ha_automatic_packages.sh "${PACKAGES:-}" && + rm /ha_automatic_packages.sh fi if [ -e "/MODULESFILE" ] && [ ! -f /ha_entrypoint.sh ]; then - for scripts in $MODULES; do - echo "$scripts : executing" - chown "$(id -u)":"$(id -g)" /etc/cont-init.d/"$scripts" - chmod a+x /etc/cont-init.d/"$scripts" - /./etc/cont-init.d/"$scripts" || echo "/etc/cont-init.d/$scripts: exiting $?" - rm /etc/cont-init.d/"$scripts" - done | tac + for scripts in $MODULES; do + echo "$scripts : executing" + chown "$(id -u)":"$(id -g)" /etc/cont-init.d/"$scripts" + chmod a+x /etc/cont-init.d/"$scripts" + /./etc/cont-init.d/"$scripts" || echo "/etc/cont-init.d/$scripts: exiting $?" + rm /etc/cont-init.d/"$scripts" + done | tac fi ####################### diff --git a/.templates/00-banner.sh b/.templates/00-banner.sh index f8f944bed..8b2336eed 100755 --- a/.templates/00-banner.sh +++ b/.templates/00-banner.sh @@ -6,45 +6,44 @@ set -e # ============================================================================== if ! bashio::supervisor.ping 2>/dev/null; then - # Degraded mode if no homeassistant - bashio::log.blue \ - '-----------------------------------------------------------' - bashio::log.blue "Starting addon without HA support" - bashio::log.blue "Version : ${BUILD_VERSION:-1.0}" - bashio::log.blue "Please use Docker Compose for env variables" - bashio::log.blue \ - '-----------------------------------------------------------' - # Use environment variables instead of addon options - echo "... convert scripts to use environment variables instead of addon options" - while IFS= read -r scripts - do - sed -i -e 's/bashio::config.has_value[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ]/g' \ - -e 's/bashio::config.true[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ] \&\& [ "${\1:-}" = "true" ]/g' \ - -e 's/\$(bashio::config[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"'])/${\1:-}/g' \ - -e 's/\$(bashio::addon.port[[:space:]]*["'"'"']\([0-9]*\)["'"'"'])/${\1:-}/g' \ - -e 's/bashio::config.require.ssl/true/g' \ - -e 's/\$(bashio::addon.ingress_port)/""/g' \ - -e 's/\$(bashio::addon.ingress_entry)/""/g' \ - -e 's/\$(bashio::addon.ip_address)/""/g' "$scripts" - done < <(grep -srl "bashio" /etc/cont-init.d /custom-services.d) - exit 0 + # Degraded mode if no homeassistant + bashio::log.blue \ + '-----------------------------------------------------------' + bashio::log.blue "Starting addon without HA support" + bashio::log.blue "Version : ${BUILD_VERSION:-1.0}" + bashio::log.blue "Please use Docker Compose for env variables" + bashio::log.blue \ + '-----------------------------------------------------------' + # Use environment variables instead of addon options + echo "... convert scripts to use environment variables instead of addon options" + while IFS= read -r scripts; do + sed -i -e 's/bashio::config.has_value[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ]/g' \ + -e 's/bashio::config.true[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ] \&\& [ "${\1:-}" = "true" ]/g' \ + -e 's/\$(bashio::config[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"'])/${\1:-}/g' \ + -e 's/\$(bashio::addon.port[[:space:]]*["'"'"']\([0-9]*\)["'"'"'])/${\1:-}/g' \ + -e 's/bashio::config.require.ssl/true/g' \ + -e 's/\$(bashio::addon.ingress_port)/""/g' \ + -e 's/\$(bashio::addon.ingress_entry)/""/g' \ + -e 's/\$(bashio::addon.ip_address)/""/g' "$scripts" + done < <(grep -srl "bashio" /etc/cont-init.d /custom-services.d) + exit 0 fi bashio::log.blue \ - '-----------------------------------------------------------' + '-----------------------------------------------------------' bashio::log.blue " Add-on: $(bashio::addon.name)" bashio::log.blue " $(bashio::addon.description)" bashio::log.blue \ - '-----------------------------------------------------------' + '-----------------------------------------------------------' bashio::log.blue " Add-on version: $(bashio::addon.version)" if bashio::var.true "$(bashio::addon.update_available)"; then - bashio::log.magenta ' There is an update available for this add-on!' - bashio::log.magenta \ - " Latest add-on version: $(bashio::addon.version_latest)" - bashio::log.magenta ' Please consider upgrading as soon as possible.' + bashio::log.magenta ' There is an update available for this add-on!' + bashio::log.magenta \ + " Latest add-on version: $(bashio::addon.version_latest)" + bashio::log.magenta ' Please consider upgrading as soon as possible.' else - bashio::log.green ' You are running the latest version of this add-on.' + bashio::log.green ' You are running the latest version of this add-on.' fi bashio::log.blue " System: $(bashio::info.operating_system)" @@ -53,33 +52,33 @@ bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)" bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)" bashio::log.blue \ - '-----------------------------------------------------------' + '-----------------------------------------------------------' bashio::log.blue \ - ' Please, share the above information when looking for help' + ' Please, share the above information when looking for help' bashio::log.blue \ - ' or support in, e.g., GitHub, forums' + ' or support in, e.g., GitHub, forums' bashio::log.blue \ - '-----------------------------------------------------------' + '-----------------------------------------------------------' bashio::log.green \ - ' Provided by: https://github.com/alexbelgium/hassio-addons ' + ' Provided by: https://github.com/alexbelgium/hassio-addons ' bashio::log.blue \ - '-----------------------------------------------------------' + '-----------------------------------------------------------' # ============================================================================== # Global actions for all addons # ============================================================================== if bashio::config.has_value "PUID" && bashio::config.has_value "PGID" && id abc &>/dev/null; then - bashio::log.green ' Defining permissions for main user : ' - PUID="$(bashio::config "PUID")" - PGID="$(bashio::config "PGID")" - usermod -o -u "$PUID" abc - groupmod -o -g "$PGID" abc - bashio::log.blue "User UID: $(id -u abc)" - bashio::log.blue "User GID: $(id -g abc)" - - bashio::log.blue \ - '-----------------------------------------------------------' + bashio::log.green ' Defining permissions for main user : ' + PUID="$(bashio::config "PUID")" + PGID="$(bashio::config "PGID")" + usermod -o -u "$PUID" abc + groupmod -o -g "$PGID" abc + bashio::log.blue "User UID: $(id -u abc)" + bashio::log.blue "User GID: $(id -g abc)" + + bashio::log.blue \ + '-----------------------------------------------------------' fi # Clean bashrc file safely -if [ -f ~/.bashrc ]; then : > ~/.bashrc; fi +if [ -f ~/.bashrc ]; then : >~/.bashrc; fi diff --git a/.templates/00-global_var.sh b/.templates/00-global_var.sh index 3159ae2b3..eec091d11 100755 --- a/.templates/00-global_var.sh +++ b/.templates/00-global_var.sh @@ -3,8 +3,8 @@ set -e if ! bashio::supervisor.ping 2>/dev/null; then - echo "..." - exit 0 + echo "..." + exit 0 fi ################################### @@ -16,11 +16,11 @@ JSONSOURCE="/data/options.json" # Define secrets location if [ -f /homeassistant/secrets.yaml ]; then - SECRETSOURCE="/homeassistant/secrets.yaml" + SECRETSOURCE="/homeassistant/secrets.yaml" elif [ -f /config/secrets.yaml ]; then - SECRETSOURCE="/config/secrets.yaml" + SECRETSOURCE="/config/secrets.yaml" else - SECRETSOURCE="false" + SECRETSOURCE="false" fi # Export keys as env variables @@ -28,70 +28,70 @@ fi mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") for KEYS in "${arr[@]}"; do - # export key - VALUE=$(jq ."$KEYS" "${JSONSOURCE}") - # Check if the value is an array - if [[ "$VALUE" == \[* ]]; then - bashio::log.warning "One of your option is an array, skipping" - else - # Continue for single values - VALUE="${VALUE//[\"\']/}" - line="${KEYS}='${VALUE}'" - # Check if secret - if [[ "${line}" == *"!secret "* ]]; then - echo "secret detected" - # Get argument - secret=${line#*secret } - # Remove trailing ' or " - secret="${secret%[\"\']}" - # Stop if secret file not mounted - if [[ "$SECRETSOURCE" == "false" ]]; then - bashio::log.warning "Homeassistant config not mounted, secrets are not supported" - continue - fi - # Check if single match - secretnum=$(sed -n "/$secret:/=" "$SECRETSOURCE" ) - [[ "$secretnum" == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file" - # Get text - secret=$(sed -n "/$secret:/p" "$SECRETSOURCE" ) - secret=${secret#*: } - line="${line%%=*}='$secret'" - VALUE="$secret" - fi - # text - if bashio::config.false "verbose" || [[ "${KEYS,,}" == *"pass"* ]]; then - bashio::log.blue "${KEYS}=******" - else - bashio::log.blue "$line" - fi + # export key + VALUE=$(jq ."$KEYS" "${JSONSOURCE}") + # Check if the value is an array + if [[ "$VALUE" == \[* ]]; then + bashio::log.warning "One of your option is an array, skipping" + else + # Continue for single values + VALUE="${VALUE//[\"\']/}" + line="${KEYS}='${VALUE}'" + # Check if secret + if [[ "${line}" == *"!secret "* ]]; then + echo "secret detected" + # Get argument + secret=${line#*secret } + # Remove trailing ' or " + secret="${secret%[\"\']}" + # Stop if secret file not mounted + if [[ "$SECRETSOURCE" == "false" ]]; then + bashio::log.warning "Homeassistant config not mounted, secrets are not supported" + continue + fi + # Check if single match + secretnum=$(sed -n "/$secret:/=" "$SECRETSOURCE") + [[ "$secretnum" == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file" + # Get text + secret=$(sed -n "/$secret:/p" "$SECRETSOURCE") + secret=${secret#*: } + line="${line%%=*}='$secret'" + VALUE="$secret" + fi + # text + if bashio::config.false "verbose" || [[ "${KEYS,,}" == *"pass"* ]]; then + bashio::log.blue "${KEYS}=******" + else + bashio::log.blue "$line" + fi - ###################################### - # Export the variable to run scripts # - ###################################### - # shellcheck disable=SC2163 - export "$line" - # export to python - if command -v "python3" &>/dev/null ; then - [ ! -f /env.py ] && echo "import os" > /env.py - # Escape \ - VALUEPY="${VALUE//\\/\\\\}" - # Avoid " and ' - VALUEPY="${VALUEPY//[\"\']/}" - echo "os.environ['${KEYS}'] = '$VALUEPY'" >> /env.py - python3 /env.py - fi - # set .env - echo "$line" >> /.env || true - # set /etc/environment - mkdir -p /etc - echo "$line" >> /etc/environment - # For non s6 - if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi - if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi - # For s6 - if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" > /var/run/s6/container_environment/"${KEYS}"; fi - echo "export ${KEYS}='${VALUE}'" >> ~/.bashrc - fi + ###################################### + # Export the variable to run scripts # + ###################################### + # shellcheck disable=SC2163 + export "$line" + # export to python + if command -v "python3" &>/dev/null; then + [ ! -f /env.py ] && echo "import os" >/env.py + # Escape \ + VALUEPY="${VALUE//\\/\\\\}" + # Avoid " and ' + VALUEPY="${VALUEPY//[\"\']/}" + echo "os.environ['${KEYS}'] = '$VALUEPY'" >>/env.py + python3 /env.py + fi + # set .env + echo "$line" >>/.env || true + # set /etc/environment + mkdir -p /etc + echo "$line" >>/etc/environment + # For non s6 + if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi + if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi + # For s6 + if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi + echo "export ${KEYS}='${VALUE}'" >>~/.bashrc + fi done ################ @@ -99,8 +99,8 @@ done ################ set +e if [ -n "$TZ" ] && [ -f /etc/localtime ]; then - if [ -f /usr/share/zoneinfo/"$TZ" ]; then - echo "Timezone set from $(cat /etc/timezone) to $TZ" - ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime && echo "$TZ" >/etc/timezone - fi + if [ -f /usr/share/zoneinfo/"$TZ" ]; then + echo "Timezone set from $(cat /etc/timezone) to $TZ" + ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime && echo "$TZ" >/etc/timezone + fi fi diff --git a/.templates/00-local_mounts.sh b/.templates/00-local_mounts.sh index aa98877c1..6bf1a52a2 100755 --- a/.templates/00-local_mounts.sh +++ b/.templates/00-local_mounts.sh @@ -3,8 +3,8 @@ set -e if ! bashio::supervisor.ping 2>/dev/null; then - echo "..." - exit 0 + echo "..." + exit 0 fi ###################### @@ -14,95 +14,97 @@ fi # Mount local Share if configured if bashio::config.has_value 'localdisks'; then - # Available devices - blkid | awk '{print substr($1, 0, length($1) - 1)}' | awk -F'/' '{print $NF}' > availabledisks - echo "NAME" >> availabledisks + # Available devices + blkid | awk '{print substr($1, 0, length($1) - 1)}' | awk -F'/' '{print $NF}' >availabledisks + echo "NAME" >>availabledisks - ## List available Disk with Labels and Id - bashio::log.blue "---------------------------------------------------" - bashio::log.info "Available Disks for mounting :" - lsblk -o name,label,size,fstype,ro | awk '$4 != "" { print $0 }' | grep -f availabledisks - bashio::log.blue "---------------------------------------------------" - rm availabledisks + ## List available Disk with Labels and Id + bashio::log.blue "---------------------------------------------------" + bashio::log.info "Available Disks for mounting :" + lsblk -o name,label,size,fstype,ro | awk '$4 != "" { print $0 }' | grep -f availabledisks + bashio::log.blue "---------------------------------------------------" + rm availabledisks - # Show support fs https://github.com/dianlight/hassio-addons/blob/2e903184254617ac2484fe7c03a6e33e6987151c/sambanas/rootfs/etc/s6-overlay/s6-rc.d/init-automount/run#L106 - fstypessupport=$(grep -v nodev /dev/null; then - bashio::log.blue "Disabled : please use another method" - exit 0 + bashio::log.blue "Disabled : please use another method" + exit 0 fi #################### # DEFINE FUNCTIONS # #################### -test_mount () { +test_mount() { - # Set initial test - MOUNTED=false - ERROR_MOUNT=false + # Set initial test + MOUNTED=false + ERROR_MOUNT=false - # Exit if not mounted - if ! mountpoint -q /mnt/"$diskname"; then - return 0 - fi + # Exit if not mounted + if ! mountpoint -q /mnt/"$diskname"; then + return 0 + fi - # Exit if can't write - [[ -e "/mnt/$diskname/testaze" ]] && rm -r "/mnt/$diskname/testaze" - # shellcheck disable=SC2015 - mkdir "/mnt/$diskname/testaze" && touch "/mnt/$diskname/testaze/testaze" && rm -r "/mnt/$diskname/testaze" || ERROR_MOUNT=true - if [[ "$ERROR_MOUNT" == "true" ]]; then - # Test write permissions - if [[ "$MOUNTOPTIONS" == *"noserverino"* ]]; then - bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check UID/GID for permissions, and if the share is rw" - else - MOUNTOPTIONS="$MOUNTOPTIONS,noserverino" - echo "... testing with noserverino" - mount_drive "$MOUNTOPTIONS" - return 0 - fi - fi + # Exit if can't write + [[ -e "/mnt/$diskname/testaze" ]] && rm -r "/mnt/$diskname/testaze" + # shellcheck disable=SC2015 + mkdir "/mnt/$diskname/testaze" && touch "/mnt/$diskname/testaze/testaze" && rm -r "/mnt/$diskname/testaze" || ERROR_MOUNT=true + if [[ "$ERROR_MOUNT" == "true" ]]; then + # Test write permissions + if [[ "$MOUNTOPTIONS" == *"noserverino"* ]]; then + bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check UID/GID for permissions, and if the share is rw" + else + MOUNTOPTIONS="$MOUNTOPTIONS,noserverino" + echo "... testing with noserverino" + mount_drive "$MOUNTOPTIONS" + return 0 + fi + fi - # Set correctly mounted bit - MOUNTED=true - return 0 + # Set correctly mounted bit + MOUNTED=true + return 0 } -mount_drive () { +mount_drive() { - # Define options - MOUNTED=true - MOUNTOPTIONS="$1" + # Define options + MOUNTED=true + MOUNTOPTIONS="$1" - # Try mounting - mount -t cifs -o "$MOUNTOPTIONS" "$disk" /mnt/"$diskname" 2>ERRORCODE || MOUNTED=false + # Try mounting + mount -t cifs -o "$MOUNTOPTIONS" "$disk" /mnt/"$diskname" 2>ERRORCODE || MOUNTED=false - # Test if succesful - if [[ "$MOUNTED" == "true" ]]; then - # shellcheck disable=SC2015 - test_mount - fi + # Test if succesful + if [[ "$MOUNTED" == "true" ]]; then + # shellcheck disable=SC2015 + test_mount + fi } @@ -68,215 +68,215 @@ mount_drive () { if bashio::config.has_value 'networkdisks'; then - # Alert message that it is a new code - if [[ "$(date +"%Y%m%d")" -lt "20240201" ]]; then - bashio::log.warning "------------------------" - bashio::log.warning "This is a new code, please report any issues on https://github.com/alexbelgium/hassio-addons" - bashio::log.warning "------------------------" - fi + # Alert message that it is a new code + if [[ "$(date +"%Y%m%d")" -lt "20240201" ]]; then + bashio::log.warning "------------------------" + bashio::log.warning "This is a new code, please report any issues on https://github.com/alexbelgium/hassio-addons" + bashio::log.warning "------------------------" + fi - echo 'Mounting smb share(s)...' + echo 'Mounting smb share(s)...' - #################### - # Define variables # - #################### + #################### + # Define variables # + #################### - # Set variables - MOREDISKS=$(bashio::config 'networkdisks') - USERNAME=$(bashio::config 'cifsusername') - PASSWORD=$(bashio::config 'cifspassword') - SMBVERS="" - SECVERS="" - CHARSET=",iocharset=utf8" + # Set variables + MOREDISKS=$(bashio::config 'networkdisks') + USERNAME=$(bashio::config 'cifsusername') + PASSWORD=$(bashio::config 'cifspassword') + SMBVERS="" + SECVERS="" + CHARSET=",iocharset=utf8" - # Clean data - MOREDISKS=${MOREDISKS// \/\//,\/\/} - MOREDISKS=${MOREDISKS//, /,} - MOREDISKS=${MOREDISKS// /"\040"} + # Clean data + MOREDISKS=${MOREDISKS// \/\//,\/\/} + MOREDISKS=${MOREDISKS//, /,} + MOREDISKS=${MOREDISKS// /"\040"} - # Is domain set - DOMAIN="" - DOMAINCLIENT="" - if bashio::config.has_value 'cifsdomain'; then - echo "... using domain $(bashio::config 'cifsdomain')" - DOMAIN=",domain=$(bashio::config 'cifsdomain')" - DOMAINCLIENT="--workgroup=$(bashio::config 'cifsdomain')" - fi + # Is domain set + DOMAIN="" + DOMAINCLIENT="" + if bashio::config.has_value 'cifsdomain'; then + echo "... using domain $(bashio::config 'cifsdomain')" + DOMAIN=",domain=$(bashio::config 'cifsdomain')" + DOMAINCLIENT="--workgroup=$(bashio::config 'cifsdomain')" + fi - # Is UID/GID set - PUID=",uid=$(id -u)" - PGID=",gid=$(id -g)" - if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then - echo "... using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')" - PUID=",uid=$(bashio::config 'PUID')" - PGID=",gid=$(bashio::config 'PGID')" - fi + # Is UID/GID set + PUID=",uid=$(id -u)" + PGID=",gid=$(id -g)" + if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then + echo "... using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')" + PUID=",uid=$(bashio::config 'PUID')" + PGID=",gid=$(bashio::config 'PGID')" + fi - ################## - # Mounting disks # - ################## + ################## + # Mounting disks # + ################## - # shellcheck disable=SC2086 - for disk in ${MOREDISKS//,/ }; do # Separate comma separated values + # shellcheck disable=SC2086 + for disk in ${MOREDISKS//,/ }; do # Separate comma separated values - # Clean name of network share - # shellcheck disable=SC2116,SC2001 - disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name - disk="${disk//"\040"/ }" #replace \040 with - diskname="${disk//\\//}" #replace \ with / - diskname="${diskname##*/}" # Get only last part of the name - MOUNTED=false + # Clean name of network share + # shellcheck disable=SC2116,SC2001 + disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name + disk="${disk//"\040"/ }" #replace \040 with + diskname="${disk//\\//}" #replace \ with / + diskname="${diskname##*/}" # Get only last part of the name + MOUNTED=false - # Start - echo "... mounting $disk" + # Start + echo "... mounting $disk" - # Data validation - if [[ ! "$disk" =~ ^.*+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[/]+.*+$ ]]; then - bashio::log.fatal "...... the structure of your \"networkdisks\" option : \"$disk\" doesn't seem correct, please use a structure like //123.12.12.12/sharedfolder,//123.12.12.12/sharedfolder2. If you don't use it, you can simply remove the text, this will avoid this error message in the future." - touch ERRORCODE - continue - fi + # Data validation + if [[ ! "$disk" =~ ^.*+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[/]+.*+$ ]]; then + bashio::log.fatal "...... the structure of your \"networkdisks\" option : \"$disk\" doesn't seem correct, please use a structure like //123.12.12.12/sharedfolder,//123.12.12.12/sharedfolder2. If you don't use it, you can simply remove the text, this will avoid this error message in the future." + touch ERRORCODE + continue + fi - # Prepare mount point - mkdir -p /mnt/"$diskname" - chown root:root /mnt/"$diskname" + # Prepare mount point + mkdir -p /mnt/"$diskname" + chown root:root /mnt/"$diskname" - # Quickly try to mount with defaults - mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}" + # Quickly try to mount with defaults + mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}" - # Deeper analysis if failed - if [ "$MOUNTED" = false ]; then + # Deeper analysis if failed + if [ "$MOUNTED" = false ]; then - # Extract ip part of server for further manipulation - server="$(echo "$disk" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")" + # Extract ip part of server for further manipulation + server="$(echo "$disk" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")" - # Does server exists - output="$(nmap -F $server -T5 -oG -)" - if ! echo "$output" | grep 445/open &>/dev/null; then - if echo "$output" | grep /open &>/dev/null; then - bashio::log.fatal "...... $server is reachable but SMB port not opened, stopping script" - touch ERRORCODE - continue - else - bashio::log.fatal "...... fatal : $server not reachable, is it correct" - touch ERRORCODE - continue - fi - else - echo "...... $server is confirmed reachable" - fi + # Does server exists + output="$(nmap -F $server -T5 -oG -)" + if ! echo "$output" | grep 445/open &>/dev/null; then + if echo "$output" | grep /open &>/dev/null; then + bashio::log.fatal "...... $server is reachable but SMB port not opened, stopping script" + touch ERRORCODE + continue + else + bashio::log.fatal "...... fatal : $server not reachable, is it correct" + touch ERRORCODE + continue + fi + else + echo "...... $server is confirmed reachable" + fi - # Are credentials correct - OUTPUT="$(smbclient -t 2 -L "$disk" -U "$USERNAME"%"$PASSWORD" -c "exit" $DOMAINCLIENT 2>&1 || true)" - if echo "$OUTPUT" | grep -q "LOGON_FAILURE"; then - bashio::log.fatal "...... incorrect Username, Password, or Domain! Script will stop." - touch ERRORCODE - # Should there be a workgroup - if ! smbclient -t 2 -L $disk -N $DOMAINCLIENT -c "exit" &>/dev/null; then - bashio::log.fatal "...... perhaps a workgroup must be specified" - touch ERRORCODE - fi - continue - elif echo "$OUTPUT" | grep -q "tree connect failed" || echo "$OUTPUT" | grep -q "NT_STATUS_CONNECTION_DISCONNECTED"; then - echo "... testing path" - bashio::log.fatal "...... invalid or inaccessible SMB path. Script will stop." - touch ERRORCODE - continue - elif ! echo "$OUTPUT" | grep -q "Disk"; then - echo "... testing path" - bashio::log.fatal "...... no shares found. Invalid or inaccessible SMB path?" - else - echo "...... credentials are valid" - fi + # Are credentials correct + OUTPUT="$(smbclient -t 2 -L "$disk" -U "$USERNAME"%"$PASSWORD" -c "exit" $DOMAINCLIENT 2>&1 || true)" + if echo "$OUTPUT" | grep -q "LOGON_FAILURE"; then + bashio::log.fatal "...... incorrect Username, Password, or Domain! Script will stop." + touch ERRORCODE + # Should there be a workgroup + if ! smbclient -t 2 -L $disk -N $DOMAINCLIENT -c "exit" &>/dev/null; then + bashio::log.fatal "...... perhaps a workgroup must be specified" + touch ERRORCODE + fi + continue + elif echo "$OUTPUT" | grep -q "tree connect failed" || echo "$OUTPUT" | grep -q "NT_STATUS_CONNECTION_DISCONNECTED"; then + echo "... testing path" + bashio::log.fatal "...... invalid or inaccessible SMB path. Script will stop." + touch ERRORCODE + continue + elif ! echo "$OUTPUT" | grep -q "Disk"; then + echo "... testing path" + bashio::log.fatal "...... no shares found. Invalid or inaccessible SMB path?" + else + echo "...... credentials are valid" + fi - # Extracting SMB versions and normalize output - # shellcheck disable=SC2210,SC2094 - SMBVERS="$(nmap --script smb-protocols "$server" -p 445 2>1 | awk '/ [0-9]/' | awk '{print $NF}' | cut -c -3 | sort -V | tail -n 1 || true)" - # Avoid : - SMBVERS="${SMBVERS/:/.}" - # Manage output - if [ -n "$SMBVERS" ]; then - case $SMBVERS in - "202"|"200"|"20") - SMBVERS="2.0" - ;; - 21) - SMBVERS="2.1" - ;; - 302) - SMBVERS="3.02" - ;; - 311) - SMBVERS="3.1.1" - ;; - "3.1") - echo "SMB 3.1 detected, converting to 3.0" - SMBVERS="3.0" - ;; - esac - echo "...... SMB version detected : $SMBVERS" - SMBVERS=",vers=$SMBVERS" - elif smbclient -t 2 -L "$server" -m NT1 -N $DOMAINCLIENT &>/dev/null; then - echo "...... SMB version : only SMBv1 is supported, this can lead to issues" - SECVERS=",sec=ntlm" - SMBVERS=",vers=1.0" - else - echo "...... SMB version : couldn't detect, default used" - SMBVERS="" - fi + # Extracting SMB versions and normalize output + # shellcheck disable=SC2210,SC2094 + SMBVERS="$(nmap --script smb-protocols "$server" -p 445 2>1 | awk '/ [0-9]/' | awk '{print $NF}' | cut -c -3 | sort -V | tail -n 1 || true)" + # Avoid : + SMBVERS="${SMBVERS/:/.}" + # Manage output + if [ -n "$SMBVERS" ]; then + case $SMBVERS in + "202" | "200" | "20") + SMBVERS="2.0" + ;; + 21) + SMBVERS="2.1" + ;; + 302) + SMBVERS="3.02" + ;; + 311) + SMBVERS="3.1.1" + ;; + "3.1") + echo "SMB 3.1 detected, converting to 3.0" + SMBVERS="3.0" + ;; + esac + echo "...... SMB version detected : $SMBVERS" + SMBVERS=",vers=$SMBVERS" + elif smbclient -t 2 -L "$server" -m NT1 -N $DOMAINCLIENT &>/dev/null; then + echo "...... SMB version : only SMBv1 is supported, this can lead to issues" + SECVERS=",sec=ntlm" + SMBVERS=",vers=1.0" + else + echo "...... SMB version : couldn't detect, default used" + SMBVERS="" + fi - # Test with different security versions - ####################################### - for SECVERS in "$SECVERS" ",sec=ntlmv2" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=krb5i" ",sec=krb5" ",sec=ntlm" ",sec=ntlmv2i"; do - if [ "$MOUNTED" = false ]; then - mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}" - fi - done + # Test with different security versions + ####################################### + for SECVERS in "$SECVERS" ",sec=ntlmv2" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=krb5i" ",sec=krb5" ",sec=ntlm" ",sec=ntlmv2i"; do + if [ "$MOUNTED" = false ]; then + mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}" + fi + done - fi + fi - # Messages - if [ "$MOUNTED" = true ]; then + # Messages + if [ "$MOUNTED" = true ]; then - bashio::log.info "...... $disk successfully mounted to /mnt/$diskname with options ${MOUNTOPTIONS/$PASSWORD/XXXXXXXXXX}" - # Remove errorcode - if [ -f ERRORCODE ]; then - rm ERRORCODE - fi + bashio::log.info "...... $disk successfully mounted to /mnt/$diskname with options ${MOUNTOPTIONS/$PASSWORD/XXXXXXXXXX}" + # Remove errorcode + if [ -f ERRORCODE ]; then + rm ERRORCODE + fi - # Alert if smbv1 - if [[ "$MOUNTOPTIONS" == *"1.0"* ]]; then - bashio::log.warning "" - bashio::log.warning "Your smb system requires smbv1. This is an obsolete protocol. Please correct this to prevent issues." - bashio::log.warning "" - fi + # Alert if smbv1 + if [[ "$MOUNTOPTIONS" == *"1.0"* ]]; then + bashio::log.warning "" + bashio::log.warning "Your smb system requires smbv1. This is an obsolete protocol. Please correct this to prevent issues." + bashio::log.warning "" + fi - else - # Mounting failed messages - bashio::log.fatal "Error, unable to mount $disk to /mnt/$diskname with username $USERNAME, $PASSWORD. Please check your remote share path, username, password, domain, try putting 0 in UID and GID" - bashio::log.fatal "Here is some debugging info :" + else + # Mounting failed messages + bashio::log.fatal "Error, unable to mount $disk to /mnt/$diskname with username $USERNAME, $PASSWORD. Please check your remote share path, username, password, domain, try putting 0 in UID and GID" + bashio::log.fatal "Here is some debugging info :" - # Provide debugging info - smbclient -t 2 -L $disk -U "$USERNAME%$PASSWORD" -c "exit" + # Provide debugging info + smbclient -t 2 -L $disk -U "$USERNAME%$PASSWORD" -c "exit" - # Error code - SMBVERS="" - SECVERS="" - PUID="" - PGID="" - CHARSET="" - mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}" - bashio::log.fatal "Error read : $(/dev/null || true - rmdir "/mnt/$diskname" || true + # clean folder + umount "/mnt/$diskname" 2>/dev/null || true + rmdir "/mnt/$diskname" || true - # Stop addon - bashio::addon.stop + # Stop addon + bashio::addon.stop - fi + fi - done + done fi diff --git a/.templates/01-config_yaml.sh b/.templates/01-config_yaml.sh index 8588b68f5..6be190683 100755 --- a/.templates/01-config_yaml.sh +++ b/.templates/01-config_yaml.sh @@ -9,8 +9,8 @@ set -e # Disable if config not present if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then - echo "..." - exit 0 + echo "..." + exit 0 fi # Define slug @@ -19,13 +19,13 @@ slug="${slug#*_}" # Check type of config folder if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then - # New config location - CONFIGLOCATION="/config" - CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml" + # New config location + CONFIGLOCATION="/config" + CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml" else - # Legacy config location - CONFIGLOCATION="/config/addons_config/${slug}" - CONFIGFILEBROWSER="/homeassistant/addons_config/$slug/config.yaml" + # Legacy config location + CONFIGLOCATION="/config/addons_config/${slug}" + CONFIGFILEBROWSER="/homeassistant/addons_config/$slug/config.yaml" fi # Default location @@ -35,50 +35,50 @@ CONFIGSOURCE="$CONFIGLOCATION"/config.yaml # Is there a custom path if bashio::config.has_value 'CONFIG_LOCATION'; then - CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") - if [[ "$CONFIGSOURCE" == *.* ]]; then - CONFIGSOURCE=$(dirname "$CONFIGSOURCE") - fi - # If does not end by config.yaml, remove trailing slash and add config.yaml - if [[ "$CONFIGSOURCE" != *".yaml" ]]; then - CONFIGSOURCE="${CONFIGSOURCE%/}"/config.yaml - fi - # Check if config is located in an acceptable location - LOCATIONOK="" - for location in "/share" "/config" "/data"; do - if [[ "$CONFIGSOURCE" == "$location"* ]]; then - LOCATIONOK=true - fi - done - if [ -z "$LOCATIONOK" ]; then - bashio::log.red "Watch-out : your CONFIG_LOCATION values can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $CONFIGLOCATION/config.yaml" - CONFIGSOURCE="$CONFIGLOCATION"/config.yaml - fi + CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") + if [[ "$CONFIGSOURCE" == *.* ]]; then + CONFIGSOURCE=$(dirname "$CONFIGSOURCE") + fi + # If does not end by config.yaml, remove trailing slash and add config.yaml + if [[ "$CONFIGSOURCE" != *".yaml" ]]; then + CONFIGSOURCE="${CONFIGSOURCE%/}"/config.yaml + fi + # Check if config is located in an acceptable location + LOCATIONOK="" + for location in "/share" "/config" "/data"; do + if [[ "$CONFIGSOURCE" == "$location"* ]]; then + LOCATIONOK=true + fi + done + if [ -z "$LOCATIONOK" ]; then + bashio::log.red "Watch-out : your CONFIG_LOCATION values can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $CONFIGLOCATION/config.yaml" + CONFIGSOURCE="$CONFIGLOCATION"/config.yaml + fi fi # Migrate if needed if [[ "$CONFIGLOCATION" == "/config" ]]; then - # Migrate file - if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then - echo "Migrating config.yaml to new config location" - mv /homeassistant/addons_config/"${slug}"/config.yaml /config/config.yaml - fi - # Migrate option - if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then - bashio::addon.option "CONFIG_LOCATION" "/config/config.yaml" - CONFIGSOURCE="/config/config.yaml" - fi + # Migrate file + if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then + echo "Migrating config.yaml to new config location" + mv /homeassistant/addons_config/"${slug}"/config.yaml /config/config.yaml + fi + # Migrate option + if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then + bashio::addon.option "CONFIG_LOCATION" "/config/config.yaml" + CONFIGSOURCE="/config/config.yaml" + fi fi if [[ "$CONFIGSOURCE" != *".yaml" ]]; then - bashio::log.error "Something is going wrong in the config location, quitting" + bashio::log.error "Something is going wrong in the config location, quitting" fi # Permissions if [[ "$CONFIGSOURCE" == *".yaml" ]]; then - echo "Setting permissions for the config.yaml directory" - mkdir -p "$(dirname "${CONFIGSOURCE}")" - chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2>/dev/null + echo "Setting permissions for the config.yaml directory" + mkdir -p "$(dirname "${CONFIGSOURCE}")" + chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2>/dev/null fi #################### @@ -88,9 +88,9 @@ fi echo "" bashio::log.green "Load environment variables from $CONFIGSOURCE if existing" if [[ "$CONFIGSOURCE" == "/config"* ]]; then - bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGFILEBROWSER" + bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGFILEBROWSER" else - bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGSOURCE" + bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGSOURCE" fi bashio::log.green "---------------------------------------------------------" bashio::log.green "Wiki here on how to use : github.com/alexbelgium/hassio-addons/wiki/Add‐ons-feature-:-add-env-variables" @@ -98,18 +98,18 @@ echo "" # Check if config file is there, or create one from template if [ ! -f "$CONFIGSOURCE" ]; then - echo "... no config file, creating one from template. Please customize the file in $CONFIGSOURCE before restarting." - # Create folder - mkdir -p "$(dirname "${CONFIGSOURCE}")" - # Placing template in config - if [ -f /templates/config.yaml ]; then - # Use available template - cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")" - else - # Download template - TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template" - curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" - fi + echo "... no config file, creating one from template. Please customize the file in $CONFIGSOURCE before restarting." + # Create folder + mkdir -p "$(dirname "${CONFIGSOURCE}")" + # Placing template in config + if [ -f /templates/config.yaml ]; then + # Use available template + cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")" + else + # Download template + TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template" + curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" + fi fi # Check if there are lines to read @@ -119,8 +119,8 @@ sed -i '/^[[:space:]]*$/d' /tempenv sed -i '/^$/d' /tempenv # Exit if empty if [ ! -s /tempenv ]; then - bashio::log.green "... no env variables found, exiting" - exit 0 + bashio::log.green "... no env variables found, exiting" + exit 0 fi rm /tempenv @@ -128,21 +128,21 @@ rm /tempenv EXIT_CODE=0 yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$? if [ "$EXIT_CODE" != 0 ]; then - cat ERROR - bashio::log.yellow "... config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above." + cat ERROR + bashio::log.yellow "... config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above." fi # Export all yaml entries as env variables # Helper function function parse_yaml { - local prefix=$2 || local prefix="" - local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') - sed -ne "s|^\($s\):|\1|" \ - -e "s| #.*$||g" \ - -e "s|#.*$||g" \ - -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ - -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | - awk -F$fs '{ + local prefix=$2 || local prefix="" + local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') + sed -ne "s|^\($s\):|\1|" \ + -e "s| #.*$||g" \ + -e "s|#.*$||g" \ + -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | + awk -F$fs '{ indent = length($1)/2; vname[indent] = $2; for (i in vname) {if (i > indent) {delete vname[i]}} @@ -163,46 +163,46 @@ SECRETSFILE="/config/secrets.yaml" if [ -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi while IFS= read -r line; do - # Clean output - line="${line//[\"\']/}" - # Check if secret - if [[ "${line}" == *'!secret '* ]]; then - echo "secret detected" - secret=${line#*secret } - # Check if single match - secretnum=$(sed -n "/$secret:/=" "$SECRETSFILE") - [[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file" - # Get text - secret=$(sed -n "/$secret:/p" "$SECRETSFILE") - secret=${secret#*: } - line="${line%%=*}='$secret'" - fi - # Data validation - if [[ "$line" =~ ^.+[=].+$ ]]; then - # extract keys and values - KEYS="${line%%=*}" - VALUE="${line#*=}" - line="${KEYS}='${VALUE}'" - export "$line" - # export to python - if command -v "python3" &>/dev/null; then - [ ! -f /env.py ] && echo "import os" > /env.py - echo "os.environ['${KEYS}'] = '${VALUE//[\"\']/}'" >> /env.py - python3 /env.py - fi - # set .env - if [ -f /.env ]; then echo "$line" >> /.env; fi - mkdir -p /etc - echo "$line" >> /etc/environment - # Export to scripts - if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi - if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi - # For s6 - if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" > /var/run/s6/container_environment/"${KEYS}"; fi - echo "export $line" >> ~/.bashrc - # Show in log - if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi - else - bashio::log.red "$line does not follow the correct structure. Please check your yaml file." - fi + # Clean output + line="${line//[\"\']/}" + # Check if secret + if [[ "${line}" == *'!secret '* ]]; then + echo "secret detected" + secret=${line#*secret } + # Check if single match + secretnum=$(sed -n "/$secret:/=" "$SECRETSFILE") + [[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file" + # Get text + secret=$(sed -n "/$secret:/p" "$SECRETSFILE") + secret=${secret#*: } + line="${line%%=*}='$secret'" + fi + # Data validation + if [[ "$line" =~ ^.+[=].+$ ]]; then + # extract keys and values + KEYS="${line%%=*}" + VALUE="${line#*=}" + line="${KEYS}='${VALUE}'" + export "$line" + # export to python + if command -v "python3" &>/dev/null; then + [ ! -f /env.py ] && echo "import os" >/env.py + echo "os.environ['${KEYS}'] = '${VALUE//[\"\']/}'" >>/env.py + python3 /env.py + fi + # set .env + if [ -f /.env ]; then echo "$line" >>/.env; fi + mkdir -p /etc + echo "$line" >>/etc/environment + # Export to scripts + if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi + if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi + # For s6 + if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi + echo "export $line" >>~/.bashrc + # Show in log + if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi + else + bashio::log.red "$line does not follow the correct structure. Please check your yaml file." + fi done <"/tmpfile" diff --git a/.templates/01-custom_script.sh b/.templates/01-custom_script.sh index 003671d54..75769b328 100755 --- a/.templates/01-custom_script.sh +++ b/.templates/01-custom_script.sh @@ -8,8 +8,8 @@ set -e # Exit if /config is not mounted or HA not used if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then - echo "..." - exit 0 + echo "..." + exit 0 fi # Define slug @@ -18,13 +18,13 @@ slug="${slug#*_}" # Check type of config folder if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then - # New config location - CONFIGLOCATION="/config" - CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh" + # New config location + CONFIGLOCATION="/config" + CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh" else - # Legacy config location - CONFIGLOCATION="/config/addons_autoscripts" - CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh" + # Legacy config location + CONFIGLOCATION="/config/addons_autoscripts" + CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh" fi # Default location @@ -36,9 +36,9 @@ bashio::log.green "Wiki here : github.com/alexbelgium/hassio-addons/wiki/Add-ons # Download template if no script found and exit if [ ! -f "$CONFIGSOURCE" ]; then - TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template" - curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true - exit 0 + TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template" + curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true + exit 0 fi # Convert scripts to linux @@ -48,20 +48,19 @@ chmod +x "$CONFIGSOURCE" # Get current shebang, if not available use another currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$CONFIGSOURCE")" if [ ! -f "${currentshebang%% *}" ]; then - for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done - sed -i "s|$currentshebang|$shebang|g" "$CONFIGSOURCE" + for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done + sed -i "s|$currentshebang|$shebang|g" "$CONFIGSOURCE" fi # Check if there is actual commands -while IFS= read -r line -do - # Remove leading and trailing whitespaces - line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" +while IFS= read -r line; do + # Remove leading and trailing whitespaces + line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - # Check if line is not empty and does not start with # - if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then - bashio::log.green "... script found, executing" - /."$CONFIGSOURCE" - exit 0 - fi -done < "$CONFIGSOURCE" + # Check if line is not empty and does not start with # + if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then + bashio::log.green "... script found, executing" + /."$CONFIGSOURCE" + exit 0 + fi +done <"$CONFIGSOURCE" diff --git a/.templates/19-json_repair.sh b/.templates/19-json_repair.sh index c2db5d9bc..7197279b8 100755 --- a/.templates/19-json_repair.sh +++ b/.templates/19-json_repair.sh @@ -8,39 +8,39 @@ JSONSOURCE='/defaults/settings.json' # If json already exists if [ -f "${JSONTOCHECK}" ]; then - # Variables - echo "Checking settings.json format" + # Variables + echo "Checking settings.json format" - # Check if json file valid or not - jq . -S "${JSONTOCHECK}" &>/dev/null && ERROR=false || ERROR=true - if [ "$ERROR" = true ]; then - bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old" - mv "${JSONSOURCE}" "${JSONSOURCE}"_old - cp "${JSONSOURCE}" "${JSONTOCHECK}" - exit 0 - fi + # Check if json file valid or not + jq . -S "${JSONTOCHECK}" &>/dev/null && ERROR=false || ERROR=true + if [ "$ERROR" = true ]; then + bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old" + mv "${JSONSOURCE}" "${JSONSOURCE}"_old + cp "${JSONSOURCE}" "${JSONTOCHECK}" + exit 0 + fi - # Get the default keys from the original file - mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") + # Get the default keys from the original file + mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") - # Check if all keys are still there, or add them - # spellcheck disable=SC2068 - for KEYS in "${arr[@]}"; do - # Check if key exists - KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}") - if [ "$KEYSTHERE" != "true" ]; then - #Fetch initial value - JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}") - #Add key - sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}" - # Message - bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}" - fi - done + # Check if all keys are still there, or add them + # spellcheck disable=SC2068 + for KEYS in "${arr[@]}"; do + # Check if key exists + KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}") + if [ "$KEYSTHERE" != "true" ]; then + #Fetch initial value + JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}") + #Add key + sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}" + # Message + bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}" + fi + done - # Show structure in a nice way - jq . -S "${JSONTOCHECK}" | cat >temp.json && mv temp.json "${JSONTOCHECK}" + # Show structure in a nice way + jq . -S "${JSONTOCHECK}" | cat >temp.json && mv temp.json "${JSONTOCHECK}" - # Message - bashio::log.info "Your settings.json was checked and seems perfectly normal!" + # Message + bashio::log.info "Your settings.json was checked and seems perfectly normal!" fi diff --git a/.templates/90-disable_ingress.sh b/.templates/90-disable_ingress.sh index a0be50b7f..93ea6eb08 100755 --- a/.templates/90-disable_ingress.sh +++ b/.templates/90-disable_ingress.sh @@ -6,17 +6,17 @@ set -e # Disable Ingress if bashio::config.true "ingress_disabled"; then - bashio::log.warning "Ingress is disabled. You'll need to connect using ip:port" + bashio::log.warning "Ingress is disabled. You'll need to connect using ip:port" - # Adapt ingress.conf - sed -i "/root/d" /etc/nginx/servers/ingress.conf - sed -i "/proxy_pass/i root /etc;" /etc/nginx/servers/ingress.conf - sed -i "/proxy_pass/i try_files '' /ingress.html =404;" /etc/nginx/servers/ingress.conf - sed -i "/proxy_pass/d" /etc/nginx/servers/ingress.conf + # Adapt ingress.conf + sed -i "/root/d" /etc/nginx/servers/ingress.conf + sed -i "/proxy_pass/i root /etc;" /etc/nginx/servers/ingress.conf + sed -i "/proxy_pass/i try_files '' /ingress.html =404;" /etc/nginx/servers/ingress.conf + sed -i "/proxy_pass/d" /etc/nginx/servers/ingress.conf - # Create index.html - touch /etc/ingress.html - cat > /etc/ingress.html << EOF + # Create index.html + touch /etc/ingress.html + cat >/etc/ingress.html < diff --git a/.templates/90-dns_set.sh b/.templates/90-dns_set.sh index 487deb4a9..eecc84fdc 100755 --- a/.templates/90-dns_set.sh +++ b/.templates/90-dns_set.sh @@ -9,36 +9,35 @@ set -e # Avoid usage of local dns such as adguard home or pihole\n" if bashio::config.has_value 'DNS_server'; then - # Define variables - DNSSERVER=$(bashio::config 'DNS_server') - DNS="" - DNSLIST="" + # Define variables + DNSSERVER=$(bashio::config 'DNS_server') + DNS="" + DNSLIST="" - # Get DNS servers - # shellcheck disable=SC2086 - for server in ${DNSSERVER//,/ }; do # Separate comma separated values - # Only add DNS if successful - if ping -c 1 "$server" &> /dev/null - then - DNS="${DNS}nameserver $server\n" - DNSLIST="$server $DNSLIST" - else - bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used" - fi - done + # Get DNS servers + # shellcheck disable=SC2086 + for server in ${DNSSERVER//,/ }; do # Separate comma separated values + # Only add DNS if successful + if ping -c 1 "$server" &>/dev/null; then + DNS="${DNS}nameserver $server\n" + DNSLIST="$server $DNSLIST" + else + bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used" + fi + done - # Only add DNS if there are DNS set - # shellcheck disable=SC2236 - if [[ -n "${DNS:-}" ]]; then - # Write resolv.conf - # shellcheck disable=SC2059 - printf "${DNS}" >/etc/resolv.conf - chmod 644 /etc/resolv.conf - bashio::log.info "DNS SERVERS set to $DNSLIST" - else - bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers." - fi + # Only add DNS if there are DNS set + # shellcheck disable=SC2236 + if [[ -n "${DNS:-}" ]]; then + # Write resolv.conf + # shellcheck disable=SC2059 + printf "${DNS}" >/etc/resolv.conf + chmod 644 /etc/resolv.conf + bashio::log.info "DNS SERVERS set to $DNSLIST" + else + bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers." + fi else - bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers." + bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers." fi diff --git a/.templates/91-silent.sh b/.templates/91-silent.sh index ce3653715..d07130eb7 100755 --- a/.templates/91-silent.sh +++ b/.templates/91-silent.sh @@ -7,8 +7,8 @@ set -e ############### if bashio::config.true 'silent'; then - APPEND=' > /dev/null' - sed -i '$s|$|'"$APPEND"'|' /etc/services.d/*/run &>/dev/null || true - sed -i '$s|$|'"$APPEND"'|' /etc/cont-init.d/*/*run* &>/dev/null || true - bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.' + APPEND=' > /dev/null' + sed -i '$s|$|'"$APPEND"'|' /etc/services.d/*/run &>/dev/null || true + sed -i '$s|$|'"$APPEND"'|' /etc/cont-init.d/*/*run* &>/dev/null || true + bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.' fi diff --git a/.templates/91-universal_graphic_drivers.sh b/.templates/91-universal_graphic_drivers.sh index bb54f0569..1437d8298 100755 --- a/.templates/91-universal_graphic_drivers.sh +++ b/.templates/91-universal_graphic_drivers.sh @@ -3,170 +3,170 @@ set -e if bashio::config.has_value "graphic_driver"; then - # Origin : https://github.com/wumingjieno1/photoprism-test/blob/main/scripts/dist/install-gpu.sh - # abort if not executed as root - if [[ $(id -u) != "0" ]]; then - # shellcheck disable=SC2128 - bashio::log.fatal "Error: Run $(basename "${BASH_SOURCE}") as root" 1>&2 - exit 1 - fi + # Origin : https://github.com/wumingjieno1/photoprism-test/blob/main/scripts/dist/install-gpu.sh + # abort if not executed as root + if [[ $(id -u) != "0" ]]; then + # shellcheck disable=SC2128 + bashio::log.fatal "Error: Run $(basename "${BASH_SOURCE}") as root" 1>&2 + exit 1 + fi - # Get installer type - if [ -f /usr/bin/apt ]; then - bashio::log.info "... Distribution detected : Debian/Ubuntu" - apt-get install -yqq software-properties-common >/dev/null - add-apt-repository ppa:kisak/kisak-mesa >/dev/null - apt-get update >/dev/null - apt-get install -yqq mesa - elif [ -f /usr/bin/apk ]; then - bashio::log.info "... Distribution detected : Alpine" - fi + # Get installer type + if [ -f /usr/bin/apt ]; then + bashio::log.info "... Distribution detected : Debian/Ubuntu" + apt-get install -yqq software-properties-common >/dev/null + add-apt-repository ppa:kisak/kisak-mesa >/dev/null + apt-get update >/dev/null + apt-get install -yqq mesa + elif [ -f /usr/bin/apk ]; then + bashio::log.info "... Distribution detected : Alpine" + fi - # Detect GPU - # shellcheck disable=SC2207 - GPU_DETECTED=($(lshw -c display -json 2>/dev/null | jq -r '.[].configuration.driver')) - bashio::log.info "... GPU detected: ${GPU_DETECTED[*]}" - graphic_driver="" + # Detect GPU + # shellcheck disable=SC2207 + GPU_DETECTED=($(lshw -c display -json 2>/dev/null | jq -r '.[].configuration.driver')) + bashio::log.info "... GPU detected: ${GPU_DETECTED[*]}" + graphic_driver="" - # Get arch type - BUILD_ARCH="$(uname -m)" - case "$BUILD_ARCH" in - amd64 | AMD64 | x86_64 | x86-64) - BUILD_ARCH=amd64 - ;; + # Get arch type + BUILD_ARCH="$(uname -m)" + case "$BUILD_ARCH" in + amd64 | AMD64 | x86_64 | x86-64) + BUILD_ARCH=amd64 + ;; - arm64 | ARM64 | aarch64) - BUILD_ARCH=arm64 - graphic_driver=aarch64_rpi - ;; + arm64 | ARM64 | aarch64) + BUILD_ARCH=arm64 + graphic_driver=aarch64_rpi + ;; - arm | ARM | aarch | armv7l | armhf) - bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2 - exit 1 - ;; + arm | ARM | aarch | armv7l | armhf) + bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2 + exit 1 + ;; - *) - bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2 - exit 1 - ;; - esac - bashio::log.info "... architecture detected: ${BUILD_ARCH}" + *) + bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2 + exit 1 + ;; + esac + bashio::log.info "... architecture detected: ${BUILD_ARCH}" - #graphic_driver="$(bashio::config "graphic_driver")" - case "$graphic_driver" in - x64_AMD) - if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi - [ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-amd && run_mods >/dev/null && bashio::log.green "... done" - [ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-classic mesa-vdpau-gallium linux-firmware-radeon >/dev/null && bashio::log.green "... done" - ;; + #graphic_driver="$(bashio::config "graphic_driver")" + case "$graphic_driver" in + x64_AMD) + if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi + [ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-amd && run_mods >/dev/null && bashio::log.green "... done" + [ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-classic mesa-vdpau-gallium linux-firmware-radeon >/dev/null && bashio::log.green "... done" + ;; - x64_NVIDIA) - if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi - [ -f /usr/bin/apk ] && apk add --no-cache linux-firmware-radeon >/dev/null && bashio::log.green "... done" - [ -f /usr/bin/apt ] && apt-get -yqq install libcuda1 libnvcuvid1 libnvidia-encode1 nvidia-opencl-icd nvidia-vdpau-driver nvidia-driver-libs nvidia-kernel-dkms libva2 vainfo libva-wayland2 >/dev/null && bashio::log.green "... done" - ;; + x64_NVIDIA) + if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi + [ -f /usr/bin/apk ] && apk add --no-cache linux-firmware-radeon >/dev/null && bashio::log.green "... done" + [ -f /usr/bin/apt ] && apt-get -yqq install libcuda1 libnvcuvid1 libnvidia-encode1 nvidia-opencl-icd nvidia-vdpau-driver nvidia-driver-libs nvidia-kernel-dkms libva2 vainfo libva-wayland2 >/dev/null && bashio::log.green "... done" + ;; - x64_Intel) - if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi - [ -f /usr/bin/apk ] && apk add --no-cache opencl mesa-dri-gallium mesa-vulkan-intel mesa-dri-intel intel-media-driver >/dev/null && bashio::log.green "... done" - [ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-opencl-intel && run_mods && apt-get -yqq install intel-opencl-icd intel-media-va-driver-non-free i965-va-driver-shaders mesa-va-drivers libmfx1 libva2 vainfo libva-wayland2 >/dev/null && bashio::log.green "... done" - ;; + x64_Intel) + if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi + [ -f /usr/bin/apk ] && apk add --no-cache opencl mesa-dri-gallium mesa-vulkan-intel mesa-dri-intel intel-media-driver >/dev/null && bashio::log.green "... done" + [ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-opencl-intel && run_mods && apt-get -yqq install intel-opencl-icd intel-media-va-driver-non-free i965-va-driver-shaders mesa-va-drivers libmfx1 libva2 vainfo libva-wayland2 >/dev/null && bashio::log.green "... done" + ;; - aarch64_rpi) - if [[ "$BUILD_ARCH" != arm64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi - bashio::log.info "Installing Rpi graphic drivers" - [ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-vc4 mesa-dri-swrast mesa-gbm xf86-video-fbdev >/dev/null && bashio::log.green "... done" - [ -f /usr/bin/apt ] && apt-get -yqq install libgles2-mesa libgles2-mesa-dev xorg-dev >/dev/null && bashio::log.green "... done" - ;; + aarch64_rpi) + if [[ "$BUILD_ARCH" != arm64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi + bashio::log.info "Installing Rpi graphic drivers" + [ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-vc4 mesa-dri-swrast mesa-gbm xf86-video-fbdev >/dev/null && bashio::log.green "... done" + [ -f /usr/bin/apt ] && apt-get -yqq install libgles2-mesa libgles2-mesa-dev xorg-dev >/dev/null && bashio::log.green "... done" + ;; - esac + esac - # Main run logic - run_mods() { - echo "[mod-init] Attempting to run Docker Modification Logic" - for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do - # Support alternative endpoints - if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then - DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}" - ENDPOINT="${DOCKER_MOD%%:*}" - USERNAME="${DOCKER_MOD%%/*}" - REPO="${ENDPOINT#*/}" - TAG="${DOCKER_MOD#*:}" - if [[ ${TAG} == "${DOCKER_MOD}" ]]; then - TAG="latest" - fi - FILENAME="${USERNAME}.${REPO}.${TAG}" - AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull" - MANIFEST_URL="https://ghcr.io/v2/${ENDPOINT}/manifests/${TAG}" - BLOB_URL="https://ghcr.io/v2/${ENDPOINT}/blobs/" - MODE="ghcr" - else - ENDPOINT="${DOCKER_MOD%%:*}" - USERNAME="${DOCKER_MOD%%/*}" - REPO="${ENDPOINT#*/}" - TAG="${DOCKER_MOD#*:}" - if [[ ${TAG} == "${DOCKER_MOD}" ]]; then - TAG="latest" - fi - FILENAME="${USERNAME}.${REPO}.${TAG}" - AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" - MANIFEST_URL="https://registry-1.docker.io/v2/${ENDPOINT}/manifests/${TAG}" - BLOB_URL="https://registry-1.docker.io/v2/${ENDPOINT}/blobs/" - MODE="dockerhub" - fi - # Kill off modification logic if any of the usernames are banned - for BANNED in $(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt); do - if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then - if [[ -z ${RUN_BANNED_MODS+x} ]]; then - echo "[mod-init] ${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic" - return - else - echo "[mod-init] You have chosen to run banned mods ${DOCKER_MOD} will be applied" - fi - fi - done - echo "[mod-init] Applying ${DOCKER_MOD} files to container" - # Get Dockerhub token for api operations - TOKEN="$( - curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ - --silent \ - --header 'GET' \ - "${AUTH_URL}" | - jq -r '.token' - )" - # Determine first and only layer of image - SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}") - # Check if we have allready applied this layer - if [[ -f "/${FILENAME}" ]] && [[ "${SHALAYER}" == "$(cat /"${FILENAME}")" ]]; then - echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping" - else - # Download and extract layer to / - curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ - --silent \ - --location \ - --request GET \ - --header "Authorization: Bearer ${TOKEN}" \ - "${BLOB_URL}${SHALAYER}" -o \ - /modtarball.tar.xz - mkdir -p /tmp/mod - tar xzf /modtarball.tar.xz -C /tmp/mod - if [[ -d /tmp/mod/etc/s6-overlay ]]; then - if [[ -d /tmp/mod/etc/cont-init.d ]]; then - rm -rf /tmp/mod/etc/cont-init.d - fi - if [[ -d /tmp/mod/etc/services.d ]]; then - rm -rf /tmp/mod/etc/services.d - fi - fi - shopt -s dotglob - cp -R /tmp/mod/* / - shopt -u dotglob - rm -rf /tmp/mod - rm -rf /modtarball.tar.xz - echo "${SHALAYER}" >"/${FILENAME}" - echo "[mod-init] ${DOCKER_MOD} applied to container" - fi - done - } + # Main run logic + run_mods() { + echo "[mod-init] Attempting to run Docker Modification Logic" + for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do + # Support alternative endpoints + if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then + DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}" + ENDPOINT="${DOCKER_MOD%%:*}" + USERNAME="${DOCKER_MOD%%/*}" + REPO="${ENDPOINT#*/}" + TAG="${DOCKER_MOD#*:}" + if [[ ${TAG} == "${DOCKER_MOD}" ]]; then + TAG="latest" + fi + FILENAME="${USERNAME}.${REPO}.${TAG}" + AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull" + MANIFEST_URL="https://ghcr.io/v2/${ENDPOINT}/manifests/${TAG}" + BLOB_URL="https://ghcr.io/v2/${ENDPOINT}/blobs/" + MODE="ghcr" + else + ENDPOINT="${DOCKER_MOD%%:*}" + USERNAME="${DOCKER_MOD%%/*}" + REPO="${ENDPOINT#*/}" + TAG="${DOCKER_MOD#*:}" + if [[ ${TAG} == "${DOCKER_MOD}" ]]; then + TAG="latest" + fi + FILENAME="${USERNAME}.${REPO}.${TAG}" + AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" + MANIFEST_URL="https://registry-1.docker.io/v2/${ENDPOINT}/manifests/${TAG}" + BLOB_URL="https://registry-1.docker.io/v2/${ENDPOINT}/blobs/" + MODE="dockerhub" + fi + # Kill off modification logic if any of the usernames are banned + for BANNED in $(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt); do + if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then + if [[ -z ${RUN_BANNED_MODS+x} ]]; then + echo "[mod-init] ${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic" + return + else + echo "[mod-init] You have chosen to run banned mods ${DOCKER_MOD} will be applied" + fi + fi + done + echo "[mod-init] Applying ${DOCKER_MOD} files to container" + # Get Dockerhub token for api operations + TOKEN="$( + curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ + --silent \ + --header 'GET' \ + "${AUTH_URL}" | + jq -r '.token' + )" + # Determine first and only layer of image + SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}") + # Check if we have allready applied this layer + if [[ -f "/${FILENAME}" ]] && [[ "${SHALAYER}" == "$(cat /"${FILENAME}")" ]]; then + echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping" + else + # Download and extract layer to / + curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ + --silent \ + --location \ + --request GET \ + --header "Authorization: Bearer ${TOKEN}" \ + "${BLOB_URL}${SHALAYER}" -o \ + /modtarball.tar.xz + mkdir -p /tmp/mod + tar xzf /modtarball.tar.xz -C /tmp/mod + if [[ -d /tmp/mod/etc/s6-overlay ]]; then + if [[ -d /tmp/mod/etc/cont-init.d ]]; then + rm -rf /tmp/mod/etc/cont-init.d + fi + if [[ -d /tmp/mod/etc/services.d ]]; then + rm -rf /tmp/mod/etc/services.d + fi + fi + shopt -s dotglob + cp -R /tmp/mod/* / + shopt -u dotglob + rm -rf /tmp/mod + rm -rf /modtarball.tar.xz + echo "${SHALAYER}" >"/${FILENAME}" + echo "[mod-init] ${DOCKER_MOD} applied to container" + fi + done + } fi diff --git a/.templates/99-custom_script.sh b/.templates/99-custom_script.sh index c3c8bce45..287b05230 100755 --- a/.templates/99-custom_script.sh +++ b/.templates/99-custom_script.sh @@ -6,5 +6,5 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") CONFIGSOURCE="$(dirname "${CONFIGSOURCE}")" if [ -f "$CONFIGSOURCE"/script.sh ]; then - "$CONFIGSOURCE"./script.sh + "$CONFIGSOURCE"./script.sh fi diff --git a/.templates/ha_autoapps.sh b/.templates/ha_autoapps.sh index 05bfecfc9..0a062149c 100755 --- a/.templates/ha_autoapps.sh +++ b/.templates/ha_autoapps.sh @@ -11,12 +11,12 @@ echo "To install : $PACKAGES" # Install bash if needed if ! command -v bash >/dev/null 2>/dev/null; then - (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null + (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null fi # Install curl if needed if ! command -v curl >/dev/null 2>/dev/null; then - (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null + (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null fi # Call apps installer script if needed diff --git a/.templates/ha_automatic_packages.sh b/.templates/ha_automatic_packages.sh index a064554fe..822facd4a 100755 --- a/.templates/ha_automatic_packages.sh +++ b/.templates/ha_automatic_packages.sh @@ -21,17 +21,17 @@ PACKAGES="${*:-}" ############################ if command -v "apk" &>/dev/null; then - # If apk based - [ "$VERBOSE" = true ] && echo "apk based" - PACKMANAGER="apk" + # If apk based + [ "$VERBOSE" = true ] && echo "apk based" + PACKMANAGER="apk" elif command -v "apt" &>/dev/null; then - # If apt-get based - [ "$VERBOSE" = true ] && echo "apt based" - PACKMANAGER="apt" + # If apt-get based + [ "$VERBOSE" = true ] && echo "apt based" + PACKMANAGER="apt" elif command -v "pacman" &>/dev/null; then - # If apt-get based - [ "$VERBOSE" = true ] && echo "pacman based" - PACKMANAGER="pacman" + # If apt-get based + [ "$VERBOSE" = true ] && echo "pacman based" + PACKMANAGER="pacman" fi ################### @@ -48,130 +48,130 @@ PACKAGES="$PACKAGES jq curl ca-certificates" # Scripts for files in "/etc/cont-init.d" "/etc/services.d"; do - # Next directory if does not exists - if ! ls $files 1>/dev/null 2>&1; then continue; fi + # Next directory if does not exists + if ! ls $files 1>/dev/null 2>&1; then continue; fi - # Test each possible command - COMMAND="nginx" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nginx" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nginx" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES nginx" - if ls /etc/nginx 1>/dev/null 2>&1; then mv /etc/nginx /etc/nginx2; fi - fi + # Test each possible command + COMMAND="nginx" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nginx" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nginx" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES nginx" + if ls /etc/nginx 1>/dev/null 2>&1; then mv /etc/nginx /etc/nginx2; fi + fi - COMMAND="mount" - if grep -q -rnw "$files/" -e "$COMMAND"; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES exfatprogs ntfs-3g ntfs-3g-progs squashfs-tools fuse lsblk" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES exfat* ntfs* squashfs-tools util-linux" - #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES ntfs-3g" - fi + COMMAND="mount" + if grep -q -rnw "$files/" -e "$COMMAND"; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES exfatprogs ntfs-3g ntfs-3g-progs squashfs-tools fuse lsblk" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES exfat* ntfs* squashfs-tools util-linux" + #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES ntfs-3g" + fi - COMMAND="ping" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES iputils" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES iputils-ping" - #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils" - fi + COMMAND="ping" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES iputils" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES iputils-ping" + #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils" + fi - COMMAND="nmap" - if grep -q -rnw "$files/" -e "$COMMAND"; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nmap nmap-scripts" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nmap" - #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils" - fi + COMMAND="nmap" + if grep -q -rnw "$files/" -e "$COMMAND"; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nmap nmap-scripts" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nmap" + #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils" + fi - COMMAND="cifs" - if grep -q -rnw "$files/" -e "$COMMAND"; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES cifs-utils keyutils" - fi + COMMAND="cifs" + if grep -q -rnw "$files/" -e "$COMMAND"; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES cifs-utils keyutils" + fi - COMMAND="smbclient" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES samba samba-client ntfs-3g" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES samba smbclient ntfs-3g" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES samba smbclient" - fi + COMMAND="smbclient" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES samba samba-client ntfs-3g" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES samba smbclient ntfs-3g" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES samba smbclient" + fi - COMMAND="dos2unix" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES dos2unix" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES dos2unix" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES dos2unix" - fi + COMMAND="dos2unix" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES dos2unix" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES dos2unix" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES dos2unix" + fi - COMMAND="openvpn" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES coreutils openvpn" - fi + COMMAND="openvpn" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES coreutils openvpn" + fi - COMMAND="jq" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES jq" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES jq" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES jq" - fi + COMMAND="jq" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES jq" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES jq" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES jq" + fi - COMMAND="yamllint" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES yamllint" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES yamllint" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES yamllint" - fi + COMMAND="yamllint" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES yamllint" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES yamllint" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES yamllint" + fi - COMMAND="git" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES git" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES git" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES git" - fi + COMMAND="git" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES git" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES git" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES git" + fi - COMMAND="sponge" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES moreutils" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES moreutils" - [ "$PACKMANAGER" = "pacman " ] && PACKAGES="$PACKAGES moreutils" - fi + COMMAND="sponge" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES moreutils" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES moreutils" + [ "$PACKMANAGER" = "pacman " ] && PACKAGES="$PACKAGES moreutils" + fi - COMMAND="sqlite3" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES sqlite" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES sqlite3" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES sqlite3" - fi + COMMAND="sqlite3" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES sqlite" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES sqlite3" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES sqlite3" + fi - COMMAND="pip" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES py3-pip" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES pip" - [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES pip" - fi + COMMAND="pip" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES py3-pip" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES pip" + [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES pip" + fi - COMMAND="wget" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES wget" - [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES wget" - [ "$PACKMANAGER" = "wget" ] && PACKAGES="$PACKAGES wget" - fi + COMMAND="wget" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES wget" + [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES wget" + [ "$PACKMANAGER" = "wget" ] && PACKAGES="$PACKAGES wget" + fi done @@ -187,15 +187,15 @@ if [ "$PACKMANAGER" = "pacman" ]; then pacman -Sy >/dev/null; fi # Install apps one by one to allow failures # shellcheck disable=SC2086 for packagestoinstall in $PACKAGES; do - [ "$VERBOSE" = true ] && echo "... $packagestoinstall" - if [ "$PACKMANAGER" = "apk" ]; then - apk add --no-cache "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) - elif [ "$PACKMANAGER" = "apt" ]; then - apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) - elif [ "$PACKMANAGER" = "pacman" ]; then - pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) - fi - [ "$VERBOSE" = true ] && echo "... $packagestoinstall done" + [ "$VERBOSE" = true ] && echo "... $packagestoinstall" + if [ "$PACKMANAGER" = "apk" ]; then + apk add --no-cache "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) + elif [ "$PACKMANAGER" = "apt" ]; then + apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) + elif [ "$PACKMANAGER" = "pacman" ]; then + pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) + fi + [ "$VERBOSE" = true ] && echo "... $packagestoinstall done" done # Clean after install @@ -204,11 +204,11 @@ if [ "$PACKMANAGER" = "apt" ]; then apt-get clean >/dev/null; fi # Replace nginx if installed if ls /etc/nginx2 1>/dev/null 2>&1; then - [ "$VERBOSE" = true ] && echo "replace nginx2" - rm -r /etc/nginx - mv /etc/nginx2 /etc/nginx - mkdir -p /var/log/nginx - touch /var/log/nginx/error.log + [ "$VERBOSE" = true ] && echo "replace nginx2" + rm -r /etc/nginx + mv /etc/nginx2 /etc/nginx + mkdir -p /var/log/nginx + touch /var/log/nginx/error.log fi ####################### @@ -223,53 +223,53 @@ micro -plugin install filemanager || true for files in "/etc/services.d" "/etc/cont-init.d"; do - # Next directory if does not exists - if ! ls $files 1>/dev/null 2>&1; then continue; fi + # Next directory if does not exists + if ! ls $files 1>/dev/null 2>&1; then continue; fi - # Bashio - if grep -q -rnw "$files/" -e 'bashio' && [ ! -f "/usr/bin/bashio" ]; then - [ "$VERBOSE" = true ] && echo "install bashio" - BASHIO_VERSION="0.14.3" - mkdir -p /tmp/bashio - curl -f -L -s -S "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar -xzf - --strip 1 -C /tmp/bashio - mv /tmp/bashio/lib /usr/lib/bashio - ln -s /usr/lib/bashio/bashio /usr/bin/bashio - rm -rf /tmp/bashio - fi + # Bashio + if grep -q -rnw "$files/" -e 'bashio' && [ ! -f "/usr/bin/bashio" ]; then + [ "$VERBOSE" = true ] && echo "install bashio" + BASHIO_VERSION="0.14.3" + mkdir -p /tmp/bashio + curl -f -L -s -S "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar -xzf - --strip 1 -C /tmp/bashio + mv /tmp/bashio/lib /usr/lib/bashio + ln -s /usr/lib/bashio/bashio /usr/bin/bashio + rm -rf /tmp/bashio + fi - # Lastversion - COMMAND="lastversion" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "install $COMMAND" - pip install $COMMAND - fi + # Lastversion + COMMAND="lastversion" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "install $COMMAND" + pip install $COMMAND + fi - # Tempio - if grep -q -rnw "$files/" -e 'tempio' && [ ! -f "/usr/bin/tempio" ]; then - [ "$VERBOSE" = true ] && echo "install tempio" - TEMPIO_VERSION="2021.09.0" - BUILD_ARCH="$(bashio::info.arch)" - curl -f -L -f -s -o /usr/bin/tempio "https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}" - chmod a+x /usr/bin/tempio - fi + # Tempio + if grep -q -rnw "$files/" -e 'tempio' && [ ! -f "/usr/bin/tempio" ]; then + [ "$VERBOSE" = true ] && echo "install tempio" + TEMPIO_VERSION="2021.09.0" + BUILD_ARCH="$(bashio::info.arch)" + curl -f -L -f -s -o /usr/bin/tempio "https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}" + chmod a+x /usr/bin/tempio + fi - # Mustache - COMMAND="mustache" - if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then - [ "$VERBOSE" = true ] && echo "$COMMAND required" - [ "$PACKMANAGER" = "apk" ] && apk add --no-cache go npm && - apk upgrade --no-cache && - apk add --no-cache --virtual .build-deps build-base git go && - go get -u github.com/quantumew/mustache-cli && - cp "$GOPATH"/bin/* /usr/bin/ && - rm -rf "$GOPATH" /var/cache/apk/* /tmp/src && - apk del .build-deps xz build-base - [ "$PACKMANAGER" = "apt" ] && apt-get update && - apt-get install -yqq go npm node-mustache - fi + # Mustache + COMMAND="mustache" + if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then + [ "$VERBOSE" = true ] && echo "$COMMAND required" + [ "$PACKMANAGER" = "apk" ] && apk add --no-cache go npm && + apk upgrade --no-cache && + apk add --no-cache --virtual .build-deps build-base git go && + go get -u github.com/quantumew/mustache-cli && + cp "$GOPATH"/bin/* /usr/bin/ && + rm -rf "$GOPATH" /var/cache/apk/* /tmp/src && + apk del .build-deps xz build-base + [ "$PACKMANAGER" = "apt" ] && apt-get update && + apt-get install -yqq go npm node-mustache + fi done if [ -f /ERROR ]; then - exit 1 + exit 1 fi diff --git a/.templates/ha_automodules.sh b/.templates/ha_automodules.sh index 223360d45..192baf2b0 100755 --- a/.templates/ha_automodules.sh +++ b/.templates/ha_automodules.sh @@ -12,12 +12,12 @@ echo "To download : $MODULES" # Install bash if not available if ! command -v bash >/dev/null 2>/dev/null; then - (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null + (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null fi # Install curl if not available if ! command -v curl >/dev/null 2>/dev/null; then - (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null + (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null fi # Install ca-certificates if not available @@ -28,9 +28,9 @@ mkdir -p /etc/cont-init.d # Download scripts for scripts in $MODULES; do - echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && - [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || - (echo "script failed to install $scripts" && exit 1) + echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && + [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || + (echo "script failed to install $scripts" && exit 1) done chmod -R 755 /etc/cont-init.d diff --git a/.templates/ha_entrypoint.sh b/.templates/ha_entrypoint.sh index cbc78dcb9..e68542fd7 100755 --- a/.templates/ha_entrypoint.sh +++ b/.templates/ha_entrypoint.sh @@ -8,48 +8,48 @@ echo "Starting..." #################### for SCRIPTS in /etc/cont-init.d/*; do - [ -e "$SCRIPTS" ] || continue - echo "$SCRIPTS: executing" + [ -e "$SCRIPTS" ] || continue + echo "$SCRIPTS: executing" - # Check if run as root - if [ "$(id -u)" -eq 0 ]; then - chown "$(id -u)":"$(id -g)" "$SCRIPTS" - chmod a+x "$SCRIPTS" - else - echo -e "\e[38;5;214m$(date) WARNING: Script executed with user $(id -u):$(id -g), things can break and chown won't work\e[0m" - # Disable chown and chmod in scripts - sed -i "s/^chown /true # chown /g" "$SCRIPTS" - sed -i "s/ chown / true # chown /g" "$SCRIPTS" - sed -i "s/^chmod /true # chmod /g" "$SCRIPTS" - sed -i "s/ chmod / true # chmod /g" "$SCRIPTS" - fi + # Check if run as root + if [ "$(id -u)" -eq 0 ]; then + chown "$(id -u)":"$(id -g)" "$SCRIPTS" + chmod a+x "$SCRIPTS" + else + echo -e "\e[38;5;214m$(date) WARNING: Script executed with user $(id -u):$(id -g), things can break and chown won't work\e[0m" + # Disable chown and chmod in scripts + sed -i "s/^chown /true # chown /g" "$SCRIPTS" + sed -i "s/ chown / true # chown /g" "$SCRIPTS" + sed -i "s/^chmod /true # chmod /g" "$SCRIPTS" + sed -i "s/ chmod / true # chmod /g" "$SCRIPTS" + fi - # Get current shebang, if not available use another - currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")" - if [ ! -f "${currentshebang%% *}" ]; then - for shebang in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/usr/bin/bash" "/usr/bin/sh" "/bin/bash" "/bin/sh"; do - command_path="${shebang%% *}" - if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then - echo "Valid shebang: $shebang" - break - fi - done - sed -i "s|$currentshebang|$shebang|g" "$SCRIPTS" - fi + # Get current shebang, if not available use another + currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")" + if [ ! -f "${currentshebang%% *}" ]; then + for shebang in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/usr/bin/bash" "/usr/bin/sh" "/bin/bash" "/bin/sh"; do + command_path="${shebang%% *}" + if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then + echo "Valid shebang: $shebang" + break + fi + done + sed -i "s|$currentshebang|$shebang|g" "$SCRIPTS" + fi - # Use source to share env variables when requested - if [ "${ha_entry_source:-null}" = true ] && command -v "source" &>/dev/null; then - sed -i "s/(.*\s|^)exit ([0-9]+)/\1 return \2 || exit \2/g" "$SCRIPTS" - sed -i "s/bashio::exit.nok/return 1/g" "$SCRIPTS" - sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS" - # shellcheck disable=SC1090 - source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" - else - "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" - fi + # Use source to share env variables when requested + if [ "${ha_entry_source:-null}" = true ] && command -v "source" &>/dev/null; then + sed -i "s/(.*\s|^)exit ([0-9]+)/\1 return \2 || exit \2/g" "$SCRIPTS" + sed -i "s/bashio::exit.nok/return 1/g" "$SCRIPTS" + sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS" + # shellcheck disable=SC1090 + source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" + else + "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" + fi - # Cleanup - rm "$SCRIPTS" + # Cleanup + rm "$SCRIPTS" done @@ -59,38 +59,41 @@ done # If PID 1, keep alive and manage sigterm if [ "$$" -eq 1 ]; then - echo " " - echo -e "\033[0;32mEverything started!\033[0m" - terminate() { - echo "Termination signal received, forwarding to subprocesses..." - # Terminate all subprocesses - if command -v pgrep &>/dev/null; then - for pid in $(pgrep -P $$); do - echo "Terminating child PID $pid" - kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid" - done - else - # Fallback to iterating through /proc if pgrep is not available - for pid in /proc/[0-9]*/; do - pid=${pid#/proc/} - pid=${pid%/} - if [[ "$pid" -ne 1 ]] && grep -q "^PPid:\s*$$" "/proc/$pid/status" 2>/dev/null; then - echo "Terminating child PID $pid" - kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid" - fi - done - fi - - wait - echo "All subprocesses terminated. Exiting." - exit 0 - } - trap terminate SIGTERM SIGINT - while :; do sleep infinity & wait $!; done + echo " " + echo -e "\033[0;32mEverything started!\033[0m" + terminate() { + echo "Termination signal received, forwarding to subprocesses..." + # Terminate all subprocesses + if command -v pgrep &>/dev/null; then + for pid in $(pgrep -P $$); do + echo "Terminating child PID $pid" + kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid" + done + else + # Fallback to iterating through /proc if pgrep is not available + for pid in /proc/[0-9]*/; do + pid=${pid#/proc/} + pid=${pid%/} + if [[ "$pid" -ne 1 ]] && grep -q "^PPid:\s*$$" "/proc/$pid/status" 2>/dev/null; then + echo "Terminating child PID $pid" + kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid" + fi + done + fi + + wait + echo "All subprocesses terminated. Exiting." + exit 0 + } + trap terminate SIGTERM SIGINT + while :; do + sleep infinity & + wait $! + done else - echo " " - echo -e "\033[0;32mStarting the upstream container\033[0m" - echo " " - # Launch lsio mods - if [ -f /docker-mods ]; then exec /docker-mods; fi + echo " " + echo -e "\033[0;32mStarting the upstream container\033[0m" + echo " " + # Launch lsio mods + if [ -f /docker-mods ]; then exec /docker-mods; fi fi diff --git a/.templates/ha_entrypoint_modif.sh b/.templates/ha_entrypoint_modif.sh index f2f688c97..7de949f49 100755 --- a/.templates/ha_entrypoint_modif.sh +++ b/.templates/ha_entrypoint_modif.sh @@ -12,23 +12,23 @@ PUID="${PUID:-0}" PGID="${PGID:-0}" if [ -f /ha_entrypoint.sh ]; then - chown -R "$PUID:$PGID" /ha_entrypoint.sh - chmod -R 755 /ha_entrypoint.sh + chown -R "$PUID:$PGID" /ha_entrypoint.sh + chmod -R 755 /ha_entrypoint.sh fi if [ -d /etc/cont-init.d ]; then - chown -R "$PUID:$PGID" /etc/cont-init.d - chmod -R 755 /etc/cont-init.d + chown -R "$PUID:$PGID" /etc/cont-init.d + chmod -R 755 /etc/cont-init.d fi if [ -d /etc/services.d ]; then - chown -R "$PUID:$PGID" /etc/services.d - chmod -R 755 /etc/services.d + chown -R "$PUID:$PGID" /etc/services.d + chmod -R 755 /etc/services.d fi if [ -d /etc/s6-rc.d ]; then - chown -R "$PUID:$PGID" /etc/s6-rc.d - chmod -R 755 /etc/s6-rc.d + chown -R "$PUID:$PGID" /etc/s6-rc.d + chmod -R 755 /etc/s6-rc.d fi # Correct shebang in entrypoint @@ -39,11 +39,11 @@ mkdir -p /run/s6/container_environment # Check if shebang exists for shebang in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/usr/bin/bash" "/usr/bin/sh" "/bin/bash" "/bin/sh"; do - command_path="${shebang%% *}" - if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then - echo "Valid shebang: $shebang" - break - fi + command_path="${shebang%% *}" + if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then + echo "Valid shebang: $shebang" + break + fi done # Define shebang @@ -51,12 +51,12 @@ sed -i "s|/command/with-contenv bashio|$shebang|g" /ha_entrypoint.sh # Correct for scripts for string in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio"; do - grep -sril "$string" /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d | while read -r files; do - sed -i "s|$string|$shebang|g" "$files" - done + grep -sril "$string" /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d | while read -r files; do + sed -i "s|$string|$shebang|g" "$files" + done done # Avoid interference with LOG_LEVEL used in the app if [ -f /usr/lib/bashio/bashio.sh ]; then - sed -i 's|{LOG_LEVEL:|{BASHIO_LOG_LEVEL:|g' /usr/lib/bashio/bashio.sh + sed -i 's|{LOG_LEVEL:|{BASHIO_LOG_LEVEL:|g' /usr/lib/bashio/bashio.sh fi diff --git a/.templates/ha_lsio.sh b/.templates/ha_lsio.sh index 8179965f5..fc4f2138b 100755 --- a/.templates/ha_lsio.sh +++ b/.templates/ha_lsio.sh @@ -12,48 +12,48 @@ echo "Setting config to $CONFIGLOCATION" # Avoid custom-init.d duplications for file in $(grep -sril 'Potential tampering with custom' /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d); do - rm -f "$file" + rm -f "$file" done # If custom config if [ "$CONFIGLOCATION" != "/config" ]; then - # Create new config folder if needed - for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do - sed -i "1a mkdir -p $CONFIGLOCATION" "$file" - done + # Create new config folder if needed + for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do + sed -i "1a mkdir -p $CONFIGLOCATION" "$file" + done - # Correct config location - for file in $(grep -Esril "/config[ '\"/]|/config\$" /etc /defaults); do - sed -Ei "s=(/config)+(/| |$|\"|\')=$CONFIGLOCATION\2=g" "$file" - done + # Correct config location + for file in $(grep -Esril "/config[ '\"/]|/config\$" /etc /defaults); do + sed -Ei "s=(/config)+(/| |$|\"|\')=$CONFIGLOCATION\2=g" "$file" + done fi # Allow UID and GID setting for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do - sed -i 's/bash/bashio/g' "$file" && sed -i '1a PUID="$(if bashio::config.has_value "PUID"; then bashio::config "PUID"; else echo "0"; fi)"' "$file" - sed -i '1a PGID="$(if bashio::config.has_value "PGID"; then bashio::config "PGID"; else echo "0"; fi)"' "$file" + sed -i 's/bash/bashio/g' "$file" && sed -i '1a PUID="$(if bashio::config.has_value "PUID"; then bashio::config "PUID"; else echo "0"; fi)"' "$file" + sed -i '1a PGID="$(if bashio::config.has_value "PGID"; then bashio::config "PGID"; else echo "0"; fi)"' "$file" done # Avoid chmod /config if ha config mounted if [ -f /config/configuration.yaml ] || [ -f /config/configuration.json ]; then - for file in /etc/services.d/*/* /etc/cont-init.d/* /etc/s6-overlay/s6-rc.d/*/*; do - if [ -f "$file" ] && [ -n "$(awk '/chown.*abc:abc.*\\/,/.*\/config( |$)/{print FILENAME}' "$file")" ]; then - sed -i "s|/config$|/data|g" "$file" - fi - done + for file in /etc/services.d/*/* /etc/cont-init.d/* /etc/s6-overlay/s6-rc.d/*/*; do + if [ -f "$file" ] && [ -n "$(awk '/chown.*abc:abc.*\\/,/.*\/config( |$)/{print FILENAME}' "$file")" ]; then + sed -i "s|/config$|/data|g" "$file" + fi + done fi # Send crond logs to addon logs if [ -f /etc/s6-overlay/s6-rc.d/svc-cron/run ]; then - sed -i "/exec busybox crond/c exec busybox crond -f -S -L /proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run - sed -i "/exec \/usr\/sbin\/cron/c exec /usr/sbin/cron -f &>/proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run + sed -i "/exec busybox crond/c exec busybox crond -f -S -L /proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run + sed -i "/exec \/usr\/sbin\/cron/c exec /usr/sbin/cron -f &>/proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run fi # variables not found for file in $(grep -srl "/usr/bin" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do - sed -i "1a set +u" "$file" + sed -i "1a set +u" "$file" done # Allow running abc as user 1 @@ -62,7 +62,7 @@ sed -i '/groupmod/ s/$/ 2>\/dev\/null || true/' /etc/s6-overlay/s6-rc.d/init-add # Replace lsiown if not found if [ ! -f /usr/bin/lsiown ]; then - for file in $(grep -sril "lsiown" /etc); do - sed -i "s|lsiown|chown|g" "$file" - done + for file in $(grep -sril "lsiown" /etc); do + sed -i "s|lsiown|chown|g" "$file" + done fi diff --git a/addons_updater/rootfs/etc/cont-init.d/99-run.sh b/addons_updater/rootfs/etc/cont-init.d/99-run.sh index 8baa1aab4..547272157 100755 --- a/addons_updater/rootfs/etc/cont-init.d/99-run.sh +++ b/addons_updater/rootfs/etc/cont-init.d/99-run.sh @@ -9,7 +9,7 @@ set -e bashio::log.info "Starting $(lastversion --version)" if bashio::config.true "dry_run"; then - bashio::log.warning "Dry run mode : on" + bashio::log.warning "Dry run mode : on" fi bashio::log.info "Checking status of referenced repositoriess..." @@ -26,9 +26,9 @@ git config --system user.name "${GITUSER}" if [[ "$GITMAIL" != "null" ]]; then git config --system user.email "${GITMAIL}"; fi if bashio::config.has_value 'gitapi'; then - LOGINFO="... setting github API" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - GITHUB_API_TOKEN=$(bashio::config 'gitapi') - export GITHUB_API_TOKEN + LOGINFO="... setting github API" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + GITHUB_API_TOKEN=$(bashio::config 'gitapi') + export GITHUB_API_TOKEN fi #Create or update local version @@ -36,14 +36,14 @@ REPOSITORY=$(bashio::config 'repository') BASENAME=$(basename "https://github.com/$REPOSITORY") if [ ! -d "/data/$BASENAME" ]; then - LOGINFO="... cloning ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - cd /data/ || exit - git clone "https://github.com/${REPOSITORY}" + LOGINFO="... cloning ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + cd /data/ || exit + git clone "https://github.com/${REPOSITORY}" else - LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - cd "/data/$BASENAME" || exit - git pull --rebase origin >/dev/null || git reset --hard origin/master >/dev/null - git pull --rebase origin >/dev/null || ( rm -r "/data/$BASENAME" && git clone "https://github.com/${REPOSITORY}" ) + LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + cd "/data/$BASENAME" || exit + git pull --rebase origin >/dev/null || git reset --hard origin/master >/dev/null + git pull --rebase origin >/dev/null || (rm -r "/data/$BASENAME" && git clone "https://github.com/${REPOSITORY}") fi LOGINFO="... parse addons" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi @@ -53,271 +53,282 @@ LOGINFO="... parse addons" && if [ "$VERBOSE" = true ]; then bashio::log.info "$ cd /data/"$BASENAME" || exit for f in */; do - if [ -f /data/"$BASENAME"/"$f"/updater.json ]; then - SLUG=${f//\/} + if [ -f /data/"$BASENAME"/"$f"/updater.json ]; then + SLUG=${f//\//} - # Rebase - LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - cd "/data/$BASENAME" || exit - git pull --rebase &>/dev/null || git reset --hard &>/dev/null - git pull --rebase &>/dev/null + # Rebase + LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + cd "/data/$BASENAME" || exit + git pull --rebase &>/dev/null || git reset --hard &>/dev/null + git pull --rebase &>/dev/null - #Define the folder addon - LOGINFO="... $SLUG : checking slug exists in repo" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - cd /data/"${BASENAME}"/"${SLUG}" || { bashio::log.error "$SLUG addon not found in this repository. Exiting."; continue; } + #Define the folder addon + LOGINFO="... $SLUG : checking slug exists in repo" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + cd /data/"${BASENAME}"/"${SLUG}" || { + bashio::log.error "$SLUG addon not found in this repository. Exiting." + continue + } - # Get variables - UPSTREAM=$(jq -r .upstream_repo updater.json) - BETA=$(jq -r .github_beta updater.json) - FULLTAG=$(jq -r .github_fulltag updater.json) - HAVINGASSET=$(jq -r .github_havingasset updater.json) - SOURCE=$(jq -r .source updater.json) - FILTER_TEXT=$(jq -r .github_tagfilter updater.json) - EXCLUDE_TEXT=$(jq -r .github_exclude updater.json) - EXCLUDE_TEXT="${EXCLUDE_TEXT:-zzzzzzzzzzzzzzzz}" - PAUSED=$(jq -r .paused updater.json) - DATE="$(date '+%d-%m-%Y')" - BYDATE=$(jq -r .dockerhub_by_date updater.json) + # Get variables + UPSTREAM=$(jq -r .upstream_repo updater.json) + BETA=$(jq -r .github_beta updater.json) + FULLTAG=$(jq -r .github_fulltag updater.json) + HAVINGASSET=$(jq -r .github_havingasset updater.json) + SOURCE=$(jq -r .source updater.json) + FILTER_TEXT=$(jq -r .github_tagfilter updater.json) + EXCLUDE_TEXT=$(jq -r .github_exclude updater.json) + EXCLUDE_TEXT="${EXCLUDE_TEXT:-zzzzzzzzzzzzzzzz}" + PAUSED=$(jq -r .paused updater.json) + DATE="$(date '+%d-%m-%Y')" + BYDATE=$(jq -r .dockerhub_by_date updater.json) - # Number of elements to check in dockerhub - if grep -q "dockerhub_list_size" updater.json; then - LISTSIZE=$(jq -r .dockerhub_list_size updater.json) - else - LISTSIZE=100 - fi + # Number of elements to check in dockerhub + if grep -q "dockerhub_list_size" updater.json; then + LISTSIZE=$(jq -r .dockerhub_list_size updater.json) + else + LISTSIZE=100 + fi - #Skip if paused - if [[ "$PAUSED" = true ]]; then bashio::log.magenta "... $SLUG addon updates are paused, skipping"; continue; fi + #Skip if paused + if [[ "$PAUSED" = true ]]; then + bashio::log.magenta "... $SLUG addon updates are paused, skipping" + continue + fi - #Find current version - LOGINFO="... $SLUG : get current version" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - CURRENT=$(jq .upstream_version updater.json) || \ - { bashio::log.error "$SLUG addon upstream tag not found in updater.json. Exiting."; continue; } + #Find current version + LOGINFO="... $SLUG : get current version" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + CURRENT=$(jq .upstream_version updater.json) || + { + bashio::log.error "$SLUG addon upstream tag not found in updater.json. Exiting." + continue + } - if [[ "$SOURCE" = dockerhub ]]; then - # Use dockerhub as upstream - # shellcheck disable=SC2116 - LOGINFO="... Source is dockerhub" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + if [[ "$SOURCE" = dockerhub ]]; then + # Use dockerhub as upstream + # shellcheck disable=SC2116 + LOGINFO="... Source is dockerhub" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - #Prepare tag flag - if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then - FILTER_TEXT="" - else - LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - FILTER_TEXT="&name=$FILTER_TEXT" - fi + #Prepare tag flag + if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then + FILTER_TEXT="" + else + LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + FILTER_TEXT="&name=$FILTER_TEXT" + fi - #Prepare tag flag - if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then - EXCLUDE_TEXT="zzzzzzzzzzzzzzzzzz" - fi + #Prepare tag flag + if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then + EXCLUDE_TEXT="zzzzzzzzzzzzzzzzzz" + fi - DOCKERHUB_REPO="${UPSTREAM%%/*}" - DOCKERHUB_IMAGE=$(echo "$UPSTREAM" | cut -d "/" -f2) - LASTVERSION=$( - curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" | - jq '.results | .[] | .name' -r | - sed -e '/.*latest.*/d' | - sed -e '/.*dev.*/d' | - sed -e '/.*nightly.*/d' | - sed -e '/.*beta.*/d' | - sed -e "/.*$EXCLUDE_TEXT.*/d" | - sort -V | - tail -n 1 - ) + DOCKERHUB_REPO="${UPSTREAM%%/*}" + DOCKERHUB_IMAGE=$(echo "$UPSTREAM" | cut -d "/" -f2) + LASTVERSION=$( + curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" | + jq '.results | .[] | .name' -r | + sed -e '/.*latest.*/d' | + sed -e '/.*dev.*/d' | + sed -e '/.*nightly.*/d' | + sed -e '/.*beta.*/d' | + sed -e "/.*$EXCLUDE_TEXT.*/d" | + sort -V | + tail -n 1 + ) - [ "${BETA}" = true ] && \ - LASTVERSION=$( - curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" | - jq '.results | .[] | .name' -r | - sed -e '/.*latest.*/d' | - sed -e '/.*dev.*/!d' | - sed -e "/.*$EXCLUDE_TEXT.*/d" | - sort -V | - tail -n 1 - ) + [ "${BETA}" = true ] && + LASTVERSION=$( + curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" | + jq '.results | .[] | .name' -r | + sed -e '/.*latest.*/d' | + sed -e '/.*dev.*/!d' | + sed -e "/.*$EXCLUDE_TEXT.*/d" | + sort -V | + tail -n 1 + ) - [ "${BYDATE}" = true ] && \ - LASTVERSION=$(curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" | - jq '.results | .[] | .name' -r | - sed -e '/.*latest.*/d' | - sed -e '/.*dev.*/d' | - sed -e '/.*nightly.*/d' | - sed -e "/.*$EXCLUDE_TEXT.*/d" | - sort -V | - tail -n 1 - ) && \ - DATE=$(curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags/?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" | - jq '.results[] | select(.name==$LASTVERSION) | .last_updated' -r --arg LASTVERSION "$LASTVERSION" - ) && \ - DATE="${DATE%T*}" && \ - LASTVERSION="$LASTVERSION-$DATE" - LOGINFO="... $SLUG : bydate is true, version is $LASTVERSION" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + [ "${BYDATE}" = true ] && + LASTVERSION=$( + curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" | + jq '.results | .[] | .name' -r | + sed -e '/.*latest.*/d' | + sed -e '/.*dev.*/d' | + sed -e '/.*nightly.*/d' | + sed -e "/.*$EXCLUDE_TEXT.*/d" | + sort -V | + tail -n 1 + ) && + DATE=$( + curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags/?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" | + jq '.results[] | select(.name==$LASTVERSION) | .last_updated' -r --arg LASTVERSION "$LASTVERSION" + ) && + DATE="${DATE%T*}" && + LASTVERSION="$LASTVERSION-$DATE" + LOGINFO="... $SLUG : bydate is true, version is $LASTVERSION" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - else + else - # Use source as upstream - ARGUMENTS="--at $SOURCE" - LOGINFO="... $SLUG : source is $SOURCE" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + # Use source as upstream + ARGUMENTS="--at $SOURCE" + LOGINFO="... $SLUG : source is $SOURCE" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - #Prepare tag flag - if [ "${FULLTAG}" = true ]; then - LOGINFO="... $SLUG : fulltag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - ARGUMENTS="$ARGUMENTS --format tag" - else - LOGINFO="... $SLUG : fulltag is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - fi + #Prepare tag flag + if [ "${FULLTAG}" = true ]; then + LOGINFO="... $SLUG : fulltag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + ARGUMENTS="$ARGUMENTS --format tag" + else + LOGINFO="... $SLUG : fulltag is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + fi - #Prepare tag flag - if [ "${HAVINGASSET}" = true ]; then - LOGINFO="... $SLUG : asset_only tag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - ARGUMENTS="$ARGUMENTS --having-asset" - else - LOGINFO="... $SLUG : asset_only is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - fi + #Prepare tag flag + if [ "${HAVINGASSET}" = true ]; then + LOGINFO="... $SLUG : asset_only tag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + ARGUMENTS="$ARGUMENTS --having-asset" + else + LOGINFO="... $SLUG : asset_only is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + fi - #Prepare tag flag - if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then - FILTER_TEXT="" - else - LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - ARGUMENTS="$ARGUMENTS --only $FILTER_TEXT" - fi + #Prepare tag flag + if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then + FILTER_TEXT="" + else + LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + ARGUMENTS="$ARGUMENTS --only $FILTER_TEXT" + fi - #Prepare tag flag - if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then - EXCLUDE_TEXT="" - else - LOGINFO="... $SLUG : github_exclude is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - ARGUMENTS="$ARGUMENTS --exclude $EXCLUDE_TEXT" - fi + #Prepare tag flag + if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then + EXCLUDE_TEXT="" + else + LOGINFO="... $SLUG : github_exclude is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + ARGUMENTS="$ARGUMENTS --exclude $EXCLUDE_TEXT" + fi - #If beta flag, select beta version - if [ "${BETA}" = true ]; then - LOGINFO="... $SLUG : beta is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - ARGUMENTS="$ARGUMENTS --pre" - else - LOGINFO="... $SLUG : beta is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - fi - - # If failure, checks if there is packages that could be used - function test_packages () { - if [ "$VERBOSE" = true ]; then - # shellcheck disable=SC2086 - bashio::log.info "source : $SOURCE and LASTVERSION : $(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" - fi - # shellcheck disable=SC2086 - if [[ "$SOURCE" == *"github"* ]] && [[ "$(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" == *"No release"* ]]; then - # Is there a package - bashio::log.warning "No version found, looking if packages available" - last_packages="$(curl -s -L https://github.com/"$UPSTREAM"/packages | sed -n "s/.*\/container\/package\/\([^\"]*\).*/\1/p")" || true - last_package="$(echo "$last_packages" | head -n 1)" || true - if [[ "$(echo -n "$last_packages" | grep -c '^')" -gt 0 ]]; then - bashio::log.warning "A total of $(echo -n "$last_packages" | grep -c '^') packages were found, using $last_package" - LASTVERSION="" - LASTVERSION="$(curl -s -L https://github.com/"$UPSTREAM"/pkgs/container/"$last_package" | sed -n "s/.*?tag=\([^\"]*\)\">.*/\1/p" | - sed -e '/.*latest.*/d' | - sed -e '/.*dev.*/d' | - sed -e '/.*nightly.*/d' | - sed -e '/.*beta.*/d' | - sort -V | - tail -n 1)" || true - if [[ "$LASTVERSION" == "" ]]; then - # Continue to next - bashio::log.warning "No packages found" - set_continue=true - else - bashio::log.info "Found tag $LASTVERSION" - echo "$LASTVERSION" - fi - else - # Continue to next - bashio::log.warning "No packages found" - set_continue=true - fi - else - # Continue to next - set_continue=true - fi - } - - # shellcheck disable=SC2086 - LASTVERSION="$(lastversion "$UPSTREAM" $ARGUMENTS || test_packages)" - - # Continue if issue - if [[ "${set_continue:-false}" == true ]]; then - continue - fi + #If beta flag, select beta version + if [ "${BETA}" = true ]; then + LOGINFO="... $SLUG : beta is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + ARGUMENTS="$ARGUMENTS --pre" + else + LOGINFO="... $SLUG : beta is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + fi - fi + # If failure, checks if there is packages that could be used + function test_packages() { + if [ "$VERBOSE" = true ]; then + # shellcheck disable=SC2086 + bashio::log.info "source : $SOURCE and LASTVERSION : $(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" + fi + # shellcheck disable=SC2086 + if [[ "$SOURCE" == *"github"* ]] && [[ "$(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" == *"No release"* ]]; then + # Is there a package + bashio::log.warning "No version found, looking if packages available" + last_packages="$(curl -s -L https://github.com/"$UPSTREAM"/packages | sed -n "s/.*\/container\/package\/\([^\"]*\).*/\1/p")" || true + last_package="$(echo "$last_packages" | head -n 1)" || true + if [[ "$(echo -n "$last_packages" | grep -c '^')" -gt 0 ]]; then + bashio::log.warning "A total of $(echo -n "$last_packages" | grep -c '^') packages were found, using $last_package" + LASTVERSION="" + LASTVERSION="$(curl -s -L https://github.com/"$UPSTREAM"/pkgs/container/"$last_package" | sed -n "s/.*?tag=\([^\"]*\)\">.*/\1/p" | + sed -e '/.*latest.*/d' | + sed -e '/.*dev.*/d' | + sed -e '/.*nightly.*/d' | + sed -e '/.*beta.*/d' | + sort -V | + tail -n 1)" || true + if [[ "$LASTVERSION" == "" ]]; then + # Continue to next + bashio::log.warning "No packages found" + set_continue=true + else + bashio::log.info "Found tag $LASTVERSION" + echo "$LASTVERSION" + fi + else + # Continue to next + bashio::log.warning "No packages found" + set_continue=true + fi + else + # Continue to next + set_continue=true + fi + } - # Add brackets - LASTVERSION='"'${LASTVERSION}'"' + # shellcheck disable=SC2086 + LASTVERSION="$(lastversion "$UPSTREAM" $ARGUMENTS || test_packages)" - # Avoid characters incompatible with HomeAssistant version name - LASTVERSION2=${LASTVERSION//+/-} - CURRENT2=${CURRENT//+/-} + # Continue if issue + if [[ "${set_continue:-false}" == true ]]; then + continue + fi - # Update if needed - if [ "${CURRENT2}" != "${LASTVERSION2}" ]; then - LOGINFO="... $SLUG : update from ${CURRENT} to ${LASTVERSION}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + fi - #Change all instances of version - LOGINFO="... $SLUG : updating files" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - for files in "config.json" "config.yaml" "Dockerfile" "build.json" "build.yaml";do - if [ -f /data/"${BASENAME}"/"${SLUG}"/$files ]; then - sed -i "s/${CURRENT}/${LASTVERSION}/g" /data/"${BASENAME}"/"${SLUG}"/"$files" - fi - done + # Add brackets + LASTVERSION='"'${LASTVERSION}'"' - # Remove " and modify version - LASTVERSION=${LASTVERSION//\"/} - CURRENT=${CURRENT//\"/} - if [ -f /data/"${BASENAME}"/"${SLUG}"/config.json ]; then - jq --arg variable "$LASTVERSION" '.version = $variable' /data/"${BASENAME}"/"${SLUG}"/config.json | sponge /data/"${BASENAME}"/"${SLUG}"/config.json # Replace version tag - elif [ -f /data/"${BASENAME}"/"${SLUG}"/config.yaml ]; then - sed -i "/version:/c\version: \"$LASTVERSION\"" /data/"${BASENAME}"/"${SLUG}"/config.yaml - fi - jq --arg variable "$LASTVERSION" '.upstream_version = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace upstream tag - jq --arg variable "$DATE" '.last_update = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace date tag + # Avoid characters incompatible with HomeAssistant version name + LASTVERSION2=${LASTVERSION//+/-} + CURRENT2=${CURRENT//+/-} - #Update changelog - touch "/data/${BASENAME}/${SLUG}/CHANGELOG.md" - if [[ "$SOURCE" == *"github"* ]]; then - sed -i "1i - Update to latest version from $UPSTREAM (changelog : https://github.com/${UPSTREAM%/}/releases)" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" - else - sed -i "1i - Update to latest version from $UPSTREAM" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" - fi - sed -i "1i ## ${LASTVERSION} (${DATE})" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" - sed -i "1i " "/data/${BASENAME}/${SLUG}/CHANGELOG.md" - LOGINFO="... $SLUG : files updated" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + # Update if needed + if [ "${CURRENT2}" != "${LASTVERSION2}" ]; then + LOGINFO="... $SLUG : update from ${CURRENT} to ${LASTVERSION}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - #Git commit and push - git add -A # add all modified files + #Change all instances of version + LOGINFO="... $SLUG : updating files" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + for files in "config.json" "config.yaml" "Dockerfile" "build.json" "build.yaml"; do + if [ -f /data/"${BASENAME}"/"${SLUG}"/$files ]; then + sed -i "s/${CURRENT}/${LASTVERSION}/g" /data/"${BASENAME}"/"${SLUG}"/"$files" + fi + done - git commit -m "Updater bot : $SLUG updated to ${LASTVERSION}" >/dev/null + # Remove " and modify version + LASTVERSION=${LASTVERSION//\"/} + CURRENT=${CURRENT//\"/} + if [ -f /data/"${BASENAME}"/"${SLUG}"/config.json ]; then + jq --arg variable "$LASTVERSION" '.version = $variable' /data/"${BASENAME}"/"${SLUG}"/config.json | sponge /data/"${BASENAME}"/"${SLUG}"/config.json # Replace version tag + elif [ -f /data/"${BASENAME}"/"${SLUG}"/config.yaml ]; then + sed -i "/version:/c\version: \"$LASTVERSION\"" /data/"${BASENAME}"/"${SLUG}"/config.yaml + fi + jq --arg variable "$LASTVERSION" '.upstream_version = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace upstream tag + jq --arg variable "$DATE" '.last_update = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace date tag - LOGINFO="... $SLUG : push to github" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi + #Update changelog + touch "/data/${BASENAME}/${SLUG}/CHANGELOG.md" + if [[ "$SOURCE" == *"github"* ]]; then + sed -i "1i - Update to latest version from $UPSTREAM (changelog : https://github.com/${UPSTREAM%/}/releases)" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" + else + sed -i "1i - Update to latest version from $UPSTREAM" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" + fi + sed -i "1i ## ${LASTVERSION} (${DATE})" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" + sed -i "1i " "/data/${BASENAME}/${SLUG}/CHANGELOG.md" + LOGINFO="... $SLUG : files updated" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - git remote set-url origin "https://${GITUSER}:${GITHUB_API_TOKEN}@github.com/${REPOSITORY}" &>/dev/null + #Git commit and push + git add -A # add all modified files - # Push - if ! bashio::config.true "dry_run"; then - git push &>/dev/null - fi + git commit -m "Updater bot : $SLUG updated to ${LASTVERSION}" >/dev/null - #Log - bashio::log.yellow "... $SLUG updated from ${CURRENT} to ${LASTVERSION}" + LOGINFO="... $SLUG : push to github" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi - else - bashio::log.green "... $SLUG is up-to-date ${CURRENT}" - fi - fi + git remote set-url origin "https://${GITUSER}:${GITHUB_API_TOKEN}@github.com/${REPOSITORY}" &>/dev/null + + # Push + if ! bashio::config.true "dry_run"; then + git push &>/dev/null + fi + + #Log + bashio::log.yellow "... $SLUG updated from ${CURRENT} to ${LASTVERSION}" + + else + bashio::log.green "... $SLUG is up-to-date ${CURRENT}" + fi + fi done || true # Continue even if issue # Clean dry run if bashio::config.true "dry_run"; then - rm -r /data/* + rm -r /data/* fi bashio::log.info "Addons update completed" diff --git a/arpspoof/rootfs/etc/cont-init.d/99-run.sh b/arpspoof/rootfs/etc/cont-init.d/99-run.sh index 9e054207b..99d273883 100755 --- a/arpspoof/rootfs/etc/cont-init.d/99-run.sh +++ b/arpspoof/rootfs/etc/cont-init.d/99-run.sh @@ -7,9 +7,9 @@ set +u # Autodefine if not defined if [ -n "$INTERFACE_NAME" ]; then - # shellcheck disable=SC2155 - export INTERFACE_NAME="$(ip route get 8.8.8.8 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')" - bashio::log.blue "Autodetection : INTERFACE_NAME=$INTERFACE_NAME" + # shellcheck disable=SC2155 + export INTERFACE_NAME="$(ip route get 8.8.8.8 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')" + bashio::log.blue "Autodetection : INTERFACE_NAME=$INTERFACE_NAME" fi bashio::log.info "Starting..." diff --git a/autobrr/rootfs/etc/cont-init.d/20-folders.sh b/autobrr/rootfs/etc/cont-init.d/20-folders.sh index 7d2e64d49..de0be3902 100755 --- a/autobrr/rootfs/etc/cont-init.d/20-folders.sh +++ b/autobrr/rootfs/etc/cont-init.d/20-folders.sh @@ -3,13 +3,13 @@ set -e if [ ! -d /data/autobrr ]; then - echo "Creating /data/autobrr" - mkdir -p /data/autobrr - chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /data/autobrr + echo "Creating /data/autobrr" + mkdir -p /data/autobrr + chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /data/autobrr fi if [ ! -d /config/addons_config/autobrr ]; then - echo "Creating /config/addons_config/autobrr" - mkdir -p /config/addons_config/autobrr - chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /config/addons_config/autobrr + echo "Creating /config/addons_config/autobrr" + mkdir -p /config/addons_config/autobrr + chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /config/addons_config/autobrr fi diff --git a/autobrr/rootfs/etc/cont-init.d/91-run.sh b/autobrr/rootfs/etc/cont-init.d/91-run.sh index 353441ef2..685792aff 100755 --- a/autobrr/rootfs/etc/cont-init.d/91-run.sh +++ b/autobrr/rootfs/etc/cont-init.d/91-run.sh @@ -9,7 +9,8 @@ set -e # Set UrlBase bashio::log.info "Starting NGinx..." -nginx & true +nginx & +true ############# # Start app # diff --git a/baikal/rootfs/etc/cont-init.d/01-migrate.sh b/baikal/rootfs/etc/cont-init.d/01-migrate.sh index 140caf329..4e4a12dd9 100755 --- a/baikal/rootfs/etc/cont-init.d/01-migrate.sh +++ b/baikal/rootfs/etc/cont-init.d/01-migrate.sh @@ -7,7 +7,7 @@ set -e #################### if [ -d /homeassistant/addons_config/baikal ]; then - echo "Moving database to new location /config, you won't be able to restore previous versions of the addon" - cp -rf /homeassistant/addons_config/baikal/* /config/ - rm -r /homeassistant/addons_config/baikal + echo "Moving database to new location /config, you won't be able to restore previous versions of the addon" + cp -rf /homeassistant/addons_config/baikal/* /config/ + rm -r /homeassistant/addons_config/baikal fi diff --git a/baikal/rootfs/etc/cont-init.d/90-run.sh b/baikal/rootfs/etc/cont-init.d/90-run.sh index f61fec4eb..55fee7088 100755 --- a/baikal/rootfs/etc/cont-init.d/90-run.sh +++ b/baikal/rootfs/etc/cont-init.d/90-run.sh @@ -8,6 +8,6 @@ chown -R nginx:nginx /data # Start app # Find the PHP FPM service script and start it -find /etc/init.d -type f -name "php*-fpm" -exec {} start \; && \ -chown -R nginx:nginx /data/Specific && \ -nginx -g "daemon off;" +find /etc/init.d -type f -name "php*-fpm" -exec {} start \; && + chown -R nginx:nginx /data/Specific && + nginx -g "daemon off;" diff --git a/battybirdnet-pi/rootfs/01-battybirdnet.sh b/battybirdnet-pi/rootfs/01-battybirdnet.sh index 98ab8e173..2d46dbba8 100755 --- a/battybirdnet-pi/rootfs/01-battybirdnet.sh +++ b/battybirdnet-pi/rootfs/01-battybirdnet.sh @@ -4,8 +4,8 @@ set -e # Remove not working elements if bashio::config.true "NO_NOISE_MODEL"; then - bashio::log.info "Activating the no_noise models as NO_NOISE_MODEL is true" - sed -i "s|server.py --area|server.py --no_noise on --area|g" "$HOME"/BirdNET-Pi/scripts/batnet_analysis.sh + bashio::log.info "Activating the no_noise models as NO_NOISE_MODEL is true" + sed -i "s|server.py --area|server.py --no_noise on --area|g" "$HOME"/BirdNET-Pi/scripts/batnet_analysis.sh fi # Add batnet service to monitoring service @@ -14,15 +14,15 @@ sed -i "s|spectrogram_viewer |spectrogram_viewer batnet_server |g" /custom-servi # Install gotty for amd64 if [ "$(uname -m)" == "x86_64" ]; then - bashio::log.info "Install gotty for amd64" - curl -L https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_amd64.tar.gz | tar xz -C /tmp - mv /tmp/gotty /usr/local/bin/gotty - chmod +x /usr/local/bin/gotty - sed -i "s| -P log| log|g" "$HOME"/BirdNET-Pi/templates/birdnet_log.service + bashio::log.info "Install gotty for amd64" + curl -L https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_amd64.tar.gz | tar xz -C /tmp + mv /tmp/gotty /usr/local/bin/gotty + chmod +x /usr/local/bin/gotty + sed -i "s| -P log| log|g" "$HOME"/BirdNET-Pi/templates/birdnet_log.service fi # Make sure bats model is on -echo 'sed -i "/BATS_ANALYSIS=/c\BATS_ANALYSIS=1" /config/birdnet.conf' >> /etc/cont-init.d/81-modifications.sh +echo 'sed -i "/BATS_ANALYSIS=/c\BATS_ANALYSIS=1" /config/birdnet.conf' >>/etc/cont-init.d/81-modifications.sh # Disable monitoring service sed -i "1a sleep infinity" /custom-services.d/30-monitoring.sh diff --git a/bazarr/rootfs/etc/cont-init.d/20-folders.sh b/bazarr/rootfs/etc/cont-init.d/20-folders.sh index 81b2023f4..1eef2edb0 100755 --- a/bazarr/rootfs/etc/cont-init.d/20-folders.sh +++ b/bazarr/rootfs/etc/cont-init.d/20-folders.sh @@ -1,33 +1,33 @@ #!/bin/bash if [ ! -d /share/storage/movies ]; then - echo "Creating /share/storage/movies" - mkdir -p /share/storage/movies - chown -R "$PUID:$PGID" /share/storage/movies + echo "Creating /share/storage/movies" + mkdir -p /share/storage/movies + chown -R "$PUID:$PGID" /share/storage/movies fi if [ ! -d /share/storage/tv ]; then - echo "Creating /share/storage/tv" - mkdir -p /share/storage/tv - chown -R "$PUID:$PGID" /share/storage/tv + echo "Creating /share/storage/tv" + mkdir -p /share/storage/tv + chown -R "$PUID:$PGID" /share/storage/tv fi if [ ! -d /share/downloads ]; then - echo "Creating /share/downloads" - mkdir -p /share/downloads - chown -R "$PUID:$PGID" /share/downloads + echo "Creating /share/downloads" + mkdir -p /share/downloads + chown -R "$PUID:$PGID" /share/downloads fi if [ -d /config/bazarr ] && [ ! -d /config/addons_config/bazarr ]; then - echo "Moving to new location /config/addons_config/bazarr" - mkdir -p /config/addons_config/bazarr - chown -R "$PUID:$PGID" /config/addons_config/bazarr - mv /config/bazarr/* /config/addons_config/bazarr/ - rm -r /config/bazarr + echo "Moving to new location /config/addons_config/bazarr" + mkdir -p /config/addons_config/bazarr + chown -R "$PUID:$PGID" /config/addons_config/bazarr + mv /config/bazarr/* /config/addons_config/bazarr/ + rm -r /config/bazarr fi if [ ! -d /config/addons_config/bazarr ]; then - echo "Creating /config/addons_config/bazarr" - mkdir -p /config/addons_config/bazarr - chown -R "$PUID:$PGID" /config/addons_config/bazarr + echo "Creating /config/addons_config/bazarr" + mkdir -p /config/addons_config/bazarr + chown -R "$PUID:$PGID" /config/addons_config/bazarr fi diff --git a/binance-trading-bot/rootfs/etc/cont-init.d/20-folders.sh b/binance-trading-bot/rootfs/etc/cont-init.d/20-folders.sh index dcf5ff0f9..6dad8500a 100755 --- a/binance-trading-bot/rootfs/etc/cont-init.d/20-folders.sh +++ b/binance-trading-bot/rootfs/etc/cont-init.d/20-folders.sh @@ -3,15 +3,15 @@ set -e if [ -d /config/binance-trading-bot ]; then - echo "Moving to new location /config/addons_config/binance-trading-bot" - mkdir -p /config/addons_config/binance-trading-bot - chmod 777 /config/addons_config/binance-trading-bot - mv /config/binance-trading-bot/* /config/addons_config/binance-trading-bot/ - rm -r /config/binance-trading-bot + echo "Moving to new location /config/addons_config/binance-trading-bot" + mkdir -p /config/addons_config/binance-trading-bot + chmod 777 /config/addons_config/binance-trading-bot + mv /config/binance-trading-bot/* /config/addons_config/binance-trading-bot/ + rm -r /config/binance-trading-bot fi if [ ! -d /config/addons_config/binance-trading-bot ]; then - echo "Creating /config/addons_config/binance-trading-bot" - mkdir -p /config/addons_config/binance-trading-bot - chmod 777 /config/addons_config/binance-trading-bot + echo "Creating /config/addons_config/binance-trading-bot" + mkdir -p /config/addons_config/binance-trading-bot + chmod 777 /config/addons_config/binance-trading-bot fi diff --git a/binance-trading-bot/rootfs/etc/cont-init.d/32-ingress.sh b/binance-trading-bot/rootfs/etc/cont-init.d/32-ingress.sh index 9fd0e7e11..5f23e3f6a 100755 --- a/binance-trading-bot/rootfs/etc/cont-init.d/32-ingress.sh +++ b/binance-trading-bot/rootfs/etc/cont-init.d/32-ingress.sh @@ -14,4 +14,3 @@ ingress_entry=$(bashio::addon.ingress_entry) sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf sed -i "s|%%ingress_entry%%|${ingress_entry}|g" /etc/nginx/servers/ingress.conf - diff --git a/binance-trading-bot/rootfs/etc/cont-init.d/99-run.sh b/binance-trading-bot/rootfs/etc/cont-init.d/99-run.sh index 9d5e62376..6b00824be 100755 --- a/binance-trading-bot/rootfs/etc/cont-init.d/99-run.sh +++ b/binance-trading-bot/rootfs/etc/cont-init.d/99-run.sh @@ -9,24 +9,28 @@ set -e ################## # Starting redis # ################## -exec redis-server & bashio::log.info "Starting redis" +exec redis-server & +bashio::log.info "Starting redis" #################### # Starting mongodb # #################### mkdir -p /data/db -exec mongod --bind_ip 127.0.0.1 & bashio::log.info "Starting mongod" +exec mongod --bind_ip 127.0.0.1 & +bashio::log.info "Starting mongod" ################ # Starting app # ################ cd /srv || true -npm start docker-entrypoint.sh & bashio::log.info "Starting binance bot" +npm start docker-entrypoint.sh & +bashio::log.info "Starting binance bot" ######################### # Starting Trading View # ######################### -python main.py & bashio::log.info "Starting trading view" +python main.py & +bashio::log.info "Starting trading view" ################## # Starting nginx # diff --git a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh index 51e1b10d1..ea6679c17 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh @@ -7,16 +7,16 @@ DEFAULT_BIRDSONGS_FOLDER="/data/clips/" CONFIG_LOCATION="/config/config.yaml" if [ ! -f "$CONFIG_LOCATION" ]; then - bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize" - curl -L -s -S https://raw.githubusercontent.com/tphakala/birdnet-go/refs/heads/main/internal/conf/config.yaml -o "$CONFIG_LOCATION" + bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize" + curl -L -s -S https://raw.githubusercontent.com/tphakala/birdnet-go/refs/heads/main/internal/conf/config.yaml -o "$CONFIG_LOCATION" fi ################# # Migrate Database ################# if [ -f /data/birdnet.db ]; then - bashio::log.warning "Moving birdnet.db to /config/birdnet.db" - mv /data/birdnet.db /config + bashio::log.warning "Moving birdnet.db to /config/birdnet.db" + mv /data/birdnet.db /config fi ###################### @@ -29,67 +29,67 @@ CURRENT_BIRDSONGS_FOLDER="${CURRENT_BIRDSONGS_FOLDER:-$DEFAULT_BIRDSONGS_FOLDER} # Adjust default path if it matches the default string if [[ "$CURRENT_BIRDSONGS_FOLDER" == "clips/" ]]; then - CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER" + CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER" fi # Set the new birdsongs folder BIRDSONGS_FOLDER="$(bashio::config "BIRDSONGS_FOLDER")" BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER:-clips/}" -BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER%/}" # Remove trailing slash if present +BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER%/}" # Remove trailing slash if present if [[ ! "$BIRDSONGS_FOLDER" == /* ]]; then - if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then - mkdir -p "/config/$BIRDSONGS_FOLDER" - fi - if [ -d "/data/$BIRDSONGS_FOLDER" ]; then - if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2>/dev/null)" ]; then - cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/ - fi - rm -r "/data/$BIRDSONGS_FOLDER" - fi - ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER" + if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then + mkdir -p "/config/$BIRDSONGS_FOLDER" + fi + if [ -d "/data/$BIRDSONGS_FOLDER" ]; then + if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2>/dev/null)" ]; then + cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/ + fi + rm -r "/data/$BIRDSONGS_FOLDER" + fi + ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER" fi bashio::log.info "... audio clips saved to $BIRDSONGS_FOLDER according to addon options" # Migrate data if the folder has changed if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then - bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER" - # Update config files with the new birdsongs folder path - yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION" - # Move files only if sqlite paths changed - if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then - bashio::log.warning "Migrating files from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER" - cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/ - mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated" - fi - # Adapt the database - if [ -f /config/birdnet.db ]; then - # Prepare - backup="$(date +%Y%m%d_%H%M%S)" - bashio::log.warning "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup named birdnet.db_$backup will be created before" + bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER" + # Update config files with the new birdsongs folder path + yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION" + # Move files only if sqlite paths changed + if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then + bashio::log.warning "Migrating files from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER" + cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/ + mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated" + fi + # Adapt the database + if [ -f /config/birdnet.db ]; then + # Prepare + backup="$(date +%Y%m%d_%H%M%S)" + bashio::log.warning "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup named birdnet.db_$backup will be created before" - # Create backup - if ! cp /config/birdnet.db "birdnet.db_$backup"; then - bashio::log.error "Failed to create a backup of the database. Aborting path modification." - exit 1 - fi + # Create backup + if ! cp /config/birdnet.db "birdnet.db_$backup"; then + bashio::log.error "Failed to create a backup of the database. Aborting path modification." + exit 1 + fi - # Execute the query using sqlite3 - SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';" - - if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then - bashio::log.warning "An error occurred while updating the paths. The database backup will be restored." - BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename - if [ -f "$BACKUP_FILE" ]; then - mv "$BACKUP_FILE" /config/birdnet.db - bashio::log.info "The database backup has been restored." - else - bashio::log.error "Backup file not found! Manual intervention required." - fi - else - echo "Paths have been successfully updated." - fi - fi + # Execute the query using sqlite3 + SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';" + + if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then + bashio::log.warning "An error occurred while updating the paths. The database backup will be restored." + BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename + if [ -f "$BACKUP_FILE" ]; then + mv "$BACKUP_FILE" /config/birdnet.db + bashio::log.info "The database backup has been restored." + else + bashio::log.error "Backup file not found! Manual intervention required." + fi + else + echo "Paths have been successfully updated." + fi + fi fi #################### diff --git a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh index dfd581e9a..636c810b9 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh @@ -5,12 +5,12 @@ set -e # Gives mariadb information if bashio::services.available 'mysql'; then - bashio::log.green "---" - bashio::log.yellow "MariaDB addon is active on your system! If you want to use it instead of sqlite, here are the informations to encode :" - bashio::log.blue "Database user : $(bashio::services "mysql" "username")" - bashio::log.blue "Database password : $(bashio::services "mysql" "password")" - bashio::log.blue "Database name : birdnet" - bashio::log.blue "Host-name : $(bashio::services "mysql" "host")" - bashio::log.blue "Port : $(bashio::services "mysql" "port")" - bashio::log.green "---" + bashio::log.green "---" + bashio::log.yellow "MariaDB addon is active on your system! If you want to use it instead of sqlite, here are the informations to encode :" + bashio::log.blue "Database user : $(bashio::services "mysql" "username")" + bashio::log.blue "Database password : $(bashio::services "mysql" "password")" + bashio::log.blue "Database name : birdnet" + bashio::log.blue "Host-name : $(bashio::services "mysql" "host")" + bashio::log.blue "Port : $(bashio::services "mysql" "port")" + bashio::log.green "---" fi diff --git a/birdnet-go/rootfs/etc/cont-init.d/33-mqtt.sh b/birdnet-go/rootfs/etc/cont-init.d/33-mqtt.sh index 2dc29425c..0e42d8af7 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/33-mqtt.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/33-mqtt.sh @@ -5,11 +5,10 @@ set -e # Gives mqtt information if bashio::services.available 'mqtt'; then - bashio::log.green "---" - bashio::log.yellow "MQTT addon is active on your system! Add the MQTT details below to the Birdnet-go config.yaml :" - bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")" - bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")" - bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")" - bashio::log.green "---" + bashio::log.green "---" + bashio::log.yellow "MQTT addon is active on your system! Add the MQTT details below to the Birdnet-go config.yaml :" + bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")" + bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")" + bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")" + bashio::log.green "---" fi - diff --git a/birdnet-go/rootfs/etc/cont-init.d/99-run.sh b/birdnet-go/rootfs/etc/cont-init.d/99-run.sh index b4fc1a88d..843d28894 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/99-run.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/99-run.sh @@ -11,11 +11,11 @@ echo " " # Adjust microphone volume if needed if command -v amixer >/dev/null 2>/dev/null; then - current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2>/dev/null || echo "100")" || true - if [[ "$current_volume" -eq 0 ]]; then - amixer sset Capture 70% - bashio::log.warning "Microphone was off, volume set to 70%." - fi || true + current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2>/dev/null || echo "100")" || true + if [[ "$current_volume" -eq 0 ]]; then + amixer sset Capture 70% + bashio::log.warning "Microphone was off, volume set to 70%." + fi || true fi ######################## @@ -24,10 +24,10 @@ fi bashio::log.info "Starting app..." # shellcheck disable=SC2086 -/usr/bin/entrypoint.sh birdnet-go realtime & true +/usr/bin/entrypoint.sh birdnet-go realtime & +true # Wait for app to become available to start nginx bashio::net.wait_for 8080 localhost 900 bashio::log.info "Starting NGinx..." exec nginx - diff --git a/birdnet-pi/rootfs/custom-services.d/00-php_pfm.sh b/birdnet-pi/rootfs/custom-services.d/00-php_pfm.sh index db5117b0a..feaded475 100755 --- a/birdnet-pi/rootfs/custom-services.d/00-php_pfm.sh +++ b/birdnet-pi/rootfs/custom-services.d/00-php_pfm.sh @@ -6,7 +6,7 @@ chown pi:pi /config # Waiting for dbus until [[ -e /var/run/dbus/system_bus_socket ]]; do - sleep 1s + sleep 1s done TZ_VALUE="$(timedatectl show -p Timezone --value)" diff --git a/birdnet-pi/rootfs/custom-services.d/01-avahi.sh b/birdnet-pi/rootfs/custom-services.d/01-avahi.sh index 2f7826808..9d007843e 100755 --- a/birdnet-pi/rootfs/custom-services.d/01-avahi.sh +++ b/birdnet-pi/rootfs/custom-services.d/01-avahi.sh @@ -2,7 +2,7 @@ # shellcheck shell=bash # Waiting for dbus until [[ -e /var/run/dbus/system_bus_socket ]]; do - sleep 1s + sleep 1s done TZ_VALUE="$(timedatectl show -p Timezone --value)" @@ -10,4 +10,4 @@ export TZ="$TZ_VALUE" echo "Starting service: avahi daemon" exec \ - avahi-daemon --no-chroot + avahi-daemon --no-chroot diff --git a/birdnet-pi/rootfs/custom-services.d/02-caddy.sh b/birdnet-pi/rootfs/custom-services.d/02-caddy.sh index 9cba7f2e7..837865614 100755 --- a/birdnet-pi/rootfs/custom-services.d/02-caddy.sh +++ b/birdnet-pi/rootfs/custom-services.d/02-caddy.sh @@ -4,8 +4,8 @@ # Dependencies sockfile="empty" until [[ -e /var/run/dbus/system_bus_socket ]] && [[ -e "$sockfile" ]]; do - sleep 1s - sockfile="$(find /run/php -name "*.sock")" + sleep 1s + sockfile="$(find /run/php -name "*.sock")" done # Correct fpm.sock diff --git a/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh b/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh index 73f2df2ac..7d363a678 100755 --- a/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh +++ b/birdnet-pi/rootfs/custom-services.d/30-monitoring.sh @@ -7,10 +7,10 @@ HOME="/home/pi" ######################################## # Logging Functions (color-coded for terminal clarity) ######################################## -log_green() { echo -e "\033[32m$1\033[0m"; } -log_red() { echo -e "\033[31m$1\033[0m"; } -log_yellow() { echo -e "\033[33m$1\033[0m"; } -log_blue() { echo -e "\033[34m$1\033[0m"; } +log_green() { echo -e "\033[32m$1\033[0m"; } +log_red() { echo -e "\033[31m$1\033[0m"; } +log_yellow() { echo -e "\033[33m$1\033[0m"; } +log_blue() { echo -e "\033[34m$1\033[0m"; } ######################################## # Read configuration @@ -35,7 +35,10 @@ touch "$ANALYZING_NOW_FILE" BIRDSONGS_DIR="$(readlink -f "$HOME/BirdSongs/Extracted/By_Date")" # Ensure directories and set permissions -mkdir -p "$INGEST_DIR" || { log_red "Failed to create directory: $INGEST_DIR"; exit 1; } +mkdir -p "$INGEST_DIR" || { + log_red "Failed to create directory: $INGEST_DIR" + exit 1 +} chown -R pi:pi "$INGEST_DIR" || log_yellow "Could not change ownership for $INGEST_DIR" chmod -R 755 "$INGEST_DIR" || log_yellow "Could not set permissions for $INGEST_DIR" @@ -45,10 +48,10 @@ SERVICES=(birdnet_analysis chart_viewer spectrogram_viewer birdnet_recording bir ######################################## # Notification settings ######################################## -NOTIFICATION_INTERVAL=1800 # 30 minutes in seconds -NOTIFICATION_INTERVAL_IN_MINUTES=$(( NOTIFICATION_INTERVAL / 60 )) +NOTIFICATION_INTERVAL=1800 # 30 minutes in seconds +NOTIFICATION_INTERVAL_IN_MINUTES=$((NOTIFICATION_INTERVAL / 60)) last_notification_time=0 -issue_reported=0 # 1 = an issue was reported, 0 = system is normal +issue_reported=0 # 1 = an issue was reported, 0 = system is normal declare -A SERVICE_INACTIVE_COUNT=() # Disk usage threshold (percentage) @@ -58,71 +61,71 @@ DISK_USAGE_THRESHOLD=95 same_file_counter=0 SAME_FILE_THRESHOLD=2 if [[ -f "$ANALYZING_NOW_FILE" ]]; then - analyzing_now=$(<"$ANALYZING_NOW_FILE") + analyzing_now=$(<"$ANALYZING_NOW_FILE") else - analyzing_now="" + analyzing_now="" fi ######################################## # Notification Functions ######################################## apprisealert() { - local issue_message="$1" - local current_time - current_time=$(date +%s) + local issue_message="$1" + local current_time + current_time=$(date +%s) - # Calculate time_diff in minutes since last notification - local time_diff=$(( (current_time - last_notification_time) / 60 )) + # Calculate time_diff in minutes since last notification + local time_diff=$(((current_time - last_notification_time) / 60)) - # Throttle notifications - if (( time_diff < NOTIFICATION_INTERVAL_IN_MINUTES )); then - log_yellow "Notification suppressed (last sent ${time_diff} minutes ago)." - return - fi + # Throttle notifications + if ((time_diff < NOTIFICATION_INTERVAL_IN_MINUTES)); then + log_yellow "Notification suppressed (last sent ${time_diff} minutes ago)." + return + fi - local stopped_service="
Stopped services: " - for service in "${SERVICES[@]}"; do - if [[ "$(systemctl is-active "$service")" != "active" ]]; then - stopped_service+="$service; " - fi - done + local stopped_service="
Stopped services: " + for service in "${SERVICES[@]}"; do + if [[ "$(systemctl is-active "$service")" != "active" ]]; then + stopped_service+="$service; " + fi + done - local notification="Issue: $issue_message" - notification+="$stopped_service" - notification+="
System: ${SITE_NAME:-$(hostname)}" - notification+="
Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')" - notification+="
----Last log lines----" - notification+="
$(timeout 15 cat /proc/1/fd/1 | head -n 5)" - notification+="
----------------------" - [[ -n "$BIRDNETPI_URL" ]] && notification+="
Access your BirdNET-Pi" + local notification="Issue: $issue_message" + notification+="$stopped_service" + notification+="
System: ${SITE_NAME:-$(hostname)}" + notification+="
Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')" + notification+="
----Last log lines----" + notification+="
$(timeout 15 cat /proc/1/fd/1 | head -n 5)" + notification+="
----------------------" + [[ -n "$BIRDNETPI_URL" ]] && notification+="
Access your BirdNET-Pi" - local TITLE="BirdNET-Analyzer Alert" - if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then - "$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \ - --input-format=html --config="$HOME/BirdNET-Pi/apprise.txt" - last_notification_time=$current_time - issue_reported=1 - else - log_red "Apprise not configured or missing!" - fi + local TITLE="BirdNET-Analyzer Alert" + if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then + "$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \ + --input-format=html --config="$HOME/BirdNET-Pi/apprise.txt" + last_notification_time=$current_time + issue_reported=1 + else + log_red "Apprise not configured or missing!" + fi } apprisealert_recovery() { - # Only send a recovery message if we had previously reported an issue - if (( issue_reported == 1 )); then - log_green "$(date) INFO: System is back to normal. Sending recovery notification." + # Only send a recovery message if we had previously reported an issue + if ((issue_reported == 1)); then + log_green "$(date) INFO: System is back to normal. Sending recovery notification." - local TITLE="BirdNET-Pi System Recovered" - local notification="All monitored services are back to normal.
" - notification+="System: ${SITE_NAME:-$(hostname)}
" - notification+="Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')" + local TITLE="BirdNET-Pi System Recovered" + local notification="All monitored services are back to normal.
" + notification+="System: ${SITE_NAME:-$(hostname)}
" + notification+="Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')" - if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then - "$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \ - --input-format=html --config="$HOME/BirdNET-Pi/apprise.txt" - fi - issue_reported=0 - fi + if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then + "$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \ + --input-format=html --config="$HOME/BirdNET-Pi/apprise.txt" + fi + issue_reported=0 + fi } ######################################## @@ -130,115 +133,115 @@ apprisealert_recovery() { ######################################## check_disk_space() { - local current_usage - current_usage=$(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $5}' | sed 's/%//') + local current_usage + current_usage=$(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $5}' | sed 's/%//') - if (( current_usage >= DISK_USAGE_THRESHOLD )); then - log_red "$(date) INFO: Disk usage is at ${current_usage}% (CRITICAL!)" - apprisealert "Disk usage critical: ${current_usage}%" - return 1 - else - log_green "$(date) INFO: Disk usage is within acceptable limits (${current_usage}%)." - return 0 - fi + if ((current_usage >= DISK_USAGE_THRESHOLD)); then + log_red "$(date) INFO: Disk usage is at ${current_usage}% (CRITICAL!)" + apprisealert "Disk usage critical: ${current_usage}%" + return 1 + else + log_green "$(date) INFO: Disk usage is within acceptable limits (${current_usage}%)." + return 0 + fi } check_analyzing_now() { - local current_file - current_file=$(cat "$ANALYZING_NOW_FILE" 2>/dev/null) - if [[ "$current_file" == "$analyzing_now" ]]; then - (( same_file_counter++ )) - else - same_file_counter=0 - analyzing_now="$current_file" - fi + local current_file + current_file=$(cat "$ANALYZING_NOW_FILE" 2>/dev/null) + if [[ "$current_file" == "$analyzing_now" ]]; then + ((same_file_counter++)) + else + same_file_counter=0 + analyzing_now="$current_file" + fi - if (( same_file_counter >= SAME_FILE_THRESHOLD )); then - log_red "$(date) INFO: 'analyzing_now' file unchanged for $SAME_FILE_THRESHOLD iterations." - apprisealert "No change in analyzing_now for ${SAME_FILE_THRESHOLD} iterations" - "$HOME/BirdNET-Pi/scripts/restart_services.sh" - same_file_counter=0 - return 1 - else - # Only log if it changed this iteration - if (( same_file_counter == 0 )); then - log_green "$(date) INFO: 'analyzing_now' file has been updated." - fi - return 0 - fi + if ((same_file_counter >= SAME_FILE_THRESHOLD)); then + log_red "$(date) INFO: 'analyzing_now' file unchanged for $SAME_FILE_THRESHOLD iterations." + apprisealert "No change in analyzing_now for ${SAME_FILE_THRESHOLD} iterations" + "$HOME/BirdNET-Pi/scripts/restart_services.sh" + same_file_counter=0 + return 1 + else + # Only log if it changed this iteration + if ((same_file_counter == 0)); then + log_green "$(date) INFO: 'analyzing_now' file has been updated." + fi + return 0 + fi } check_queue() { - local wav_count - wav_count=$(find -L "$INGEST_DIR" -maxdepth 1 -name '*.wav' | wc -l) + local wav_count + wav_count=$(find -L "$INGEST_DIR" -maxdepth 1 -name '*.wav' | wc -l) - log_green "$(date) INFO: Queue is at a manageable level (${wav_count} wav files)." + log_green "$(date) INFO: Queue is at a manageable level (${wav_count} wav files)." - if (( wav_count > 50 )); then - log_red "$(date) INFO: Queue >50. Stopping recorder + restarting analyzer." - apprisealert "Queue exceeded 50: stopping recorder, restarting analyzer." - sudo systemctl stop birdnet_recording - sudo systemctl restart birdnet_analysis - return 1 - elif (( wav_count > 30 )); then - log_red "$(date) INFO: Queue >30. Restarting analyzer." - apprisealert "Queue exceeded 30: restarting analyzer." - sudo systemctl restart birdnet_analysis - return 1 - fi - return 0 + if ((wav_count > 50)); then + log_red "$(date) INFO: Queue >50. Stopping recorder + restarting analyzer." + apprisealert "Queue exceeded 50: stopping recorder, restarting analyzer." + sudo systemctl stop birdnet_recording + sudo systemctl restart birdnet_analysis + return 1 + elif ((wav_count > 30)); then + log_red "$(date) INFO: Queue >30. Restarting analyzer." + apprisealert "Queue exceeded 30: restarting analyzer." + sudo systemctl restart birdnet_analysis + return 1 + fi + return 0 } check_services() { - local any_inactive=0 + local any_inactive=0 - for service in "${SERVICES[@]}"; do - if [[ "$(systemctl is-active "$service")" != "active" ]]; then - SERVICE_INACTIVE_COUNT["$service"]=$(( SERVICE_INACTIVE_COUNT["$service"] + 1 )) + for service in "${SERVICES[@]}"; do + if [[ "$(systemctl is-active "$service")" != "active" ]]; then + SERVICE_INACTIVE_COUNT["$service"]=$((SERVICE_INACTIVE_COUNT["$service"] + 1)) - if (( SERVICE_INACTIVE_COUNT["$service"] == 1 )); then - # First time inactive => Try to start - log_yellow "$(date) INFO: Service '$service' is inactive. Attempting to start..." - systemctl start "$service" - any_inactive=1 - elif (( SERVICE_INACTIVE_COUNT["$service"] == 2 )); then - # Second consecutive time => Send an alert - log_red "$(date) INFO: Service '$service' is still inactive after restart attempt." - apprisealert "Service '$service' remains inactive after restart attempt." - any_inactive=1 - else - # Beyond second check => keep logging or do advanced actions - log_red "$(date) INFO: Service '$service' inactive for ${SERVICE_INACTIVE_COUNT["$service"]} checks in a row." - any_inactive=1 - fi - else - # Service is active => reset counter - if (( SERVICE_INACTIVE_COUNT["$service"] > 0 )); then - log_green "$(date) INFO: Service '$service' is back to active. Resetting counter." - fi - SERVICE_INACTIVE_COUNT["$service"]=0 - fi - done + if ((SERVICE_INACTIVE_COUNT["$service"] == 1)); then + # First time inactive => Try to start + log_yellow "$(date) INFO: Service '$service' is inactive. Attempting to start..." + systemctl start "$service" + any_inactive=1 + elif ((SERVICE_INACTIVE_COUNT["$service"] == 2)); then + # Second consecutive time => Send an alert + log_red "$(date) INFO: Service '$service' is still inactive after restart attempt." + apprisealert "Service '$service' remains inactive after restart attempt." + any_inactive=1 + else + # Beyond second check => keep logging or do advanced actions + log_red "$(date) INFO: Service '$service' inactive for ${SERVICE_INACTIVE_COUNT["$service"]} checks in a row." + any_inactive=1 + fi + else + # Service is active => reset counter + if ((SERVICE_INACTIVE_COUNT["$service"] > 0)); then + log_green "$(date) INFO: Service '$service' is back to active. Resetting counter." + fi + SERVICE_INACTIVE_COUNT["$service"]=0 + fi + done - if (( any_inactive == 0 )); then - log_green "$(date) INFO: All services are active" - return 0 - else - log_red "$(date) INFO: One or more services are inactive" - return 1 - fi + if ((any_inactive == 0)); then + log_green "$(date) INFO: All services are active" + return 0 + else + log_red "$(date) INFO: One or more services are inactive" + return 1 + fi } check_for_empty_stream() { - local log_tail - log_tail=$(timeout 15 cat /proc/1/fd/1 | tail -n 5) + local log_tail + log_tail=$(timeout 15 cat /proc/1/fd/1 | tail -n 5) - if echo "$log_tail" | grep -q "Haliastur indus"; then - log_red "$(date) INFO: Potential empty stream detected (frequent 'Haliastur indus')." - apprisealert "Potential empty stream detected — frequent 'Haliastur indus' in log" - return 1 - fi - return 0 + if echo "$log_tail" | grep -q "Haliastur indus"; then + log_red "$(date) INFO: Potential empty stream detected (frequent 'Haliastur indus')." + apprisealert "Potential empty stream detected — frequent 'Haliastur indus' in log" + return 1 + fi + return 0 } ######################################## @@ -248,32 +251,32 @@ TZ_VALUE="$(timedatectl show -p Timezone --value)" export TZ="$TZ_VALUE" while true; do - sleep 61 - log_blue "----------------------------------------" - log_blue "$(date) INFO: Starting monitoring check" - any_issue=0 + sleep 61 + log_blue "----------------------------------------" + log_blue "$(date) INFO: Starting monitoring check" + any_issue=0 - # 1) Disk usage - check_disk_space || any_issue=1 + # 1) Disk usage + check_disk_space || any_issue=1 - # 2) 'analyzing_now' file - check_analyzing_now || any_issue=1 + # 2) 'analyzing_now' file + check_analyzing_now || any_issue=1 - # 3) Queue check - check_queue || any_issue=1 + # 3) Queue check + check_queue || any_issue=1 - # 4) Services check - check_services || any_issue=1 + # 4) Services check + check_services || any_issue=1 - # 5) Check for potential empty stream - check_for_empty_stream || any_issue=1 + # 5) Check for potential empty stream + check_for_empty_stream || any_issue=1 - # Final summary - if (( any_issue == 0 )); then - log_green "$(date) INFO: All systems are functioning normally" - apprisealert_recovery - else - log_red "$(date) INFO: Issues detected. System status is not fully operational." - fi - log_blue "----------------------------------------" + # Final summary + if ((any_issue == 0)); then + log_green "$(date) INFO: All systems are functioning normally" + apprisealert_recovery + else + log_red "$(date) INFO: Issues detected. System status is not fully operational." + fi + log_blue "----------------------------------------" done diff --git a/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh b/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh index b5f3873ca..82b9e38e4 100755 --- a/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh +++ b/birdnet-pi/rootfs/etc/cont-finish.d/savestreamdata.sh @@ -6,46 +6,46 @@ MAX_SIZE=$((50 * 1024 * 1024)) # Function to check if a file is a valid WAV is_valid_wav() { - local file="$1" - # Check if the file contains a valid WAV header - file "$file" | grep -qE 'WAVE audio' + local file="$1" + # Check if the file contains a valid WAV header + file "$file" | grep -qE 'WAVE audio' } if [ -d "$HOME"/BirdSongs/StreamData ]; then - bashio::log.fatal "Container stopping, saving temporary files." + bashio::log.fatal "Container stopping, saving temporary files." - # Stop the services in parallel - if systemctl is-active --quiet birdnet_analysis; then - bashio::log.info "Stopping birdnet_analysis service." - systemctl stop birdnet_analysis & - fi + # Stop the services in parallel + if systemctl is-active --quiet birdnet_analysis; then + bashio::log.info "Stopping birdnet_analysis service." + systemctl stop birdnet_analysis & + fi - if systemctl is-active --quiet birdnet_recording; then - bashio::log.info "Stopping birdnet_recording service." - systemctl stop birdnet_recording & - fi + if systemctl is-active --quiet birdnet_recording; then + bashio::log.info "Stopping birdnet_recording service." + systemctl stop birdnet_recording & + fi - # Wait for both services to stop - wait + # Wait for both services to stop + wait - # Create the destination directory - mkdir -p /config/TemporaryFiles + # Create the destination directory + mkdir -p /config/TemporaryFiles - # Move only valid WAV files under 50MB - shopt -s nullglob # Prevent errors if no files match - for file in "$HOME"/BirdSongs/StreamData/*.wav; do - if [ -f "$file" ] && [ "$(stat --format="%s" "$file")" -lt "$MAX_SIZE" ] && is_valid_wav "$file"; then - if mv -v "$file" /config/TemporaryFiles/; then - bashio::log.info "Moved valid WAV file: $(basename "$file")" - else - bashio::log.error "Failed to move: $(basename "$file")" - fi - else - bashio::log.warning "Skipping invalid or large file: $(basename "$file")" - fi - done + # Move only valid WAV files under 50MB + shopt -s nullglob # Prevent errors if no files match + for file in "$HOME"/BirdSongs/StreamData/*.wav; do + if [ -f "$file" ] && [ "$(stat --format="%s" "$file")" -lt "$MAX_SIZE" ] && is_valid_wav "$file"; then + if mv -v "$file" /config/TemporaryFiles/; then + bashio::log.info "Moved valid WAV file: $(basename "$file")" + else + bashio::log.error "Failed to move: $(basename "$file")" + fi + else + bashio::log.warning "Skipping invalid or large file: $(basename "$file")" + fi + done - bashio::log.info "... files safe, allowing container to stop." + bashio::log.info "... files safe, allowing container to stop." else - bashio::log.info "No StreamData directory to process." + bashio::log.info "No StreamData directory to process." fi diff --git a/birdnet-pi/rootfs/etc/cont-init.d/01-structure.sh b/birdnet-pi/rootfs/etc/cont-init.d/01-structure.sh index fab4757b9..4a77263e6 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/01-structure.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/01-structure.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ############### @@ -23,24 +23,24 @@ bashio::log.info "Ensuring the file structure is correct:" echo "... creating default files" DEFAULT_FILES=("apprise.txt" "exclude_species_list.txt" "IdentifiedSoFar.txt" "disk_check_exclude.txt" "confirmed_species_list.txt" "blacklisted_images.txt" "whitelist_species_list.txt") for file in "${DEFAULT_FILES[@]}"; do - if [ ! -f "/config/$file" ]; then - echo "" > "/config/$file" - fi + if [ ! -f "/config/$file" ]; then + echo "" >"/config/$file" + fi done touch /config/include_species_list.txt # Ensure this is always created # Set BirdSongs folder location from configuration if specified BIRDSONGS_FOLDER="/config/BirdSongs" if bashio::config.has_value "BIRDSONGS_FOLDER"; then - BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")" - echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION" - mkdir -p "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be created" - chown -R pi:pi "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be given permissions for 1000:1000" - if [ -d "$BIRDSONGS_FOLDER_OPTION" ] && [ "$(stat -c '%u:%g' "$BIRDSONGS_FOLDER_OPTION")" == "1000:1000" ]; then - BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION" - else - bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs" - fi + BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")" + echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION" + mkdir -p "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be created" + chown -R pi:pi "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be given permissions for 1000:1000" + if [ -d "$BIRDSONGS_FOLDER_OPTION" ] && [ "$(stat -c '%u:%g' "$BIRDSONGS_FOLDER_OPTION")" == "1000:1000" ]; then + BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION" + else + bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs" + fi fi # Create default folders @@ -49,12 +49,12 @@ mkdir -p "$BIRDSONGS_FOLDER/By_Date" "$BIRDSONGS_FOLDER/Charts" # Use tmpfs if installed if df -T /tmp | grep -q "tmpfs"; then - echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear" - mkdir -p /tmp/StreamData /tmp/Processed - [ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData" - [ -d "$HOME/BirdSongs/Processed" ] && rm -r "$HOME/BirdSongs/Processed" - sudo -u pi ln -fs /tmp/StreamData "$HOME/BirdSongs/StreamData" - sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed" + echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear" + mkdir -p /tmp/StreamData /tmp/Processed + [ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData" + [ -d "$HOME/BirdSongs/Processed" ] && rm -r "$HOME/BirdSongs/Processed" + sudo -u pi ln -fs /tmp/StreamData "$HOME/BirdSongs/StreamData" + sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed" fi # Set permissions for created files and folders @@ -67,19 +67,19 @@ cp "$HOME/BirdNET-Pi/birdnet.conf" "$HOME/BirdNET-Pi/birdnet.bak" # Create default birdnet.conf if not existing if [ ! -f /config/birdnet.conf ]; then - cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/ + cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/ fi # Create default birds.db if [ ! -f /config/birds.db ]; then - echo "... creating initial db" - "$HOME/BirdNET-Pi/scripts/createdb.sh" - cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/ + echo "... creating initial db" + "$HOME/BirdNET-Pi/scripts/createdb.sh" + cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/ elif [ "$(stat -c%s /config/birds.db)" -lt 10240 ]; then - echo "... your db is corrupted, creating new one" - rm /config/birds.db - "$HOME/BirdNET-Pi/scripts/createdb.sh" - cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/ + echo "... your db is corrupted, creating new one" + rm /config/birds.db + "$HOME/BirdNET-Pi/scripts/createdb.sh" + cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/ fi # Symlink configuration files @@ -87,12 +87,12 @@ echo "... creating symlinks for configuration files" CONFIG_FILES=("$HOME/BirdNET-Pi/birdnet.conf" "$HOME/BirdNET-Pi/scripts/whitelist_species_list.txt" "$HOME/BirdNET-Pi/blacklisted_images.txt" "$HOME/BirdNET-Pi/scripts/birds.db" "$HOME/BirdNET-Pi/BirdDB.txt" "$HOME/BirdNET-Pi/scripts/disk_check_exclude.txt" "$HOME/BirdNET-Pi/apprise.txt" "$HOME/BirdNET-Pi/exclude_species_list.txt" "$HOME/BirdNET-Pi/include_species_list.txt" "$HOME/BirdNET-Pi/IdentifiedSoFar.txt" "$HOME/BirdNET-Pi/scripts/confirmed_species_list.txt") for file in "${CONFIG_FILES[@]}"; do - filename="${file##*/}" - [ ! -f "/config/$filename" ] && touch "/config/$filename" - [ -e "$file" ] && rm "$file" - sudo -u pi ln -fs "/config/$filename" "$file" - sudo -u pi ln -fs "/config/$filename" "$HOME/BirdNET-Pi/scripts/$filename" - sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename" + filename="${file##*/}" + [ ! -f "/config/$filename" ] && touch "/config/$filename" + [ -e "$file" ] && rm "$file" + sudo -u pi ln -fs "/config/$filename" "$file" + sudo -u pi ln -fs "/config/$filename" "$HOME/BirdNET-Pi/scripts/$filename" + sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename" done # Create thisrun.txt for legacy modes @@ -106,9 +106,9 @@ chown pi:pi /usr/local/bin/* # Symlink BirdSongs folders for folder in By_Date Charts; do - echo "... creating symlink for $BIRDSONGS_FOLDER/$folder" - [ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder" - sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder" + echo "... creating symlink for $BIRDSONGS_FOLDER/$folder" + [ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder" + sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder" done # Set permissions for newly created files and folders @@ -121,4 +121,3 @@ echo "... setting up Matplotlabdir" mkdir -p "$HOME"/.cache/matplotlib chown -R "pi:pi" "$HOME"/.cache/matplotlib chmod 777 "$HOME"/.cache/matplotlib - diff --git a/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh b/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh index fc2a896a8..887e3a44c 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/02-restorestreamdata.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ###################### @@ -19,32 +19,32 @@ fi if [ -d /config/TemporaryFiles ]; then - # Check if there are .wav files in /config/TemporaryFiles - if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then - bashio::log.warning "Container was stopped while files were still being analyzed." - echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData." + # Check if there are .wav files in /config/TemporaryFiles + if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then + bashio::log.warning "Container was stopped while files were still being analyzed." + echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData." - # Create the destination directory if it does not exist - mkdir -p "$HOME"/BirdSongs/StreamData + # Create the destination directory if it does not exist + mkdir -p "$HOME"/BirdSongs/StreamData - # Count the number of .wav files to be moved - file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l) - echo "... found $file_count .wav files to restore." + # Count the number of .wav files to be moved + file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l) + echo "... found $file_count .wav files to restore." - # Move the .wav files using `mv` to avoid double log entries - mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/ + # Move the .wav files using `mv` to avoid double log entries + mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/ - # Update permissions only if files were moved successfully - if [ "$file_count" -gt 0 ]; then - chown -R pi:pi "$HOME"/BirdSongs/StreamData - fi + # Update permissions only if files were moved successfully + if [ "$file_count" -gt 0 ]; then + chown -R pi:pi "$HOME"/BirdSongs/StreamData + fi - echo "... $file_count files restored successfully." - else - echo "... no .wav files found to restore." - fi + echo "... $file_count files restored successfully." + else + echo "... no .wav files found to restore." + fi - # Clean up the source folder if it is empty - rm -r /config/TemporaryFiles + # Clean up the source folder if it is empty + rm -r /config/TemporaryFiles fi diff --git a/birdnet-pi/rootfs/etc/cont-init.d/31-config_checks.sh b/birdnet-pi/rootfs/etc/cont-init.d/31-config_checks.sh index b76d3ded3..f77d083da 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/31-config_checks.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/31-config_checks.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ###################### @@ -25,22 +25,22 @@ configtemplate="$HOME"/BirdNET-Pi/birdnet.bak # Ensure both files exist before proceeding if [ ! -f "$configcurrent" ] || [ ! -f "$configtemplate" ]; then - bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present." - exit 1 + bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present." + exit 1 fi # Extract variable names from config template and read each one grep -o '^[^#=]*=' "$configtemplate" | sed 's/=//' | while read -r var; do - # Check if the variable is in configcurrent, if not, append it - if ! grep -q "^$var=" "$configcurrent"; then - bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added" - grep "^$var=" "$configtemplate" >> "$configcurrent" - fi - # Check for duplicates - if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then - bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out except for the first one" - sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent" - fi + # Check if the variable is in configcurrent, if not, append it + if ! grep -q "^$var=" "$configcurrent"; then + bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added" + grep "^$var=" "$configtemplate" >>"$configcurrent" + fi + # Check for duplicates + if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then + bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out except for the first one" + sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent" + fi done ############## @@ -48,8 +48,8 @@ done ############## if [[ "$(bashio::addon.port "80")" == 3000 ]]; then - bashio::log.fatal "This is crazy but your port is set to 3000 and streamlit doesn't accept this port! You need to change it from the addon options and restart. Thanks" - sleep infinity + bashio::log.fatal "This is crazy but your port is set to 3000 and streamlit doesn't accept this port! You need to change it from the addon options and restart. Thanks" + sleep infinity fi ################## @@ -60,11 +60,11 @@ bashio::log.info "Performing potential updates" # Adapt update_birdnet_snippets sed -i "s|systemctl list-unit-files|false \&\& echo|g" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Avoid systemctl -sed -i "/systemctl /d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Avoid systemctl -sed -i "/install_tmp_mount/d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Use HA tmp -sed -i "/find /d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Not useful -sed -i "/set -x/d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Not useful -sed -i "/restart_services/d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Not useful +sed -i "/systemctl /d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Avoid systemctl +sed -i "/install_tmp_mount/d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Use HA tmp +sed -i "/find /d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Not useful +sed -i "/set -x/d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Not useful +sed -i "/restart_services/d" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Not useful sed -i "s|/etc/birdnet/birdnet.conf|/config/birdnet.conf|g" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh sed -i "/update_caddyfile/c echo \"yes\"" "$HOME"/BirdNET-Pi/scripts/update_birdnet_snippets.sh # Avoid systemctl diff --git a/birdnet-pi/rootfs/etc/cont-init.d/33-mqtt.sh b/birdnet-pi/rootfs/etc/cont-init.d/33-mqtt.sh index 5bac8446e..286441373 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/33-mqtt.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/33-mqtt.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ############ @@ -18,67 +18,67 @@ fi ############ # Function to perform common setup steps -common_steps () { - # Attempt to connect to the MQTT broker - TOPIC="birdnet" - if mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -t "$TOPIC" -m "test" -u "$MQTT_USER" -P "$MQTT_PASS" -q 1 -d --will-topic "$TOPIC" --will-payload "Disconnected" --will-qos 1 --will-retain > /dev/null 2>&1; then - # Adapt script with MQTT settings - sed -i "s|%%mqtt_server%%|$MQTT_HOST|g" /helpers/birdnet_to_mqtt.py - sed -i "s|\"%%mqtt_port%%\"|$MQTT_PORT|g" /helpers/birdnet_to_mqtt.py - sed -i "s|%%mqtt_user%%|$MQTT_USER|g" /helpers/birdnet_to_mqtt.py - sed -i "s|%%mqtt_pass%%|$MQTT_PASS|g" /helpers/birdnet_to_mqtt.py +common_steps() { + # Attempt to connect to the MQTT broker + TOPIC="birdnet" + if mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -t "$TOPIC" -m "test" -u "$MQTT_USER" -P "$MQTT_PASS" -q 1 -d --will-topic "$TOPIC" --will-payload "Disconnected" --will-qos 1 --will-retain >/dev/null 2>&1; then + # Adapt script with MQTT settings + sed -i "s|%%mqtt_server%%|$MQTT_HOST|g" /helpers/birdnet_to_mqtt.py + sed -i "s|\"%%mqtt_port%%\"|$MQTT_PORT|g" /helpers/birdnet_to_mqtt.py + sed -i "s|%%mqtt_user%%|$MQTT_USER|g" /helpers/birdnet_to_mqtt.py + sed -i "s|%%mqtt_pass%%|$MQTT_PASS|g" /helpers/birdnet_to_mqtt.py - # Copy script to the appropriate directory - cp /helpers/birdnet_to_mqtt.py "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py - chown pi:pi "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py - chmod +x "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py + # Copy script to the appropriate directory + cp /helpers/birdnet_to_mqtt.py "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py + chown pi:pi "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py + chmod +x "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py - # Add hooks to the main analysis script - sed -i "/load_global_model, run_analysis/a from utils.birdnet_to_mqtt import automatic_mqtt_publish" "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py - sed -i '/write_to_db(/a\ automatic_mqtt_publish(file, detection, os.path.basename(detection.file_name_extr))' "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py - else - bashio::log.fatal "MQTT connection failed, it will not be configured" - fi + # Add hooks to the main analysis script + sed -i "/load_global_model, run_analysis/a from utils.birdnet_to_mqtt import automatic_mqtt_publish" "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py + sed -i '/write_to_db(/a\ automatic_mqtt_publish(file, detection, os.path.basename(detection.file_name_extr))' "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py + else + bashio::log.fatal "MQTT connection failed, it will not be configured" + fi } # Check if MQTT service is available and not disabled if [[ -f "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py ]] && bashio::services.available 'mqtt' && ! bashio::config.true 'MQTT_DISABLED'; then - bashio::log.green "---" - bashio::log.blue "MQTT addon is active on your system! Birdnet-pi is now automatically configured to send its output to MQTT" - bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")" - bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")" - bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")" - bashio::log.green "---" - bashio::log.blue "Data will be posted to the topic : 'birdnet'" - bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}" - bashio::log.blue "---" + bashio::log.green "---" + bashio::log.blue "MQTT addon is active on your system! Birdnet-pi is now automatically configured to send its output to MQTT" + bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")" + bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")" + bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")" + bashio::log.green "---" + bashio::log.blue "Data will be posted to the topic : 'birdnet'" + bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}" + bashio::log.blue "---" - # Apply MQTT settings - MQTT_HOST="$(bashio::services "mqtt" "host")" - MQTT_PORT="$(bashio::services "mqtt" "port")" - MQTT_USER="$(bashio::services "mqtt" "username")" - MQTT_PASS="$(bashio::services "mqtt" "password")" + # Apply MQTT settings + MQTT_HOST="$(bashio::services "mqtt" "host")" + MQTT_PORT="$(bashio::services "mqtt" "port")" + MQTT_USER="$(bashio::services "mqtt" "username")" + MQTT_PASS="$(bashio::services "mqtt" "password")" - # Perform common setup steps - common_steps + # Perform common setup steps + common_steps # Check if manual MQTT configuration is provided elif [[ -f "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py ]] && bashio::config.has_value "MQTT_HOST_manual" && bashio::config.has_value "MQTT_PORT_manual"; then - bashio::log.green "---" - bashio::log.blue "MQTT is manually configured in the addon options" - bashio::log.blue "Birdnet-pi is now automatically configured to send its output to MQTT" - bashio::log.green "---" - bashio::log.blue "Data will be posted to the topic : 'birdnet'" - bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}" - bashio::log.blue "---" + bashio::log.green "---" + bashio::log.blue "MQTT is manually configured in the addon options" + bashio::log.blue "Birdnet-pi is now automatically configured to send its output to MQTT" + bashio::log.green "---" + bashio::log.blue "Data will be posted to the topic : 'birdnet'" + bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}" + bashio::log.blue "---" - # Apply manual MQTT settings - MQTT_HOST="$(bashio::config "MQTT_HOST_manual")" - MQTT_PORT="$(bashio::config "MQTT_PORT_manual")" - MQTT_USER="$(bashio::config "MQTT_USER_manual")" - MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")" + # Apply manual MQTT settings + MQTT_HOST="$(bashio::config "MQTT_HOST_manual")" + MQTT_PORT="$(bashio::config "MQTT_PORT_manual")" + MQTT_USER="$(bashio::config "MQTT_USER_manual")" + MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")" - # Perform common setup steps - common_steps + # Perform common setup steps + common_steps fi diff --git a/birdnet-pi/rootfs/etc/cont-init.d/81-modifications.sh b/birdnet-pi/rootfs/etc/cont-init.d/81-modifications.sh index ebec9d6a3..b95264120 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/81-modifications.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/81-modifications.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ################ @@ -23,20 +23,20 @@ bashio::log.info "Adapting webui" ###################### if bashio::supervisor.ping 2>/dev/null; then - # Remove services tab from webui - echo "... removing System Controls from webui as should be used from HA" - sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php" + # Remove services tab from webui + echo "... removing System Controls from webui as should be used from HA" + sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php" - # Remove pulseaudio - echo "... disabling pulseaudio as managed by HomeAssistant" - grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do - sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file" - done + # Remove pulseaudio + echo "... disabling pulseaudio as managed by HomeAssistant" + grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do + sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file" + done - # Check if port 80 is correctly configured - if [ -n "$(bashio::addon.port "80")" ] && [ "$(bashio::addon.port "80")" != 80 ]; then - bashio::log.fatal "The port 80 is enabled, but should still be 80 if you want automatic SSL certificates generation to work." - fi + # Check if port 80 is correctly configured + if [ -n "$(bashio::addon.port "80")" ] && [ "$(bashio::addon.port "80")" != 80 ]; then + bashio::log.fatal "The port 80 is enabled, but should still be 80 if you want automatic SSL certificates generation to work." + fi fi # General elements @@ -45,25 +45,25 @@ fi # Remove Ram drive option from webui echo "... removing Ram drive from webui as it is handled from HA" if grep -q "Ram drive" "$HOME/BirdNET-Pi/scripts/service_controls.php"; then - sed -i '/Ram drive/{n;s/center"/center" style="display: none;"/;}' "$HOME/BirdNET-Pi/scripts/service_controls.php" - sed -i '/Ram drive/d' "$HOME/BirdNET-Pi/scripts/service_controls.php" + sed -i '/Ram drive/{n;s/center"/center" style="display: none;"/;}' "$HOME/BirdNET-Pi/scripts/service_controls.php" + sed -i '/Ram drive/d' "$HOME/BirdNET-Pi/scripts/service_controls.php" fi # Allow symlinks echo "... ensuring symlinks work" for files in "$HOME"/BirdNET-Pi/scripts/*.sh; do - sed -i "s|find |find -L |g" "$files" - sed -i "s|find -L -L |find -L |g" "$files" + sed -i "s|find |find -L |g" "$files" + sed -i "s|find -L -L |find -L |g" "$files" done # Correct services to start as user pi echo "... updating services to start as user pi" if ! grep -q "/usr/bin/sudo" "$HOME/BirdNET-Pi/templates/birdnet_analysis.service"; then - while IFS= read -r file; do - if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then - sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file" - fi - done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print) + while IFS= read -r file; do + if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then + sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file" + fi + done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print) fi # Allow pulseaudio system @@ -73,16 +73,16 @@ sed -i 's#pulseaudio --start#pulseaudio --start 2>/dev/null && pulseaudio --chec # Send services log to container logs echo "... redirecting services logs to container logs" while IFS= read -r file; do - sed -i "/StandardError/d" "$file" - sed -i "/StandardOutput/d" "$file" - sed -i "/\[Service/a StandardError=append:/proc/1/fd/1" "$file" - sed -i "/\[Service/a StandardOutput=append:/proc/1/fd/1" "$file" + sed -i "/StandardError/d" "$file" + sed -i "/StandardOutput/d" "$file" + sed -i "/\[Service/a StandardError=append:/proc/1/fd/1" "$file" + sed -i "/\[Service/a StandardOutput=append:/proc/1/fd/1" "$file" done < <(find "$HOME/BirdNET-Pi/templates/" -name "*.service" -print) # Preencode API key if [[ -f "$HOME/BirdNET-Pi/scripts/common.php" ]] && ! grep -q "221160312" "$HOME/BirdNET-Pi/scripts/common.php"; then - sed -i "/return \$_SESSION\['my_config'\];/i\ \ \ \ if (isset(\$_SESSION\['my_config'\]) \&\& empty(\$_SESSION\['my_config'\]\['FLICKR_API_KEY'\])) {\n\ \ \ \ \ \ \ \ \$_SESSION\['my_config'\]\['FLICKR_API_KEY'\] = \"221160312e1c22\";\n\ \ \ \ }" "$HOME"/BirdNET-Pi/scripts/common.php - sed -i "s|e1c22|e1c22ec60ecf336951b0e77|g" "$HOME"/BirdNET-Pi/scripts/common.php + sed -i "/return \$_SESSION\['my_config'\];/i\ \ \ \ if (isset(\$_SESSION\['my_config'\]) \&\& empty(\$_SESSION\['my_config'\]\['FLICKR_API_KEY'\])) {\n\ \ \ \ \ \ \ \ \$_SESSION\['my_config'\]\['FLICKR_API_KEY'\] = \"221160312e1c22\";\n\ \ \ \ }" "$HOME"/BirdNET-Pi/scripts/common.php + sed -i "s|e1c22|e1c22ec60ecf336951b0e77|g" "$HOME"/BirdNET-Pi/scripts/common.php fi # Correct log services to show /proc/1/fd/1 @@ -92,8 +92,8 @@ sed -i "s|birdnet_log.sh|cat /proc/1/fd/1|g" "$HOME/BirdNET-Pi/templates/birdnet # Correct backup script if [[ -f "$HOME/BirdNET-Pi/scripts/backup_data.sh" ]]; then - echo "... correct backup script" - sed -i "/PHP_SERVICE=/c PHP_SERVICE=\$(systemctl list-unit-files -t service --no-pager | grep 'php' | grep 'fpm' | awk '{print \$1}')" "$HOME/BirdNET-Pi/scripts/backup_data.sh" + echo "... correct backup script" + sed -i "/PHP_SERVICE=/c PHP_SERVICE=\$(systemctl list-unit-files -t service --no-pager | grep 'php' | grep 'fpm' | awk '{print \$1}')" "$HOME/BirdNET-Pi/scripts/backup_data.sh" fi # Caddyfile modifications @@ -101,27 +101,27 @@ echo "... modifying Caddyfile configurations" caddy fmt --overwrite /etc/caddy/Caddyfile #Change port to leave 80 free for certificate requests if ! grep -q "http://:8081" /etc/caddy/Caddyfile; then - sed -i "s|http://|http://:8081|g" /etc/caddy/Caddyfile - sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" - if [ -f /etc/caddy/Caddyfile.original ]; then - rm /etc/caddy/Caddyfile.original - fi + sed -i "s|http://|http://:8081|g" /etc/caddy/Caddyfile + sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" + if [ -f /etc/caddy/Caddyfile.original ]; then + rm /etc/caddy/Caddyfile.original + fi fi # Correct webui paths echo "... correcting webui paths" if ! grep -q "/stats/" "$HOME/BirdNET-Pi/homepage/views.php"; then - sed -i "s|/stats|/stats/|g" "$HOME/BirdNET-Pi/homepage/views.php" - sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php" + sed -i "s|/stats|/stats/|g" "$HOME/BirdNET-Pi/homepage/views.php" + sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php" fi # Correct systemctl path if [ -f /helpers/systemctl ] && [ -f /helpers/journalctl ]; then - echo "... updating systemctl and journalctl" - cp -rf /helpers/systemctl /bin/systemctl - cp -rf /helpers/journalctl /bin/journalctl - chown pi:pi /bin/systemctl /bin/journalctl - chmod a+x /bin/systemctl /bin/journalctl + echo "... updating systemctl and journalctl" + cp -rf /helpers/systemctl /bin/systemctl + cp -rf /helpers/journalctl /bin/journalctl + chown pi:pi /bin/systemctl /bin/journalctl + chmod a+x /bin/systemctl /bin/journalctl fi # Allow reverse proxy for streamlit @@ -130,34 +130,34 @@ sed -i "s|plotly_streamlit.py --browser.gatherUsageStats|plotly_streamlit.py --s # Clean saved mp3 files if [[ -f "$HOME/BirdNET-Pi/scripts/utils/reporting.py" ]]; then - echo ".. add highpass and lowpass to sox extracts" - sed -i "s|f'={stop}']|f'={stop}', 'highpass', '250']|g" "$HOME/BirdNET-Pi/scripts/utils/reporting.py" + echo ".. add highpass and lowpass to sox extracts" + sed -i "s|f'={stop}']|f'={stop}', 'highpass', '250']|g" "$HOME/BirdNET-Pi/scripts/utils/reporting.py" fi # Correct timedatectl path echo "... updating timedatectl path" if [[ -f /helpers/timedatectl ]]; then - mv /helpers/timedatectl /usr/bin/timedatectl - chown pi:pi /usr/bin/timedatectl - chmod a+x /usr/bin/timedatectl + mv /helpers/timedatectl /usr/bin/timedatectl + chown pi:pi /usr/bin/timedatectl + chmod a+x /usr/bin/timedatectl fi # Set RECS_DIR echo "... setting RECS_DIR to /tmp" grep -rl "RECS_DIR" "$HOME" --exclude="*.php" | while read -r file; do - sed -i "s|conf\['RECS_DIR'\]|'/tmp'|g" "$file" - sed -i "s|\$RECS_DIR|/tmp|g" "$file" - sed -i "s|\${RECS_DIR}|/tmp|g" "$file" - sed -i "/^RECS_DIR=/c RECS_DIR=/tmp" "$file" - sed -i "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file" + sed -i "s|conf\['RECS_DIR'\]|'/tmp'|g" "$file" + sed -i "s|\$RECS_DIR|/tmp|g" "$file" + sed -i "s|\${RECS_DIR}|/tmp|g" "$file" + sed -i "/^RECS_DIR=/c RECS_DIR=/tmp" "$file" + sed -i "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file" done mkdir -p /tmp # Correct language labels according to birdnet.conf echo "... adapting labels according to birdnet.conf" if export "$(grep "^DATABASE_LANG" /config/birdnet.conf)"; then - bashio::log.info "Setting language to ${DATABASE_LANG:-en}" - "$HOME/BirdNET-Pi/scripts/install_language_label_nm.sh" -l "${DATABASE_LANG:-}" &>/dev/null || bashio::log.warning "Failed to update language labels" + bashio::log.info "Setting language to ${DATABASE_LANG:-en}" + "$HOME/BirdNET-Pi/scripts/install_language_label_nm.sh" -l "${DATABASE_LANG:-}" &>/dev/null || bashio::log.warning "Failed to update language labels" else - bashio::log.warning "DATABASE_LANG not found in configuration. Using default labels." + bashio::log.warning "DATABASE_LANG not found in configuration. Using default labels." fi diff --git a/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh b/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh index 343dacb1c..3300de165 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ################# @@ -24,9 +24,9 @@ ingress_entry=$(bashio::addon.ingress_entry) # Quits if ingress is not active if [[ "$ingress_entry" != "/api"* ]]; then - bashio::log.info "Ingress entry is not set, exiting configuration." - sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh - exit 0 + bashio::log.info "Ingress entry is not set, exiting configuration." + sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh + exit 0 fi bashio::log.info "Adapting for ingress" @@ -35,26 +35,26 @@ echo "... setting up nginx" # Check if the NGINX configuration file exists nginx_conf="/etc/nginx/servers/ingress.conf" if [ -f "$nginx_conf" ]; then - sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf" - sed -i "s/%%interface%%/${ingress_interface}/g" "$nginx_conf" - sed -i "s|%%ingress_entry%%|${ingress_entry}|g" "$nginx_conf" + sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf" + sed -i "s/%%interface%%/${ingress_interface}/g" "$nginx_conf" + sed -i "s|%%ingress_entry%%|${ingress_entry}|g" "$nginx_conf" else - bashio::log.error "NGINX configuration file not found: $nginx_conf" - exit 1 + bashio::log.error "NGINX configuration file not found: $nginx_conf" + exit 1 fi # Disable log sed -i "/View Log/d" "$HOME/BirdNET-Pi/homepage/views.php" echo "... ensuring restricted area access" -echo "${ingress_entry}" > /ingress_url +echo "${ingress_entry}" >/ingress_url # Modify PHP file safely php_file="$HOME/BirdNET-Pi/scripts/common.php" if [ -f "$php_file" ]; then - sed -i "/function is_authenticated/a if (strpos(\$_SERVER['HTTP_REFERER'], '/api/hassio_ingress') !== false && strpos(\$_SERVER['HTTP_REFERER'], trim(file_get_contents('/ingress_url'))) !== false) { \$ret = true; return \$ret; }" "$php_file" + sed -i "/function is_authenticated/a if (strpos(\$_SERVER['HTTP_REFERER'], '/api/hassio_ingress') !== false && strpos(\$_SERVER['HTTP_REFERER'], trim(file_get_contents('/ingress_url'))) !== false) { \$ret = true; return \$ret; }" "$php_file" else - bashio::log.warning "PHP file not found: $php_file" + bashio::log.warning "PHP file not found: $php_file" fi echo "... adapting Caddyfile for ingress" @@ -66,8 +66,8 @@ chmod +x /helpers/caddy_ingress.sh # Update the Caddyfile if update script exists caddy_update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" if [ -f "$caddy_update_script" ]; then - sed -i "/sudo caddy fmt --overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script" + sed -i "/sudo caddy fmt --overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script" else - bashio::log.error "Caddy update script not found: $caddy_update_script" - exit 1 + bashio::log.error "Caddy update script not found: $caddy_update_script" + exit 1 fi diff --git a/birdnet-pi/rootfs/etc/cont-init.d/92-ssl.sh b/birdnet-pi/rootfs/etc/cont-init.d/92-ssl.sh index 3de547c80..659a2c737 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/92-ssl.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/92-ssl.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ############### @@ -18,33 +18,32 @@ fi ############### if bashio::config.true 'ssl'; then - bashio::log.info "SSL is enabled using addon options, setting up NGINX and Caddy." + bashio::log.info "SSL is enabled using addon options, setting up NGINX and Caddy." - # Check required SSL configurations - bashio::config.require.ssl - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') + # Check required SSL configurations + bashio::config.require.ssl + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') - # Ensure Caddyfile exists before modifying - caddyfile="/etc/caddy/Caddyfile" - if [ -f "$caddyfile" ]; then - sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile" - sed -i "s|http://:8081|https://:8081|g" "$caddyfile" - else - bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration." - exit 1 - fi + # Ensure Caddyfile exists before modifying + caddyfile="/etc/caddy/Caddyfile" + if [ -f "$caddyfile" ]; then + sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile" + sed -i "s|http://:8081|https://:8081|g" "$caddyfile" + else + bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration." + exit 1 + fi - # Ensure update_caddyfile.sh exists before modifying - update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" - if [ -f "$update_script" ]; then - sed -i "s|http://:8081|https://:8081|g" "$update_script" - if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then - sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script" - fi - else - bashio::log.error "Update script not found: $update_script, skipping SSL setup for update." - exit 1 - fi + # Ensure update_caddyfile.sh exists before modifying + update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" + if [ -f "$update_script" ]; then + sed -i "s|http://:8081|https://:8081|g" "$update_script" + if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then + sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script" + fi + else + bashio::log.error "Update script not found: $update_script, skipping SSL setup for update." + exit 1 + fi fi - diff --git a/birdnet-pi/rootfs/etc/cont-init.d/98-oldcpu.sh b/birdnet-pi/rootfs/etc/cont-init.d/98-oldcpu.sh index 28e0ddd84..a66a6cee5 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/98-oldcpu.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/98-oldcpu.sh @@ -7,10 +7,10 @@ set -e ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ###################### @@ -19,19 +19,19 @@ fi # Check if the CPU supports AVX2 if [[ "$(uname -m)" = "x86_64" ]]; then - if lscpu | grep -q "Flags"; then - if ! lscpu | grep -q "avx2"; then - bashio::log.warning "NON SUPPORTED CPU DETECTED" - bashio::log.warning "Your cpu doesn't support avx2, the analyzer service will likely won't work" - bashio::log.warning "Trying to install tensorflow instead of tflite_runtime instead. This might take some time (up to 5 minutes)." - bashio::log.warning "You could try also Birdnet-Go which should supports your cpu" - source /home/pi/BirdNET-Pi/birdnet/bin/activate - mkdir -p /home/pi/.cache/pip || true &>/dev/null - chmod 777 /home/pi/.cache/pip || true &>/dev/null - pip3 uninstall -y tflite_runtime - pip install --upgrade packaging==23.2 - pip3 install --upgrade --force-reinstall "https://github.com/snowzach/tensorflow-multiarch/releases/download/v2.16.1/tensorflow-2.16.1-cp311-cp311-linux_x86_64.whl" - deactivate - fi - fi + if lscpu | grep -q "Flags"; then + if ! lscpu | grep -q "avx2"; then + bashio::log.warning "NON SUPPORTED CPU DETECTED" + bashio::log.warning "Your cpu doesn't support avx2, the analyzer service will likely won't work" + bashio::log.warning "Trying to install tensorflow instead of tflite_runtime instead. This might take some time (up to 5 minutes)." + bashio::log.warning "You could try also Birdnet-Go which should supports your cpu" + source /home/pi/BirdNET-Pi/birdnet/bin/activate + mkdir -p /home/pi/.cache/pip || true &>/dev/null + chmod 777 /home/pi/.cache/pip || true &>/dev/null + pip3 uninstall -y tflite_runtime + pip install --upgrade packaging==23.2 + pip3 install --upgrade --force-reinstall "https://github.com/snowzach/tensorflow-multiarch/releases/download/v2.16.1/tensorflow-2.16.1-cp311-cp311-linux_x86_64.whl" + deactivate + fi + fi fi diff --git a/birdnet-pi/rootfs/etc/cont-init.d/99-run.sh b/birdnet-pi/rootfs/etc/cont-init.d/99-run.sh index c337fdae6..e0d31badc 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/99-run.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/99-run.sh @@ -8,10 +8,10 @@ set -eu ################## if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then - mkdir -p /etc/scripts-init - sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh - sed -i "/ rm/d" /ha_entrypoint.sh - cp "${BASH_SOURCE[0]}" /etc/scripts-init/ + mkdir -p /etc/scripts-init + sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh + sed -i "/ rm/d" /ha_entrypoint.sh + cp "${BASH_SOURCE[0]}" /etc/scripts-init/ fi ############## @@ -21,52 +21,52 @@ fi # Set password bashio::log.info "Setting password for the user pi" if bashio::config.has_value "pi_password"; then - echo "pi:$(bashio::config "pi_password")" | chpasswd + echo "pi:$(bashio::config "pi_password")" | chpasswd fi bashio::log.info "Password set successfully for user pi." # Use timezone defined in add-on options if available bashio::log.info "Setting timezone :" if bashio::config.has_value 'TZ'; then - TZ_VALUE="$(bashio::config 'TZ')" - if timedatectl set-timezone "$TZ_VALUE"; then - echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)." - else - bashio::log.warning "Couldn't set timezone to $TZ_VALUE. Refer to the list of valid timezones: https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html" - timedatectl set-ntp true &>/dev/null - fi + TZ_VALUE="$(bashio::config 'TZ')" + if timedatectl set-timezone "$TZ_VALUE"; then + echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)." + else + bashio::log.warning "Couldn't set timezone to $TZ_VALUE. Refer to the list of valid timezones: https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html" + timedatectl set-ntp true &>/dev/null + fi # Use BirdNET-defined timezone if no add-on option is provided elif [ -f /data/timezone ]; then - BIRDN_CONFIG_TZ="$(cat /data/timezone)" - timedatectl set-ntp false &>/dev/null - if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then - echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config." - else - bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone." - timedatectl set-ntp true &>/dev/null - fi + BIRDN_CONFIG_TZ="$(cat /data/timezone)" + timedatectl set-ntp false &>/dev/null + if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then + echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config." + else + bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone." + timedatectl set-ntp true &>/dev/null + fi # Fallback to automatic timezone if no manual settings are found else - if timedatectl set-ntp true &>/dev/null; then - bashio::log.info "... automatic timezone enabled." - else - bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options." - fi + if timedatectl set-ntp true &>/dev/null; then + bashio::log.info "... automatic timezone enabled." + else + bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options." + fi fi || true # Use ALSA CARD defined in add-on options if available if [ -n "${ALSA_CARD:-}" ]; then - bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD" - for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do - if [ -f "$file" ]; then - sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file" - fi - done + bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD" + for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do + if [ -f "$file" ]; then + sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file" + fi + done fi # Fix timezone as per installer CURRENT_TIMEZONE="$(timedatectl show --value --property=Timezone)" -[ -f /etc/timezone ] && echo "$CURRENT_TIMEZONE" | sudo tee /etc/timezone > /dev/null +[ -f /etc/timezone ] && echo "$CURRENT_TIMEZONE" | sudo tee /etc/timezone >/dev/null bashio::log.info "Starting system services" @@ -82,10 +82,10 @@ chmod +x "$HOME/BirdNET-Pi/scripts/restart_services.sh" >/dev/null # Start livestream services if enabled in configuration if bashio::config.true "LIVESTREAM_BOOT_ENABLED"; then - echo "... starting livestream services" - systemctl enable icecast2 >/dev/null - systemctl start icecast2.service >/dev/null - systemctl enable --now livestream.service >/dev/null + echo "... starting livestream services" + systemctl enable icecast2 >/dev/null + systemctl start icecast2.service >/dev/null + systemctl enable --now livestream.service >/dev/null fi # Start diff --git a/birdnet-pi/rootfs/helpers/caddy_ingress.sh b/birdnet-pi/rootfs/helpers/caddy_ingress.sh index f6e077922..b2a831fb6 100755 --- a/birdnet-pi/rootfs/helpers/caddy_ingress.sh +++ b/birdnet-pi/rootfs/helpers/caddy_ingress.sh @@ -7,7 +7,7 @@ set +u source /etc/birdnet/birdnet.conf # Create ingress configuration for Caddyfile - cat << EOF >> /etc/caddy/Caddyfile +cat <>/etc/caddy/Caddyfile :8082 { root * ${EXTRACTED} file_server browse diff --git a/birdnet-pi/rootfs/helpers/timedatectl b/birdnet-pi/rootfs/helpers/timedatectl index 93f30ef83..ccfc4da01 100755 --- a/birdnet-pi/rootfs/helpers/timedatectl +++ b/birdnet-pi/rootfs/helpers/timedatectl @@ -2,106 +2,106 @@ # Function to show the current timezone using two alternative methods show_timezone() { - if [ -f /data/timezone ]; then - cat /data/timezone - elif [ -f /etc/timezone ]; then - cat /etc/timezone - elif [ -f /etc/localtime ]; then - readlink /etc/localtime | sed 's|/usr/share/zoneinfo/||' - else - echo "Cannot determine timezone." - fi + if [ -f /data/timezone ]; then + cat /data/timezone + elif [ -f /etc/timezone ]; then + cat /etc/timezone + elif [ -f /etc/localtime ]; then + readlink /etc/localtime | sed 's|/usr/share/zoneinfo/||' + else + echo "Cannot determine timezone." + fi } # Function to set the timezone set_timezone() { - local new_timezone="$1" - if [ ! -f "/usr/share/zoneinfo/$new_timezone" ]; then - echo "Invalid timezone: $new_timezone" - return 1 - fi + local new_timezone="$1" + if [ ! -f "/usr/share/zoneinfo/$new_timezone" ]; then + echo "Invalid timezone: $new_timezone" + return 1 + fi - echo "$new_timezone" > /data/timezone - echo "$new_timezone" > /etc/timezone - ln -sf "/usr/share/zoneinfo/$new_timezone" /etc/localtime + echo "$new_timezone" >/data/timezone + echo "$new_timezone" >/etc/timezone + ln -sf "/usr/share/zoneinfo/$new_timezone" /etc/localtime - # Update /etc/environment if it exists - if [ -f /etc/environment ]; then - sed -i "/^TZ=/c\TZ=$new_timezone" /etc/environment - fi + # Update /etc/environment if it exists + if [ -f /etc/environment ]; then + sed -i "/^TZ=/c\TZ=$new_timezone" /etc/environment + fi - # Update s6 container environment if it exists - if [ -d /var/run/s6/container_environment ]; then - echo "$new_timezone" > /var/run/s6/container_environment/TZ - fi + # Update s6 container environment if it exists + if [ -d /var/run/s6/container_environment ]; then + echo "$new_timezone" >/var/run/s6/container_environment/TZ + fi - echo "Timezone set to: $new_timezone" + echo "Timezone set to: $new_timezone" } # Function to enable or disable NTP set_ntp() { - case "$1" in - "false") - systemctl stop systemd-timesyncd - systemctl disable systemd-timesyncd - echo "NTP disabled" - ;; - "true") - systemctl start systemd-timesyncd - systemctl enable systemd-timesyncd + case "$1" in + "false") + systemctl stop systemd-timesyncd + systemctl disable systemd-timesyncd + echo "NTP disabled" + ;; + "true") + systemctl start systemd-timesyncd + systemctl enable systemd-timesyncd - # Remove the /data/timezone file when NTP is enabled - if [ -f /data/timezone ]; then - rm -f /data/timezone - echo "Timezone configuration file /data/timezone deleted." - fi + # Remove the /data/timezone file when NTP is enabled + if [ -f /data/timezone ]; then + rm -f /data/timezone + echo "Timezone configuration file /data/timezone deleted." + fi - echo "NTP enabled" - ;; - *) - echo "Invalid argument for set-ntp. Use 'false' or 'true'." - ;; - esac + echo "NTP enabled" + ;; + *) + echo "Invalid argument for set-ntp. Use 'false' or 'true'." + ;; + esac } # Function to show detailed time settings show_time_details() { - local local_time - local utc_time - local time_zone - local ntp_status="no" - local ntp_service="inactive" + local local_time + local utc_time + local time_zone + local ntp_status="no" + local ntp_service="inactive" - local_time="$(date)" - utc_time="$(date -u)" - time_zone="$(show_timezone)" - - # Check if NTP is used - if systemctl is-active --quiet systemd-timesyncd; then - ntp_status="yes" - ntp_service="active" - fi + local_time="$(date)" + utc_time="$(date -u)" + time_zone="$(show_timezone)" - # Print the information - echo "Local time: $local_time" - echo "Universal time: $utc_time" - echo "Time zone: $time_zone" - echo "Network time on: $ntp_status" - echo "NTP service: $ntp_service" + # Check if NTP is used + if systemctl is-active --quiet systemd-timesyncd; then + ntp_status="yes" + ntp_service="active" + fi + + # Print the information + echo "Local time: $local_time" + echo "Universal time: $utc_time" + echo "Time zone: $time_zone" + echo "Network time on: $ntp_status" + echo "NTP service: $ntp_service" } # Main script logic case "$1" in - "set-ntp") - set_ntp "$2" - ;; - "show") - show_timezone - ;; - "set-timezone") - set_timezone "$2" - ;; - *) - show_time_details - ;; +"set-ntp") + set_ntp "$2" + ;; +"show") + show_timezone + ;; +"set-timezone") + set_timezone "$2" + ;; +*) + show_time_details + ;; esac diff --git a/birdnet-pi/rootfs/helpers/timedatectl2 b/birdnet-pi/rootfs/helpers/timedatectl2 index 3a181da94..e705fb46c 100755 --- a/birdnet-pi/rootfs/helpers/timedatectl2 +++ b/birdnet-pi/rootfs/helpers/timedatectl2 @@ -12,7 +12,7 @@ # ------------------------------------------------------------------------------ print_usage() { - cat <&2 - exit 1 + echo "Error: $*" >&2 + exit 1 } # ------------------------------------------------------------------------------ @@ -45,180 +45,180 @@ abort() { # ------------------------------------------------------------------------------ show_status() { - echo "=== System Time/Date ===" - date + echo "=== System Time/Date ===" + date - echo - echo "=== Time Zone ===" - # Attempt to parse the symlink at /etc/localtime - # On many systems, /etc/localtime is a symlink to /usr/share/zoneinfo/Region/City - if [ -L /etc/localtime ]; then - local tz_target - tz_target=$(readlink -f /etc/localtime) - # Remove the /usr/share/zoneinfo/ part to display just Region/City - local tz_name - tz_name="${tz_target#/usr/share/zoneinfo/}" - echo "Time zone: $tz_name" - else - # Some distros have /etc/localtime as a copy of the zone file - # Try to read /etc/timezone as a fallback (Debian-based) - if [ -f /etc/timezone ]; then - echo "Time zone: $(cat /etc/timezone)" - else - echo "Time zone: Unknown (not a symlink, and /etc/timezone missing)" - fi - fi + echo + echo "=== Time Zone ===" + # Attempt to parse the symlink at /etc/localtime + # On many systems, /etc/localtime is a symlink to /usr/share/zoneinfo/Region/City + if [ -L /etc/localtime ]; then + local tz_target + tz_target=$(readlink -f /etc/localtime) + # Remove the /usr/share/zoneinfo/ part to display just Region/City + local tz_name + tz_name="${tz_target#/usr/share/zoneinfo/}" + echo "Time zone: $tz_name" + else + # Some distros have /etc/localtime as a copy of the zone file + # Try to read /etc/timezone as a fallback (Debian-based) + if [ -f /etc/timezone ]; then + echo "Time zone: $(cat /etc/timezone)" + else + echo "Time zone: Unknown (not a symlink, and /etc/timezone missing)" + fi + fi - echo - echo "=== RTC in local TZ? ===" - # If /etc/adjtime exists and the last line is "LOCAL", that typically indicates localtime - # If it’s "UTC" or absent, the RTC is typically in UTC. - if [ -f /etc/adjtime ]; then - local rtc_mode - rtc_mode=$(tail -n 1 /etc/adjtime) - if [ "$rtc_mode" = "LOCAL" ]; then - echo "RTC is in local time." - else - echo "RTC is in UTC." - fi - else - echo "Cannot determine RTC mode (no /etc/adjtime)." - fi + echo + echo "=== RTC in local TZ? ===" + # If /etc/adjtime exists and the last line is "LOCAL", that typically indicates localtime + # If it’s "UTC" or absent, the RTC is typically in UTC. + if [ -f /etc/adjtime ]; then + local rtc_mode + rtc_mode=$(tail -n 1 /etc/adjtime) + if [ "$rtc_mode" = "LOCAL" ]; then + echo "RTC is in local time." + else + echo "RTC is in UTC." + fi + else + echo "Cannot determine RTC mode (no /etc/adjtime)." + fi - echo - echo "=== NTP Service Status ===" - # Attempt to detect if systemd-timesyncd is enabled/active - if command -v systemctl &>/dev/null; then - if systemctl is-enabled systemd-timesyncd &>/dev/null; then - echo "systemd-timesyncd service is enabled." - else - echo "systemd-timesyncd service is disabled." - fi + echo + echo "=== NTP Service Status ===" + # Attempt to detect if systemd-timesyncd is enabled/active + if command -v systemctl &>/dev/null; then + if systemctl is-enabled systemd-timesyncd &>/dev/null; then + echo "systemd-timesyncd service is enabled." + else + echo "systemd-timesyncd service is disabled." + fi - if systemctl is-active systemd-timesyncd &>/dev/null; then - echo "systemd-timesyncd service is active (running)." - else - echo "systemd-timesyncd service is not running." - fi - else - echo "systemctl is not available. Cannot determine NTP status this way." - fi + if systemctl is-active systemd-timesyncd &>/dev/null; then + echo "systemd-timesyncd service is active (running)." + else + echo "systemd-timesyncd service is not running." + fi + else + echo "systemctl is not available. Cannot determine NTP status this way." + fi - echo + echo } set_time() { - local new_time="$1" + local new_time="$1" - if [ -z "$new_time" ]; then - abort "Please specify a time, e.g. '2025-03-21 18:00:00'" - fi + if [ -z "$new_time" ]; then + abort "Please specify a time, e.g. '2025-03-21 18:00:00'" + fi - echo "Setting system time to: $new_time" - # Using 'date' to set system time. - # Format can be e.g. "YYYY-MM-DD HH:MM:SS" - # Usually you need root privileges for this: - if ! date -s "$new_time"; then - abort "Failed to set system time. Check your permissions?" - fi + echo "Setting system time to: $new_time" + # Using 'date' to set system time. + # Format can be e.g. "YYYY-MM-DD HH:MM:SS" + # Usually you need root privileges for this: + if ! date -s "$new_time"; then + abort "Failed to set system time. Check your permissions?" + fi - # Also sync to hardware clock: - if command -v hwclock &>/dev/null; then - hwclock --systohc || echo "Warning: couldn't sync with HW clock." - fi + # Also sync to hardware clock: + if command -v hwclock &>/dev/null; then + hwclock --systohc || echo "Warning: couldn't sync with HW clock." + fi } list_timezones() { - local zoneinfo_dir="/usr/share/zoneinfo" - if [ ! -d "$zoneinfo_dir" ]; then - abort "Cannot find $zoneinfo_dir directory." - fi + local zoneinfo_dir="/usr/share/zoneinfo" + if [ ! -d "$zoneinfo_dir" ]; then + abort "Cannot find $zoneinfo_dir directory." + fi - echo "List of available time zones (under $zoneinfo_dir):" - # We filter out possible files that are not real zone data. - # On some systems, zone data might be in subdirectories (Region/City). - find "$zoneinfo_dir" -type f | sed "s|^$zoneinfo_dir/||" + echo "List of available time zones (under $zoneinfo_dir):" + # We filter out possible files that are not real zone data. + # On some systems, zone data might be in subdirectories (Region/City). + find "$zoneinfo_dir" -type f | sed "s|^$zoneinfo_dir/||" } set_timezone() { - local tz="$1" + local tz="$1" - if [ -z "$tz" ]; then - abort "Please specify a time zone, e.g. 'America/New_York'" - fi + if [ -z "$tz" ]; then + abort "Please specify a time zone, e.g. 'America/New_York'" + fi - local zoneinfo_file="/usr/share/zoneinfo/$tz" - if [ ! -f "$zoneinfo_file" ]; then - abort "Time zone '$tz' not found under /usr/share/zoneinfo" - fi + local zoneinfo_file="/usr/share/zoneinfo/$tz" + if [ ! -f "$zoneinfo_file" ]; then + abort "Time zone '$tz' not found under /usr/share/zoneinfo" + fi - echo "Linking /etc/localtime to $zoneinfo_file" - ln -sf "$zoneinfo_file" /etc/localtime || abort "Failed to link /etc/localtime" + echo "Linking /etc/localtime to $zoneinfo_file" + ln -sf "$zoneinfo_file" /etc/localtime || abort "Failed to link /etc/localtime" - # Some distros use /etc/timezone to store the name of the current timezone - if [ -w /etc/timezone ]; then - echo "$tz" >/etc/timezone - fi + # Some distros use /etc/timezone to store the name of the current timezone + if [ -w /etc/timezone ]; then + echo "$tz" >/etc/timezone + fi - echo "Time zone changed to $tz." + echo "Time zone changed to $tz." } set_local_rtc() { - local is_local="$1" + local is_local="$1" - if [ -z "$is_local" ]; then - abort "Please specify 0 or 1. Example: set-local-rtc 1" - fi + if [ -z "$is_local" ]; then + abort "Please specify 0 or 1. Example: set-local-rtc 1" + fi - # We update /etc/adjtime accordingly: - # - If local time: last line should be LOCAL - # - If UTC: last line should be UTC - # We also update the hardware clock accordingly. - if [ "$is_local" = "1" ]; then - echo "Configuring RTC to use local time." - # "hwclock --localtime" is fairly ambiguous (it sets hardware clock from system time). - # We use the below approach: - hwclock --systohc --localtime || echo "Warning: couldn't set HW clock localtime." - # Overwrite /etc/adjtime fully: - cat </etc/adjtime + # We update /etc/adjtime accordingly: + # - If local time: last line should be LOCAL + # - If UTC: last line should be UTC + # We also update the hardware clock accordingly. + if [ "$is_local" = "1" ]; then + echo "Configuring RTC to use local time." + # "hwclock --localtime" is fairly ambiguous (it sets hardware clock from system time). + # We use the below approach: + hwclock --systohc --localtime || echo "Warning: couldn't set HW clock localtime." + # Overwrite /etc/adjtime fully: + cat </etc/adjtime 0.0 0 0.0 0 LOCAL EOF - else - echo "Configuring RTC to use UTC." - hwclock --systohc --utc || echo "Warning: couldn't set HW clock to UTC." - cat </etc/adjtime + else + echo "Configuring RTC to use UTC." + hwclock --systohc --utc || echo "Warning: couldn't set HW clock to UTC." + cat </etc/adjtime 0.0 0 0.0 0 UTC EOF - fi + fi } set_ntp() { - local enable_ntp="$1" - if ! command -v systemctl &>/dev/null; then - echo "systemctl not available. Cannot manage systemd-timesyncd. Exiting." - return 1 - fi + local enable_ntp="$1" + if ! command -v systemctl &>/dev/null; then + echo "systemctl not available. Cannot manage systemd-timesyncd. Exiting." + return 1 + fi - # systemd-timesyncd is the typical built-in NTP client for systemd-based systems - case "$enable_ntp" in - true|True|1|on) - echo "Enabling and starting systemd-timesyncd..." - systemctl enable systemd-timesyncd || echo "Failed to enable timesyncd." - systemctl start systemd-timesyncd || echo "Failed to start timesyncd." - ;; - false|False|0|off) - echo "Disabling and stopping systemd-timesyncd..." - systemctl disable systemd-timesyncd || echo "Failed to disable timesyncd." - systemctl stop systemd-timesyncd || echo "Failed to stop timesyncd." - ;; - *) - abort "Unknown argument '$enable_ntp'. Use 'true' or 'false'." - ;; - esac + # systemd-timesyncd is the typical built-in NTP client for systemd-based systems + case "$enable_ntp" in + true | True | 1 | on) + echo "Enabling and starting systemd-timesyncd..." + systemctl enable systemd-timesyncd || echo "Failed to enable timesyncd." + systemctl start systemd-timesyncd || echo "Failed to start timesyncd." + ;; + false | False | 0 | off) + echo "Disabling and stopping systemd-timesyncd..." + systemctl disable systemd-timesyncd || echo "Failed to disable timesyncd." + systemctl stop systemd-timesyncd || echo "Failed to stop timesyncd." + ;; + *) + abort "Unknown argument '$enable_ntp'. Use 'true' or 'false'." + ;; + esac } # ------------------------------------------------------------------------------ @@ -226,43 +226,43 @@ set_ntp() { # ------------------------------------------------------------------------------ main() { - local cmd="$1" - shift || true + local cmd="$1" + shift || true - case "$cmd" in - status) - show_status - ;; - set-time) - set_time "$@" - ;; - set-timezone) - set_timezone "$@" - ;; - list-timezones) - list_timezones - ;; - set-local-rtc) - set_local_rtc "$@" - ;; - set-ntp) - set_ntp "$@" - ;; - ""|help|--help|-h) - print_usage - ;; - *) - echo "Unknown command: $cmd" - print_usage - exit 1 - ;; - esac + case "$cmd" in + status) + show_status + ;; + set-time) + set_time "$@" + ;; + set-timezone) + set_timezone "$@" + ;; + list-timezones) + list_timezones + ;; + set-local-rtc) + set_local_rtc "$@" + ;; + set-ntp) + set_ntp "$@" + ;; + "" | help | --help | -h) + print_usage + ;; + *) + echo "Unknown command: $cmd" + print_usage + exit 1 + ;; + esac } if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then - if [ $# -lt 1 ]; then - print_usage - exit 0 - fi - main "$@" + if [ $# -lt 1 ]; then + print_usage + exit 0 + fi + main "$@" fi diff --git a/calibre/rootfs/etc/cont-init.d/01-migrate.sh b/calibre/rootfs/etc/cont-init.d/01-migrate.sh index 82ba934bb..fae8b18b8 100755 --- a/calibre/rootfs/etc/cont-init.d/01-migrate.sh +++ b/calibre/rootfs/etc/cont-init.d/01-migrate.sh @@ -7,9 +7,9 @@ set -e #################### if [ -d /homeassistant/addons_config/calibre ]; then - echo "Moving database to new location /config" - cp -rf /homeassistant/addons_config/calibre/* /config/ - rm -r /homeassistant/addons_config/calibre + echo "Moving database to new location /config" + cp -rf /homeassistant/addons_config/calibre/* /config/ + rm -r /homeassistant/addons_config/calibre fi # Legacy path diff --git a/calibre/rootfs/etc/cont-init.d/20-folders.sh b/calibre/rootfs/etc/cont-init.d/20-folders.sh index 7df5f0617..3b9e2e2d6 100755 --- a/calibre/rootfs/etc/cont-init.d/20-folders.sh +++ b/calibre/rootfs/etc/cont-init.d/20-folders.sh @@ -11,23 +11,23 @@ PGID=$(bashio::config "PGID") LOCATION=$(bashio::config 'data_location') if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then - # Default location - LOCATION="/config" + # Default location + LOCATION="/config" 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" + 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 + # 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="/config" - 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 + if [ -z "$LOCATIONOK" ]; then + LOCATION="/config" + 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 @@ -36,29 +36,29 @@ 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 + 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|/config|$LOCATION|g" $(find "$folders" -type f) &>/dev/null || true - fi + if [ -d "$folders" ]; then + sed -i "s|/config|$LOCATION|g" $(find "$folders" -type f) &>/dev/null || true + 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 +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\n" "HOME=\"$LOCATION\"" - printf "%s\n" "FM_HOME=\"$LOCATION\"" -} >> ~/.bashrc + printf "%s\n" "HOME=\"$LOCATION\"" + printf "%s\n" "FM_HOME=\"$LOCATION\"" +} >>~/.bashrc # Create folder echo "Creating $LOCATION" diff --git a/calibre/rootfs/etc/cont-init.d/80-configuration.sh b/calibre/rootfs/etc/cont-init.d/80-configuration.sh index 2affd9e3f..6bce29c38 100755 --- a/calibre/rootfs/etc/cont-init.d/80-configuration.sh +++ b/calibre/rootfs/etc/cont-init.d/80-configuration.sh @@ -5,50 +5,50 @@ set -e # Install specific apps if bashio::config.has_value 'additional_apps'; then - bashio::log.info "Installing additional apps :" - # hadolint ignore=SC2005 - NEWAPPS=$(bashio::config 'additional_apps') - for packagestoinstall in ${NEWAPPS//,/ }; do - bashio::log.green "... $packagestoinstall" - if command -v "apk" &>/dev/null; then - apk add --no-cache "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") - elif command -v "apt" &>/dev/null; then - apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") - elif command -v "pacman" &>/dev/null; then - pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") - fi - done + bashio::log.info "Installing additional apps :" + # hadolint ignore=SC2005 + NEWAPPS=$(bashio::config 'additional_apps') + for packagestoinstall in ${NEWAPPS//,/ }; do + bashio::log.green "... $packagestoinstall" + if command -v "apk" &>/dev/null; then + apk add --no-cache "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") + elif command -v "apt" &>/dev/null; then + apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") + elif command -v "pacman" &>/dev/null; then + pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") + fi + done fi # Set TZ if bashio::config.has_value 'TZ'; then - TIMEZONE=$(bashio::config 'TZ') - bashio::log.info "Setting timezone to $TIMEZONE" - ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime - echo "$TIMEZONE" >/etc/timezone + TIMEZONE=$(bashio::config 'TZ') + bashio::log.info "Setting timezone to $TIMEZONE" + ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime + echo "$TIMEZONE" >/etc/timezone fi || (bashio::log.fatal "Error : $TIMEZONE not found. Here is a list of valid timezones : https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html") # Set cli args if bashio::config.has_value 'CLI_ARGS'; then - bashio::log.info "Setting password to the value defined in options" - CLI_ARGS=$(bashio::config 'CLI_ARGS') - bashio::log.info "Setting arguments to $CLI_ARGS" - if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CLI_ARGS" >/var/run/s6/container_environment/CLI_ARGS; fi - printf "%s\n" "CLI_ARGS=\"$CLI_ARGS\"" >>~/.bashrc + bashio::log.info "Setting password to the value defined in options" + CLI_ARGS=$(bashio::config 'CLI_ARGS') + bashio::log.info "Setting arguments to $CLI_ARGS" + if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CLI_ARGS" >/var/run/s6/container_environment/CLI_ARGS; fi + printf "%s\n" "CLI_ARGS=\"$CLI_ARGS\"" >>~/.bashrc fi || true # Set keyboard if bashio::config.has_value 'KEYBOARD'; then - KEYBOARD=$(bashio::config 'KEYBOARD') - bashio::log.info "Setting keyboard to $KEYBOARD" - if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" >/var/run/s6/container_environment/KEYBOARD; fi - printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >>~/.bashrc + KEYBOARD=$(bashio::config 'KEYBOARD') + bashio::log.info "Setting keyboard to $KEYBOARD" + if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" >/var/run/s6/container_environment/KEYBOARD; fi + printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >>~/.bashrc fi || true # Set password if bashio::config.has_value 'PASSWORD'; then - bashio::log.info "Setting password to the value defined in options" - PASSWORD=$(bashio::config 'PASSWORD') - passwd -d abc - echo -e "$PASSWORD\n$PASSWORD" | passwd abc + bashio::log.info "Setting password to the value defined in options" + PASSWORD=$(bashio::config 'PASSWORD') + passwd -d abc + echo -e "$PASSWORD\n$PASSWORD" | passwd abc fi || true diff --git a/calibre_web/rootfs/etc/cont-init.d/00-a_migrate.sh b/calibre_web/rootfs/etc/cont-init.d/00-a_migrate.sh index 9d91969f8..902491ceb 100755 --- a/calibre_web/rootfs/etc/cont-init.d/00-a_migrate.sh +++ b/calibre_web/rootfs/etc/cont-init.d/00-a_migrate.sh @@ -7,10 +7,9 @@ set -e #################### if [ -d /homeassistant/addons_config/calibre-web ] && [ ! -L /homeassistant/addons_config/calibre-web ]; then - if [ "$(ls -A /homeassistant/addons_config/calibre-web)" ]; then - echo "Moving database to new location /config" - cp -rf /homeassistant/addons_config/calibre-web/* "$LOCATION"/ - fi - rm -r /homeassistant/addons_config/calibre-web + if [ "$(ls -A /homeassistant/addons_config/calibre-web)" ]; then + echo "Moving database to new location /config" + cp -rf /homeassistant/addons_config/calibre-web/* "$LOCATION"/ + fi + rm -r /homeassistant/addons_config/calibre-web fi - diff --git a/calibre_web/rootfs/etc/cont-init.d/00-data_location.sh b/calibre_web/rootfs/etc/cont-init.d/00-data_location.sh index f06733191..896fc826d 100755 --- a/calibre_web/rootfs/etc/cont-init.d/00-data_location.sh +++ b/calibre_web/rootfs/etc/cont-init.d/00-data_location.sh @@ -10,23 +10,23 @@ PGID=$(bashio::config "PGID") LOCATION=$(bashio::config 'data_location') if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then - # Default location - LOCATION="/config" + # Default location + LOCATION="/config" 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" + 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 + # 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=/config - 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 + if [ -z "$LOCATIONOK" ]; then + LOCATION=/config + 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 @@ -37,10 +37,10 @@ sed -i "1a export FM_HOME=$LOCATION" /etc/services.d/*/run sed -i "s|/config|$LOCATION|g" /defaults/* sed -i "s|/config|$LOCATION|g" /etc/cont-init.d/* sed -i "s|/config|$LOCATION|g" /etc/services.d/*/run -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\n" "HOME=\"$LOCATION\"" >> ~/.bashrc -printf "%s\n" "FM_HOME=\"$LOCATION\"" >> ~/.bashrc +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\n" "HOME=\"$LOCATION\"" >>~/.bashrc +printf "%s\n" "FM_HOME=\"$LOCATION\"" >>~/.bashrc usermod --home "$LOCATION" abc diff --git a/calibre_web/rootfs/etc/cont-init.d/20-folders.sh b/calibre_web/rootfs/etc/cont-init.d/20-folders.sh index da450e78b..185bf9981 100755 --- a/calibre_web/rootfs/etc/cont-init.d/20-folders.sh +++ b/calibre_web/rootfs/etc/cont-init.d/20-folders.sh @@ -1,8 +1,8 @@ #!/bin/bash if [ ! -d /config ]; then - echo "Creating /config" - mkdir -p /config + echo "Creating /config" + mkdir -p /config fi chown -R "$PUID:$PGID" /config diff --git a/calibre_web/rootfs/etc/cont-init.d/31-correct_smb.sh b/calibre_web/rootfs/etc/cont-init.d/31-correct_smb.sh index 53d4711ba..24ea8470a 100755 --- a/calibre_web/rootfs/etc/cont-init.d/31-correct_smb.sh +++ b/calibre_web/rootfs/etc/cont-init.d/31-correct_smb.sh @@ -1,5 +1,5 @@ #!/bin/bash if [ -f /etc/cont-init.d/00-smb_mounts.sh ]; then - sed -i "s|cifs -o \"|cifs -o \"nobrl,|g" /etc/cont-init.d/00-smb_mounts.sh + sed -i "s|cifs -o \"|cifs -o \"nobrl,|g" /etc/cont-init.d/00-smb_mounts.sh fi diff --git a/calibre_web/rootfs/etc/cont-init.d/32-nginx.sh b/calibre_web/rootfs/etc/cont-init.d/32-nginx.sh index 69a4bd22b..e17c021cc 100755 --- a/calibre_web/rootfs/etc/cont-init.d/32-nginx.sh +++ b/calibre_web/rootfs/etc/cont-init.d/32-nginx.sh @@ -42,7 +42,7 @@ declare ingress_port ingress_user='admin' if bashio::config.has_value 'ingress_user'; then - ingress_user=$(bashio::config 'ingress_user') + ingress_user=$(bashio::config 'ingress_user') fi ingress_port=$(bashio::addon.ingress_port) diff --git a/calibre_web/rootfs/etc/cont-init.d/80-configuration.sh b/calibre_web/rootfs/etc/cont-init.d/80-configuration.sh index 1dca6cb8d..21f488c34 100755 --- a/calibre_web/rootfs/etc/cont-init.d/80-configuration.sh +++ b/calibre_web/rootfs/etc/cont-init.d/80-configuration.sh @@ -5,9 +5,9 @@ set -e # Set TZ if bashio::config.has_value 'TZ'; then - TIMEZONE=$(bashio::config 'TZ') - bashio::log.info "Setting timezone to $TIMEZONE" - ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime && echo "$TIMEZONE" >/etc/timezone + TIMEZONE=$(bashio::config 'TZ') + bashio::log.info "Setting timezone to $TIMEZONE" + ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime && echo "$TIMEZONE" >/etc/timezone fi bashio::log.info "Install libnss3" @@ -15,9 +15,9 @@ apt-get update && apt-get install libnss3 &>/dev/null # Set Ingress login if [ ! -f /config/app.db ]; then - bashio::log.warning "First boot : disabling Ingress until addon restart" + bashio::log.warning "First boot : disabling Ingress until addon restart" else - sqlite3 /config/app.db 'update settings set config_reverse_proxy_login_header_name="X-WebAuth-User",config_allow_reverse_proxy_header_login=1' + sqlite3 /config/app.db 'update settings set config_reverse_proxy_login_header_name="X-WebAuth-User",config_allow_reverse_proxy_header_login=1' fi bashio::log.info "Default username:password is admin:admin123" diff --git a/cloudcommander/rootfs/etc/cont-init.d/99-run.sh b/cloudcommander/rootfs/etc/cont-init.d/99-run.sh index d6764fcae..3d7fe706c 100755 --- a/cloudcommander/rootfs/etc/cont-init.d/99-run.sh +++ b/cloudcommander/rootfs/etc/cont-init.d/99-run.sh @@ -7,9 +7,9 @@ set -e #################### if [ -f /homeassistant/addons_config/cloudcommander ]; then - echo "Moving database to new location /config" - cp -rnf /homeassistant/addons_config/cloudcommander/* /config/ || true - rm -r /homeassistant/addons_config/cloudcommander + echo "Moving database to new location /config" + cp -rnf /homeassistant/addons_config/cloudcommander/* /config/ || true + rm -r /homeassistant/addons_config/cloudcommander fi ###################### @@ -22,12 +22,12 @@ find /homeassistant/addons_config -maxdepth 1 -type l -delete # Remove erroneous folders if [ -d /homeassistant ]; then - if [ -d /config/addons_config ]; then - rm -r /config/addons_config - fi - if [ -d /config/addons_autoscripts ]; then - rm -r /config/addons_autoscripts - fi + if [ -d /config/addons_config ]; then + rm -r /config/addons_config + fi + if [ -d /config/addons_autoscripts ]; then + rm -r /config/addons_autoscripts + fi fi # Create symlinks @@ -50,8 +50,8 @@ export CLOUDCMD_PREFIX declare ADDON_PROTOCOL=http if bashio::config.true 'ssl'; then - ADDON_PROTOCOL=https - bashio::config.require.ssl + ADDON_PROTOCOL=https + bashio::config.require.ssl fi # port=$(bashio::addon.port 80) @@ -68,15 +68,15 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log ############### if bashio::config.has_value 'CUSTOM_OPTIONS'; then - CUSTOMOPTIONS=" $(bashio::config 'CUSTOM_OPTIONS')" + CUSTOMOPTIONS=" $(bashio::config 'CUSTOM_OPTIONS')" else - CUSTOMOPTIONS="" + CUSTOMOPTIONS="" fi if bashio::config.has_value 'DROPBOX_TOKEN'; then - DROPBOX_TOKEN="--dropbox --dropbox-token $(bashio::config 'DROPBOX_TOKEN')" + DROPBOX_TOKEN="--dropbox --dropbox-token $(bashio::config 'DROPBOX_TOKEN')" else - DROPBOX_TOKEN="" + DROPBOX_TOKEN="" fi bashio::log.info "Starting..." diff --git a/codex/rootfs/etc/cont-init.d/91-csrf.sh b/codex/rootfs/etc/cont-init.d/91-csrf.sh index 58276cb3c..5752e70b9 100755 --- a/codex/rootfs/etc/cont-init.d/91-csrf.sh +++ b/codex/rootfs/etc/cont-init.d/91-csrf.sh @@ -19,39 +19,39 @@ urls+=("$(bashio::jq "$result" '.external_url' | cut -d'/' -f3 | cut -d':' -f1)" # Get supported interfaces for interface in $(bashio::network.interfaces); do - urls+=("$(bashio::network.ipv6_address "${interface}" | cut -d'/' -f1)") - urls+=("$(bashio::network.ipv4_address "${interface}" | cut -d'/' -f1)") + urls+=("$(bashio::network.ipv6_address "${interface}" | cut -d'/' -f1)") + urls+=("$(bashio::network.ipv4_address "${interface}" | cut -d'/' -f1)") done if bashio::config.has_value 'csrf_allowed'; then - bashio::log.info "Setup manually defined ALLOWED_CSRF domains" + bashio::log.info "Setup manually defined ALLOWED_CSRF domains" - while read -r line; do - urls+=("$line") - done <<< "$(bashio::config 'csrf_allowed')" + while read -r line; do + urls+=("$line") + done <<<"$(bashio::config 'csrf_allowed')" fi # Add internal and external URL as it if [[ "$(bashio::jq "$result" '.external_url')" != "null" ]]; then - CSRF=$(bashio::jq "$result" '.external_url') + CSRF=$(bashio::jq "$result" '.external_url') fi if [[ "$(bashio::jq "$result" '.internal_url')" != "null" ]]; then - CSRF=$(bashio::jq "$result" '.internal_url'),${CSRF} + CSRF=$(bashio::jq "$result" '.internal_url'),${CSRF} fi # Loop through URls to add them in the CSRF string for url in "${urls[@]}"; do - if bashio::var.has_value "${url}"; then - if [[ "${url}" != "null" ]] && [[ "${url}" != "null.local" ]]; then - CSRF="https://${url}:${port},http://${url}:${port},https://${url},http://${url}",${CSRF} - if bashio::var.has_value "$(bashio::addon.port 9810)"; then - CSRF="https://${url}:${addon_port},http://${url}:${addon_port}",${CSRF} - fi - fi - fi + if bashio::var.has_value "${url}"; then + if [[ "${url}" != "null" ]] && [[ "${url}" != "null.local" ]]; then + CSRF="https://${url}:${port},http://${url}:${port},https://${url},http://${url}",${CSRF} + if bashio::var.has_value "$(bashio::addon.port 9810)"; then + CSRF="https://${url}:${addon_port},http://${url}:${addon_port}",${CSRF} + fi + fi + fi done CSRF=${CSRF::-1} # Save CSFR -echo -n "${CSRF}" > /var/run/s6/container_environment/PAPERLESS_CSRF_TRUSTED_ORIGINS +echo -n "${CSRF}" >/var/run/s6/container_environment/PAPERLESS_CSRF_TRUSTED_ORIGINS bashio::log.blue "PAPERLESS_CSRF_TRUSTED_ORIGINS is set to ${CSRF}" diff --git a/codex/rootfs/etc/cont-init.d/99-run.sh b/codex/rootfs/etc/cont-init.d/99-run.sh index 9dcfbcc1d..0859f7cea 100755 --- a/codex/rootfs/etc/cont-init.d/99-run.sh +++ b/codex/rootfs/etc/cont-init.d/99-run.sh @@ -6,14 +6,14 @@ ############ if bashio::config.has_value 'TZ'; then - TIMEZONE=$(bashio::config 'TZ') - bashio::log.info "Setting timezone to $TIMEZONE" - if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then - ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime - echo "$TIMEZONE" >/etc/timezone - else - bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" - fi + TIMEZONE=$(bashio::config 'TZ') + bashio::log.info "Setting timezone to $TIMEZONE" + if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then + ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime + echo "$TIMEZONE" >/etc/timezone + else + bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" + fi fi ################# @@ -32,7 +32,7 @@ export FB_BASEURL declare ADDON_PROTOCOL=http # Generate Ingress configuration if bashio::config.true 'ssl'; then - ADDON_PROTOCOL=https + ADDON_PROTOCOL=https fi #port=$(bashio::addon.port 80) @@ -46,10 +46,10 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log # Correct baseurl for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do - if [ -f "$file" ]; then - sed -i "/root_path/d" "$file" - sed -i "1a root_path = \"${FB_BASEURL}\"" "$file" - fi + if [ -f "$file" ]; then + sed -i "/root_path/d" "$file" + sed -i "1a root_path = \"${FB_BASEURL}\"" "$file" + fi done ############## @@ -60,7 +60,8 @@ bashio::log.warning "Default password admin:admin..." bashio::log.info "Starting..." # shellcheck disable=SC2086 -/./usr/local/bin/codex & true +/./usr/local/bin/codex & +true bashio::net.wait_for 9810 localhost 900 || true bashio::log.info "Started !" diff --git a/comixed/rootfs/etc/cont-init.d/99-run.sh b/comixed/rootfs/etc/cont-init.d/99-run.sh index f051bb839..7dddb7d31 100755 --- a/comixed/rootfs/etc/cont-init.d/99-run.sh +++ b/comixed/rootfs/etc/cont-init.d/99-run.sh @@ -6,14 +6,14 @@ ############ if bashio::config.has_value 'TZ'; then - TIMEZONE=$(bashio::config 'TZ') - bashio::log.info "Setting timezone to $TIMEZONE" - if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then - ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime - echo "$TIMEZONE" >/etc/timezone - else - bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" - fi + TIMEZONE=$(bashio::config 'TZ') + bashio::log.info "Setting timezone to $TIMEZONE" + if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then + ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime + echo "$TIMEZONE" >/etc/timezone + else + bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" + fi fi ################# @@ -22,37 +22,37 @@ fi INGRESS="false" if [[ "$INGRESS" == "true" ]]; then - #declare port - #declare certfile - declare ingress_interface - declare ingress_port - #declare keyfile - - FB_BASEURL="$(bashio::addon.ingress_entry)" - export FB_BASEURL - - declare ADDON_PROTOCOL=http - # Generate Ingress configuration - if bashio::config.true 'ssl'; then - ADDON_PROTOCOL=https - fi - - #port=$(bashio::addon.port 80) - ingress_port=$(bashio::addon.ingress_port) - ingress_interface=$(bashio::addon.ip_address) - sed -i "s|%%protocol%%|${ADDON_PROTOCOL}|g" /etc/nginx/servers/ingress.conf - sed -i "s|%%port%%|${ingress_port}|g" /etc/nginx/servers/ingress.conf - sed -i "s|%%interface%%|${ingress_interface}|g" /etc/nginx/servers/ingress.conf - sed -i "s|%%subpath%%|${FB_BASEURL}/|g" /etc/nginx/servers/ingress.conf - mkdir -p /var/log/nginx && touch /var/log/nginx/error.log - - # Correct baseurl - for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do - if [ -f "$file" ]; then - sed -i "/root_path/d" "$file" - sed -i "1a root_path = \"${FB_BASEURL}\"" "$file" - fi - done + #declare port + #declare certfile + declare ingress_interface + declare ingress_port + #declare keyfile + + FB_BASEURL="$(bashio::addon.ingress_entry)" + export FB_BASEURL + + declare ADDON_PROTOCOL=http + # Generate Ingress configuration + if bashio::config.true 'ssl'; then + ADDON_PROTOCOL=https + fi + + #port=$(bashio::addon.port 80) + ingress_port=$(bashio::addon.ingress_port) + ingress_interface=$(bashio::addon.ip_address) + sed -i "s|%%protocol%%|${ADDON_PROTOCOL}|g" /etc/nginx/servers/ingress.conf + sed -i "s|%%port%%|${ingress_port}|g" /etc/nginx/servers/ingress.conf + sed -i "s|%%interface%%|${ingress_interface}|g" /etc/nginx/servers/ingress.conf + sed -i "s|%%subpath%%|${FB_BASEURL}/|g" /etc/nginx/servers/ingress.conf + mkdir -p /var/log/nginx && touch /var/log/nginx/error.log + + # Correct baseurl + for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do + if [ -f "$file" ]; then + sed -i "/root_path/d" "$file" + sed -i "1a root_path = \"${FB_BASEURL}\"" "$file" + fi + done fi ########### diff --git a/emby/rootfs/etc/cont-init.d/20-folders.sh b/emby/rootfs/etc/cont-init.d/20-folders.sh index d40e82ba2..db1f7fa07 100755 --- a/emby/rootfs/etc/cont-init.d/20-folders.sh +++ b/emby/rootfs/etc/cont-init.d/20-folders.sh @@ -5,52 +5,52 @@ set -e data_location="${data_location:-/share/emby}" config_location="/config/emby" log() { - bashio::log.info "$1" + bashio::log.info "$1" } log "Updating folder structure and permission : data stored in $data_location" declare -A directories=( - ["/emby"]="" - ["/share/storage/tv"]="" - ["/share/storage/movies"]="" - ["$data_location"]="" - ["$config_location"]="" + ["/emby"]="" + ["/share/storage/tv"]="" + ["/share/storage/movies"]="" + ["$data_location"]="" + ["$config_location"]="" ) for dir in "${!directories[@]}"; do - log "Creating directory: $dir" - mkdir -p "$dir" - chown -R "$PUID:$PGID" "$dir" + log "Creating directory: $dir" + mkdir -p "$dir" + chown -R "$PUID:$PGID" "$dir" done if [ -d /homeassistant/emby ]; then - log "Migrate previous config location" - cp -rf /homeassistant/emby/* "$config_location"/ - mv /homeassistant/emby /homeassistant/emby_migrated - chown -R "$PUID:$PGID" "$config_location" + log "Migrate previous config location" + cp -rf /homeassistant/emby/* "$config_location"/ + mv /homeassistant/emby /homeassistant/emby_migrated + chown -R "$PUID:$PGID" "$config_location" fi if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then - cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/ - mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh + cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/ + mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh fi declare -A links=( - ["/emby/cache"]="$data_location/cache" - ["/emby/config"]="$config_location" - ["/emby/data"]="$data_location/data" - ["/emby/logs"]="$data_location/logs" - ["/emby/metadata"]="$data_location/metadata" - ["/emby/plugins"]="$data_location/plugins" - ["/emby/root"]="$data_location/root" + ["/emby/cache"]="$data_location/cache" + ["/emby/config"]="$config_location" + ["/emby/data"]="$data_location/data" + ["/emby/logs"]="$data_location/logs" + ["/emby/metadata"]="$data_location/metadata" + ["/emby/plugins"]="$data_location/plugins" + ["/emby/root"]="$data_location/root" ) for link in "${!links[@]}"; do - if [ ! -d "$link" ]; then - log "Creating link for $link" - mkdir -p "${links[$link]}" - chown -R "$PUID:$PGID" "${links[$link]}" - ln -s "${links[$link]}" "$link" - fi + if [ ! -d "$link" ]; then + log "Creating link for $link" + mkdir -p "${links[$link]}" + chown -R "$PUID:$PGID" "${links[$link]}" + ln -s "${links[$link]}" "$link" + fi done diff --git a/emby/rootfs/etc/cont-init.d/91-silent.sh b/emby/rootfs/etc/cont-init.d/91-silent.sh index d9d6c4a86..da63fe452 100755 --- a/emby/rootfs/etc/cont-init.d/91-silent.sh +++ b/emby/rootfs/etc/cont-init.d/91-silent.sh @@ -7,7 +7,7 @@ set -e ############### if bashio::config.true 'silent'; then - APPEND=' >/dev/null' - sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run - bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.' + APPEND=' >/dev/null' + sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run + bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.' fi diff --git a/emby_beta/rootfs/etc/cont-init.d/20-folders.sh b/emby_beta/rootfs/etc/cont-init.d/20-folders.sh index d40e82ba2..db1f7fa07 100755 --- a/emby_beta/rootfs/etc/cont-init.d/20-folders.sh +++ b/emby_beta/rootfs/etc/cont-init.d/20-folders.sh @@ -5,52 +5,52 @@ set -e data_location="${data_location:-/share/emby}" config_location="/config/emby" log() { - bashio::log.info "$1" + bashio::log.info "$1" } log "Updating folder structure and permission : data stored in $data_location" declare -A directories=( - ["/emby"]="" - ["/share/storage/tv"]="" - ["/share/storage/movies"]="" - ["$data_location"]="" - ["$config_location"]="" + ["/emby"]="" + ["/share/storage/tv"]="" + ["/share/storage/movies"]="" + ["$data_location"]="" + ["$config_location"]="" ) for dir in "${!directories[@]}"; do - log "Creating directory: $dir" - mkdir -p "$dir" - chown -R "$PUID:$PGID" "$dir" + log "Creating directory: $dir" + mkdir -p "$dir" + chown -R "$PUID:$PGID" "$dir" done if [ -d /homeassistant/emby ]; then - log "Migrate previous config location" - cp -rf /homeassistant/emby/* "$config_location"/ - mv /homeassistant/emby /homeassistant/emby_migrated - chown -R "$PUID:$PGID" "$config_location" + log "Migrate previous config location" + cp -rf /homeassistant/emby/* "$config_location"/ + mv /homeassistant/emby /homeassistant/emby_migrated + chown -R "$PUID:$PGID" "$config_location" fi if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then - cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/ - mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh + cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/ + mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh fi declare -A links=( - ["/emby/cache"]="$data_location/cache" - ["/emby/config"]="$config_location" - ["/emby/data"]="$data_location/data" - ["/emby/logs"]="$data_location/logs" - ["/emby/metadata"]="$data_location/metadata" - ["/emby/plugins"]="$data_location/plugins" - ["/emby/root"]="$data_location/root" + ["/emby/cache"]="$data_location/cache" + ["/emby/config"]="$config_location" + ["/emby/data"]="$data_location/data" + ["/emby/logs"]="$data_location/logs" + ["/emby/metadata"]="$data_location/metadata" + ["/emby/plugins"]="$data_location/plugins" + ["/emby/root"]="$data_location/root" ) for link in "${!links[@]}"; do - if [ ! -d "$link" ]; then - log "Creating link for $link" - mkdir -p "${links[$link]}" - chown -R "$PUID:$PGID" "${links[$link]}" - ln -s "${links[$link]}" "$link" - fi + if [ ! -d "$link" ]; then + log "Creating link for $link" + mkdir -p "${links[$link]}" + chown -R "$PUID:$PGID" "${links[$link]}" + ln -s "${links[$link]}" "$link" + fi done diff --git a/emby_beta/rootfs/etc/cont-init.d/91-silent.sh b/emby_beta/rootfs/etc/cont-init.d/91-silent.sh index d9d6c4a86..da63fe452 100755 --- a/emby_beta/rootfs/etc/cont-init.d/91-silent.sh +++ b/emby_beta/rootfs/etc/cont-init.d/91-silent.sh @@ -7,7 +7,7 @@ set -e ############### if bashio::config.true 'silent'; then - APPEND=' >/dev/null' - sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run - bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.' + APPEND=' >/dev/null' + sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run + bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.' fi diff --git a/enedisgateway2mqtt/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh b/enedisgateway2mqtt/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh index 617bff405..98fa2cf71 100755 --- a/enedisgateway2mqtt/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh +++ b/enedisgateway2mqtt/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh @@ -8,21 +8,21 @@ set -e ##################### if bashio::config.true 'mqtt_autodiscover'; then - bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." - # Check if available - if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi - # Get variables - bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." - export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'" - export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'" - export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'" - export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'" - export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'" + bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." + # Check if available + if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi + # Get variables + bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." + export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'" + export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'" + export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'" + export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'" + export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'" - # Export variables - for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do - sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2>/dev/null || true - # Log - bashio::log.blue "$variables" - done + # Export variables + for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do + sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2>/dev/null || true + # Log + bashio::log.blue "$variables" + done fi diff --git a/enedisgateway2mqtt/rootfs/etc/cont-init.d/99-run.sh b/enedisgateway2mqtt/rootfs/etc/cont-init.d/99-run.sh index fde70b04c..9ed04d958 100755 --- a/enedisgateway2mqtt/rootfs/etc/cont-init.d/99-run.sh +++ b/enedisgateway2mqtt/rootfs/etc/cont-init.d/99-run.sh @@ -10,7 +10,7 @@ set -e CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") # Check CONFIGSOURCE ends with config.yaml if [ "$(basename "$CONFIGSOURCE")" != "config.yaml" ]; then - bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")" + bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")" fi DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db" @@ -22,8 +22,8 @@ chmod 777 -R "$(dirname "${DATABASESOURCE}")" # Check absence of config file if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then - bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak" - mv /data/config.yaml "$CONFIGSOURCE".bak + bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak" + mv /data/config.yaml "$CONFIGSOURCE".bak fi ######################################################### @@ -31,24 +31,24 @@ fi ######################################################### if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then - mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/ - rm -r /config/addons_config/enedisgateway2mqtt_dev + mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/ + rm -r /config/addons_config/enedisgateway2mqtt_dev fi # If migration was performed, save file in config folder if [ -f /data/enedisgateway.db.migrate ]; then - bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")" - mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")" + bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")" + mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")" fi # If migration was performed, save file in config folder if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then - mv /data/cache.db "$(dirname "${CONFIGSOURCE}")" + mv /data/cache.db "$(dirname "${CONFIGSOURCE}")" fi # If migration was not performed, enable migration if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then - mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data + mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data fi ############ @@ -57,15 +57,15 @@ fi # Check if database is here or create symlink if [ -f "$DATABASESOURCE" ]; then - # Create symlink if not existing yet - ln -sf "${DATABASESOURCE}" /data && echo "creating symlink" - bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")" + # Create symlink if not existing yet + ln -sf "${DATABASESOURCE}" /data && echo "creating symlink" + bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")" else - # Create symlink for addon to create database - mkdir -p "$(dirname "$DATABASESOURCE")" - touch "${DATABASESOURCE}" - ln -sf "$DATABASESOURCE" /data - rm "$DATABASESOURCE" + # Create symlink for addon to create database + mkdir -p "$(dirname "$DATABASESOURCE")" + touch "${DATABASESOURCE}" + ln -sf "$DATABASESOURCE" /data + rm "$DATABASESOURCE" fi ########## @@ -74,35 +74,36 @@ fi # Check if config file is there, or create one from template if [ -f "$CONFIGSOURCE" ]; then - # Create symlink if not existing yet - # shellcheck disable=SC2015 - [ -f /data/config.yaml ] && rm /data/config.yaml || true - ln -sf "$CONFIGSOURCE" /data || true - bashio::log.info "Using config file found in $CONFIGSOURCE" + # Create symlink if not existing yet + # shellcheck disable=SC2015 + [ -f /data/config.yaml ] && rm /data/config.yaml || true + ln -sf "$CONFIGSOURCE" /data || true + bashio::log.info "Using config file found in $CONFIGSOURCE" - # Check if yaml is valid - EXIT_CODE=0 - yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$? - if [ "$EXIT_CODE" = 0 ]; then - echo "Config file is a valid yaml" - else - cat ERROR - bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com" - fi + # Check if yaml is valid + EXIT_CODE=0 + yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$? + if [ "$EXIT_CODE" = 0 ]; then + echo "Config file is a valid yaml" + else + cat ERROR + bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com" + fi else - # Create symlink for addon to create config - cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/ - ln -sf "$CONFIGSOURCE" /data - rm "$CONFIGSOURCE" - # Need to restart - bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting." + # Create symlink for addon to create config + cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/ + ln -sf "$CONFIGSOURCE" /data + rm "$CONFIGSOURCE" + # Need to restart + bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting." fi ############## # Launch App # ############## echo " " -nginx & bashio::log.info "Starting nginx" +nginx & +bashio::log.info "Starting nginx" echo " " bashio::log.info "Starting the app" echo " " diff --git a/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh b/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh index 617bff405..98fa2cf71 100755 --- a/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh +++ b/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/91-mqtt_autodiscover.sh @@ -8,21 +8,21 @@ set -e ##################### if bashio::config.true 'mqtt_autodiscover'; then - bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." - # Check if available - if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi - # Get variables - bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." - export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'" - export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'" - export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'" - export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'" - export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'" + bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." + # Check if available + if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi + # Get variables + bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." + export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'" + export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'" + export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'" + export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'" + export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'" - # Export variables - for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do - sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2>/dev/null || true - # Log - bashio::log.blue "$variables" - done + # Export variables + for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do + sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2>/dev/null || true + # Log + bashio::log.blue "$variables" + done fi diff --git a/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/99-run.sh b/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/99-run.sh index fde70b04c..9ed04d958 100755 --- a/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/99-run.sh +++ b/enedisgateway2mqtt_dev/rootfs/etc/cont-init.d/99-run.sh @@ -10,7 +10,7 @@ set -e CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") # Check CONFIGSOURCE ends with config.yaml if [ "$(basename "$CONFIGSOURCE")" != "config.yaml" ]; then - bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")" + bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")" fi DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db" @@ -22,8 +22,8 @@ chmod 777 -R "$(dirname "${DATABASESOURCE}")" # Check absence of config file if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then - bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak" - mv /data/config.yaml "$CONFIGSOURCE".bak + bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak" + mv /data/config.yaml "$CONFIGSOURCE".bak fi ######################################################### @@ -31,24 +31,24 @@ fi ######################################################### if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then - mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/ - rm -r /config/addons_config/enedisgateway2mqtt_dev + mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/ + rm -r /config/addons_config/enedisgateway2mqtt_dev fi # If migration was performed, save file in config folder if [ -f /data/enedisgateway.db.migrate ]; then - bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")" - mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")" + bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")" + mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")" fi # If migration was performed, save file in config folder if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then - mv /data/cache.db "$(dirname "${CONFIGSOURCE}")" + mv /data/cache.db "$(dirname "${CONFIGSOURCE}")" fi # If migration was not performed, enable migration if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then - mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data + mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data fi ############ @@ -57,15 +57,15 @@ fi # Check if database is here or create symlink if [ -f "$DATABASESOURCE" ]; then - # Create symlink if not existing yet - ln -sf "${DATABASESOURCE}" /data && echo "creating symlink" - bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")" + # Create symlink if not existing yet + ln -sf "${DATABASESOURCE}" /data && echo "creating symlink" + bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")" else - # Create symlink for addon to create database - mkdir -p "$(dirname "$DATABASESOURCE")" - touch "${DATABASESOURCE}" - ln -sf "$DATABASESOURCE" /data - rm "$DATABASESOURCE" + # Create symlink for addon to create database + mkdir -p "$(dirname "$DATABASESOURCE")" + touch "${DATABASESOURCE}" + ln -sf "$DATABASESOURCE" /data + rm "$DATABASESOURCE" fi ########## @@ -74,35 +74,36 @@ fi # Check if config file is there, or create one from template if [ -f "$CONFIGSOURCE" ]; then - # Create symlink if not existing yet - # shellcheck disable=SC2015 - [ -f /data/config.yaml ] && rm /data/config.yaml || true - ln -sf "$CONFIGSOURCE" /data || true - bashio::log.info "Using config file found in $CONFIGSOURCE" + # Create symlink if not existing yet + # shellcheck disable=SC2015 + [ -f /data/config.yaml ] && rm /data/config.yaml || true + ln -sf "$CONFIGSOURCE" /data || true + bashio::log.info "Using config file found in $CONFIGSOURCE" - # Check if yaml is valid - EXIT_CODE=0 - yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$? - if [ "$EXIT_CODE" = 0 ]; then - echo "Config file is a valid yaml" - else - cat ERROR - bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com" - fi + # Check if yaml is valid + EXIT_CODE=0 + yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$? + if [ "$EXIT_CODE" = 0 ]; then + echo "Config file is a valid yaml" + else + cat ERROR + bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com" + fi else - # Create symlink for addon to create config - cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/ - ln -sf "$CONFIGSOURCE" /data - rm "$CONFIGSOURCE" - # Need to restart - bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting." + # Create symlink for addon to create config + cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/ + ln -sf "$CONFIGSOURCE" /data + rm "$CONFIGSOURCE" + # Need to restart + bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting." fi ############## # Launch App # ############## echo " " -nginx & bashio::log.info "Starting nginx" +nginx & +bashio::log.info "Starting nginx" echo " " bashio::log.info "Starting the app" echo " " diff --git a/epicgamesfree/rootfs/etc/cont-init.d/99-run.sh b/epicgamesfree/rootfs/etc/cont-init.d/99-run.sh index ab37fd9e5..3adfeeacb 100755 --- a/epicgamesfree/rootfs/etc/cont-init.d/99-run.sh +++ b/epicgamesfree/rootfs/etc/cont-init.d/99-run.sh @@ -8,14 +8,14 @@ set -e HOME="/config/addons_config/epicgamesfree" if [ ! -f "$HOME"/config.json ]; then - # Copy default config.json - cp /templates/config.json "$HOME"/config.json - chmod 777 "$HOME"/config.json - bashio::log.warning "A default config.json file was copied in $HOME. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on" - sleep 5 - bashio::exit.nok + # Copy default config.json + cp /templates/config.json "$HOME"/config.json + chmod 777 "$HOME"/config.json + bashio::log.warning "A default config.json file was copied in $HOME. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on" + sleep 5 + bashio::exit.nok else - bashio::log.warning "The config.json file found in $HOME will be used. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on" + bashio::log.warning "The config.json file found in $HOME will be used. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on" fi # Permissions diff --git a/filebrowser/rootfs/etc/cont-init.d/20-folders.sh b/filebrowser/rootfs/etc/cont-init.d/20-folders.sh index 37e54308b..63361e185 100755 --- a/filebrowser/rootfs/etc/cont-init.d/20-folders.sh +++ b/filebrowser/rootfs/etc/cont-init.d/20-folders.sh @@ -7,9 +7,9 @@ set -e #################### if [ -f /homeassistant/addons_config/filebrowser/filebrowser.dB ]; then - echo "Moving database to new location /config" - cp -rnf /homeassistant/addons_config/filebrowser/* /config/ - rm -r /homeassistant/addons_config/filebrowser + echo "Moving database to new location /config" + cp -rnf /homeassistant/addons_config/filebrowser/* /config/ + rm -r /homeassistant/addons_config/filebrowser fi ###################### @@ -19,24 +19,24 @@ fi # Clean symlinks find /config -maxdepth 1 -type l -delete if [ -d /homeassistant/addons_config ]; then - find /homeassistant/addons_config -maxdepth 1 -type l -delete + find /homeassistant/addons_config -maxdepth 1 -type l -delete fi # Remove erroneous folders if [ -d /homeassistant ]; then - if [ -d /config/addons_config ]; then - rm -r /config/addons_config - fi - if [ -d /config/addons_autoscripts ]; then - rm -r /config/addons_autoscripts - fi + if [ -d /config/addons_config ]; then + rm -r /config/addons_config + fi + if [ -d /config/addons_autoscripts ]; then + rm -r /config/addons_autoscripts + fi fi # Create symlinks with legacy folders if [ -d /homeassistant/addons_config ]; then - ln -s /homeassistant/addons_config /config - find /addon_configs/ -maxdepth 1 -mindepth 1 -type d -not -name "*filebrowser*" -exec ln -s {} /config/addons_config/ \; + ln -s /homeassistant/addons_config /config + find /addon_configs/ -maxdepth 1 -mindepth 1 -type d -not -name "*filebrowser*" -exec ln -s {} /config/addons_config/ \; fi if [ -d /homeassistant/addons_autoscripts ]; then - ln -s /homeassistant/addons_autoscripts /config + ln -s /homeassistant/addons_autoscripts /config fi diff --git a/filebrowser/rootfs/etc/cont-init.d/99-run.sh b/filebrowser/rootfs/etc/cont-init.d/99-run.sh index c1760d196..162d219de 100755 --- a/filebrowser/rootfs/etc/cont-init.d/99-run.sh +++ b/filebrowser/rootfs/etc/cont-init.d/99-run.sh @@ -7,14 +7,14 @@ set -e ############ if bashio::config.has_value 'TZ'; then - TIMEZONE=$(bashio::config 'TZ') - bashio::log.info "Setting timezone to $TIMEZONE" - if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then - ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime - echo "$TIMEZONE" >/etc/timezone - else - bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" - fi + TIMEZONE=$(bashio::config 'TZ') + bashio::log.info "Setting timezone to $TIMEZONE" + if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then + ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime + echo "$TIMEZONE" >/etc/timezone + else + bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" + fi fi ################### @@ -23,13 +23,13 @@ fi bashio::config.require.ssl if bashio::config.true 'ssl'; then - bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths" - #set variables - CERTFILE="-t /ssl/$(bashio::config 'certfile')" - KEYFILE="-k /ssl/$(bashio::config 'keyfile')" + bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths" + #set variables + CERTFILE="-t /ssl/$(bashio::config 'certfile')" + KEYFILE="-k /ssl/$(bashio::config 'keyfile')" else - CERTFILE="" - KEYFILE="" + CERTFILE="" + KEYFILE="" fi ################# @@ -48,7 +48,7 @@ export FB_BASEURL declare ADDON_PROTOCOL=http # Generate Ingress configuration if bashio::config.true 'ssl'; then - ADDON_PROTOCOL=https + ADDON_PROTOCOL=https fi #port=$(bashio::addon.port 80) @@ -67,41 +67,41 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log NOAUTH="" if bashio::config.true 'NoAuth'; then - if ! bashio::fs.file_exists "/data/noauth"; then - rm /data/auth &>/dev/null || true - rm /config/filebrowser.dB &>/dev/null || true - touch /data/noauth - NOAUTH="--noauth" - bashio::log.warning "Auth method change, database reset" - fi - bashio::log.info "NoAuth option selected" + if ! bashio::fs.file_exists "/data/noauth"; then + rm /data/auth &>/dev/null || true + rm /config/filebrowser.dB &>/dev/null || true + touch /data/noauth + NOAUTH="--noauth" + bashio::log.warning "Auth method change, database reset" + fi + bashio::log.info "NoAuth option selected" else - if ! bashio::fs.file_exists "/data/auth"; then - rm /data/noauth &>/dev/null || true - rm /config/filebrowser.dB &>/dev/null || true - touch /data/auth - bashio::log.warning "Auth method change, database reset" - fi - bashio::log.info "Default username/password : admin/admin" + if ! bashio::fs.file_exists "/data/auth"; then + rm /data/noauth &>/dev/null || true + rm /config/filebrowser.dB &>/dev/null || true + touch /data/auth + bashio::log.warning "Auth method change, database reset" + fi + bashio::log.info "Default username/password : admin/admin" fi # Set base folder if bashio::config.has_value 'base_folder'; then - BASE_FOLDER=$(bashio::config 'base_folder') + BASE_FOLDER=$(bashio::config 'base_folder') else - BASE_FOLDER=/ + BASE_FOLDER=/ fi # Disable thumbnails if bashio::config.true 'disable_thumbnails'; then - DISABLE_THUMBNAILS="--disable-thumbnails" + DISABLE_THUMBNAILS="--disable-thumbnails" else - DISABLE_THUMBNAILS="" + DISABLE_THUMBNAILS="" fi # Remove configuration file if [ -f /.filebrowser.json ]; then - rm /.filebrowser.json + rm /.filebrowser.json fi bashio::log.info "Starting..." diff --git a/fireflyiii/rootfs/etc/cont-init.d/99-run.sh b/fireflyiii/rootfs/etc/cont-init.d/99-run.sh index f2246d87a..8ef6f50a4 100755 --- a/fireflyiii/rootfs/etc/cont-init.d/99-run.sh +++ b/fireflyiii/rootfs/etc/cont-init.d/99-run.sh @@ -12,8 +12,8 @@ APP_KEY="$(bashio::config 'APP_KEY')" # If not base64 if [[ ! "$APP_KEY" == *"base64"* ]]; then - # Check APP_KEY format - if [ ! "${#APP_KEY}" = 32 ]; then bashio::exit.nok "Your APP_KEY has ${#APP_KEY} instead of 32 characters"; fi + # Check APP_KEY format + if [ ! "${#APP_KEY}" = 32 ]; then bashio::exit.nok "Your APP_KEY has ${#APP_KEY} instead of 32 characters"; fi fi # Backup APP_KEY file @@ -27,7 +27,7 @@ CURRENT=$(sed -e '/^[]*$/d' /config/addons_config/fireflyiii/APP_KEY # Save if new if [ "$CURRENT" != "$APP_KEY" ]; then - echo "$APP_KEY" >>/config/addons_config/fireflyiii/APP_KEY_BACKUP.txt + echo "$APP_KEY" >>/config/addons_config/fireflyiii/APP_KEY_BACKUP.txt fi # Update permissions @@ -43,83 +43,83 @@ chmod -R 775 /config/addons_config/fireflyiii bashio::log.info "Defining database" case $(bashio::config 'DB_CONNECTION') in - # Use sqlite - sqlite_internal) - bashio::log.info "Using built in sqlite" +# Use sqlite +sqlite_internal) + bashio::log.info "Using built in sqlite" - # Set variable - export DB_CONNECTION=sqlite - export DB_DATABASE=/config/addons_config/fireflyiii/database/database.sqlite + # Set variable + export DB_CONNECTION=sqlite + export DB_DATABASE=/config/addons_config/fireflyiii/database/database.sqlite - # Creating folders - mkdir -p /config/addons_config/fireflyiii/database - chown -R www-data:www-data /config/addons_config/fireflyiii/database + # Creating folders + mkdir -p /config/addons_config/fireflyiii/database + chown -R www-data:www-data /config/addons_config/fireflyiii/database - # Creating database - if [ ! -f /config/addons_config/fireflyiii/database/database.sqlite ]; then - # Create database - touch /config/addons_config/fireflyiii/database/database.sqlite - # Install database - echo "updating database" - php artisan migrate:refresh --seed --quiet - php artisan firefly-iii:upgrade-database --quiet - php artisan passport:install --quiet - fi + # Creating database + if [ ! -f /config/addons_config/fireflyiii/database/database.sqlite ]; then + # Create database + touch /config/addons_config/fireflyiii/database/database.sqlite + # Install database + echo "updating database" + php artisan migrate:refresh --seed --quiet + php artisan firefly-iii:upgrade-database --quiet + php artisan passport:install --quiet + fi - # Creating symlink - rm -r /var/www/html/storage/database - ln -s /config/addons_config/fireflyiii/database /var/www/html/storage + # Creating symlink + rm -r /var/www/html/storage/database + ln -s /config/addons_config/fireflyiii/database /var/www/html/storage - # Updating permissions - chmod 775 /config/addons_config/fireflyiii/database/database.sqlite - chown -R www-data:www-data /config/addons_config/fireflyiii - chown -R www-data:www-data /var/www/html/storage - ;; + # Updating permissions + chmod 775 /config/addons_config/fireflyiii/database/database.sqlite + chown -R www-data:www-data /config/addons_config/fireflyiii + chown -R www-data:www-data /var/www/html/storage + ;; - # Use MariaDB - mariadb_addon) - bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..." - if ! bashio::services.available 'mysql'; then - bashio::log.fatal \ - "Local database access should be provided by the MariaDB addon" - bashio::exit.nok \ - "Please ensure it is installed and started" - fi + # Use MariaDB +mariadb_addon) + bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..." + if ! bashio::services.available 'mysql'; then + bashio::log.fatal \ + "Local database access should be provided by the MariaDB addon" + bashio::exit.nok \ + "Please ensure it is installed and started" + fi - # Use values - DB_CONNECTION=mysql - DB_HOST=$(bashio::services "mysql" "host") - DB_PORT=$(bashio::services "mysql" "port") - DB_DATABASE=firefly - DB_USERNAME=$(bashio::services "mysql" "username") - DB_PASSWORD=$(bashio::services "mysql" "password") - export DB_CONNECTION - export DB_HOST && bashio::log.blue "DB_HOST=$DB_HOST" - export DB_PORT && bashio::log.blue "DB_PORT=$DB_PORT" - export DB_DATABASE && bashio::log.blue "DB_DATABASE=$DB_DATABASE" - export DB_USERNAME && bashio::log.blue "DB_USERNAME=$DB_USERNAME" - export DB_PASSWORD && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD" + # Use values + DB_CONNECTION=mysql + DB_HOST=$(bashio::services "mysql" "host") + DB_PORT=$(bashio::services "mysql" "port") + DB_DATABASE=firefly + DB_USERNAME=$(bashio::services "mysql" "username") + DB_PASSWORD=$(bashio::services "mysql" "password") + export DB_CONNECTION + export DB_HOST && bashio::log.blue "DB_HOST=$DB_HOST" + export DB_PORT && bashio::log.blue "DB_PORT=$DB_PORT" + export DB_DATABASE && bashio::log.blue "DB_DATABASE=$DB_DATABASE" + export DB_USERNAME && bashio::log.blue "DB_USERNAME=$DB_USERNAME" + export DB_PASSWORD && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD" - bashio::log.warning "Firefly-iii is using the Maria DB addon" - bashio::log.warning "Please ensure this is included in your backups" - bashio::log.warning "Uninstalling the MariaDB addon will remove any data" + bashio::log.warning "Firefly-iii is using the Maria DB addon" + bashio::log.warning "Please ensure this is included in your backups" + bashio::log.warning "Uninstalling the MariaDB addon will remove any data" - bashio::log.info "Creating database for Firefly-iii if required" - mysql \ - -u "${DB_USERNAME}" -p"${DB_PASSWORD}" \ - -h "${DB_HOST}" -P "${DB_PORT}" \ - -e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;" - ;; + bashio::log.info "Creating database for Firefly-iii if required" + mysql \ + -u "${DB_USERNAME}" -p"${DB_PASSWORD}" \ + -h "${DB_HOST}" -P "${DB_PORT}" \ + -e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;" + ;; - # Use remote - *) - bashio::log.info "Using remote database. Requirement : filling all addon options fields, and making sure the database already exists" - for conditions in "DB_HOST" "DB_PORT" "DB_DATABASE" "DB_USERNAME" "DB_PASSWORD"; do - if ! bashio::config.has_value "$conditions"; then - bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options" - fi - done - ;; + # Use remote +*) + bashio::log.info "Using remote database. Requirement : filling all addon options fields, and making sure the database already exists" + for conditions in "DB_HOST" "DB_PORT" "DB_DATABASE" "DB_USERNAME" "DB_PASSWORD"; do + if ! bashio::config.has_value "$conditions"; then + bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options" + fi + done + ;; esac @@ -131,13 +131,13 @@ bashio::log.info "Defining upload folder" # Creating folder if [ ! -d /config/addons_config/fireflyiii/upload ]; then - mkdir -p /config/addons_config/fireflyiii/upload - chown -R www-data:www-data /config/addons_config/fireflyiii/upload + mkdir -p /config/addons_config/fireflyiii/upload + chown -R www-data:www-data /config/addons_config/fireflyiii/upload fi # Creating symlink if [ -d /var/www/html/storage/ha_upload ]; then - rm -r /var/www/html/storage/ha_upload + rm -r /var/www/html/storage/ha_upload fi ln -s /config/addons_config/fireflyiii/upload /var/www/html/storage/ha_upload @@ -148,28 +148,31 @@ chmod -R 775 /config/addons_config/fireflyiii # Test f=/config/addons_config/fireflyiii -while [[ $f != / ]]; do chmod 777 "$f"; f=$(dirname "$f"); done; +while [[ $f != / ]]; do + chmod 777 "$f" + f=$(dirname "$f") +done ################ # CRON OPTIONS # ################ if bashio::config.has_value 'Updates'; then - # Align update with options - echo "" - FREQUENCY=$(bashio::config 'Updates') - bashio::log.info "$FREQUENCY updates" - echo "" + # Align update with options + echo "" + FREQUENCY=$(bashio::config 'Updates') + bashio::log.info "$FREQUENCY updates" + echo "" - # Sets cron // do not delete this message - cp /templates/cronupdate /etc/cron."${FREQUENCY}"/ - chmod 777 /etc/cron."${FREQUENCY}"/cronupdate + # Sets cron // do not delete this message + cp /templates/cronupdate /etc/cron."${FREQUENCY}"/ + chmod 777 /etc/cron."${FREQUENCY}"/cronupdate - # Sets cron to run with www-data user - # sed -i 's|root|www-data|g' /etc/crontab + # Sets cron to run with www-data user + # sed -i 's|root|www-data|g' /etc/crontab - # Starts cron - service cron start + # Starts cron + service cron start fi ############## @@ -179,8 +182,8 @@ fi bashio::log.info "Please wait while the app is loading !" if bashio::config.true 'silent'; then - bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug" - sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh >/dev/null' + bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug" + sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh >/dev/null' else - sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh' + sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh' fi diff --git a/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-migration_config.sh b/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-migration_config.sh index 7322b7e7f..1d65d47b2 100755 --- a/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-migration_config.sh +++ b/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-migration_config.sh @@ -5,17 +5,17 @@ set -e slug=fireflyiii_data_importer if [[ "$(bashio::config "CONFIG_LOCATION")" == *"/addons_config/fireflyiii_data_importer"* ]]; then - bashio::log.warning "Reset CONFIG_LOCATION to /config" - bashio::addon.option "CONFIG_LOCATION" "/config" - bashio::addon.restart + bashio::log.warning "Reset CONFIG_LOCATION to /config" + bashio::addon.option "CONFIG_LOCATION" "/config" + bashio::addon.restart fi CONFIGSOURCE="$(bashio::config "CONFIG_LOCATION")" if [ -d "/homeassistant/addons_config/$slug" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then - echo "Migrating /homeassistant/addons_config/$slug" - mv /homeassistant/addons_config/"$slug"/* "$CONFIGSOURCE"/ - touch /homeassistant/addons_config/$slug/migrated + echo "Migrating /homeassistant/addons_config/$slug" + mv /homeassistant/addons_config/"$slug"/* "$CONFIGSOURCE"/ + touch /homeassistant/addons_config/$slug/migrated fi # Create directory diff --git a/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh b/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh index 63ece5c63..24b2010df 100755 --- a/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh +++ b/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh @@ -9,9 +9,9 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") ################# if [ "$(ls -A "$CONFIGSOURCE/configurations")" ]; then - bashio::log.info "Configurations were found in $CONFIGSOURCE/configurations, they will be loaded." - JSON_CONFIGURATION_DIR="$CONFIGSOURCE/configurations" - export JSON_CONFIGURATION_DIR + bashio::log.info "Configurations were found in $CONFIGSOURCE/configurations, they will be loaded." + JSON_CONFIGURATION_DIR="$CONFIGSOURCE/configurations" + export JSON_CONFIGURATION_DIR fi # Allow config dir @@ -31,36 +31,36 @@ export CAN_POST_AUTOIMPORT="$(bashio::config "CAN_POST_AUTOIMPORT")" if bashio::config.has_value 'Updates'; then - # Align update with options - echo "" - FREQUENCY=$(bashio::config 'Updates') - bashio::log.info "$FREQUENCY updates" - echo "" + # Align update with options + echo "" + FREQUENCY=$(bashio::config 'Updates') + bashio::log.info "$FREQUENCY updates" + echo "" - # Sets cron // do not delete this message - cp /templates/cronupdate /etc/cron."${FREQUENCY}"/ - chmod 777 /etc/cron."${FREQUENCY}"/cronupdate + # Sets cron // do not delete this message + cp /templates/cronupdate /etc/cron."${FREQUENCY}"/ + chmod 777 /etc/cron."${FREQUENCY}"/cronupdate - # Sets cron to run with www-data user - # sed -i 's|root|www-data|g' /etc/crontab + # Sets cron to run with www-data user + # sed -i 's|root|www-data|g' /etc/crontab - # Starts cron - service cron start + # Starts cron + service cron start - # Export variables - IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files" - export IMPORT_DIR_WHITELIST + # Export variables + IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files" + export IMPORT_DIR_WHITELIST - bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE}/import_files will be imported $FREQUENCY." + bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE}/import_files will be imported $FREQUENCY." - if [ ! "$(ls -A "${CONFIGSOURCE}"/import_files)" ]; then - bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}/import_files. There will therefore be be no automatic updates." - true - fi + if [ ! "$(ls -A "${CONFIGSOURCE}"/import_files)" ]; then + bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}/import_files. There will therefore be be no automatic updates." + true + fi else - bashio::log.info "Automatic updates not set in addon config. If you add configuration files in ${CONFIGSOURCE}/import_files, they won't be automatically updated." + bashio::log.info "Automatic updates not set in addon config. If you add configuration files in ${CONFIGSOURCE}/import_files, they won't be automatically updated." fi diff --git a/fireflyiii_fints_importer/rootfs/etc/cont-init.d/20-folders.sh b/fireflyiii_fints_importer/rootfs/etc/cont-init.d/20-folders.sh index a272ca21f..7a456641f 100755 --- a/fireflyiii_fints_importer/rootfs/etc/cont-init.d/20-folders.sh +++ b/fireflyiii_fints_importer/rootfs/etc/cont-init.d/20-folders.sh @@ -9,13 +9,13 @@ mkdir -p "$CONFIGSOURCE" # If no file, provide example if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /data/configurations ]; then - cp -r /data/configurations/* "$CONFIGSOURCE"/ || true - rm -r /data/configurations + cp -r /data/configurations/* "$CONFIGSOURCE"/ || true + rm -r /data/configurations fi if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /app/configurations ]; then - cp -r /app/configurations/* "$CONFIGSOURCE"/ || true - rm -r /app/configurations + cp -r /app/configurations/* "$CONFIGSOURCE"/ || true + rm -r /app/configurations fi ln -sf "$CONFIGSOURCE" /data/configurations diff --git a/fireflyiii_fints_importer/rootfs/etc/cont-init.d/99-run.sh b/fireflyiii_fints_importer/rootfs/etc/cont-init.d/99-run.sh index f05e67ddc..4da3e01f5 100755 --- a/fireflyiii_fints_importer/rootfs/etc/cont-init.d/99-run.sh +++ b/fireflyiii_fints_importer/rootfs/etc/cont-init.d/99-run.sh @@ -9,9 +9,9 @@ CONFIGSOURCE="/config/addons_config/fireflyiii_fints_importer" ################# if [ "$(ls -A "$CONFIGSOURCE")" ]; then - bashio::log.info "Configurations were found in $CONFIGSOURCE, they will be loaded." + bashio::log.info "Configurations were found in $CONFIGSOURCE, they will be loaded." else - bashio::log.warning "No configurations in $CONFIGSOURCE, you'll need to input the infos manually." + bashio::log.warning "No configurations in $CONFIGSOURCE, you'll need to input the infos manually." fi ################ @@ -20,44 +20,43 @@ fi if bashio::config.has_value 'Updates'; then - if [ "$(ls -A "${CONFIGSOURCE}")" ]; then + if [ "$(ls -A "${CONFIGSOURCE}")" ]; then - # Align update with options - echo "" - FREQUENCY=$(bashio::config 'Updates') - bashio::log.info "$FREQUENCY updates" - echo "" + # Align update with options + echo "" + FREQUENCY=$(bashio::config 'Updates') + bashio::log.info "$FREQUENCY updates" + echo "" - for i in $(seq 4 2 12) - do - hour=" $i" - freqDir="/etc/periodic/daily$i" - echo "0 ${hour:(-4)} * * * run-parts \"$freqDir\"" >> /etc/crontabs/root - mkdir "$freqDir" - done + for i in $(seq 4 2 12); do + hour=" $i" + freqDir="/etc/periodic/daily$i" + echo "0 ${hour:(-4)} * * * run-parts \"$freqDir\"" >>/etc/crontabs/root + mkdir "$freqDir" + done - # Sets cron // do not delete this message - freqDir="/etc/periodic/${FREQUENCY}" - cp /templates/cronupdate "$freqDir/" - chmod 777 "$freqDir/cronupdate" + # Sets cron // do not delete this message + freqDir="/etc/periodic/${FREQUENCY}" + cp /templates/cronupdate "$freqDir/" + chmod 777 "$freqDir/cronupdate" - # Sets cron to run with www-data user - # sed -i 's|root|www-data|g' /etc/crontab + # Sets cron to run with www-data user + # sed -i 's|root|www-data|g' /etc/crontab - # Starts cron - echo "Timezone $TZ" - export TZ - crond -l 2 -f > /dev/stdout 2> /dev/stderr & + # Starts cron + echo "Timezone $TZ" + export TZ + crond -l 2 -f >/dev/stdout 2>/dev/stderr & - # Export variables - IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files" - export IMPORT_DIR_WHITELIST + # Export variables + IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files" + export IMPORT_DIR_WHITELIST - bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE} will be imported $FREQUENCY." + bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE} will be imported $FREQUENCY." - else - bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}. There will therefore be be no automatic updates." - fi + else + bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}. There will therefore be be no automatic updates." + fi fi @@ -68,8 +67,8 @@ fi bashio::log.info "Please wait while the app is loading !" if bashio::config.true 'silent'; then - bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug" - php -S 0.0.0.0:8080 /app/index.php >/dev/null + bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug" + php -S 0.0.0.0:8080 /app/index.php >/dev/null else - php -S 0.0.0.0:8080 /app/index.php + php -S 0.0.0.0:8080 /app/index.php fi diff --git a/flexget/rootfs/etc/cont-init.d/00-folders.sh b/flexget/rootfs/etc/cont-init.d/00-folders.sh index e17be913a..5aa12a3a0 100755 --- a/flexget/rootfs/etc/cont-init.d/00-folders.sh +++ b/flexget/rootfs/etc/cont-init.d/00-folders.sh @@ -5,15 +5,15 @@ set -e slug=flexget if [ -d /config/$slug ]; then - echo "Moving to new location /config/addons_config/$slug" - mkdir -p /config/addons_config/$slug - chmod 777 /config/addons_config/$slug - mv /config/$slug/* /config/addons_config/$slug/ - rm -r /config/$slug + echo "Moving to new location /config/addons_config/$slug" + mkdir -p /config/addons_config/$slug + chmod 777 /config/addons_config/$slug + mv /config/$slug/* /config/addons_config/$slug/ + rm -r /config/$slug fi if [ ! -d /config/addons_config/$slug ]; then - echo "Creating /config/addons_config/$slug" - mkdir -p /config/addons_config/$slug - chmod 777 /config/addons_config/$slug + echo "Creating /config/addons_config/$slug" + mkdir -p /config/addons_config/$slug + chmod 777 /config/addons_config/$slug fi diff --git a/free_games_claimer/rootfs/etc/cont-init.d/00-migrate_files.sh b/free_games_claimer/rootfs/etc/cont-init.d/00-migrate_files.sh index 9e98657f0..c6bb3b547 100755 --- a/free_games_claimer/rootfs/etc/cont-init.d/00-migrate_files.sh +++ b/free_games_claimer/rootfs/etc/cont-init.d/00-migrate_files.sh @@ -3,12 +3,12 @@ # Migrate files for new config location slug="free_games_claimer" if [ -f "/homeassistant/addons_config/$slug/config.yaml" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then - bashio::log.warning "Migrating config.yaml" - mv "/homeassistant/addons_config/$slug"/* /config/ || true - echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" > "/homeassistant/addons_config/$slug/migrated" + bashio::log.warning "Migrating config.yaml" + mv "/homeassistant/addons_config/$slug"/* /config/ || true + echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" >"/homeassistant/addons_config/$slug/migrated" fi if [ -f "/homeassistant/addons_autoscripts/$slug.sh" ]; then - bashio::log.warning "Migrating autoscript" - mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true + bashio::log.warning "Migrating autoscript" + mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true fi diff --git a/free_games_claimer/rootfs/etc/cont-init.d/99-run.sh b/free_games_claimer/rootfs/etc/cont-init.d/99-run.sh index a2cb2471a..977f4bd93 100755 --- a/free_games_claimer/rootfs/etc/cont-init.d/99-run.sh +++ b/free_games_claimer/rootfs/etc/cont-init.d/99-run.sh @@ -11,20 +11,20 @@ CONFIG_HOME="$(dirname "$CONFIG_HOME")" # Use new config file if [ ! -f "$CONFIG_HOME/config.env" ]; then - # Copy default config.env - cp /templates/config.env "$CONFIG_HOME/" - chmod 755 "$CONFIG_HOME/config.env" - bashio::log.warning "A default config.env file was copied to $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on" + # Copy default config.env + cp /templates/config.env "$CONFIG_HOME/" + chmod 755 "$CONFIG_HOME/config.env" + bashio::log.warning "A default config.env file was copied to $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on" else - bashio::log.info "Using existing config.env file in $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on" + bashio::log.info "Using existing config.env file in $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on" fi # Remove erroneous folder named config.env (bug fix for looping issue) if [ -d "$CONFIG_HOME/config.env" ]; then - bashio::log.warning "Found directory named config.env, deleting it..." - rm -rf "$CONFIG_HOME/config.env" # Fix: Ensures directory removal even if it exists - cp /templates/config.env "$CONFIG_HOME/config.env" # Recreate as a valid file - chmod 755 "$CONFIG_HOME/config.env" + bashio::log.warning "Found directory named config.env, deleting it..." + rm -rf "$CONFIG_HOME/config.env" # Fix: Ensures directory removal even if it exists + cp /templates/config.env "$CONFIG_HOME/config.env" # Recreate as a valid file + chmod 755 "$CONFIG_HOME/config.env" fi # Copy new file @@ -61,23 +61,23 @@ cd /data || true # Fetch commands CMD_ARGUMENTS="$(bashio::config "CMD_ARGUMENTS")" IFS=';' -read -ar strarr <<< "$CMD_ARGUMENTS" +read -ar strarr <<<"$CMD_ARGUMENTS" # Sanitizes commands trim() { - local var="$*" - var="${var#"${var%%[![:space:]]*}"}" - var="${var%"${var##*[![:space:]]}"}" - printf '%s' "$var" + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" + var="${var%"${var##*[![:space:]]}"}" + printf '%s' "$var" } # Add docker-entrypoint command for val in "${strarr[@]}"; do - val="$(trim "$val")" - echo " " - bashio::log.info "Starting the app with arguments \"$val\"" - echo " " - echo "$val" | xargs docker-entrypoint.sh || true + val="$(trim "$val")" + echo " " + bashio::log.info "Starting the app with arguments \"$val\"" + echo " " + echo "$val" | xargs docker-entrypoint.sh || true done bashio::log.info "All actions concluded. Stopping in 10 seconds." diff --git a/gazpar2mqtt/rootfs/etc/cont-init.d/89-mqtt_autodiscover.sh b/gazpar2mqtt/rootfs/etc/cont-init.d/89-mqtt_autodiscover.sh index 9e260a479..1c729cdb0 100755 --- a/gazpar2mqtt/rootfs/etc/cont-init.d/89-mqtt_autodiscover.sh +++ b/gazpar2mqtt/rootfs/etc/cont-init.d/89-mqtt_autodiscover.sh @@ -7,26 +7,26 @@ set -e ##################### if bashio::config.true 'mqtt_autodiscover'; then - bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." - # Check if available - if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi - # Get variables - bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." - MQTT_HOST=$(bashio::services mqtt "host") - export MQTT_HOST - MQTT_PORT=$(bashio::services mqtt "port") - export MQTT_PORT - MQTT_SSL=$(bashio::services mqtt "ssl") - export MQTT_SSL - MQTT_USERNAME=$(bashio::services mqtt "username") - export MQTT_USERNAME - MQTT_PASSWORD=$(bashio::services mqtt "password") - export MQTT_PASSWORD + bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." + # Check if available + if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi + # Get variables + bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." + MQTT_HOST=$(bashio::services mqtt "host") + export MQTT_HOST + MQTT_PORT=$(bashio::services mqtt "port") + export MQTT_PORT + MQTT_SSL=$(bashio::services mqtt "ssl") + export MQTT_SSL + MQTT_USERNAME=$(bashio::services mqtt "username") + export MQTT_USERNAME + MQTT_PASSWORD=$(bashio::services mqtt "password") + export MQTT_PASSWORD - # Export variables - for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do - sed -i "1a export $variables" /etc/services.d/*/*run* 2>/dev/null || true - # Log - bashio::log.blue "$variables" - done + # Export variables + for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do + sed -i "1a export $variables" /etc/services.d/*/*run* 2>/dev/null || true + # Log + bashio::log.blue "$variables" + done fi diff --git a/gitea/rootfs/etc/cont-init.d/99-run.sh b/gitea/rootfs/etc/cont-init.d/99-run.sh index 320107f2c..2a66325d0 100755 --- a/gitea/rootfs/etc/cont-init.d/99-run.sh +++ b/gitea/rootfs/etc/cont-init.d/99-run.sh @@ -4,64 +4,64 @@ set -e for file in /data/gitea/conf/app.ini /etc/templates/app.ini; do - if [ ! -f "$file" ]; then - continue - fi + if [ ! -f "$file" ]; then + continue + fi - ############## - # SSL CONFIG # - ############## + ############## + # SSL CONFIG # + ############## - # Clean values - sed -i "/PROTOCOL/d" "$file" - sed -i "/CERT_FILE/d" "$file" - sed -i "/KEY_FILE/d" "$file" + # Clean values + sed -i "/PROTOCOL/d" "$file" + sed -i "/CERT_FILE/d" "$file" + sed -i "/KEY_FILE/d" "$file" - # Add ssl - bashio::config.require.ssl - if bashio::config.true 'ssl'; then - PROTOCOL=https - bashio::log.info "ssl is enabled" - sed -i "/server/a PROTOCOL=https" "$file" - sed -i "/server/a CERT_FILE=/ssl/$(bashio::config 'certfile')" "$file" - sed -i "/server/a KEY_FILE=/ssl/$(bashio::config 'keyfile')" "$file" - chmod 744 /ssl/* - else - PROTOCOL=http - sed -i "/server/a PROTOCOL=http" "$file" - fi + # Add ssl + bashio::config.require.ssl + if bashio::config.true 'ssl'; then + PROTOCOL=https + bashio::log.info "ssl is enabled" + sed -i "/server/a PROTOCOL=https" "$file" + sed -i "/server/a CERT_FILE=/ssl/$(bashio::config 'certfile')" "$file" + sed -i "/server/a KEY_FILE=/ssl/$(bashio::config 'keyfile')" "$file" + chmod 744 /ssl/* + else + PROTOCOL=http + sed -i "/server/a PROTOCOL=http" "$file" + fi - ################## - # ADAPT ROOT_URL # - ################## + ################## + # ADAPT ROOT_URL # + ################## - if bashio::config.has_value 'ROOT_URL'; then - bashio::log.blue "ROOT_URL set, using value : $(bashio::config 'ROOT_URL')" - else - ROOT_URL="$PROTOCOL://$(bashio::config 'DOMAIN'):$(bashio::addon.port 3000)" - bashio::log.blue "ROOT_URL not set, using extrapolated value : $ROOT_URL" - sed -i "/server/a ROOT_URL=$ROOT_URL" "$file" - fi + if bashio::config.has_value 'ROOT_URL'; then + bashio::log.blue "ROOT_URL set, using value : $(bashio::config 'ROOT_URL')" + else + ROOT_URL="$PROTOCOL://$(bashio::config 'DOMAIN'):$(bashio::addon.port 3000)" + bashio::log.blue "ROOT_URL not set, using extrapolated value : $ROOT_URL" + sed -i "/server/a ROOT_URL=$ROOT_URL" "$file" + fi - #################### - # ADAPT PARAMETERS # - #################### + #################### + # ADAPT PARAMETERS # + #################### - for param in APP_NAME DOMAIN ROOT_URL; do - # Remove parameter - sed -i "/$param/d" "$file" + for param in APP_NAME DOMAIN ROOT_URL; do + # Remove parameter + sed -i "/$param/d" "$file" - # Define parameter - if bashio::config.has_value "$param"; then - echo "parameter set : $param=$(bashio::config "$param")" - sed -i "/server/a $param = \"$(bashio::config "$param")\"" "$file" + # Define parameter + if bashio::config.has_value "$param"; then + echo "parameter set : $param=$(bashio::config "$param")" + sed -i "/server/a $param = \"$(bashio::config "$param")\"" "$file" - # Allow at setup - sed -i "1a $param=\"$(bashio::config "$param")\"" /etc/s6/gitea/setup + # Allow at setup + sed -i "1a $param=\"$(bashio::config "$param")\"" /etc/s6/gitea/setup - fi + fi - done + done done diff --git a/grampsweb/rootfs/etc/cont-init.d/32-nginx_ssl.sh b/grampsweb/rootfs/etc/cont-init.d/32-nginx_ssl.sh index b4d756e45..c0051af70 100755 --- a/grampsweb/rootfs/etc/cont-init.d/32-nginx_ssl.sh +++ b/grampsweb/rootfs/etc/cont-init.d/32-nginx_ssl.sh @@ -16,19 +16,18 @@ sed -i "s|%%interface%%|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ssl.co # Ssl values if bashio::config.true 'ssl'; then - echo "Defining ssl configuration" - bashio::config.require.ssl - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') + echo "Defining ssl configuration" + bashio::config.require.ssl + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') - #Check if files exist - echo "... checking if referenced certificates exist" - [ ! -f /ssl/"$certfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$certfile not found" && bashio::exit.nok - [ ! -f /ssl/"$keyfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$keyfile not found" && bashio::exit.nok + #Check if files exist + echo "... checking if referenced certificates exist" + [ ! -f /ssl/"$certfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$certfile not found" && bashio::exit.nok + [ ! -f /ssl/"$keyfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$keyfile not found" && bashio::exit.nok - - sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf - sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf - sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf - bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port "$port")" + sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf + sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf + sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf + bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port "$port")" fi diff --git a/grampsweb/rootfs/etc/cont-init.d/99-run.sh b/grampsweb/rootfs/etc/cont-init.d/99-run.sh index 8ca38c077..d3d3af37b 100755 --- a/grampsweb/rootfs/etc/cont-init.d/99-run.sh +++ b/grampsweb/rootfs/etc/cont-init.d/99-run.sh @@ -6,21 +6,21 @@ set -e # Set structure # ################# for folders in config users indexdir secret media cache thumbnail_cache persist; do - mkdir -p /config/"$folders" - if [ -d /app/"$folders" ] && [ "$(ls -A /app/"$folders")" ]; then - cp -rn /app/"$folders"/* /config/"$folders" - fi - rm -rf /app/"$folders" - ln -sf /config/"$folders" /app/"$folders" + mkdir -p /config/"$folders" + if [ -d /app/"$folders" ] && [ "$(ls -A /app/"$folders")" ]; then + cp -rn /app/"$folders"/* /config/"$folders" + fi + rm -rf /app/"$folders" + ln -sf /config/"$folders" /app/"$folders" done # Persist database and plugins mkdir -p /config/gramps if [ -d /root/.gramps ]; then - if [ "$(ls -A /root/.gramps)" ]; then - cp -rf /root/.gramps/* /config/gramps - fi - rm -rf /root/.gramps + if [ "$(ls -A /root/.gramps)" ]; then + cp -rf /root/.gramps/* /config/gramps + fi + rm -rf /root/.gramps fi ln -sf /config/gramps /root/.gramps @@ -29,22 +29,22 @@ ln -sf /config/gramps /root/.gramps ##################### # Check if the secret key is defined in addon options if bashio::config.has_value "GRAMPSWEB_SECRET_KEY"; then - bashio::log.warning "Using the secret key defined in the addon options." - GRAMPSWEB_SECRET_KEY="$(bashio::config "GRAMPSWEB_SECRET_KEY")" - export GRAMPSWEB_SECRET_KEY + bashio::log.warning "Using the secret key defined in the addon options." + GRAMPSWEB_SECRET_KEY="$(bashio::config "GRAMPSWEB_SECRET_KEY")" + export GRAMPSWEB_SECRET_KEY else - # Check if the secret file exists; if not, create a new one - if [ ! -s /config/secret/secret ]; then - bashio::log.warning "No secret key found in /config/secret/secret, generating a new one." - mkdir -p /config/secret - python3 -c "import secrets; print(secrets.token_urlsafe(32))" | tr -d "\n" > /config/secret/secret - bashio::log.warning "New secret key generated and stored in /config/secret/secret" - fi - bashio::log.warning "Using existing secret key from /config/secret/secret." - bashio::log.warning "Secret key saved to addon options." - GRAMPSWEB_SECRET_KEY="$(cat /config/secret/secret)" - export GRAMPSWEB_SECRET_KEY - bashio::addon.option "GRAMPSWEB_SECRET_KEY" "$GRAMPSWEB_SECRET_KEY" + # Check if the secret file exists; if not, create a new one + if [ ! -s /config/secret/secret ]; then + bashio::log.warning "No secret key found in /config/secret/secret, generating a new one." + mkdir -p /config/secret + python3 -c "import secrets; print(secrets.token_urlsafe(32))" | tr -d "\n" >/config/secret/secret + bashio::log.warning "New secret key generated and stored in /config/secret/secret" + fi + bashio::log.warning "Using existing secret key from /config/secret/secret." + bashio::log.warning "Secret key saved to addon options." + GRAMPSWEB_SECRET_KEY="$(cat /config/secret/secret)" + export GRAMPSWEB_SECRET_KEY + bashio::addon.option "GRAMPSWEB_SECRET_KEY" "$GRAMPSWEB_SECRET_KEY" fi ################## @@ -73,7 +73,8 @@ CELERY_PID=$! # Staring nginx # ################# echo "Starting nginx..." -exec nginx & bashio::log.info "Starting nginx" +exec nginx & +bashio::log.info "Starting nginx" NGINX_PID=$! # Wait for all background processes diff --git a/grav/rootfs/etc/cont-init.d/20-folders.sh b/grav/rootfs/etc/cont-init.d/20-folders.sh index 0f8c23790..a2a5a4d3c 100755 --- a/grav/rootfs/etc/cont-init.d/20-folders.sh +++ b/grav/rootfs/etc/cont-init.d/20-folders.sh @@ -5,9 +5,9 @@ set -e echo "Updating folders..." for FOLDERS in "/share/grav" "/app/grav-admin/backup"; do - echo "... $FOLDERS" - mkdir -p $FOLDERS - chown -R "$PUID:$PGID" $FOLDERS + echo "... $FOLDERS" + mkdir -p $FOLDERS + chown -R "$PUID:$PGID" $FOLDERS done bashio::log.warning "If error of missing folder when loading addon, just restart" diff --git a/guacamole/rootfs/etc/cont-init.d/10-migrate.sh b/guacamole/rootfs/etc/cont-init.d/10-migrate.sh index b2036bf67..c318e18d7 100755 --- a/guacamole/rootfs/etc/cont-init.d/10-migrate.sh +++ b/guacamole/rootfs/etc/cont-init.d/10-migrate.sh @@ -9,6 +9,6 @@ set -e slug=guacamole if [ -d /homeassistant/addons_config/"$slug" ] && [ ! -d /config/postgres ]; then - echo "Moving database to new location /config" - cp -rf /homeassistant/addons_config/"$slug"/* /config/ + echo "Moving database to new location /config" + cp -rf /homeassistant/addons_config/"$slug"/* /config/ fi diff --git a/guacamole/rootfs/etc/cont-init.d/90-ingress.sh b/guacamole/rootfs/etc/cont-init.d/90-ingress.sh index e72bdc2e7..762817df6 100755 --- a/guacamole/rootfs/etc/cont-init.d/90-ingress.sh +++ b/guacamole/rootfs/etc/cont-init.d/90-ingress.sh @@ -13,19 +13,19 @@ declare keyfile port=$(bashio::addon.port 80) if bashio::var.has_value "${port}"; then - bashio::config.require.ssl + bashio::config.require.ssl - if bashio::config.true 'ssl'; then - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') + if bashio::config.true 'ssl'; then + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') - mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf - sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf - sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf + mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf + sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf + sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf - else - mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf - fi + else + mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf + fi fi ingress_port=$(bashio::addon.ingress_port) diff --git a/immich/rootfs/etc/cont-init.d/01-migrate.sh b/immich/rootfs/etc/cont-init.d/01-migrate.sh index 9da5fd0ab..5aa3f048f 100755 --- a/immich/rootfs/etc/cont-init.d/01-migrate.sh +++ b/immich/rootfs/etc/cont-init.d/01-migrate.sh @@ -5,17 +5,17 @@ PREVIOUS_FOLDER="immich" # Move main folder if [ -f /homeassistant/addons_config/"$PREVIOUS_FOLDER"/config.yaml ]; then - bashio::log.warning "----------------------------------------" - bashio::log.warning "Migrating configuration to the new addon" - bashio::log.warning "----------------------------------------" - cp -rnp /homeassistant/addons_config/"$PREVIOUS_FOLDER"/ /config/ - mv /homeassistant/addons_config/"$PREVIOUS_FOLDER" "$PREVIOUS_FOLDER"_migrated - if [ -d /config/addons_config ]; then rm -r /config/addons_config; fi - echo "Files moved to /addon_configs/$HOSTNAME" + bashio::log.warning "----------------------------------------" + bashio::log.warning "Migrating configuration to the new addon" + bashio::log.warning "----------------------------------------" + cp -rnp /homeassistant/addons_config/"$PREVIOUS_FOLDER"/ /config/ + mv /homeassistant/addons_config/"$PREVIOUS_FOLDER" "$PREVIOUS_FOLDER"_migrated + if [ -d /config/addons_config ]; then rm -r /config/addons_config; fi + echo "Files moved to /addon_configs/$HOSTNAME" fi # Move autoscript if [ -f /homeassistant/addons_autoscrips/immich.sh ]; then - cp -rnf /homeassistant/addons_autoscrips/"$PREVIOUS_FOLDER".sh /config/ &>/dev/null || true - bashio::log.yellow "... moved $PREVIOUS_FOLDER.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME" + cp -rnf /homeassistant/addons_autoscrips/"$PREVIOUS_FOLDER".sh /config/ &>/dev/null || true + bashio::log.yellow "... moved $PREVIOUS_FOLDER.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME" fi diff --git a/immich/rootfs/etc/cont-init.d/20-folders.sh b/immich/rootfs/etc/cont-init.d/20-folders.sh index 43c887952..8783a1fda 100755 --- a/immich/rootfs/etc/cont-init.d/20-folders.sh +++ b/immich/rootfs/etc/cont-init.d/20-folders.sh @@ -7,14 +7,14 @@ set -e ###################### if bashio::config.has_value "PUID"; then - PUID="$(bashio::config 'PUID')" + PUID="$(bashio::config 'PUID')" else - PUID=0 + PUID=0 fi if bashio::config.has_value "PGID"; then - PGID="$(bashio::config 'PGID')" + PGID="$(bashio::config 'PGID')" else - PGID=0 + PGID=0 fi ########################## @@ -23,7 +23,7 @@ fi # Clean typesense if [ -d /data/typesense ]; then - rm -r /data/typesense + rm -r /data/typesense fi ################# @@ -34,9 +34,9 @@ bashio::log.info "Setting data location" DATA_LOCATION="$(bashio::config 'data_location')" export IMMICH_MEDIA_LOCATION="$DATA_LOCATION" if [ -d /var/run/s6/container_environment ]; then - printf "%s" "$DATA_LOCATION" > /var/run/s6/container_environment/IMMICH_MEDIA_LOCATION + printf "%s" "$DATA_LOCATION" >/var/run/s6/container_environment/IMMICH_MEDIA_LOCATION fi -printf "%s\n" "IMMICH_MEDIA_LOCATION=\"$DATA_LOCATION\"" >> ~/.bashrc +printf "%s\n" "IMMICH_MEDIA_LOCATION=\"$DATA_LOCATION\"" >>~/.bashrc echo "... check $DATA_LOCATION folder exists" mkdir -p "$DATA_LOCATION" @@ -63,32 +63,32 @@ chmod 777 /data #################### if bashio::config.has_value "library_location"; then - LIBRARY_LOCATION="$(bashio::config 'library_location')" - bashio::log.info "Setting library location to $LIBRARY_LOCATION. This will not move any of your files, you'll need to do this manually" - mkdir -p "$LIBRARY_LOCATION" - chown -R "$PUID":"$PGID" "$LIBRARY_LOCATION" - - # Check if the existing library is a directory and not a symlink and has contents - if [ -d "$DATA_LOCATION/library" ] && [ ! -L "$DATA_LOCATION/library" ] && [ "$(ls -A "$DATA_LOCATION/library")" ]; then - bashio::log.yellow "-------------------------------" - bashio::log.warning "Library folder in $DATA_LOCATION/library already exists, is a real folder, and is not empty. Moving to $DATA_LOCATION/library_old" - bashio::log.yellow "-------------------------------" - mv "$DATA_LOCATION/library" "$DATA_LOCATION/library_old" - sleep 5 - fi - - # Create symbolic link only if it doesn't already exist or is incorrect - if [ ! -L "$DATA_LOCATION/library" ] || [ "$(readlink -f "$DATA_LOCATION/library")" != "$LIBRARY_LOCATION" ]; then - ln -sf "$LIBRARY_LOCATION" "$DATA_LOCATION/library" - fi + LIBRARY_LOCATION="$(bashio::config 'library_location')" + bashio::log.info "Setting library location to $LIBRARY_LOCATION. This will not move any of your files, you'll need to do this manually" + mkdir -p "$LIBRARY_LOCATION" + chown -R "$PUID":"$PGID" "$LIBRARY_LOCATION" + + # Check if the existing library is a directory and not a symlink and has contents + if [ -d "$DATA_LOCATION/library" ] && [ ! -L "$DATA_LOCATION/library" ] && [ "$(ls -A "$DATA_LOCATION/library")" ]; then + bashio::log.yellow "-------------------------------" + bashio::log.warning "Library folder in $DATA_LOCATION/library already exists, is a real folder, and is not empty. Moving to $DATA_LOCATION/library_old" + bashio::log.yellow "-------------------------------" + mv "$DATA_LOCATION/library" "$DATA_LOCATION/library_old" + sleep 5 + fi + + # Create symbolic link only if it doesn't already exist or is incorrect + if [ ! -L "$DATA_LOCATION/library" ] || [ "$(readlink -f "$DATA_LOCATION/library")" != "$LIBRARY_LOCATION" ]; then + ln -sf "$LIBRARY_LOCATION" "$DATA_LOCATION/library" + fi fi ################## # REDIS LOCATION # ################## -echo "sed -i \"s=/config/redis=/data/redis=g\" /etc/s6*/s6*/*/run" >> /docker-mods -echo "sed -i \"s=/config/log/redis=/data/log=g\" /etc/s6*/s6*/*/run" >> /docker-mods +echo "sed -i \"s=/config/redis=/data/redis=g\" /etc/s6*/s6*/*/run" >>/docker-mods +echo "sed -i \"s=/config/log/redis=/data/log=g\" /etc/s6*/s6*/*/run" >>/docker-mods mkdir -p /data/redis mkdir -p /data/log chmod 777 /data/redis diff --git a/immich/rootfs/etc/cont-init.d/99-run.sh b/immich/rootfs/etc/cont-init.d/99-run.sh index 2a5350e15..4b55c61c1 100755 --- a/immich/rootfs/etc/cont-init.d/99-run.sh +++ b/immich/rootfs/etc/cont-init.d/99-run.sh @@ -5,134 +5,134 @@ set -e # Function to export options from JSON to env variables export_options() { - local json_source="/data/options.json" - bashio::log.info "Exporting addon options from ${json_source}" + local json_source="/data/options.json" + bashio::log.info "Exporting addon options from ${json_source}" - # WARNING: Exporting all keys can cause trouble if your config contains unsafe or untrusted keys! - mapfile -t keys < <(jq -r 'keys[]' "${json_source}") - for key in "${keys[@]}"; do - local value - value=$(jq -r ".${key}" "${json_source}") - if bashio::config.false "verbose" || [[ "$key" == *"PASS"* ]]; then - bashio::log.blue "${key}=******" - else - bashio::log.blue "${key}='${value}'" - fi - export "${key}=${value}" - done + # WARNING: Exporting all keys can cause trouble if your config contains unsafe or untrusted keys! + mapfile -t keys < <(jq -r 'keys[]' "${json_source}") + for key in "${keys[@]}"; do + local value + value=$(jq -r ".${key}" "${json_source}") + if bashio::config.false "verbose" || [[ "$key" == *"PASS"* ]]; then + bashio::log.blue "${key}=******" + else + bashio::log.blue "${key}='${value}'" + fi + export "${key}=${value}" + done } # Function to check and adjust DB_HOSTNAME if necessary check_db_hostname() { - if [[ "${DB_HOSTNAME}" == "homeassistant.local" ]]; then - local host_ip - host_ip=$(bashio::network.ipv4_address) - host_ip=${host_ip%/*} - export DB_HOSTNAME="$host_ip" - bashio::log.warning "DB_HOSTNAME was set to homeassistant.local. Using detected IP: $DB_HOSTNAME" - fi + if [[ "${DB_HOSTNAME}" == "homeassistant.local" ]]; then + local host_ip + host_ip=$(bashio::network.ipv4_address) + host_ip=${host_ip%/*} + export DB_HOSTNAME="$host_ip" + bashio::log.warning "DB_HOSTNAME was set to homeassistant.local. Using detected IP: $DB_HOSTNAME" + fi - if ! ping -c 1 -W 3 "$DB_HOSTNAME" >/dev/null 2>&1; then - bashio::log.warning "------------------------------------" - bashio::log.warning "DB_HOSTNAME ($DB_HOSTNAME) is not reachable." - bashio::log.warning "Please set it to the IP address of your database." - bashio::log.warning "The addon will stop until this is fixed." - bashio::log.warning "------------------------------------" - sleep 30 - bashio::addon.stop - else - echo "$DB_HOSTNAME is reachable." - fi + if ! ping -c 1 -W 3 "$DB_HOSTNAME" >/dev/null 2>&1; then + bashio::log.warning "------------------------------------" + bashio::log.warning "DB_HOSTNAME ($DB_HOSTNAME) is not reachable." + bashio::log.warning "Please set it to the IP address of your database." + bashio::log.warning "The addon will stop until this is fixed." + bashio::log.warning "------------------------------------" + sleep 30 + bashio::addon.stop + else + echo "$DB_HOSTNAME is reachable." + fi } # Function to migrate internal database to external storage if needed migrate_database() { - if [ -f /share/postgresql_immich.tar.gz ]; then - bashio::log.warning "Previous database export found at /share/postgresql_immich.tar.gz" - elif [ -d /data/postgresql ]; then - bashio::log.warning "Internal Postgres database detected. Migrating to /share/postgresql_immich.tar.gz" - tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql - rm -rf /data/postgresql - fi + if [ -f /share/postgresql_immich.tar.gz ]; then + bashio::log.warning "Previous database export found at /share/postgresql_immich.tar.gz" + elif [ -d /data/postgresql ]; then + bashio::log.warning "Internal Postgres database detected. Migrating to /share/postgresql_immich.tar.gz" + tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql + rm -rf /data/postgresql + fi } # Function to validate required configuration values validate_config() { - local missing=false - for var in DB_USERNAME DB_HOSTNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT JWT_SECRET; do - if ! bashio::config.has_value "${var}"; then - bashio::log.error "Missing required configuration: ${var}" - missing=true - fi - done - if [ "$missing" = true ]; then - bashio::exit.nok "Please ensure all required options are set." - fi + local missing=false + for var in DB_USERNAME DB_HOSTNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT JWT_SECRET; do + if ! bashio::config.has_value "${var}"; then + bashio::log.error "Missing required configuration: ${var}" + missing=true + fi + done + if [ "$missing" = true ]; then + bashio::exit.nok "Please ensure all required options are set." + fi } # Function to export DB variables to s6 environment if applicable export_db_env() { - if [ -d /var/run/s6/container_environment ]; then - for var in DB_USERNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT DB_HOSTNAME JWT_SECRET; do - if [ -n "${!var:-}" ]; then - printf "%s" "${!var}" > "/var/run/s6/container_environment/${var}" - fi - done - fi + if [ -d /var/run/s6/container_environment ]; then + for var in DB_USERNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT DB_HOSTNAME JWT_SECRET; do + if [ -n "${!var:-}" ]; then + printf "%s" "${!var}" >"/var/run/s6/container_environment/${var}" + fi + done + fi } # Function to set up the root user with a secure password setup_root_user() { - # Generate DB_ROOT_PASSWORD if not set (12-character alphanumeric). - if bashio::config.has_value "DB_ROOT_PASSWORD"; then - export DB_ROOT_PASSWORD="$(bashio::config 'DB_ROOT_PASSWORD')" - else - bashio::log.warning "DB_ROOT_PASSWORD not set. Generating a random 12-character alphanumeric password and storing it in the addon options." - export DB_ROOT_PASSWORD="$(tr -dc 'A-Za-z0-9' "/var/run/s6/container_environment/DB_ROOT_PASSWORD" - fi - fi + # Store generated password in the s6 environment if available + if [ -d /var/run/s6/container_environment ]; then + printf "%s" "${DB_ROOT_PASSWORD}" >"/var/run/s6/container_environment/DB_ROOT_PASSWORD" + fi + fi - # Try to connect as root using the default insecure password. - if psql "postgres://root:securepassword@${DB_HOSTNAME}:${DB_PORT}/postgres" -c '\q' 2>/dev/null; then - bashio::log.info "Detected root user with default password. Updating to new DB_ROOT_PASSWORD..." - psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" </dev/null; then + bashio::log.info "Detected root user with default password. Updating to new DB_ROOT_PASSWORD..." + psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" </dev/null + curl --progress-bar -f -S -J -L -o /tmp/joal.tar.gz "$(curl -f -s -L https://api.github.com/repos/anthonyraymond/joal/releases/latest | grep -o "http.*joal.tar.gz")" >/dev/null fi mkdir -p /data/joal tar zxvf /tmp/joal.tar.gz -C /data/joal >/dev/null @@ -35,9 +35,9 @@ bashio::log.info "Joal updated" # If config doesn't exist, create it if [ ! -f /config/addons_config/joal/config.json ]; then - bashio::log.info "Symlinking config files" - mkdir -p /config/addons_config/joal - cp /data/joal/config.json /config/addons_config/joal/config.json + bashio::log.info "Symlinking config files" + mkdir -p /config/addons_config/joal + cp /data/joal/config.json /config/addons_config/joal/config.json fi # Refresh symlink @@ -87,9 +87,9 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log ############### if [ "$VERBOSE" = true ]; then - nohup java -jar /joal/joal.jar --joal-conf=/data/joal --spring.main.web-environment=true --server.port="8081" --joal.ui.path.prefix="${UIPATH}" --joal.ui.secret-token="$TOKEN" + nohup java -jar /joal/joal.jar --joal-conf=/data/joal --spring.main.web-environment=true --server.port="8081" --joal.ui.path.prefix="${UIPATH}" --joal.ui.secret-token="$TOKEN" else - nohup java -jar /joal/joal.jar --joal-conf=/data/joal --spring.main.web-environment=true --server.port="8081" --joal.ui.path.prefix="${UIPATH}" --joal.ui.secret-token="$TOKEN" >/dev/null + nohup java -jar /joal/joal.jar --joal-conf=/data/joal --spring.main.web-environment=true --server.port="8081" --joal.ui.path.prefix="${UIPATH}" --joal.ui.secret-token="$TOKEN" >/dev/null fi & bashio::log.info "Please wait, loading..." @@ -116,11 +116,11 @@ exec nginx & ########### if bashio::config.has_value 'run_duration'; then - RUNTIME=$(bashio::config 'run_duration') - bashio::log.info "Addon will stop after $RUNTIME" - sleep "$RUNTIME" && - bashio::log.info "Timeout achieved, addon will stop !" && - exit 0 + RUNTIME=$(bashio::config 'run_duration') + bashio::log.info "Addon will stop after $RUNTIME" + sleep "$RUNTIME" && + bashio::log.info "Timeout achieved, addon will stop !" && + exit 0 else - bashio::log.info "Run_duration option not defined, addon will run continuously" + bashio::log.info "Run_duration option not defined, addon will run continuously" fi diff --git a/joplin/rootfs/etc/cont-init.d/99-run.sh b/joplin/rootfs/etc/cont-init.d/99-run.sh index 5c7ff8eef..b8f3ac759 100755 --- a/joplin/rootfs/etc/cont-init.d/99-run.sh +++ b/joplin/rootfs/etc/cont-init.d/99-run.sh @@ -8,22 +8,22 @@ bashio::log.warning "Warning - minimum configuration recommended : 2 cpu cores a # Check data location LOCATION=$(bashio::config 'data_location') if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then - # Default location - LOCATION="/config/addons_config/joplin" + # Default location + LOCATION="/config/addons_config/joplin" 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" + bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually" fi # Create folder if [ ! -d "$LOCATION" ]; then - echo "Creating $LOCATION" - mkdir -p "$LOCATION" + echo "Creating $LOCATION" + mkdir -p "$LOCATION" fi touch "$LOCATION"/database.sqlite if [ ! -d "$LOCATION"/resources ]; then - mkdir -p "$LOCATION"/resources + mkdir -p "$LOCATION"/resources fi ln -s "$LOCATION"/resources /home/joplin/packages/server @@ -33,17 +33,17 @@ chmod 777 "$LOCATION/database.sqlite" export SQLITE_DATABASE="$LOCATION/database.sqlite" if bashio::config.has_value 'POSTGRES_DATABASE'; then - bashio::log.info "Using postgres" + bashio::log.info "Using postgres" - bashio::config.has_value 'DB_CLIENT' && export DB_CLIENT=$(bashio::config 'DB_CLIENT') && bashio::log.info 'Database client set' - bashio::config.has_value 'POSTGRES_PASSWORD' && export POSTGRES_PASSWORD=$(bashio::config 'POSTGRES_PASSWORD') && bashio::log.info 'Postgrep Password set' - bashio::config.has_value 'POSTGRES_DATABASE' && export POSTGRES_DATABASE=$(bashio::config 'POSTGRES_DATABASE') && bashio::log.info 'Postgrep Database set' - bashio::config.has_value 'POSTGRES_USER' && export POSTGRES_USER=$(bashio::config 'POSTGRES_USER') && bashio::log.info 'Postgrep User set' - bashio::config.has_value 'POSTGRES_PORT' && export POSTGRES_PORT=$(bashio::config 'POSTGRES_PORT') && bashio::log.info 'Postgrep Port set' - bashio::config.has_value 'POSTGRES_HOST' && export POSTGRES_HOST=$(bashio::config 'POSTGRES_HOST') && bashio::log.info 'Postgrep Host set' + bashio::config.has_value 'DB_CLIENT' && export DB_CLIENT=$(bashio::config 'DB_CLIENT') && bashio::log.info 'Database client set' + bashio::config.has_value 'POSTGRES_PASSWORD' && export POSTGRES_PASSWORD=$(bashio::config 'POSTGRES_PASSWORD') && bashio::log.info 'Postgrep Password set' + bashio::config.has_value 'POSTGRES_DATABASE' && export POSTGRES_DATABASE=$(bashio::config 'POSTGRES_DATABASE') && bashio::log.info 'Postgrep Database set' + bashio::config.has_value 'POSTGRES_USER' && export POSTGRES_USER=$(bashio::config 'POSTGRES_USER') && bashio::log.info 'Postgrep User set' + bashio::config.has_value 'POSTGRES_PORT' && export POSTGRES_PORT=$(bashio::config 'POSTGRES_PORT') && bashio::log.info 'Postgrep Port set' + bashio::config.has_value 'POSTGRES_HOST' && export POSTGRES_HOST=$(bashio::config 'POSTGRES_HOST') && bashio::log.info 'Postgrep Host set' else - bashio::log.info "Using sqlite" + bashio::log.info "Using sqlite" fi diff --git a/kometa/rootfs/etc/cont-init.d/20-configuration.sh b/kometa/rootfs/etc/cont-init.d/20-configuration.sh index 22072d57c..34ffd6c3d 100755 --- a/kometa/rootfs/etc/cont-init.d/20-configuration.sh +++ b/kometa/rootfs/etc/cont-init.d/20-configuration.sh @@ -13,8 +13,8 @@ PUID=$(bashio::config 'PUID') PGID=$(bashio::config 'PGID') if [ ! -d "$(dirname "${CONFIGSOURCE}")" ]; then - echo "Creating $(dirname "${CONFIGSOURCE}")" - mkdir -p "$(dirname "${CONFIGSOURCE}")" + echo "Creating $(dirname "${CONFIGSOURCE}")" + mkdir -p "$(dirname "${CONFIGSOURCE}")" fi chown -R "$PUID":"$PGID" "$(dirname "${CONFIGSOURCE}")" @@ -25,8 +25,8 @@ chown -R "$PUID":"$PGID" "$(dirname "${CONFIGSOURCE}")" # Check if config file is there, or create one from template if [ -f "$CONFIGSOURCE" ]; then - bashio::log.info "Using config file found in $CONFIGSOURCE" + bashio::log.info "Using config file found in $CONFIGSOURCE" else - cp /templates/config.yml "$(dirname "${CONFIGSOURCE}")" - bashio::log.warning "No config file, creating one from template. Please correct the config.yml file before restarting the addon !" + cp /templates/config.yml "$(dirname "${CONFIGSOURCE}")" + bashio::log.warning "No config file, creating one from template. Please correct the config.yml file before restarting the addon !" fi diff --git a/lidarr/rootfs/etc/cont-init.d/20-folders.sh b/lidarr/rootfs/etc/cont-init.d/20-folders.sh index 6fe943bd1..22ace1813 100755 --- a/lidarr/rootfs/etc/cont-init.d/20-folders.sh +++ b/lidarr/rootfs/etc/cont-init.d/20-folders.sh @@ -3,27 +3,27 @@ set -e if [ ! -d /share/music ]; then - echo "Creating /share/music" - mkdir -p /share/music - chown -R "$PUID:$PGID" /share/music + echo "Creating /share/music" + mkdir -p /share/music + chown -R "$PUID:$PGID" /share/music fi if [ ! -d /share/downloads ]; then - echo "Creating /share/downloads" - mkdir -p /share/downloads - chown -R "$PUID:$PGID" /share/downloads + echo "Creating /share/downloads" + mkdir -p /share/downloads + chown -R "$PUID:$PGID" /share/downloads fi if [ -d /config/lidarr ] && [ ! -d /config/addons_config/lidarr ]; then - echo "Moving to new location /config/addons_config/lidarr" - mkdir -p /config/addons_config/lidarr - chmod 777 /config/addons_config/lidarr - mv /config/lidarr/* /config/addons_config/lidarr/ - rm -r /config/lidarr + echo "Moving to new location /config/addons_config/lidarr" + mkdir -p /config/addons_config/lidarr + chmod 777 /config/addons_config/lidarr + mv /config/lidarr/* /config/addons_config/lidarr/ + rm -r /config/lidarr fi if [ ! -d /config/addons_config/lidarr ]; then - echo "Creating /config/addons_config/lidarr" - mkdir -p /config/addons_config/lidarr - chmod 777 /config/addons_config/lidarr + echo "Creating /config/addons_config/lidarr" + mkdir -p /config/addons_config/lidarr + chmod 777 /config/addons_config/lidarr fi diff --git a/linkwarden/rootfs/etc/cont-init.d/99-run.sh b/linkwarden/rootfs/etc/cont-init.d/99-run.sh index 83c4da809..2448ad618 100755 --- a/linkwarden/rootfs/etc/cont-init.d/99-run.sh +++ b/linkwarden/rootfs/etc/cont-init.d/99-run.sh @@ -15,33 +15,33 @@ mkdir -p "$STORAGE_FOLDER" bashio::log.info "Setting postgres..." if [[ "$DATABASE_URL" == *"localhost"* ]]; then - echo "... with local database" - echo "... set database in /config/postgres" - mkdir -p /config/postgres - mkdir -p /var/run/postgresql - chown postgres:postgres /var/run/postgresql - chown -R postgres:postgres /config/postgres - chmod 0700 /config/postgres - # Create folder - if [ ! -e /config/postgres/postgresql.conf ]; then - echo "... init folder" - sudo -u postgres /usr/lib/postgresql/16/bin/initdb -D /config/postgres - fi - chown -R postgres:postgres /config/postgres - chmod 0700 /config/postgres + echo "... with local database" + echo "... set database in /config/postgres" + mkdir -p /config/postgres + mkdir -p /var/run/postgresql + chown postgres:postgres /var/run/postgresql + chown -R postgres:postgres /config/postgres + chmod 0700 /config/postgres + # Create folder + if [ ! -e /config/postgres/postgresql.conf ]; then + echo "... init folder" + sudo -u postgres /usr/lib/postgresql/16/bin/initdb -D /config/postgres + fi + chown -R postgres:postgres /config/postgres + chmod 0700 /config/postgres - echo "... starting server" - sudo -u postgres service postgresql start - sleep 5 + echo "... starting server" + sudo -u postgres service postgresql start + sleep 5 - echo "... create user and table" - # Set password - sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'homeassistant';" + echo "... create user and table" + # Set password + sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'homeassistant';" - # Create database if does not exist - echo "CREATE DATABASE linkwarden; GRANT ALL PRIVILEGES ON DATABASE linkwarden to postgres; - \q"> setup_postgres.sql - sudo -u postgres bash -c 'cat setup_postgres.sql | psql "postgres://postgres:homeassistant@localhost:5432"' || true + # Create database if does not exist + echo "CREATE DATABASE linkwarden; GRANT ALL PRIVILEGES ON DATABASE linkwarden to postgres; + \q" >setup_postgres.sql + sudo -u postgres bash -c 'cat setup_postgres.sql | psql "postgres://postgres:homeassistant@localhost:5432"' || true fi ######################## diff --git a/mealie/rootfs/etc/cont-init.d/31-nginx.sh b/mealie/rootfs/etc/cont-init.d/31-nginx.sh index 03036ad1e..056b3d672 100755 --- a/mealie/rootfs/etc/cont-init.d/31-nginx.sh +++ b/mealie/rootfs/etc/cont-init.d/31-nginx.sh @@ -4,21 +4,21 @@ set -e if bashio::config.true 'ssl'; then - bashio::log.info "Add ssl" + bashio::log.info "Add ssl" - # Validate ssl - bashio::config.require.ssl + # Validate ssl + bashio::config.require.ssl - # Adapt nginx template - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') - sed -i "s|%%certfile%%|${certfile}|g" /etc/nginx/servers/ssl.conf - sed -i "s|%%keyfile%%|${keyfile}|g" /etc/nginx/servers/ssl.conf - sed -i "s|9001;|9001 ssl;|g" /etc/nginx/servers/ssl.conf + # Adapt nginx template + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') + sed -i "s|%%certfile%%|${certfile}|g" /etc/nginx/servers/ssl.conf + sed -i "s|%%keyfile%%|${keyfile}|g" /etc/nginx/servers/ssl.conf + sed -i "s|9001;|9001 ssl;|g" /etc/nginx/servers/ssl.conf else - sed -i "/ssl/d" /etc/nginx/servers/ssl.conf + sed -i "/ssl/d" /etc/nginx/servers/ssl.conf fi @@ -35,9 +35,9 @@ sed -i "s|%%base_subpath%%|${base_path}|g" /etc/nginx/servers/ingress.conf sed -i "s|%%base_subpath%%|${base_path}|g" /etc/nginx/servers/ssl.conf if bashio::config.has_value "BASE_URL"; then - BASE_URL="$(bashio::config "BASE_URL")" - BASE_URL="${BASE_URL#*://}:$(bashio::addon.port 9001)" - sed -i "s|%%BASE_URL%%|$BASE_URL|g" /etc/nginx/servers/ssl.conf + BASE_URL="$(bashio::config "BASE_URL")" + BASE_URL="${BASE_URL#*://}:$(bashio::addon.port 9001)" + sed -i "s|%%BASE_URL%%|$BASE_URL|g" /etc/nginx/servers/ssl.conf else - sed -i "/BASE_URL/d" /etc/nginx/servers/ssl.conf + sed -i "/BASE_URL/d" /etc/nginx/servers/ssl.conf fi diff --git a/monica/rootfs/etc/cont-init.d/99-run.sh b/monica/rootfs/etc/cont-init.d/99-run.sh index bd9fa1eac..53291ce9e 100755 --- a/monica/rootfs/etc/cont-init.d/99-run.sh +++ b/monica/rootfs/etc/cont-init.d/99-run.sh @@ -21,74 +21,74 @@ bashio::log.info "Data selected : $database" case "$database" in - # Use sqlite - sqlite) - DB_DATABASE="/config/database.sqlite" - export DB_DATABASE - DB_CONNECTION=sqlite - export DB_CONNECTION - touch "$DB_DATABASE" - mkdir -p /var/www/html/database - ln -sf "$DB_DATABASE" /var/www/html/database/database.sqlite - chown www-data:www-data "$DB_DATABASE" - bashio::log.blue "Using $DB_DATABASE" - ;; +# Use sqlite +sqlite) + DB_DATABASE="/config/database.sqlite" + export DB_DATABASE + DB_CONNECTION=sqlite + export DB_CONNECTION + touch "$DB_DATABASE" + mkdir -p /var/www/html/database + ln -sf "$DB_DATABASE" /var/www/html/database/database.sqlite + chown www-data:www-data "$DB_DATABASE" + bashio::log.blue "Using $DB_DATABASE" + ;; - # Use Mariadb_addon - MariaDB_addon) - # Use MariaDB - DB_CONNECTION=mysql - export DB_CONNECTION - bashio::log.green "Using MariaDB addon. Requirements: running MariaDB addon. Discovering values..." - if ! bashio::services.available 'mysql'; then - bashio::log.fatal "Local database access should be provided by the MariaDB addon" - bashio::exit.nok "Please ensure it is installed and started" - fi +# Use Mariadb_addon +MariaDB_addon) + # Use MariaDB + DB_CONNECTION=mysql + export DB_CONNECTION + bashio::log.green "Using MariaDB addon. Requirements: running MariaDB addon. Discovering values..." + if ! bashio::services.available 'mysql'; then + bashio::log.fatal "Local database access should be provided by the MariaDB addon" + bashio::exit.nok "Please ensure it is installed and started" + fi - # Use values - DB_HOST=$(bashio::services "mysql" "host") && bashio::log.blue "DB_HOST=$DB_HOST" && sed -i "1a export DB_HOST=$DB_HOST" /usr/local/bin/entrypoint.sh - DB_PORT=$(bashio::services "mysql" "port") && bashio::log.blue "DB_PORT=$DB_PORT" && sed -i "1a export DB_PORT=$DB_PORT" /usr/local/bin/entrypoint.sh - DB_DATABASE=monica && bashio::log.blue "DB_DATABASE=$DB_DATABASE" && sed -i "1a export DB_DATABASE=$DB_DATABASE" /usr/local/bin/entrypoint.sh - DB_USERNAME=$(bashio::services "mysql" "username") && bashio::log.blue "DB_USERNAME=$DB_USERNAME" && sed -i "1a export DB_USERNAME=$DB_USERNAME" /usr/local/bin/entrypoint.sh - DB_PASSWORD=$(bashio::services "mysql" "password") && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD" && sed -i "1a export DB_PASSWORD=$DB_PASSWORD" /usr/local/bin/entrypoint.sh - export DB_HOST - export DB_PORT - export DB_DATABASE - export DB_USERNAME - export DB_PASSWORD + # Use values + DB_HOST=$(bashio::services "mysql" "host") && bashio::log.blue "DB_HOST=$DB_HOST" && sed -i "1a export DB_HOST=$DB_HOST" /usr/local/bin/entrypoint.sh + DB_PORT=$(bashio::services "mysql" "port") && bashio::log.blue "DB_PORT=$DB_PORT" && sed -i "1a export DB_PORT=$DB_PORT" /usr/local/bin/entrypoint.sh + DB_DATABASE=monica && bashio::log.blue "DB_DATABASE=$DB_DATABASE" && sed -i "1a export DB_DATABASE=$DB_DATABASE" /usr/local/bin/entrypoint.sh + DB_USERNAME=$(bashio::services "mysql" "username") && bashio::log.blue "DB_USERNAME=$DB_USERNAME" && sed -i "1a export DB_USERNAME=$DB_USERNAME" /usr/local/bin/entrypoint.sh + DB_PASSWORD=$(bashio::services "mysql" "password") && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD" && sed -i "1a export DB_PASSWORD=$DB_PASSWORD" /usr/local/bin/entrypoint.sh + export DB_HOST + export DB_PORT + export DB_DATABASE + export DB_USERNAME + export DB_PASSWORD - bashio::log.warning "Monica is using the MariaDB addon" - bashio::log.warning "Please ensure this is included in your backups" - bashio::log.warning "Uninstalling the MariaDB addon will remove any data" + bashio::log.warning "Monica is using the MariaDB addon" + bashio::log.warning "Please ensure this is included in your backups" + bashio::log.warning "Uninstalling the MariaDB addon will remove any data" - # Create database - mysql --host="$DB_HOST" --port="$DB_PORT" --user="$DB_USERNAME" --password="$DB_PASSWORD" -e"CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" + # Create database + mysql --host="$DB_HOST" --port="$DB_PORT" --user="$DB_USERNAME" --password="$DB_PASSWORD" -e"CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" - ;; + ;; - # Use Mariadb_addon - Mysql_external) - DB_CONNECTION=mysql - export DB_CONNECTION - for var in DB_DATABASE DB_HOST DB_PASSWORD DB_PORT DB_USERNAME; do - # Verify all variables are set - if ! bashio::config.has_value "$var"; then - bashio::log.fatal "You have selected to not use the automatic MariaDB detection by manually configuring the addon options, but the option $var is not set." - exit 1 - fi - "$var=$(bashio::config "var")" - export "${var?}" - bashio::log.blue "$var=$(bashio::config "var")" - done - # Alert if MariaDB is available - if bashio::services.available 'mysql'; then - bashio::log.warning "The MariaDB addon is available, but you have selected to use your own database by manually configuring the addon options" - fi +# Use Mariadb_addon +Mysql_external) + DB_CONNECTION=mysql + export DB_CONNECTION + for var in DB_DATABASE DB_HOST DB_PASSWORD DB_PORT DB_USERNAME; do + # Verify all variables are set + if ! bashio::config.has_value "$var"; then + bashio::log.fatal "You have selected to not use the automatic MariaDB detection by manually configuring the addon options, but the option $var is not set." + exit 1 + fi + "$var=$(bashio::config "var")" + export "${var?}" + bashio::log.blue "$var=$(bashio::config "var")" + done + # Alert if MariaDB is available + if bashio::services.available 'mysql'; then + bashio::log.warning "The MariaDB addon is available, but you have selected to use your own database by manually configuring the addon options" + fi - # Create database - mysql --host="$DB_HOST" --port="$DB_PORT" --user="$DB_USERNAME" --password="$DB_PASSWORD" -e"CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" + # Create database + mysql --host="$DB_HOST" --port="$DB_PORT" --user="$DB_USERNAME" --password="$DB_PASSWORD" -e"CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" - ;; + ;; esac @@ -101,11 +101,14 @@ APP_KEY=$(bashio::config "APP_KEY") # Check if APP_KEY is not 32 characters long if [ -z "$APP_KEY" ] || [ ${#APP_KEY} -lt 32 ]; then - APP_KEY="$(echo -n 'base64:'; openssl rand -base64 32)" - bashio::addon.option "APP_KEY" "${APP_KEY}" - bashio::log.warning "The APP_KEY set was invalid, generated a random one: ${APP_KEY}. Restarting to take it into account" - echo "${APP_KEY}" >> /config/APP_KEY - bashio::addon.restart + APP_KEY="$( + echo -n 'base64:' + openssl rand -base64 32 + )" + bashio::addon.option "APP_KEY" "${APP_KEY}" + bashio::log.warning "The APP_KEY set was invalid, generated a random one: ${APP_KEY}. Restarting to take it into account" + echo "${APP_KEY}" >>/config/APP_KEY + bashio::addon.restart fi APP_KEY="$(bashio::config "APP_KEY")" export APP_KEY diff --git a/navidrome/rootfs/etc/cont-init.d/99-run.sh b/navidrome/rootfs/etc/cont-init.d/99-run.sh index 8e0813568..d1b59deb7 100755 --- a/navidrome/rootfs/etc/cont-init.d/99-run.sh +++ b/navidrome/rootfs/etc/cont-init.d/99-run.sh @@ -18,54 +18,53 @@ ND_BASEURL=$(bashio::config 'base_url') export ND_BASEURL if bashio::config.true 'ssl'; then - bashio::log.info "ssl is enabled" - ND_TLSCERT=$(bashio::config 'certfile') - export ND_TLSCERT - ND_TLSKEY=$(bashio::config 'keyfile') - export ND_TLSKEY + bashio::log.info "ssl is enabled" + ND_TLSCERT=$(bashio::config 'certfile') + export ND_TLSCERT + ND_TLSKEY=$(bashio::config 'keyfile') + export ND_TLSKEY fi if bashio::config.has_value 'default_language'; then - ND_DEFAULTLANGUAGE=$(bashio::config 'default_language') - export ND_DEFAULTLANGUAGE + ND_DEFAULTLANGUAGE=$(bashio::config 'default_language') + export ND_DEFAULTLANGUAGE fi if bashio::config.has_value 'image_cache_size'; then - ND_IMAGECACHESIZE=$(bashio::config 'image_cache_size') - export ND_IMAGECACHESIZE + ND_IMAGECACHESIZE=$(bashio::config 'image_cache_size') + export ND_IMAGECACHESIZE fi if bashio::config.has_value 'lastfm_api_key'; then - ND_LASTFM_APIKEY=$(bashio::config 'lastfm_api_key') - export ND_LASTFM_APIKEY + ND_LASTFM_APIKEY=$(bashio::config 'lastfm_api_key') + export ND_LASTFM_APIKEY fi if bashio::config.has_value 'lastfm_secret'; then - ND_LASTFM_SECRET=$(bashio::config 'lastfm_secret') - export ND_LASTFM_SECRET + ND_LASTFM_SECRET=$(bashio::config 'lastfm_secret') + export ND_LASTFM_SECRET fi if bashio::config.has_value 'password_encryption_key'; then - ND_PASSWORDENCRYPTIONKEY=$(bashio::config 'password_encryption_key') - export ND_PASSWORDENCRYPTIONKEY + ND_PASSWORDENCRYPTIONKEY=$(bashio::config 'password_encryption_key') + export ND_PASSWORDENCRYPTIONKEY fi if bashio::config.has_value 'scan_schedule'; then - ND_SCANSCHEDULE=$(bashio::config 'scan_schedule') - export ND_SCANSCHEDULE + ND_SCANSCHEDULE=$(bashio::config 'scan_schedule') + export ND_SCANSCHEDULE fi if bashio::config.has_value 'spotify_id'; then - ND_SPOTIFY_ID=$(bashio::config 'spotify_id') - export ND_SPOTIFY_ID + ND_SPOTIFY_ID=$(bashio::config 'spotify_id') + export ND_SPOTIFY_ID fi if bashio::config.has_value 'spotify_secret'; then - ND_SPOTIFY_SECRET=$(bashio::config 'spotify_secret') - export ND_SPOTIFY_SECRET + ND_SPOTIFY_SECRET=$(bashio::config 'spotify_secret') + export ND_SPOTIFY_SECRET fi if bashio::config.has_value 'transcoding_cache_size'; then - ND_TRANSCODINGCACHESIZE=$(bashio::config 'transcoding_cache_size') - export ND_TRANSCODINGCACHESIZE + ND_TRANSCODINGCACHESIZE=$(bashio::config 'transcoding_cache_size') + export ND_TRANSCODINGCACHESIZE fi if bashio::config.has_value 'welcome_message'; then - ND_UIWELCOMEMESSAGE=$(bashio::config 'welcome_message') - export ND_UIWELCOMEMESSAGE + ND_UIWELCOMEMESSAGE=$(bashio::config 'welcome_message') + export ND_UIWELCOMEMESSAGE fi - ############## # LAUNCH APP # ############## diff --git a/netalertx/rootfs/etc/cont-init.d/99-run.sh b/netalertx/rootfs/etc/cont-init.d/99-run.sh index fa2061df3..efdf71125 100755 --- a/netalertx/rootfs/etc/cont-init.d/99-run.sh +++ b/netalertx/rootfs/etc/cont-init.d/99-run.sh @@ -11,20 +11,20 @@ bashio::log.info "Update structure" # In the addon script, make symlinks on the fly echo "Creating symlinks" for folder in config db; do - echo "Creating for $folder" - # Create symlinks - mkdir -p /config/"$folder" - if [ -d /app/"$folder" ] && [ "$(ls -A /app/"$folder")" ]; then - cp -rn /app/"$folder"/* /config/"$folder"/ - fi - rm -r /app/"$folder" - ln -sf /config/"$folder" /app/"$folder" + echo "Creating for $folder" + # Create symlinks + mkdir -p /config/"$folder" + if [ -d /app/"$folder" ] && [ "$(ls -A /app/"$folder")" ]; then + cp -rn /app/"$folder"/* /config/"$folder"/ + fi + rm -r /app/"$folder" + ln -sf /config/"$folder" /app/"$folder" done sudo chown -R nginx:www-data /config/db/ sudo chown -R nginx:www-data /config/config/ if [ -f /config/db/app.db ]; then - chmod a+rwx /config/db/app.db + chmod a+rwx /config/db/app.db fi ##################### @@ -36,65 +36,66 @@ config_file="/config/config/app.conf" # Function to execute the main logic execute_main_logic() { - bashio::log.info "Initiating scan of Home Assistant network configuration..." + bashio::log.info "Initiating scan of Home Assistant network configuration..." - # Get the local IPv4 address - local_ip="$(bashio::network.ipv4_address)" - local_ip="${local_ip%/*}" # Remove CIDR notation - echo "... Detected local IP: $local_ip" - echo "... Scanning network for changes" + # Get the local IPv4 address + local_ip="$(bashio::network.ipv4_address)" + local_ip="${local_ip%/*}" # Remove CIDR notation + echo "... Detected local IP: $local_ip" + echo "... Scanning network for changes" - # Ensure arp-scan is installed - if ! command -v arp-scan &>/dev/null; then - bashio::log.error "arp-scan command not found. Please install arp-scan to proceed." - exit 1 - fi + # Ensure arp-scan is installed + if ! command -v arp-scan &>/dev/null; then + bashio::log.error "arp-scan command not found. Please install arp-scan to proceed." + exit 1 + fi - # Get current settings - if ! grep -q "^SCAN_SUBNETS" "$config_file"; then - bashio::log.fatal "SCAN_SUBNETS is not found in your $config_file, please correct your file first" - fi + # Get current settings + if ! grep -q "^SCAN_SUBNETS" "$config_file"; then + bashio::log.fatal "SCAN_SUBNETS is not found in your $config_file, please correct your file first" + fi - # Iterate over network interfaces - for interface in $(bashio::network.interfaces); do - echo "Scanning interface: $interface" + # Iterate over network interfaces + for interface in $(bashio::network.interfaces); do + echo "Scanning interface: $interface" - # Check if the interface is already configured - if grep -q "$interface" "$config_file"; then - echo "... $interface is already configured in app.conf" - else - # Update SCAN_SUBNETS in app.conf - SCAN_SUBNETS="$(grep "^SCAN_SUBNETS" "$config_file" | head -1)" - if [[ "$SCAN_SUBNETS" != *"$local_ip"*"$interface"* ]]; then - # Add to the app.conf - NEW_SCAN_SUBNETS="${SCAN_SUBNETS%]}, '${local_ip}/24 --interface=${interface}']" - sed -i "/^SCAN_SUBNETS/c\\$NEW_SCAN_SUBNETS" "$config_file" - # Check availability of hosts - VALUE="$(arp-scan --interface="$interface" "${local_ip}/24" 2>/dev/null \ - | grep "responded" \ - | awk -F'.' '{print $NF}' \ - | awk '{print $1}' || true)" - echo "... $interface is available in Home Assistant (with $VALUE devices), added to app.conf" - fi - fi - done + # Check if the interface is already configured + if grep -q "$interface" "$config_file"; then + echo "... $interface is already configured in app.conf" + else + # Update SCAN_SUBNETS in app.conf + SCAN_SUBNETS="$(grep "^SCAN_SUBNETS" "$config_file" | head -1)" + if [[ "$SCAN_SUBNETS" != *"$local_ip"*"$interface"* ]]; then + # Add to the app.conf + NEW_SCAN_SUBNETS="${SCAN_SUBNETS%]}, '${local_ip}/24 --interface=${interface}']" + sed -i "/^SCAN_SUBNETS/c\\$NEW_SCAN_SUBNETS" "$config_file" + # Check availability of hosts + VALUE="$(arp-scan --interface="$interface" "${local_ip}/24" 2>/dev/null | + grep "responded" | + awk -F'.' '{print $NF}' | + awk '{print $1}' || true)" + echo "... $interface is available in Home Assistant (with $VALUE devices), added to app.conf" + fi + fi + done - bashio::log.info "Network scan completed." + bashio::log.info "Network scan completed." } # Function to wait for the config file wait_for_config_file() { - echo "Waiting for $config_file to become available..." - while [ ! -f "$config_file" ]; do - sleep 5 # Wait for 5 seconds before checking again - done - echo "$config_file is now available. Starting the script." - execute_main_logic + echo "Waiting for $config_file to become available..." + while [ ! -f "$config_file" ]; do + sleep 5 # Wait for 5 seconds before checking again + done + echo "$config_file is now available. Starting the script." + execute_main_logic } # Main script logic if [ -f "$config_file" ]; then - execute_main_logic + execute_main_logic else - wait_for_config_file & true + wait_for_config_file & + true fi diff --git a/nextcloud/rootfs/defaults/nextcloud-perms.sh b/nextcloud/rootfs/defaults/nextcloud-perms.sh index 09a86cb6e..0e10bee5e 100755 --- a/nextcloud/rootfs/defaults/nextcloud-perms.sh +++ b/nextcloud/rootfs/defaults/nextcloud-perms.sh @@ -8,7 +8,7 @@ set -e echo "Cleaning files" for var in /data/config/nginx /data/config/crontabs /data/config/logs; do - if [ -d "$var" ]; then rm -r "$var"; fi + if [ -d "$var" ]; then rm -r "$var"; fi done ######################## @@ -22,10 +22,10 @@ rootuser='root' printf "Creating possible missing Directories\n" for folder in "$ocpath"/data "$ocpath"/assets "$ocpath"/updater "$ocpath"/apps "$ocpath"/assets "$ocpath"/config "$ocpath"/data "$ocpath"/themes /data/config/nextcloud/config /data/config/nextcloud/data /ssl/nextcloud/keys; do - if [ ! -d "$folder" ]; then - echo "... $folder" - mkdir -p "$folder" || true - fi + if [ ! -d "$folder" ]; then + echo "... $folder" + mkdir -p "$folder" || true + fi done printf "chmod Files and Directories. This could take some time, please wait...\n" @@ -39,17 +39,17 @@ find "${ocpath}"/ -type d -exec chmod 0750 {} \; printf "chown Directories. This could take some time, please wait...\n" chown -R ${rootuser}:${htgroup} "${ocpath}"/ for folder in "${ocpath}"/apps/ "${ocpath}"/assets/ "${ocpath}"/config/ "${ocpath}"/data/ "${ocpath}"/themes/ /ssl/nextcloud/keys; do - chown -R ${htuser}:${htgroup} "$folder" || true + chown -R ${htuser}:${htgroup} "$folder" || true done printf "chmod/chown .htaccess\n" if [ -f "${ocpath}"/.htaccess ]; then - chmod 0644 "${ocpath}"/.htaccess - chown "${rootuser}":"${htgroup}" "${ocpath}"/.htaccess + chmod 0644 "${ocpath}"/.htaccess + chown "${rootuser}":"${htgroup}" "${ocpath}"/.htaccess fi if [ -f "${ocpath}"/data/.htaccess ]; then - chmod 0644 "${ocpath}"/data/.htaccess - chown "${rootuser}":"${htgroup}" "${ocpath}"/data/.htaccess + chmod 0644 "${ocpath}"/data/.htaccess + chown "${rootuser}":"${htgroup}" "${ocpath}"/data/.htaccess fi diff --git a/nextcloud/rootfs/etc/cont-init.d/00-migrate_files.sh b/nextcloud/rootfs/etc/cont-init.d/00-migrate_files.sh index c542086ce..b177a128b 100755 --- a/nextcloud/rootfs/etc/cont-init.d/00-migrate_files.sh +++ b/nextcloud/rootfs/etc/cont-init.d/00-migrate_files.sh @@ -3,12 +3,12 @@ # Migrate files for new config location slug="nextcloud-ocr" if [ -f "/homeassistant/addons_config/$slug/config.yaml" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then - bashio::log.warning "Migrating config.yaml" - mv "/homeassistant/addons_config/$slug"/* /config/ || true - echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" > "/homeassistant/addons_config/$slug/migrated" + bashio::log.warning "Migrating config.yaml" + mv "/homeassistant/addons_config/$slug"/* /config/ || true + echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" >"/homeassistant/addons_config/$slug/migrated" fi if [ -f "/homeassistant/addons_autoscripts/$slug.sh" ]; then - bashio::log.warning "Migrating autoscript" - mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true + bashio::log.warning "Migrating autoscript" + mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true fi diff --git a/nextcloud/rootfs/etc/cont-init.d/01-folders.sh b/nextcloud/rootfs/etc/cont-init.d/01-folders.sh index bac38eed8..4c069fe94 100755 --- a/nextcloud/rootfs/etc/cont-init.d/01-folders.sh +++ b/nextcloud/rootfs/etc/cont-init.d/01-folders.sh @@ -3,11 +3,11 @@ set -e if bashio::config.has_value "PUID" && bashio::config.has_value "PGID"; then - PUID="$(bashio::config "PUID")" - PGID="$(bashio::config "PGID")" - bashio::log.green "Setting user to $PUID:$PGID" - id -u abc &>/dev/null || usermod -o -u "$PUID" abc || true - id -g abc &>/dev/null || groupmod -o -g "$PGID" abc || true + PUID="$(bashio::config "PUID")" + PGID="$(bashio::config "PGID")" + bashio::log.green "Setting user to $PUID:$PGID" + id -u abc &>/dev/null || usermod -o -u "$PUID" abc || true + id -g abc &>/dev/null || groupmod -o -g "$PGID" abc || true fi echo "Updating permissions..." @@ -18,44 +18,44 @@ chown -R "$PUID:$PGID" "/data/config" # Check current version if [ -f /data/config/www/nextcloud/config/config.php ]; then - datadirectory="$(sed -n "s|.*datadirectory.*' => '*\(.*[^ ]\) *',.*|\1|p" /data/config/www/nextcloud/config/config.php)" - echo "... data directory detected : $datadirectory" + datadirectory="$(sed -n "s|.*datadirectory.*' => '*\(.*[^ ]\) *',.*|\1|p" /data/config/www/nextcloud/config/config.php)" + echo "... data directory detected : $datadirectory" else - datadirectory=/config/data - echo "Nextcloud is not installed yet, the default data directory is : $datadirectory. You can change it during nextcloud installation." - mkdir -p /config/data - chmod 777 /config/data - mkdir -p /share/nextcloud - chmod 777 /share/nextcloud + datadirectory=/config/data + echo "Nextcloud is not installed yet, the default data directory is : $datadirectory. You can change it during nextcloud installation." + mkdir -p /config/data + chmod 777 /config/data + mkdir -p /share/nextcloud + chmod 777 /share/nextcloud fi # Is the directory valid if [[ "$datadirectory" == *"/mnt/"* ]] && [ ! -f "$datadirectory"/index.html ]; then - bashio::log.fatal "Data directory does not seem to be valid. Is your drive connected? Stopping to avoid corrupting the data directory." - bashio::addon.stop + bashio::log.fatal "Data directory does not seem to be valid. Is your drive connected? Stopping to avoid corrupting the data directory." + bashio::addon.stop fi # Remove nginx conf if existing if [ -f /data/config/nginx/site-confs/default.conf ]; then - rm /data/config/nginx/site-confs/default.conf - # Avoid cannot enable app - sed -i "s|front_controller_active true|front_controller_active false|g" /defaults/nginx/site-confs/default.conf.sample + rm /data/config/nginx/site-confs/default.conf + # Avoid cannot enable app + sed -i "s|front_controller_active true|front_controller_active false|g" /defaults/nginx/site-confs/default.conf.sample fi # Set permissions mkdir -p "$datadirectory" if bashio::config.true "skip_permissions_check"; then - bashio::log.yellow "--------------------------------------------" - bashio::log.yellow "Permissions check skipped : \"skip_permissions_check\" is true" - bashio::log.yellow "--------------------------------------------" + bashio::log.yellow "--------------------------------------------" + bashio::log.yellow "Permissions check skipped : \"skip_permissions_check\" is true" + bashio::log.yellow "--------------------------------------------" elif [[ "$PUID" = "0" ]] && [[ "$PGID" = "0" ]]; then - bashio::log.yellow "--------------------------------------------" - bashio::log.yellow "Permissions check skipped : \"PUID and PGID are 0\" is true" - bashio::log.yellow "--------------------------------------------" + bashio::log.yellow "--------------------------------------------" + bashio::log.yellow "Permissions check skipped : \"PUID and PGID are 0\" is true" + bashio::log.yellow "--------------------------------------------" else - bashio::log.yellow "... setting permissions, this might take a long time. If it takes too long at each boot, you could instead activate skip_permissions_check in the addon options" - chmod 755 -R "$datadirectory" || true - chown -R "$PUID:$PGID" "$datadirectory" || true + bashio::log.yellow "... setting permissions, this might take a long time. If it takes too long at each boot, you could instead activate skip_permissions_check in the addon options" + chmod 755 -R "$datadirectory" || true + chown -R "$PUID:$PGID" "$datadirectory" || true fi mkdir -p /scripts diff --git a/nextcloud/rootfs/etc/cont-init.d/02-init_steps.sh b/nextcloud/rootfs/etc/cont-init.d/02-init_steps.sh index 3d7b209d8..77bf299ba 100755 --- a/nextcloud/rootfs/etc/cont-init.d/02-init_steps.sh +++ b/nextcloud/rootfs/etc/cont-init.d/02-init_steps.sh @@ -12,12 +12,12 @@ if [ ! -f /app/www/public/occ ]; then cp /etc/cont-init.d/"$(basename "${BASH_SO echo "Setting logs" for var in /data/config/log/nginx/error.log /data/config/log/nginx/access.log /data/config/log/php/error.log; do - # Make sure directory exists - mkdir -p "$(dirname "$var")" - # Clean files - if [ -f "$var" ]; then rm -r "$var"; fi - # Create symlink - ln -sf /proc/1/fd/1 "$var" + # Make sure directory exists + mkdir -p "$(dirname "$var")" + # Clean files + if [ -f "$var" ]; then rm -r "$var"; fi + # Create symlink + ln -sf /proc/1/fd/1 "$var" done ################ @@ -32,39 +32,39 @@ if [ -f /notinstalled ]; then exit 0; fi # Check current version if [ -f /data/config/www/nextcloud/config/config.php ]; then - CURRENTVERSION="$(sed -n "s|.*version.*' => '*\(.*[^ ]\) *',.*|\1|p" /data/config/www/nextcloud/config/config.php)" + CURRENTVERSION="$(sed -n "s|.*version.*' => '*\(.*[^ ]\) *',.*|\1|p" /data/config/www/nextcloud/config/config.php)" else - CURRENTVERSION="Not found" + CURRENTVERSION="Not found" fi echo " " # If not installed, or files not available if [[ $($LAUNCHER -V 2>&1) == *"not installed"* ]] || [ ! -f /data/config/www/nextcloud/config/config.php ]; then - bashio::log.green "--------------------------------------------------------------------------------------------------------------" - bashio::log.yellow "Nextcloud not installed, please wait for addon startup, login Webui, install Nextcloud, then restart the addon" - bashio::log.green "--------------------------------------------------------------------------------------------------------------" - bashio::log.green " " - touch /notinstalled - exit 0 - # Is there missing files + bashio::log.green "--------------------------------------------------------------------------------------------------------------" + bashio::log.yellow "Nextcloud not installed, please wait for addon startup, login Webui, install Nextcloud, then restart the addon" + bashio::log.green "--------------------------------------------------------------------------------------------------------------" + bashio::log.green " " + touch /notinstalled + exit 0 + # Is there missing files elif [[ $($LAUNCHER -V 2>&1) =~ ^"Nextcloud "[0-9].* ]]; then - # Log - bashio::log.green "----------------------------------------" - bashio::log.green " Nextcloud $CURRENTVERSION is installed " - bashio::log.green "----------------------------------------" - # Tentative to downgrade + # Log + bashio::log.green "----------------------------------------" + bashio::log.green " Nextcloud $CURRENTVERSION is installed " + bashio::log.green "----------------------------------------" + # Tentative to downgrade else - bashio::log.red "-------------------------------------------------" - bashio::log.red " Unknown error detected, auto-repair will launch " - bashio::log.red "-------------------------------------------------" - bashio::log.red "Error message:" - bashio::log.red "$($LAUNCHER -V 2>&1)" - bashio::log.red "------------------------------------------------------------------" - sudo -u abc -s /bin/bash -c "php /app/www/public/occ maintenance:repair" || true - sudo -u abc -s /bin/bash -c "php /app/www/public/occ maintenance:repair-share-owner" || true - sudo -u abc -s /bin/bash -c "php /app/www/public/occ app:update --all" || true - sudo -u abc -s /bin/bash -c "php /app/www/public/occ upgrade" || true + bashio::log.red "-------------------------------------------------" + bashio::log.red " Unknown error detected, auto-repair will launch " + bashio::log.red "-------------------------------------------------" + bashio::log.red "Error message:" + bashio::log.red "$($LAUNCHER -V 2>&1)" + bashio::log.red "------------------------------------------------------------------" + sudo -u abc -s /bin/bash -c "php /app/www/public/occ maintenance:repair" || true + sudo -u abc -s /bin/bash -c "php /app/www/public/occ maintenance:repair-share-owner" || true + sudo -u abc -s /bin/bash -c "php /app/www/public/occ app:update --all" || true + sudo -u abc -s /bin/bash -c "php /app/www/public/occ upgrade" || true fi echo " " @@ -75,10 +75,10 @@ echo " " # Updater apps code if ! bashio::config.true "disable_updates"; then - bashio::log.green "... checking for app updates" - sudo -u abc -s /bin/bash -c "php /app/www/public/occ app:update --all" || true + bashio::log.green "... checking for app updates" + sudo -u abc -s /bin/bash -c "php /app/www/public/occ app:update --all" || true else - bashio::log.yellow "... disable_updates set, apps need to be updated manually" + bashio::log.yellow "... disable_updates set, apps need to be updated manually" fi ########################### @@ -101,8 +101,8 @@ echo "... Remove CODE if installed as not compatible" ################ if bashio::config.has_value "default_phone_region"; then - echo "... Define default_phone_region" - sudo -u abc php /app/www/public/occ config:system:set default_phone_region --value="$(bashio::config "default_phone_region")" + echo "... Define default_phone_region" + sudo -u abc php /app/www/public/occ config:system:set default_phone_region --value="$(bashio::config "default_phone_region")" fi ###################### @@ -111,10 +111,10 @@ fi echo "... Disabling check_data_directory_permissions" for files in /defaults/config.php /data/config/www/nextcloud/config/config.php; do - if [ -f "$files" ]; then - sed -i "/check_data_directory_permissions/d" "$files" - sed -i "/datadirectory/a\ \ 'check_data_directory_permissions' => false," "$files" - fi + if [ -f "$files" ]; then + sed -i "/check_data_directory_permissions/d" "$files" + sed -i "/datadirectory/a\ \ 'check_data_directory_permissions' => false," "$files" + fi done timeout 10 sudo -u abc php /app/www/public/occ config:system:set check_data_directory_permissions --value=false --type=bool || echo "Please install nextcloud first" @@ -123,12 +123,12 @@ timeout 10 sudo -u abc php /app/www/public/occ config:system:set check_data_dire ################## for variable in env_memory_limit env_upload_max_filesize env_post_max_size; do - if bashio::config.has_value "$variable"; then - variable="${variable#env_}" - sed -i "/$variable/c $variable = $(bashio::config "env_$variable")" /etc/php*/conf.d/nextcloud.ini - sed -i "/$variable/c $variable = $(bashio::config "env_$variable")" /etc/php*/php.ini - bashio::log.blue "$variable set to $(bashio::config "env_$variable")" - fi + if bashio::config.has_value "$variable"; then + variable="${variable#env_}" + sed -i "/$variable/c $variable = $(bashio::config "env_$variable")" /etc/php*/conf.d/nextcloud.ini + sed -i "/$variable/c $variable = $(bashio::config "env_$variable")" /etc/php*/php.ini + bashio::log.blue "$variable set to $(bashio::config "env_$variable")" + fi done ##################### @@ -136,19 +136,19 @@ done ##################### if bashio::config.true "enable_thumbnails"; then - echo "... enabling thumbnails" - # Add variables - sudo -u abc php /app/www/public/occ config:system:set preview_ffmpeg_path --value='/usr/bin/ffmpeg' - sudo -u abc php /app/www/public/occ config:system:set enable_previews --value=true - i=0 - for element in AVI BMP Font GIF HEIC Image JPEG Krita MarkDown MKV Movie MP3 MP4 OpenDocument PDF PNG SVG TIFF TXT XBitmap; do # Comma separated values - sudo -u abc php /app/www/public/occ config:system:set enabledPreviewProviders "$i" --value="OC\\Preview\\${element}" >/dev/null - i=$((i + 1)) - done + echo "... enabling thumbnails" + # Add variables + sudo -u abc php /app/www/public/occ config:system:set preview_ffmpeg_path --value='/usr/bin/ffmpeg' + sudo -u abc php /app/www/public/occ config:system:set enable_previews --value=true + i=0 + for element in AVI BMP Font GIF HEIC Image JPEG Krita MarkDown MKV Movie MP3 MP4 OpenDocument PDF PNG SVG TIFF TXT XBitmap; do # Comma separated values + sudo -u abc php /app/www/public/occ config:system:set enabledPreviewProviders "$i" --value="OC\\Preview\\${element}" >/dev/null + i=$((i + 1)) + done else - # Remove variables - echo "... disabling thumbnails" - sudo -u abc php /app/www/public/occ config:system:set enable_previews --value=false + # Remove variables + echo "... disabling thumbnails" + sudo -u abc php /app/www/public/occ config:system:set enable_previews --value=false fi ########################## @@ -156,6 +156,6 @@ fi ########################## if [[ "$(occ config:system:get maintenance_window_start)" == "" ]]; then - echo "... maintenance windows not set, it will be changed to 1" - sudo -u abc php /app/www/public/occ config:system:set maintenance_window_start --type=integer --value=1 + echo "... maintenance windows not set, it will be changed to 1" + sudo -u abc php /app/www/public/occ config:system:set maintenance_window_start --type=integer --value=1 fi diff --git a/nextcloud/rootfs/etc/cont-init.d/02-mariadb_discovery.sh b/nextcloud/rootfs/etc/cont-init.d/02-mariadb_discovery.sh index 426dfcc86..80c3098ba 100755 --- a/nextcloud/rootfs/etc/cont-init.d/02-mariadb_discovery.sh +++ b/nextcloud/rootfs/etc/cont-init.d/02-mariadb_discovery.sh @@ -8,12 +8,12 @@ if [ ! -f /app/www/public/occ ]; then cp /etc/cont-init.d/"$(basename "${BASH_SO if bashio::services.available 'mysql'; then - bashio::log.green "---" - bashio::log.yellow "MariaDB addon was found! It can't be configured automatically due to the way Nextcloud works, but you can configure it manually when running the web UI for the first time using those values :" - bashio::log.blue "Database user : $(bashio::services "mysql" "username")" - bashio::log.blue "Database password : $(bashio::services "mysql" "password")" - bashio::log.blue "Database name : nextcloud" - bashio::log.blue "Host-name : $(bashio::services "mysql" "host"):$(bashio::services "mysql" "port")" - bashio::log.green "---" + bashio::log.green "---" + bashio::log.yellow "MariaDB addon was found! It can't be configured automatically due to the way Nextcloud works, but you can configure it manually when running the web UI for the first time using those values :" + bashio::log.blue "Database user : $(bashio::services "mysql" "username")" + bashio::log.blue "Database password : $(bashio::services "mysql" "password")" + bashio::log.blue "Database name : nextcloud" + bashio::log.blue "Host-name : $(bashio::services "mysql" "host"):$(bashio::services "mysql" "port")" + bashio::log.green "---" fi diff --git a/nextcloud/rootfs/etc/cont-init.d/30-ssl.sh b/nextcloud/rootfs/etc/cont-init.d/30-ssl.sh index 8f6abcbed..e94009e6e 100755 --- a/nextcloud/rootfs/etc/cont-init.d/30-ssl.sh +++ b/nextcloud/rootfs/etc/cont-init.d/30-ssl.sh @@ -4,22 +4,22 @@ set -e if bashio::config.true 'use_own_certs'; then - bashio::log.green "Using referenced ssl certificates" - CERTFILE=$(bashio::config 'certfile') - KEYFILE=$(bashio::config 'keyfile') + bashio::log.green "Using referenced ssl certificates" + CERTFILE=$(bashio::config 'certfile') + KEYFILE=$(bashio::config 'keyfile') - # Validate ssl - bashio::config.require.ssl + # Validate ssl + bashio::config.require.ssl - #Check if files exist - echo "... checking if referenced files exist" - [ ! -f /ssl/"$CERTFILE" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$CERTFILE not found" && bashio::exit.nok - [ ! -f /ssl/"$KEYFILE" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$KEYFILE not found" && bashio::exit.nok + #Check if files exist + echo "... checking if referenced files exist" + [ ! -f /ssl/"$CERTFILE" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$CERTFILE not found" && bashio::exit.nok + [ ! -f /ssl/"$KEYFILE" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$KEYFILE not found" && bashio::exit.nok - [[ -f /data/config/keys/cert.key ]] && rm /data/config/keys/cert.key - [[ -f /data/config/keys/cert.crt ]] && rm /data/config/keys/cert.crt - cp /ssl/"$CERTFILE" /data/config/keys/cert.crt - cp /ssl/"$KEYFILE" /data/config/keys/cert.key - echo "... done" + [[ -f /data/config/keys/cert.key ]] && rm /data/config/keys/cert.key + [[ -f /data/config/keys/cert.crt ]] && rm /data/config/keys/cert.crt + cp /ssl/"$CERTFILE" /data/config/keys/cert.crt + cp /ssl/"$KEYFILE" /data/config/keys/cert.key + echo "... done" fi diff --git a/nextcloud/rootfs/etc/cont-init.d/99-add_packages.sh b/nextcloud/rootfs/etc/cont-init.d/99-add_packages.sh index 13c934ef0..5a6c1c1c2 100755 --- a/nextcloud/rootfs/etc/cont-init.d/99-add_packages.sh +++ b/nextcloud/rootfs/etc/cont-init.d/99-add_packages.sh @@ -8,31 +8,30 @@ if [ ! -f /app/www/public/occ ]; then cp /etc/cont-init.d/"$(basename "${BASH_SO # Install specific packages if [ ! -d /data/config/www/nextcloud/apps/pdfannotate ]; then - CURRENT="$PWD" - cd /data/config/www/nextcloud/apps || exit - git clone https://gitlab.com/nextcloud-other/nextcloud-annotate pdfannotate - cd "$CURRENT" || exit - apk add --no-cache ghostscript >/dev/null - echo "Nextcloud annotate app added to Nextcloud app store" + CURRENT="$PWD" + cd /data/config/www/nextcloud/apps || exit + git clone https://gitlab.com/nextcloud-other/nextcloud-annotate pdfannotate + cd "$CURRENT" || exit + apk add --no-cache ghostscript >/dev/null + echo "Nextcloud annotate app added to Nextcloud app store" fi # Install specific apps if bashio::config.has_value 'additional_apps'; then - bashio::log.info "Installing additional apps :" - NEWAPPS="$(bashio::config 'additional_apps')" - OIFS=$IFS - IFS="," - re='^( *).*' - read -ra array <<< "$NEWAPPS" - IFS=$OIFS - for element in "${array[@]}" - do - if [[ $element =~ $re ]]; then - # shellcheck disable=SC2295 - APP="${element#${BASH_REMATCH[1]}}" - bashio::log.green "... $APP" - # shellcheck disable=SC2015,SC2086 - apk add --no-cache $APP >/dev/null || bashio::log.red "... not successful, please check $APP package name" - fi - done + bashio::log.info "Installing additional apps :" + NEWAPPS="$(bashio::config 'additional_apps')" + OIFS=$IFS + IFS="," + re='^( *).*' + read -ra array <<<"$NEWAPPS" + IFS=$OIFS + for element in "${array[@]}"; do + if [[ $element =~ $re ]]; then + # shellcheck disable=SC2295 + APP="${element#${BASH_REMATCH[1]}}" + bashio::log.green "... $APP" + # shellcheck disable=SC2015,SC2086 + apk add --no-cache $APP >/dev/null || bashio::log.red "... not successful, please check $APP package name" + fi + done fi diff --git a/nextcloud/rootfs/etc/cont-init.d/99-elasticsearch.sh b/nextcloud/rootfs/etc/cont-init.d/99-elasticsearch.sh index bed4d4ec9..fa064af3f 100755 --- a/nextcloud/rootfs/etc/cont-init.d/99-elasticsearch.sh +++ b/nextcloud/rootfs/etc/cont-init.d/99-elasticsearch.sh @@ -16,54 +16,54 @@ PGID=$(bashio::config "PGID") LAUNCHER="sudo -u abc php /app/www/public/occ" if $LAUNCHER fulltextsearch:test &>/dev/null; then - echo "Full Text Search is already working" + echo "Full Text Search is already working" - ############ - # BASED ON # - ################################################################################# - # https://raw.githubusercontent.com/nextcloud/vm/master/apps/fulltextsearch.sh # - # T&M Hansson IT AB © - 2021, https://www.hanssonit.se/ # - # SwITNet Ltd © - 2021, https://switnet.net/ # - ################################################################################# + ############ + # BASED ON # + ################################################################################# + # https://raw.githubusercontent.com/nextcloud/vm/master/apps/fulltextsearch.sh # + # T&M Hansson IT AB © - 2021, https://www.hanssonit.se/ # + # SwITNet Ltd © - 2021, https://switnet.net/ # + ################################################################################# - if bashio::config.true 'Full_Text_Search'; then + if bashio::config.true 'Full_Text_Search'; then - # Get Full Text Search app for nextcloud - echo "Installing Full Text Search" - for app in "${APPS[@]}"; do - echo "... installing apps : $app" - $LAUNCHER app:install $app >/dev/null - $LAUNCHER app:enable $app >/dev/null - done - chown -R "$PUID":"$PGID" $NEXTCLOUD_PATH/apps + # Get Full Text Search app for nextcloud + echo "Installing Full Text Search" + for app in "${APPS[@]}"; do + echo "... installing apps : $app" + $LAUNCHER app:install $app >/dev/null + $LAUNCHER app:enable $app >/dev/null + done + chown -R "$PUID":"$PGID" $NEXTCLOUD_PATH/apps - if bashio::config.has_value 'elasticsearch_server'; then - HOST=$(bashio::config 'elasticsearch_server') - else - bashio::log.warning 'Please define elasticsearch server url in addon options. Default value of http://db21ed7f-elasticsearch:9200 will be used' - HOST=http://db21ed7f-elasticsearch:9200 - fi + if bashio::config.has_value 'elasticsearch_server'; then + HOST=$(bashio::config 'elasticsearch_server') + else + bashio::log.warning 'Please define elasticsearch server url in addon options. Default value of http://db21ed7f-elasticsearch:9200 will be used' + HOST=http://db21ed7f-elasticsearch:9200 + fi - # Final setup - echo "... settings apps" - $LAUNCHER fulltextsearch_elasticsearch:configure "{\"elastic_host\":\"$HOST\"}" &>/dev/null - $LAUNCHER fulltextsearch_elasticsearch:configure "{\"elastic_index\":\"my_index\"}" &>/dev/null - $LAUNCHER fulltextsearch_elasticsearch:configure "{\"analyzer_tokenizer\":\"standard\"}" &>/dev/null - $LAUNCHER fulltextsearch:configure '{"search_platform":"OCA\\FullTextSearch_Elasticsearch\\Platform\\ElasticSearchPlatform"}' &>/dev/null || true - $LAUNCHER files_fulltextsearch:configure "{\"files_pdf\":\"1\",\"files_office\":\"1\"}" &>/dev/null || true + # Final setup + echo "... settings apps" + $LAUNCHER fulltextsearch_elasticsearch:configure "{\"elastic_host\":\"$HOST\"}" &>/dev/null + $LAUNCHER fulltextsearch_elasticsearch:configure "{\"elastic_index\":\"my_index\"}" &>/dev/null + $LAUNCHER fulltextsearch_elasticsearch:configure "{\"analyzer_tokenizer\":\"standard\"}" &>/dev/null + $LAUNCHER fulltextsearch:configure '{"search_platform":"OCA\\FullTextSearch_Elasticsearch\\Platform\\ElasticSearchPlatform"}' &>/dev/null || true + $LAUNCHER files_fulltextsearch:configure "{\"files_pdf\":\"1\",\"files_office\":\"1\"}" &>/dev/null || true - # Is server detected - # Wait further for cache for index to work - echo "Waiting for a few seconds before indexing starts..." - sleep 5s - if $LAUNCHER fulltextsearch:test &>/dev/null; then - bashio::log.info "Full Text Search was successfully installed using elasticsearch server $HOST!" + # Is server detected + # Wait further for cache for index to work + echo "Waiting for a few seconds before indexing starts..." + sleep 5s + if $LAUNCHER fulltextsearch:test &>/dev/null; then + bashio::log.info "Full Text Search was successfully installed using elasticsearch server $HOST!" - else + else - bashio::log.warning "Elasticsearch can't connect. Please manually define its server in the options" - fi - else - echo "Full_Text_Search option not set" - fi + bashio::log.warning "Elasticsearch can't connect. Please manually define its server in the options" + fi + else + echo "Full_Text_Search option not set" + fi fi diff --git a/nextcloud/rootfs/etc/cont-init.d/99-ocr.sh b/nextcloud/rootfs/etc/cont-init.d/99-ocr.sh index 7407cf7de..9846f791d 100755 --- a/nextcloud/rootfs/etc/cont-init.d/99-ocr.sh +++ b/nextcloud/rootfs/etc/cont-init.d/99-ocr.sh @@ -11,36 +11,36 @@ if [ -f /notinstalled ]; then exit 0; fi # Install OCR if requested if [ "$(bashio::config 'OCR')" = "true" ]; then - # Install package - if bashio::config.true 'OCR'; then + # Install package + if bashio::config.true 'OCR'; then - # Get Full Text Search app for nextcloud - echo "... installing apps : fulltextsearch" - occ app:install files_fulltextsearch_tesseract &>/dev/null || true - occ app:enable files_fulltextsearch_tesseract &>/dev/null || true + # Get Full Text Search app for nextcloud + echo "... installing apps : fulltextsearch" + occ app:install files_fulltextsearch_tesseract &>/dev/null || true + occ app:enable files_fulltextsearch_tesseract &>/dev/null || true - echo "Installing OCR" - apk add --quiet --no-cache ocrmypdf - apk add --quiet --no-cache tesseract-ocr || apk add --quiet --no-cache tesseract-ocr@community - # Install additional language if requested - if bashio::config.has_value 'OCRLANG'; then - OCRLANG=$(bashio::config 'OCRLANG') - for LANG in $(echo "$OCRLANG" | tr "," " "); do - if [ "$LANG" != "eng" ]; then - apk add --quiet --no-cache tesseract-ocr-data-"$LANG" || apk add --quiet --no-cache tesseract-ocr-data-"$LANG"@community - fi - bashio::log.info "OCR Language installed : $LANG" || bashio::log.fatal "Couldn't install OCR lang $LANG. Please check its format is conform" - # Downloading trainer data - cd /usr/share/tessdata || true - rm -r "$LANG".traineddata &>/dev/null || true - wget https://github.com/tesseract-ocr/tessdata/raw/main/"$LANG".traineddata &>/dev/null - done - fi - elif [ "$(bashio::config 'OCR')" = "false" ]; then - bashio::log.info 'Removing OCR' - # Delete package - apk del tesseract-ocr.* &>/dev/null || true - # Remove app - occ app:disable files_fulltextsearch_tesseract &>/dev/null || true - fi + echo "Installing OCR" + apk add --quiet --no-cache ocrmypdf + apk add --quiet --no-cache tesseract-ocr || apk add --quiet --no-cache tesseract-ocr@community + # Install additional language if requested + if bashio::config.has_value 'OCRLANG'; then + OCRLANG=$(bashio::config 'OCRLANG') + for LANG in $(echo "$OCRLANG" | tr "," " "); do + if [ "$LANG" != "eng" ]; then + apk add --quiet --no-cache tesseract-ocr-data-"$LANG" || apk add --quiet --no-cache tesseract-ocr-data-"$LANG"@community + fi + bashio::log.info "OCR Language installed : $LANG" || bashio::log.fatal "Couldn't install OCR lang $LANG. Please check its format is conform" + # Downloading trainer data + cd /usr/share/tessdata || true + rm -r "$LANG".traineddata &>/dev/null || true + wget https://github.com/tesseract-ocr/tessdata/raw/main/"$LANG".traineddata &>/dev/null + done + fi + elif [ "$(bashio::config 'OCR')" = "false" ]; then + bashio::log.info 'Removing OCR' + # Delete package + apk del tesseract-ocr.* &>/dev/null || true + # Remove app + occ app:disable files_fulltextsearch_tesseract &>/dev/null || true + fi fi diff --git a/nextcloud/rootfs/etc/cont-init.d/99-trusted_domains.sh b/nextcloud/rootfs/etc/cont-init.d/99-trusted_domains.sh index 4d7a05f5d..4ab31cd18 100755 --- a/nextcloud/rootfs/etc/cont-init.d/99-trusted_domains.sh +++ b/nextcloud/rootfs/etc/cont-init.d/99-trusted_domains.sh @@ -19,33 +19,33 @@ LAUNCHER="sudo -u abc php /app/www/public/occ" if bashio::config.has_value 'trusted_domains'; then - bashio::log.info "Currently set trusted domains :" - $LAUNCHER config:system:get trusted_domains || bashio::log.info "No trusted domain set yet. The first one will be set when doing initial configuration" + bashio::log.info "Currently set trusted domains :" + $LAUNCHER config:system:get trusted_domains || bashio::log.info "No trusted domain set yet. The first one will be set when doing initial configuration" - bashio::log.info "Trusted domains set in the configuration. Refreshing domains." && - ################################### - # Remove previous trusted domains # - ################################### - bashio::log.info "... removing previously added trusted domain (except for first one created)" - i=2 - until [ $i -gt 5 ]; do - $LAUNCHER config:system:delete trusted_domains $i && - ((i = i + 1)) || exit - done + bashio::log.info "Trusted domains set in the configuration. Refreshing domains." && + ################################### + # Remove previous trusted domains # + ################################### + bashio::log.info "... removing previously added trusted domain (except for first one created)" + i=2 + until [ $i -gt 5 ]; do + $LAUNCHER config:system:delete trusted_domains $i && + ((i = i + 1)) || exit + done - ########################### - # Add new trusted domains # - ########################### - TRUSTEDDOMAINS=$(bashio::config 'trusted_domains') - bashio::log.info "... alignement with trusted domains list : ${TRUSTEDDOMAINS}" - for domain in ${TRUSTEDDOMAINS//,/ }; do # Comma separated values - bashio::log.info "... adding ${domain}" - # shellcheck disable=SC2086 - $LAUNCHER config:system:set trusted_domains $i --value="${domain}" - i=$((i + 1)) - done + ########################### + # Add new trusted domains # + ########################### + TRUSTEDDOMAINS=$(bashio::config 'trusted_domains') + bashio::log.info "... alignement with trusted domains list : ${TRUSTEDDOMAINS}" + for domain in ${TRUSTEDDOMAINS//,/ }; do # Comma separated values + bashio::log.info "... adding ${domain}" + # shellcheck disable=SC2086 + $LAUNCHER config:system:set trusted_domains $i --value="${domain}" + i=$((i + 1)) + done - bashio::log.info "Remaining configurated trusted domains :" - bashio::log.info "$($LAUNCHER config:system:get trusted_domains)" || exit + bashio::log.info "Remaining configurated trusted domains :" + bashio::log.info "$($LAUNCHER config:system:get trusted_domains)" || exit fi diff --git a/nzbget/rootfs/etc/cont-init.d/20-folders.sh b/nzbget/rootfs/etc/cont-init.d/20-folders.sh index b6a77c7d1..a663b3d6a 100755 --- a/nzbget/rootfs/etc/cont-init.d/20-folders.sh +++ b/nzbget/rootfs/etc/cont-init.d/20-folders.sh @@ -5,14 +5,14 @@ set -e slug=nzbget if [ -d "/homeassistant/addons_config/$slug" ]; then - echo "Migrating /homeassistant/addons_config/$slug to /addon_configs/xxx-$slug" - cp -rnf /homeassistant/addons_config/"$slug"/* /config/ - mv /homeassistant/addons_config/"$slug" /homeassistant/addons_config/"$slug"_migrated + echo "Migrating /homeassistant/addons_config/$slug to /addon_configs/xxx-$slug" + cp -rnf /homeassistant/addons_config/"$slug"/* /config/ + mv /homeassistant/addons_config/"$slug" /homeassistant/addons_config/"$slug"_migrated fi if [ -f "/homeassistant/addons_autoscripts/$slug.sh" ]; then - bashio::log.warning "Migrating autoscript" - mv /homeassistant/addons_autoscripts/$slug.sh /config/ + bashio::log.warning "Migrating autoscript" + mv /homeassistant/addons_autoscripts/$slug.sh /config/ fi chmod 777 /config/* diff --git a/omada/rootfs/etc/cont-init.d/99-run.sh b/omada/rootfs/etc/cont-init.d/99-run.sh index f39a14800..d39fca209 100755 --- a/omada/rootfs/etc/cont-init.d/99-run.sh +++ b/omada/rootfs/etc/cont-init.d/99-run.sh @@ -6,15 +6,15 @@ CONFIGSOURCE="/config" # Use ssl if [ -d /ssl ]; then - mkdir -p /cert - cp -r /ssl/* /cert - chown -R 508:508 /cert + mkdir -p /cert + cp -r /ssl/* /cert + chown -R 508:508 /cert fi # Create directory if [ ! -f "$CONFIGSOURCE" ]; then - echo "Creating directory" - mkdir -p "$CONFIGSOURCE" + echo "Creating directory" + mkdir -p "$CONFIGSOURCE" fi # Migrate previous files @@ -30,17 +30,17 @@ echo "Creating symlink" # Create potentially missing folers for folders in html keystore pdf db portal; do - mkdir -p "$CONFIGSOURCE/$folders" + mkdir -p "$CONFIGSOURCE/$folders" done touch /config/LAST_RAN_OMADA_VER.txt # Create symlinks for all files in /data for item in "$CONFIGSOURCE"/*; do - # Get the base name of the file or folder - base_name=$(basename "$item") - # Create a symbolic link in the current working directory - ln -s "$item" /opt/tplink/EAPController/data/"$base_name" - echo "Created symlink for '$base_name'" + # Get the base name of the file or folder + base_name=$(basename "$item") + # Create a symbolic link in the current working directory + ln -s "$item" /opt/tplink/EAPController/data/"$base_name" + echo "Created symlink for '$base_name'" done # Create logfile diff --git a/omada_v3/rootfs/etc/cont-init.d/00-folders.sh b/omada_v3/rootfs/etc/cont-init.d/00-folders.sh index 4ed7d6dac..730a3269c 100755 --- a/omada_v3/rootfs/etc/cont-init.d/00-folders.sh +++ b/omada_v3/rootfs/etc/cont-init.d/00-folders.sh @@ -6,15 +6,15 @@ CONFIGSOURCE="/data" # Use ssl if [ -d /ssl ]; then - mkdir -p /cert - cp /ssl/* /cert 2>/dev/null - chown -R 508:508 /cert + mkdir -p /cert + cp /ssl/* /cert 2>/dev/null + chown -R 508:508 /cert fi # Create directory if [ ! -d "$CONFIGSOURCE" ]; then - echo "Creating directory" - mkdir -p "$CONFIGSOURCE" + echo "Creating directory" + mkdir -p "$CONFIGSOURCE" fi # Ensure structure is correct diff --git a/ombi/rootfs/etc/cont-init.d/20-folders.sh b/ombi/rootfs/etc/cont-init.d/20-folders.sh index 5a3d3b070..b349fb67b 100755 --- a/ombi/rootfs/etc/cont-init.d/20-folders.sh +++ b/ombi/rootfs/etc/cont-init.d/20-folders.sh @@ -6,15 +6,15 @@ slug=ombi if [ ! -d /config/addons_config/$slug ]; then - if [ -d /config/$slug ]; then - echo "Moving to new location /config/addons_config/$slug" - mkdir -p /config/addons_config/$slug - chmod 777 /config/addons_config/$slug - mv /config/$slug/* /config/addons_config/$slug/ - rm -r /config/$slug - fi + if [ -d /config/$slug ]; then + echo "Moving to new location /config/addons_config/$slug" + mkdir -p /config/addons_config/$slug + chmod 777 /config/addons_config/$slug + mv /config/$slug/* /config/addons_config/$slug/ + rm -r /config/$slug + fi - echo "Creating /config/addons_config/$slug" - mkdir -p /config/addons_config/$slug - chmod 777 /config/addons_config/$slug + echo "Creating /config/addons_config/$slug" + mkdir -p /config/addons_config/$slug + chmod 777 /config/addons_config/$slug fi diff --git a/openproject/rootfs/etc/cont-init.d/99-run.sh b/openproject/rootfs/etc/cont-init.d/99-run.sh index 9848be924..b8ae33b4f 100755 --- a/openproject/rootfs/etc/cont-init.d/99-run.sh +++ b/openproject/rootfs/etc/cont-init.d/99-run.sh @@ -4,13 +4,13 @@ bashio::log.info "Starting OpenProject" # Ensure persistence for PGDATA and asset folders for folder in pg assets; do - mkdir -p /data/"$folder" - if [ -d /config/"$folder" ] && [ "$(ls -A /config/"$folder"/)" ]; then - # Copy only if source is non-empty - cp -rf /config/"$folder"/. /data/"$folder"/ - rm -rf /config/"$folder" - fi - chmod 700 /data/"$folder" + mkdir -p /data/"$folder" + if [ -d /config/"$folder" ] && [ "$(ls -A /config/"$folder"/)" ]; then + # Copy only if source is non-empty + cp -rf /config/"$folder"/. /data/"$folder"/ + rm -rf /config/"$folder" + fi + chmod 700 /data/"$folder" done echo "Setting permissions" diff --git a/organizr/rootfs/etc/cont-init.d/00-folders.sh b/organizr/rootfs/etc/cont-init.d/00-folders.sh index c293ce6cb..d2ff5bf04 100755 --- a/organizr/rootfs/etc/cont-init.d/00-folders.sh +++ b/organizr/rootfs/etc/cont-init.d/00-folders.sh @@ -3,7 +3,7 @@ set -e if [ ! -d /data/organizr ]; then - echo "Creating /data/organizr" - mkdir -p /data/organizr - chown -R "$PUID:$PGID" /data/organizr + echo "Creating /data/organizr" + mkdir -p /data/organizr + chown -R "$PUID:$PGID" /data/organizr fi diff --git a/overseerr/rootfs/etc/cont-init.d/00-config_location.sh b/overseerr/rootfs/etc/cont-init.d/00-config_location.sh index 12e914b54..8f09ee743 100755 --- a/overseerr/rootfs/etc/cont-init.d/00-config_location.sh +++ b/overseerr/rootfs/etc/cont-init.d/00-config_location.sh @@ -11,5 +11,5 @@ chmod -R 755 "$CONFIG_LOCATION" # shellcheck disable=SC2013 for file in $(grep -Esril "/config/addons_config/overseerr" /etc/logrotate.d /defaults /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d); do - sed -i "s=/config/addons_config/overseerr=$CONFIG_LOCATION=g" "$file" + sed -i "s=/config/addons_config/overseerr=$CONFIG_LOCATION=g" "$file" done diff --git a/overseerr/rootfs/etc/cont-init.d/20-folders.sh b/overseerr/rootfs/etc/cont-init.d/20-folders.sh index b24086b6d..91f871dd9 100755 --- a/overseerr/rootfs/etc/cont-init.d/20-folders.sh +++ b/overseerr/rootfs/etc/cont-init.d/20-folders.sh @@ -1,18 +1,18 @@ #!/bin/bash if [ ! -d /config/addons_config/overseerr ]; then - echo "Creating /config/addons_config/overseerr" - mkdir -p /config/addons_config/overseerr + echo "Creating /config/addons_config/overseerr" + mkdir -p /config/addons_config/overseerr fi if [ -d /config/addons_config/addons_config/overseerr ]; then - echo "Migrating data to /config/addons_config/overseerr" - mv /config/addons_config/addons_config/overseerr /config/addons_config/overseerr + echo "Migrating data to /config/addons_config/overseerr" + mv /config/addons_config/addons_config/overseerr /config/addons_config/overseerr fi # shellcheck disable=SC2013 for file in $(grep -Esril "/config/.config/yarn" /usr /etc /defaults); do - sed -i "s=/config/.config/yarn=/config/addons_config/overseerr/yarn=g" "$file" + sed -i "s=/config/.config/yarn=/config/addons_config/overseerr/yarn=g" "$file" done yarn config set global-folder /config/addons_config/overseerr/yarn chown -R "$PUID:$PGID" /config/addons_config/overseerr diff --git a/papermerge/rootfs/etc/cont-init.d/91-OCR.sh b/papermerge/rootfs/etc/cont-init.d/91-OCR.sh index f0c4ffa4e..f11585ab6 100755 --- a/papermerge/rootfs/etc/cont-init.d/91-OCR.sh +++ b/papermerge/rootfs/etc/cont-init.d/91-OCR.sh @@ -9,51 +9,51 @@ OCRLANG="$(bashio::config "ocrlang")" CONFIGLOCATION="$(bashio::config "CONFIG_LOCATION")" #If it's a file, get the folder if [ ! -d "$CONFIGLOCATION" ]; then - CONFIGLOCATION="$(dirname "$CONFIGLOCATION")" + CONFIGLOCATION="$(dirname "$CONFIGLOCATION")" fi #Correct previous bug sed -i "s|OCRLANG|OCR_LANGUAGES|g" "$CONFIGLOCATION"/papermerge.conf.py languageCount=$(echo "$OCRLANG" | tr -cd ',' | wc -c) -languageCount=$((languageCount+1)) +languageCount=$((languageCount + 1)) bashio::log.info "Configuring ${languageCount} languages" if [ -n "$OCRLANG" ]; then - lineStart=$(sed -n '/OCR_LANGUAGES/=' "$CONFIGLOCATION"/papermerge.conf.py) - bashio::log.info "OCRLANG variable is set, processing the language packages" - lineEnd=$(sed -n '/}/=' "$CONFIGLOCATION"/papermerge.conf.py) - sed -i "${lineStart},${lineEnd}d" "$CONFIGLOCATION"/papermerge.conf.py || true + lineStart=$(sed -n '/OCR_LANGUAGES/=' "$CONFIGLOCATION"/papermerge.conf.py) + bashio::log.info "OCRLANG variable is set, processing the language packages" + lineEnd=$(sed -n '/}/=' "$CONFIGLOCATION"/papermerge.conf.py) + sed -i "${lineStart},${lineEnd}d" "$CONFIGLOCATION"/papermerge.conf.py || true - bashio::log.info "Writing new configuration" - echo "OCR_LANGUAGES = {" >> "$CONFIGLOCATION"/papermerge.conf.py + bashio::log.info "Writing new configuration" + echo "OCR_LANGUAGES = {" >>"$CONFIGLOCATION"/papermerge.conf.py - languages=$(echo "$OCRLANG" | tr "," "\n") + languages=$(echo "$OCRLANG" | tr "," "\n") - apt-get update >/dev/null + apt-get update >/dev/null - i=0 - for language in $languages; do - bashio::log.info "Processing language ${language}" - if apt-cache show tesseract-ocr-"${language}" >/dev/null 2>&1; then - bashio::log.info "Installing tesseract-ocr-${language}" - apt-get install -yqq tesseract-ocr-"${language}" >/dev/null - languageFullName=$(apt-cache show tesseract-ocr-"${language}" | grep -E '^(Description|Description-en):' | grep -oE '[^ ]+$') - bashio::log.info "${language} identified as ${languageFullName}" - i=$((i+1)) - if [[ $i -eq $languageCount ]]; then - echo " \"$language\" : \"$languageFullName\"" >> "$CONFIGLOCATION"/papermerge.conf.py - elif [[ $i -eq 1 ]]; then - echo " \"$language\" : \"$languageFullName\"," >> "$CONFIGLOCATION"/papermerge.conf.py - bashio::log.info "Setting default language to ${language}" - sed -i "s/^OCR_DEFAULT_LANGUAGE = \"eng\"/OCR_DEFAULT_LANGUAGE = \"${language}\"/g" "$CONFIGLOCATION"/papermerge.conf.py - else - echo " \"$language\" : \"$languageFullName\"," >> "$CONFIGLOCATION"/papermerge.conf.py - fi - bashio::log.info "... ${language} installed" - else - bashio::log.info "Package tesseract-ocr-${language} not found in the repository, skipping" - fi - done - echo "}" >> "$CONFIGLOCATION"/papermerge.conf.py + i=0 + for language in $languages; do + bashio::log.info "Processing language ${language}" + if apt-cache show tesseract-ocr-"${language}" >/dev/null 2>&1; then + bashio::log.info "Installing tesseract-ocr-${language}" + apt-get install -yqq tesseract-ocr-"${language}" >/dev/null + languageFullName=$(apt-cache show tesseract-ocr-"${language}" | grep -E '^(Description|Description-en):' | grep -oE '[^ ]+$') + bashio::log.info "${language} identified as ${languageFullName}" + i=$((i + 1)) + if [[ $i -eq $languageCount ]]; then + echo " \"$language\" : \"$languageFullName\"" >>"$CONFIGLOCATION"/papermerge.conf.py + elif [[ $i -eq 1 ]]; then + echo " \"$language\" : \"$languageFullName\"," >>"$CONFIGLOCATION"/papermerge.conf.py + bashio::log.info "Setting default language to ${language}" + sed -i "s/^OCR_DEFAULT_LANGUAGE = \"eng\"/OCR_DEFAULT_LANGUAGE = \"${language}\"/g" "$CONFIGLOCATION"/papermerge.conf.py + else + echo " \"$language\" : \"$languageFullName\"," >>"$CONFIGLOCATION"/papermerge.conf.py + fi + bashio::log.info "... ${language} installed" + else + bashio::log.info "Package tesseract-ocr-${language} not found in the repository, skipping" + fi + done + echo "}" >>"$CONFIGLOCATION"/papermerge.conf.py fi diff --git a/papermerge/rootfs/etc/cont-init.d/99-configuration.sh b/papermerge/rootfs/etc/cont-init.d/99-configuration.sh index 407255bc6..4eeafc17a 100755 --- a/papermerge/rootfs/etc/cont-init.d/99-configuration.sh +++ b/papermerge/rootfs/etc/cont-init.d/99-configuration.sh @@ -33,14 +33,14 @@ bashio::log.info "Import dir set to $IMPORTDIR" #chown -R "$PUID:$PGID" /config if [ ! -d "$MEDIADIR" ]; then - echo "Creating $MEDIADIR" - mkdir -p "$MEDIADIR" + echo "Creating $MEDIADIR" + mkdir -p "$MEDIADIR" fi chown -R "$PUID:$PGID" "$MEDIADIR" if [ ! -d "$IMPORTDIR" ]; then - echo "Creating $IMPORTDIR" - mkdir -p "$IMPORTDIR" + echo "Creating $IMPORTDIR" + mkdir -p "$IMPORTDIR" fi chown -R "$PUID:$PGID" "$IMPORTDIR" @@ -53,22 +53,22 @@ IMAPUSERNAME=$(bashio::config 'imapusername') IMAPPASSWORD=$(bashio::config 'imappassword') if [ "$IMAPHOST" != "null" ]; then - printf "\nIMPORT_MAIL_HOST = \"%s\"" "$IMAPHOST" >> /data/config/papermerge.conf.py - bashio::log.info "IMPORT_MAIL_HOST set to $IMAPHOST" + printf "\nIMPORT_MAIL_HOST = \"%s\"" "$IMAPHOST" >>/data/config/papermerge.conf.py + bashio::log.info "IMPORT_MAIL_HOST set to $IMAPHOST" - if [ "$IMAPUSERNAME" != "null" ]; then - printf "\nIMPORT_MAIL_USER = \"%s\"" "$IMAPUSERNAME" >> /data/config/papermerge.conf.py - bashio::log.info "IMPORT_MAIL_USER set to $IMAPUSERNAME" - else - bashio::log.info "! IMAPHOST has been set, but no IMAPUSERNAME. Please check your configuration!" - fi + if [ "$IMAPUSERNAME" != "null" ]; then + printf "\nIMPORT_MAIL_USER = \"%s\"" "$IMAPUSERNAME" >>/data/config/papermerge.conf.py + bashio::log.info "IMPORT_MAIL_USER set to $IMAPUSERNAME" + else + bashio::log.info "! IMAPHOST has been set, but no IMAPUSERNAME. Please check your configuration!" + fi - if [ "$IMAPPASSWORD" != "null" ]; then - printf "\nIMPORT_MAIL_PASS = \"%s\"" "$IMAPPASSWORD" >> /data/config/papermerge.conf.py - IMAPPASSWORDMASKED=$(echo "$IMAPPASSWORD" | sed -r 's/./x/g') - bashio::log.info "IMPORT_MAIL_PASS set to $IMAPPASSWORDMASKED" - else - bashio::log.info "! IMAPHOST has been set, but no IMAPPASSWORD. Please check your configuration!" - fi + if [ "$IMAPPASSWORD" != "null" ]; then + printf "\nIMPORT_MAIL_PASS = \"%s\"" "$IMAPPASSWORD" >>/data/config/papermerge.conf.py + IMAPPASSWORDMASKED=$(echo "$IMAPPASSWORD" | sed -r 's/./x/g') + bashio::log.info "IMPORT_MAIL_PASS set to $IMAPPASSWORDMASKED" + else + bashio::log.info "! IMAPHOST has been set, but no IMAPPASSWORD. Please check your configuration!" + fi fi diff --git a/photoprism/rootfs/etc/cont-init.d/00-folders.sh b/photoprism/rootfs/etc/cont-init.d/00-folders.sh index 5e235200d..ac9b9d6f6 100755 --- a/photoprism/rootfs/etc/cont-init.d/00-folders.sh +++ b/photoprism/rootfs/etc/cont-init.d/00-folders.sh @@ -3,28 +3,28 @@ set -e if bashio::config.has_value "PUID" && bashio::config.has_value "PGID"; then - PUID="$(bashio::config "PUID")" - PGID="$(bashio::config "PGID")" - bashio::log.green "Setting user to $PUID:$PGID" - id -u photoprism &>/dev/null || usermod -o -u "$PUID" photoprism || true - id -g photoprism &>/dev/null || groupmod -o -g "$PGID" photoprism || true + PUID="$(bashio::config "PUID")" + PGID="$(bashio::config "PGID")" + bashio::log.green "Setting user to $PUID:$PGID" + id -u photoprism &>/dev/null || usermod -o -u "$PUID" photoprism || true + id -g photoprism &>/dev/null || groupmod -o -g "$PGID" photoprism || true fi bashio::log.info "Preparing scripts" echo "... creating structure" mkdir -p \ - /data/photoprism/originals \ - /data/photoprism/import \ - /data/photoprism/storage/config \ - /data/photoprism/backup \ - /data/photoprism/storage/cache + /data/photoprism/originals \ + /data/photoprism/import \ + /data/photoprism/storage/config \ + /data/photoprism/backup \ + /data/photoprism/storage/cache echo "... setting permissions" chmod -R 777 /data/photoprism chown -Rf photoprism:photoprism /data/photoprism chmod -Rf a+rwx /data/photoprism for line in BACKUP_PATH IMPORT_PATH ORIGINALS_PATH STORAGE_PATH; do - mkdir -p "$line" - chmod -R 777 "$line" - chown -Rf photoprism:photoprism "$line" + mkdir -p "$line" + chmod -R 777 "$line" + chown -Rf photoprism:photoprism "$line" done diff --git a/photoprism/rootfs/etc/cont-init.d/30-graphic_drivers.sh b/photoprism/rootfs/etc/cont-init.d/30-graphic_drivers.sh index b38e59664..42295728f 100755 --- a/photoprism/rootfs/etc/cont-init.d/30-graphic_drivers.sh +++ b/photoprism/rootfs/etc/cont-init.d/30-graphic_drivers.sh @@ -4,33 +4,33 @@ set -e if bashio::config.has_value 'graphic_drivers'; then - GRAPHIC_DRIVERS="$(bashio::config 'graphic_drivers')" - bashio::log.info "Installing selected graphic drivers : $GRAPHIC_DRIVERS..." + GRAPHIC_DRIVERS="$(bashio::config 'graphic_drivers')" + bashio::log.info "Installing selected graphic drivers : $GRAPHIC_DRIVERS..." - ### Download WebUI - case "$GRAPHIC_DRIVERS" in + ### Download WebUI + case "$GRAPHIC_DRIVERS" in - "mesa") - apt-get update - apt-get install -yqq -- *mesa* >/dev/null - echo "... done" - ;; + "mesa") + apt-get update + apt-get install -yqq -- *mesa* >/dev/null + echo "... done" + ;; - "nvidia") - apt-get update - apt-get install -yqq -- *nvidia* >/dev/null - echo "... done" - ;; + "nvidia") + apt-get update + apt-get install -yqq -- *nvidia* >/dev/null + echo "... done" + ;; - "radeon") - apt-get update - apt-get install -yqq -- *radeon* >/dev/null - echo "... done" - ;; + "radeon") + apt-get update + apt-get install -yqq -- *radeon* >/dev/null + echo "... done" + ;; - *) - echo "... no drivers selected" - ;; + *) + echo "... no drivers selected" + ;; - esac + esac fi diff --git a/photoprism/rootfs/etc/cont-init.d/32-nginx_ssl.sh b/photoprism/rootfs/etc/cont-init.d/32-nginx_ssl.sh index 9d940f96a..3baf85316 100755 --- a/photoprism/rootfs/etc/cont-init.d/32-nginx_ssl.sh +++ b/photoprism/rootfs/etc/cont-init.d/32-nginx_ssl.sh @@ -16,19 +16,18 @@ sed -i "s|%%interface%%|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ssl.co # Ssl values if bashio::config.true 'ssl'; then - echo "Defining ssl configuration" - bashio::config.require.ssl - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') + echo "Defining ssl configuration" + bashio::config.require.ssl + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') - #Check if files exist - echo "... checking if referenced certificates exist" - [ ! -f /ssl/"$certfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$certfile not found" && bashio::exit.nok - [ ! -f /ssl/"$keyfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$keyfile not found" && bashio::exit.nok + #Check if files exist + echo "... checking if referenced certificates exist" + [ ! -f /ssl/"$certfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$certfile not found" && bashio::exit.nok + [ ! -f /ssl/"$keyfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$keyfile not found" && bashio::exit.nok - - sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf - sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf - sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf - bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port 2342)" + sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf + sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf + sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf + bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port 2342)" fi diff --git a/photoprism/rootfs/etc/cont-init.d/99-run.sh b/photoprism/rootfs/etc/cont-init.d/99-run.sh index 9fa844c09..6cbd68dde 100755 --- a/photoprism/rootfs/etc/cont-init.d/99-run.sh +++ b/photoprism/rootfs/etc/cont-init.d/99-run.sh @@ -11,57 +11,57 @@ bashio::log.info "Defining database" case $(bashio::config 'DB_TYPE') in - # Use sqlite - sqlite) - bashio::log.info "Using a local sqlite database" - ;; +# Use sqlite +sqlite) + bashio::log.info "Using a local sqlite database" + ;; - mariadb_addon) - bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." - if ! bashio::services.available 'mysql'; then - bashio::log.fatal \ - "Local database access should be provided by the MariaDB addon" - bashio::exit.nok \ - "Please ensure it is installed and started" - fi +mariadb_addon) + bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." + if ! bashio::services.available 'mysql'; then + bashio::log.fatal \ + "Local database access should be provided by the MariaDB addon" + bashio::exit.nok \ + "Please ensure it is installed and started" + fi - # Install mysqlclient - pip install pymysql &>/dev/null || true + # Install mysqlclient + pip install pymysql &>/dev/null || true - # Use values - PHOTOPRISM_DATABASE_DRIVER="mysql" - PHOTOPRISM_DATABASE_SERVER="$(bashio::services 'mysql' 'host'):$(bashio::services 'mysql' 'port')" - PHOTOPRISM_DATABASE_NAME="photoprism" - PHOTOPRISM_DATABASE_USER="$(bashio::services 'mysql' 'username')" - PHOTOPRISM_DATABASE_PASSWORD="$(bashio::services 'mysql' 'password')" - export PHOTOPRISM_DATABASE_DRIVER && \ - bashio::log.blue "PHOTOPRISM_DATABASE_DRIVER=$PHOTOPRISM_DATABASE_DRIVER" - export PHOTOPRISM_DATABASE_SERVER && \ - bashio::log.blue "PHOTOPRISM_DATABASE_SERVER=$PHOTOPRISM_DATABASE_SERVER" - export PHOTOPRISM_DATABASE_NAME && \ - bashio::log.blue "PHOTOPRISM_DATABASE_NAME=$PHOTOPRISM_DATABASE_NAME" - export PHOTOPRISM_DATABASE_USER && \ - bashio::log.blue "PHOTOPRISM_DATABASE_USER=$PHOTOPRISM_DATABASE_USER" - export PHOTOPRISM_DATABASE_PASSWORD && \ - bashio::log.blue "PHOTOPRISM_DATABASE_PASSWORD=$PHOTOPRISM_DATABASE_PASSWORD" + # Use values + PHOTOPRISM_DATABASE_DRIVER="mysql" + PHOTOPRISM_DATABASE_SERVER="$(bashio::services 'mysql' 'host'):$(bashio::services 'mysql' 'port')" + PHOTOPRISM_DATABASE_NAME="photoprism" + PHOTOPRISM_DATABASE_USER="$(bashio::services 'mysql' 'username')" + PHOTOPRISM_DATABASE_PASSWORD="$(bashio::services 'mysql' 'password')" + export PHOTOPRISM_DATABASE_DRIVER && + bashio::log.blue "PHOTOPRISM_DATABASE_DRIVER=$PHOTOPRISM_DATABASE_DRIVER" + export PHOTOPRISM_DATABASE_SERVER && + bashio::log.blue "PHOTOPRISM_DATABASE_SERVER=$PHOTOPRISM_DATABASE_SERVER" + export PHOTOPRISM_DATABASE_NAME && + bashio::log.blue "PHOTOPRISM_DATABASE_NAME=$PHOTOPRISM_DATABASE_NAME" + export PHOTOPRISM_DATABASE_USER && + bashio::log.blue "PHOTOPRISM_DATABASE_USER=$PHOTOPRISM_DATABASE_USER" + export PHOTOPRISM_DATABASE_PASSWORD && + bashio::log.blue "PHOTOPRISM_DATABASE_PASSWORD=$PHOTOPRISM_DATABASE_PASSWORD" - { - echo "export PHOTOPRISM_DATABASE_DRIVER=\"${PHOTOPRISM_DATABASE_DRIVER}\"" - echo "export PHOTOPRISM_DATABASE_SERVER=\"${PHOTOPRISM_DATABASE_SERVER}\"" - echo "export PHOTOPRISM_DATABASE_NAME=\"${PHOTOPRISM_DATABASE_NAME}\"" - echo "export PHOTOPRISM_DATABASE_USER=\"${PHOTOPRISM_DATABASE_USER}\"" - echo "export PHOTOPRISM_DATABASE_PASSWORD=\"${PHOTOPRISM_DATABASE_PASSWORD}\"" - } >> ~/.bashrc + { + echo "export PHOTOPRISM_DATABASE_DRIVER=\"${PHOTOPRISM_DATABASE_DRIVER}\"" + echo "export PHOTOPRISM_DATABASE_SERVER=\"${PHOTOPRISM_DATABASE_SERVER}\"" + echo "export PHOTOPRISM_DATABASE_NAME=\"${PHOTOPRISM_DATABASE_NAME}\"" + echo "export PHOTOPRISM_DATABASE_USER=\"${PHOTOPRISM_DATABASE_USER}\"" + echo "export PHOTOPRISM_DATABASE_PASSWORD=\"${PHOTOPRISM_DATABASE_PASSWORD}\"" + } >>~/.bashrc - bashio::log.warning "Photoprism is using the Maria DB addon" - bashio::log.warning "Please ensure this is included in your backups" - bashio::log.warning "Uninstalling the MariaDB addon will remove any data" + bashio::log.warning "Photoprism is using the Maria DB addon" + bashio::log.warning "Please ensure this is included in your backups" + bashio::log.warning "Uninstalling the MariaDB addon will remove any data" - # Create database - mysql --skip-ssl --host="$(bashio::services 'mysql' 'host')" --port="$(bashio::services 'mysql' 'port')" --user="$PHOTOPRISM_DATABASE_USER" --password="$PHOTOPRISM_DATABASE_PASSWORD" -e"CREATE DATABASE IF NOT EXISTS $PHOTOPRISM_DATABASE_NAME;" - # Force character set - mysql --skip-ssl --host="$(bashio::services 'mysql' 'host')" --port="$(bashio::services 'mysql' 'port')" --user="$PHOTOPRISM_DATABASE_USER" --password="$PHOTOPRISM_DATABASE_PASSWORD" -e"ALTER DATABASE $PHOTOPRISM_DATABASE_NAME CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;" || true - ;; + # Create database + mysql --skip-ssl --host="$(bashio::services 'mysql' 'host')" --port="$(bashio::services 'mysql' 'port')" --user="$PHOTOPRISM_DATABASE_USER" --password="$PHOTOPRISM_DATABASE_PASSWORD" -e"CREATE DATABASE IF NOT EXISTS $PHOTOPRISM_DATABASE_NAME;" + # Force character set + mysql --skip-ssl --host="$(bashio::services 'mysql' 'host')" --port="$(bashio::services 'mysql' 'port')" --user="$PHOTOPRISM_DATABASE_USER" --password="$PHOTOPRISM_DATABASE_PASSWORD" -e"ALTER DATABASE $PHOTOPRISM_DATABASE_NAME CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;" || true + ;; esac ########### @@ -69,16 +69,16 @@ esac ########### if bashio::config.true "ingress_disabled"; then - bashio::log.warning "Ingress is disabled. You'll need to connect using ip:port" - sed -i "s|$(bashio::addon.ingress_entry)||g" /etc/nginx/servers/ssl.conf - sed -i "s|location = /|location = /null|g" /etc/nginx/servers/ssl.conf - # sed -i "7,10d" /etc/nginx/servers/ssl.conf - # rm /etc/nginx/servers/ingress.conf + bashio::log.warning "Ingress is disabled. You'll need to connect using ip:port" + sed -i "s|$(bashio::addon.ingress_entry)||g" /etc/nginx/servers/ssl.conf + sed -i "s|location = /|location = /null|g" /etc/nginx/servers/ssl.conf + # sed -i "7,10d" /etc/nginx/servers/ssl.conf + # rm /etc/nginx/servers/ingress.conf else - PHOTOPRISM_SITE_URL="$(bashio::addon.ingress_entry)/" - export PHOTOPRISM_SITE_URL - echo "export PHOTOPRISM_SITE_URL=\"${PHOTOPRISM_SITE_URL}\"" >> ~/.bashrc - bashio::log.warning "Ingress is enabled. To connect, you must add $PHOTOPRISM_SITE_URL to the end of your access point. Example : http://my-url:8123$PHOTOPRISM_SITE_URL" + PHOTOPRISM_SITE_URL="$(bashio::addon.ingress_entry)/" + export PHOTOPRISM_SITE_URL + echo "export PHOTOPRISM_SITE_URL=\"${PHOTOPRISM_SITE_URL}\"" >>~/.bashrc + bashio::log.warning "Ingress is enabled. To connect, you must add $PHOTOPRISM_SITE_URL to the end of your access point. Example : http://my-url:8123$PHOTOPRISM_SITE_URL" fi ############## @@ -98,39 +98,39 @@ export PHOTOPRISM_IMPORT_PATH export PHOTOPRISM_BACKUP_PATH { - echo "export PHOTOPRISM_UPLOAD_NSFW=\"${PHOTOPRISM_UPLOAD_NSFW}\"" - echo "export PHOTOPRISM_STORAGE_PATH=\"${PHOTOPRISM_STORAGE_PATH}\"" - echo "export PHOTOPRISM_ORIGINALS_PATH=\"${PHOTOPRISM_ORIGINALS_PATH}\"" - echo "export PHOTOPRISM_IMPORT_PATH=\"${PHOTOPRISM_IMPORT_PATH}\"" - echo "export PHOTOPRISM_BACKUP_PATH=\"${PHOTOPRISM_BACKUP_PATH}\"" -} >> ~/.bashrc + echo "export PHOTOPRISM_UPLOAD_NSFW=\"${PHOTOPRISM_UPLOAD_NSFW}\"" + echo "export PHOTOPRISM_STORAGE_PATH=\"${PHOTOPRISM_STORAGE_PATH}\"" + echo "export PHOTOPRISM_ORIGINALS_PATH=\"${PHOTOPRISM_ORIGINALS_PATH}\"" + echo "export PHOTOPRISM_IMPORT_PATH=\"${PHOTOPRISM_IMPORT_PATH}\"" + echo "export PHOTOPRISM_BACKUP_PATH=\"${PHOTOPRISM_BACKUP_PATH}\"" +} >>~/.bashrc # Test configs for variabletest in $PHOTOPRISM_STORAGE_PATH $PHOTOPRISM_ORIGINALS_PATH $PHOTOPRISM_IMPORT_PATH $PHOTOPRISM_BACKUP_PATH; do - # Check if path exists - if bashio::fs.directory_exists "$variabletest"; then - true - else - bashio::log.info "Path $variabletest doesn't exist. Creating it now..." - mkdir -p "$variabletest" || bashio::log.fatal "Can't create $variabletest path" - fi - # Check if path writable - # shellcheck disable=SC2015 - touch "$variabletest"/aze && rm "$variabletest"/aze || bashio::log.fatal "$variabletest path is not writable" + # Check if path exists + if bashio::fs.directory_exists "$variabletest"; then + true + else + bashio::log.info "Path $variabletest doesn't exist. Creating it now..." + mkdir -p "$variabletest" || bashio::log.fatal "Can't create $variabletest path" + fi + # Check if path writable + # shellcheck disable=SC2015 + touch "$variabletest"/aze && rm "$variabletest"/aze || bashio::log.fatal "$variabletest path is not writable" done # Define id if bashio::config.has_value "PUID" && bashio::config.has_value "PGID"; then - PUID="$(bashio::config "PUID")" - PGID="$(bashio::config "PGID")" - export PHOTOPRISM_UID="$PUID" - export PHOTOPRISM_GID="$PGID" - sed -i "1a PHOTOPRISM_UID=$PHOTOPRISM_UID" /scripts/entrypoint.sh - sed -i "1a PHOTOPRISM_GID=$PHOTOPRISM_GID" /scripts/entrypoint.sh - { - echo "export PHOTOPRISM_UID=\"${PHOTOPRISM_UID}\"" - echo "export PHOTOPRISM_GID=\"${PHOTOPRISM_GID}\"" - } >> ~/.bashrc + PUID="$(bashio::config "PUID")" + PGID="$(bashio::config "PGID")" + export PHOTOPRISM_UID="$PUID" + export PHOTOPRISM_GID="$PGID" + sed -i "1a PHOTOPRISM_UID=$PHOTOPRISM_UID" /scripts/entrypoint.sh + sed -i "1a PHOTOPRISM_GID=$PHOTOPRISM_GID" /scripts/entrypoint.sh + { + echo "export PHOTOPRISM_UID=\"${PHOTOPRISM_UID}\"" + echo "export PHOTOPRISM_GID=\"${PHOTOPRISM_GID}\"" + } >>~/.bashrc fi # Start messages @@ -138,7 +138,8 @@ bashio::log.info "Please wait 1 or 2 minutes to allow the server to load" bashio::log.info 'Default username : admin, default password: "please_change_password"' # shellcheck disable=SC1091 -. /scripts/entrypoint.sh photoprism start & bashio::log.info "Starting, please wait for next green text..." +. /scripts/entrypoint.sh photoprism start & +bashio::log.info "Starting, please wait for next green text..." bashio::net.wait_for 2341 localhost 900 bashio::log.info "App launched" diff --git a/photoprism/rootfs/run.sh b/photoprism/rootfs/run.sh index 873dad333..c45386dde 100755 --- a/photoprism/rootfs/run.sh +++ b/photoprism/rootfs/run.sh @@ -8,13 +8,13 @@ set -e ########### for SCRIPTS in "/00-banner.sh" "/00-local_mounts.sh" "/00-smb_mounts.sh"; do - echo $SCRIPTS - chown "$(id -u)":"$(id -g)" "$SCRIPTS" - chmod a+x $SCRIPTS - sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' $SCRIPTS - /.$SCRIPTS && - true || true # Prevents script crash on failure - echo "exit $?" + echo $SCRIPTS + chown "$(id -u)":"$(id -g)" "$SCRIPTS" + chmod a+x $SCRIPTS + sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' $SCRIPTS + /.$SCRIPTS && + true || true # Prevents script crash on failure + echo "exit $?" done ############## @@ -29,31 +29,31 @@ export PHOTOPRISM_IMPORT_PATH=$(bashio::config 'IMPORT_PATH') export PHOTOPRISM_BACKUP_PATH=$(bashio::config 'BACKUP_PATH') { - printf "%s\n" "PHOTOPRISM_UPLOAD_NSFW=\"${PHOTOPRISM_UPLOAD_NSFW}\"" - printf "%s\n" "PHOTOPRISM_STORAGE_PATH=\"${PHOTOPRISM_STORAGE_PATH}\"" - printf "%s\n" "PHOTOPRISM_ORIGINALS_PATH=\"${PHOTOPRISM_ORIGINALS_PATH}\"" - printf "%s\n" "PHOTOPRISM_IMPORT_PATH=\"${PHOTOPRISM_IMPORT_PATH}\"" - printf "%s\n" "PHOTOPRISM_BACKUP_PATH=\"${PHOTOPRISM_BACKUP_PATH}\"" -} >> ~/.bashrc + printf "%s\n" "PHOTOPRISM_UPLOAD_NSFW=\"${PHOTOPRISM_UPLOAD_NSFW}\"" + printf "%s\n" "PHOTOPRISM_STORAGE_PATH=\"${PHOTOPRISM_STORAGE_PATH}\"" + printf "%s\n" "PHOTOPRISM_ORIGINALS_PATH=\"${PHOTOPRISM_ORIGINALS_PATH}\"" + printf "%s\n" "PHOTOPRISM_IMPORT_PATH=\"${PHOTOPRISM_IMPORT_PATH}\"" + printf "%s\n" "PHOTOPRISM_BACKUP_PATH=\"${PHOTOPRISM_BACKUP_PATH}\"" +} >>~/.bashrc if bashio::config.has_value 'CUSTOM_OPTIONS'; then - CUSTOMOPTIONS=$(bashio::config 'CUSTOM_OPTIONS') + CUSTOMOPTIONS=$(bashio::config 'CUSTOM_OPTIONS') else - CUSTOMOPTIONS="" + CUSTOMOPTIONS="" fi # Test configs for variabletest in $PHOTOPRISM_STORAGE_PATH $PHOTOPRISM_ORIGINALS_PATH $PHOTOPRISM_IMPORT_PATH $PHOTOPRISM_BACKUP_PATH; do - # Check if path exists - if bashio::fs.directory_exists "$variabletest"; then - true - else - bashio::log.info "Path $variabletest doesn't exist. Creating it now..." - mkdir -p "$variabletest" || bashio::log.fatal "Can't create $variabletest path" - fi - # Check if path writable - # shellcheck disable=SC2015 - touch "$variabletest"/aze && rm "$variabletest"/aze || bashio::log.fatal "$variabletest path is not writable" + # Check if path exists + if bashio::fs.directory_exists "$variabletest"; then + true + else + bashio::log.info "Path $variabletest doesn't exist. Creating it now..." + mkdir -p "$variabletest" || bashio::log.fatal "Can't create $variabletest path" + fi + # Check if path writable + # shellcheck disable=SC2015 + touch "$variabletest"/aze && rm "$variabletest"/aze || bashio::log.fatal "$variabletest path is not writable" done # Start messages diff --git a/plex/rootfs/etc/cont-init.d/21-folders.sh b/plex/rootfs/etc/cont-init.d/21-folders.sh index c9d3c1ae8..fdbabf7bd 100755 --- a/plex/rootfs/etc/cont-init.d/21-folders.sh +++ b/plex/rootfs/etc/cont-init.d/21-folders.sh @@ -9,20 +9,20 @@ set -e echo "Database stored in /share/plex" if [ ! -d "/share/plex/Plex Media Server" ]; then - echo "... creating /share/plex/Plex Media Server" - mkdir -p "/share/plex/Plex Media Server" + echo "... creating /share/plex/Plex Media Server" + mkdir -p "/share/plex/Plex Media Server" fi if [ -d "/config/Library/Application Support/Plex Media Server" ]; then - echo "... creating /symlink" - rm -r "/config/Library/Application Support/*" - ln -s "/share/plex/Plex Media Server" "/config/Library/Application Support" + echo "... creating /symlink" + rm -r "/config/Library/Application Support/*" + ln -s "/share/plex/Plex Media Server" "/config/Library/Application Support" fi if [ ! -d "/config/Library/Application Support" ]; then - echo "... creating /symlink" - mkdir -p "/config/Library/Application Support" - ln -s "/share/plex/Plex Media Server" "/config/Library/Application Support" + echo "... creating /symlink" + mkdir -p "/config/Library/Application Support" + ln -s "/share/plex/Plex Media Server" "/config/Library/Application Support" fi chown -R "$PUID:$PGID" /share/plex diff --git a/plex/rootfs/etc/cont-init.d/90-create_links.sh b/plex/rootfs/etc/cont-init.d/90-create_links.sh index a172ba153..31ff7becc 100755 --- a/plex/rootfs/etc/cont-init.d/90-create_links.sh +++ b/plex/rootfs/etc/cont-init.d/90-create_links.sh @@ -5,19 +5,19 @@ ################## if [ ! -d /share/plex ]; then - echo "Creating /share/plex" - mkdir -p /share/plex + echo "Creating /share/plex" + mkdir -p /share/plex fi if [ ! -d /share/plex/Library ]; then - echo "moving Library folder" - mv /config/Library /share/plex - ln -s /share/plex/Library /config - echo "links done" + echo "moving Library folder" + mv /config/Library /share/plex + ln -s /share/plex/Library /config + echo "links done" else - rm -r /config/Library - ln -s /share/plex/Library /config - echo "Using existing config" + rm -r /config/Library + ln -s /share/plex/Library /config + echo "Using existing config" fi chown -R "$PUID:$PGID" /config/Library diff --git a/portainer/rootfs/etc/cont-init.d/30-nginx.sh b/portainer/rootfs/etc/cont-init.d/30-nginx.sh index f3220b584..ce0a1641a 100755 --- a/portainer/rootfs/etc/cont-init.d/30-nginx.sh +++ b/portainer/rootfs/etc/cont-init.d/30-nginx.sh @@ -11,23 +11,23 @@ declare portainer_protocol=http # Generate Ingress configuration if bashio::config.true 'ssl'; then - bashio::config.require.ssl - portainer_protocol=https - sed -i "s|9000|9443|g" /etc/nginx/includes/upstream.conf - sed -i "s|9000|9443|g" /etc/services.d/nginx/run - sed -i "s|9099 default_server|9099 ssl|g" /etc/nginx/templates/ingress.gtpl - sed -i '7 i ssl_certificate /ssl/{{ .certfile }};' /etc/nginx/templates/ingress.gtpl - sed -i '7 i ssl_certificate_key /ssl/{{ .keyfile }};' /etc/nginx/templates/ingress.gtpl - bashio::log.info "Ssl enabled, please use https for connection" + bashio::config.require.ssl + portainer_protocol=https + sed -i "s|9000|9443|g" /etc/nginx/includes/upstream.conf + sed -i "s|9000|9443|g" /etc/services.d/nginx/run + sed -i "s|9099 default_server|9099 ssl|g" /etc/nginx/templates/ingress.gtpl + sed -i '7 i ssl_certificate /ssl/{{ .certfile }};' /etc/nginx/templates/ingress.gtpl + sed -i '7 i ssl_certificate_key /ssl/{{ .keyfile }};' /etc/nginx/templates/ingress.gtpl + bashio::log.info "Ssl enabled, please use https for connection" fi bashio::var.json \ - interface "$(bashio::addon.ip_address)" \ - port "^$(bashio::addon.ingress_port)" \ - protocol "${portainer_protocol}" \ - certfile "$(bashio::config 'certfile')" \ - keyfile "$(bashio::config 'keyfile')" \ - ssl "^$(bashio::config 'ssl')" | -tempio \ - -template /etc/nginx/templates/ingress.gtpl \ - -out /etc/nginx/servers/ingress.conf + interface "$(bashio::addon.ip_address)" \ + port "^$(bashio::addon.ingress_port)" \ + protocol "${portainer_protocol}" \ + certfile "$(bashio::config 'certfile')" \ + keyfile "$(bashio::config 'keyfile')" \ + ssl "^$(bashio::config 'ssl')" | + tempio \ + -template /etc/nginx/templates/ingress.gtpl \ + -out /etc/nginx/servers/ingress.conf diff --git a/postgres_15/rootfs/etc/cont-init.d/20-folders.sh b/postgres_15/rootfs/etc/cont-init.d/20-folders.sh index c4f63643a..6d0fc4b63 100755 --- a/postgres_15/rootfs/etc/cont-init.d/20-folders.sh +++ b/postgres_15/rootfs/etc/cont-init.d/20-folders.sh @@ -4,16 +4,16 @@ set -e # Migration if [ -d /data/database ]; then - bashio::log.warning "Database migrated to /config" - mv /data/database /config + bashio::log.warning "Database migrated to /config" + mv /data/database /config fi if [ -f /homeassistant/addons_config/postgres/config.yaml ]; then - bashio::log.warning "Config migrated to /config" - mv /homeassistant/addons_config/postgres/* /config/ - rm -r /homeassistant/addons_config/postgres - # Correct database location - sed -i "s|/data/database|/config/database|g" /config/postgresql.conf + bashio::log.warning "Config migrated to /config" + mv /homeassistant/addons_config/postgres/* /config/ + rm -r /homeassistant/addons_config/postgres + # Correct database location + sed -i "s|/data/database|/config/database|g" /config/postgresql.conf fi # touch sql file diff --git a/postgres_15/rootfs/etc/cont-init.d/99-run.sh b/postgres_15/rootfs/etc/cont-init.d/99-run.sh index 1ab4a239d..9a1fee9a0 100755 --- a/postgres_15/rootfs/etc/cont-init.d/99-run.sh +++ b/postgres_15/rootfs/etc/cont-init.d/99-run.sh @@ -9,13 +9,13 @@ PG_MAJOR_VERSION="${PG_MAJOR:-15}" RESTART_FLAG_FILE="$CONFIG_HOME/restart_needed" fix_permissions() { - mkdir -p "$PGDATA" - chown -R postgres:postgres "$PGDATA" - chmod 700 "$PGDATA" - if [ -d /config/backups ]; then - chown -R postgres:postgres /config/backups - chmod 700 /config/backups - fi + mkdir -p "$PGDATA" + chown -R postgres:postgres "$PGDATA" + chmod 700 "$PGDATA" + if [ -d /config/backups ]; then + chown -R postgres:postgres /config/backups + chmod 700 /config/backups + fi } chmod -R 755 "$CONFIG_HOME" @@ -25,369 +25,371 @@ RESTART_NEEDED=false cd /config || true get_pgdata_version() { - if [ -f "$PGDATA/PG_VERSION" ]; then - cat "$PGDATA/PG_VERSION" - else - bashio::log.error "FATAL: $PGDATA/PG_VERSION not found; cannot determine cluster version." - exit 1 - fi + if [ -f "$PGDATA/PG_VERSION" ]; then + cat "$PGDATA/PG_VERSION" + else + bashio::log.error "FATAL: $PGDATA/PG_VERSION not found; cannot determine cluster version." + exit 1 + fi } extract_so_from_deb() { - local debfile="$1" - local targetdir="$2" - local sofile="$3" - local tmpdir - tmpdir=$(mktemp -d) - dpkg-deb -x "$debfile" "$tmpdir" - find "$tmpdir" -name "$sofile" -exec cp {} "$targetdir" \; - rm -rf "$tmpdir" + local debfile="$1" + local targetdir="$2" + local sofile="$3" + local tmpdir + tmpdir=$(mktemp -d) + dpkg-deb -x "$debfile" "$tmpdir" + find "$tmpdir" -name "$sofile" -exec cp {} "$targetdir" \; + rm -rf "$tmpdir" } install_vchord_and_vectors_for_old_pg() { - local old_pgver="$1" - local vectorchord_tag="${VECTORCHORD_TAG:-0.3.0}" - local pgvectors_tag="${PGVECTORS_TAG:-0.3.0}" - case "$(uname -m)" in - x86_64 | amd64 | AMD64 | x86-64) - targetarch=amd64 - ;; - aarch64 | arm64 | ARM64) - targetarch=arm64 - ;; - *) - echo "Unsupported architecture: $(uname -m)" - exit 1 - ;; - esac - local vchord_url - local vectors_url - local vchord_deb - local vectors_deb - local old_pg_lib="/usr/lib/postgresql/$old_pgver/lib" + local old_pgver="$1" + local vectorchord_tag="${VECTORCHORD_TAG:-0.3.0}" + local pgvectors_tag="${PGVECTORS_TAG:-0.3.0}" + case "$(uname -m)" in + x86_64 | amd64 | AMD64 | x86-64) + targetarch=amd64 + ;; + aarch64 | arm64 | ARM64) + targetarch=arm64 + ;; + *) + echo "Unsupported architecture: $(uname -m)" + exit 1 + ;; + esac + local vchord_url + local vectors_url + local vchord_deb + local vectors_deb + local old_pg_lib="/usr/lib/postgresql/$old_pgver/lib" - mkdir -p "$old_pg_lib" + mkdir -p "$old_pg_lib" - vchord_url="https://github.com/tensorchord/VectorChord/releases/download/${vectorchord_tag}/postgresql-${old_pgver}-vchord_${vectorchord_tag}-1_${targetarch}.deb" - vchord_deb="/tmp/vchord-${old_pgver}.deb" - bashio::log.info "Downloading $vchord_url" - wget -nv -O "$vchord_deb" "$vchord_url" - extract_so_from_deb "$vchord_deb" "$old_pg_lib" "vchord.so" - rm -f "$vchord_deb" + vchord_url="https://github.com/tensorchord/VectorChord/releases/download/${vectorchord_tag}/postgresql-${old_pgver}-vchord_${vectorchord_tag}-1_${targetarch}.deb" + vchord_deb="/tmp/vchord-${old_pgver}.deb" + bashio::log.info "Downloading $vchord_url" + wget -nv -O "$vchord_deb" "$vchord_url" + extract_so_from_deb "$vchord_deb" "$old_pg_lib" "vchord.so" + rm -f "$vchord_deb" - vectors_url="https://github.com/tensorchord/pgvecto.rs/releases/download/v${pgvectors_tag}/vectors-pg${old_pgver}_${pgvectors_tag}_${targetarch}.deb" - vectors_deb="/tmp/pgvectors-${old_pgver}.deb" - bashio::log.info "Downloading $vectors_url" - wget -nv -O "$vectors_deb" "$vectors_url" - extract_so_from_deb "$vectors_deb" "$old_pg_lib" "vectors.so" - rm -f "$vectors_deb" + vectors_url="https://github.com/tensorchord/pgvecto.rs/releases/download/v${pgvectors_tag}/vectors-pg${old_pgver}_${pgvectors_tag}_${targetarch}.deb" + vectors_deb="/tmp/pgvectors-${old_pgver}.deb" + bashio::log.info "Downloading $vectors_url" + wget -nv -O "$vectors_deb" "$vectors_url" + extract_so_from_deb "$vectors_deb" "$old_pg_lib" "vectors.so" + rm -f "$vectors_deb" } drop_vectors_everywhere() { - local old_pgver="$1" - fix_permissions - su - postgres -c "$BINARIES_DIR/$old_pgver/bin/pg_ctl \ + local old_pgver="$1" + fix_permissions + su - postgres -c "$BINARIES_DIR/$old_pgver/bin/pg_ctl \ -w -D '$PGDATA' -o \"-c config_file=/etc/postgresql/postgresql.conf \ -c listen_addresses='' -c port=65432\" start" - for db in $(su - postgres -c \ - "$BINARIES_DIR/$old_pgver/bin/psql -Atc \ + for db in $(su - postgres -c \ + "$BINARIES_DIR/$old_pgver/bin/psql -Atc \ \"SELECT datname FROM pg_database WHERE datistemplate = false AND datallowconn\""); do - if su - postgres -c \ - "$BINARIES_DIR/$old_pgver/bin/psql -d $db -Atc \ - \"SELECT 1 FROM pg_extension WHERE extname='vectors'\"" \ - | grep -q 1; then - bashio::log.warning "Dropping extension vectors from DB $db" - su - postgres -c \ - "$BINARIES_DIR/$old_pgver/bin/psql -d $db -c \ + if su - postgres -c \ + "$BINARIES_DIR/$old_pgver/bin/psql -d $db -Atc \ + \"SELECT 1 FROM pg_extension WHERE extname='vectors'\"" | + grep -q 1; then + bashio::log.warning "Dropping extension vectors from DB $db" + su - postgres -c \ + "$BINARIES_DIR/$old_pgver/bin/psql -d $db -c \ 'DROP EXTENSION vectors CASCADE;'" - fi - done - su - postgres -c "$BINARIES_DIR/$old_pgver/bin/pg_ctl -w -D '$PGDATA' stop" + fi + done + su - postgres -c "$BINARIES_DIR/$old_pgver/bin/pg_ctl -w -D '$PGDATA' stop" } start_postgres() { - bashio::log.info "Starting PostgreSQL..." - if [ "$(bashio::info.arch)" = "armv7" ]; then - bashio::log.warning "ARMv7 detected: Starting without vectors.so" - /usr/local/bin/immich-docker-entrypoint.sh postgres & true - exit 0 - else - /usr/local/bin/immich-docker-entrypoint.sh postgres -c config_file=/etc/postgresql/postgresql.conf & true - fi + bashio::log.info "Starting PostgreSQL..." + if [ "$(bashio::info.arch)" = "armv7" ]; then + bashio::log.warning "ARMv7 detected: Starting without vectors.so" + /usr/local/bin/immich-docker-entrypoint.sh postgres & + true + exit 0 + else + /usr/local/bin/immich-docker-entrypoint.sh postgres -c config_file=/etc/postgresql/postgresql.conf & + true + fi } wait_for_postgres() { - local tries=0 - while ! pg_isready -h "$DB_HOSTNAME" -p "$DB_PORT" -U "$DB_USERNAME" >/dev/null 2>&1; do - tries=$((tries+1)) - if [ "$tries" -ge 60 ]; then - bashio::log.error "Postgres did not start after 2 minutes, aborting." - exit 1 - fi - echo "PostgreSQL is starting up... ($tries/60)" - sleep 2 - done + local tries=0 + while ! pg_isready -h "$DB_HOSTNAME" -p "$DB_PORT" -U "$DB_USERNAME" >/dev/null 2>&1; do + tries=$((tries + 1)) + if [ "$tries" -ge 60 ]; then + bashio::log.error "Postgres did not start after 2 minutes, aborting." + exit 1 + fi + echo "PostgreSQL is starting up... ($tries/60)" + sleep 2 + done } restart_immich_addons_if_flagged() { - if [ -f "$RESTART_FLAG_FILE" ]; then - bashio::log.warning "Detected pending Immich add-on restart flag. Restarting all running Immich add-ons..." + if [ -f "$RESTART_FLAG_FILE" ]; then + bashio::log.warning "Detected pending Immich add-on restart flag. Restarting all running Immich add-ons..." - local addons_json slug found=0 + local addons_json slug found=0 - # Get the add-ons list, fail on HTTP errors, show errors if API call fails - addons_json=$(curl -fsSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/addons) || { - bashio::log.error "Supervisor API call failed or unauthorized: $addons_json" - rm -f "$RESTART_FLAG_FILE" - return 1 - } + # Get the add-ons list, fail on HTTP errors, show errors if API call fails + addons_json=$(curl -fsSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/addons) || { + bashio::log.error "Supervisor API call failed or unauthorized: $addons_json" + rm -f "$RESTART_FLAG_FILE" + return 1 + } - if command -v jq >/dev/null; then - # Use correct JSON path for modern Supervisor API - for slug in $(echo "$addons_json" | jq -r '.addons[] | select(.state=="started") | .slug'); do - if [[ "$slug" == *immich* ]]; then - bashio::log.info "Restarting addon $slug" - curl -fsSL -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" \ - "http://supervisor/addons/$slug/restart" - found=1 - fi - done - else - # Fallback: grep/cut for legacy environments, less robust - for slug in $(echo "$addons_json" | grep -o '"slug":"[^"]*"' | cut -d: -f2 | tr -d '"'); do - if [[ "$slug" == *immich* ]]; then - bashio::log.info "Restarting addon $slug" - curl -fsSL -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" \ - "http://supervisor/addons/$slug/restart" - found=1 - fi - done - fi + if command -v jq >/dev/null; then + # Use correct JSON path for modern Supervisor API + for slug in $(echo "$addons_json" | jq -r '.addons[] | select(.state=="started") | .slug'); do + if [[ "$slug" == *immich* ]]; then + bashio::log.info "Restarting addon $slug" + curl -fsSL -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" \ + "http://supervisor/addons/$slug/restart" + found=1 + fi + done + else + # Fallback: grep/cut for legacy environments, less robust + for slug in $(echo "$addons_json" | grep -o '"slug":"[^"]*"' | cut -d: -f2 | tr -d '"'); do + if [[ "$slug" == *immich* ]]; then + bashio::log.info "Restarting addon $slug" + curl -fsSL -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" \ + "http://supervisor/addons/$slug/restart" + found=1 + fi + done + fi - if [ "$found" -eq 0 ]; then - bashio::log.info "No Immich-related addon found running." - fi - rm -f "$RESTART_FLAG_FILE" - fi + if [ "$found" -eq 0 ]; then + bashio::log.info "No Immich-related addon found running." + fi + rm -f "$RESTART_FLAG_FILE" + fi } get_available_extension_version() { - local extname="$1" - psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/postgres" -v ON_ERROR_STOP=1 -tAc \ - "SELECT default_version FROM pg_available_extensions WHERE name = '$extname';" 2>/dev/null | xargs + local extname="$1" + psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/postgres" -v ON_ERROR_STOP=1 -tAc \ + "SELECT default_version FROM pg_available_extensions WHERE name = '$extname';" 2>/dev/null | xargs } is_extension_available() { - local extname="$1" - local result - result=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/postgres" -v ON_ERROR_STOP=1 -tAc \ - "SELECT 1 FROM pg_available_extensions WHERE name = '$extname';" 2>/dev/null | xargs) - [[ "$result" == "1" ]] + local extname="$1" + local result + result=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/postgres" -v ON_ERROR_STOP=1 -tAc \ + "SELECT 1 FROM pg_available_extensions WHERE name = '$extname';" 2>/dev/null | xargs) + [[ "$result" == "1" ]] } get_user_databases() { - psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/postgres" -v ON_ERROR_STOP=1 -tAc \ - "SELECT datname FROM pg_database WHERE datistemplate = false AND datallowconn = true;" + psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/postgres" -v ON_ERROR_STOP=1 -tAc \ + "SELECT datname FROM pg_database WHERE datistemplate = false AND datallowconn = true;" } get_installed_extension_version() { - local extname="$1" - local dbname="$2" - psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/$dbname" -v ON_ERROR_STOP=1 -tAc \ - "SELECT extversion FROM pg_extension WHERE extname = '$extname';" 2>/dev/null | xargs + local extname="$1" + local dbname="$2" + psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/$dbname" -v ON_ERROR_STOP=1 -tAc \ + "SELECT extversion FROM pg_extension WHERE extname = '$extname';" 2>/dev/null | xargs } compare_versions() { - local v1="$1" - local v2="$2" - if [ "$v1" = "$v2" ]; then return 1; fi - if [ "$(printf '%s\n' "$v1" "$v2" | sort -V | head -n1)" = "$v1" ]; then - return 0 - fi - return 1 + local v1="$1" + local v2="$2" + if [ "$v1" = "$v2" ]; then return 1; fi + if [ "$(printf '%s\n' "$v1" "$v2" | sort -V | head -n1)" = "$v1" ]; then + return 0 + fi + return 1 } show_db_extensions() { - bashio::log.info "==== PostgreSQL databases and enabled extensions ====" - for db in $(get_user_databases); do - bashio::log.info "Database: $db" - exts=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/$db" -tAc \ - "SELECT extname || ' (v' || extversion || ')' FROM pg_extension ORDER BY extname;") - if [ -n "$exts" ]; then - while read -r ext; do - [ -n "$ext" ] && bashio::log.info " - $ext" - done <<< "$exts" - else - bashio::log.info " (no extensions enabled)" - fi - done - bashio::log.info "==============================================" + bashio::log.info "==== PostgreSQL databases and enabled extensions ====" + for db in $(get_user_databases); do + bashio::log.info "Database: $db" + exts=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT/$db" -tAc \ + "SELECT extname || ' (v' || extversion || ')' FROM pg_extension ORDER BY extname;") + if [ -n "$exts" ]; then + while read -r ext; do + [ -n "$ext" ] && bashio::log.info " - $ext" + done <<<"$exts" + else + bashio::log.info " (no extensions enabled)" + fi + done + bashio::log.info "==============================================" } upgrade_extension_if_needed() { - local extname="$1" - if ! is_extension_available "$extname"; then - bashio::log.info "$extname extension not available on this Postgres instance." - return - fi - local available_version - available_version=$(get_available_extension_version "$extname") - if [ -z "$available_version" ]; then - bashio::log.info "Could not determine available version for $extname." - return - fi - for db in $(get_user_databases); do - local installed_version - installed_version=$(get_installed_extension_version "$extname" "$db") - if [ -n "$installed_version" ]; then - if compare_versions "$installed_version" "$available_version"; then - bashio::log.info "Upgrading $extname in $db from $installed_version to $available_version" - if psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME@$DB_PORT/$db" -v ON_ERROR_STOP=1 -c "ALTER EXTENSION $extname UPDATE;"; then - RESTART_NEEDED=true - else - bashio::log.error "Failed to upgrade $extname in $db. Aborting startup." - exit 1 - fi - else - bashio::log.info "$extname in $db already at latest version ($installed_version)" - fi - fi - done + local extname="$1" + if ! is_extension_available "$extname"; then + bashio::log.info "$extname extension not available on this Postgres instance." + return + fi + local available_version + available_version=$(get_available_extension_version "$extname") + if [ -z "$available_version" ]; then + bashio::log.info "Could not determine available version for $extname." + return + fi + for db in $(get_user_databases); do + local installed_version + installed_version=$(get_installed_extension_version "$extname" "$db") + if [ -n "$installed_version" ]; then + if compare_versions "$installed_version" "$available_version"; then + bashio::log.info "Upgrading $extname in $db from $installed_version to $available_version" + if psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME@$DB_PORT/$db" -v ON_ERROR_STOP=1 -c "ALTER EXTENSION $extname UPDATE;"; then + RESTART_NEEDED=true + else + bashio::log.error "Failed to upgrade $extname in $db. Aborting startup." + exit 1 + fi + else + bashio::log.info "$extname in $db already at latest version ($installed_version)" + fi + fi + done } upgrade_postgres_if_needed() { - CLUSTER_VERSION=$(get_pgdata_version) - IMAGE_VERSION="$PG_MAJOR_VERSION" + CLUSTER_VERSION=$(get_pgdata_version) + IMAGE_VERSION="$PG_MAJOR_VERSION" - if [ "$CLUSTER_VERSION" != "$IMAGE_VERSION" ]; then - bashio::log.warning "Postgres data directory version is $CLUSTER_VERSION but image wants $IMAGE_VERSION. Running upgrade..." + if [ "$CLUSTER_VERSION" != "$IMAGE_VERSION" ]; then + bashio::log.warning "Postgres data directory version is $CLUSTER_VERSION but image wants $IMAGE_VERSION. Running upgrade..." - export DATA_DIR="$PGDATA" - export BINARIES_DIR="/usr/lib/postgresql" - export BACKUP_DIR="/config/backups" - export PSQL_VERSION="$IMAGE_VERSION" - export SUPPORTED_POSTGRES_VERSIONS="$CLUSTER_VERSION $IMAGE_VERSION" + export DATA_DIR="$PGDATA" + export BINARIES_DIR="/usr/lib/postgresql" + export BACKUP_DIR="/config/backups" + export PSQL_VERSION="$IMAGE_VERSION" + export SUPPORTED_POSTGRES_VERSIONS="$CLUSTER_VERSION $IMAGE_VERSION" - apt-get update &>/dev/null - apt-get install -y procps rsync "postgresql-$IMAGE_VERSION" "postgresql-$CLUSTER_VERSION" + apt-get update &>/dev/null + apt-get install -y procps rsync "postgresql-$IMAGE_VERSION" "postgresql-$CLUSTER_VERSION" - if [ ! -d "$BINARIES_DIR/$CLUSTER_VERSION/bin" ]; then - bashio::log.error "Old postgres binaries not found at $BINARIES_DIR/$CLUSTER_VERSION/bin" - exit 1 - fi - if [ ! -d "$BINARIES_DIR/$IMAGE_VERSION/bin" ]; then - bashio::log.error "New postgres binaries not found at $BINARIES_DIR/$IMAGE_VERSION/bin" - exit 1 - fi + if [ ! -d "$BINARIES_DIR/$CLUSTER_VERSION/bin" ]; then + bashio::log.error "Old postgres binaries not found at $BINARIES_DIR/$CLUSTER_VERSION/bin" + exit 1 + fi + if [ ! -d "$BINARIES_DIR/$IMAGE_VERSION/bin" ]; then + bashio::log.error "New postgres binaries not found at $BINARIES_DIR/$IMAGE_VERSION/bin" + exit 1 + fi - install_vchord_and_vectors_for_old_pg "$CLUSTER_VERSION" + install_vchord_and_vectors_for_old_pg "$CLUSTER_VERSION" - mkdir -p "$BACKUP_DIR" - backup_target="$BACKUP_DIR/postgresql-$CLUSTER_VERSION" - bashio::log.info "Backing up data directory to $backup_target..." - if ! rsync -a --delete "$PGDATA/" "$backup_target/"; then - bashio::log.error "Backup with rsync failed!" - exit 1 - fi + mkdir -p "$BACKUP_DIR" + backup_target="$BACKUP_DIR/postgresql-$CLUSTER_VERSION" + bashio::log.info "Backing up data directory to $backup_target..." + if ! rsync -a --delete "$PGDATA/" "$backup_target/"; then + bashio::log.error "Backup with rsync failed!" + exit 1 + fi - cp -n --preserve=mode "/var/postgresql-conf-tpl/postgresql.hdd.conf" /etc/postgresql/postgresql.conf - sed -i "s@##PGDATA@$PGDATA@" /etc/postgresql/postgresql.conf + cp -n --preserve=mode "/var/postgresql-conf-tpl/postgresql.hdd.conf" /etc/postgresql/postgresql.conf + sed -i "s@##PGDATA@$PGDATA@" /etc/postgresql/postgresql.conf - drop_vectors_everywhere "$CLUSTER_VERSION" + drop_vectors_everywhere "$CLUSTER_VERSION" - fix_permissions + fix_permissions - bashio::log.info "Starting old Postgres ($CLUSTER_VERSION) to capture encoding/locale settings" - su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/pg_ctl -w -D '$PGDATA' -o \"-c config_file=/etc/postgresql/postgresql.conf\" start" + bashio::log.info "Starting old Postgres ($CLUSTER_VERSION) to capture encoding/locale settings" + su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/pg_ctl -w -D '$PGDATA' -o \"-c config_file=/etc/postgresql/postgresql.conf\" start" - LC_COLLATE=$(su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/psql -d postgres -Atc 'SHOW LC_COLLATE;'") - LC_CTYPE=$(su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/psql -d postgres -Atc 'SHOW LC_CTYPE;'") - ENCODING=$(su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/psql -d postgres -Atc 'SHOW server_encoding;'") + LC_COLLATE=$(su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/psql -d postgres -Atc 'SHOW LC_COLLATE;'") + LC_CTYPE=$(su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/psql -d postgres -Atc 'SHOW LC_CTYPE;'") + ENCODING=$(su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/psql -d postgres -Atc 'SHOW server_encoding;'") - bashio::log.info "Detected cluster: LC_COLLATE=$LC_COLLATE, LC_CTYPE=$LC_CTYPE, ENCODING=$ENCODING" + bashio::log.info "Detected cluster: LC_COLLATE=$LC_COLLATE, LC_CTYPE=$LC_CTYPE, ENCODING=$ENCODING" - bashio::log.info "Stopping old Postgres ($CLUSTER_VERSION)" - su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/pg_ctl -w -D '$PGDATA' -o \"-c config_file=/etc/postgresql/postgresql.conf\" stop" + bashio::log.info "Stopping old Postgres ($CLUSTER_VERSION)" + su - postgres -c "$BINARIES_DIR/$CLUSTER_VERSION/bin/pg_ctl -w -D '$PGDATA' -o \"-c config_file=/etc/postgresql/postgresql.conf\" stop" - rm -rf "$PGDATA" + rm -rf "$PGDATA" - fix_permissions + fix_permissions - bashio::log.info "Initializing new data cluster for $IMAGE_VERSION" - su - postgres -c "$BINARIES_DIR/$IMAGE_VERSION/bin/initdb --encoding=$ENCODING --lc-collate=$LC_COLLATE --lc-ctype=$LC_CTYPE -D '$PGDATA'" + bashio::log.info "Initializing new data cluster for $IMAGE_VERSION" + su - postgres -c "$BINARIES_DIR/$IMAGE_VERSION/bin/initdb --encoding=$ENCODING --lc-collate=$LC_COLLATE --lc-ctype=$LC_CTYPE -D '$PGDATA'" - fix_permissions + fix_permissions - bashio::log.info "Running pg_upgrade from $CLUSTER_VERSION → $IMAGE_VERSION" - chmod 700 "$PGDATA" - chmod 700 "$backup_target" - if ! su - postgres -c "$BINARIES_DIR/$IMAGE_VERSION/bin/pg_upgrade \ + bashio::log.info "Running pg_upgrade from $CLUSTER_VERSION → $IMAGE_VERSION" + chmod 700 "$PGDATA" + chmod 700 "$backup_target" + if ! su - postgres -c "$BINARIES_DIR/$IMAGE_VERSION/bin/pg_upgrade \ -b '$BINARIES_DIR/$CLUSTER_VERSION/bin' \ -B '$BINARIES_DIR/$IMAGE_VERSION/bin' \ -d '$backup_target' \ -D '$PGDATA' -o \"-c config_file=/etc/postgresql/postgresql.conf\" -O \"-c config_file=/etc/postgresql/postgresql.conf\""; then - bashio::log.error "pg_upgrade failed!" - exit 1 - fi + bashio::log.error "pg_upgrade failed!" + exit 1 + fi - if [ -f "$backup_target/postgresql.conf" ]; then - cp "$backup_target/postgresql.conf" "$PGDATA" - fi + if [ -f "$backup_target/postgresql.conf" ]; then + cp "$backup_target/postgresql.conf" "$PGDATA" + fi - if [ -f "$backup_target/pg_hba.conf" ]; then - cp -f "$backup_target/pg_hba.conf" "$PGDATA" - fi + if [ -f "$backup_target/pg_hba.conf" ]; then + cp -f "$backup_target/pg_hba.conf" "$PGDATA" + fi - bashio::log.info "Upgrade completed successfully." - RESTART_NEEDED=true + bashio::log.info "Upgrade completed successfully." + RESTART_NEEDED=true - else - bashio::log.info "PostgreSQL data directory version ($CLUSTER_VERSION) matches image version ($IMAGE_VERSION)." - fi + else + bashio::log.info "PostgreSQL data directory version ($CLUSTER_VERSION) matches image version ($IMAGE_VERSION)." + fi } main() { - bashio::log.info "Checking for required PostgreSQL cluster upgrade before server start..." - if [ -f /config/database/PG_VERSION ]; then - upgrade_postgres_if_needed - fi + bashio::log.info "Checking for required PostgreSQL cluster upgrade before server start..." + if [ -f /config/database/PG_VERSION ]; then + upgrade_postgres_if_needed + fi - start_postgres + start_postgres - bashio::log.info "Waiting for PostgreSQL to start..." + bashio::log.info "Waiting for PostgreSQL to start..." - DB_PORT=5432 - DB_HOSTNAME=localhost - DB_PASSWORD="$(bashio::config 'POSTGRES_PASSWORD')" - DB_PASSWORD="$(jq -rn --arg x "$DB_PASSWORD" '$x|@uri')" - DB_USERNAME=postgres - if bashio::config.has_value "POSTGRES_USER"; then - DB_USERNAME="$(bashio::config "POSTGRES_USER")" - fi - export DB_PORT DB_HOSTNAME DB_USERNAME DB_PASSWORD + DB_PORT=5432 + DB_HOSTNAME=localhost + DB_PASSWORD="$(bashio::config 'POSTGRES_PASSWORD')" + DB_PASSWORD="$(jq -rn --arg x "$DB_PASSWORD" '$x|@uri')" + DB_USERNAME=postgres + if bashio::config.has_value "POSTGRES_USER"; then + DB_USERNAME="$(bashio::config "POSTGRES_USER")" + fi + export DB_PORT DB_HOSTNAME DB_USERNAME DB_PASSWORD - wait_for_postgres - restart_immich_addons_if_flagged + wait_for_postgres + restart_immich_addons_if_flagged - su - postgres -c "psql -d postgres -c 'DROP EXTENSION IF EXISTS vectors CASCADE;'" + su - postgres -c "psql -d postgres -c 'DROP EXTENSION IF EXISTS vectors CASCADE;'" - upgrade_extension_if_needed "vectors" - upgrade_extension_if_needed "vchord" - show_db_extensions + upgrade_extension_if_needed "vectors" + upgrade_extension_if_needed "vchord" + show_db_extensions - if [ "$RESTART_NEEDED" = true ]; then - bashio::log.warning "A critical update (Postgres or extension) occurred. Will trigger Immich add-on restart after DB comes back up." - touch "$RESTART_FLAG_FILE" - bashio::addon.restart - exit 0 - fi + if [ "$RESTART_NEEDED" = true ]; then + bashio::log.warning "A critical update (Postgres or extension) occurred. Will trigger Immich add-on restart after DB comes back up." + touch "$RESTART_FLAG_FILE" + bashio::addon.restart + exit 0 + fi - bashio::log.info "All initialization/version check steps completed successfully!" + bashio::log.info "All initialization/version check steps completed successfully!" - if [ -d /config/backups ]; then - echo "Cleaning /config/backups now that upgrade is done" - rm -r /config/backups - fi + if [ -d /config/backups ]; then + echo "Cleaning /config/backups now that upgrade is done" + rm -r /config/backups + fi } main diff --git a/prowlarr/rootfs/etc/cont-init.d/20-folders.sh b/prowlarr/rootfs/etc/cont-init.d/20-folders.sh index d1ca17245..07aed815b 100755 --- a/prowlarr/rootfs/etc/cont-init.d/20-folders.sh +++ b/prowlarr/rootfs/etc/cont-init.d/20-folders.sh @@ -1,15 +1,15 @@ #!/bin/bash if [ -d /config/prowlarr ] && [ ! -d /config/addons_config/prowlarr ]; then - echo "Moving to new location /config/addons_config/prowlarr" - mkdir -p /config/addons_config/prowlarr - chown -R "$PUID:$PGID" /config/addons_config/prowlarr - mv /config/prowlarr/* /config/addons_config/prowlarr/ - rm -r /config/prowlarr + echo "Moving to new location /config/addons_config/prowlarr" + mkdir -p /config/addons_config/prowlarr + chown -R "$PUID:$PGID" /config/addons_config/prowlarr + mv /config/prowlarr/* /config/addons_config/prowlarr/ + rm -r /config/prowlarr fi if [ ! -d /config/addons_config/prowlarr ]; then - echo "Creating /config/addons_config/prowlarr" - mkdir -p /config/addons_config/prowlarr - chown -R "$PUID:$PGID" /config/addons_config/prowlarr + echo "Creating /config/addons_config/prowlarr" + mkdir -p /config/addons_config/prowlarr + chown -R "$PUID:$PGID" /config/addons_config/prowlarr fi diff --git a/qbittorrent/rootfs/etc/cont-init.d/00-folders.sh b/qbittorrent/rootfs/etc/cont-init.d/00-folders.sh index e088528a7..f85788557 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/00-folders.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/00-folders.sh @@ -9,51 +9,51 @@ MIGRATED="" # Move main folder if [ -f /homeassistant/addons_config/qBittorrent/qBittorrent.conf ] && [ ! -f /homeassistant/addons_config/qBittorrent/migrated ]; then - bashio::log.warning "----------------------------------------" - bashio::log.warning "Migrating configuration to the new addon" - bashio::log.warning "----------------------------------------" - cp -rnp /homeassistant/addons_config/qBittorrent/* /config/qBittorrent/ &>/dev/null || true - if [ -d /config/qBittorrent/addons_config ]; then rm -r /config/qBittorrent/addons_config; fi - if [ -d /config/qBittorrent/qBittorrent ]; then rm -r /config/qBittorrent/qBittorrent; fi - echo "Files moved to /addon_configs/$HOSTNAME/openvpn" > /homeassistant/addons_config/qBittorrent/migrated - bashio::log.yellow "... moved files from /config/addons_config/qBittorrent to /addon_configs/$HOSTNAME/qBitorrent (must be accessed with my Filebrowser addon)" - MIGRATED=true + bashio::log.warning "----------------------------------------" + bashio::log.warning "Migrating configuration to the new addon" + bashio::log.warning "----------------------------------------" + cp -rnp /homeassistant/addons_config/qBittorrent/* /config/qBittorrent/ &>/dev/null || true + if [ -d /config/qBittorrent/addons_config ]; then rm -r /config/qBittorrent/addons_config; fi + if [ -d /config/qBittorrent/qBittorrent ]; then rm -r /config/qBittorrent/qBittorrent; fi + echo "Files moved to /addon_configs/$HOSTNAME/openvpn" >/homeassistant/addons_config/qBittorrent/migrated + bashio::log.yellow "... moved files from /config/addons_config/qBittorrent to /addon_configs/$HOSTNAME/qBitorrent (must be accessed with my Filebrowser addon)" + MIGRATED=true fi # Move config if [ -f /config/qBittorrent/config/qBittorrent.conf ]; then - mv /config/qBittorrent/config/* /config/qBittorrent/ || true - mv /config/qBittorrent/data/* /config/qBittorrent/ || true - rm -r /config/qBittorrent/config || true - rm -r /config/qBittorrent/data || true - MIGRATED=true + mv /config/qBittorrent/config/* /config/qBittorrent/ || true + mv /config/qBittorrent/data/* /config/qBittorrent/ || true + rm -r /config/qBittorrent/config || true + rm -r /config/qBittorrent/data || true + MIGRATED=true fi # Move openvpn if [ -d /homeassistant/openvpn ]; then - if [ ! -f /homeassistant/openvpn/migrated ] && [ "$(ls -A /homeassistant/openvpn)" ]; then - cp -rnf /homeassistant/openvpn/* /config/openvpn &>/dev/null || true - echo "Files moved to /addon_configs/$HOSTNAME/openvpn" > /homeassistant/openvpn/migrated - fi + if [ ! -f /homeassistant/openvpn/migrated ] && [ "$(ls -A /homeassistant/openvpn)" ]; then + cp -rnf /homeassistant/openvpn/* /config/openvpn &>/dev/null || true + echo "Files moved to /addon_configs/$HOSTNAME/openvpn" >/homeassistant/openvpn/migrated + fi fi # Move config.yaml if [ -f /homeassistant/addons_config/qbittorrent/config.yaml ] && [ ! -f /homeassistant/addons_config/qbittorrent/migrated ]; then - cp -rnf /homeassistant/addons_config/qbittorrent/* /config/ &>/dev/null || true - rm -r /homeassistant/addons_config/qbittorrent - bashio::log.yellow "... moved config.yaml from /config/addons_config/qbittorrent to /addon_configs/$HOSTNAME" + cp -rnf /homeassistant/addons_config/qbittorrent/* /config/ &>/dev/null || true + rm -r /homeassistant/addons_config/qbittorrent + bashio::log.yellow "... moved config.yaml from /config/addons_config/qbittorrent to /addon_configs/$HOSTNAME" fi # Move autoscript if [ -f /homeassistant/addons_autoscrips/qbittorrent.sh ]; then - cp -rnf /homeassistant/addons_autoscrips/qbittorrent.sh /config/ &>/dev/null || true - mv /homeassistant/addons_autoscrips/qbittorrent.sh /homeassistant/addons_autoscrips/qbittorrent.sh.bak - bashio::log.yellow "... moved qbittorrent.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME" + cp -rnf /homeassistant/addons_autoscrips/qbittorrent.sh /config/ &>/dev/null || true + mv /homeassistant/addons_autoscrips/qbittorrent.sh /homeassistant/addons_autoscrips/qbittorrent.sh.bak + bashio::log.yellow "... moved qbittorrent.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME" fi # Reboot post migration if [[ "$MIGRATED" == "true" ]]; then - bashio::log.warning "Options were changed, restarting the addon" - sleep 5 - bashio::addon.restart + bashio::log.warning "Options were changed, restarting the addon" + sleep 5 + bashio::addon.restart fi diff --git a/qbittorrent/rootfs/etc/cont-init.d/30-nginx.sh b/qbittorrent/rootfs/etc/cont-init.d/30-nginx.sh index 169f8f801..e7672635e 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/30-nginx.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/30-nginx.sh @@ -16,7 +16,7 @@ declare qbittorrent_protocol=http # Generate Ingress configuration if bashio::config.true 'ssl'; then - qbittorrent_protocol=https + qbittorrent_protocol=https fi [ "$DEBUG" = "debug" ] && echo "Before cp" diff --git a/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh b/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh index 0f3ac46eb..d9794911d 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/91-qbittorrent_configuration.sh @@ -12,7 +12,7 @@ mkdir -p "$CONFIG_LOCATION" # copy default config if [ ! -f "$CONFIG_LOCATION"/qBittorrent.conf ]; then - cp /defaults/qBittorrent.conf "$CONFIG_LOCATION"/qBittorrent.conf + cp /defaults/qBittorrent.conf "$CONFIG_LOCATION"/qBittorrent.conf fi cd "$CONFIG_LOCATION"/ || true @@ -31,9 +31,9 @@ ORIGINAL_SIZE="$(wc -c "$CONFIG_LOCATION"/qBittorrent.conf)" ########### if bashio::config.has_value 'run_duration'; then - echo "Timer mode set" + echo "Timer mode set" else - rm -r /etc/services.d/timer + rm -r /etc/services.d/timer fi ################## @@ -43,26 +43,25 @@ fi # Set configuration if bashio::config.has_value 'SavePath'; then - # Set variable - DOWNLOADS=$(bashio::config 'SavePath') - DOWNLOADS=${DOWNLOADS:-/share/downloads} # Default if not set + # Set variable + DOWNLOADS=$(bashio::config 'SavePath') + DOWNLOADS=${DOWNLOADS:-/share/downloads} # Default if not set - # Replace save path - sed -i -e "/SavePath/d" \ - -e "/\[Preferences\]/a Downloads\\\SavePath=$DOWNLOADS" \ - -e "/\[AutoRun\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \ - -e "/\[Preferences\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \ - -e "/\[BitTorrent\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \ - -e "/\[BitTorrent\]/a Session\\\DefaultSavePath=$DOWNLOADS" qBittorrent.conf + # Replace save path + sed -i -e "/SavePath/d" \ + -e "/\[Preferences\]/a Downloads\\\SavePath=$DOWNLOADS" \ + -e "/\[AutoRun\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \ + -e "/\[Preferences\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \ + -e "/\[BitTorrent\]/a Downloads\\\DefaultSavePath=$DOWNLOADS" \ + -e "/\[BitTorrent\]/a Session\\\DefaultSavePath=$DOWNLOADS" qBittorrent.conf - - # Info - bashio::log.info "Downloads can be found in $DOWNLOADS" + # Info + bashio::log.info "Downloads can be found in $DOWNLOADS" fi # Create default location if [ ! -d "$DOWNLOADS" ]; then - mkdir -p "$DOWNLOADS" || bashio::log.fatal "Error : folder defined in SavePath doesn't exist and can't be created. Check path" + mkdir -p "$DOWNLOADS" || bashio::log.fatal "Error : folder defined in SavePath doesn't exist and can't be created. Check path" fi chown -R "$PUID:$PGID" "$DOWNLOADS" || bashio::log.fatal "Error, please check default save folder configuration in addon" @@ -71,13 +70,13 @@ chown -R "$PUID:$PGID" "$DOWNLOADS" || bashio::log.fatal "Error, please check de ############## sed -i -e "/CSRFProtection/d" \ - -e "/ClickjackingProtection/d" \ - -e "/HostHeaderValidation/d" \ - -e "/WebUI\\\Address/d" \ - -e "/\[Preferences\]/a \WebUI\\\CSRFProtection=false" \ - -e "/\[Preferences\]/a \WebUI\\\ClickjackingProtection=false" \ - -e "/\[Preferences\]/a \WebUI\\\HostHeaderValidation=false" \ - -e "/\[Preferences\]/a \WebUI\\\Address=\*" qBittorrent.conf + -e "/ClickjackingProtection/d" \ + -e "/HostHeaderValidation/d" \ + -e "/WebUI\\\Address/d" \ + -e "/\[Preferences\]/a \WebUI\\\CSRFProtection=false" \ + -e "/\[Preferences\]/a \WebUI\\\ClickjackingProtection=false" \ + -e "/\[Preferences\]/a \WebUI\\\HostHeaderValidation=false" \ + -e "/\[Preferences\]/a \WebUI\\\Address=\*" qBittorrent.conf #sed -i '/WebUI\ReverseProxySupportEnabled/d' qBittorrent.conf #sed -i "$LINE i\WebUI\\\ReverseProxySupportEnabled=true" qBittorrent.conf @@ -99,15 +98,15 @@ sed -i '/HTTPS/d' qBittorrent.conf bashio::config.require.ssl if bashio::config.true 'ssl'; then - bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths" - #set variables - CERTFILE=$(bashio::config 'certfile') - KEYFILE=$(bashio::config 'keyfile') + bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths" + #set variables + CERTFILE=$(bashio::config 'certfile') + KEYFILE=$(bashio::config 'keyfile') - #Modify configuration - sed -i "$LINE i\WebUI\\\HTTPS\\\Enabled=True" qBittorrent.conf - sed -i "$LINE i\WebUI\\\HTTPS\\\CertificatePath=/ssl/$CERTFILE" qBittorrent.conf - sed -i "$LINE i\WebUI\\\HTTPS\\\KeyPath=/ssl/$KEYFILE" qBittorrent.conf + #Modify configuration + sed -i "$LINE i\WebUI\\\HTTPS\\\Enabled=True" qBittorrent.conf + sed -i "$LINE i\WebUI\\\HTTPS\\\CertificatePath=/ssl/$CERTFILE" qBittorrent.conf + sed -i "$LINE i\WebUI\\\HTTPS\\\KeyPath=/ssl/$KEYFILE" qBittorrent.conf fi ################ @@ -124,12 +123,12 @@ WHITELIST="${WHITELIST//,/,\ }" sed -i '/AuthSubnetWhitelist/d' qBittorrent.conf if [[ "${#WHITELIST}" -gt 5 ]]; then - sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=true" qBittorrent.conf - sed -i "$LINE i\WebUI\\\AuthSubnetWhitelist=$WHITELIST" qBittorrent.conf - bashio::log.info "Whitelisted subsets will not require a password : $WHITELIST" + sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=true" qBittorrent.conf + sed -i "$LINE i\WebUI\\\AuthSubnetWhitelist=$WHITELIST" qBittorrent.conf + bashio::log.info "Whitelisted subsets will not require a password : $WHITELIST" else - sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=false" qBittorrent.conf - bashio::log.info "Whitelisted subsets deactivated" + sed -i "$LINE i\WebUI\\\AuthSubnetWhitelistEnabled=false" qBittorrent.conf + bashio::log.info "Whitelisted subsets deactivated" fi ############### @@ -138,9 +137,9 @@ fi cd "$CONFIG_LOCATION"/ || true if bashio::config.has_value 'Username'; then - USERNAME="$(bashio::config 'Username')" + USERNAME="$(bashio::config 'Username')" else - USERNAME="admin" + USERNAME="admin" fi #clean data @@ -151,7 +150,7 @@ bashio::log.info "WEBUI username set to $USERNAME" # Add default password if not existing if ! grep -q Password_PBKDF2 qBittorrent.conf; then - sed -i "/\[Preferences\]/a\WebUI\\\Password_PBKDF2=\"@ByteArray(cps93Gf8ma8EM3QRon+spg==:wYFoMNVmdiqzWYQ6mFrvET+RRbBSIPVfXFFeEy0ZEagxvNuEF7uGVnG5iq8oeu38kGLtmJqCM2w8cTdtORDP2A==)\"" qBittorrent.conf + sed -i "/\[Preferences\]/a\WebUI\\\Password_PBKDF2=\"@ByteArray(cps93Gf8ma8EM3QRon+spg==:wYFoMNVmdiqzWYQ6mFrvET+RRbBSIPVfXFFeEy0ZEagxvNuEF7uGVnG5iq8oeu38kGLtmJqCM2w8cTdtORDP2A==)\"" qBittorrent.conf fi #################### @@ -162,9 +161,9 @@ fi # Check file size if [[ "$ORIGINAL_SIZE" != "$(wc -c "$CONFIG_LOCATION"/qBittorrent.conf)" ]]; then - bashio::log.warning "Configuration changed, rebooting" - sleep 5 - bashio::addon.restart + bashio::log.warning "Configuration changed, rebooting" + sleep 5 + bashio::addon.restart fi ################ @@ -175,62 +174,62 @@ CUSTOMUI=$(bashio::config 'customUI') # Clean data if not custom if [ ! "$CUSTOMUI" = custom ]; then - sed -i '/AlternativeUIEnabled/d' qBittorrent.conf - sed -i '/RootFolder/d' qBittorrent.conf - rm -f -r /webui - mkdir -p /webui - chown "$PUID:$PGID" /webui + sed -i '/AlternativeUIEnabled/d' qBittorrent.conf + sed -i '/RootFolder/d' qBittorrent.conf + rm -f -r /webui + mkdir -p /webui + chown "$PUID:$PGID" /webui fi # Clean data if not custom if [ "$CUSTOMUI" = default ]; then - echo "" - bashio::log.warning "Default Webui selected ! It will not work for ingress, which will stay with vuetorrent" - echo "" - sed -i '/AlternativeUIEnabled/d' qBittorrent.conf - sed -i '/RootFolder/d' qBittorrent.conf - # Update ingress webui - curl -f -s -S -O -J -L "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null - unzip -o vuetorrent.zip -d / >/dev/null - rm vuetorrent.zip + echo "" + bashio::log.warning "Default Webui selected ! It will not work for ingress, which will stay with vuetorrent" + echo "" + sed -i '/AlternativeUIEnabled/d' qBittorrent.conf + sed -i '/RootFolder/d' qBittorrent.conf + # Update ingress webui + curl -f -s -S -O -J -L "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null + unzip -o vuetorrent.zip -d / >/dev/null + rm vuetorrent.zip fi # Install webui if bashio::config.has_value 'customUI' && [ ! "$CUSTOMUI" = default ] && [ ! "$CUSTOMUI" = custom ]; then - ### Variables - bashio::log.info "Alternate UI enabled : $CUSTOMUI. If webui don't work, disable this option" + ### Variables + bashio::log.info "Alternate UI enabled : $CUSTOMUI. If webui don't work, disable this option" - ### Download WebUI - case $CUSTOMUI in - "vuetorrent") - curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases/latest | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null - ;; + ### Download WebUI + case $CUSTOMUI in + "vuetorrent") + curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/WDaan/VueTorrent/releases/latest | grep -o "http.*vuetorrent.zip" | head -1)" >/dev/null + ;; - "qbit-matUI") - curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/bill-ahmed/qbit-matUI/releases/latest | grep -o "http.*Unix.*.zip" | head -1)" >/dev/null - echo "" - bashio::log.warning "qbit-matUI selected ! It will not work for ingress, which will stay with vuetorrent" - echo "" - ;; + "qbit-matUI") + curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/bill-ahmed/qbit-matUI/releases/latest | grep -o "http.*Unix.*.zip" | head -1)" >/dev/null + echo "" + bashio::log.warning "qbit-matUI selected ! It will not work for ingress, which will stay with vuetorrent" + echo "" + ;; - "qb-web") - curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/CzBiX/qb-web/releases | grep -o "http.*qb-web-.*zip" | head -1)" >/dev/null - ;; + "qb-web") + curl -f -s -S -J -L -o /webui/release.zip "$(curl -f -s -L https://api.github.com/repos/CzBiX/qb-web/releases | grep -o "http.*qb-web-.*zip" | head -1)" >/dev/null + ;; - esac || { bashio::log.warning "$CUSTOMUI could not be downloaded, please raise an issue on the github repository. The default UI will be used" && exit 0 ; } + esac || { bashio::log.warning "$CUSTOMUI could not be downloaded, please raise an issue on the github repository. The default UI will be used" && exit 0; } - ### Install WebUI - mkdir -p /webui/"$CUSTOMUI" - unzip -q /webui/release.zip -d /webui/"$CUSTOMUI" - rm /webui/*.zip - CUSTOMUIDIR="$(dirname "$(find /webui/"$CUSTOMUI" -iname "public" -type d)")" - sed -i "$LINE i\WebUI\\\AlternativeUIEnabled=true" "$CONFIG_LOCATION"/qBittorrent.conf - sed -i "$LINE i\WebUI\\\RootFolder=$CUSTOMUIDIR" "$CONFIG_LOCATION"/qBittorrent.conf - # Set ingress ui - if [[ "$CUSTOMUI" != qbit-matUI ]]; then - sed -i "s=/vuetorrent/public/=$CUSTOMUIDIR/public/=g" /etc/nginx/servers/ingress.conf || true - sed -i "s=vue.torrent=$CUSTOMUI.torrent=g" /etc/nginx/servers/ingress.conf || true - fi + ### Install WebUI + mkdir -p /webui/"$CUSTOMUI" + unzip -q /webui/release.zip -d /webui/"$CUSTOMUI" + rm /webui/*.zip + CUSTOMUIDIR="$(dirname "$(find /webui/"$CUSTOMUI" -iname "public" -type d)")" + sed -i "$LINE i\WebUI\\\AlternativeUIEnabled=true" "$CONFIG_LOCATION"/qBittorrent.conf + sed -i "$LINE i\WebUI\\\RootFolder=$CUSTOMUIDIR" "$CONFIG_LOCATION"/qBittorrent.conf + # Set ingress ui + if [[ "$CUSTOMUI" != qbit-matUI ]]; then + sed -i "s=/vuetorrent/public/=$CUSTOMUIDIR/public/=g" /etc/nginx/servers/ingress.conf || true + sed -i "s=vue.torrent=$CUSTOMUI.torrent=g" /etc/nginx/servers/ingress.conf || true + fi fi ########## diff --git a/qbittorrent/rootfs/etc/cont-init.d/92-qbit_manage.sh b/qbittorrent/rootfs/etc/cont-init.d/92-qbit_manage.sh index f10d7ba6c..fc0a47db4 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/92-qbit_manage.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/92-qbit_manage.sh @@ -4,37 +4,38 @@ set -e if bashio::config.true "qbit_manage"; then - bashio::log.info "qbit_manage activated, setting system" + bashio::log.info "qbit_manage activated, setting system" - # Set folder - echo "... setting folder" - mkdir -p /config/qbit_manage - chmod -R 777 /config/qbit_manage + # Set folder + echo "... setting folder" + mkdir -p /config/qbit_manage + chmod -R 777 /config/qbit_manage - # Create default file - if [ ! -f /config/qbit_manage/qbit_manage.yml ]; then - echo "... create default file" - cp /qbit_manage/config/config.yml.sample /config/qbit_manage/qbit_manage.yml - fi + # Create default file + if [ ! -f /config/qbit_manage/qbit_manage.yml ]; then + echo "... create default file" + cp /qbit_manage/config/config.yml.sample /config/qbit_manage/qbit_manage.yml + fi - # Set qBittorrent options - echo "... align QBT username and password" - # qBittorrent path to local - echo "... default url set to 127.0.0.1, change manually if you have an external qbt system" - sed -i "s/localhost/127.0.0.1/g" /config/qbit_manage/qbit_manage.yml - # Set password from options - echo "... setting username to the addon options one" - sed -i "/user:/c\ user: '$(bashio::config 'Username')'" /config/qbit_manage/qbit_manage.yml - # If password is default, correct - echo "... default password set to homeassistant, change manually in the file if not" - sed -i "/pass: password/c\ pass: homeassistant" /config/qbit_manage/qbit_manage.yml - # Set root dir - echo "... downloads directory set to $(bashio::config 'SavePath')" - sed -i "/ root_dir/d" /config/qbit_manage/qbit_manage.yml - sed -i "/directory:/a\ root_dir: \"$(bashio::config 'SavePath')\"" /config/qbit_manage/qbit_manage.yml + # Set qBittorrent options + echo "... align QBT username and password" + # qBittorrent path to local + echo "... default url set to 127.0.0.1, change manually if you have an external qbt system" + sed -i "s/localhost/127.0.0.1/g" /config/qbit_manage/qbit_manage.yml + # Set password from options + echo "... setting username to the addon options one" + sed -i "/user:/c\ user: '$(bashio::config 'Username')'" /config/qbit_manage/qbit_manage.yml + # If password is default, correct + echo "... default password set to homeassistant, change manually in the file if not" + sed -i "/pass: password/c\ pass: homeassistant" /config/qbit_manage/qbit_manage.yml + # Set root dir + echo "... downloads directory set to $(bashio::config 'SavePath')" + sed -i "/ root_dir/d" /config/qbit_manage/qbit_manage.yml + sed -i "/directory:/a\ root_dir: \"$(bashio::config 'SavePath')\"" /config/qbit_manage/qbit_manage.yml - # Startup delay 30s ; config file specific ; log file specific - python /qbit_manage/qbit_manage.py -sd 30 --config-file "/config/qbit_manage/qbit_manage.yml" --log-file "/config/qbit_manage/qbit_manage.log" & true - bashio::log.info "qbit_manage started with config in /addon_configs/$HOSTNAME/qbit_manage/qbit_manage.yaml accessible with the Filebrowser addon" + # Startup delay 30s ; config file specific ; log file specific + python /qbit_manage/qbit_manage.py -sd 30 --config-file "/config/qbit_manage/qbit_manage.yml" --log-file "/config/qbit_manage/qbit_manage.log" & + true + bashio::log.info "qbit_manage started with config in /addon_configs/$HOSTNAME/qbit_manage/qbit_manage.yaml accessible with the Filebrowser addon" fi diff --git a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh index d273bdd83..3f4edee41 100755 --- a/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh +++ b/qbittorrent/rootfs/etc/cont-init.d/93-openvpn.sh @@ -10,260 +10,260 @@ QBT_CONFIG_FILE="/config/qBittorrent/qBittorrent.conf" if bashio::config.true 'openvpn_enabled'; then - bashio::log.info "----------------------------" - bashio::log.info "Openvpn enabled, configuring" - bashio::log.info "----------------------------" + bashio::log.info "----------------------------" + bashio::log.info "Openvpn enabled, configuring" + bashio::log.info "----------------------------" - # Get current ip - curl -s ipecho.net/plain > /currentip + # Get current ip + curl -s ipecho.net/plain >/currentip - # Function to check for files path - function check_path () { + # Function to check for files path + function check_path() { - # Get variable - file="$1" + # Get variable + file="$1" - # Double check exists - if [ ! -f "$file" ]; then - bashio::warning "$file not found" - return 1 - fi - - # Check each lines - cp "$file" /tmpfile - line_number=0 - while read -r line; do - # Increment the line number - ((line_number=line_number+1)) + # Double check exists + if [ ! -f "$file" ]; then + bashio::warning "$file not found" + return 1 + fi - # Check if lines starting with auth-user-pass have a valid argument - ################################################################### - if [[ "$line" == "auth-user-pass"* ]]; then - # Extract the second argument - file_name="$(echo "$line" | awk -F' ' '{print $2}')" - # If second argument is null or - - if [ -z "$file_name" ] || [[ "$file_name" == -* ]]; then - # Insert to explain why a comment is made - sed -i "${line_number}i # The following line is commented out as does not contain a valid argument" "$file" - # Increment as new line added - ((line_number=line_number+1)) - # Comment out the line - sed -i "${line_number}s/^/# /" "$file" - # Go to next line - continue - fi - fi - - # Check if the line contains a txt file - ####################################### - if [[ ! $line =~ ^"#" ]] && [[ ! $line =~ ^";" ]] && [[ "$line" == *" "*"."* ]] || [[ "$line" == "auth-user-pass"* ]]; then - # Extract the txt file name from the line - file_name="$(echo "$line" | awk -F' ' '{print $2}')" - # if contains only numbers and dots it is likely an ip, don't check it - if [[ "$file_name" =~ ^[0-9\.]+$ ]]; then - continue - fi - # Check if the txt file exists - if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [ ! -f "$file_name" ]; then - # Check if the txt file exists in the /config/openvpn/ directory - if [ -f "/config/openvpn/${file_name##*/}" ]; then - # Append /config/openvpn/ in front of the original txt file in the ovpn file - sed -i "${line_number}s|$file_name|/config/openvpn/${file_name##*/}|" "$file" - # Print a success message - bashio::log.warning "Appended /config/openvpn/ to ${file_name##*/} in $file" - else - # Print an error message - bashio::log.warning "$file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory" - fi - fi - fi - done < /tmpfile - rm /tmpfile + # Check each lines + cp "$file" /tmpfile + line_number=0 + while read -r line; do + # Increment the line number + ((line_number = line_number + 1)) - # Standardize lf - dos2unix "$file" + # Check if lines starting with auth-user-pass have a valid argument + ################################################################### + if [[ "$line" == "auth-user-pass"* ]]; then + # Extract the second argument + file_name="$(echo "$line" | awk -F' ' '{print $2}')" + # If second argument is null or - + if [ -z "$file_name" ] || [[ "$file_name" == -* ]]; then + # Insert to explain why a comment is made + sed -i "${line_number}i # The following line is commented out as does not contain a valid argument" "$file" + # Increment as new line added + ((line_number = line_number + 1)) + # Comment out the line + sed -i "${line_number}s/^/# /" "$file" + # Go to next line + continue + fi + fi - # Remove custom up & down - sed -i '/^up /s/^/#/' "$file" - sed -i '/^down /s/^/#/' "$file" + # Check if the line contains a txt file + ####################################### + if [[ ! $line =~ ^"#" ]] && [[ ! $line =~ ^";" ]] && [[ "$line" == *" "*"."* ]] || [[ "$line" == "auth-user-pass"* ]]; then + # Extract the txt file name from the line + file_name="$(echo "$line" | awk -F' ' '{print $2}')" + # if contains only numbers and dots it is likely an ip, don't check it + if [[ "$file_name" =~ ^[0-9\.]+$ ]]; then + continue + fi + # Check if the txt file exists + if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [ ! -f "$file_name" ]; then + # Check if the txt file exists in the /config/openvpn/ directory + if [ -f "/config/openvpn/${file_name##*/}" ]; then + # Append /config/openvpn/ in front of the original txt file in the ovpn file + sed -i "${line_number}s|$file_name|/config/openvpn/${file_name##*/}|" "$file" + # Print a success message + bashio::log.warning "Appended /config/openvpn/ to ${file_name##*/} in $file" + else + # Print an error message + bashio::log.warning "$file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory" + fi + fi + fi + done /dev/null 2>&1; then - # Look for openvpn files - # Wildcard search for openvpn config files and store results in array - mapfile -t VPN_CONFIGS < <( find /config/openvpn -maxdepth 1 -name "*.ovpn" -print ) - # Choose random config - VPN_CONFIG="${VPN_CONFIGS[$RANDOM % ${#VPN_CONFIGS[@]}]}" - # Get the VPN_CONFIG name without the path and extension - openvpn_config="${VPN_CONFIG##*/}" - echo "... Openvpn enabled, but openvpn_config option empty. Selecting a random ovpn file : ${openvpn_config}. Other available files :" - printf '%s\n' "${VPN_CONFIGS[@]}" - # If openvpn_enabled set, config not set, and openvpn folder empty - else - bashio::exit.nok "openvpn_enabled is set, however, your openvpn folder is empty ! Are you sure you added it in /addon_configs/$HOSTNAME/openvpn using the Filebrowser addon ?" - fi + ##################### + # CONFIGURE OPENVPN # + ##################### - # Send to openvpn script - sed -i "s|/config/openvpn/config.ovpn|/config/openvpn/$openvpn_config|g" /etc/s6-overlay/s6-rc.d/svc-qbittorrent/run - - # Check path - check_path /config/openvpn/"${openvpn_config}" + # If openvpn_config option used + if bashio::config.has_value "openvpn_config"; then + openvpn_config=$(bashio::config 'openvpn_config') + # If file found + if [ -f /config/openvpn/"$openvpn_config" ]; then + # If correct type + if [[ "$openvpn_config" == *".ovpn" ]] || [[ "$openvpn_config" == *".conf" ]]; then + echo "... configured ovpn file : using /addon_configs/$HOSTNAME/openvpn/$openvpn_config" + else + bashio::exit.nok "Configured ovpn file : $openvpn_config is set but does not end by .ovpn ; it can't be used!" + fi + else + bashio::exit.nok "Configured ovpn file : $openvpn_config not found! Are you sure you added it in /addon_configs/$HOSTNAME/openvpn using the Filebrowser addon ?" + fi - # Set credentials - if bashio::config.has_value "openvpn_username"; then - openvpn_username=$(bashio::config 'openvpn_username') - echo "${openvpn_username}" >/etc/openvpn/credentials - else - bashio::exit.nok "Openvpn is enabled, but openvpn_username option is empty! Exiting" - fi - if bashio::config.has_value "openvpn_password"; then - openvpn_password=$(bashio::config 'openvpn_password') - echo "${openvpn_password}" >>/etc/openvpn/credentials - else - bashio::exit.nok "Openvpn is enabled, but openvpn_password option is empty! Exiting" - fi + # If openvpn_config not set, but folder is not empty + elif ls /config/openvpn/*.ovpn >/dev/null 2>&1; then + # Look for openvpn files + # Wildcard search for openvpn config files and store results in array + mapfile -t VPN_CONFIGS < <(find /config/openvpn -maxdepth 1 -name "*.ovpn" -print) + # Choose random config + VPN_CONFIG="${VPN_CONFIGS[$RANDOM % ${#VPN_CONFIGS[@]}]}" + # Get the VPN_CONFIG name without the path and extension + openvpn_config="${VPN_CONFIG##*/}" + echo "... Openvpn enabled, but openvpn_config option empty. Selecting a random ovpn file : ${openvpn_config}. Other available files :" + printf '%s\n' "${VPN_CONFIGS[@]}" + # If openvpn_enabled set, config not set, and openvpn folder empty + else + bashio::exit.nok "openvpn_enabled is set, however, your openvpn folder is empty ! Are you sure you added it in /addon_configs/$HOSTNAME/openvpn using the Filebrowser addon ?" + fi - # Add credentials file - if grep -q ^auth-user-pass /config/openvpn/"$openvpn_config" ; then - # Credentials specified are they custom ? - file_name="$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config" | awk -F' ' '{print $2}')" - file_name="${file_name:-null}" - if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [[ "$file_name" != "null" ]]; then - if [ -f "$file_name" ]; then - # If credential specified, exists, and is not the addon default - bashio::log.warning "auth-user-pass specified in the ovpn file, addon username and passwords won't be used !" - else - # Credential referenced but doesn't exist - bashio::log.warning "auth-user-pass $file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory. The addon will attempt to use it's own username and password instead." - # Comment previous lines - sed -i '/^auth-user-pass/i # specified auth-user-pass file not found, disabling' /config/openvpn/"$openvpn_config" - sed -i '/^auth-user-pass/s/^/#/' /config/openvpn/"$openvpn_config" - # No credentials specified, using addons username and password - echo "# Please do not remove the line below, it allows using the addon username and password" >> /config/openvpn/"$openvpn_config" - echo "auth-user-pass /etc/openvpn/credentials" >> /etc/openvpn/"$openvpn_config" - fi - else - # Standardize just to be sure - sed -i "/\/etc\/openvpn\/credentials/c auth-user-pass \/etc\/openvpn\/credentials" /config/openvpn/"$openvpn_config" - fi - else - # No credentials specified, using addons username and password - echo "# Please do not remove the line below, it allows using the addon username and password" >> /config/openvpn/"$openvpn_config" - echo "auth-user-pass /etc/openvpn/credentials" >> /config/openvpn/"$openvpn_config" - fi + # Send to openvpn script + sed -i "s|/config/openvpn/config.ovpn|/config/openvpn/$openvpn_config|g" /etc/s6-overlay/s6-rc.d/svc-qbittorrent/run - # Permissions - chmod 755 /config/openvpn/* - chmod 755 /etc/openvpn/* - chmod 600 /etc/openvpn/credentials - chmod 755 /etc/openvpn/up.sh - chmod 755 /etc/openvpn/down.sh - chmod 755 /etc/openvpn/up-qbittorrent.sh - chmod +x /etc/openvpn/up.sh - chmod +x /etc/openvpn/down.sh - chmod +x /etc/openvpn/up-qbittorrent.sh + # Check path + check_path /config/openvpn/"${openvpn_config}" - echo "... openvpn correctly set, qbittorrent will run tunnelled through openvpn" + # Set credentials + if bashio::config.has_value "openvpn_username"; then + openvpn_username=$(bashio::config 'openvpn_username') + echo "${openvpn_username}" >/etc/openvpn/credentials + else + bashio::exit.nok "Openvpn is enabled, but openvpn_username option is empty! Exiting" + fi + if bashio::config.has_value "openvpn_password"; then + openvpn_password=$(bashio::config 'openvpn_password') + echo "${openvpn_password}" >>/etc/openvpn/credentials + else + bashio::exit.nok "Openvpn is enabled, but openvpn_password option is empty! Exiting" + fi - ######################### - # CONFIGURE QBITTORRENT # - ######################### + # Add credentials file + if grep -q ^auth-user-pass /config/openvpn/"$openvpn_config"; then + # Credentials specified are they custom ? + file_name="$(sed -n "/^auth-user-pass/p" /config/openvpn/"$openvpn_config" | awk -F' ' '{print $2}')" + file_name="${file_name:-null}" + if [[ "$file_name" != *"/etc/openvpn/credentials"* ]] && [[ "$file_name" != "null" ]]; then + if [ -f "$file_name" ]; then + # If credential specified, exists, and is not the addon default + bashio::log.warning "auth-user-pass specified in the ovpn file, addon username and passwords won't be used !" + else + # Credential referenced but doesn't exist + bashio::log.warning "auth-user-pass $file_name is referenced in your ovpn file but does not exist, and can't be found either in the /config/openvpn/ directory. The addon will attempt to use it's own username and password instead." + # Comment previous lines + sed -i '/^auth-user-pass/i # specified auth-user-pass file not found, disabling' /config/openvpn/"$openvpn_config" + sed -i '/^auth-user-pass/s/^/#/' /config/openvpn/"$openvpn_config" + # No credentials specified, using addons username and password + echo "# Please do not remove the line below, it allows using the addon username and password" >>/config/openvpn/"$openvpn_config" + echo "auth-user-pass /etc/openvpn/credentials" >>/etc/openvpn/"$openvpn_config" + fi + else + # Standardize just to be sure + sed -i "/\/etc\/openvpn\/credentials/c auth-user-pass \/etc\/openvpn\/credentials" /config/openvpn/"$openvpn_config" + fi + else + # No credentials specified, using addons username and password + echo "# Please do not remove the line below, it allows using the addon username and password" >>/config/openvpn/"$openvpn_config" + echo "auth-user-pass /etc/openvpn/credentials" >>/config/openvpn/"$openvpn_config" + fi - # WITH CONTAINER BINDING - ######################### - # If alternative mode enabled, bind container - if bashio::config.true 'openvpn_alt_mode'; then - echo "Using container binding" + # Permissions + chmod 755 /config/openvpn/* + chmod 755 /etc/openvpn/* + chmod 600 /etc/openvpn/credentials + chmod 755 /etc/openvpn/up.sh + chmod 755 /etc/openvpn/down.sh + chmod 755 /etc/openvpn/up-qbittorrent.sh + chmod +x /etc/openvpn/up.sh + chmod +x /etc/openvpn/down.sh + chmod +x /etc/openvpn/up-qbittorrent.sh - # Remove interface - echo "... deleting previous interface settings" - sed -i '/Interface/d' "$QBT_CONFIG_FILE" + echo "... openvpn correctly set, qbittorrent will run tunnelled through openvpn" - # Modify ovpn config - if grep -q route-nopull /config/openvpn/"$openvpn_config"; then - echo "... removing route-nopull from your config.ovpn" - sed -i '/route-nopull/d' /config/openvpn/"$openvpn_config" - fi + ######################### + # CONFIGURE QBITTORRENT # + ######################### - # Exit - exit 0 - fi + # WITH CONTAINER BINDING + ######################### + # If alternative mode enabled, bind container + if bashio::config.true 'openvpn_alt_mode'; then + echo "Using container binding" - # WITH INTERFACE BINDING - ######################### - # Connection with interface binding - echo "Using interface binding in the qBittorrent app" + # Remove interface + echo "... deleting previous interface settings" + sed -i '/Interface/d' "$QBT_CONFIG_FILE" - # Define preferences line - cd /config/qBittorrent/ || exit 1 + # Modify ovpn config + if grep -q route-nopull /config/openvpn/"$openvpn_config"; then + echo "... removing route-nopull from your config.ovpn" + sed -i '/route-nopull/d' /config/openvpn/"$openvpn_config" + fi - # If qBittorrent.conf exists - if [ -f "$QBT_CONFIG_FILE" ]; then - # Remove previous line and bind tun0 - echo "... deleting previous interface settings" - sed -i '/Interface/d' "$QBT_CONFIG_FILE" + # Exit + exit 0 + fi - # Bind tun0 - echo "... binding tun0 interface in qBittorrent configuration" - sed -i "/\[Preferences\]/ i\Connection\\\Interface=tun0" "$QBT_CONFIG_FILE" - sed -i "/\[Preferences\]/ i\Connection\\\InterfaceName=tun0" "$QBT_CONFIG_FILE" + # WITH INTERFACE BINDING + ######################### + # Connection with interface binding + echo "Using interface binding in the qBittorrent app" - # Add to ongoing session - sed -i "/\[BitTorrent\]/a \Session\\\Interface=tun0" "$QBT_CONFIG_FILE" - sed -i "/\[BitTorrent\]/a \Session\\\InterfaceName=tun0" "$QBT_CONFIG_FILE" + # Define preferences line + cd /config/qBittorrent/ || exit 1 - else - bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options " - exit 1 - fi + # If qBittorrent.conf exists + if [ -f "$QBT_CONFIG_FILE" ]; then + # Remove previous line and bind tun0 + echo "... deleting previous interface settings" + sed -i '/Interface/d' "$QBT_CONFIG_FILE" - # Modify ovpn config - if ! grep -q route-nopull /config/openvpn/"$openvpn_config"; then - echo "... adding route-nopull to your config.ovpn" - sed -i "1a route-nopull" /config/openvpn/"$openvpn_config" - fi + # Bind tun0 + echo "... binding tun0 interface in qBittorrent configuration" + sed -i "/\[Preferences\]/ i\Connection\\\Interface=tun0" "$QBT_CONFIG_FILE" + sed -i "/\[Preferences\]/ i\Connection\\\InterfaceName=tun0" "$QBT_CONFIG_FILE" + + # Add to ongoing session + sed -i "/\[BitTorrent\]/a \Session\\\Interface=tun0" "$QBT_CONFIG_FILE" + sed -i "/\[BitTorrent\]/a \Session\\\InterfaceName=tun0" "$QBT_CONFIG_FILE" + + else + bashio::log.error "qBittorrent config file doesn't exist, openvpn must be added manually to qbittorrent options " + exit 1 + fi + + # Modify ovpn config + if ! grep -q route-nopull /config/openvpn/"$openvpn_config"; then + echo "... adding route-nopull to your config.ovpn" + sed -i "1a route-nopull" /config/openvpn/"$openvpn_config" + fi else - ################## - # REMOVE OPENVPN # - ################## + ################## + # REMOVE OPENVPN # + ################## - # Ensure no redirection by removing the direction tag - if [ -f "$QBT_CONFIG_FILE" ]; then - sed -i '/Interface/d' "$QBT_CONFIG_FILE" - fi - bashio::log.info "Direct connection without VPN enabled" + # Ensure no redirection by removing the direction tag + if [ -f "$QBT_CONFIG_FILE" ]; then + sed -i '/Interface/d' "$QBT_CONFIG_FILE" + fi + bashio::log.info "Direct connection without VPN enabled" fi diff --git a/qbittorrent/rootfs/etc/openvpn/down.sh b/qbittorrent/rootfs/etc/openvpn/down.sh index 0355af840..ab944d904 100755 --- a/qbittorrent/rootfs/etc/openvpn/down.sh +++ b/qbittorrent/rootfs/etc/openvpn/down.sh @@ -5,30 +5,30 @@ # Contributed by Roy Marples (uberlord@gentoo.org) # If we have a service specific script, run this now -if [ -x /etc/openvpn/"${RC_SVCNAME}"-down.sh ] ; then - /etc/openvpn/"${RC_SVCNAME}"-down.sh "$@" +if [ -x /etc/openvpn/"${RC_SVCNAME}"-down.sh ]; then + /etc/openvpn/"${RC_SVCNAME}"-down.sh "$@" fi # Restore resolv.conf to how it was if [ "${PEER_DNS}" != "no" ]; then - if [ -x /sbin/resolvconf ] ; then - /sbin/resolvconf -d "${dev}" - elif [ -e /etc/resolv.conf-"${dev}".sv ] ; then - # Important that we cat instead of move incase resolv.conf is - # a symlink and not an actual file - cat /etc/resolv.conf-"${dev}".sv > /etc/resolv.conf - rm -f /etc/resolv.conf-"${dev}".sv - fi + if [ -x /sbin/resolvconf ]; then + /sbin/resolvconf -d "${dev}" + elif [ -e /etc/resolv.conf-"${dev}".sv ]; then + # Important that we cat instead of move incase resolv.conf is + # a symlink and not an actual file + cat /etc/resolv.conf-"${dev}".sv >/etc/resolv.conf + rm -f /etc/resolv.conf-"${dev}".sv + fi fi if [ -n "${RC_SVCNAME}" ]; then - # Re-enter the init script to start any dependant services - if /etc/init.d/"${RC_SVCNAME}" --quiet status ; then - export IN_BACKGROUND=true - if [ -d /var/run/s6/container_environment ]; then printf "%s" "true" > /var/run/s6/container_environment/IN_BACKGROUND; fi - printf "%s\n" "IN_BACKGROUND=\"true\"" >> ~/.bashrc - /etc/init.d/"${RC_SVCNAME}" --quiet stop - fi + # Re-enter the init script to start any dependant services + if /etc/init.d/"${RC_SVCNAME}" --quiet status; then + export IN_BACKGROUND=true + if [ -d /var/run/s6/container_environment ]; then printf "%s" "true" >/var/run/s6/container_environment/IN_BACKGROUND; fi + printf "%s\n" "IN_BACKGROUND=\"true\"" >>~/.bashrc + /etc/init.d/"${RC_SVCNAME}" --quiet stop + fi fi exit 0 diff --git a/qbittorrent/rootfs/etc/openvpn/up-qbittorrent.sh b/qbittorrent/rootfs/etc/openvpn/up-qbittorrent.sh index 0f0101dbc..67bd3211f 100755 --- a/qbittorrent/rootfs/etc/openvpn/up-qbittorrent.sh +++ b/qbittorrent/rootfs/etc/openvpn/up-qbittorrent.sh @@ -5,5 +5,5 @@ set -e WEBUI_PORT=${WEBUI_PORT:-8080} exec \ - s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${WEBUI_PORT}" \ - s6-setuidgid abc /usr/bin/qbittorrent-nox --webui-port="${WEBUI_PORT}" + s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${WEBUI_PORT}" \ + s6-setuidgid abc /usr/bin/qbittorrent-nox --webui-port="${WEBUI_PORT}" diff --git a/qbittorrent/rootfs/etc/openvpn/up.sh b/qbittorrent/rootfs/etc/openvpn/up.sh index dc7c55394..829e26f05 100755 --- a/qbittorrent/rootfs/etc/openvpn/up.sh +++ b/qbittorrent/rootfs/etc/openvpn/up.sh @@ -25,44 +25,44 @@ # and try and let resolvconf handle it if [ "${PEER_DNS}" != "no" ]; then - NS= - DOMAIN= - SEARCH= - i=1 - while true ; do - eval opt=\$foreign_option_${i} - [ -z "${opt}" ] && break - if [ "${opt}" != "${opt#dhcp-option DOMAIN *}" ] ; then - if [ -z "${DOMAIN}" ] ; then - DOMAIN="${opt#dhcp-option DOMAIN *}" - else - SEARCH="${SEARCH}${SEARCH:+ }${opt#dhcp-option DOMAIN *}" - fi - elif [ "${opt}" != "${opt#dhcp-option DNS *}" ] ; then - NS="${NS}nameserver ${opt#dhcp-option DNS *}\n" - fi - i=$((${i} + 1)) - done + NS= + DOMAIN= + SEARCH= + i=1 + while true; do + eval opt=\$foreign_option_${i} + [ -z "${opt}" ] && break + if [ "${opt}" != "${opt#dhcp-option DOMAIN *}" ]; then + if [ -z "${DOMAIN}" ]; then + DOMAIN="${opt#dhcp-option DOMAIN *}" + else + SEARCH="${SEARCH}${SEARCH:+ }${opt#dhcp-option DOMAIN *}" + fi + elif [ "${opt}" != "${opt#dhcp-option DNS *}" ]; then + NS="${NS}nameserver ${opt#dhcp-option DNS *}\n" + fi + i=$((${i} + 1)) + done - if [ -n "${NS}" ] ; then - DNS="# Generated by openvpn for interface ${dev}\n" - if [ -n "${SEARCH}" ] ; then - DNS="${DNS}search ${DOMAIN} ${SEARCH}\n" - elif [ -n "${DOMAIN}" ]; then - DNS="${DNS}domain ${DOMAIN}\n" - fi - DNS="${DNS}${NS}" - if [ -x /sbin/resolvconf ] ; then - printf "${DNS}" | /sbin/resolvconf -a "${dev}" - else - # Preserve the existing resolv.conf - if [ -e /etc/resolv.conf ] ; then - cp /etc/resolv.conf /etc/resolv.conf-"${dev}".sv - fi - printf "${DNS}" > /etc/resolv.conf - chmod 644 /etc/resolv.conf - fi - fi + if [ -n "${NS}" ]; then + DNS="# Generated by openvpn for interface ${dev}\n" + if [ -n "${SEARCH}" ]; then + DNS="${DNS}search ${DOMAIN} ${SEARCH}\n" + elif [ -n "${DOMAIN}" ]; then + DNS="${DNS}domain ${DOMAIN}\n" + fi + DNS="${DNS}${NS}" + if [ -x /sbin/resolvconf ]; then + printf "${DNS}" | /sbin/resolvconf -a "${dev}" + else + # Preserve the existing resolv.conf + if [ -e /etc/resolv.conf ]; then + cp /etc/resolv.conf /etc/resolv.conf-"${dev}".sv + fi + printf "${DNS}" >/etc/resolv.conf + chmod 644 /etc/resolv.conf + fi + fi fi # Below section is Gentoo specific @@ -70,18 +70,18 @@ fi # as we could have >1 openvpn service if [ -n "${RC_SVCNAME}" ]; then - # If we have a service specific script, run this now - if [ -x /etc/openvpn/"${RC_SVCNAME}"-up.sh ] ; then - /etc/openvpn/"${RC_SVCNAME}"-up.sh "$@" - fi + # If we have a service specific script, run this now + if [ -x /etc/openvpn/"${RC_SVCNAME}"-up.sh ]; then + /etc/openvpn/"${RC_SVCNAME}"-up.sh "$@" + fi - # Re-enter the init script to start any dependant services - if ! /etc/init.d/"${RC_SVCNAME}" --quiet status ; then - export IN_BACKGROUND=true - if [ -d /var/run/s6/container_environment ]; then printf "%s" "true" > /var/run/s6/container_environment/IN_BACKGROUND; fi - printf "%s\n" "IN_BACKGROUND=\"true\"" >> ~/.bashrc - /etc/init.d/${RC_SVCNAME} --quiet start - fi + # Re-enter the init script to start any dependant services + if ! /etc/init.d/"${RC_SVCNAME}" --quiet status; then + export IN_BACKGROUND=true + if [ -d /var/run/s6/container_environment ]; then printf "%s" "true" >/var/run/s6/container_environment/IN_BACKGROUND; fi + printf "%s\n" "IN_BACKGROUND=\"true\"" >>~/.bashrc + /etc/init.d/${RC_SVCNAME} --quiet start + fi fi ############### diff --git a/radarr/rootfs/etc/cont-init.d/20-folders.sh b/radarr/rootfs/etc/cont-init.d/20-folders.sh index 9e5b03d57..19c19f35e 100755 --- a/radarr/rootfs/etc/cont-init.d/20-folders.sh +++ b/radarr/rootfs/etc/cont-init.d/20-folders.sh @@ -1,27 +1,27 @@ #!/bin/bash if [ ! -d /share/storage/movies ]; then - echo "Creating /share/storage/movies" - mkdir -p /share/storage/movies - chown -R "$PUID:$PGID" /share/storage/movies + echo "Creating /share/storage/movies" + mkdir -p /share/storage/movies + chown -R "$PUID:$PGID" /share/storage/movies fi if [ ! -d /share/downloads ]; then - echo "Creating /share/downloads" - mkdir -p /share/downloads - chown -R "$PUID:$PGID" /share/downloads + echo "Creating /share/downloads" + mkdir -p /share/downloads + chown -R "$PUID:$PGID" /share/downloads fi if [ -d /config/radarr ] && [ ! -d /config/addons_config/radarr ]; then - echo "Moving to new location /config/addons_config/radarr" - mkdir -p /config/addons_config/radarr - chown -R "$PUID:$PGID" /config/addons_config/radarr - mv /config/radarr/* /config/addons_config/radarr/ - rm -r /config/radarr + echo "Moving to new location /config/addons_config/radarr" + mkdir -p /config/addons_config/radarr + chown -R "$PUID:$PGID" /config/addons_config/radarr + mv /config/radarr/* /config/addons_config/radarr/ + rm -r /config/radarr fi if [ ! -d /config/addons_config/radarr ]; then - echo "Creating /config/addons_config/radarr" - mkdir -p /config/addons_config/radarr - chown -R "$PUID:$PGID" /config/addons_config/radarr + echo "Creating /config/addons_config/radarr" + mkdir -p /config/addons_config/radarr + chown -R "$PUID:$PGID" /config/addons_config/radarr fi diff --git a/radarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh b/radarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh index 32694f5f0..c9eaf4ed5 100755 --- a/radarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh +++ b/radarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh @@ -25,41 +25,41 @@ CONFIG_LOCATION=/config/addons_config/"$slug"/config.xml if [ -f "$CONFIG_LOCATION" ]; then - # Define addon mode - connection_mode="$(bashio::config "connection_mode")" - bashio::log.green "---------------------------" - bashio::log.green "Connection_mode is $connection_mode" - bashio::log.green "---------------------------" - case "$connection_mode" in - # Ingress mode, authentification is disabled - ingress_noauth) - bashio::log.green "Ingress is enabled, authentification is disabled" - bashio::log.yellow "WARNING : Make sure that the port is not exposed externally by your router to avoid a security risk !" - # Define UrlBase - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" - # Disable local auth - sed -i "/AuthenticationType/d" "$CONFIG_LOCATION" - sed -i "2a DisabledForLocalAddresses" "$CONFIG_LOCATION" - # Disable local auth - sed -i "/AuthenticationMethod/d" "$CONFIG_LOCATION" - sed -i "2a external" "$CONFIG_LOCATION" - ;; - # Ingress mode, with authentification - ingress_auth) - bashio::log.green "Ingress is enabled, and external authentification is enabled" - # Define UrlBase - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" - sed -i "/external/d" "$CONFIG_LOCATION" - ;; - # No ingress mode, with authentification - noingress_auth) - bashio::log.green "Disabling ingress and enabling authentification" - bashio::log.yellow "WARNING : Ingress is disabled so the app won't be available from HA itself !" - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "/external/d" "$CONFIG_LOCATION" - ;; - esac + # Define addon mode + connection_mode="$(bashio::config "connection_mode")" + bashio::log.green "---------------------------" + bashio::log.green "Connection_mode is $connection_mode" + bashio::log.green "---------------------------" + case "$connection_mode" in + # Ingress mode, authentification is disabled + ingress_noauth) + bashio::log.green "Ingress is enabled, authentification is disabled" + bashio::log.yellow "WARNING : Make sure that the port is not exposed externally by your router to avoid a security risk !" + # Define UrlBase + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" + # Disable local auth + sed -i "/AuthenticationType/d" "$CONFIG_LOCATION" + sed -i "2a DisabledForLocalAddresses" "$CONFIG_LOCATION" + # Disable local auth + sed -i "/AuthenticationMethod/d" "$CONFIG_LOCATION" + sed -i "2a external" "$CONFIG_LOCATION" + ;; + # Ingress mode, with authentification + ingress_auth) + bashio::log.green "Ingress is enabled, and external authentification is enabled" + # Define UrlBase + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" + sed -i "/external/d" "$CONFIG_LOCATION" + ;; + # No ingress mode, with authentification + noingress_auth) + bashio::log.green "Disabling ingress and enabling authentification" + bashio::log.yellow "WARNING : Ingress is disabled so the app won't be available from HA itself !" + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "/external/d" "$CONFIG_LOCATION" + ;; + esac fi diff --git a/readarr/rootfs/etc/cont-init.d/00-config_location.sh b/readarr/rootfs/etc/cont-init.d/00-config_location.sh index 2b7b6f018..2f2c61332 100755 --- a/readarr/rootfs/etc/cont-init.d/00-config_location.sh +++ b/readarr/rootfs/etc/cont-init.d/00-config_location.sh @@ -3,9 +3,9 @@ set -e if bashio::config.has_value 'CONFIG_LOCATION'; then - CONFIG_LOCATION="$(bashio::config 'CONFIG_LOCATION')" - # Modify if it is a base directory - if [[ "$CONFIG_LOCATION" == *.* ]]; then CONFIG_LOCATION="$(dirname "$CONFIG_LOCATION")"; fi + CONFIG_LOCATION="$(bashio::config 'CONFIG_LOCATION')" + # Modify if it is a base directory + if [[ "$CONFIG_LOCATION" == *.* ]]; then CONFIG_LOCATION="$(dirname "$CONFIG_LOCATION")"; fi fi CONFIG_LOCATION=$(bashio::config 'CONFIG_LOCATION') @@ -16,5 +16,5 @@ chown -R "$PUID:$PGID" "$CONFIG_LOCATION" # shellcheck disable=SC2013 for file in $(grep -sril "/config/addons_config/readarr" /etc /defaults); do - sed -i "s|/config/addons_config/readarr|$CONFIG_LOCATION|g" "$file" + sed -i "s|/config/addons_config/readarr|$CONFIG_LOCATION|g" "$file" done diff --git a/readarr/rootfs/etc/cont-init.d/20-folders.sh b/readarr/rootfs/etc/cont-init.d/20-folders.sh index 0128086fb..63f43fa91 100755 --- a/readarr/rootfs/etc/cont-init.d/20-folders.sh +++ b/readarr/rootfs/etc/cont-init.d/20-folders.sh @@ -1,32 +1,32 @@ #!/bin/bash if [ ! -d /share/storage/ebook ]; then - echo "Creating /share/storage/ebook" - mkdir -p /share/storage/ebook - chown -R "$PUID:$PGID" /share/storage/ebook + echo "Creating /share/storage/ebook" + mkdir -p /share/storage/ebook + chown -R "$PUID:$PGID" /share/storage/ebook fi if [ ! -d /share/downloads ]; then - echo "Creating /share/downloads" - mkdir -p /share/downloads - chown -R "$PUID:$PGID" /share/downloads + echo "Creating /share/downloads" + mkdir -p /share/downloads + chown -R "$PUID:$PGID" /share/downloads fi if [ -d /config/readarr ] && [ ! -d /config/addons_config/readarr ]; then - echo "Moving to new location /config/addons_config/readarr" - mkdir -p /config/addons_config/readarr - chown -R "$PUID:$PGID" /config/addons_config/readarr - mv /config/readarr/* /config/addons_config/readarr/ - rm -r /config/readarr + echo "Moving to new location /config/addons_config/readarr" + mkdir -p /config/addons_config/readarr + chown -R "$PUID:$PGID" /config/addons_config/readarr + mv /config/readarr/* /config/addons_config/readarr/ + rm -r /config/readarr fi if [ ! -d /config/addons_config/readarr ]; then - echo "Creating /config/addons_config/readarr" - mkdir -p /config/addons_config/readarr - chown -R "$PUID:$PGID" /config/addons_config/readarr + echo "Creating /config/addons_config/readarr" + mkdir -p /config/addons_config/readarr + chown -R "$PUID:$PGID" /config/addons_config/readarr fi if [ -d /config/addons_config/readarr/readarr ]; then - mv /config/addons_config/readarr/readarr/{.,}* /config/addons_config/readarr/ - rmdir /config/addons_config/readarr/readarr + mv /config/addons_config/readarr/readarr/{.,}* /config/addons_config/readarr/ + rmdir /config/addons_config/readarr/readarr fi diff --git a/readarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh b/readarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh index 0170cf788..1893efb9d 100755 --- a/readarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh +++ b/readarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh @@ -25,41 +25,41 @@ CONFIG_LOCATION=/config/addons_config/"$slug"/config.xml if [ -f "$CONFIG_LOCATION" ]; then - # Define addon mode - connection_mode="$(bashio::config "connection_mode")" - bashio::log.green "---------------------------" - bashio::log.green "Connection_mode is $connection_mode" - bashio::log.green "---------------------------" - case "$connection_mode" in - # Ingress mode, authentification is disabled - ingress_noauth) - bashio::log.green "Ingress is enabled, authentification is disabled" - bashio::log.yellow "WARNING : Make sure that the port is not exposed externally by your router to avoid a security risk !" - # Define UrlBase - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" - # Disable local auth - sed -i "/AuthenticationType/d" "$CONFIG_LOCATION" - sed -i "2a DisabledForLocalAddresses" "$CONFIG_LOCATION" - # Disable local auth - sed -i "/AuthenticationMethod/d" "$CONFIG_LOCATION" - sed -i "2a external" "$CONFIG_LOCATION" - ;; - # Ingress mode, with authentification - ingress_auth) - bashio::log.green "Ingress is enabled, and external authentification is enabled" - # Define UrlBase - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" - sed -i "/external/d" "$CONFIG_LOCATION" - ;; - # No ingress mode, with authentification - noingress_auth) - bashio::log.green "Disabling ingress and enabling authentification" - bashio::log.yellow "WARNING : Ingress is disabled so the app won't be available from HA itself !" - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "/external/d" "$CONFIG_LOCATION" - ;; - esac + # Define addon mode + connection_mode="$(bashio::config "connection_mode")" + bashio::log.green "---------------------------" + bashio::log.green "Connection_mode is $connection_mode" + bashio::log.green "---------------------------" + case "$connection_mode" in + # Ingress mode, authentification is disabled + ingress_noauth) + bashio::log.green "Ingress is enabled, authentification is disabled" + bashio::log.yellow "WARNING : Make sure that the port is not exposed externally by your router to avoid a security risk !" + # Define UrlBase + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" + # Disable local auth + sed -i "/AuthenticationType/d" "$CONFIG_LOCATION" + sed -i "2a DisabledForLocalAddresses" "$CONFIG_LOCATION" + # Disable local auth + sed -i "/AuthenticationMethod/d" "$CONFIG_LOCATION" + sed -i "2a external" "$CONFIG_LOCATION" + ;; + # Ingress mode, with authentification + ingress_auth) + bashio::log.green "Ingress is enabled, and external authentification is enabled" + # Define UrlBase + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" + sed -i "/external/d" "$CONFIG_LOCATION" + ;; + # No ingress mode, with authentification + noingress_auth) + bashio::log.green "Disabling ingress and enabling authentification" + bashio::log.yellow "WARNING : Ingress is disabled so the app won't be available from HA itself !" + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "/external/d" "$CONFIG_LOCATION" + ;; + esac fi diff --git a/resiliosync/rootfs/etc/cont-init.d/00-folders.sh b/resiliosync/rootfs/etc/cont-init.d/00-folders.sh index 592dc13f5..d54090c69 100755 --- a/resiliosync/rootfs/etc/cont-init.d/00-folders.sh +++ b/resiliosync/rootfs/etc/cont-init.d/00-folders.sh @@ -13,52 +13,52 @@ PGID=$(bashio::config "PGID") # Create function # ################### -change_folders () { - CONFIGLOCATION=$1 - ORIGINALLOCATION=$2 - TYPE=$3 +change_folders() { + CONFIGLOCATION=$1 + ORIGINALLOCATION=$2 + TYPE=$3 - # Inform - bashio::log.info "Setting $TYPE to $CONFIGLOCATION" + # Inform + bashio::log.info "Setting $TYPE to $CONFIGLOCATION" - if [ "$CONFIGLOCATION" != "$ORIGINALLOCATION" ]; then + if [ "$CONFIGLOCATION" != "$ORIGINALLOCATION" ]; then - # Modify files - echo "Adapting files" - # shellcheck disable=SC2013,SC2086 - for file in $(grep -ril "$ORIGINALLOCATION" /etc /defaults); do sed -i "s=$ORIGINALLOCATION=$CONFIGLOCATION=g" $file; done + # Modify files + echo "Adapting files" + # shellcheck disable=SC2013,SC2086 + for file in $(grep -ril "$ORIGINALLOCATION" /etc /defaults); do sed -i "s=$ORIGINALLOCATION=$CONFIGLOCATION=g" $file; done - # Adapt sync.conf - for FILE in "$ORIGINALLOCATION/sync.conf" "$CONFIGLOCATION/sync.conf" "/defaults/sync.conf"; do - if [ "$TYPE" = "config_location" ]; then - [ -f "$FILE" ] && jq --arg variable "$CONFIGLOCATION" '.storage_path = $variable' "$FILE" | sponge "$FILE" - fi - if [ "$TYPE" = "data_location" ]; then - [ -f "$FILE" ] && jq --arg variable "$CONFIGLOCATION" '.directory_root = $variable' "$FILE" | sponge "$FILE" - fi - if [ "$TYPE" = "downloads_location" ]; then - [ -f "$FILE" ] && jq --arg variable "$CONFIGLOCATION" '.files_default_path = $variable' "$FILE" | sponge "$FILE" - fi - done + # Adapt sync.conf + for FILE in "$ORIGINALLOCATION/sync.conf" "$CONFIGLOCATION/sync.conf" "/defaults/sync.conf"; do + if [ "$TYPE" = "config_location" ]; then + [ -f "$FILE" ] && jq --arg variable "$CONFIGLOCATION" '.storage_path = $variable' "$FILE" | sponge "$FILE" + fi + if [ "$TYPE" = "data_location" ]; then + [ -f "$FILE" ] && jq --arg variable "$CONFIGLOCATION" '.directory_root = $variable' "$FILE" | sponge "$FILE" + fi + if [ "$TYPE" = "downloads_location" ]; then + [ -f "$FILE" ] && jq --arg variable "$CONFIGLOCATION" '.files_default_path = $variable' "$FILE" | sponge "$FILE" + fi + done - # Transfer files - if [ -d "$ORIGINALLOCATION" ] && [ "$(ls -A "$ORIGINALLOCATION" 2>/dev/null)" ]; then - echo "Files were existing in $ORIGINALLOCATION, they will be moved to $CONFIGLOCATION" - mv "$ORIGINALLOCATION"/* "$CONFIGLOCATION"/ - rmdir "$ORIGINALLOCATION" - fi 2>/dev/null || true - fi + # Transfer files + if [ -d "$ORIGINALLOCATION" ] && [ "$(ls -A "$ORIGINALLOCATION" 2>/dev/null)" ]; then + echo "Files were existing in $ORIGINALLOCATION, they will be moved to $CONFIGLOCATION" + mv "$ORIGINALLOCATION"/* "$CONFIGLOCATION"/ + rmdir "$ORIGINALLOCATION" + fi 2>/dev/null || true + fi - # Create folders - echo "Checking if folders exist" - for FOLDER in "$CONFIGLOCATION" "$CONFIGLOCATION"/folders "$CONFIGLOCATION"/mounted_folders "$CONFIGLOCATION"/downloads; do - [ ! -d "$FOLDER" ] && echo "Creating $FOLDER" && mkdir -p "$FOLDER" - done + # Create folders + echo "Checking if folders exist" + for FOLDER in "$CONFIGLOCATION" "$CONFIGLOCATION"/folders "$CONFIGLOCATION"/mounted_folders "$CONFIGLOCATION"/downloads; do + [ ! -d "$FOLDER" ] && echo "Creating $FOLDER" && mkdir -p "$FOLDER" + done - # Set permissions - echo "Setting ownership to $PUID:$PGID" - chown -R "$PUID":"$PGID" "$CONFIGLOCATION" - chmod -R 777 "$CONFIGLOCATION" + # Set permissions + echo "Setting ownership to $PUID:$PGID" + chown -R "$PUID":"$PGID" "$CONFIGLOCATION" + chmod -R 777 "$CONFIGLOCATION" } @@ -72,5 +72,5 @@ change_folders "$(bashio::config 'data_location')" "/share/resiliosync" "data_lo change_folders "$(bashio::config 'downloads_location')" "/share/resiliosync_downloads" "downloads_location" if [[ ! -e "$(bashio::config 'config_location')"/sync.conf ]]; then - cp /defaults/sync.conf "$(bashio::config 'config_location')"/sync.conf + cp /defaults/sync.conf "$(bashio::config 'config_location')"/sync.conf fi diff --git a/sabnzbd/rootfs/etc/cont-init.d/20-folders.sh b/sabnzbd/rootfs/etc/cont-init.d/20-folders.sh index dc407754d..0c5e5a04b 100755 --- a/sabnzbd/rootfs/etc/cont-init.d/20-folders.sh +++ b/sabnzbd/rootfs/etc/cont-init.d/20-folders.sh @@ -5,14 +5,14 @@ set -e slug=sabnzbd if [ -d "/homeassistant/addons_config/$slug" ]; then - echo "Migrating /homeassistant/addons_config/$slug to /addon_configs/xxx-$slug" - cp -rnf /homeassistant/addons_config/"$slug"/* /config/ - mv /homeassistant/addons_config/"$slug" /homeassistant/addons_config/"$slug"_migrated + echo "Migrating /homeassistant/addons_config/$slug to /addon_configs/xxx-$slug" + cp -rnf /homeassistant/addons_config/"$slug"/* /config/ + mv /homeassistant/addons_config/"$slug" /homeassistant/addons_config/"$slug"_migrated fi if [ -f "/homeassistant/addons_autoscripts/$slug.sh" ]; then - bashio::log.warning "Migrating autoscript" - mv /homeassistant/addons_autoscripts/$slug.sh /config/ + bashio::log.warning "Migrating autoscript" + mv /homeassistant/addons_autoscripts/$slug.sh /config/ fi chmod 777 /config/* diff --git a/scrutiny/rootfs/etc/cont-init.d/01-configuration.sh b/scrutiny/rootfs/etc/cont-init.d/01-configuration.sh index 2e7e7380a..0526785f2 100755 --- a/scrutiny/rootfs/etc/cont-init.d/01-configuration.sh +++ b/scrutiny/rootfs/etc/cont-init.d/01-configuration.sh @@ -20,9 +20,9 @@ ln -s "$DATABASELOCATION"/influxdb /opt/scrutiny ############################### if [ -f /data/scrutiny.db ]; then - bashio::log.warning "Previous database detected, migration will start. Backup stored in /share/scrutiny.db.bak" - cp /data/scrutiny.db /share/scrutiny.db.bak - mv /data/scrutiny.db "$DATABASELOCATION"/config/ + bashio::log.warning "Previous database detected, migration will start. Backup stored in /share/scrutiny.db.bak" + cp /data/scrutiny.db /share/scrutiny.db.bak + mv /data/scrutiny.db "$DATABASELOCATION"/config/ fi ###### @@ -31,9 +31,9 @@ fi # Align timezone with options if bashio::config.has_value "TZ"; then - TZ="$(bashio::config 'TZ')" - bashio::log.info "Timezone : $TZ" - sed -i "1a export TZ=$TZ" /etc/cont-init.d/01-timezone + TZ="$(bashio::config 'TZ')" + bashio::log.info "Timezone : $TZ" + sed -i "1a export TZ=$TZ" /etc/cont-init.d/01-timezone fi ################ @@ -45,71 +45,71 @@ FREQUENCY="$(bashio::config 'Updates')" bashio::log.info "$FREQUENCY updates as defined in the 'Updates' option" case "$FREQUENCY" in - "Quarterly") - sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"*/15 * * * *\"" /etc/cont-init.d/50-cron-config - ;; +"Quarterly") + sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"*/15 * * * *\"" /etc/cont-init.d/50-cron-config + ;; - "Hourly") - sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 * * * *\"" /etc/cont-init.d/50-cron-config - ;; +"Hourly") + sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 * * * *\"" /etc/cont-init.d/50-cron-config + ;; - "Daily") - sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * *\"" /etc/cont-init.d/50-cron-config - ;; +"Daily") + sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * *\"" /etc/cont-init.d/50-cron-config + ;; - "Weekly") - sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * 0\"" /etc/cont-init.d/50-cron-config - ;; +"Weekly") + sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * 0\"" /etc/cont-init.d/50-cron-config + ;; - "Custom") - interval="$(bashio::config 'Updates_custom_time')" - bashio::log.info "... frequency is defined manually as $interval" +"Custom") + interval="$(bashio::config 'Updates_custom_time')" + bashio::log.info "... frequency is defined manually as $interval" - case "$interval" in - *m) # Matches intervals in minutes, like "5m" or "30m" - minutes="${interval%m}" - if [[ "$minutes" -gt 0 && "$minutes" -le 59 ]]; then - cron_schedule="*/$minutes * * * *" - else - bashio::log.error "Invalid minute interval: $interval" - fi - ;; + case "$interval" in + *m) # Matches intervals in minutes, like "5m" or "30m" + minutes="${interval%m}" + if [[ "$minutes" -gt 0 && "$minutes" -le 59 ]]; then + cron_schedule="*/$minutes * * * *" + else + bashio::log.error "Invalid minute interval: $interval" + fi + ;; - *h) # Matches intervals in hours, like "2h" - hours="${interval%h}" - if [[ "$hours" -gt 0 && "$hours" -le 23 ]]; then - cron_schedule="0 */$hours * * *" - else - bashio::log.error "Invalid hour interval: $interval" - fi - ;; + *h) # Matches intervals in hours, like "2h" + hours="${interval%h}" + if [[ "$hours" -gt 0 && "$hours" -le 23 ]]; then + cron_schedule="0 */$hours * * *" + else + bashio::log.error "Invalid hour interval: $interval" + fi + ;; - *w) # Matches intervals in weeks, like "1w" - weeks="${interval%w}" - if [[ "$weeks" -gt 0 && "$weeks" -le 4 ]]; then - cron_schedule="0 0 * * 0" # Weekly on Sunday (adjust if needed for multi-week) - else - bashio::log.error "Invalid week interval: $interval" - fi - ;; + *w) # Matches intervals in weeks, like "1w" + weeks="${interval%w}" + if [[ "$weeks" -gt 0 && "$weeks" -le 4 ]]; then + cron_schedule="0 0 * * 0" # Weekly on Sunday (adjust if needed for multi-week) + else + bashio::log.error "Invalid week interval: $interval" + fi + ;; - *mo) # Matches intervals in months, like "1mo" - months="${interval%mo}" - if [[ "$months" -gt 0 && "$months" -le 12 ]]; then - cron_schedule="0 0 1 */$months *" # Monthly on the 1st - else - bashio::log.error "Invalid month interval: $interval" - fi - ;; + *mo) # Matches intervals in months, like "1mo" + months="${interval%mo}" + if [[ "$months" -gt 0 && "$months" -le 12 ]]; then + cron_schedule="0 0 1 */$months *" # Monthly on the 1st + else + bashio::log.error "Invalid month interval: $interval" + fi + ;; - *) - bashio::log.error "Empty or unsupported custom interval. It should be in the format of 5m (every 5 minutes), 10d (every 10 days), 3w (every 3 weeks), 3mo (every 3 months)" - ;; - esac + *) + bashio::log.error "Empty or unsupported custom interval. It should be in the format of 5m (every 5 minutes), 10d (every 10 days), 3w (every 3 weeks), 3mo (every 3 months)" + ;; + esac - if [[ -n "$cron_schedule" ]]; then - sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"$cron_schedule\"" /etc/cont-init.d/50-cron-config - bashio::log.info "Custom cron schedule set to: $cron_schedule" - fi - ;; + if [[ -n "$cron_schedule" ]]; then + sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"$cron_schedule\"" /etc/cont-init.d/50-cron-config + bashio::log.info "Custom cron schedule set to: $cron_schedule" + fi + ;; esac diff --git a/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh b/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh index 3b8d0806b..77585d14d 100755 --- a/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh +++ b/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh @@ -13,19 +13,19 @@ declare keyfile port=$(bashio::addon.port 80) if bashio::var.has_value "${port}"; then - bashio::config.require.ssl + bashio::config.require.ssl - if bashio::config.true 'ssl'; then - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') + if bashio::config.true 'ssl'; then + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') - mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf - sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf - sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf + mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf + sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf + sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf - else - mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf - fi + else + mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf + fi fi ingress_port=$(bashio::addon.ingress_port) diff --git a/scrutiny/rootfs/etc/cont-init.d/90-run.sh b/scrutiny/rootfs/etc/cont-init.d/90-run.sh index d6116eb2b..0ecdd0ace 100755 --- a/scrutiny/rootfs/etc/cont-init.d/90-run.sh +++ b/scrutiny/rootfs/etc/cont-init.d/90-run.sh @@ -7,21 +7,21 @@ set -e ######################### if bashio::config.true "expose_collector"; then - bashio::log.info "collector.yaml exposed in /share/scrutiny" - mkdir -p /share/scrutiny - if [ -f /data/config/collector.yaml ] ; then - cp -rnf /data/config/collector.yaml /share/scrutiny || true - rm -R /data/config/collector.yaml - fi - if [ -f /opt/scrutiny/config/collector.yaml ] ; then - cp -rnf /opt/scrutiny/config/collector.yaml /share/scrutiny || true - rm /opt/scrutiny/config/collector.yaml - fi - touch /share/scrutiny/collector.yaml - ln -sf /share/scrutiny/collector.yaml /data/config || true - mkdir -p /opt/scrutiny/config - ln -sf /share/scrutiny/collector.yaml /opt/scrutiny/config/collector.yaml || true - chmod 777 -R /share/scrutiny + bashio::log.info "collector.yaml exposed in /share/scrutiny" + mkdir -p /share/scrutiny + if [ -f /data/config/collector.yaml ]; then + cp -rnf /data/config/collector.yaml /share/scrutiny || true + rm -R /data/config/collector.yaml + fi + if [ -f /opt/scrutiny/config/collector.yaml ]; then + cp -rnf /opt/scrutiny/config/collector.yaml /share/scrutiny || true + rm /opt/scrutiny/config/collector.yaml + fi + touch /share/scrutiny/collector.yaml + ln -sf /share/scrutiny/collector.yaml /data/config || true + mkdir -p /opt/scrutiny/config + ln -sf /share/scrutiny/collector.yaml /opt/scrutiny/config/collector.yaml || true + chmod 777 -R /share/scrutiny fi ######## @@ -29,22 +29,22 @@ fi ######## if [[ "$(bashio::config "Mode")" == Collector ]]; then - # Clean services - bashio::log.warning "Collector only mode. WebUI and Influxdb will be disabled" - rm -r /etc/services.d/influxdb - rm -r /etc/services.d/scrutiny - rm -r /etc/services.d/nginx - sed -i "/wait/d" /etc/services.d/collector-once/run - sed -i "/scrutiny api not ready/d" /etc/services.d/collector-once/run + # Clean services + bashio::log.warning "Collector only mode. WebUI and Influxdb will be disabled" + rm -r /etc/services.d/influxdb + rm -r /etc/services.d/scrutiny + rm -r /etc/services.d/nginx + sed -i "/wait/d" /etc/services.d/collector-once/run + sed -i "/scrutiny api not ready/d" /etc/services.d/collector-once/run - # Check collector - if bashio::config.has_value "COLLECTOR_API_ENDPOINT"; then - echo "export COLLECTOR_API_ENDPOINT=$(bashio::config "COLLECTOR_API_ENDPOINT")" >> /env.sh - sed -i "1a export COLLECTOR_API_ENDPOINT=$(bashio::config "COLLECTOR_API_ENDPOINT")" /etc/services.d/collector-once/run - if [ -d /var/run/s6/container_environment ]; then printf "%s" "$COLLECTOR_API_ENDPOINT" > /var/run/s6/container_environment/COLLECTOR_API_ENDPOINT; fi - printf "%s\n" "IN_BACKGROUND=\"$COLLECTOR_API_ENDPOINT\"" >> ~/.bashrc - bashio::log.info "Using 'COLLECTOR_API_ENDPOINT' $(bashio::config "COLLECTOR_API_ENDPOINT")" - else - bashio::exit.nok "Mode is set to 'Collector', but 'COLLECTOR_API_ENDPOINT' is not defined" - fi + # Check collector + if bashio::config.has_value "COLLECTOR_API_ENDPOINT"; then + echo "export COLLECTOR_API_ENDPOINT=$(bashio::config "COLLECTOR_API_ENDPOINT")" >>/env.sh + sed -i "1a export COLLECTOR_API_ENDPOINT=$(bashio::config "COLLECTOR_API_ENDPOINT")" /etc/services.d/collector-once/run + if [ -d /var/run/s6/container_environment ]; then printf "%s" "$COLLECTOR_API_ENDPOINT" >/var/run/s6/container_environment/COLLECTOR_API_ENDPOINT; fi + printf "%s\n" "IN_BACKGROUND=\"$COLLECTOR_API_ENDPOINT\"" >>~/.bashrc + bashio::log.info "Using 'COLLECTOR_API_ENDPOINT' $(bashio::config "COLLECTOR_API_ENDPOINT")" + else + bashio::exit.nok "Mode is set to 'Collector', but 'COLLECTOR_API_ENDPOINT' is not defined" + fi fi diff --git a/seafile/rootfs/etc/cont-init.d/99-run.sh b/seafile/rootfs/etc/cont-init.d/99-run.sh index d8c8a1d2d..8c733f897 100755 --- a/seafile/rootfs/etc/cont-init.d/99-run.sh +++ b/seafile/rootfs/etc/cont-init.d/99-run.sh @@ -17,20 +17,20 @@ JSONSOURCE="/data/options.json" mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") for KEYS in "${arr[@]}"; do - # export key - VALUE=$(jq ."$KEYS" "${JSONSOURCE}") - line="${KEYS}='${VALUE//[\"\']/}'" - # text - if bashio::config.false "verbose" || [[ "${KEYS}" == *"PASS"* ]]; then - bashio::log.blue "${KEYS}=******" - else - bashio::log.blue "$line" - fi - # Use locally - export "${KEYS}=${VALUE//[\"\']/}" - # Export the variable to run scripts - sed -i "1a export $line" /home/seafile/*.sh 2>/dev/null - find /opt/seafile -name '*.sh' -print0 | xargs -0 sed -i "1a export $line" + # export key + VALUE=$(jq ."$KEYS" "${JSONSOURCE}") + line="${KEYS}='${VALUE//[\"\']/}'" + # text + if bashio::config.false "verbose" || [[ "${KEYS}" == *"PASS"* ]]; then + bashio::log.blue "${KEYS}=******" + else + bashio::log.blue "$line" + fi + # Use locally + export "${KEYS}=${VALUE//[\"\']/}" + # Export the variable to run scripts + sed -i "1a export $line" /home/seafile/*.sh 2>/dev/null + find /opt/seafile -name '*.sh' -print0 | xargs -0 sed -i "1a export $line" done ################# @@ -73,43 +73,43 @@ bashio::log.info "Defining database" case $(bashio::config 'database') in - # Use sqlite - sqlite) - export "SQLITE=1" && sed -i "1a export SQLITE=1" /home/seafile/*.sh - ;; +# Use sqlite +sqlite) + export "SQLITE=1" && sed -i "1a export SQLITE=1" /home/seafile/*.sh + ;; - # Use mariadb - mariadb_addon) - bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." - if ! bashio::services.available 'mysql'; then - bashio::log.fatal \ - "Local database access should be provided by the MariaDB addon" - bashio::exit.nok \ - "Please ensure it is installed and started" - fi + # Use mariadb +mariadb_addon) + bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." + if ! bashio::services.available 'mysql'; then + bashio::log.fatal \ + "Local database access should be provided by the MariaDB addon" + bashio::exit.nok \ + "Please ensure it is installed and started" + fi - # Use values - export MYSQL_HOST="$(bashio::services 'mysql' 'host')" && sed -i "1a export MYSQL_HOST=$(bashio::services 'mysql' 'host')" /home/seafile/*.sh - export MYSQL_PORT="$(bashio::services 'mysql' 'port')" && sed -i "1a export MYSQL_PORT=$(bashio::services 'mysql' 'port')" /home/seafile/*.sh - export MYSQL_USER="$(bashio::services "mysql" "username")" && sed -i "1a export MYSQL_USER=$(bashio::services 'mysql' 'username')" /home/seafile/*.sh - export MYSQL_USER_PASSWD="$(bashio::services "mysql" "password")" && sed -i "1a export MYSQL_USER_PASSWD=$(bashio::services 'mysql' 'password')" /home/seafile/*.sh - export MYSQL_ROOT_PASSWD="$(bashio::services "mysql" "password")" && sed -i "1a export MYSQL_ROOT_PASSWD=$(bashio::services 'mysql' 'password')" /home/seafile/*.sh + # Use values + export MYSQL_HOST="$(bashio::services 'mysql' 'host')" && sed -i "1a export MYSQL_HOST=$(bashio::services 'mysql' 'host')" /home/seafile/*.sh + export MYSQL_PORT="$(bashio::services 'mysql' 'port')" && sed -i "1a export MYSQL_PORT=$(bashio::services 'mysql' 'port')" /home/seafile/*.sh + export MYSQL_USER="$(bashio::services "mysql" "username")" && sed -i "1a export MYSQL_USER=$(bashio::services 'mysql' 'username')" /home/seafile/*.sh + export MYSQL_USER_PASSWD="$(bashio::services "mysql" "password")" && sed -i "1a export MYSQL_USER_PASSWD=$(bashio::services 'mysql' 'password')" /home/seafile/*.sh + export MYSQL_ROOT_PASSWD="$(bashio::services "mysql" "password")" && sed -i "1a export MYSQL_ROOT_PASSWD=$(bashio::services 'mysql' 'password')" /home/seafile/*.sh - # Mariadb requires a user - echo "Adapting scripts" - sed -i 's|port=${MYSQL_PORT})|port=${MYSQL_PORT}, user="${MYSQL_USER}")|g' /home/seafile/wait_for_db.sh + # Mariadb requires a user + echo "Adapting scripts" + sed -i 's|port=${MYSQL_PORT})|port=${MYSQL_PORT}, user="${MYSQL_USER}")|g' /home/seafile/wait_for_db.sh - # Mariadb has no root user - echo "Adapting root name" - sed -i 's|user="root"|user="service"|g' /home/seafile/clean_db.sh - sed -i "s|'root'|'service'|g" /opt/seafile/*/setup-seafile-mysql.sh - sed -i "s|'root'|'service'|g" /opt/seafile/*/setup-seafile-mysql.py + # Mariadb has no root user + echo "Adapting root name" + sed -i 's|user="root"|user="service"|g' /home/seafile/clean_db.sh + sed -i "s|'root'|'service'|g" /opt/seafile/*/setup-seafile-mysql.sh + sed -i "s|'root'|'service'|g" /opt/seafile/*/setup-seafile-mysql.py - # Informations - bashio::log.warning "This addon is using the Maria DB addon" - bashio::log.warning "Please ensure this is included in your backups" - bashio::log.warning "Uninstalling the MariaDB addon will remove any data" - ;; + # Informations + bashio::log.warning "This addon is using the Maria DB addon" + bashio::log.warning "Please ensure this is included in your backups" + bashio::log.warning "Uninstalling the MariaDB addon will remove any data" + ;; esac ############## diff --git a/signalk/rootfs/etc/cont-init.d/99-run.sh b/signalk/rootfs/etc/cont-init.d/99-run.sh index e0bdfaef4..b3622b269 100755 --- a/signalk/rootfs/etc/cont-init.d/99-run.sh +++ b/signalk/rootfs/etc/cont-init.d/99-run.sh @@ -5,7 +5,7 @@ set -e # Set configuration directory if [ -d "/home/node/.signalk" ]; then - rm -r "/home/node/.signalk" + rm -r "/home/node/.signalk" fi # Variables @@ -22,9 +22,9 @@ groupmod -o -g 0 node # Ensure 600 for SSL files echo "... specifying security files permissions" for file in ssl-key.pem ssl-cert.pem security.json; do - if [ -e "/config/$file" ]; then - chmod 600 "/config/$file" - fi + if [ -e "/config/$file" ]; then + chmod 600 "/config/$file" + fi done bashio::log.info "Starting application" diff --git a/sonarr/rootfs/etc/cont-init.d/20-folders.sh b/sonarr/rootfs/etc/cont-init.d/20-folders.sh index a97820bf2..dbff725ac 100755 --- a/sonarr/rootfs/etc/cont-init.d/20-folders.sh +++ b/sonarr/rootfs/etc/cont-init.d/20-folders.sh @@ -1,27 +1,27 @@ #!/bin/bash if [ ! -d /share/storage/tv ]; then - echo "Creating /share/storage/tv" - mkdir -p /share/storage/tv - chown -R "$PUID:$PGID" /share/storage/tv + echo "Creating /share/storage/tv" + mkdir -p /share/storage/tv + chown -R "$PUID:$PGID" /share/storage/tv fi if [ ! -d /share/downloads ]; then - echo "Creating /share/downloads" - mkdir -p /share/downloads - chown -R "$PUID:$PGID" /share/downloads + echo "Creating /share/downloads" + mkdir -p /share/downloads + chown -R "$PUID:$PGID" /share/downloads fi if [ -d /config/sonarr ] && [ ! -d /config/addons_config/sonarr ]; then - echo "Moving to new location /config/addons_config/sonarr" - mkdir -p /config/addons_config/sonarr - chown -R "$PUID:$PGID" /config/addons_config/sonarr - mv /config/sonarr/* /config/addons_config/sonarr/ - rm -r /config/sonarr + echo "Moving to new location /config/addons_config/sonarr" + mkdir -p /config/addons_config/sonarr + chown -R "$PUID:$PGID" /config/addons_config/sonarr + mv /config/sonarr/* /config/addons_config/sonarr/ + rm -r /config/sonarr fi if [ ! -d /config/addons_config/sonarr ]; then - echo "Creating /config/addons_config/sonarr" - mkdir -p /config/addons_config/sonarr - chown -R "$PUID:$PGID" /config/addons_config/sonarr + echo "Creating /config/addons_config/sonarr" + mkdir -p /config/addons_config/sonarr + chown -R "$PUID:$PGID" /config/addons_config/sonarr fi diff --git a/sonarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh b/sonarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh index 0dee0e709..37fd29fef 100755 --- a/sonarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh +++ b/sonarr/rootfs/etc/cont-init.d/32-nginx_ingress.sh @@ -25,41 +25,41 @@ CONFIG_LOCATION=/config/addons_config/"$slug"/config.xml if [ -f "$CONFIG_LOCATION" ]; then - # Define addon mode - connection_mode="$(bashio::config "connection_mode")" - bashio::log.green "---------------------------" - bashio::log.green "Connection_mode is $connection_mode" - bashio::log.green "---------------------------" - case "$connection_mode" in - # Ingress mode, authentification is disabled - ingress_noauth) - bashio::log.green "Ingress is enabled, authentification is disabled" - bashio::log.yellow "WARNING : Make sure that the port is not exposed externally by your router to avoid a security risk !" - # Define UrlBase - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" - # Disable local auth - sed -i "/AuthenticationType/d" "$CONFIG_LOCATION" - sed -i "2a DisabledForLocalAddresses" "$CONFIG_LOCATION" - # Disable local auth - sed -i "/AuthenticationMethod/d" "$CONFIG_LOCATION" - sed -i "2a external" "$CONFIG_LOCATION" - ;; - # Ingress mode, with authentification - ingress_auth) - bashio::log.green "Ingress is enabled, and external authentification is enabled" - # Define UrlBase - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" - sed -i "/external/d" "$CONFIG_LOCATION" - ;; - # No ingress mode, with authentification - noingress_auth) - bashio::log.green "Disabling ingress and enabling authentification" - bashio::log.yellow "WARNING : Ingress is disabled so the app won't be available from HA itself !" - sed -i "/UrlBase/d" "$CONFIG_LOCATION" - sed -i "/external/d" "$CONFIG_LOCATION" - ;; - esac + # Define addon mode + connection_mode="$(bashio::config "connection_mode")" + bashio::log.green "---------------------------" + bashio::log.green "Connection_mode is $connection_mode" + bashio::log.green "---------------------------" + case "$connection_mode" in + # Ingress mode, authentification is disabled + ingress_noauth) + bashio::log.green "Ingress is enabled, authentification is disabled" + bashio::log.yellow "WARNING : Make sure that the port is not exposed externally by your router to avoid a security risk !" + # Define UrlBase + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" + # Disable local auth + sed -i "/AuthenticationType/d" "$CONFIG_LOCATION" + sed -i "2a DisabledForLocalAddresses" "$CONFIG_LOCATION" + # Disable local auth + sed -i "/AuthenticationMethod/d" "$CONFIG_LOCATION" + sed -i "2a external" "$CONFIG_LOCATION" + ;; + # Ingress mode, with authentification + ingress_auth) + bashio::log.green "Ingress is enabled, and external authentification is enabled" + # Define UrlBase + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "2a $slug<\/UrlBase>" "$CONFIG_LOCATION" + sed -i "/external/d" "$CONFIG_LOCATION" + ;; + # No ingress mode, with authentification + noingress_auth) + bashio::log.green "Disabling ingress and enabling authentification" + bashio::log.yellow "WARNING : Ingress is disabled so the app won't be available from HA itself !" + sed -i "/UrlBase/d" "$CONFIG_LOCATION" + sed -i "/external/d" "$CONFIG_LOCATION" + ;; + esac fi diff --git a/sponsorblockcast/rootfs/etc/cont-init.d/99-run.sh b/sponsorblockcast/rootfs/etc/cont-init.d/99-run.sh index e116f6d5d..bcc334e3d 100755 --- a/sponsorblockcast/rootfs/etc/cont-init.d/99-run.sh +++ b/sponsorblockcast/rootfs/etc/cont-init.d/99-run.sh @@ -8,9 +8,9 @@ mkdir -p /tmp/castsponsorskip # Export options as env variables for var in CSS_CATEGORIES CSS_DISCOVER_INTERVAL CSS_PAUSED_INTERVAL CSS_PLAYING_INTERVAL CSS_YOUTUBE_API_KEY CSS_MUTE_ADS; do - if bashio::config.has_value "$var"; then - export "$var"="$(bashio::config "$var")" - fi + if bashio::config.has_value "$var"; then + export "$var"="$(bashio::config "$var")" + fi done # Starting app diff --git a/tandoor_recipes/rootfs/etc/cont-init.d/20-folders.sh b/tandoor_recipes/rootfs/etc/cont-init.d/20-folders.sh index b54992575..b91684a3c 100755 --- a/tandoor_recipes/rootfs/etc/cont-init.d/20-folders.sh +++ b/tandoor_recipes/rootfs/etc/cont-init.d/20-folders.sh @@ -5,7 +5,7 @@ set -e slug="tandoor_recipes" if [ ! -d /config/addons_config/$slug ]; then - echo "Creating /config/addons_config/$slug" - mkdir -p /config/addons_config/$slug + echo "Creating /config/addons_config/$slug" + mkdir -p /config/addons_config/$slug fi chmod -R 755 /config/addons_config/$slug diff --git a/tandoor_recipes/rootfs/etc/cont-init.d/99-run.sh b/tandoor_recipes/rootfs/etc/cont-init.d/99-run.sh index d3e0bfc1a..6e39d601b 100755 --- a/tandoor_recipes/rootfs/etc/cont-init.d/99-run.sh +++ b/tandoor_recipes/rootfs/etc/cont-init.d/99-run.sh @@ -13,9 +13,9 @@ export DEBUG=$(bashio::config 'DEBUG') && bashio::log.blue "DEBUG=$DEBUG" CSRF_TRUSTED_ORIGINS="http://localhost" for element in ${ALLOWED_HOSTS//,/ }; do # Separate comma separated values - element="${element#"https://"}" - element="${element#"http://"}" - CSRF_TRUSTED_ORIGINS="http://$element,https://$element,$CSRF_TRUSTED_ORIGINS" + element="${element#"https://"}" + element="${element#"http://"}" + CSRF_TRUSTED_ORIGINS="http://$element,https://$element,$CSRF_TRUSTED_ORIGINS" done export CSRF_TRUSTED_ORIGINS export ALLOWED_HOSTS="*" @@ -34,66 +34,66 @@ bashio::log.info "Defining database" export DB_TYPE=$(bashio::config 'DB_TYPE') case $(bashio::config 'DB_TYPE') in - # Use sqlite - sqlite) - bashio::log.info "Using a local sqlite database" - export DB_ENGINE="django.db.backends.sqlite3" - export POSTGRES_DB="/config/addons_config/tandoor_recipes/recipes.db" - ;; +# Use sqlite +sqlite) + bashio::log.info "Using a local sqlite database" + export DB_ENGINE="django.db.backends.sqlite3" + export POSTGRES_DB="/config/addons_config/tandoor_recipes/recipes.db" + ;; - # tandoor recipes doesnt support mariadb. - # mariadb_addon) - # bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." - # if ! bashio::services.available 'mysql'; then - # bashio::log.fatal \ - # "Local database access should be provided by the MariaDB addon" - # bashio::exit.nok \ - # "Please ensure it is installed and started" - # fi + # tandoor recipes doesnt support mariadb. + # mariadb_addon) + # bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." + # if ! bashio::services.available 'mysql'; then + # bashio::log.fatal \ + # "Local database access should be provided by the MariaDB addon" + # bashio::exit.nok \ + # "Please ensure it is installed and started" + # fi - # Install apps - # apk add --no-cache postgresql-libs gettext zlib libjpeg libxml2-dev libxslt-dev mysql-client mariadb-connector-c-dev mariadb-dev >/dev/null + # Install apps + # apk add --no-cache postgresql-libs gettext zlib libjpeg libxml2-dev libxslt-dev mysql-client mariadb-connector-c-dev mariadb-dev >/dev/null - # Install mysqlclient - # pip install pymysql &>/dev/null + # Install mysqlclient + # pip install pymysql &>/dev/null - # export DB_ENGINE=django.db.backends.mysql - # export POSTGRES_HOST=$(bashio::services "mysql" "host") && bashio::log.blue "POSTGRES_HOST=$POSTGRES_HOST" - # export POSTGRES_PORT=$(bashio::services "mysql" "port") && bashio::log.blue "POSTGRES_PORT=$POSTGRES_PORT" - # export POSTGRES_USER=$(bashio::services "mysql" "username") && bashio::log.blue "POSTGRES_USER=$POSTGRES_USER" - # export POSTGRES_PASSWORD=$(bashio::services "mysql" "password") && bashio::log.blue "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" - # export POSTGRES_DB="tandoor" && bashio::log.blue "POSTGRES_DB=tandoor" + # export DB_ENGINE=django.db.backends.mysql + # export POSTGRES_HOST=$(bashio::services "mysql" "host") && bashio::log.blue "POSTGRES_HOST=$POSTGRES_HOST" + # export POSTGRES_PORT=$(bashio::services "mysql" "port") && bashio::log.blue "POSTGRES_PORT=$POSTGRES_PORT" + # export POSTGRES_USER=$(bashio::services "mysql" "username") && bashio::log.blue "POSTGRES_USER=$POSTGRES_USER" + # export POSTGRES_PASSWORD=$(bashio::services "mysql" "password") && bashio::log.blue "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" + # export POSTGRES_DB="tandoor" && bashio::log.blue "POSTGRES_DB=tandoor" - # Use values - # sed -i "1a export DB_ENGINE=django.db.backends.mysql" /opt/recipes/boot.sh - # sed -i "1a export POSTGRES_HOST=$(bashio::services "mysql" "host")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_HOST=$POSTGRES_HOST" - # sed -i "1a export POSTGRES_PORT=$(bashio::services "mysql" "port")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_PORT=$POSTGRES_PORT" - # sed -i "1a export POSTGRES_USER=$(bashio::services "mysql" "username")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_USER=$POSTGRES_USER" - # sed -i "1a export POSTGRES_PASSWORD=$(bashio::services "mysql" "password")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" - # sed -i "1a export POSTGRES_DB=tandoor" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_DB=tandoor" + # Use values + # sed -i "1a export DB_ENGINE=django.db.backends.mysql" /opt/recipes/boot.sh + # sed -i "1a export POSTGRES_HOST=$(bashio::services "mysql" "host")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_HOST=$POSTGRES_HOST" + # sed -i "1a export POSTGRES_PORT=$(bashio::services "mysql" "port")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_PORT=$POSTGRES_PORT" + # sed -i "1a export POSTGRES_USER=$(bashio::services "mysql" "username")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_USER=$POSTGRES_USER" + # sed -i "1a export POSTGRES_PASSWORD=$(bashio::services "mysql" "password")" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" + # sed -i "1a export POSTGRES_DB=tandoor" /opt/recipes/boot.sh && bashio::log.blue "POSTGRES_DB=tandoor" - # bashio::log.warning "This addon is using the Maria DB addon" - # bashio::log.warning "Please ensure this is included in your backups" - # bashio::log.warning "Uninstalling the MariaDB addon will remove any data" + # bashio::log.warning "This addon is using the Maria DB addon" + # bashio::log.warning "Please ensure this is included in your backups" + # bashio::log.warning "Uninstalling the MariaDB addon will remove any data" - # bashio::log.info "Creating database if required" + # bashio::log.info "Creating database if required" - # mysql \ - # -u "${POSTGRES_USER}" -p"${POSTGRES_PASSWORD}" \ - # -h "${POSTGRES_HOST}" -P "${POSTGRES_PORT}" \ - # -e "CREATE DATABASE IF NOT EXISTS \`${POSTGRES_DB}\` ;" - # ;; + # mysql \ + # -u "${POSTGRES_USER}" -p"${POSTGRES_PASSWORD}" \ + # -h "${POSTGRES_HOST}" -P "${POSTGRES_PORT}" \ + # -e "CREATE DATABASE IF NOT EXISTS \`${POSTGRES_DB}\` ;" + # ;; - # use postgresql - postgresql_external) - bashio::log.info "Using an external database, please populate all required fields in the addons config" - export DB_ENGINE=django.db.backends.postgresql - export POSTGRES_HOST=$(bashio::config "POSTGRES_HOST") && bashio::log.blue "POSTGRES_HOST=$POSTGRES_HOST" - export POSTGRES_PORT=$(bashio::config "POSTGRES_PORT") && bashio::log.blue "POSTGRES_PORT=$POSTGRES_PORT" - export POSTGRES_DB=$(bashio::config "POSTGRES_DB") && bashio::log.blue "POSTGRES_DB=$POSTGRES_DB" - export POSTGRES_USER=$(bashio::config "POSTGRES_USER") && bashio::log.blue "POSTGRES_USER=$POSTGRES_USER" - export POSTGRES_PASSWORD=$(bashio::config "POSTGRES_PASSWORD") && bashio::log.blue "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" - ;; + # use postgresql +postgresql_external) + bashio::log.info "Using an external database, please populate all required fields in the addons config" + export DB_ENGINE=django.db.backends.postgresql + export POSTGRES_HOST=$(bashio::config "POSTGRES_HOST") && bashio::log.blue "POSTGRES_HOST=$POSTGRES_HOST" + export POSTGRES_PORT=$(bashio::config "POSTGRES_PORT") && bashio::log.blue "POSTGRES_PORT=$POSTGRES_PORT" + export POSTGRES_DB=$(bashio::config "POSTGRES_DB") && bashio::log.blue "POSTGRES_DB=$POSTGRES_DB" + export POSTGRES_USER=$(bashio::config "POSTGRES_USER") && bashio::log.blue "POSTGRES_USER=$POSTGRES_USER" + export POSTGRES_PASSWORD=$(bashio::config "POSTGRES_PASSWORD") && bashio::log.blue "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" + ;; esac @@ -109,9 +109,9 @@ ln -s /config/addons_config/tandoor_recipes/mediafiles /opt/recipes ln -s /data/recipes/staticfiles /opt/recipes if bashio::config.has_value "externalfiles_folder"; then - externalfiles_folder="$(bashio::config "externalfiles_folder")" + externalfiles_folder="$(bashio::config "externalfiles_folder")" else - externalfiles_folder="/config/addons_config/tandoor_recipes/externalfiles" + externalfiles_folder="/config/addons_config/tandoor_recipes/externalfiles" fi mkdir -p "$externalfiles_folder" ln -s "$externalfiles_folder" /opt/recipes diff --git a/teamspeak/rootfs/etc/cont-init.d/20-folders.sh b/teamspeak/rootfs/etc/cont-init.d/20-folders.sh index 799464a2a..7392a78a1 100755 --- a/teamspeak/rootfs/etc/cont-init.d/20-folders.sh +++ b/teamspeak/rootfs/etc/cont-init.d/20-folders.sh @@ -4,10 +4,10 @@ set -e # Data remanence for /teamspeak/save if [ -d /teamspeak ]; then - cp -rn /teamspeak/* /data - rm -r /teamspeak - ln -sf /data /teamspeak - chmod -R 777 /teamspeak + cp -rn /teamspeak/* /data + rm -r /teamspeak + ln -sf /data /teamspeak + chmod -R 777 /teamspeak fi #chown -R PUID:PGID /data diff --git a/teamspeak/rootfs/etc/services.d/logs.sh b/teamspeak/rootfs/etc/services.d/logs.sh index 3f26b029b..5a2ce523d 100755 --- a/teamspeak/rootfs/etc/services.d/logs.sh +++ b/teamspeak/rootfs/etc/services.d/logs.sh @@ -3,11 +3,11 @@ set -e if [ ! -f /touched ]; then - until [[ -n $(cat /data/*_1.log 2>/dev/null) ]]; do - sleep 1 - done - bashio::log.info "Here are the admin informations:" - cat /data/*_1.log - touch /touched - rm /etc/services.d/logs.sh + until [[ -n $(cat /data/*_1.log 2>/dev/null) ]]; do + sleep 1 + done + bashio::log.info "Here are the admin informations:" + cat /data/*_1.log + touch /touched + rm /etc/services.d/logs.sh fi diff --git a/transmission/rootfs/etc/cont-init.d/01-config.sh b/transmission/rootfs/etc/cont-init.d/01-config.sh index a13ca5c57..c431fc055 100755 --- a/transmission/rootfs/etc/cont-init.d/01-config.sh +++ b/transmission/rootfs/etc/cont-init.d/01-config.sh @@ -18,8 +18,8 @@ CONFIGDIR="/config/addons_config/transmission" #################### if [ -d /config/transmission ]; then - cp -r /config/transmission /config/addons_config/transmission - rm -r /config/transmission + cp -r /config/transmission /config/addons_config/transmission + rm -r /config/transmission fi ############### @@ -33,8 +33,8 @@ mkdir -p /watch || true chown -R "$PUID:$PGID" "$CONFIGDIR" if ! bashio::fs.file_exists "$CONFIGDIR/settings.json"; then - echo "Creating default config" - cp "/defaults/settings.json" "$CONFIGDIR/settings.json" + echo "Creating default config" + cp "/defaults/settings.json" "$CONFIGDIR/settings.json" fi ################# @@ -45,7 +45,7 @@ fi ############## if bashio::config.has_value 'customUI'; then - CUSTOMUI=$(bashio::config 'customUI') + CUSTOMUI=$(bashio::config 'customUI') fi bashio::log.info "UI selected : $CUSTOMUI" @@ -66,13 +66,13 @@ chown "$PUID:$PGID" "$download_dir" # if incomplete dir > 2, to allow both null and '', set it as existing if [ ${#incomplete_dir} -ge 2 ]; then - echo "Incomplete dir set: $incomplete_dir" - CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=true") - mkdir -p "$incomplete_dir" - chown "$PUID:$PGID" "$incomplete_dir" + echo "Incomplete dir set: $incomplete_dir" + CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=true") + mkdir -p "$incomplete_dir" + chown "$PUID:$PGID" "$incomplete_dir" else - echo "Incomplete dir disabled" - CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=false") + echo "Incomplete dir disabled" + CONFIG=$(bashio::jq "${CONFIG}" ".\"incomplete-dir-enabled\"=false") fi # Defaults @@ -82,11 +82,11 @@ CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-host-whitelist-enabled\"=false") CONFIG=$(bashio::jq "${CONFIG}" ".\"bind-address-ipv4\"=\"0.0.0.0\"") if bashio::config.has_value 'watch_dir'; then - CONFIG=$(bashio::jq "${CONFIG}" ".\"watch-dir\"=\"$(bashio::config 'watch_dir')\"") + CONFIG=$(bashio::jq "${CONFIG}" ".\"watch-dir\"=\"$(bashio::config 'watch_dir')\"") fi echo "${CONFIG}" >"$CONFIGDIR"/settings.json && -jq . -S "$CONFIGDIR"/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json + jq . -S "$CONFIGDIR"/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json # USER and PASS ############### @@ -95,17 +95,17 @@ CONFIG=$(<"$CONFIGDIR"/settings.json) USER=$(bashio::config 'user') PASS=$(bashio::config 'pass') if bashio::config.has_value 'user'; then - BOOLEAN=true - bashio::log.info "User & Pass set, authentification will be with user : $USER and pass : $PASS" + BOOLEAN=true + bashio::log.info "User & Pass set, authentification will be with user : $USER and pass : $PASS" else - BOOLEAN=false - bashio::log.warning "User & Pass not set, no authentification required" + BOOLEAN=false + bashio::log.warning "User & Pass not set, no authentification required" fi CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-authentication-required\"=${BOOLEAN}") CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-username\"=\"${USER}\"") CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-password\"=\"${PASS}\"") echo "${CONFIG}" >"$CONFIGDIR"/settings.json && -jq . -S "$CONFIGDIR"/settings.json | cat >temp.json && mv temp.json "$CONFIGDIR"/settings.json + jq . -S "$CONFIGDIR"/settings.json | cat >temp.json && mv temp.json "$CONFIGDIR"/settings.json # WHITELIST ########### @@ -113,13 +113,13 @@ jq . -S "$CONFIGDIR"/settings.json | cat >temp.json && mv temp.json "$CONFIGDIR" CONFIG=$(<"$CONFIGDIR"/settings.json) WHITELIST=$(bashio::config 'whitelist') if bashio::config.has_value 'whitelist'; then - BOOLEAN=true - bashio::log.info "Whitelist set, no authentification from IP $WHITELIST" + BOOLEAN=true + bashio::log.info "Whitelist set, no authentification from IP $WHITELIST" else - BOOLEAN=false - sed -i "2 i\"rpc-whitelist-enabled\": false," "$CONFIGDIR"/settings.json + BOOLEAN=false + sed -i "2 i\"rpc-whitelist-enabled\": false," "$CONFIGDIR"/settings.json fi CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-whitelist-enabled\"=${BOOLEAN}") CONFIG=$(bashio::jq "${CONFIG}" ".\"rpc-whitelist\"=\"$WHITELIST\"") echo "${CONFIG}" >"$CONFIGDIR"/settings.json && -jq . -S "$CONFIGDIR"/settings.json | cat >temp.json && mv temp.json "$CONFIGDIR"/settings.json + jq . -S "$CONFIGDIR"/settings.json | cat >temp.json && mv temp.json "$CONFIGDIR"/settings.json diff --git a/transmission/rootfs/etc/cont-init.d/19-json_repair.sh b/transmission/rootfs/etc/cont-init.d/19-json_repair.sh index 6b6b32b2d..b84278dbc 100755 --- a/transmission/rootfs/etc/cont-init.d/19-json_repair.sh +++ b/transmission/rootfs/etc/cont-init.d/19-json_repair.sh @@ -7,41 +7,41 @@ JSONSOURCE='/defaults/settings.json' # If json already exists if [ -f "${JSONTOCHECK}" ]; then - # Variables - echo "Checking settings.json format" + # Variables + echo "Checking settings.json format" - # Check if json file valid or not - jq . -S "${JSONTOCHECK}" &>/dev/null && ERROR=false || ERROR=true - if [ "$ERROR" = true ]; then - bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old" - mv "${JSONSOURCE}" "${JSONSOURCE}"_old - cp "${JSONSOURCE}" "${JSONTOCHECK}" - exit 0 - fi + # Check if json file valid or not + jq . -S "${JSONTOCHECK}" &>/dev/null && ERROR=false || ERROR=true + if [ "$ERROR" = true ]; then + bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old" + mv "${JSONSOURCE}" "${JSONSOURCE}"_old + cp "${JSONSOURCE}" "${JSONTOCHECK}" + exit 0 + fi - # Get the default keys from the original file - mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") + # Get the default keys from the original file + mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") - # Check if all keys are still there, or add them - # shellcheck disable=SC2086 - for KEYS in "${arr[@]}"; do - # Check if key exists - KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}") - if [ "$KEYSTHERE" != "true" ]; then - #Fetch initial value - JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}") - #Add key - sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}" - # Message - bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}" - fi - done + # Check if all keys are still there, or add them + # shellcheck disable=SC2086 + for KEYS in "${arr[@]}"; do + # Check if key exists + KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}") + if [ "$KEYSTHERE" != "true" ]; then + #Fetch initial value + JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}") + #Add key + sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}" + # Message + bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}" + fi + done - # Show structure in a nice way - jq . -S "${JSONTOCHECK}" | cat >temp.json && mv temp.json "${JSONTOCHECK}" + # Show structure in a nice way + jq . -S "${JSONTOCHECK}" | cat >temp.json && mv temp.json "${JSONTOCHECK}" - # Message - bashio::log.info "Your settings.json was checked and seems perfectly normal!" + # Message + bashio::log.info "Your settings.json was checked and seems perfectly normal!" fi # Repair structure diff --git a/transmission/rootfs/etc/cont-init.d/90-customUI.sh b/transmission/rootfs/etc/cont-init.d/90-customUI.sh index f0271cf6c..b9d673951 100755 --- a/transmission/rootfs/etc/cont-init.d/90-customUI.sh +++ b/transmission/rootfs/etc/cont-init.d/90-customUI.sh @@ -10,67 +10,67 @@ CUSTOMUI=$(bashio::config 'customUI') # Install webui if bashio::config.has_value 'customUI' && [ ! "$CUSTOMUI" = default ] && [ ! "$CUSTOMUI" = custom ]; then - # Variables - bashio::log.info "Alternate UI enabled : $CUSTOMUI. If webui don't work, disable this option" + # Variables + bashio::log.info "Alternate UI enabled : $CUSTOMUI. If webui don't work, disable this option" - # Clean folders - if [ -d /"$CUSTOMUI" ]; then rm -r /"${CUSTOMUI:?}"; fi - if [ -f /"$CUSTOMUI" ]; then rm -r /"${CUSTOMUI:?}"; fi + # Clean folders + if [ -d /"$CUSTOMUI" ]; then rm -r /"${CUSTOMUI:?}"; fi + if [ -f /"$CUSTOMUI" ]; then rm -r /"${CUSTOMUI:?}"; fi - ### Download WebUI - case $CUSTOMUI in - "combustion-release") - curl -o /tmp/combustion.zip -L "https://github.com/Secretmapper/combustion/archive/release.zip" - unzip /tmp/combustion.zip -d / - ;; + ### Download WebUI + case $CUSTOMUI in + "combustion-release") + curl -o /tmp/combustion.zip -L "https://github.com/Secretmapper/combustion/archive/release.zip" + unzip /tmp/combustion.zip -d / + ;; - "transmission-web-control") - ### Install WebUI - mkdir -p /transmission-web-control - curl -sL "$(curl -s https://api.github.com/repos/ronggang/transmission-web-control/releases/latest | jq --raw-output '.tarball_url')" | tar -C /transmission-web-control/ --strip-components=2 -xz \ - # Enables the original UI button in transmission-web-control - ln -s /usr/share/transmission/public_html/* /transmission-web-control/ 2>/dev/null || true - ln -s /usr/share/transmission/public_html/index.html /transmission-web-control/index.original.html - ;; + "transmission-web-control") + ### Install WebUI + mkdir -p /transmission-web-control + curl -sL "$(curl -s https://api.github.com/repos/ronggang/transmission-web-control/releases/latest | jq --raw-output '.tarball_url')" | tar -C /transmission-web-control/ --strip-components=2 -xz + # Enables the original UI button in transmission-web-control + ln -s /usr/share/transmission/public_html/* /transmission-web-control/ 2>/dev/null || true + ln -s /usr/share/transmission/public_html/index.html /transmission-web-control/index.original.html + ;; - "kettu") - mkdir -p /kettu && \ - curl -o /tmp/kettu.tar.gz -L "https://github.com/endor/kettu/archive/master.tar.gz" - tar xf /tmp/kettu.tar.gz -C /kettu --strip-components=1 - ;; + "kettu") + mkdir -p /kettu && + curl -o /tmp/kettu.tar.gz -L "https://github.com/endor/kettu/archive/master.tar.gz" + tar xf /tmp/kettu.tar.gz -C /kettu --strip-components=1 + ;; - "flood-for-transmission") - curl -o /tmp/flood-for-transmission.tar.gz -L "https://github.com/johman10/flood-for-transmission/releases/download/latest/flood-for-transmission.tar.gz" - tar xf /tmp/flood-for-transmission.tar.gz -C / - ;; + "flood-for-transmission") + curl -o /tmp/flood-for-transmission.tar.gz -L "https://github.com/johman10/flood-for-transmission/releases/download/latest/flood-for-transmission.tar.gz" + tar xf /tmp/flood-for-transmission.tar.gz -C / + ;; - "transmissionic") - TRANSMISSIONIC_VERSION=$(curl -s -L "https://api.github.com/repos/6c65726f79/Transmissionic/releases/latest" | jq -r .tag_name) - echo "**** grab transmissionic ****" && \ - if [ -z "${TRANSMISSIONIC_VERSION+x}" ]; then \ - TRANSMISSIONIC_VERSION="$(curl -s "https://api.github.com/repos/6c65726f79/Transmissionic/releases/latest" \ - | jq -rc ".tag_name")"; \ - fi && \ - curl -o \ - /tmp/transmissionic.zip -L \ - "https://github.com/6c65726f79/Transmissionic/releases/download/${TRANSMISSIONIC_VERSION}/Transmissionic-webui-${TRANSMISSIONIC_VERSION}.zip" && \ - unzip \ - /tmp/transmissionic.zip -d \ - /themes && \ - mv /themes/web /transmissionic - ;; + "transmissionic") + TRANSMISSIONIC_VERSION=$(curl -s -L "https://api.github.com/repos/6c65726f79/Transmissionic/releases/latest" | jq -r .tag_name) + echo "**** grab transmissionic ****" && + if [ -z "${TRANSMISSIONIC_VERSION+x}" ]; then + TRANSMISSIONIC_VERSION="$(curl -s "https://api.github.com/repos/6c65726f79/Transmissionic/releases/latest" | + jq -rc ".tag_name")" + fi && + curl -o \ + /tmp/transmissionic.zip -L \ + "https://github.com/6c65726f79/Transmissionic/releases/download/${TRANSMISSIONIC_VERSION}/Transmissionic-webui-${TRANSMISSIONIC_VERSION}.zip" && + unzip \ + /tmp/transmissionic.zip -d \ + /themes && + mv /themes/web /transmissionic + ;; - **) - exit 0 - ;; + **) + exit 0 + ;; - esac + esac - # Define variable - CUSTOMUI="/${CUSTOMUI}" - chown -R abc:abc "$CUSTOMUI" - if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export TRANSMISSION_WEB_HOME=$CUSTOMUI" /etc/services.d/*/*run* 2>/dev/null; fi - if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CUSTOMUI" > /var/run/s6/container_environment/TRANSMISSION_WEB_HOME; fi - printf "%s\n" "TRANSMISSION_WEB_HOME=\"$CUSTOMUI\"" >> ~/.bashrc + # Define variable + CUSTOMUI="/${CUSTOMUI}" + chown -R abc:abc "$CUSTOMUI" + if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export TRANSMISSION_WEB_HOME=$CUSTOMUI" /etc/services.d/*/*run* 2>/dev/null; fi + if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CUSTOMUI" >/var/run/s6/container_environment/TRANSMISSION_WEB_HOME; fi + printf "%s\n" "TRANSMISSION_WEB_HOME=\"$CUSTOMUI\"" >>~/.bashrc fi diff --git a/transmission_openvpn/rootfs/etc/cont-init.d/99-run.sh b/transmission_openvpn/rootfs/etc/cont-init.d/99-run.sh index ace02ffaf..a7d749e3b 100755 --- a/transmission_openvpn/rootfs/etc/cont-init.d/99-run.sh +++ b/transmission_openvpn/rootfs/etc/cont-init.d/99-run.sh @@ -7,8 +7,8 @@ bashio::log.info "Exporting variables" for k in $(bashio::jq "/data/options.json" 'keys | .[]'); do - bashio::log.blue "$k"="$(bashio::config "$k")" - export "$k"="$(bashio::config "$k")" + bashio::log.blue "$k"="$(bashio::config "$k")" + export "$k"="$(bashio::config "$k")" done echo "" @@ -19,14 +19,14 @@ mkdir -p "$TRANSMISSION_HOME"/openvpn ########################### if [ -f "$TRANSMISSION_HOME"/settings.json ]; then - echo "Updating variables" - sed -i "/download-dir/c \"download-dir\": \"$(bashio::config 'TRANSMISSION_DOWNLOAD_DIR')\"," "$TRANSMISSION_HOME"/settings.json - if bashio::config.has_value 'TRANSMISSION_INCOMPLETE_DIR'; then - sed -i "/\"incomplete-dir\"/c \"incomplete-dir\": \"$(bashio::config 'TRANSMISSION_INCOMPLETE_DIR')\"," "$TRANSMISSION_HOME"/settings.json || true - sed -i "/\"incomplete-dir-enabled\"/c \"incomplete-dir-enabled\": true," "$TRANSMISSION_HOME"/settings.json || true - fi - sed -i "/watch-dir/c \"watch-dir\": \"$(bashio::config 'TRANSMISSION_WATCH_DIR')\"," "$TRANSMISSION_HOME"/settings.json || true - sed -i.bak ':begin;$!N;s/,\n}/\n}/g;tbegin;P;D' "$TRANSMISSION_HOME"/settings.json + echo "Updating variables" + sed -i "/download-dir/c \"download-dir\": \"$(bashio::config 'TRANSMISSION_DOWNLOAD_DIR')\"," "$TRANSMISSION_HOME"/settings.json + if bashio::config.has_value 'TRANSMISSION_INCOMPLETE_DIR'; then + sed -i "/\"incomplete-dir\"/c \"incomplete-dir\": \"$(bashio::config 'TRANSMISSION_INCOMPLETE_DIR')\"," "$TRANSMISSION_HOME"/settings.json || true + sed -i "/\"incomplete-dir-enabled\"/c \"incomplete-dir-enabled\": true," "$TRANSMISSION_HOME"/settings.json || true + fi + sed -i "/watch-dir/c \"watch-dir\": \"$(bashio::config 'TRANSMISSION_WATCH_DIR')\"," "$TRANSMISSION_HOME"/settings.json || true + sed -i.bak ':begin;$!N;s/,\n}/\n}/g;tbegin;P;D' "$TRANSMISSION_HOME"/settings.json fi ####################### @@ -41,18 +41,18 @@ TRANSMISSION_HOME="$(bashio::config 'TRANSMISSION_HOME')" # Get id if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then - echo "Using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')" - PUID="$(bashio::config 'PUID')" - PGID="$(bashio::config 'PGID')" + echo "Using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')" + PUID="$(bashio::config 'PUID')" + PGID="$(bashio::config 'PGID')" else - PUID="$(id -u)" - PGID="$(id -g)" + PUID="$(id -u)" + PGID="$(id -g)" fi # Update permissions for folder in "$DOWNLOAD_DIR" "$INCOMPLETE_DIR" "$WATCH_DIR" "$TRANSMISSION_HOME"; do - mkdir -p "$folder" - chown -R "$PUID:$PGID" "$folder" + mkdir -p "$folder" + chown -R "$PUID:$PGID" "$folder" done ################### @@ -61,97 +61,96 @@ done # Migrate OPENVPN_CUSTOM_PROVIDER to OPENVPN_PROVIDER if bashio::config.true 'OPENVPN_CUSTOM_PROVIDER'; then - # Use new option - bashio::addon.option "OPENVPN_PROVIDER" "custom" - # Remove previous option - bashio::addon.option "OPENVPN_CUSTOM_PROVIDER" - # log - bashio::log.yellow "OPENVPN_CUSTOM_PROVIDER actived, OPENVPN_PROVIDER set to custom" - # Restart - bashio::addon.restart + # Use new option + bashio::addon.option "OPENVPN_PROVIDER" "custom" + # Remove previous option + bashio::addon.option "OPENVPN_CUSTOM_PROVIDER" + # log + bashio::log.yellow "OPENVPN_CUSTOM_PROVIDER actived, OPENVPN_PROVIDER set to custom" + # Restart + bashio::addon.restart fi # Function to check for files path -function check_path () { +function check_path() { - # Get variable - file="$1" + # Get variable + file="$1" - # Double check exists - if [ ! -f "$file" ]; then - bashio::warning "$file not found" - return 1 - fi + # Double check exists + if [ ! -f "$file" ]; then + bashio::warning "$file not found" + return 1 + fi - cp "$file" /tmpfile + cp "$file" /tmpfile - # Loop through each line of the input file - while read -r line - do - # Check if the line contains a txt file - if [[ "$line" =~ \.txt ]] || [[ "$line" =~ \.crt ]]; then - # Extract the txt file name from the line - file_name="$(echo "$line" | awk -F' ' '{print $2}')" - # Check if the txt file exists - if [ ! -f "$file_name" ]; then - # Check if the txt file exists in the /config/openvpn/ directory - if [ -f "/etc/openvpn/custom/${file_name##*/}" ]; then - # Append /config/openvpn/ in front of the original txt file in the ovpn file - sed -i "s|$file_name|/etc/openvpn/custom/${file_name##*/}|g" "$file" - # Print a success message - bashio::log.warning "Appended /etc/openvpn/custom/ to ${file_name##*/} in $file" - else - # Print an error message - bashio::log.warning "$file_name is referenced in your ovpn file but does not exist in the $TRANSMISSION_HOME/openvpn folder" - sleep 5 - fi - fi - fi - done < /tmpfile + # Loop through each line of the input file + while read -r line; do + # Check if the line contains a txt file + if [[ "$line" =~ \.txt ]] || [[ "$line" =~ \.crt ]]; then + # Extract the txt file name from the line + file_name="$(echo "$line" | awk -F' ' '{print $2}')" + # Check if the txt file exists + if [ ! -f "$file_name" ]; then + # Check if the txt file exists in the /config/openvpn/ directory + if [ -f "/etc/openvpn/custom/${file_name##*/}" ]; then + # Append /config/openvpn/ in front of the original txt file in the ovpn file + sed -i "s|$file_name|/etc/openvpn/custom/${file_name##*/}|g" "$file" + # Print a success message + bashio::log.warning "Appended /etc/openvpn/custom/ to ${file_name##*/} in $file" + else + # Print an error message + bashio::log.warning "$file_name is referenced in your ovpn file but does not exist in the $TRANSMISSION_HOME/openvpn folder" + sleep 5 + fi + fi + fi + done /env.sh - chmod 777 /env.sh - chmod +x /usr/bin/restart_addon - sed -i "1a . /env.sh; /usr/bin/restart_addon >/proc/1/fd/1 2>/proc/1/fd/2" /etc/openvpn/tunnelDown.sh + bashio::log.info "Auto restarting addon if openvpn down" + ( + set -o posix + export -p + ) >/env.sh + chmod 777 /env.sh + chmod +x /usr/bin/restart_addon + sed -i "1a . /env.sh; /usr/bin/restart_addon >/proc/1/fd/1 2>/proc/1/fd/2" /etc/openvpn/tunnelDown.sh fi if [ -f /data/addonrestarted ]; then - bashio::log.warning "Warning, transmission had failed and the addon has self-rebooted as 'auto_restart' option was on. Please check that it is still running" - rm /data/addonrestarted + bashio::log.warning "Warning, transmission had failed and the addon has self-rebooted as 'auto_restart' option was on. Please check that it is still running" + rm /data/addonrestarted fi ####################### @@ -194,14 +196,15 @@ echo "" # Correct mullvad if [ "$(bashio::config "OPENVPN_PROVIDER")" == "mullvad" ]; then - bashio::log.info "Mullvad selected, copying script for IPv6 disabling" - chown "$PUID:$PGID" /opt/modify-mullvad.sh - chmod +x /opt/modify-mullvad.sh - sed -i '$i/opt/modify-mullvad.sh' /etc/openvpn/start.sh + bashio::log.info "Mullvad selected, copying script for IPv6 disabling" + chown "$PUID:$PGID" /opt/modify-mullvad.sh + chmod +x /opt/modify-mullvad.sh + sed -i '$i/opt/modify-mullvad.sh' /etc/openvpn/start.sh fi bashio::log.info "Starting app" -/./etc/openvpn/start.sh & echo "" +/./etc/openvpn/start.sh & +echo "" ################# # Allow ingress # diff --git a/transmission_openvpn/rootfs/opt/modify-mullvad.sh b/transmission_openvpn/rootfs/opt/modify-mullvad.sh index f365d47cd..ffbfb7407 100755 --- a/transmission_openvpn/rootfs/opt/modify-mullvad.sh +++ b/transmission_openvpn/rootfs/opt/modify-mullvad.sh @@ -1,12 +1,12 @@ #!/bin/bash if bashio::config.has_value "OPENVPN_CUSTOM_PROVIDER"; then - OVPNLOCATION="$(bashio::config "OPENVPN_CUSTOM_PROVIDER_OVPN_LOCATION")" - OPENVPN_PROVIDER="${OVPNLOCATION##*/}" - OPENVPN_PROVIDER="${OPENVPN_PROVIDER%.*}" - OPENVPN_PROVIDER="${OPENVPN_PROVIDER,,}" + OVPNLOCATION="$(bashio::config "OPENVPN_CUSTOM_PROVIDER_OVPN_LOCATION")" + OPENVPN_PROVIDER="${OVPNLOCATION##*/}" + OPENVPN_PROVIDER="${OPENVPN_PROVIDER%.*}" + OPENVPN_PROVIDER="${OPENVPN_PROVIDER,,}" else - OPENVPN_PROVIDER="mullvad" + OPENVPN_PROVIDER="mullvad" fi echo "Removing IPv6 from mullvad" diff --git a/ubooquity/rootfs/etc/32-nginx_ingress.sh b/ubooquity/rootfs/etc/32-nginx_ingress.sh index 0dc1fe02e..fce42c568 100755 --- a/ubooquity/rootfs/etc/32-nginx_ingress.sh +++ b/ubooquity/rootfs/etc/32-nginx_ingress.sh @@ -15,13 +15,13 @@ declare port port=$(bashio::addon.ingress_port) # shellcheck disable=SC2210 if [ "$port" ] >1; then - # Adapt nginx - sed -i "s|%%port%%|$port|g" /etc/nginx/servers/ingress.conf - sed -i "s|%%interface%%|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ingress.conf - # Removebaseurl - jq '.reverseProxyPrefix = ""' /config/addons_config/ubooquity/preferences.json | sponge /config/addons_config/ubooquity/preferences.json - # Log - bashio::log.info "Ingress enabled" + # Adapt nginx + sed -i "s|%%port%%|$port|g" /etc/nginx/servers/ingress.conf + sed -i "s|%%interface%%|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ingress.conf + # Removebaseurl + jq '.reverseProxyPrefix = ""' /config/addons_config/ubooquity/preferences.json | sponge /config/addons_config/ubooquity/preferences.json + # Log + bashio::log.info "Ingress enabled" else - rm /etc/nginx/servers/ingress.conf + rm /etc/nginx/servers/ingress.conf fi diff --git a/ubooquity/rootfs/etc/cont-init.d/00-folders.sh b/ubooquity/rootfs/etc/cont-init.d/00-folders.sh index ab1d78dfa..63a6d21ad 100755 --- a/ubooquity/rootfs/etc/cont-init.d/00-folders.sh +++ b/ubooquity/rootfs/etc/cont-init.d/00-folders.sh @@ -6,20 +6,20 @@ slug=ubooquity if [ ! -d /config/addons_config/$slug ]; then - if [ -d /config/$slug ]; then - echo "Moving to new location /config/addons_config/$slug" - mkdir -p /config/addons_config/$slug - chmod 777 /config/addons_config/$slug - mv /config/$slug/* /config/addons_config/$slug/ - rm -r /config/$slug - fi + if [ -d /config/$slug ]; then + echo "Moving to new location /config/addons_config/$slug" + mkdir -p /config/addons_config/$slug + chmod 777 /config/addons_config/$slug + mv /config/$slug/* /config/addons_config/$slug/ + rm -r /config/$slug + fi - echo "Creating /config/addons_config/$slug" - mkdir -p /config/addons_config/$slug - chmod 777 /config/addons_config/$slug + echo "Creating /config/addons_config/$slug" + mkdir -p /config/addons_config/$slug + chmod 777 /config/addons_config/$slug fi # Remove empty config file -if [ ! -s /config/addons_config/$slug/preferences.json ] ; then - rm /config/addons_config/$slug/preferences.json || true +if [ ! -s /config/addons_config/$slug/preferences.json ]; then + rm /config/addons_config/$slug/preferences.json || true fi diff --git a/ubooquity/rootfs/etc/cont-init.d/32-nginx_ssl.sh b/ubooquity/rootfs/etc/cont-init.d/32-nginx_ssl.sh index 7d45ed9b4..05bd07ce4 100755 --- a/ubooquity/rootfs/etc/cont-init.d/32-nginx_ssl.sh +++ b/ubooquity/rootfs/etc/cont-init.d/32-nginx_ssl.sh @@ -18,11 +18,11 @@ sed -i "s|%%interface%%|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ssl.co # Ssl values if bashio::config.true 'ssl'; then - bashio::config.require.ssl - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') - sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf - sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf - sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf - bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port 2205)/ubooquity ; admin is at https://YOURIP:$(bashio::addon.port 2206)/ubooquity/admin" + bashio::config.require.ssl + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') + sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf + sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf + sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf + bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port 2205)/ubooquity ; admin is at https://YOURIP:$(bashio::addon.port 2206)/ubooquity/admin" fi diff --git a/ubooquity/rootfs/etc/cont-init.d/93-custom_webUI.sh b/ubooquity/rootfs/etc/cont-init.d/93-custom_webUI.sh index cc111f97b..fa1eda1ac 100755 --- a/ubooquity/rootfs/etc/cont-init.d/93-custom_webUI.sh +++ b/ubooquity/rootfs/etc/cont-init.d/93-custom_webUI.sh @@ -7,33 +7,33 @@ set -e ################ if bashio::config.has_value 'theme'; then - ### Variables - CUSTOMUI=$(bashio::config 'theme') - bashio::log.info "Alternate theme enabled : $CUSTOMUI. If webui don't work, disable this option" + ### Variables + CUSTOMUI=$(bashio::config 'theme') + bashio::log.info "Alternate theme enabled : $CUSTOMUI. If webui don't work, disable this option" - ### Download WebUI - case "$CUSTOMUI" in - "comixology2") - curl -f -s -S -J -L -o /data/release.zip https://github.com/scooterpsu/Comixology_Ubooquity_2/releases/download/v3.4/comixology2.zip >/dev/null && - unzip -o -q /data/release.zip -d /config/addons_config/ubooquity/themes/ - ;; + ### Download WebUI + case "$CUSTOMUI" in + "comixology2") + curl -f -s -S -J -L -o /data/release.zip https://github.com/scooterpsu/Comixology_Ubooquity_2/releases/download/v3.4/comixology2.zip >/dev/null && + unzip -o -q /data/release.zip -d /config/addons_config/ubooquity/themes/ + ;; - "plextheme-master") - curl -f -s -S -J -L -o /data/release.zip https://github.com/FinalAngel/plextheme/archive/master.zip >/dev/null && - unzip -q /data/release.zip -d /config/addons_config/ubooquity/themes/ - # && mv /config/addons_config/ubooquity/themes/plextheme-master/ /config/addons_config/ubooquity/themes/ - ;; + "plextheme-master") + curl -f -s -S -J -L -o /data/release.zip https://github.com/FinalAngel/plextheme/archive/master.zip >/dev/null && + unzip -q /data/release.zip -d /config/addons_config/ubooquity/themes/ + # && mv /config/addons_config/ubooquity/themes/plextheme-master/ /config/addons_config/ubooquity/themes/ + ;; - "default") - exit 0 - ;; + "default") + exit 0 + ;; - esac + esac - ### Clean files - rm /data/release.zip || true + ### Clean files + rm /data/release.zip || true - ### Set preference - jq --arg variable "$CUSTOMUI" '.theme = $variable' /config/addons_config/ubooquity/preferences.json | sponge /config/addons_config/ubooquity/preferences.json + ### Set preference + jq --arg variable "$CUSTOMUI" '.theme = $variable' /config/addons_config/ubooquity/preferences.json | sponge /config/addons_config/ubooquity/preferences.json fi diff --git a/unpackerr/rootfs/etc/cont-init.d/90-vpn.sh b/unpackerr/rootfs/etc/cont-init.d/90-vpn.sh index 7fec55c21..504b1b292 100755 --- a/unpackerr/rootfs/etc/cont-init.d/90-vpn.sh +++ b/unpackerr/rootfs/etc/cont-init.d/90-vpn.sh @@ -4,24 +4,24 @@ set +e VPN_PROVIDER="${VPN_PROVIDER:-null}" case "$VPN_PROVIDER" in - "generic") - sed -i "1a sleep infinity" etc/s6*/s6*/service-pia/run - sed -i "1a sleep infinity" etc/s6*/s6*/service-proton/run - ;; +"generic") + sed -i "1a sleep infinity" etc/s6*/s6*/service-pia/run + sed -i "1a sleep infinity" etc/s6*/s6*/service-proton/run + ;; - "pia") - sed -i "1a sleep infinity" /etc/s6*/s6*/service-privoxy/run - sed -i "1a sleep infinity" /etc/s6*/s6*/service-proton/run - ;; +"pia") + sed -i "1a sleep infinity" /etc/s6*/s6*/service-privoxy/run + sed -i "1a sleep infinity" /etc/s6*/s6*/service-proton/run + ;; - "proton") - sed -i "1a sleep infinity" /etc/s6*/s6*/service-privoxy/run - sed -i "1a sleep infinity" /etc/s6*/s6*/service-pia/run - ;; +"proton") + sed -i "1a sleep infinity" /etc/s6*/s6*/service-privoxy/run + sed -i "1a sleep infinity" /etc/s6*/s6*/service-pia/run + ;; - **) - sed -i "1a sleep infinity" /etc/s6*/s6*/service-privoxy/run - sed -i "1a sleep infinity" /etc/s6*/s6*/service-proton/run - sed -i "1a sleep infinity" /etc/s6*/s6*/service-pia/run - ;; +**) + sed -i "1a sleep infinity" /etc/s6*/s6*/service-privoxy/run + sed -i "1a sleep infinity" /etc/s6*/s6*/service-proton/run + sed -i "1a sleep infinity" /etc/s6*/s6*/service-pia/run + ;; esac 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 b4d4df523..58274c383 100755 --- a/webtop_kde/rootfs/etc/cont-init.d/20-folders.sh +++ b/webtop_kde/rootfs/etc/cont-init.d/20-folders.sh @@ -9,29 +9,29 @@ PGID=$(bashio::config "PGID") # Set user for microsoft edge if available if [ -f /usr/bin/microsoft-edge-real ]; then - chown "$PUID:$PGID" /usr/bin/microsoft-edge* - chmod +x /usr/bin/microsoft-edge* + chown "$PUID:$PGID" /usr/bin/microsoft-edge* + chmod +x /usr/bin/microsoft-edge* fi # Check data location LOCATION=$(bashio::config 'data_location') if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then - # Default location - LOCATION="/config/data_kde" + # Default location + LOCATION="/config/data_kde" else - # 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 + # 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="/config/data_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 + if [ -z "$LOCATIONOK" ]; then + LOCATION="/config/data_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 @@ -39,17 +39,17 @@ 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 + 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|/config/data_kde|$LOCATION|g" $(find "$folders" -type f) &>/dev/null || true - fi + if [ -d "$folders" ]; then + sed -i "s|/config/data_kde|$LOCATION|g" $(find "$folders" -type f) &>/dev/null || true + fi done # Change user home @@ -57,12 +57,12 @@ sed -i "s|^\(abc:[^:]*:[^:]*:[^:]*:[^:]*:\)[^:]*|\1$LOCATION|" /etc/passwd #usermod --home "$LOCATION" abc || true # 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 +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\n" "export HOME=\"$LOCATION\"" - printf "%s\n" "export FM_HOME=\"$LOCATION\"" -} >> ~/.bashrc + printf "%s\n" "export HOME=\"$LOCATION\"" + printf "%s\n" "export FM_HOME=\"$LOCATION\"" +} >>~/.bashrc # Create folder echo "Creating $LOCATION" @@ -72,8 +72,8 @@ mkdir -p "$LOCATION" mkdir -p /.cache chmod 777 /.cache if [ -d "/config/.cache" ]; then - cp -rf /config/.cache /.cache - rm -r /config/.cache + cp -rf /config/.cache /.cache + rm -r /config/.cache fi ln -sf /config/.cache /.cache diff --git a/webtop_kde/rootfs/etc/cont-init.d/80-configuration.sh b/webtop_kde/rootfs/etc/cont-init.d/80-configuration.sh index 9ee5c4c85..712e94576 100755 --- a/webtop_kde/rootfs/etc/cont-init.d/80-configuration.sh +++ b/webtop_kde/rootfs/etc/cont-init.d/80-configuration.sh @@ -5,68 +5,68 @@ set -e # Install specific apps if bashio::config.has_value 'additional_apps'; then - bashio::log.info "Installing additional apps :" - # hadolint ignore=SC2005 - NEWAPPS=$(bashio::config 'additional_apps') - for packagestoinstall in ${NEWAPPS//,/ }; do - bashio::log.green "... $packagestoinstall" - if command -v "apk" &>/dev/null; then - apk add --no-cache "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") - elif command -v "apt" &>/dev/null; then - apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") - elif command -v "pacman" &>/dev/null; then - pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") - fi - done + bashio::log.info "Installing additional apps :" + # hadolint ignore=SC2005 + NEWAPPS=$(bashio::config 'additional_apps') + for packagestoinstall in ${NEWAPPS//,/ }; do + bashio::log.green "... $packagestoinstall" + if command -v "apk" &>/dev/null; then + apk add --no-cache "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") + elif command -v "apt" &>/dev/null; then + apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") + elif command -v "pacman" &>/dev/null; then + pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") + fi + done fi # Set TZ if bashio::config.has_value 'TZ'; then - TIMEZONE=$(bashio::config 'TZ') - bashio::log.info "Setting timezone to $TIMEZONE" - ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime - echo "$TIMEZONE" >/etc/timezone + TIMEZONE=$(bashio::config 'TZ') + bashio::log.info "Setting timezone to $TIMEZONE" + ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime + echo "$TIMEZONE" >/etc/timezone fi || (bashio::log.fatal "Error : $TIMEZONE not found. Here is a list of valid timezones : https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html") # Set keyboard if bashio::config.has_value 'KEYBOARD'; then - KEYBOARD=$(bashio::config 'KEYBOARD') - bashio::log.info "Setting keyboard to $KEYBOARD" - if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" > /var/run/s6/container_environment/KEYBOARD; fi - printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >> ~/.bashrc + KEYBOARD=$(bashio::config 'KEYBOARD') + bashio::log.info "Setting keyboard to $KEYBOARD" + if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" >/var/run/s6/container_environment/KEYBOARD; fi + printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >>~/.bashrc fi || true # Set password if bashio::config.has_value 'PASSWORD'; then - bashio::log.info "Setting password to the value defined in options" - PASSWORD=$(bashio::config 'PASSWORD') - passwd -d abc - echo -e "$PASSWORD\n$PASSWORD" | passwd abc + bashio::log.info "Setting password to the value defined in options" + PASSWORD=$(bashio::config 'PASSWORD') + passwd -d abc + echo -e "$PASSWORD\n$PASSWORD" | passwd abc elif ! bashio::config.has_value 'PASSWORD' && [[ -n "$(bashio::addon.port "3000")" ]] && [[ -n $(bashio::addon.port "3001") ]]; then - bashio::log.warning "SEVERE RISK IDENTIFIED" - bashio::log.warning "You are opening an external port but your password is not defined" - bashio::log.warning "You risk being hacked ! Please disable the external ports, or use a password" + bashio::log.warning "SEVERE RISK IDENTIFIED" + bashio::log.warning "You are opening an external port but your password is not defined" + bashio::log.warning "You risk being hacked ! Please disable the external ports, or use a password" fi # Set password if bashio::config.true 'install_ms_edge'; then - bashio::log.info "Adding microsoft edge" - # Install edge - apt-get update - echo "**** install edge ****" - apt-get install --no-install-recommends -y ca-certificates - if [ -z ${EDGE_VERSION+x} ]; then \ - EDGE_VERSION=$(curl -sL https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/ | \ - awk -F'( 0' "${NGINX_CONFIG}" > tmpfile +awk -v n=4 '/server/{n--}; n > 0' "${NGINX_CONFIG}" >tmpfile mv tmpfile "${NGINX_CONFIG}" # Remove ipv6 diff --git a/webtop_kde/rootfs/etc/cont-init.d/90-ssl.sh b/webtop_kde/rootfs/etc/cont-init.d/90-ssl.sh index 5d011d509..bb9290b78 100755 --- a/webtop_kde/rootfs/etc/cont-init.d/90-ssl.sh +++ b/webtop_kde/rootfs/etc/cont-init.d/90-ssl.sh @@ -3,20 +3,20 @@ set -e if bashio::config.true 'use_own_certs'; then - bashio::log.green "Using referenced ssl certificates to connect with https. Please remember to open the ssl port in the addon options" - CERTFILE="$(bashio::config 'certfile')" - KEYFILE="$(bashio::config 'keyfile')" - NGINX_CONFIG="/defaults/default.conf" + bashio::log.green "Using referenced ssl certificates to connect with https. Please remember to open the ssl port in the addon options" + CERTFILE="$(bashio::config 'certfile')" + KEYFILE="$(bashio::config 'keyfile')" + NGINX_CONFIG="/defaults/default.conf" - #Check if files exist - echo "... checking if referenced files exist" - if [ -f /ssl/"$CERTFILE" ] && [ -f /ssl/"$KEYFILE" ]; then - # Add ssl file - sed -i "s|/config/data/ssl/cert.pem|/ssl/$CERTFILE|g" "$NGINX_CONFIG" - sed -i "s|/config/data/ssl/cert.key|/ssl/$KEYFILE|g" "$NGINX_CONFIG" - echo "... done" - else - bashio::log.warning "... certificate /ssl/$CERTFILE and /ssl/$KEYFILE and not found, using self-generated certificates" - fi + #Check if files exist + echo "... checking if referenced files exist" + if [ -f /ssl/"$CERTFILE" ] && [ -f /ssl/"$KEYFILE" ]; then + # Add ssl file + sed -i "s|/config/data/ssl/cert.pem|/ssl/$CERTFILE|g" "$NGINX_CONFIG" + sed -i "s|/config/data/ssl/cert.key|/ssl/$KEYFILE|g" "$NGINX_CONFIG" + echo "... done" + else + bashio::log.warning "... certificate /ssl/$CERTFILE and /ssl/$KEYFILE and not found, using self-generated certificates" + fi fi diff --git a/webtop_kde/rootfs/helpers/microsoft-edge-stable b/webtop_kde/rootfs/helpers/microsoft-edge-stable index 371e1c709..c20665083 100755 --- a/webtop_kde/rootfs/helpers/microsoft-edge-stable +++ b/webtop_kde/rootfs/helpers/microsoft-edge-stable @@ -4,7 +4,7 @@ BIN=/usr/bin/microsoft-edge-real # Run normally on privved containers or modified un non priv ${BIN} \ - --password-store=basic \ - --no-sandbox \ - --test-type \ - "$@" > /dev/null 2>&1 + --password-store=basic \ + --no-sandbox \ + --test-type \ + "$@" >/dev/null 2>&1 diff --git a/webtrees/rootfs/etc/cont-init.d/02-mariadb_discovery.sh b/webtrees/rootfs/etc/cont-init.d/02-mariadb_discovery.sh index b3cfb3e87..8c86b8a64 100755 --- a/webtrees/rootfs/etc/cont-init.d/02-mariadb_discovery.sh +++ b/webtrees/rootfs/etc/cont-init.d/02-mariadb_discovery.sh @@ -3,13 +3,13 @@ set -e if bashio::services.available 'mysql'; then - bashio::log.green "---" - bashio::log.yellow "MariaDB addon discovered on your system. If you want to use it, you need to use those values when doing the initial startup wizard, or modify manually the config.ini.php file in /config/data (mapped to /addon_configs/xxx-webtrees/data when accessing using a third party tool)" - bashio::log.blue "Host-name : $(bashio::services "mysql" "host")" - bashio::log.blue "Port : $(bashio::services "mysql" "port")" - bashio::log.blue "Database user : $(bashio::services "mysql" "username")" - bashio::log.blue "Database password : $(bashio::services "mysql" "password")" - bashio::log.blue "Database name : webtrees" - bashio::log.blue "Database prefix : wt_" - bashio::log.green "---" + bashio::log.green "---" + bashio::log.yellow "MariaDB addon discovered on your system. If you want to use it, you need to use those values when doing the initial startup wizard, or modify manually the config.ini.php file in /config/data (mapped to /addon_configs/xxx-webtrees/data when accessing using a third party tool)" + bashio::log.blue "Host-name : $(bashio::services "mysql" "host")" + bashio::log.blue "Port : $(bashio::services "mysql" "port")" + bashio::log.blue "Database user : $(bashio::services "mysql" "username")" + bashio::log.blue "Database password : $(bashio::services "mysql" "password")" + bashio::log.blue "Database name : webtrees" + bashio::log.blue "Database prefix : wt_" + bashio::log.green "---" fi diff --git a/webtrees/rootfs/etc/cont-init.d/99-run.sh b/webtrees/rootfs/etc/cont-init.d/99-run.sh index 3bd96c75d..6deb037b2 100755 --- a/webtrees/rootfs/etc/cont-init.d/99-run.sh +++ b/webtrees/rootfs/etc/cont-init.d/99-run.sh @@ -21,25 +21,25 @@ cp -rn /var2/www/webtrees/modules_v4/* /config/modules_v4/ &>/dev/null || true # Check if a migration is needed if bashio::fs.file_exists "$DATA_LOCATION_FILE"; then - DATA_LOCATION_CURRENT="$(cat "$DATA_LOCATION_FILE")" - DATA_LOCATION_CURRENT="${DATA_LOCATION_CURRENT%/}" + DATA_LOCATION_CURRENT="$(cat "$DATA_LOCATION_FILE")" + DATA_LOCATION_CURRENT="${DATA_LOCATION_CURRENT%/}" elif [[ -d /share/webtrees ]] && [[ "$(ls -A /share/webtrees)" ]]; then - DATA_LOCATION_CURRENT="/share/webtrees" + DATA_LOCATION_CURRENT="/share/webtrees" else - DATA_LOCATION_CURRENT="$DATA_LOCATION" + DATA_LOCATION_CURRENT="$DATA_LOCATION" fi # Migrate files if [[ "$DATA_LOCATION_CURRENT" != "$DATA_LOCATION" ]] && [[ "$(ls -A "$DATA_LOCATION_CURRENT")" ]]; then - bashio::log.warning "Data location was changed from $DATA_LOCATION_CURRENT to $DATA_LOCATION, migrating files" - cp -rnf "$DATA_LOCATION_CURRENT"/* "$DATA_LOCATION"/ &>/dev/null || true - echo "Files moved to $DATA_LOCATION" > "$DATA_LOCATION_CURRENT"/migrated - mv "$DATA_LOCATION_CURRENT" "${DATA_LOCATION_CURRENT}_migrated" + bashio::log.warning "Data location was changed from $DATA_LOCATION_CURRENT to $DATA_LOCATION, migrating files" + cp -rnf "$DATA_LOCATION_CURRENT"/* "$DATA_LOCATION"/ &>/dev/null || true + echo "Files moved to $DATA_LOCATION" >"$DATA_LOCATION_CURRENT"/migrated + mv "$DATA_LOCATION_CURRENT" "${DATA_LOCATION_CURRENT}_migrated" fi # Saving data location echo "... using data folder $DATA_LOCATION" -echo -n "$DATA_LOCATION" > "$DATA_LOCATION_FILE" +echo -n "$DATA_LOCATION" >"$DATA_LOCATION_FILE" # Update entrypoint # Correct data directory @@ -64,8 +64,8 @@ chmod -R 755 "/config" # Remove /data/data if [[ -d "$DATA_LOCATION"/data ]] && [[ "$(ls -A "$DATA_LOCATION"/data/*)" ]]; then - mv "$DATA_LOCATION"/data/* "$DATA_LOCATION"/ - rm -r "$DATA_LOCATION"/data + mv "$DATA_LOCATION"/data/* "$DATA_LOCATION"/ + rm -r "$DATA_LOCATION"/data fi ################ @@ -81,52 +81,52 @@ BASE_URL="${BASE_URL%%:*}" bashio::config.require.ssl if bashio::config.true 'ssl'; then - #set variables - CERTFILE=$(bashio::config 'certfile') - KEYFILE=$(bashio::config 'keyfile') + #set variables + CERTFILE=$(bashio::config 'certfile') + KEYFILE=$(bashio::config 'keyfile') - #Replace variables - export SSL_CERT_FILE="/ssl/$CERTFILE" - export SSL_CERT_KEY_FILE="/ssl/$KEYFILE" + #Replace variables + export SSL_CERT_FILE="/ssl/$CERTFILE" + export SSL_CERT_KEY_FILE="/ssl/$KEYFILE" - #Send env variables - export HTTPS=true - export SSL=true - export HTTPS_REDIRECT=true - BASE_URL_PORT=":$(bashio::addon.port 443)" - if [[ "$BASE_URL_PORT" == ":443" ]]; then BASE_URL_PORT=""; fi - BASE_URL_PROTO="https" + #Send env variables + export HTTPS=true + export SSL=true + export HTTPS_REDIRECT=true + BASE_URL_PORT=":$(bashio::addon.port 443)" + if [[ "$BASE_URL_PORT" == ":443" ]]; then BASE_URL_PORT=""; fi + BASE_URL_PROTO="https" - #Communication - bashio::log.info "Ssl enabled. If webui don't work, check if the port 443 was opened in the addon options, disable ssl or check your certificate paths" + #Communication + bashio::log.info "Ssl enabled. If webui don't work, check if the port 443 was opened in the addon options, disable ssl or check your certificate paths" else - export HTTPS=false - export SSL=false - export HTTPS_REDIRECT=false - BASE_URL_PORT=":$(bashio::addon.port 80)" - if [[ "$BASE_URL_PORT" == ":80" ]]; then BASE_URL_PORT=""; fi - BASE_URL_PROTO="http" + export HTTPS=false + export SSL=false + export HTTPS_REDIRECT=false + BASE_URL_PORT=":$(bashio::addon.port 80)" + if [[ "$BASE_URL_PORT" == ":80" ]]; then BASE_URL_PORT=""; fi + BASE_URL_PROTO="http" fi if [[ "$BASE_URL_PORT" == ":" ]]; then - bashio::log.fatal "Your $BASE_URL_PROTO port is not set in the addon options, please check your configuration and restart" - bashio::addon.stop + bashio::log.fatal "Your $BASE_URL_PROTO port is not set in the addon options, please check your configuration and restart" + bashio::addon.stop fi BASE_URL="${BASE_URL_PROTO}://${BASE_URL}${BASE_URL_PORT}" export BASE_URL # CLOUDFLARE if bashio::config.true "base_url_portless"; then - export BASE_URL=$(bashio::config 'BASE_URL') + export BASE_URL=$(bashio::config 'BASE_URL') fi # Correct base url if needed echo "... align base url with latest addon value" if [ -f "$DATA_LOCATION"/config.ini.php ]; then - echo "Aligning base_url addon config" - LINE=$(sed -n '/base_url/=' "$DATA_LOCATION"/config.ini.php) - sed -i "$LINE a base_url=\"$BASE_URL\"" "$DATA_LOCATION"/config.ini.php - sed -i "$LINE d" "$DATA_LOCATION"/config.ini.php + echo "Aligning base_url addon config" + LINE=$(sed -n '/base_url/=' "$DATA_LOCATION"/config.ini.php) + sed -i "$LINE a base_url=\"$BASE_URL\"" "$DATA_LOCATION"/config.ini.php + sed -i "$LINE d" "$DATA_LOCATION"/config.ini.php fi || true ############## @@ -140,13 +140,13 @@ bashio::log.info "Launching app, please wait" ################### if bashio::config.has_value "trusted_headers" && [ -f "$DATA_LOCATION"/config.ini.php ]; then - bashio::log.info "Aligning trusted_headers addon config (use single address, or a range of addresses in CIDR format)" - sed -i "/trusted_headers/ d" "$DATA_LOCATION"/config.ini.php - sed -i "1a trusted_headers=\"$(bashio::config 'trusted_headers')\"" "$DATA_LOCATION"/config.ini.php + bashio::log.info "Aligning trusted_headers addon config (use single address, or a range of addresses in CIDR format)" + sed -i "/trusted_headers/ d" "$DATA_LOCATION"/config.ini.php + sed -i "1a trusted_headers=\"$(bashio::config 'trusted_headers')\"" "$DATA_LOCATION"/config.ini.php elif [ -f "$DATA_LOCATION"/config.ini.php ]; then - bashio::log.info "Aligning trusted_headers addon config with cf-connecting-ip" - sed -i "/trusted_headers/ d" "$DATA_LOCATION"/config.ini.php - sed -i "1a trusted_headers=\"cf-connecting-ip\"" "$DATA_LOCATION"/config.ini.php + bashio::log.info "Aligning trusted_headers addon config with cf-connecting-ip" + sed -i "/trusted_headers/ d" "$DATA_LOCATION"/config.ini.php + sed -i "1a trusted_headers=\"cf-connecting-ip\"" "$DATA_LOCATION"/config.ini.php fi ############ diff --git a/webtrees/rootfs/etc/scripts/launcher.sh b/webtrees/rootfs/etc/scripts/launcher.sh index 82f625179..104ee9946 100755 --- a/webtrees/rootfs/etc/scripts/launcher.sh +++ b/webtrees/rootfs/etc/scripts/launcher.sh @@ -4,19 +4,19 @@ set -e bashio::log.green "---" if [ ! -f "%%data_location%%/config.ini.php" ]; then - bashio::log.info "First boot : open the UI at $BASE_URL to access the start-up wizard" - if bashio::services.available 'mysql'; then - bashio::log.info "MariaDB is available, if you want to use it please fill the values below" - bashio::log.blue "Host-name : $(bashio::services "mysql" "host")" - bashio::log.blue "Port : $(bashio::services "mysql" "port")" - bashio::log.blue "Database user : $(bashio::services "mysql" "username")" - bashio::log.blue "Database password : $(bashio::services "mysql" "password")" - bashio::log.blue "Database name : webtrees" - bashio::log.blue "Database prefix : wt_" - bashio::log.green "---" - else - bashio::log.info "As you don't have the MariaDB addon running, you should likely select sqlite as database, when the name webtrees" - fi + bashio::log.info "First boot : open the UI at $BASE_URL to access the start-up wizard" + if bashio::services.available 'mysql'; then + bashio::log.info "MariaDB is available, if you want to use it please fill the values below" + bashio::log.blue "Host-name : $(bashio::services "mysql" "host")" + bashio::log.blue "Port : $(bashio::services "mysql" "port")" + bashio::log.blue "Database user : $(bashio::services "mysql" "username")" + bashio::log.blue "Database password : $(bashio::services "mysql" "password")" + bashio::log.blue "Database name : webtrees" + bashio::log.blue "Database prefix : wt_" + bashio::log.green "---" + else + bashio::log.info "As you don't have the MariaDB addon running, you should likely select sqlite as database, when the name webtrees" + fi else - bashio::log.info "Webtrees started. You can access your webui at : %%base_url%%" + bashio::log.info "Webtrees started. You can access your webui at : %%base_url%%" fi diff --git a/wger/rootfs/etc/cont-init.d/90-run.sh b/wger/rootfs/etc/cont-init.d/90-run.sh index 9ba1ecaaa..0e46a0765 100755 --- a/wger/rootfs/etc/cont-init.d/90-run.sh +++ b/wger/rootfs/etc/cont-init.d/90-run.sh @@ -10,29 +10,33 @@ sed -i "s|/home/wger/db/database.sqlite|/data/database.sqlite|g" /home/wger/src/ ##################### mkdir -p /data/static if [ -d /home/wger/static ]; then - if [ -n "$(ls -A /home/wger/static 2>/dev/null)" ]; then - cp -rnf /home/wger/static/* /data/static/ - fi - rm -r /home/wger/static + if [ -n "$(ls -A /home/wger/static 2>/dev/null)" ]; then + cp -rnf /home/wger/static/* /data/static/ + fi + rm -r /home/wger/static fi ln -s /data/static /home/wger mkdir -p /data/media if [ -d /home/wger/media ]; then - if [ -n "$(ls -A /home/wger/media 2>/dev/null)" ]; then - cp -rnf /home/wger/media/* /data/media/ - fi - rm -r /home/wger/media + if [ -n "$(ls -A /home/wger/media 2>/dev/null)" ]; then + cp -rnf /home/wger/media/* /data/media/ + fi + rm -r /home/wger/media fi ln -s /data/media /home/wger ##################### # Align permissions # ##################### -(set -o posix; export -p) > /data/env.sh +( + set -o posix + export -p +) >/data/env.sh chown -R 1000:1000 /data chown -R 1000:1000 /home/wger chmod -R 777 /data bashio::log.info "Starting nginx" -nginx || true & true +nginx || true & +true diff --git a/whoogle/rootfs/etc/cont-init.d/32-nginx_ingress.sh b/whoogle/rootfs/etc/cont-init.d/32-nginx_ingress.sh index ff3d6774a..08a922f50 100755 --- a/whoogle/rootfs/etc/cont-init.d/32-nginx_ingress.sh +++ b/whoogle/rootfs/etc/cont-init.d/32-nginx_ingress.sh @@ -24,19 +24,19 @@ declare keyfile port=$(bashio::addon.port 80) if bashio::var.has_value "${port}"; then - bashio::config.require.ssl + bashio::config.require.ssl - if bashio::config.true 'ssl'; then - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') + if bashio::config.true 'ssl'; then + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') - mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf - sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf - sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf + mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf + sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf + sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf - else - mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf - fi + else + mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf + fi fi ingress_port="$(bashio::addon.ingress_port)" diff --git a/whoogle/rootfs/etc/cont-init.d/99-run.sh b/whoogle/rootfs/etc/cont-init.d/99-run.sh index 762e0594a..2de52d1c2 100755 --- a/whoogle/rootfs/etc/cont-init.d/99-run.sh +++ b/whoogle/rootfs/etc/cont-init.d/99-run.sh @@ -1,5 +1,7 @@ #!/bin/sh -exec misc/tor/start-tor.sh & ./run & echo "Starting NGinx..." +exec misc/tor/start-tor.sh & +./run & +echo "Starting NGinx..." exec nginx diff --git a/zoneminder/rootfs/etc/cont-init.d/00-folders.sh b/zoneminder/rootfs/etc/cont-init.d/00-folders.sh index f8c9cf508..86c743d17 100755 --- a/zoneminder/rootfs/etc/cont-init.d/00-folders.sh +++ b/zoneminder/rootfs/etc/cont-init.d/00-folders.sh @@ -8,9 +8,9 @@ CONFIGSOURCE="/config/addons_config/zoneminder" # Set image location if bashio::config.has_value "Images_location"; then - IMAGESOURCE=$(bashio::config "Images_location") + IMAGESOURCE=$(bashio::config "Images_location") else - IMAGESOURCE="$CONFIGSOURCE"/images + IMAGESOURCE="$CONFIGSOURCE"/images fi # Create directory diff --git a/zoneminder/rootfs/etc/cont-init.d/99-run.sh b/zoneminder/rootfs/etc/cont-init.d/99-run.sh index cbef743b7..67a3c676f 100755 --- a/zoneminder/rootfs/etc/cont-init.d/99-run.sh +++ b/zoneminder/rootfs/etc/cont-init.d/99-run.sh @@ -10,8 +10,8 @@ set -e CONFIGSOURCE="/config/addons_config/zoneminder" if [ ! -f "$CONFIGSOURCE"/zm.conf ]; then - # Copy conf files - cp /etc/zm/zm.conf "$CONFIGSOURCE" + # Copy conf files + cp /etc/zm/zm.conf "$CONFIGSOURCE" fi ################### @@ -21,57 +21,56 @@ fi bashio::log.info "Defining database" case "$(bashio::config "DB_CONNECTION")" in - # Use MariaDB - mariadb_addon) - bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..." - if ! bashio::services.available 'mysql'; then - bashio::log.fatal \ - "Local database access should be provided by the MariaDB addon" - bashio::exit.nok \ - "Please ensure it is installed and started" - fi +# Use MariaDB +mariadb_addon) + bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..." + if ! bashio::services.available 'mysql'; then + bashio::log.fatal \ + "Local database access should be provided by the MariaDB addon" + bashio::exit.nok \ + "Please ensure it is installed and started" + fi - # Use values - DB_CONNECTION=mysql - ZM_DB_HOST=$(bashio::services "mysql" "host") - ZM_DB_PORT=$(bashio::services "mysql" "port") - ZM_DB_NAME=firefly - ZM_DB_USER=$(bashio::services "mysql" "username") - ZM_DB_PASS=$(bashio::services "mysql" "password") - export DB_CONNECTION - export remoteDB=1 - export ZM_DB_HOST && bashio::log.blue "ZM_DB_HOST=$ZM_DB_HOST" - export ZM_DB_PORT && bashio::log.blue "ZM_DB_PORT=$ZM_DB_PORT" - export ZM_DB_NAME && bashio::log.blue "ZM_DB_NAME=$ZM_DB_NAME" - export ZM_DB_USER && bashio::log.blue "ZM_DB_USER=$ZM_DB_USER" - export ZM_DB_PASS && bashio::log.blue "ZM_DB_PASS=$ZM_DB_PASS" + # Use values + DB_CONNECTION=mysql + ZM_DB_HOST=$(bashio::services "mysql" "host") + ZM_DB_PORT=$(bashio::services "mysql" "port") + ZM_DB_NAME=firefly + ZM_DB_USER=$(bashio::services "mysql" "username") + ZM_DB_PASS=$(bashio::services "mysql" "password") + export DB_CONNECTION + export remoteDB=1 + export ZM_DB_HOST && bashio::log.blue "ZM_DB_HOST=$ZM_DB_HOST" + export ZM_DB_PORT && bashio::log.blue "ZM_DB_PORT=$ZM_DB_PORT" + export ZM_DB_NAME && bashio::log.blue "ZM_DB_NAME=$ZM_DB_NAME" + export ZM_DB_USER && bashio::log.blue "ZM_DB_USER=$ZM_DB_USER" + export ZM_DB_PASS && bashio::log.blue "ZM_DB_PASS=$ZM_DB_PASS" - bashio::log.warning "Firefly-iii is using the Maria DB addon" - bashio::log.warning "Please ensure this is included in your backups" - bashio::log.warning "Uninstalling the MariaDB addon will remove any data" + bashio::log.warning "Firefly-iii is using the Maria DB addon" + bashio::log.warning "Please ensure this is included in your backups" + bashio::log.warning "Uninstalling the MariaDB addon will remove any data" - bashio::log.info "Creating database for Firefly-iii if required" - mysql \ - -u "${ZM_DB_USER}" -p"${ZM_DB_PASS}" \ - -h "${ZM_DB_HOST}" -P "${ZM_DB_PORT}" \ - -e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;" - ;; + bashio::log.info "Creating database for Firefly-iii if required" + mysql \ + -u "${ZM_DB_USER}" -p"${ZM_DB_PASS}" \ + -h "${ZM_DB_HOST}" -P "${ZM_DB_PORT}" \ + -e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;" + ;; - # Use remote - external) - bashio::log.info "Using remote database. Requirement : filling all addon options fields, and making sure the database already exists" - for conditions in "ZM_DB_HOST" "ZM_DB_PORT" "ZM_DB_NAME" "ZM_DB_USER" "ZM_DB_PASS"; do - if ! bashio::config.has_value "$conditions"; then - bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options" - fi - done - ;; + # Use remote +external) + bashio::log.info "Using remote database. Requirement : filling all addon options fields, and making sure the database already exists" + for conditions in "ZM_DB_HOST" "ZM_DB_PORT" "ZM_DB_NAME" "ZM_DB_USER" "ZM_DB_PASS"; do + if ! bashio::config.has_value "$conditions"; then + bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options" + fi + done + ;; - - # Use remote - *) - bashio::log.info "Using internal database" - ;; + # Use remote +*) + bashio::log.info "Using internal database" + ;; esac diff --git a/zzz_archived_bitwarden/rootfs/etc/cont-init.d/nginx.sh b/zzz_archived_bitwarden/rootfs/etc/cont-init.d/nginx.sh index 0ce2350b6..386dc40c2 100755 --- a/zzz_archived_bitwarden/rootfs/etc/cont-init.d/nginx.sh +++ b/zzz_archived_bitwarden/rootfs/etc/cont-init.d/nginx.sh @@ -12,20 +12,20 @@ declare max_body_size bashio::config.require.ssl if bashio::config.true 'ssl'; then - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') - mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf - sed -i "s#%%certfile%%#${certfile}#g" /etc/nginx/servers/direct.conf - sed -i "s#%%keyfile%%#${keyfile}#g" /etc/nginx/servers/direct.conf + mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf + sed -i "s#%%certfile%%#${certfile}#g" /etc/nginx/servers/direct.conf + sed -i "s#%%keyfile%%#${keyfile}#g" /etc/nginx/servers/direct.conf else - mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf + mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf fi max_body_size="10M" # Increase body size to match config if bashio::config.has_value 'request_size_limit'; then - max_body_size=$(bashio::config 'request_size_limit') + max_body_size=$(bashio::config 'request_size_limit') fi sed -i "s/%%max_body_size%%/${max_body_size}/g" \ - /etc/nginx/includes/server_params.conf + /etc/nginx/includes/server_params.conf diff --git a/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/20-migration_config.sh b/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/20-migration_config.sh index 739e4f0ef..2387409bb 100755 --- a/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/20-migration_config.sh +++ b/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/20-migration_config.sh @@ -4,10 +4,10 @@ slug=paperless_ng if [ -d "/homeassistant/addons_config/$slug" ]; then - echo "Migrating /homeassistant/addons_config/$slug" - mv /homeassistant/addons_config/"$slug"/media /config/ || true - mv /homeassistant/addons_config/"$slug"/consume /config/ || true - mkdir -p /config/data - mv /homeassistant/addons_config/"$slug"/* /config/data/ || true - rm -r /homeassistant/addons_config/"$slug" + echo "Migrating /homeassistant/addons_config/$slug" + mv /homeassistant/addons_config/"$slug"/media /config/ || true + mv /homeassistant/addons_config/"$slug"/consume /config/ || true + mkdir -p /config/data + mv /homeassistant/addons_config/"$slug"/* /config/data/ || true + rm -r /homeassistant/addons_config/"$slug" fi diff --git a/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/31-nginx.sh b/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/31-nginx.sh index e2dc0cae1..8935c2054 100755 --- a/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/31-nginx.sh +++ b/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/31-nginx.sh @@ -2,23 +2,23 @@ # shellcheck shell=bash if bashio::config.true 'ssl'; then - # Validate ssl - bashio::config.require.ssl + # Validate ssl + bashio::config.require.ssl - # Adapt nginx template - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') - sed -i "s#%%certfile%%#${certfile}#g" /etc/nginx/servers/direct.conf - sed -i "s#%%keyfile%%#${keyfile}#g" /etc/nginx/servers/direct.conf + # Adapt nginx template + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') + sed -i "s#%%certfile%%#${certfile}#g" /etc/nginx/servers/direct.conf + sed -i "s#%%keyfile%%#${keyfile}#g" /etc/nginx/servers/direct.conf - # Configure URL - if bashio::config.has_value "PAPERLESS_URL"; then - bashio::log.warning "Ssl enabled, your site will be available at $(bashio::config "PAPERLESS_URL"). Don't forget to enable the https alternative port in the addon options." - else - bashio::log.fatal "PAPERLESS_URL not set, you won't be able to access your site (CSRF error)" - fi + # Configure URL + if bashio::config.has_value "PAPERLESS_URL"; then + bashio::log.warning "Ssl enabled, your site will be available at $(bashio::config "PAPERLESS_URL"). Don't forget to enable the https alternative port in the addon options." + else + bashio::log.fatal "PAPERLESS_URL not set, you won't be able to access your site (CSRF error)" + fi else - sed -i "s|default_server ssl|default_server|g" /etc/nginx/servers/direct.conf - sed -i "/ssl/d" /etc/nginx/servers/direct.conf + sed -i "s|default_server ssl|default_server|g" /etc/nginx/servers/direct.conf + sed -i "/ssl/d" /etc/nginx/servers/direct.conf fi diff --git a/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/99-run.sh b/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/99-run.sh index 91628f6eb..9a8dd5ea7 100755 --- a/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/99-run.sh +++ b/zzz_archived_paperless_ngx/rootfs/etc/cont-init.d/99-run.sh @@ -16,8 +16,8 @@ if bashio::config.has_value "PGID"; then export USERMAP_GID="$(bashio::config "P if bashio::config.has_value "TZ"; then export PAPERLESS_TIME_ZONE="$(bashio::config "TZ")"; fi if bashio::config.has_value "PAPERLESS_URL"; then export PAPERLESS_URL="$(bashio::config "PAPERLESS_URL")"; fi if bashio::config.has_value "OCRLANG"; then - PAPERLESS_OCR_LANGUAGES="$(bashio::config "OCRLANG")" - export PAPERLESS_OCR_LANGUAGES="${PAPERLESS_OCR_LANGUAGES,,}" + PAPERLESS_OCR_LANGUAGES="$(bashio::config "OCRLANG")" + export PAPERLESS_OCR_LANGUAGES="${PAPERLESS_OCR_LANGUAGES,,}" fi if bashio::config.has_value "PAPERLESS_OCR_MODE"; then export PAPERLESS_OCR_MODE="$(bashio::config "PAPERLESS_OCR_MODE")"; fi if bashio::config.has_value "PAPERLESS_DATA_DIR"; then export PAPERLESS_DATA_DIR="$(bashio::config "PAPERLESS_DATA_DIR")"; fi @@ -28,10 +28,10 @@ if bashio::config.has_value "PAPERLESS_EXPORT_DIR"; then export PAPERLESS_EXPORT # Create folder and permissions if needed chown -R paperless:paperless /config for variable in "$PAPERLESS_DATA_DIR" "$PAPERLESS_MEDIA_ROOT" "$PAPERLESS_CONSUMPTION_DIR" "$PAPERLESS_EXPORT_DIR"; do - echo "Creating directory \"$variable\"" - mkdir -p "$variable" - chmod -R 755 "$variable" - chown -R paperless:paperless "$variable" + echo "Creating directory \"$variable\"" + mkdir -p "$variable" + chmod -R 755 "$variable" + chown -R paperless:paperless "$variable" done ################### @@ -42,38 +42,37 @@ bashio::log.info "Defining database" case "$(bashio::config 'database')" in - # Use mariadb - mariadb_addon) - bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." - if ! bashio::services.available 'mysql'; then - bashio::log.fatal \ - "Local database access should be provided by the MariaDB addon" - bashio::exit.nok \ - "Please ensure it is installed and started" - fi +# Use mariadb +mariadb_addon) + bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Discovering values..." + if ! bashio::services.available 'mysql'; then + bashio::log.fatal \ + "Local database access should be provided by the MariaDB addon" + bashio::exit.nok \ + "Please ensure it is installed and started" + fi - # Use values - export PAPERLESS_DBENGINE=mariadb - export PAPERLESS_DBHOST="$(bashio::services 'mysql' 'host')" - export PAPERLESS_DBPORT="$(bashio::services 'mysql' 'port')" - export PAPERLESS_DBNAME=paperless - export PAPERLESS_DBUSER="$(bashio::services "mysql" "username")" - export PAPERLESS_DBPASS="$(bashio::services "mysql" "password")" + # Use values + export PAPERLESS_DBENGINE=mariadb + export PAPERLESS_DBHOST="$(bashio::services 'mysql' 'host')" + export PAPERLESS_DBPORT="$(bashio::services 'mysql' 'port')" + export PAPERLESS_DBNAME=paperless + export PAPERLESS_DBUSER="$(bashio::services "mysql" "username")" + export PAPERLESS_DBPASS="$(bashio::services "mysql" "password")" - # Create database - mysql --host="$PAPERLESS_DBHOST" --port="$PAPERLESS_DBPORT" --user="$PAPERLESS_DBUSER" --password="$PAPERLESS_DBPASS" -e"CREATE DATABASE IF NOT EXISTS $PAPERLESS_DBNAME;" + # Create database + mysql --host="$PAPERLESS_DBHOST" --port="$PAPERLESS_DBPORT" --user="$PAPERLESS_DBUSER" --password="$PAPERLESS_DBPASS" -e"CREATE DATABASE IF NOT EXISTS $PAPERLESS_DBNAME;" - # Informations - bashio::log.warning "This addon is using the Maria DB addon" - bashio::log.warning "Please ensure this is included in your backups" - bashio::log.warning "Uninstalling the MariaDB addon will remove any data" - ;; + # Informations + bashio::log.warning "This addon is using the Maria DB addon" + bashio::log.warning "Please ensure this is included in your backups" + bashio::log.warning "Uninstalling the MariaDB addon will remove any data" + ;; - - # Use sqlite - *) - bashio::log.info "Using sqlite as database driver" - ;; + # Use sqlite +*) + bashio::log.info "Using sqlite as database driver" + ;; esac set +u @@ -81,41 +80,43 @@ set +u # For all relevant variables for variable in PAPERLESS_DATA_DIR PAPERLESS_MEDIA_ROOT PAPERLESS_CONSUMPTION_DIR PAPERLESS_EXPORT_DIR USERMAP_UID USERMAP_GID PAPERLESS_TIME_ZONE PAPERLESS_URL PAPERLESS_OCR_LANGUAGES PAPERLESS_OCR_MODE PAPERLESS_ADMIN_PASSWORD PAPERLESS_ADMIN_USER PAPERLESS_DBENGINE PAPERLESS_DBHOST PAPERLESS_DBPORT PAPERLESS_DBNAME PAPERLESS_DBUSER PAPERLESS_DBPASS; do - # Skip if not defined - if [[ -z "$(eval echo "\$$variable")" ]]; then continue; fi + # Skip if not defined + if [[ -z "$(eval echo "\$$variable")" ]]; then continue; fi - # Variable content - variablecontent="$(eval echo "\$$variable")" - # Sanitize " ' ` in current variable - variablecontent="${variablecontent//[\"\'\`]/}" - #if [[ "$variablecontent" = *" "* ]] && [[ "$variable" != "PAPERLESS_OCR_LANGUAGES" ]]; then - # variablecontent="\"$variablecontent\"" - #fi - bashio::log.blue "$variable=\"$variablecontent\"" - # Add to entrypoint - sed -i "1a export $variable=\"$variablecontent\"" /sbin/docker-entrypoint.sh - # Export - export "$variable"="$variablecontent" - # Add to bashrc - eval echo "$variable=\"$variablecontent\"" >> ~/.bashrc - # set .env - echo "$variable=\"$variablecontent\"" >> /.env || true - # set /etc/environment - mkdir -p /etc - echo "$variable=\"$variablecontent\"" >> /etc/environment - # For s6 - if [ -d /var/run/s6/container_environment ]; then printf "%s" "${variablecontent}" > /var/run/s6/container_environment/"${variable}"; fi + # Variable content + variablecontent="$(eval echo "\$$variable")" + # Sanitize " ' ` in current variable + variablecontent="${variablecontent//[\"\'\`]/}" + #if [[ "$variablecontent" = *" "* ]] && [[ "$variable" != "PAPERLESS_OCR_LANGUAGES" ]]; then + # variablecontent="\"$variablecontent\"" + #fi + bashio::log.blue "$variable=\"$variablecontent\"" + # Add to entrypoint + sed -i "1a export $variable=\"$variablecontent\"" /sbin/docker-entrypoint.sh + # Export + export "$variable"="$variablecontent" + # Add to bashrc + eval echo "$variable=\"$variablecontent\"" >>~/.bashrc + # set .env + echo "$variable=\"$variablecontent\"" >>/.env || true + # set /etc/environment + mkdir -p /etc + echo "$variable=\"$variablecontent\"" >>/etc/environment + # For s6 + if [ -d /var/run/s6/container_environment ]; then printf "%s" "${variablecontent}" >/var/run/s6/container_environment/"${variable}"; fi done ################# # Staring redis # ################# -exec redis-server & bashio::log.info "Starting redis" +exec redis-server & +bashio::log.info "Starting redis" ################# # Staring nginx # ################# -exec nginx & bashio::log.info "Starting nginx" +exec nginx & +bashio::log.info "Starting nginx" ############### # Starting app # diff --git a/zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh b/zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh index 01a520bfe..f90f25ac9 100755 --- a/zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh +++ b/zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh @@ -7,44 +7,44 @@ echo "Starting..." #################### for SCRIPTS in /etc/cont-init.d/*; do - [ -e "$SCRIPTS" ] || continue - echo "$SCRIPTS: executing" + [ -e "$SCRIPTS" ] || continue + echo "$SCRIPTS: executing" - # Check if run as root - if test "$(id -u)" == 0 && test "$(id -u)" == 0; then - chown "$(id -u)":"$(id -g)" "$SCRIPTS" - chmod a+x "$SCRIPTS" - else - bashio::log.warning "Script executed with user $(id -u):$(id -g), things can break and chown won't work" - # Disable chown and chmod in scripts - sed -i "s/^chown /true # chown /g" "$SCRIPTS" - sed -i "s/ chown / true # chown /g" "$SCRIPTS" - sed -i "s/^chmod /true # chmod /g" "$SCRIPTS" - sed -i "s/ chmod / true # chmod /g" "$SCRIPTS" - fi + # Check if run as root + if test "$(id -u)" == 0 && test "$(id -u)" == 0; then + chown "$(id -u)":"$(id -g)" "$SCRIPTS" + chmod a+x "$SCRIPTS" + else + bashio::log.warning "Script executed with user $(id -u):$(id -g), things can break and chown won't work" + # Disable chown and chmod in scripts + sed -i "s/^chown /true # chown /g" "$SCRIPTS" + sed -i "s/ chown / true # chown /g" "$SCRIPTS" + sed -i "s/^chmod /true # chmod /g" "$SCRIPTS" + sed -i "s/ chmod / true # chmod /g" "$SCRIPTS" + fi - # Get current shebang, if not available use another - currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")" - if [ ! -f "${currentshebang%% *}" ]; then - for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done - sed -i "s|$currentshebang|$shebang|g" "$SCRIPTS" - fi + # Get current shebang, if not available use another + currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")" + if [ ! -f "${currentshebang%% *}" ]; then + for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done + sed -i "s|$currentshebang|$shebang|g" "$SCRIPTS" + fi - # Use source to share env variables when requested - if [ "${ha_entry_source:-null}" = true ] && command -v "source" &>/dev/null; then - # Exit cannot be used with source - sed -i "s/(.*\s|^)exit ([0-9]+)/\1 return \2 || exit \2/g" "$SCRIPTS" - sed -i "s/bashio::exit.nok/return 1/g" "$SCRIPTS" - sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS" - # shellcheck source=/dev/null - source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" - else - # Support for posix only shell - /."$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" - fi + # Use source to share env variables when requested + if [ "${ha_entry_source:-null}" = true ] && command -v "source" &>/dev/null; then + # Exit cannot be used with source + sed -i "s/(.*\s|^)exit ([0-9]+)/\1 return \2 || exit \2/g" "$SCRIPTS" + sed -i "s/bashio::exit.nok/return 1/g" "$SCRIPTS" + sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS" + # shellcheck source=/dev/null + source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" + else + # Support for posix only shell + /."$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" + fi - # Cleanup - rm "$SCRIPTS" + # Cleanup + rm "$SCRIPTS" done ###################### diff --git a/zzz_archived_plex_meta_manager/rootfs/etc/cont-init.d/20-configuration.sh b/zzz_archived_plex_meta_manager/rootfs/etc/cont-init.d/20-configuration.sh index 2a6304686..bcf12fa51 100755 --- a/zzz_archived_plex_meta_manager/rootfs/etc/cont-init.d/20-configuration.sh +++ b/zzz_archived_plex_meta_manager/rootfs/etc/cont-init.d/20-configuration.sh @@ -13,8 +13,8 @@ PUID=$(bashio::config 'PUID') PGID=$(bashio::config 'PGID') if [ ! -d "$(dirname "${CONFIGSOURCE}")" ]; then - echo "Creating $(dirname "${CONFIGSOURCE}")" - mkdir -p "$(dirname "${CONFIGSOURCE}")" + echo "Creating $(dirname "${CONFIGSOURCE}")" + mkdir -p "$(dirname "${CONFIGSOURCE}")" fi chown -R "$PUID":"$PGID" "$(dirname "${CONFIGSOURCE}")" @@ -25,8 +25,8 @@ chown -R "$PUID":"$PGID" "$(dirname "${CONFIGSOURCE}")" # Check if config file is there, or create one from template if [ -f "$CONFIGSOURCE" ]; then - bashio::log.info "Using config file found in $CONFIGSOURCE" + bashio::log.info "Using config file found in $CONFIGSOURCE" else - cp /templates/config.yml "$(dirname "${CONFIGSOURCE}")" - bashio::log.warning "No config file, creating one from template. Please correct the config.yml file before restarting the addon !" + cp /templates/config.yml "$(dirname "${CONFIGSOURCE}")" + bashio::log.warning "No config file, creating one from template. Please correct the config.yml file before restarting the addon !" fi