fix: auto-fix linting issues

This commit is contained in:
alexbelgium
2025-07-23 08:58:09 +00:00
committed by github-actions[bot]
parent 3539f328fb
commit f5428e0950
224 changed files with 5663 additions and 5662 deletions

View File

@@ -7,41 +7,41 @@ set -e
# Automatic modules download # # Automatic modules download #
############################## ##############################
if [ -e "/MODULESFILE" ]; then if [ -e "/MODULESFILE" ]; then
MODULES=$(</MODULESFILE) MODULES=$(< /MODULESFILE)
MODULES="${MODULES:-00-banner.sh}" MODULES="${MODULES:-00-banner.sh}"
echo "Executing modules script : $MODULES" echo "Executing modules script : $MODULES"
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 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 && && 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 && && 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 && && 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 && && 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 && chmod -R 755 /etc/cont-init.d
fi fi
####################### #######################
# Automatic installer # # Automatic installer #
####################### #######################
if [ -e "/ENVFILE" ]; then if [ -e "/ENVFILE" ]; then
PACKAGES=$(</ENVFILE) PACKAGES=$(< /ENVFILE)
echo "Executing dependency script with custom elements : $PACKAGES" echo "Executing dependency script with custom elements : $PACKAGES"
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 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 && && 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 && && 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 && && chmod 777 /ha_automatic_packages.sh \
eval /./ha_automatic_packages.sh "${PACKAGES:-}" && && eval /./ha_automatic_packages.sh "${PACKAGES:-}" \
rm /ha_automatic_packages.sh && rm /ha_automatic_packages.sh
fi fi
if [ -e "/MODULESFILE" ] && [ ! -f /ha_entrypoint.sh ]; then if [ -e "/MODULESFILE" ] && [ ! -f /ha_entrypoint.sh ]; then
for scripts in $MODULES; do for scripts in $MODULES; do
echo "$scripts : executing" echo "$scripts : executing"
chown "$(id -u)":"$(id -g)" /etc/cont-init.d/"$scripts" chown "$(id -u)":"$(id -g)" /etc/cont-init.d/"$scripts"
chmod a+x /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 $?" /./etc/cont-init.d/"$scripts" || echo "/etc/cont-init.d/$scripts: exiting $?"
rm /etc/cont-init.d/"$scripts" rm /etc/cont-init.d/"$scripts"
done | tac done | tac
fi fi
####################### #######################

View File

@@ -5,45 +5,45 @@ set -e
# Displays a simple add-on banner on startup # Displays a simple add-on banner on startup
# ============================================================================== # ==============================================================================
if ! bashio::supervisor.ping 2>/dev/null; then if ! bashio::supervisor.ping 2> /dev/null; then
# Degraded mode if no homeassistant # Degraded mode if no homeassistant
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
bashio::log.blue "Starting addon without HA support" bashio::log.blue "Starting addon without HA support"
bashio::log.blue "Version : ${BUILD_VERSION:-1.0}" bashio::log.blue "Version : ${BUILD_VERSION:-1.0}"
bashio::log.blue "Please use Docker Compose for env variables" bashio::log.blue "Please use Docker Compose for env variables"
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
# Use environment variables instead of addon options # Use environment variables instead of addon options
echo "... convert scripts to use environment variables instead of addon options" echo "... convert scripts to use environment variables instead of addon options"
while IFS= read -r scripts; do while IFS= read -r scripts; do
sed -i -e 's/bashio::config.has_value[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ]/g' \ 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.true[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ] \&\& [ "${\1:-}" = "true" ]/g' \
-e 's/\$(bashio::config[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"'])/${\1:-}/g' \ -e 's/\$(bashio::config[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"'])/${\1:-}/g' \
-e 's/\$(bashio::addon.port[[:space:]]*["'"'"']\([0-9]*\)["'"'"'])/${\1:-}/g' \ -e 's/\$(bashio::addon.port[[:space:]]*["'"'"']\([0-9]*\)["'"'"'])/${\1:-}/g' \
-e 's/bashio::config.require.ssl/true/g' \ -e 's/bashio::config.require.ssl/true/g' \
-e 's/\$(bashio::addon.ingress_port)/""/g' \ -e 's/\$(bashio::addon.ingress_port)/""/g' \
-e 's/\$(bashio::addon.ingress_entry)/""/g' \ -e 's/\$(bashio::addon.ingress_entry)/""/g' \
-e 's/\$(bashio::addon.ip_address)/""/g' "$scripts" -e 's/\$(bashio::addon.ip_address)/""/g' "$scripts"
done < <(grep -srl "bashio" /etc/cont-init.d /custom-services.d) done < <(grep -srl "bashio" /etc/cont-init.d /custom-services.d)
exit 0 exit 0
fi fi
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
bashio::log.blue " Add-on: $(bashio::addon.name)" bashio::log.blue " Add-on: $(bashio::addon.name)"
bashio::log.blue " $(bashio::addon.description)" bashio::log.blue " $(bashio::addon.description)"
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
bashio::log.blue " Add-on version: $(bashio::addon.version)" bashio::log.blue " Add-on version: $(bashio::addon.version)"
if bashio::var.true "$(bashio::addon.update_available)"; then if bashio::var.true "$(bashio::addon.update_available)"; then
bashio::log.magenta ' There is an update available for this add-on!' bashio::log.magenta ' There is an update available for this add-on!'
bashio::log.magenta \ bashio::log.magenta \
" Latest add-on version: $(bashio::addon.version_latest)" " Latest add-on version: $(bashio::addon.version_latest)"
bashio::log.magenta ' Please consider upgrading as soon as possible.' bashio::log.magenta ' Please consider upgrading as soon as possible.'
else 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 fi
bashio::log.blue " System: $(bashio::info.operating_system)" bashio::log.blue " System: $(bashio::info.operating_system)"
@@ -52,33 +52,33 @@ bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)" bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
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 \ bashio::log.blue \
' or support in, e.g., GitHub, forums' ' or support in, e.g., GitHub, forums'
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
bashio::log.green \ bashio::log.green \
' Provided by: https://github.com/alexbelgium/hassio-addons ' ' Provided by: https://github.com/alexbelgium/hassio-addons '
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
# ============================================================================== # ==============================================================================
# Global actions for all addons # Global actions for all addons
# ============================================================================== # ==============================================================================
if bashio::config.has_value "PUID" && bashio::config.has_value "PGID" && id abc &>/dev/null; then if bashio::config.has_value "PUID" && bashio::config.has_value "PGID" && id abc &> /dev/null; then
bashio::log.green ' Defining permissions for main user : ' bashio::log.green ' Defining permissions for main user : '
PUID="$(bashio::config "PUID")" PUID="$(bashio::config "PUID")"
PGID="$(bashio::config "PGID")" PGID="$(bashio::config "PGID")"
usermod -o -u "$PUID" abc usermod -o -u "$PUID" abc
groupmod -o -g "$PGID" abc groupmod -o -g "$PGID" abc
bashio::log.blue "User UID: $(id -u abc)" bashio::log.blue "User UID: $(id -u abc)"
bashio::log.blue "User GID: $(id -g abc)" bashio::log.blue "User GID: $(id -g abc)"
bashio::log.blue \ bashio::log.blue \
'-----------------------------------------------------------' '-----------------------------------------------------------'
fi fi
# Clean bashrc file safely # Clean bashrc file safely
if [ -f ~/.bashrc ]; then : >~/.bashrc; fi if [ -f ~/.bashrc ]; then : > ~/.bashrc; fi

View File

@@ -2,9 +2,9 @@
# shellcheck shell=bash # shellcheck shell=bash
set -e set -e
if ! bashio::supervisor.ping 2>/dev/null; then if ! bashio::supervisor.ping 2> /dev/null; then
echo "..." echo "..."
exit 0 exit 0
fi fi
################################### ###################################
@@ -16,11 +16,11 @@ JSONSOURCE="/data/options.json"
# Define secrets location # Define secrets location
if [ -f /homeassistant/secrets.yaml ]; then if [ -f /homeassistant/secrets.yaml ]; then
SECRETSOURCE="/homeassistant/secrets.yaml" SECRETSOURCE="/homeassistant/secrets.yaml"
elif [ -f /config/secrets.yaml ]; then elif [ -f /config/secrets.yaml ]; then
SECRETSOURCE="/config/secrets.yaml" SECRETSOURCE="/config/secrets.yaml"
else else
SECRETSOURCE="false" SECRETSOURCE="false"
fi fi
# Export keys as env variables # Export keys as env variables
@@ -29,89 +29,89 @@ mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
# Escape special characters using printf and enclose in double quotes # Escape special characters using printf and enclose in double quotes
sanitize_variable() { sanitize_variable() {
local raw="$1" # original value local raw="$1" # original value
local escaped # value after printf %q local escaped # value after printf %q
# Check if the value is an array # Check if the value is an array
if [[ "$raw" == \[* ]]; then if [[ "$raw" == \[* ]]; then
echo "One of your options is an array, skipping" echo "One of your options is an array, skipping"
return return
fi fi
printf -v escaped '%q' "$raw" printf -v escaped '%q' "$raw"
# If nothing changed, return the original. # If nothing changed, return the original.
if [[ "$raw" == "$escaped" ]]; then if [[ "$raw" == "$escaped" ]]; then
printf '%s' "$raw" printf '%s' "$raw"
return return
fi fi
# Otherwise protect the escaped string with double quotes. # Otherwise protect the escaped string with double quotes.
printf '"%s"' "$escaped" printf '"%s"' "$escaped"
} }
for KEYS in "${arr[@]}"; do for KEYS in "${arr[@]}"; do
# export key # export key
VALUE=$(jq -r --raw-output ".\"$KEYS\"" "$JSONSOURCE") VALUE=$(jq -r --raw-output ".\"$KEYS\"" "$JSONSOURCE")
# Check if the value is an array # Check if the value is an array
if [[ "$VALUE" == \[* ]]; then if [[ "$VALUE" == \[* ]]; then
bashio::log.warning "One of your option is an array, skipping" bashio::log.warning "One of your option is an array, skipping"
else else
# Sanitize variable # Sanitize variable
VALUE=$(sanitize_variable "$VALUE") VALUE=$(sanitize_variable "$VALUE")
# Continue for single values # Continue for single values
line="${KEYS}=${VALUE}" line="${KEYS}=${VALUE}"
# Check if secret # Check if secret
if [[ "${line}" == *"!secret "* ]]; then if [[ "${line}" == *"!secret "* ]]; then
echo "secret detected" echo "secret detected"
# Get argument # Get argument
secret=${line#*secret } secret=${line#*secret }
# Remove trailing ' or " # Remove trailing ' or "
secret="${secret%[\"\']}" secret="${secret%[\"\']}"
# Stop if secret file not mounted # Stop if secret file not mounted
if [[ "$SECRETSOURCE" == "false" ]]; then if [[ "$SECRETSOURCE" == "false" ]]; then
bashio::log.warning "Homeassistant config not mounted, secrets are not supported" bashio::log.warning "Homeassistant config not mounted, secrets are not supported"
continue continue
fi fi
# Check if single match # Check if single match
secretnum=$(sed -n "/$secret:/=" "$SECRETSOURCE") secretnum=$(sed -n "/$secret:/=" "$SECRETSOURCE")
[[ "$secretnum" == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file" [[ "$secretnum" == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
# Get text # Get text
secret=$(sed -n "/$secret:/p" "$SECRETSOURCE") secret=$(sed -n "/$secret:/p" "$SECRETSOURCE")
secret=${secret#*: } secret=${secret#*: }
line="${line%%=*}='$secret'" line="${line%%=*}='$secret'"
VALUE="$secret" VALUE="$secret"
fi fi
# text # text
if bashio::config.false "verbose" || [[ "${KEYS,,}" == *"pass"* ]]; then if bashio::config.false "verbose" || [[ "${KEYS,,}" == *"pass"* ]]; then
bashio::log.blue "${KEYS}=******" bashio::log.blue "${KEYS}=******"
else else
bashio::log.blue "$line" bashio::log.blue "$line"
fi fi
###################################### ######################################
# Export the variable to run scripts # # Export the variable to run scripts #
###################################### ######################################
# shellcheck disable=SC2163 # shellcheck disable=SC2163
export "$line" export "$line"
# export to python # export to python
if command -v "python3" &>/dev/null; then if command -v "python3" &> /dev/null; then
[ ! -f /env.py ] && echo "import os" >/env.py [ ! -f /env.py ] && echo "import os" > /env.py
# Escape \ # Escape \
VALUEPY="${VALUE//\\/\\\\}" VALUEPY="${VALUE//\\/\\\\}"
# Avoid " and ' # Avoid " and '
VALUEPY="${VALUEPY//[\"\']/}" VALUEPY="${VALUEPY//[\"\']/}"
echo "os.environ['${KEYS}'] = '$VALUEPY'" >>/env.py echo "os.environ['${KEYS}'] = '$VALUEPY'" >> /env.py
python3 /env.py python3 /env.py
fi fi
# set .env # set .env
echo "$line" >>/.env || true echo "$line" >> /.env || true
# set /etc/environment # set /etc/environment
mkdir -p /etc mkdir -p /etc
echo "$line" >>/etc/environment echo "$line" >> /etc/environment
# For non s6 # 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/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 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 # For s6
if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" > /var/run/s6/container_environment/"${KEYS}"; fi
echo "export ${KEYS}='${VALUE}'" >>~/.bashrc echo "export ${KEYS}='${VALUE}'" >> ~/.bashrc
fi fi
done done
################ ################
@@ -120,8 +120,8 @@ done
set +eu set +eu
if [ -n "$TZ" ] && [ -f /etc/localtime ]; then if [ -n "$TZ" ] && [ -f /etc/localtime ]; then
if [ -f /usr/share/zoneinfo/"$TZ" ]; then if [ -f /usr/share/zoneinfo/"$TZ" ]; then
echo "Timezone set from $(cat /etc/timezone) to $TZ" echo "Timezone set from $(cat /etc/timezone) to $TZ"
ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime && echo "$TZ" >/etc/timezone ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
fi fi
fi fi

View File

@@ -2,9 +2,9 @@
# shellcheck shell=bash # shellcheck shell=bash
set -e set -e
if ! bashio::supervisor.ping 2>/dev/null; then if ! bashio::supervisor.ping 2> /dev/null; then
echo "..." echo "..."
exit 0 exit 0
fi fi
###################### ######################
@@ -14,97 +14,97 @@ fi
# Mount local Share if configured # Mount local Share if configured
if bashio::config.has_value 'localdisks'; then if bashio::config.has_value 'localdisks'; then
# Available devices # Available devices
blkid | awk '{print substr($1, 0, length($1) - 1)}' | awk -F'/' '{print $NF}' >availabledisks blkid | awk '{print substr($1, 0, length($1) - 1)}' | awk -F'/' '{print $NF}' > availabledisks
echo "NAME" >>availabledisks echo "NAME" >> availabledisks
## List available Disk with Labels and Id ## List available Disk with Labels and Id
bashio::log.blue "---------------------------------------------------" bashio::log.blue "---------------------------------------------------"
bashio::log.info "Available Disks for mounting :" bashio::log.info "Available Disks for mounting :"
lsblk -o name,label,size,fstype,ro | awk '$4 != "" { print $0 }' | grep -f availabledisks lsblk -o name,label,size,fstype,ro | awk '$4 != "" { print $0 }' | grep -f availabledisks
bashio::log.blue "---------------------------------------------------" bashio::log.blue "---------------------------------------------------"
rm availabledisks 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 # 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 </proc/filesystems | awk '{$1=" "$1}1' | tr -d '\n\t') fstypessupport=$(grep -v nodev < /proc/filesystems | awk '{$1=" "$1}1' | tr -d '\n\t')
bashio::log.green "Supported fs : ${fstypessupport}" bashio::log.green "Supported fs : ${fstypessupport}"
bashio::log.green "Inspired from : github.com/dianlight" bashio::log.green "Inspired from : github.com/dianlight"
bashio::log.blue "---------------------------------------------------" bashio::log.blue "---------------------------------------------------"
MOREDISKS=$(bashio::config 'localdisks') MOREDISKS=$(bashio::config 'localdisks')
echo "Local Disks mounting..." echo "Local Disks mounting..."
# Separate comma separated values # Separate comma separated values
# shellcheck disable=SC2086 # shellcheck disable=SC2086
for disk in ${MOREDISKS//,/ }; do for disk in ${MOREDISKS//,/ }; do
# Remove text until last slash # Remove text until last slash
disk="${disk##*/}" disk="${disk##*/}"
# Function to check what is the type of device # Function to check what is the type of device
if [ -e /dev/"$disk" ]; then if [ -e /dev/"$disk" ]; then
echo "... $disk is a physical device" echo "... $disk is a physical device"
devpath=/dev devpath=/dev
elif [ -e /dev/disk/by-uuid/"$disk" ] || lsblk -o UUID | grep -q "$disk"; then elif [ -e /dev/disk/by-uuid/"$disk" ] || lsblk -o UUID | grep -q "$disk"; then
echo "... $disk is a device by UUID" echo "... $disk is a device by UUID"
devpath=/dev/disk/by-uuid devpath=/dev/disk/by-uuid
elif [ -e /dev/disk/by-label/"$disk" ] || lsblk -o LABEL | grep -q "$disk"; then elif [ -e /dev/disk/by-label/"$disk" ] || lsblk -o LABEL | grep -q "$disk"; then
echo "... $disk is a device by label" echo "... $disk is a device by label"
devpath=/dev/disk/by-label devpath=/dev/disk/by-label
else else
bashio::log.fatal "$disk does not match any known physical device, UUID, or label. " bashio::log.fatal "$disk does not match any known physical device, UUID, or label. "
continue continue
fi fi
# Creates dir # Creates dir
mkdir -p /mnt/"$disk" mkdir -p /mnt/"$disk"
if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then
PUID="$(bashio::config 'PUID')" PUID="$(bashio::config 'PUID')"
PGID="$(bashio::config 'PGID')" PGID="$(bashio::config 'PGID')"
chown "$PUID:$PGID" /mnt/"$disk" chown "$PUID:$PGID" /mnt/"$disk"
fi fi
# Check FS type and set relative options (thanks @https://github.com/dianlight/hassio-addons) # Check FS type and set relative options (thanks @https://github.com/dianlight/hassio-addons)
fstype=$(lsblk "$devpath"/"$disk" -no fstype) fstype=$(lsblk "$devpath"/"$disk" -no fstype)
options="nosuid,relatime,noexec" options="nosuid,relatime,noexec"
type="auto" type="auto"
# Check if supported # Check if supported
if [[ "${fstypessupport}" != *"${fstype}"* ]]; then if [[ "${fstypessupport}" != *"${fstype}"* ]]; then
bashio::log.fatal : "${fstype} type for ${disk} is not supported" bashio::log.fatal : "${fstype} type for ${disk} is not supported"
break break
fi fi
# Mount drive # Mount drive
bashio::log.info "Mounting ${disk} of type ${fstype}" bashio::log.info "Mounting ${disk} of type ${fstype}"
case "$fstype" in case "$fstype" in
exfat | vfat | msdos) exfat | vfat | msdos)
bashio::log.warning "${fstype} permissions and ACL don't works and this is an EXPERIMENTAL support" bashio::log.warning "${fstype} permissions and ACL don't works and this is an EXPERIMENTAL support"
options="${options},umask=000" options="${options},umask=000"
;; ;;
ntfs) ntfs)
bashio::log.warning "${fstype} is an EXPERIMENTAL support" bashio::log.warning "${fstype} is an EXPERIMENTAL support"
options="${options},umask=000" options="${options},umask=000"
type="ntfs" type="ntfs"
;; ;;
squashfs) squashfs)
bashio::log.warning "${fstype} is an EXPERIMENTAL support" bashio::log.warning "${fstype} is an EXPERIMENTAL support"
options="loop" options="loop"
type="squashfs" type="squashfs"
;; ;;
esac esac
# Legacy mounting : mount to share if still exists (avoid breaking changes) # Legacy mounting : mount to share if still exists (avoid breaking changes)
dirpath="/mnt" dirpath="/mnt"
if [ -d /share/"$disk" ]; then dirpath="/share"; fi if [ -d /share/"$disk" ]; then dirpath="/share"; fi
# shellcheck disable=SC2015 # shellcheck disable=SC2015
mount -t $type "$devpath"/"$disk" "$dirpath"/"$disk" -o $options && bashio::log.info "Success! $disk mounted to /mnt/$disk" || mount -t $type "$devpath"/"$disk" "$dirpath"/"$disk" -o $options && bashio::log.info "Success! $disk mounted to /mnt/$disk" \
( || (
bashio::log.fatal "Unable to mount local drives! Please check the name." bashio::log.fatal "Unable to mount local drives! Please check the name."
rmdir /mnt/"$disk" rmdir /mnt/"$disk"
bashio::addon.stop bashio::addon.stop
) )
done done
fi fi

View File

@@ -3,9 +3,9 @@
# shellcheck disable= # shellcheck disable=
set -e set -e
if ! bashio::supervisor.ping 2>/dev/null; then if ! bashio::supervisor.ping 2> /dev/null; then
bashio::log.blue "Disabled : please use another method" bashio::log.blue "Disabled : please use another method"
exit 0 exit 0
fi fi
#################### ####################
@@ -14,51 +14,51 @@ fi
test_mount() { test_mount() {
# Set initial test # Set initial test
MOUNTED=false MOUNTED=false
ERROR_MOUNT=false ERROR_MOUNT=false
# Exit if not mounted # Exit if not mounted
if ! mountpoint -q /mnt/"$diskname"; then if ! mountpoint -q /mnt/"$diskname"; then
return 0 return 0
fi fi
# Exit if can't write # Exit if can't write
[[ -e "/mnt/$diskname/testaze" ]] && rm -r "/mnt/$diskname/testaze" [[ -e "/mnt/$diskname/testaze" ]] && rm -r "/mnt/$diskname/testaze"
# shellcheck disable=SC2015 # shellcheck disable=SC2015
mkdir "/mnt/$diskname/testaze" && touch "/mnt/$diskname/testaze/testaze" && rm -r "/mnt/$diskname/testaze" || ERROR_MOUNT=true mkdir "/mnt/$diskname/testaze" && touch "/mnt/$diskname/testaze/testaze" && rm -r "/mnt/$diskname/testaze" || ERROR_MOUNT=true
if [[ "$ERROR_MOUNT" == "true" ]]; then if [[ "$ERROR_MOUNT" == "true" ]]; then
# Test write permissions # Test write permissions
if [[ "$MOUNTOPTIONS" == *"noserverino"* ]]; then 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" 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 else
MOUNTOPTIONS="$MOUNTOPTIONS,noserverino" MOUNTOPTIONS="$MOUNTOPTIONS,noserverino"
echo "... testing with noserverino" echo "... testing with noserverino"
mount_drive "$MOUNTOPTIONS" mount_drive "$MOUNTOPTIONS"
return 0 return 0
fi fi
fi fi
# Set correctly mounted bit # Set correctly mounted bit
MOUNTED=true MOUNTED=true
return 0 return 0
} }
mount_drive() { mount_drive() {
# Define options # Define options
MOUNTED=true MOUNTED=true
MOUNTOPTIONS="$1" MOUNTOPTIONS="$1"
# Try mounting # Try mounting
mount -t cifs -o "$MOUNTOPTIONS" "$disk" /mnt/"$diskname" 2>ERRORCODE || MOUNTED=false mount -t cifs -o "$MOUNTOPTIONS" "$disk" /mnt/"$diskname" 2> ERRORCODE || MOUNTED=false
# Test if succesful # Test if succesful
if [[ "$MOUNTED" == "true" ]]; then if [[ "$MOUNTED" == "true" ]]; then
# shellcheck disable=SC2015 # shellcheck disable=SC2015
test_mount test_mount
fi fi
} }
@@ -68,215 +68,215 @@ mount_drive() {
if bashio::config.has_value 'networkdisks'; then if bashio::config.has_value 'networkdisks'; then
# Alert message that it is a new code # Alert message that it is a new code
if [[ "$(date +"%Y%m%d")" -lt "20240201" ]]; then if [[ "$(date +"%Y%m%d")" -lt "20240201" ]]; then
bashio::log.warning "------------------------" 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 "This is a new code, please report any issues on https://github.com/alexbelgium/hassio-addons"
bashio::log.warning "------------------------" bashio::log.warning "------------------------"
fi fi
echo 'Mounting smb share(s)...' echo 'Mounting smb share(s)...'
#################### ####################
# Define variables # # Define variables #
#################### ####################
# Set variables # Set variables
MOREDISKS=$(bashio::config 'networkdisks') MOREDISKS=$(bashio::config 'networkdisks')
USERNAME=$(bashio::config 'cifsusername') USERNAME=$(bashio::config 'cifsusername')
PASSWORD=$(bashio::config 'cifspassword') PASSWORD=$(bashio::config 'cifspassword')
SMBVERS="" SMBVERS=""
SECVERS="" SECVERS=""
CHARSET=",iocharset=utf8" CHARSET=",iocharset=utf8"
# Clean data # Clean data
MOREDISKS=${MOREDISKS// \/\//,\/\/} MOREDISKS=${MOREDISKS// \/\//,\/\/}
MOREDISKS=${MOREDISKS//, /,} MOREDISKS=${MOREDISKS//, /,}
MOREDISKS=${MOREDISKS// /"\040"} MOREDISKS=${MOREDISKS// /"\040"}
# Is domain set # Is domain set
DOMAIN="" DOMAIN=""
DOMAINCLIENT="" DOMAINCLIENT=""
if bashio::config.has_value 'cifsdomain'; then if bashio::config.has_value 'cifsdomain'; then
echo "... using domain $(bashio::config 'cifsdomain')" echo "... using domain $(bashio::config 'cifsdomain')"
DOMAIN=",domain=$(bashio::config 'cifsdomain')" DOMAIN=",domain=$(bashio::config 'cifsdomain')"
DOMAINCLIENT="--workgroup=$(bashio::config 'cifsdomain')" DOMAINCLIENT="--workgroup=$(bashio::config 'cifsdomain')"
fi fi
# Is UID/GID set # Is UID/GID set
PUID=",uid=$(id -u)" PUID=",uid=$(id -u)"
PGID=",gid=$(id -g)" PGID=",gid=$(id -g)"
if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then
echo "... using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')" echo "... using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')"
PUID=",uid=$(bashio::config 'PUID')" PUID=",uid=$(bashio::config 'PUID')"
PGID=",gid=$(bashio::config 'PGID')" PGID=",gid=$(bashio::config 'PGID')"
fi fi
################## ##################
# Mounting disks # # Mounting disks #
################## ##################
# shellcheck disable=SC2086 # shellcheck disable=SC2086
for disk in ${MOREDISKS//,/ }; do # Separate comma separated values for disk in ${MOREDISKS//,/ }; do # Separate comma separated values
# Clean name of network share # Clean name of network share
# shellcheck disable=SC2116,SC2001 # shellcheck disable=SC2116,SC2001
disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name
disk="${disk//"\040"/ }" #replace \040 with disk="${disk//"\040"/ }" #replace \040 with
diskname="${disk//\\//}" #replace \ with / diskname="${disk//\\//}" #replace \ with /
diskname="${diskname##*/}" # Get only last part of the name diskname="${diskname##*/}" # Get only last part of the name
MOUNTED=false MOUNTED=false
# Start # Start
echo "... mounting $disk" echo "... mounting $disk"
# Data validation # Data validation
if [[ ! "$disk" =~ ^.*+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[/]+.*+$ ]]; then 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." 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 touch ERRORCODE
continue continue
fi fi
# Prepare mount point # Prepare mount point
mkdir -p /mnt/"$diskname" mkdir -p /mnt/"$diskname"
chown root:root /mnt/"$diskname" chown root:root /mnt/"$diskname"
# Quickly try to mount with defaults # 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}" mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
# Deeper analysis if failed # Deeper analysis if failed
if [ "$MOUNTED" = false ]; then if [ "$MOUNTED" = false ]; then
# Extract ip part of server for further manipulation # Extract ip part of server for further manipulation
server="$(echo "$disk" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")" server="$(echo "$disk" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")"
# Does server exists # Does server exists
output="$(nmap -F $server -T5 -oG -)" output="$(nmap -F $server -T5 -oG -)"
if ! echo "$output" | grep 445/open &>/dev/null; then if ! echo "$output" | grep 445/open &> /dev/null; then
if echo "$output" | grep /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" bashio::log.fatal "...... $server is reachable but SMB port not opened, stopping script"
touch ERRORCODE touch ERRORCODE
continue continue
else else
bashio::log.fatal "...... fatal : $server not reachable, is it correct" bashio::log.fatal "...... fatal : $server not reachable, is it correct"
touch ERRORCODE touch ERRORCODE
continue continue
fi fi
else else
echo "...... $server is confirmed reachable" echo "...... $server is confirmed reachable"
fi fi
# Are credentials correct # Are credentials correct
OUTPUT="$(smbclient -t 2 -L "$disk" -U "$USERNAME"%"$PASSWORD" -c "exit" $DOMAINCLIENT 2>&1 || true)" OUTPUT="$(smbclient -t 2 -L "$disk" -U "$USERNAME"%"$PASSWORD" -c "exit" $DOMAINCLIENT 2>&1 || true)"
if echo "$OUTPUT" | grep -q "LOGON_FAILURE"; then if echo "$OUTPUT" | grep -q "LOGON_FAILURE"; then
bashio::log.fatal "...... incorrect Username, Password, or Domain! Script will stop." bashio::log.fatal "...... incorrect Username, Password, or Domain! Script will stop."
touch ERRORCODE touch ERRORCODE
# Should there be a workgroup # Should there be a workgroup
if ! smbclient -t 2 -L $disk -N $DOMAINCLIENT -c "exit" &>/dev/null; then if ! smbclient -t 2 -L $disk -N $DOMAINCLIENT -c "exit" &> /dev/null; then
bashio::log.fatal "...... perhaps a workgroup must be specified" bashio::log.fatal "...... perhaps a workgroup must be specified"
touch ERRORCODE touch ERRORCODE
fi fi
continue continue
elif echo "$OUTPUT" | grep -q "tree connect failed" || echo "$OUTPUT" | grep -q "NT_STATUS_CONNECTION_DISCONNECTED"; then elif echo "$OUTPUT" | grep -q "tree connect failed" || echo "$OUTPUT" | grep -q "NT_STATUS_CONNECTION_DISCONNECTED"; then
echo "... testing path" echo "... testing path"
bashio::log.fatal "...... invalid or inaccessible SMB path. Script will stop." bashio::log.fatal "...... invalid or inaccessible SMB path. Script will stop."
touch ERRORCODE touch ERRORCODE
continue continue
elif ! echo "$OUTPUT" | grep -q "Disk"; then elif ! echo "$OUTPUT" | grep -q "Disk"; then
echo "... testing path" echo "... testing path"
bashio::log.fatal "...... no shares found. Invalid or inaccessible SMB path?" bashio::log.fatal "...... no shares found. Invalid or inaccessible SMB path?"
else else
echo "...... credentials are valid" echo "...... credentials are valid"
fi fi
# Extracting SMB versions and normalize output # Extracting SMB versions and normalize output
# shellcheck disable=SC2210,SC2094 # 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)" 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 : # Avoid :
SMBVERS="${SMBVERS/:/.}" SMBVERS="${SMBVERS/:/.}"
# Manage output # Manage output
if [ -n "$SMBVERS" ]; then if [ -n "$SMBVERS" ]; then
case $SMBVERS in case $SMBVERS in
"202" | "200" | "20") "202" | "200" | "20")
SMBVERS="2.0" SMBVERS="2.0"
;; ;;
21) 21)
SMBVERS="2.1" SMBVERS="2.1"
;; ;;
302) 302)
SMBVERS="3.02" SMBVERS="3.02"
;; ;;
311) 311)
SMBVERS="3.1.1" SMBVERS="3.1.1"
;; ;;
"3.1") "3.1")
echo "SMB 3.1 detected, converting to 3.0" echo "SMB 3.1 detected, converting to 3.0"
SMBVERS="3.0" SMBVERS="3.0"
;; ;;
esac esac
echo "...... SMB version detected : $SMBVERS" echo "...... SMB version detected : $SMBVERS"
SMBVERS=",vers=$SMBVERS" SMBVERS=",vers=$SMBVERS"
elif smbclient -t 2 -L "$server" -m NT1 -N $DOMAINCLIENT &>/dev/null; then 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" echo "...... SMB version : only SMBv1 is supported, this can lead to issues"
SECVERS=",sec=ntlm" SECVERS=",sec=ntlm"
SMBVERS=",vers=1.0" SMBVERS=",vers=1.0"
else else
echo "...... SMB version : couldn't detect, default used" echo "...... SMB version : couldn't detect, default used"
SMBVERS="" SMBVERS=""
fi fi
# Test with different security versions # Test with different security versions
####################################### #######################################
for SECVERS in "$SECVERS" ",sec=ntlmv2" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=krb5i" ",sec=krb5" ",sec=ntlm" ",sec=ntlmv2i"; do for SECVERS in "$SECVERS" ",sec=ntlmv2" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=krb5i" ",sec=krb5" ",sec=ntlm" ",sec=ntlmv2i"; do
if [ "$MOUNTED" = false ]; then if [ "$MOUNTED" = false ]; then
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}" mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
fi fi
done done
fi fi
# Messages # Messages
if [ "$MOUNTED" = true ]; then if [ "$MOUNTED" = true ]; then
bashio::log.info "...... $disk successfully mounted to /mnt/$diskname with options ${MOUNTOPTIONS/$PASSWORD/XXXXXXXXXX}" bashio::log.info "...... $disk successfully mounted to /mnt/$diskname with options ${MOUNTOPTIONS/$PASSWORD/XXXXXXXXXX}"
# Remove errorcode # Remove errorcode
if [ -f ERRORCODE ]; then if [ -f ERRORCODE ]; then
rm ERRORCODE rm ERRORCODE
fi fi
# Alert if smbv1 # Alert if smbv1
if [[ "$MOUNTOPTIONS" == *"1.0"* ]]; then if [[ "$MOUNTOPTIONS" == *"1.0"* ]]; then
bashio::log.warning "" 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 "Your smb system requires smbv1. This is an obsolete protocol. Please correct this to prevent issues."
bashio::log.warning "" bashio::log.warning ""
fi fi
else else
# Mounting failed messages # 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 "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 :" bashio::log.fatal "Here is some debugging info :"
# Provide debugging info # Provide debugging info
smbclient -t 2 -L $disk -U "$USERNAME%$PASSWORD" -c "exit" smbclient -t 2 -L $disk -U "$USERNAME%$PASSWORD" -c "exit"
# Error code # Error code
SMBVERS="" SMBVERS=""
SECVERS="" SECVERS=""
PUID="" PUID=""
PGID="" PGID=""
CHARSET="" CHARSET=""
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}" 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 : $(<ERRORCODE), addon will stop in 1 min" bashio::log.fatal "Error read : $(< ERRORCODE), addon will stop in 1 min"
# clean folder # clean folder
umount "/mnt/$diskname" 2>/dev/null || true umount "/mnt/$diskname" 2> /dev/null || true
rmdir "/mnt/$diskname" || true rmdir "/mnt/$diskname" || true
# Stop addon # Stop addon
bashio::addon.stop bashio::addon.stop
fi fi
done done
fi fi

View File

@@ -6,9 +6,9 @@
################## ##################
# Disable if config not present # Disable if config not present
if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then if [ ! -d /config ] || ! bashio::supervisor.ping 2> /dev/null; then
echo "..." echo "..."
exit 0 exit 0
fi fi
# Define slug # Define slug
@@ -17,13 +17,13 @@ slug="${slug#*_}"
# Check type of config folder # Check type of config folder
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
# New config location # New config location
CONFIGLOCATION="/config" CONFIGLOCATION="/config"
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml" CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml"
else else
# Legacy config location # Legacy config location
CONFIGLOCATION="/config/addons_config/${slug}" CONFIGLOCATION="/config/addons_config/${slug}"
CONFIGFILEBROWSER="/homeassistant/addons_config/$slug/config.yaml" CONFIGFILEBROWSER="/homeassistant/addons_config/$slug/config.yaml"
fi fi
# Default location # Default location
@@ -32,51 +32,51 @@ CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
# Is there a custom path # Is there a custom path
if bashio::config.has_value 'CONFIG_LOCATION'; then if bashio::config.has_value 'CONFIG_LOCATION'; then
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
if [[ "$CONFIGSOURCE" == *"."* ]]; then if [[ "$CONFIGSOURCE" == *"."* ]]; then
CONFIGSOURCE=$(dirname "$CONFIGSOURCE") CONFIGSOURCE=$(dirname "$CONFIGSOURCE")
fi fi
# If does not end by config.yaml, remove trailing slash and add config.yaml # If does not end by config.yaml, remove trailing slash and add config.yaml
if [[ "$CONFIGSOURCE" != *".yaml" ]]; then if [[ "$CONFIGSOURCE" != *".yaml" ]]; then
CONFIGSOURCE="${CONFIGSOURCE%/}"/config.yaml CONFIGSOURCE="${CONFIGSOURCE%/}"/config.yaml
fi fi
# Check if config is located in an acceptable location # Check if config is located in an acceptable location
LOCATIONOK="" LOCATIONOK=""
for location in "/share" "/config" "/data"; do for location in "/share" "/config" "/data"; do
if [[ "$CONFIGSOURCE" == "$location"* ]]; then if [[ "$CONFIGSOURCE" == "$location"* ]]; then
LOCATIONOK=true LOCATIONOK=true
fi fi
done done
if [ -z "$LOCATIONOK" ]; then 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" 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 CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
fi fi
fi fi
# Migrate if needed # Migrate if needed
if [[ "$CONFIGLOCATION" == "/config" ]]; then if [[ "$CONFIGLOCATION" == "/config" ]]; then
# Migrate file # Migrate file
if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then
echo "Migrating config.yaml to new config location" echo "Migrating config.yaml to new config location"
mv "/homeassistant/addons_config/${slug}/config.yaml" /config/config.yaml mv "/homeassistant/addons_config/${slug}/config.yaml" /config/config.yaml
fi fi
# Migrate option # Migrate option
if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then
bashio::addon.option "CONFIG_LOCATION" "/config/config.yaml" bashio::addon.option "CONFIG_LOCATION" "/config/config.yaml"
CONFIGSOURCE="/config/config.yaml" CONFIGSOURCE="/config/config.yaml"
fi fi
fi fi
if [[ "$CONFIGSOURCE" != *".yaml" ]]; then 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"
exit 1 exit 1
fi fi
# Permissions # Permissions
if [[ "$CONFIGSOURCE" == *".yaml" ]]; then if [[ "$CONFIGSOURCE" == *".yaml" ]]; then
echo "Setting permissions for the config.yaml directory" echo "Setting permissions for the config.yaml directory"
mkdir -p "$(dirname "${CONFIGSOURCE}")" mkdir -p "$(dirname "${CONFIGSOURCE}")"
chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2>/dev/null chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2> /dev/null
fi fi
#################### ####################
@@ -86,9 +86,9 @@ fi
echo "" echo ""
bashio::log.green "Load environment variables from $CONFIGSOURCE if existing" bashio::log.green "Load environment variables from $CONFIGSOURCE if existing"
if [[ "$CONFIGSOURCE" == "/config"* ]]; then 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 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 fi
bashio::log.green "---------------------------------------------------------" bashio::log.green "---------------------------------------------------------"
bashio::log.green "Wiki here on how to use: https://github.com/alexbelgium/hassio-addons/wiki/Addons-feature:-add-env-variables" bashio::log.green "Wiki here on how to use: https://github.com/alexbelgium/hassio-addons/wiki/Addons-feature:-add-env-variables"
@@ -96,18 +96,18 @@ echo ""
# Check if config file is there, or create one from template # Check if config file is there, or create one from template
if [ ! -f "$CONFIGSOURCE" ]; then if [ ! -f "$CONFIGSOURCE" ]; then
echo "... no config file, creating one from template. Please customize the file in $CONFIGSOURCE before restarting." echo "... no config file, creating one from template. Please customize the file in $CONFIGSOURCE before restarting."
# Create folder # Create folder
mkdir -p "$(dirname "${CONFIGSOURCE}")" mkdir -p "$(dirname "${CONFIGSOURCE}")"
# Placing template in config # Placing template in config
if [ -f /templates/config.yaml ]; then if [ -f /templates/config.yaml ]; then
# Use available template # Use available template
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")" cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"
else else
# Download template # Download template
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template" TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template"
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE"
fi fi
fi fi
# Check if there are lines to read # Check if there are lines to read
@@ -115,20 +115,20 @@ cp "$CONFIGSOURCE" /tempenv
sed -i '/^#/d' /tempenv sed -i '/^#/d' /tempenv
sed -i '/^[[:space:]]*$/d' /tempenv sed -i '/^[[:space:]]*$/d' /tempenv
sed -i '/^$/d' /tempenv sed -i '/^$/d' /tempenv
echo "" >>/tempenv echo "" >> /tempenv
# Exit if empty # Exit if empty
if [ ! -s /tempenv ]; then if [ ! -s /tempenv ]; then
bashio::log.green "... no env variables found, exiting" bashio::log.green "... no env variables found, exiting"
exit 0 exit 0
fi fi
# Check if yaml is valid # Check if yaml is valid
EXIT_CODE=0 EXIT_CODE=0
yamllint -d relaxed /tempenv &>ERROR || EXIT_CODE=$? yamllint -d relaxed /tempenv &> ERROR || EXIT_CODE=$?
if [ "$EXIT_CODE" != 0 ]; then if [ "$EXIT_CODE" != 0 ]; then
cat ERROR cat ERROR
bashio::log.yellow "... config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above." bashio::log.yellow "... config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above."
fi fi
# converts yaml to variables # converts yaml to variables
@@ -139,64 +139,64 @@ SECRETSFILE="/config/secrets.yaml"
if [ ! -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi if [ ! -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi
while IFS= read -r line; do while IFS= read -r line; do
# Skip empty lines # Skip empty lines
if [[ -z "$line" ]]; then if [[ -z "$line" ]]; then
continue continue
fi fi
# Check if secret # Check if secret
if [[ "$line" == *!secret* ]]; then if [[ "$line" == *!secret* ]]; then
echo "Secret detected" echo "Secret detected"
if [ ! -f "$SECRETSFILE" ]; then if [ ! -f "$SECRETSFILE" ]; then
bashio::log.fatal "Secrets file not found in $SECRETSFILE, $line skipped" bashio::log.fatal "Secrets file not found in $SECRETSFILE, $line skipped"
continue continue
fi fi
secret=$(echo "$line" | sed 's/.*!secret \(.*\)/\1/') secret=$(echo "$line" | sed 's/.*!secret \(.*\)/\1/')
# Check if single match # Check if single match
secretnum=$(sed -n "/$secret:/=" "$SECRETSFILE") secretnum=$(sed -n "/$secret:/=" "$SECRETSFILE")
if [[ $(echo "$secretnum" | grep -q ' ') ]]; then if [[ $(echo "$secretnum" | grep -q ' ') ]]; then
bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file" bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
fi fi
# Get text # Get text
secret_value=$(sed -n "/$secret:/s/.*: //p" "$SECRETSFILE") secret_value=$(sed -n "/$secret:/s/.*: //p" "$SECRETSFILE")
line="${line%%=*}='$secret_value'" line="${line%%=*}='$secret_value'"
fi fi
# Data validation # Data validation
if [[ "$line" =~ ^[^[:space:]]+.+[=].+$ ]]; then if [[ "$line" =~ ^[^[:space:]]+.+[=].+$ ]]; then
# extract keys and values # extract keys and values
KEYS="${line%%=*}" KEYS="${line%%=*}"
VALUE="${line#*=}" VALUE="${line#*=}"
# Check if VALUE is quoted # Check if VALUE is quoted
#if [[ "$VALUE" != \"*\" ]] && [[ "$VALUE" != \'*\' ]]; then #if [[ "$VALUE" != \"*\" ]] && [[ "$VALUE" != \'*\' ]]; then
# VALUE="\"$VALUE\"" # VALUE="\"$VALUE\""
#fi #fi
line="${KEYS}=${VALUE}" line="${KEYS}=${VALUE}"
export "$line" export "$line"
# export to python # export to python
if command -v "python3" &>/dev/null; then if command -v "python3" &> /dev/null; then
[ ! -f /env.py ] && echo "import os" >/env.py [ ! -f /env.py ] && echo "import os" > /env.py
# Escape single quotes in VALUE # Escape single quotes in VALUE
VALUE_ESCAPED="${VALUE//\'/\'\"\'\"\'}" VALUE_ESCAPED="${VALUE//\'/\'\"\'\"\'}"
echo "os.environ['${KEYS}'] = '${VALUE_ESCAPED}'" >>/env.py echo "os.environ['${KEYS}'] = '${VALUE_ESCAPED}'" >> /env.py
python3 /env.py python3 /env.py
fi fi
# set .env # set .env
echo "$line" >>/.env echo "$line" >> /.env
# set environment # set environment
mkdir -p /etc mkdir -p /etc
echo "$line" >>/etc/environment echo "$line" >> /etc/environment
# Export to scripts # 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/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 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 # For s6
if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" > /var/run/s6/container_environment/"${KEYS}"; fi
echo "export $line" >>~/.bashrc echo "export $line" >> ~/.bashrc
# Show in log # Show in log
if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi
else else
bashio::log.red "Skipping line that does not follow the correct structure: $line" bashio::log.red "Skipping line that does not follow the correct structure: $line"
fi fi
done <"/tempenv" done < "/tempenv"
rm /tempenv rm /tempenv

View File

@@ -7,9 +7,9 @@ set -e
################## ##################
# Exit if /config is not mounted or HA not used # Exit if /config is not mounted or HA not used
if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then if [ ! -d /config ] || ! bashio::supervisor.ping 2> /dev/null; then
echo "..." echo "..."
exit 0 exit 0
fi fi
# Define slug # Define slug
@@ -18,13 +18,13 @@ slug="${slug#*_}"
# Check type of config folder # Check type of config folder
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
# New config location # New config location
CONFIGLOCATION="/config" CONFIGLOCATION="/config"
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh" CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh"
else else
# Legacy config location # Legacy config location
CONFIGLOCATION="/config/addons_autoscripts" CONFIGLOCATION="/config/addons_autoscripts"
CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh" CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh"
fi fi
# Default location # Default location
@@ -36,31 +36,31 @@ bashio::log.green "Wiki here : github.com/alexbelgium/hassio-addons/wiki/Add-ons
# Download template if no script found and exit # Download template if no script found and exit
if [ ! -f "$CONFIGSOURCE" ]; then if [ ! -f "$CONFIGSOURCE" ]; then
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template" TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template"
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true
exit 0 exit 0
fi fi
# Convert scripts to linux # Convert scripts to linux
dos2unix "$CONFIGSOURCE" &>/dev/null || true dos2unix "$CONFIGSOURCE" &> /dev/null || true
chmod +x "$CONFIGSOURCE" chmod +x "$CONFIGSOURCE"
# Get current shebang, if not available use another # Get current shebang, if not available use another
currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$CONFIGSOURCE")" currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$CONFIGSOURCE")"
if [ ! -f "${currentshebang%% *}" ]; then 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 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" sed -i "s|$currentshebang|$shebang|g" "$CONFIGSOURCE"
fi fi
# Check if there is actual commands # Check if there is actual commands
while IFS= read -r line; do while IFS= read -r line; do
# Remove leading and trailing whitespaces # Remove leading and trailing whitespaces
line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Check if line is not empty and does not start with # # Check if line is not empty and does not start with #
if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then
bashio::log.green "... script found, executing" bashio::log.green "... script found, executing"
/."$CONFIGSOURCE" /."$CONFIGSOURCE"
break break
fi fi
done <"$CONFIGSOURCE" done < "$CONFIGSOURCE"

View File

@@ -8,39 +8,39 @@ JSONSOURCE='/defaults/settings.json'
# If json already exists # If json already exists
if [ -f "${JSONTOCHECK}" ]; then if [ -f "${JSONTOCHECK}" ]; then
# Variables # Variables
echo "Checking settings.json format" echo "Checking settings.json format"
# Check if json file valid or not # Check if json file valid or not
jq . -S "${JSONTOCHECK}" &>/dev/null && ERROR=false || ERROR=true jq . -S "${JSONTOCHECK}" &> /dev/null && ERROR=false || ERROR=true
if [ "$ERROR" = true ]; then 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" 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 mv "${JSONSOURCE}" "${JSONSOURCE}"_old
cp "${JSONSOURCE}" "${JSONTOCHECK}" cp "${JSONSOURCE}" "${JSONTOCHECK}"
exit 0 exit 0
fi fi
# Get the default keys from the original file # Get the default keys from the original file
mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
# Check if all keys are still there, or add them # Check if all keys are still there, or add them
# spellcheck disable=SC2068 # spellcheck disable=SC2068
for KEYS in "${arr[@]}"; do for KEYS in "${arr[@]}"; do
# Check if key exists # Check if key exists
KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}") KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}")
if [ "$KEYSTHERE" != "true" ]; then if [ "$KEYSTHERE" != "true" ]; then
#Fetch initial value #Fetch initial value
JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}") JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}")
#Add key #Add key
sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}" sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}"
# Message # Message
bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}" bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}"
fi fi
done done
# Show structure in a nice way # Show structure in a nice way
jq . -S "${JSONTOCHECK}" | cat >temp.json && mv temp.json "${JSONTOCHECK}" jq . -S "${JSONTOCHECK}" | cat > temp.json && mv temp.json "${JSONTOCHECK}"
# Message # Message
bashio::log.info "Your settings.json was checked and seems perfectly normal!" bashio::log.info "Your settings.json was checked and seems perfectly normal!"
fi fi

View File

@@ -6,17 +6,17 @@ set -e
# Disable Ingress # Disable Ingress
if bashio::config.true "ingress_disabled"; then 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 # Adapt ingress.conf
sed -i "/root/d" /etc/nginx/servers/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 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/i try_files '' /ingress.html =404;" /etc/nginx/servers/ingress.conf
sed -i "/proxy_pass/d" /etc/nginx/servers/ingress.conf sed -i "/proxy_pass/d" /etc/nginx/servers/ingress.conf
# Create index.html # Create index.html
touch /etc/ingress.html touch /etc/ingress.html
cat >/etc/ingress.html <<EOF cat > /etc/ingress.html << EOF
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>

View File

@@ -9,35 +9,35 @@ set -e
# Avoid usage of local dns such as adguard home or pihole\n" # Avoid usage of local dns such as adguard home or pihole\n"
if bashio::config.has_value 'DNS_server'; then if bashio::config.has_value 'DNS_server'; then
# Define variables # Define variables
DNSSERVER=$(bashio::config 'DNS_server') DNSSERVER=$(bashio::config 'DNS_server')
DNS="" DNS=""
DNSLIST="" DNSLIST=""
# Get DNS servers # Get DNS servers
# shellcheck disable=SC2086 # shellcheck disable=SC2086
for server in ${DNSSERVER//,/ }; do # Separate comma separated values for server in ${DNSSERVER//,/ }; do # Separate comma separated values
# Only add DNS if successful # Only add DNS if successful
if ping -c 1 "$server" &>/dev/null; then if ping -c 1 "$server" &> /dev/null; then
DNS="${DNS}nameserver $server\n" DNS="${DNS}nameserver $server\n"
DNSLIST="$server $DNSLIST" DNSLIST="$server $DNSLIST"
else else
bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used" bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used"
fi fi
done done
# Only add DNS if there are DNS set # Only add DNS if there are DNS set
# shellcheck disable=SC2236 # shellcheck disable=SC2236
if [[ -n "${DNS:-}" ]]; then if [[ -n "${DNS:-}" ]]; then
# Write resolv.conf # Write resolv.conf
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "${DNS}" >/etc/resolv.conf printf "${DNS}" > /etc/resolv.conf
chmod 644 /etc/resolv.conf chmod 644 /etc/resolv.conf
bashio::log.info "DNS SERVERS set to $DNSLIST" bashio::log.info "DNS SERVERS set to $DNSLIST"
else else
bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers." bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers."
fi fi
else 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 fi

View File

@@ -7,8 +7,8 @@ set -e
############### ###############
if bashio::config.true 'silent'; then if bashio::config.true 'silent'; then
APPEND=' > /dev/null' APPEND=' > /dev/null'
sed -i '$s|$|'"$APPEND"'|' /etc/services.d/*/run &>/dev/null || true sed -i '$s|$|'"$APPEND"'|' /etc/services.d/*/run &> /dev/null || true
sed -i '$s|$|'"$APPEND"'|' /etc/cont-init.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.' bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
fi fi

View File

@@ -3,170 +3,170 @@ set -e
if bashio::config.has_value "graphic_driver"; then if bashio::config.has_value "graphic_driver"; then
# Origin : https://github.com/wumingjieno1/photoprism-test/blob/main/scripts/dist/install-gpu.sh # Origin : https://github.com/wumingjieno1/photoprism-test/blob/main/scripts/dist/install-gpu.sh
# abort if not executed as root # abort if not executed as root
if [[ $(id -u) != "0" ]]; then if [[ $(id -u) != "0" ]]; then
# shellcheck disable=SC2128 # shellcheck disable=SC2128
bashio::log.fatal "Error: Run $(basename "${BASH_SOURCE}") as root" 1>&2 bashio::log.fatal "Error: Run $(basename "${BASH_SOURCE}") as root" 1>&2
exit 1 exit 1
fi fi
# Get installer type # Get installer type
if [ -f /usr/bin/apt ]; then if [ -f /usr/bin/apt ]; then
bashio::log.info "... Distribution detected : Debian/Ubuntu" bashio::log.info "... Distribution detected : Debian/Ubuntu"
apt-get install -yqq software-properties-common >/dev/null apt-get install -yqq software-properties-common > /dev/null
add-apt-repository ppa:kisak/kisak-mesa >/dev/null add-apt-repository ppa:kisak/kisak-mesa > /dev/null
apt-get update >/dev/null apt-get update > /dev/null
apt-get install -yqq mesa apt-get install -yqq mesa
elif [ -f /usr/bin/apk ]; then elif [ -f /usr/bin/apk ]; then
bashio::log.info "... Distribution detected : Alpine" bashio::log.info "... Distribution detected : Alpine"
fi fi
# Detect GPU # Detect GPU
# shellcheck disable=SC2207 # shellcheck disable=SC2207
GPU_DETECTED=($(lshw -c display -json 2>/dev/null | jq -r '.[].configuration.driver')) GPU_DETECTED=($(lshw -c display -json 2> /dev/null | jq -r '.[].configuration.driver'))
bashio::log.info "... GPU detected: ${GPU_DETECTED[*]}" bashio::log.info "... GPU detected: ${GPU_DETECTED[*]}"
graphic_driver="" graphic_driver=""
# Get arch type # Get arch type
BUILD_ARCH="$(uname -m)" BUILD_ARCH="$(uname -m)"
case "$BUILD_ARCH" in case "$BUILD_ARCH" in
amd64 | AMD64 | x86_64 | x86-64) amd64 | AMD64 | x86_64 | x86-64)
BUILD_ARCH=amd64 BUILD_ARCH=amd64
;; ;;
arm64 | ARM64 | aarch64) arm64 | ARM64 | aarch64)
BUILD_ARCH=arm64 BUILD_ARCH=arm64
graphic_driver=aarch64_rpi graphic_driver=aarch64_rpi
;; ;;
arm | ARM | aarch | armv7l | armhf) arm | ARM | aarch | armv7l | armhf)
bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2 bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2
exit 1 exit 1
;; ;;
*) *)
bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2 bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2
exit 1 exit 1
;; ;;
esac esac
bashio::log.info "... architecture detected: ${BUILD_ARCH}" bashio::log.info "... architecture detected: ${BUILD_ARCH}"
#graphic_driver="$(bashio::config "graphic_driver")" #graphic_driver="$(bashio::config "graphic_driver")"
case "$graphic_driver" in case "$graphic_driver" in
x64_AMD) x64_AMD)
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi 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/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" [ -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) x64_NVIDIA)
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi 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/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" [ -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) x64_Intel)
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi 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/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" [ -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) aarch64_rpi)
if [[ "$BUILD_ARCH" != arm64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi 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" 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/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" [ -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 # Main run logic
run_mods() { run_mods() {
echo "[mod-init] Attempting to run Docker Modification Logic" echo "[mod-init] Attempting to run Docker Modification Logic"
for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do
# Support alternative endpoints # Support alternative endpoints
if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then
DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}" DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}"
ENDPOINT="${DOCKER_MOD%%:*}" ENDPOINT="${DOCKER_MOD%%:*}"
USERNAME="${DOCKER_MOD%%/*}" USERNAME="${DOCKER_MOD%%/*}"
REPO="${ENDPOINT#*/}" REPO="${ENDPOINT#*/}"
TAG="${DOCKER_MOD#*:}" TAG="${DOCKER_MOD#*:}"
if [[ ${TAG} == "${DOCKER_MOD}" ]]; then if [[ ${TAG} == "${DOCKER_MOD}" ]]; then
TAG="latest" TAG="latest"
fi fi
FILENAME="${USERNAME}.${REPO}.${TAG}" FILENAME="${USERNAME}.${REPO}.${TAG}"
AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull" AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull"
MANIFEST_URL="https://ghcr.io/v2/${ENDPOINT}/manifests/${TAG}" MANIFEST_URL="https://ghcr.io/v2/${ENDPOINT}/manifests/${TAG}"
BLOB_URL="https://ghcr.io/v2/${ENDPOINT}/blobs/" BLOB_URL="https://ghcr.io/v2/${ENDPOINT}/blobs/"
MODE="ghcr" MODE="ghcr"
else else
ENDPOINT="${DOCKER_MOD%%:*}" ENDPOINT="${DOCKER_MOD%%:*}"
USERNAME="${DOCKER_MOD%%/*}" USERNAME="${DOCKER_MOD%%/*}"
REPO="${ENDPOINT#*/}" REPO="${ENDPOINT#*/}"
TAG="${DOCKER_MOD#*:}" TAG="${DOCKER_MOD#*:}"
if [[ ${TAG} == "${DOCKER_MOD}" ]]; then if [[ ${TAG} == "${DOCKER_MOD}" ]]; then
TAG="latest" TAG="latest"
fi fi
FILENAME="${USERNAME}.${REPO}.${TAG}" FILENAME="${USERNAME}.${REPO}.${TAG}"
AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull" 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}" MANIFEST_URL="https://registry-1.docker.io/v2/${ENDPOINT}/manifests/${TAG}"
BLOB_URL="https://registry-1.docker.io/v2/${ENDPOINT}/blobs/" BLOB_URL="https://registry-1.docker.io/v2/${ENDPOINT}/blobs/"
MODE="dockerhub" MODE="dockerhub"
fi fi
# Kill off modification logic if any of the usernames are banned # 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 for BANNED in $(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt); do
if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then
if [[ -z ${RUN_BANNED_MODS+x} ]]; then if [[ -z ${RUN_BANNED_MODS+x} ]]; then
echo "[mod-init] ${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic" echo "[mod-init] ${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic"
return return
else else
echo "[mod-init] You have chosen to run banned mods ${DOCKER_MOD} will be applied" echo "[mod-init] You have chosen to run banned mods ${DOCKER_MOD} will be applied"
fi fi
fi fi
done done
echo "[mod-init] Applying ${DOCKER_MOD} files to container" echo "[mod-init] Applying ${DOCKER_MOD} files to container"
# Get Dockerhub token for api operations # Get Dockerhub token for api operations
TOKEN="$( TOKEN="$(
curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ curl -f --retry 10 --retry-max-time 60 --retry-connrefused \
--silent \ --silent \
--header 'GET' \ --header 'GET' \
"${AUTH_URL}" | "${AUTH_URL}" \
jq -r '.token' | jq -r '.token'
)" )"
# Determine first and only layer of image # Determine first and only layer of image
SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}") SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}")
# Check if we have allready applied this layer # Check if we have allready applied this layer
if [[ -f "/${FILENAME}" ]] && [[ "${SHALAYER}" == "$(cat /"${FILENAME}")" ]]; then if [[ -f "/${FILENAME}" ]] && [[ "${SHALAYER}" == "$(cat /"${FILENAME}")" ]]; then
echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping" echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping"
else else
# Download and extract layer to / # Download and extract layer to /
curl -f --retry 10 --retry-max-time 60 --retry-connrefused \ curl -f --retry 10 --retry-max-time 60 --retry-connrefused \
--silent \ --silent \
--location \ --location \
--request GET \ --request GET \
--header "Authorization: Bearer ${TOKEN}" \ --header "Authorization: Bearer ${TOKEN}" \
"${BLOB_URL}${SHALAYER}" -o \ "${BLOB_URL}${SHALAYER}" -o \
/modtarball.tar.xz /modtarball.tar.xz
mkdir -p /tmp/mod mkdir -p /tmp/mod
tar xzf /modtarball.tar.xz -C /tmp/mod tar xzf /modtarball.tar.xz -C /tmp/mod
if [[ -d /tmp/mod/etc/s6-overlay ]]; then if [[ -d /tmp/mod/etc/s6-overlay ]]; then
if [[ -d /tmp/mod/etc/cont-init.d ]]; then if [[ -d /tmp/mod/etc/cont-init.d ]]; then
rm -rf /tmp/mod/etc/cont-init.d rm -rf /tmp/mod/etc/cont-init.d
fi fi
if [[ -d /tmp/mod/etc/services.d ]]; then if [[ -d /tmp/mod/etc/services.d ]]; then
rm -rf /tmp/mod/etc/services.d rm -rf /tmp/mod/etc/services.d
fi fi
fi fi
shopt -s dotglob shopt -s dotglob
cp -R /tmp/mod/* / cp -R /tmp/mod/* /
shopt -u dotglob shopt -u dotglob
rm -rf /tmp/mod rm -rf /tmp/mod
rm -rf /modtarball.tar.xz rm -rf /modtarball.tar.xz
echo "${SHALAYER}" >"/${FILENAME}" echo "${SHALAYER}" > "/${FILENAME}"
echo "[mod-init] ${DOCKER_MOD} applied to container" echo "[mod-init] ${DOCKER_MOD} applied to container"
fi fi
done done
} }
fi fi

View File

@@ -6,5 +6,5 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
CONFIGSOURCE="$(dirname "${CONFIGSOURCE}")" CONFIGSOURCE="$(dirname "${CONFIGSOURCE}")"
if [ -f "$CONFIGSOURCE"/script.sh ]; then if [ -f "$CONFIGSOURCE"/script.sh ]; then
"$CONFIGSOURCE"./script.sh "$CONFIGSOURCE"./script.sh
fi fi

View File

@@ -10,13 +10,13 @@ PACKAGES="$1"
echo "To install : $PACKAGES" echo "To install : $PACKAGES"
# Install bash if needed # Install bash if needed
if ! command -v bash >/dev/null 2>/dev/null; then 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 fi
# Install curl if needed # Install curl if needed
if ! command -v curl >/dev/null 2>/dev/null; then 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 fi
# Call apps installer script if needed # Call apps installer script if needed

View File

@@ -8,11 +8,11 @@ set -e
#Verbose or not #Verbose or not
VERBOSE=false VERBOSE=false
#Avoid fails on non declared variables #Avoid fails on non declared variables
set +u 2>/dev/null || true set +u 2> /dev/null || true
#If no packages, empty #If no packages, empty
PACKAGES="${*:-}" PACKAGES="${*:-}"
#Avoids messages if non interactive #Avoids messages if non interactive
(echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections) &>/dev/null || true (echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections) &> /dev/null || true
[ "$VERBOSE" = true ] && echo "ENV : $PACKAGES" [ "$VERBOSE" = true ] && echo "ENV : $PACKAGES"
@@ -20,18 +20,18 @@ PACKAGES="${*:-}"
# CHECK WHICH BASE IS USED # # CHECK WHICH BASE IS USED #
############################ ############################
if command -v "apk" &>/dev/null; then if command -v "apk" &> /dev/null; then
# If apk based # If apk based
[ "$VERBOSE" = true ] && echo "apk based" [ "$VERBOSE" = true ] && echo "apk based"
PACKMANAGER="apk" PACKMANAGER="apk"
elif command -v "apt" &>/dev/null; then elif command -v "apt" &> /dev/null; then
# If apt-get based # If apt-get based
[ "$VERBOSE" = true ] && echo "apt based" [ "$VERBOSE" = true ] && echo "apt based"
PACKMANAGER="apt" PACKMANAGER="apt"
elif command -v "pacman" &>/dev/null; then elif command -v "pacman" &> /dev/null; then
# If apt-get based # If apt-get based
[ "$VERBOSE" = true ] && echo "pacman based" [ "$VERBOSE" = true ] && echo "pacman based"
PACKMANAGER="pacman" PACKMANAGER="pacman"
fi fi
################### ###################
@@ -48,130 +48,130 @@ PACKAGES="$PACKAGES jq curl ca-certificates"
# Scripts # Scripts
for files in "/etc/cont-init.d" "/etc/services.d"; do for files in "/etc/cont-init.d" "/etc/services.d"; do
# Next directory if does not exists # Next directory if does not exists
if ! ls $files 1>/dev/null 2>&1; then continue; fi if ! ls $files 1> /dev/null 2>&1; then continue; fi
# Test each possible command # Test each possible command
COMMAND="nginx" COMMAND="nginx"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nginx" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nginx"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nginx" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nginx"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES nginx" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES nginx"
if ls /etc/nginx 1>/dev/null 2>&1; then mv /etc/nginx /etc/nginx2; fi if ls /etc/nginx 1> /dev/null 2>&1; then mv /etc/nginx /etc/nginx2; fi
fi fi
COMMAND="mount" COMMAND="mount"
if grep -q -rnw "$files/" -e "$COMMAND"; then if grep -q -rnw "$files/" -e "$COMMAND"; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES exfatprogs ntfs-3g ntfs-3g-progs squashfs-tools fuse lsblk" [ "$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" = "apt" ] && PACKAGES="$PACKAGES exfat* ntfs* squashfs-tools util-linux"
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES ntfs-3g" #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES ntfs-3g"
fi fi
COMMAND="ping" COMMAND="ping"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES iputils" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES iputils"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES iputils-ping" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES iputils-ping"
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils" #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils"
fi fi
COMMAND="nmap" COMMAND="nmap"
if grep -q -rnw "$files/" -e "$COMMAND"; then if grep -q -rnw "$files/" -e "$COMMAND"; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nmap nmap-scripts" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nmap nmap-scripts"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nmap" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nmap"
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils" #[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils"
fi fi
COMMAND="cifs" COMMAND="cifs"
if grep -q -rnw "$files/" -e "$COMMAND"; then if grep -q -rnw "$files/" -e "$COMMAND"; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES cifs-utils keyutils" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
fi fi
COMMAND="smbclient" COMMAND="smbclient"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES samba samba-client ntfs-3g" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES samba samba-client ntfs-3g"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES samba smbclient ntfs-3g" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES samba smbclient ntfs-3g"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES samba smbclient" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES samba smbclient"
fi fi
COMMAND="dos2unix" COMMAND="dos2unix"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES dos2unix" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES dos2unix"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES dos2unix" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES dos2unix"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES dos2unix" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES dos2unix"
fi fi
COMMAND="openvpn" COMMAND="openvpn"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES coreutils openvpn" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES coreutils openvpn"
fi fi
COMMAND="jq" COMMAND="jq"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES jq" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES jq"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES jq" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES jq"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES jq" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES jq"
fi fi
COMMAND="yamllint" COMMAND="yamllint"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES yamllint" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES yamllint"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES yamllint" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES yamllint"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES yamllint" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES yamllint"
fi fi
COMMAND="git" COMMAND="git"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES git" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES git"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES git" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES git"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES git" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES git"
fi fi
COMMAND="sponge" COMMAND="sponge"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES moreutils" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES moreutils"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES moreutils" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES moreutils"
[ "$PACKMANAGER" = "pacman " ] && PACKAGES="$PACKAGES moreutils" [ "$PACKMANAGER" = "pacman " ] && PACKAGES="$PACKAGES moreutils"
fi fi
COMMAND="sqlite3" COMMAND="sqlite3"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES sqlite" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES sqlite"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES sqlite3" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES sqlite3"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES sqlite3" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES sqlite3"
fi fi
COMMAND="pip" COMMAND="pip"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES py3-pip" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES py3-pip"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES pip" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES pip"
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES pip" [ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES pip"
fi fi
COMMAND="wget" COMMAND="wget"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES wget" [ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES wget"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES wget" [ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES wget"
[ "$PACKMANAGER" = "wget" ] && PACKAGES="$PACKAGES wget" [ "$PACKMANAGER" = "wget" ] && PACKAGES="$PACKAGES wget"
fi fi
done done
@@ -181,34 +181,34 @@ done
# Install apps # Install apps
[ "$VERBOSE" = true ] && echo "installing packages $PACKAGES" [ "$VERBOSE" = true ] && echo "installing packages $PACKAGES"
if [ "$PACKMANAGER" = "apt" ]; then apt-get update >/dev/null; fi if [ "$PACKMANAGER" = "apt" ]; then apt-get update > /dev/null; fi
if [ "$PACKMANAGER" = "pacman" ]; then pacman -Sy >/dev/null; fi if [ "$PACKMANAGER" = "pacman" ]; then pacman -Sy > /dev/null; fi
# Install apps one by one to allow failures # Install apps one by one to allow failures
# shellcheck disable=SC2086 # shellcheck disable=SC2086
for packagestoinstall in $PACKAGES; do for packagestoinstall in $PACKAGES; do
[ "$VERBOSE" = true ] && echo "... $packagestoinstall" [ "$VERBOSE" = true ] && echo "... $packagestoinstall"
if [ "$PACKMANAGER" = "apk" ]; then if [ "$PACKMANAGER" = "apk" ]; then
apk add --no-cache "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) apk add --no-cache "$packagestoinstall" &> /dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
elif [ "$PACKMANAGER" = "apt" ]; then elif [ "$PACKMANAGER" = "apt" ]; then
apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) apt-get install -yqq --no-install-recommends "$packagestoinstall" &> /dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
elif [ "$PACKMANAGER" = "pacman" ]; then elif [ "$PACKMANAGER" = "pacman" ]; then
pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR) pacman --noconfirm -S "$packagestoinstall" &> /dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
fi fi
[ "$VERBOSE" = true ] && echo "... $packagestoinstall done" [ "$VERBOSE" = true ] && echo "... $packagestoinstall done"
done done
# Clean after install # Clean after install
[ "$VERBOSE" = true ] && echo "Cleaning apt cache" [ "$VERBOSE" = true ] && echo "Cleaning apt cache"
if [ "$PACKMANAGER" = "apt" ]; then apt-get clean >/dev/null; fi if [ "$PACKMANAGER" = "apt" ]; then apt-get clean > /dev/null; fi
# Replace nginx if installed # Replace nginx if installed
if ls /etc/nginx2 1>/dev/null 2>&1; then if ls /etc/nginx2 1> /dev/null 2>&1; then
[ "$VERBOSE" = true ] && echo "replace nginx2" [ "$VERBOSE" = true ] && echo "replace nginx2"
rm -r /etc/nginx rm -r /etc/nginx
mv /etc/nginx2 /etc/nginx mv /etc/nginx2 /etc/nginx
mkdir -p /var/log/nginx mkdir -p /var/log/nginx
touch /var/log/nginx/error.log touch /var/log/nginx/error.log
fi fi
####################### #######################
@@ -223,53 +223,53 @@ micro -plugin install filemanager || true
for files in "/etc/services.d" "/etc/cont-init.d"; do for files in "/etc/services.d" "/etc/cont-init.d"; do
# Next directory if does not exists # Next directory if does not exists
if ! ls $files 1>/dev/null 2>&1; then continue; fi if ! ls $files 1> /dev/null 2>&1; then continue; fi
# Bashio # Bashio
if grep -q -rnw "$files/" -e 'bashio' && [ ! -f "/usr/bin/bashio" ]; then if grep -q -rnw "$files/" -e 'bashio' && [ ! -f "/usr/bin/bashio" ]; then
[ "$VERBOSE" = true ] && echo "install bashio" [ "$VERBOSE" = true ] && echo "install bashio"
BASHIO_VERSION="0.14.3" BASHIO_VERSION="0.14.3"
mkdir -p /tmp/bashio 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 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 mv /tmp/bashio/lib /usr/lib/bashio
ln -s /usr/lib/bashio/bashio /usr/bin/bashio ln -s /usr/lib/bashio/bashio /usr/bin/bashio
rm -rf /tmp/bashio rm -rf /tmp/bashio
fi fi
# Lastversion # Lastversion
COMMAND="lastversion" COMMAND="lastversion"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "install $COMMAND" [ "$VERBOSE" = true ] && echo "install $COMMAND"
pip install $COMMAND pip install $COMMAND
fi fi
# Tempio # Tempio
if grep -q -rnw "$files/" -e 'tempio' && [ ! -f "/usr/bin/tempio" ]; then if grep -q -rnw "$files/" -e 'tempio' && [ ! -f "/usr/bin/tempio" ]; then
[ "$VERBOSE" = true ] && echo "install tempio" [ "$VERBOSE" = true ] && echo "install tempio"
TEMPIO_VERSION="2021.09.0" TEMPIO_VERSION="2021.09.0"
BUILD_ARCH="$(bashio::info.arch)" 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}" 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 chmod a+x /usr/bin/tempio
fi fi
# Mustache # Mustache
COMMAND="mustache" COMMAND="mustache"
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
[ "$VERBOSE" = true ] && echo "$COMMAND required" [ "$VERBOSE" = true ] && echo "$COMMAND required"
[ "$PACKMANAGER" = "apk" ] && apk add --no-cache go npm && [ "$PACKMANAGER" = "apk" ] && apk add --no-cache go npm \
apk upgrade --no-cache && && apk upgrade --no-cache \
apk add --no-cache --virtual .build-deps build-base git go && && apk add --no-cache --virtual .build-deps build-base git go \
go get -u github.com/quantumew/mustache-cli && && go get -u github.com/quantumew/mustache-cli \
cp "$GOPATH"/bin/* /usr/bin/ && && cp "$GOPATH"/bin/* /usr/bin/ \
rm -rf "$GOPATH" /var/cache/apk/* /tmp/src && && rm -rf "$GOPATH" /var/cache/apk/* /tmp/src \
apk del .build-deps xz build-base && apk del .build-deps xz build-base
[ "$PACKMANAGER" = "apt" ] && apt-get update && [ "$PACKMANAGER" = "apt" ] && apt-get update \
apt-get install -yqq go npm node-mustache && apt-get install -yqq go npm node-mustache
fi fi
done done
if [ -f /ERROR ]; then if [ -f /ERROR ]; then
exit 1 exit 1
fi fi

View File

@@ -11,26 +11,26 @@ MODULES="$MODULES 00-banner.sh 01-custom_script.sh 01-config_yaml.sh 00-global_v
echo "To download : $MODULES" echo "To download : $MODULES"
# Install bash if not available # Install bash if not available
if ! command -v bash >/dev/null 2>/dev/null; then 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 fi
# Install curl if not available # Install curl if not available
if ! command -v curl >/dev/null 2>/dev/null; then 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 fi
# Install ca-certificates if not available # Install ca-certificates if not available
apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates >/dev/null || true apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates > /dev/null || true
# Create folder for scripts # Create folder for scripts
mkdir -p /etc/cont-init.d mkdir -p /etc/cont-init.d
# Download scripts # Download scripts
for scripts in $MODULES; do 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" && 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")" != "" ] || && [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] \
(echo "script failed to install $scripts" && exit 1) || (echo "script failed to install $scripts" && exit 1)
done done
chmod -R 755 /etc/cont-init.d chmod -R 755 /etc/cont-init.d

15
.templates/ha_entrypoint.sh Executable file → Normal file
View File

@@ -30,7 +30,7 @@ for SCRIPTS in /etc/cont-init.d/*; do
if [ ! -f "${currentshebang%% *}" ]; then 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 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%% *}" command_path="${shebang%% *}"
if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then if [ -x "$command_path" ] && "$command_path" echo "yes" > /dev/null 2>&1; then
echo "Valid shebang: $shebang" echo "Valid shebang: $shebang"
break break
fi fi
@@ -39,7 +39,7 @@ for SCRIPTS in /etc/cont-init.d/*; do
fi fi
# Use source to share env variables when requested # Use source to share env variables when requested
if [ "${ha_entry_source:-null}" = true ] && command -v "source" &>/dev/null; then 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/(.*\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.nok/return 1/g" "$SCRIPTS"
sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS" sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS"
@@ -61,7 +61,8 @@ for service_dir in /etc/services.d/*; do
# Replace s6-setuidgid with su-based equivalent # Replace s6-setuidgid with su-based equivalent
sed -i -E 's|^s6-setuidgid[[:space:]]+([a-zA-Z0-9._-]+)[[:space:]]+(.*)$|su -s /bin/bash \1 -c "\2"|g' "$runfile" sed -i -E 's|^s6-setuidgid[[:space:]]+([a-zA-Z0-9._-]+)[[:space:]]+(.*)$|su -s /bin/bash \1 -c "\2"|g' "$runfile"
chmod +x "$runfile" chmod +x "$runfile"
( exec "$runfile" ) & true (exec "$runfile") &
true
fi fi
done done
@@ -76,19 +77,19 @@ if [ "$$" -eq 1 ]; then
terminate() { terminate() {
echo "Termination signal received, forwarding to subprocesses..." echo "Termination signal received, forwarding to subprocesses..."
# Terminate all subprocesses # Terminate all subprocesses
if command -v pgrep &>/dev/null; then if command -v pgrep &> /dev/null; then
for pid in $(pgrep -P $$); do for pid in $(pgrep -P $$); do
echo "Terminating child PID $pid" echo "Terminating child PID $pid"
kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid" kill -TERM "$pid" 2> /dev/null || echo "Failed to terminate PID $pid"
done done
else else
# Fallback to iterating through /proc if pgrep is not available # Fallback to iterating through /proc if pgrep is not available
for pid in /proc/[0-9]*/; do for pid in /proc/[0-9]*/; do
pid=${pid#/proc/} pid=${pid#/proc/}
pid=${pid%/} pid=${pid%/}
if [[ "$pid" -ne 1 ]] && grep -q "^PPid:\s*$$" "/proc/$pid/status" 2>/dev/null; then if [[ "$pid" -ne 1 ]] && grep -q "^PPid:\s*$$" "/proc/$pid/status" 2> /dev/null; then
echo "Terminating child PID $pid" echo "Terminating child PID $pid"
kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid" kill -TERM "$pid" 2> /dev/null || echo "Failed to terminate PID $pid"
fi fi
done done
fi fi

View File

@@ -12,23 +12,23 @@ PUID="${PUID:-0}"
PGID="${PGID:-0}" PGID="${PGID:-0}"
if [ -f /ha_entrypoint.sh ]; then if [ -f /ha_entrypoint.sh ]; then
chown -R "$PUID:$PGID" /ha_entrypoint.sh chown -R "$PUID:$PGID" /ha_entrypoint.sh
chmod -R 755 /ha_entrypoint.sh chmod -R 755 /ha_entrypoint.sh
fi fi
if [ -d /etc/cont-init.d ]; then if [ -d /etc/cont-init.d ]; then
chown -R "$PUID:$PGID" /etc/cont-init.d chown -R "$PUID:$PGID" /etc/cont-init.d
chmod -R 755 /etc/cont-init.d chmod -R 755 /etc/cont-init.d
fi fi
if [ -d /etc/services.d ]; then if [ -d /etc/services.d ]; then
chown -R "$PUID:$PGID" /etc/services.d chown -R "$PUID:$PGID" /etc/services.d
chmod -R 755 /etc/services.d chmod -R 755 /etc/services.d
fi fi
if [ -d /etc/s6-rc.d ]; then if [ -d /etc/s6-rc.d ]; then
chown -R "$PUID:$PGID" /etc/s6-rc.d chown -R "$PUID:$PGID" /etc/s6-rc.d
chmod -R 755 /etc/s6-rc.d chmod -R 755 /etc/s6-rc.d
fi fi
# Correct shebang in entrypoint # Correct shebang in entrypoint
@@ -39,11 +39,11 @@ mkdir -p /run/s6/container_environment
# Check if shebang exists # 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 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%% *}" command_path="${shebang%% *}"
if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then if [ -x "$command_path" ] && "$command_path" echo "yes" > /dev/null 2>&1; then
echo "Valid shebang: $shebang" echo "Valid shebang: $shebang"
break break
fi fi
done done
# Define shebang # Define shebang
@@ -51,12 +51,12 @@ sed -i "s|/command/with-contenv bashio|$shebang|g" /ha_entrypoint.sh
# Correct for scripts # Correct for scripts
for string in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio"; do 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 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" sed -i "s|$string|$shebang|g" "$files"
done done
done done
# Avoid interference with LOG_LEVEL used in the app # Avoid interference with LOG_LEVEL used in the app
if [ -f /usr/lib/bashio/bashio.sh ]; then 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 fi

View File

@@ -12,48 +12,48 @@ echo "Setting config to $CONFIGLOCATION"
# Avoid custom-init.d duplications # 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 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 done
# If custom config # If custom config
if [ "$CONFIGLOCATION" != "/config" ]; then if [ "$CONFIGLOCATION" != "/config" ]; then
# Create new config folder if needed # Create new config folder if needed
for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do
sed -i "1a mkdir -p $CONFIGLOCATION" "$file" sed -i "1a mkdir -p $CONFIGLOCATION" "$file"
done done
# Correct config location # Correct config location
for file in $(grep -Esril "/config[ '\"/]|/config\$" /etc /defaults); do for file in $(grep -Esril "/config[ '\"/]|/config\$" /etc /defaults); do
sed -Ei "s=(/config)+(/| |$|\"|\')=$CONFIGLOCATION\2=g" "$file" sed -Ei "s=(/config)+(/| |$|\"|\')=$CONFIGLOCATION\2=g" "$file"
done done
fi fi
# Allow UID and GID setting # Allow UID and GID setting
for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do 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 '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 '1a PGID="$(if bashio::config.has_value "PGID"; then bashio::config "PGID"; else echo "0"; fi)"' "$file"
done done
# Avoid chmod /config if ha config mounted # Avoid chmod /config if ha config mounted
if [ -f /config/configuration.yaml ] || [ -f /config/configuration.json ]; then 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 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 if [ -f "$file" ] && [ -n "$(awk '/chown.*abc:abc.*\\/,/.*\/config( |$)/{print FILENAME}' "$file")" ]; then
sed -i "s|/config$|/data|g" "$file" sed -i "s|/config$|/data|g" "$file"
fi fi
done done
fi fi
# Send crond logs to addon logs # Send crond logs to addon logs
if [ -f /etc/s6-overlay/s6-rc.d/svc-cron/run ]; then 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 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 \/usr\/sbin\/cron/c exec /usr/sbin/cron -f &>/proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run
fi fi
# variables not found # variables not found
for file in $(grep -srl "/usr/bin" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do 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 done
# Allow running abc as user 1 # 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 # Replace lsiown if not found
if [ ! -f /usr/bin/lsiown ]; then if [ ! -f /usr/bin/lsiown ]; then
for file in $(grep -sril "lsiown" /etc); do for file in $(grep -sril "lsiown" /etc); do
sed -i "s|lsiown|chown|g" "$file" sed -i "s|lsiown|chown|g" "$file"
done done
fi fi

View File

@@ -9,7 +9,7 @@ set -e
bashio::log.info "Starting $(lastversion --version)" bashio::log.info "Starting $(lastversion --version)"
if bashio::config.true "dry_run"; then if bashio::config.true "dry_run"; then
bashio::log.warning "Dry run mode : on" bashio::log.warning "Dry run mode : on"
fi fi
bashio::log.info "Checking status of referenced repositoriess..." 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 [[ "$GITMAIL" != "null" ]]; then git config --system user.email "${GITMAIL}"; fi
if bashio::config.has_value 'gitapi'; then if bashio::config.has_value 'gitapi'; then
LOGINFO="... setting github API" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... setting github API" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
GITHUB_API_TOKEN=$(bashio::config 'gitapi') GITHUB_API_TOKEN=$(bashio::config 'gitapi')
export GITHUB_API_TOKEN export GITHUB_API_TOKEN
fi fi
#Create or update local version #Create or update local version
@@ -36,14 +36,14 @@ REPOSITORY=$(bashio::config 'repository')
BASENAME=$(basename "https://github.com/$REPOSITORY") BASENAME=$(basename "https://github.com/$REPOSITORY")
if [ ! -d "/data/$BASENAME" ]; then if [ ! -d "/data/$BASENAME" ]; then
LOGINFO="... cloning ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... cloning ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
cd /data/ || exit cd /data/ || exit
git clone "https://github.com/${REPOSITORY}" git clone "https://github.com/${REPOSITORY}"
else else
LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
cd "/data/$BASENAME" || exit cd "/data/$BASENAME" || exit
git pull --rebase origin >/dev/null || git reset --hard origin/master >/dev/null 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}") git pull --rebase origin > /dev/null || (rm -r "/data/$BASENAME" && git clone "https://github.com/${REPOSITORY}")
fi fi
LOGINFO="... parse addons" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... parse addons" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
@@ -53,282 +53,282 @@ LOGINFO="... parse addons" && if [ "$VERBOSE" = true ]; then bashio::log.info "$
cd /data/"$BASENAME" || exit cd /data/"$BASENAME" || exit
for f in */; do for f in */; do
if [ -f /data/"$BASENAME"/"$f"/updater.json ]; then if [ -f /data/"$BASENAME"/"$f"/updater.json ]; then
SLUG=${f//\//} SLUG=${f//\//}
# Rebase # Rebase
LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
cd "/data/$BASENAME" || exit cd "/data/$BASENAME" || exit
git pull --rebase &>/dev/null || git reset --hard &>/dev/null git pull --rebase &> /dev/null || git reset --hard &> /dev/null
git pull --rebase &>/dev/null git pull --rebase &> /dev/null
#Define the folder addon #Define the folder addon
LOGINFO="... $SLUG : checking slug exists in repo" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : checking slug exists in repo" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
cd /data/"${BASENAME}"/"${SLUG}" || { cd /data/"${BASENAME}"/"${SLUG}" || {
bashio::log.error "$SLUG addon not found in this repository. Exiting." bashio::log.error "$SLUG addon not found in this repository. Exiting."
continue continue
} }
# Get variables # Get variables
UPSTREAM=$(jq -r .upstream_repo updater.json) UPSTREAM=$(jq -r .upstream_repo updater.json)
BETA=$(jq -r .github_beta updater.json) BETA=$(jq -r .github_beta updater.json)
FULLTAG=$(jq -r .github_fulltag updater.json) FULLTAG=$(jq -r .github_fulltag updater.json)
HAVINGASSET=$(jq -r .github_havingasset updater.json) HAVINGASSET=$(jq -r .github_havingasset updater.json)
SOURCE=$(jq -r .source updater.json) SOURCE=$(jq -r .source updater.json)
FILTER_TEXT=$(jq -r .github_tagfilter updater.json) FILTER_TEXT=$(jq -r .github_tagfilter updater.json)
EXCLUDE_TEXT=$(jq -r .github_exclude updater.json) EXCLUDE_TEXT=$(jq -r .github_exclude updater.json)
EXCLUDE_TEXT="${EXCLUDE_TEXT:-zzzzzzzzzzzzzzzz}" EXCLUDE_TEXT="${EXCLUDE_TEXT:-zzzzzzzzzzzzzzzz}"
PAUSED=$(jq -r .paused updater.json) PAUSED=$(jq -r .paused updater.json)
DATE="$(date '+%d-%m-%Y')" DATE="$(date '+%d-%m-%Y')"
BYDATE=$(jq -r .dockerhub_by_date updater.json) BYDATE=$(jq -r .dockerhub_by_date updater.json)
# Number of elements to check in dockerhub # Number of elements to check in dockerhub
if grep -q "dockerhub_list_size" updater.json; then if grep -q "dockerhub_list_size" updater.json; then
LISTSIZE=$(jq -r .dockerhub_list_size updater.json) LISTSIZE=$(jq -r .dockerhub_list_size updater.json)
else else
LISTSIZE=100 LISTSIZE=100
fi fi
#Skip if paused #Skip if paused
if [[ "$PAUSED" = true ]]; then if [[ "$PAUSED" = true ]]; then
bashio::log.magenta "... $SLUG addon updates are paused, skipping" bashio::log.magenta "... $SLUG addon updates are paused, skipping"
continue continue
fi fi
#Find current version #Find current version
LOGINFO="... $SLUG : get current version" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : get current version" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
CURRENT=$(jq .upstream_version updater.json) || CURRENT=$(jq .upstream_version updater.json) \
{ || {
bashio::log.error "$SLUG addon upstream tag not found in updater.json. Exiting." bashio::log.error "$SLUG addon upstream tag not found in updater.json. Exiting."
continue continue
} }
if [[ "$SOURCE" = dockerhub ]]; then if [[ "$SOURCE" = dockerhub ]]; then
# Use dockerhub as upstream # Use dockerhub as upstream
# shellcheck disable=SC2116 # shellcheck disable=SC2116
LOGINFO="... Source is dockerhub" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... Source is dockerhub" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
#Prepare tag flag #Prepare tag flag
if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then
FILTER_TEXT="" FILTER_TEXT=""
else else
LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
FILTER_TEXT="&name=$FILTER_TEXT" FILTER_TEXT="&name=$FILTER_TEXT"
fi fi
#Prepare tag flag #Prepare tag flag
if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then
EXCLUDE_TEXT="zzzzzzzzzzzzzzzzzz" EXCLUDE_TEXT="zzzzzzzzzzzzzzzzzz"
fi fi
DOCKERHUB_REPO="${UPSTREAM%%/*}" DOCKERHUB_REPO="${UPSTREAM%%/*}"
DOCKERHUB_IMAGE=$(echo "$UPSTREAM" | cut -d "/" -f2) DOCKERHUB_IMAGE=$(echo "$UPSTREAM" | cut -d "/" -f2)
LASTVERSION=$( LASTVERSION=$(
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" | 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 | | jq '.results | .[] | .name' -r \
sed -e '/.*latest.*/d' | | sed -e '/.*latest.*/d' \
sed -e '/.*dev.*/d' | | sed -e '/.*dev.*/d' \
sed -e '/.*nightly.*/d' | | sed -e '/.*nightly.*/d' \
sed -e '/.*beta.*/d' | | sed -e '/.*beta.*/d' \
sed -e "/.*$EXCLUDE_TEXT.*/d" | | sed -e "/.*$EXCLUDE_TEXT.*/d" \
sort -V | | sort -V \
tail -n 1 | tail -n 1
) )
[ "${BETA}" = true ] && [ "${BETA}" = true ] \
LASTVERSION=$( && LASTVERSION=$(
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" | 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 | | jq '.results | .[] | .name' -r \
sed -e '/.*latest.*/d' | | sed -e '/.*latest.*/d' \
sed -e '/.*dev.*/!d' | | sed -e '/.*dev.*/!d' \
sed -e "/.*$EXCLUDE_TEXT.*/d" | | sed -e "/.*$EXCLUDE_TEXT.*/d" \
sort -V | | sort -V \
tail -n 1 | tail -n 1
) )
[ "${BYDATE}" = true ] && [ "${BYDATE}" = true ] \
LASTVERSION=$( && 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" | 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 | | jq '.results | .[] | .name' -r \
sed -e '/.*latest.*/d' | | sed -e '/.*latest.*/d' \
sed -e '/.*dev.*/d' | | sed -e '/.*dev.*/d' \
sed -e '/.*nightly.*/d' | | sed -e '/.*nightly.*/d' \
sed -e "/.*$EXCLUDE_TEXT.*/d" | | sed -e "/.*$EXCLUDE_TEXT.*/d" \
sort -V | | sort -V \
tail -n 1 | tail -n 1
) && ) \
DATE=$( && 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" | 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" | jq '.results[] | select(.name==$LASTVERSION) | .last_updated' -r --arg LASTVERSION "$LASTVERSION"
) && ) \
DATE="${DATE%T*}" && && DATE="${DATE%T*}" \
LASTVERSION="$LASTVERSION-$DATE" && LASTVERSION="$LASTVERSION-$DATE"
LOGINFO="... $SLUG : bydate is true, version is $LASTVERSION" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : bydate is true, version is $LASTVERSION" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
else else
# Use source as upstream # Use source as upstream
ARGUMENTS="--at $SOURCE" ARGUMENTS="--at $SOURCE"
LOGINFO="... $SLUG : source is $SOURCE" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : source is $SOURCE" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
#Prepare tag flag #Prepare tag flag
if [ "${FULLTAG}" = true ]; then if [ "${FULLTAG}" = true ]; then
LOGINFO="... $SLUG : github_fulltag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : github_fulltag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
ARGUMENTS="$ARGUMENTS --format tag" ARGUMENTS="$ARGUMENTS --format tag"
else else
LOGINFO="... $SLUG : github_fulltag is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : github_fulltag is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
fi fi
#Prepare tag flag #Prepare tag flag
if [ "${HAVINGASSET}" = true ]; then if [ "${HAVINGASSET}" = true ]; then
LOGINFO="... $SLUG : asset_only tag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : asset_only tag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
ARGUMENTS="$ARGUMENTS --having-asset" ARGUMENTS="$ARGUMENTS --having-asset"
else else
LOGINFO="... $SLUG : asset_only is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : asset_only is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
fi fi
#Prepare tag flag #Prepare tag flag
if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then
FILTER_TEXT="" FILTER_TEXT=""
else else
LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
ARGUMENTS="$ARGUMENTS --only $FILTER_TEXT" ARGUMENTS="$ARGUMENTS --only $FILTER_TEXT"
fi fi
#Prepare tag flag #Prepare tag flag
if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then
EXCLUDE_TEXT="" EXCLUDE_TEXT=""
else else
LOGINFO="... $SLUG : github_exclude is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : github_exclude is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
ARGUMENTS="$ARGUMENTS --exclude $EXCLUDE_TEXT" ARGUMENTS="$ARGUMENTS --exclude $EXCLUDE_TEXT"
fi fi
#If beta flag, select beta version #If beta flag, select beta version
if [ "${BETA}" = true ]; then if [ "${BETA}" = true ]; then
LOGINFO="... $SLUG : beta is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : beta is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
ARGUMENTS="$ARGUMENTS --pre" ARGUMENTS="$ARGUMENTS --pre"
else else
LOGINFO="... $SLUG : beta is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi 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 # If failure, checks if there is packages that could be used
function test_packages() { function test_packages() {
if [ "$VERBOSE" = true ]; then if [ "$VERBOSE" = true ]; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
bashio::log.info "source : $SOURCE and LASTVERSION : $(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" bashio::log.info "source : $SOURCE and LASTVERSION : $(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)"
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
if [[ "$SOURCE" == *"github"* ]] && [[ "$(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" == *"No release"* ]]; then if [[ "$SOURCE" == *"github"* ]] && [[ "$(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" == *"No release"* ]]; then
# Is there a package # Is there a package
bashio::log.warning "No version found, looking if packages available" 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_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 last_package="$(echo "$last_packages" | head -n 1)" || true
if [[ "$(echo -n "$last_packages" | grep -c '^')" -gt 0 ]]; then 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" bashio::log.warning "A total of $(echo -n "$last_packages" | grep -c '^') packages were found, using $last_package"
LASTVERSION="" LASTVERSION=""
LASTVERSION="$(curl -s -L https://github.com/"$UPSTREAM"/pkgs/container/"$last_package" | sed -n "s/.*?tag=\([^\"]*\)\">.*/\1/p" | LASTVERSION="$(curl -s -L https://github.com/"$UPSTREAM"/pkgs/container/"$last_package" | sed -n "s/.*?tag=\([^\"]*\)\">.*/\1/p" \
sed -e '/.*latest.*/d' | | sed -e '/.*latest.*/d' \
sed -e '/.*dev.*/d' | | sed -e '/.*dev.*/d' \
sed -e '/.*nightly.*/d' | | sed -e '/.*nightly.*/d' \
sed -e '/.*beta.*/d' | | sed -e '/.*beta.*/d' \
sort -V | | sort -V \
tail -n 1)" || true | tail -n 1)" || true
if [[ "$LASTVERSION" == "" ]]; then if [[ "$LASTVERSION" == "" ]]; then
# Continue to next # Continue to next
bashio::log.warning "No packages found" bashio::log.warning "No packages found"
set_continue=true set_continue=true
else else
bashio::log.info "Found tag $LASTVERSION" bashio::log.info "Found tag $LASTVERSION"
echo "$LASTVERSION" echo "$LASTVERSION"
fi fi
else else
# Continue to next # Continue to next
bashio::log.warning "No packages found" bashio::log.warning "No packages found"
set_continue=true set_continue=true
fi fi
else else
# Continue to next # Continue to next
set_continue=true set_continue=true
fi fi
} }
# shellcheck disable=SC2086 # shellcheck disable=SC2086
LASTVERSION="$(lastversion "$UPSTREAM" $ARGUMENTS || test_packages)" LASTVERSION="$(lastversion "$UPSTREAM" $ARGUMENTS || test_packages)"
# Continue if issue # Continue if issue
if [[ "${set_continue:-false}" == true ]]; then if [[ "${set_continue:-false}" == true ]]; then
continue continue
fi fi
fi fi
# Add brackets # Add brackets
LASTVERSION='"'${LASTVERSION}'"' LASTVERSION='"'${LASTVERSION}'"'
# Avoid characters incompatible with HomeAssistant version name # Avoid characters incompatible with HomeAssistant version name
LASTVERSION2=${LASTVERSION//+/-} LASTVERSION2=${LASTVERSION//+/-}
CURRENT2=${CURRENT//+/-} CURRENT2=${CURRENT//+/-}
# Update if needed # Update if needed
if [ "${CURRENT2}" != "${LASTVERSION2}" ]; then if [ "${CURRENT2}" != "${LASTVERSION2}" ]; then
LOGINFO="... $SLUG : update from ${CURRENT} to ${LASTVERSION}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : update from ${CURRENT} to ${LASTVERSION}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
#Change all instances of version #Change all instances of version
LOGINFO="... $SLUG : updating files" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi 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 for files in "config.json" "config.yaml" "Dockerfile" "build.json" "build.yaml"; do
if [ -f /data/"${BASENAME}"/"${SLUG}"/$files ]; then if [ -f /data/"${BASENAME}"/"${SLUG}"/$files ]; then
sed -i "s/${CURRENT}/${LASTVERSION}/g" /data/"${BASENAME}"/"${SLUG}"/"$files" sed -i "s/${CURRENT}/${LASTVERSION}/g" /data/"${BASENAME}"/"${SLUG}"/"$files"
fi fi
done done
# Remove " and modify version # Remove " and modify version
LASTVERSION=${LASTVERSION//\"/} LASTVERSION=${LASTVERSION//\"/}
CURRENT=${CURRENT//\"/} CURRENT=${CURRENT//\"/}
if [ -f /data/"${BASENAME}"/"${SLUG}"/config.json ]; then 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 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 elif [ -f /data/"${BASENAME}"/"${SLUG}"/config.yaml ]; then
sed -i "/version:/c\version: \"$LASTVERSION\"" /data/"${BASENAME}"/"${SLUG}"/config.yaml sed -i "/version:/c\version: \"$LASTVERSION\"" /data/"${BASENAME}"/"${SLUG}"/config.yaml
fi 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 "$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 jq --arg variable "$DATE" '.last_update = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace date tag
#Update changelog #Update changelog
touch "/data/${BASENAME}/${SLUG}/CHANGELOG.md" touch "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
if [[ "$SOURCE" == *"github"* ]]; then if [[ "$SOURCE" == *"github"* ]]; then
sed -i "1i - Update to latest version from $UPSTREAM (changelog : https://github.com/${UPSTREAM%/}/releases)" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" sed -i "1i - Update to latest version from $UPSTREAM (changelog : https://github.com/${UPSTREAM%/}/releases)" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
else else
sed -i "1i - Update to latest version from $UPSTREAM" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" sed -i "1i - Update to latest version from $UPSTREAM" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
fi fi
sed -i "1i ## ${LASTVERSION} (${DATE})" "/data/${BASENAME}/${SLUG}/CHANGELOG.md" sed -i "1i ## ${LASTVERSION} (${DATE})" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
sed -i "1i " "/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 LOGINFO="... $SLUG : files updated" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
#Git commit and push #Git commit and push
git add -A # add all modified files git add -A # add all modified files
git commit -m "Updater bot : $SLUG updated to ${LASTVERSION}" >/dev/null git commit -m "Updater bot : $SLUG updated to ${LASTVERSION}" > /dev/null
LOGINFO="... $SLUG : push to github" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi LOGINFO="... $SLUG : push to github" && 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 remote set-url origin "https://${GITUSER}:${GITHUB_API_TOKEN}@github.com/${REPOSITORY}" &> /dev/null
# Push # Push
if ! bashio::config.true "dry_run"; then if ! bashio::config.true "dry_run"; then
git push &>/dev/null git push &> /dev/null
fi fi
#Log #Log
bashio::log.yellow "... $SLUG updated from ${CURRENT} to ${LASTVERSION}" bashio::log.yellow "... $SLUG updated from ${CURRENT} to ${LASTVERSION}"
else else
bashio::log.green "... $SLUG is up-to-date ${CURRENT}" bashio::log.green "... $SLUG is up-to-date ${CURRENT}"
fi fi
fi fi
done || true # Continue even if issue done || true # Continue even if issue
# Clean dry run # Clean dry run
if bashio::config.true "dry_run"; then if bashio::config.true "dry_run"; then
rm -r /data/* rm -r /data/*
fi fi
bashio::log.info "Addons update completed" bashio::log.info "Addons update completed"

View File

@@ -7,9 +7,9 @@ set +u
# Autodefine if not defined # Autodefine if not defined
if [ -n "$INTERFACE_NAME" ]; then if [ -n "$INTERFACE_NAME" ]; then
# shellcheck disable=SC2155 # shellcheck disable=SC2155
export INTERFACE_NAME="$(ip route get 8.8.8.8 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')" export INTERFACE_NAME="$(ip route get 8.8.8.8 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')"
bashio::log.blue "Autodetection : INTERFACE_NAME=$INTERFACE_NAME" bashio::log.blue "Autodetection : INTERFACE_NAME=$INTERFACE_NAME"
fi fi
bashio::log.info "Starting..." bashio::log.info "Starting..."

View File

@@ -3,13 +3,13 @@
set -e set -e
if [ ! -d /data/autobrr ]; then if [ ! -d /data/autobrr ]; then
echo "Creating /data/autobrr" echo "Creating /data/autobrr"
mkdir -p /data/autobrr mkdir -p /data/autobrr
chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /data/autobrr chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /data/autobrr
fi fi
if [ ! -d /config/addons_config/autobrr ]; then if [ ! -d /config/addons_config/autobrr ]; then
echo "Creating /config/addons_config/autobrr" echo "Creating /config/addons_config/autobrr"
mkdir -p /config/addons_config/autobrr mkdir -p /config/addons_config/autobrr
chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /config/addons_config/autobrr chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /config/addons_config/autobrr
fi fi

View File

@@ -7,7 +7,7 @@ set -e
#################### ####################
if [ -d /homeassistant/addons_config/baikal ]; then 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" 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/ cp -rf /homeassistant/addons_config/baikal/* /config/
rm -r /homeassistant/addons_config/baikal rm -r /homeassistant/addons_config/baikal
fi fi

View File

@@ -8,6 +8,6 @@ chown -R nginx:nginx /data
# Start app # Start app
# Find the PHP FPM service script and start it # Find the PHP FPM service script and start it
find /etc/init.d -type f -name "php*-fpm" -exec {} start \; && find /etc/init.d -type f -name "php*-fpm" -exec {} start \; \
chown -R nginx:nginx /data/Specific && && chown -R nginx:nginx /data/Specific \
nginx -g "daemon off;" && nginx -g "daemon off;"

View File

@@ -4,8 +4,8 @@ set -e
# Remove not working elements # Remove not working elements
if bashio::config.true "NO_NOISE_MODEL"; then if bashio::config.true "NO_NOISE_MODEL"; then
bashio::log.info "Activating the no_noise models as NO_NOISE_MODEL is true" 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 sed -i "s|server.py --area|server.py --no_noise on --area|g" "$HOME"/BirdNET-Pi/scripts/batnet_analysis.sh
fi fi
# Add batnet service to monitoring service # 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 # Install gotty for amd64
if [ "$(uname -m)" == "x86_64" ]; then if [ "$(uname -m)" == "x86_64" ]; then
bashio::log.info "Install gotty for amd64" 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 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 mv /tmp/gotty /usr/local/bin/gotty
chmod +x /usr/local/bin/gotty chmod +x /usr/local/bin/gotty
sed -i "s| -P log| log|g" "$HOME"/BirdNET-Pi/templates/birdnet_log.service sed -i "s| -P log| log|g" "$HOME"/BirdNET-Pi/templates/birdnet_log.service
fi fi
# Make sure bats model is on # 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 # Disable monitoring service
sed -i "1a sleep infinity" /custom-services.d/30-monitoring.sh sed -i "1a sleep infinity" /custom-services.d/30-monitoring.sh

View File

@@ -1,33 +1,33 @@
#!/bin/bash #!/bin/bash
if [ ! -d /share/storage/movies ]; then if [ ! -d /share/storage/movies ]; then
echo "Creating /share/storage/movies" echo "Creating /share/storage/movies"
mkdir -p /share/storage/movies mkdir -p /share/storage/movies
chown -R "$PUID:$PGID" /share/storage/movies chown -R "$PUID:$PGID" /share/storage/movies
fi fi
if [ ! -d /share/storage/tv ]; then if [ ! -d /share/storage/tv ]; then
echo "Creating /share/storage/tv" echo "Creating /share/storage/tv"
mkdir -p /share/storage/tv mkdir -p /share/storage/tv
chown -R "$PUID:$PGID" /share/storage/tv chown -R "$PUID:$PGID" /share/storage/tv
fi fi
if [ ! -d /share/downloads ]; then if [ ! -d /share/downloads ]; then
echo "Creating /share/downloads" echo "Creating /share/downloads"
mkdir -p /share/downloads mkdir -p /share/downloads
chown -R "$PUID:$PGID" /share/downloads chown -R "$PUID:$PGID" /share/downloads
fi fi
if [ -d /config/bazarr ] && [ ! -d /config/addons_config/bazarr ]; then if [ -d /config/bazarr ] && [ ! -d /config/addons_config/bazarr ]; then
echo "Moving to new location /config/addons_config/bazarr" echo "Moving to new location /config/addons_config/bazarr"
mkdir -p /config/addons_config/bazarr mkdir -p /config/addons_config/bazarr
chown -R "$PUID:$PGID" /config/addons_config/bazarr chown -R "$PUID:$PGID" /config/addons_config/bazarr
mv /config/bazarr/* /config/addons_config/bazarr/ mv /config/bazarr/* /config/addons_config/bazarr/
rm -r /config/bazarr rm -r /config/bazarr
fi fi
if [ ! -d /config/addons_config/bazarr ]; then if [ ! -d /config/addons_config/bazarr ]; then
echo "Creating /config/addons_config/bazarr" echo "Creating /config/addons_config/bazarr"
mkdir -p /config/addons_config/bazarr mkdir -p /config/addons_config/bazarr
chown -R "$PUID:$PGID" /config/addons_config/bazarr chown -R "$PUID:$PGID" /config/addons_config/bazarr
fi fi

View File

@@ -3,15 +3,15 @@
set -e set -e
if [ -d /config/binance-trading-bot ]; then if [ -d /config/binance-trading-bot ]; then
echo "Moving to new location /config/addons_config/binance-trading-bot" echo "Moving to new location /config/addons_config/binance-trading-bot"
mkdir -p /config/addons_config/binance-trading-bot mkdir -p /config/addons_config/binance-trading-bot
chmod 777 /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/ mv /config/binance-trading-bot/* /config/addons_config/binance-trading-bot/
rm -r /config/binance-trading-bot rm -r /config/binance-trading-bot
fi fi
if [ ! -d /config/addons_config/binance-trading-bot ]; then if [ ! -d /config/addons_config/binance-trading-bot ]; then
echo "Creating /config/addons_config/binance-trading-bot" echo "Creating /config/addons_config/binance-trading-bot"
mkdir -p /config/addons_config/binance-trading-bot mkdir -p /config/addons_config/binance-trading-bot
chmod 777 /config/addons_config/binance-trading-bot chmod 777 /config/addons_config/binance-trading-bot
fi fi

View File

@@ -7,16 +7,16 @@ DEFAULT_BIRDSONGS_FOLDER="/data/clips/"
CONFIG_LOCATION="/config/config.yaml" CONFIG_LOCATION="/config/config.yaml"
if [ ! -f "$CONFIG_LOCATION" ]; then if [ ! -f "$CONFIG_LOCATION" ]; then
bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize" 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" curl -L -s -S https://raw.githubusercontent.com/tphakala/birdnet-go/refs/heads/main/internal/conf/config.yaml -o "$CONFIG_LOCATION"
fi fi
################# #################
# Migrate Database # Migrate Database
################# #################
if [ -f /data/birdnet.db ]; then if [ -f /data/birdnet.db ]; then
bashio::log.warning "Moving birdnet.db to /config/birdnet.db" bashio::log.warning "Moving birdnet.db to /config/birdnet.db"
mv /data/birdnet.db /config mv /data/birdnet.db /config
fi fi
###################### ######################
@@ -29,7 +29,7 @@ CURRENT_BIRDSONGS_FOLDER="${CURRENT_BIRDSONGS_FOLDER:-$DEFAULT_BIRDSONGS_FOLDER}
# Adjust default path if it matches the default string # Adjust default path if it matches the default string
if [[ "$CURRENT_BIRDSONGS_FOLDER" == "clips/" ]]; then if [[ "$CURRENT_BIRDSONGS_FOLDER" == "clips/" ]]; then
CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER" CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER"
fi fi
# Set the new birdsongs folder # Set the new birdsongs folder
@@ -37,59 +37,59 @@ BIRDSONGS_FOLDER="$(bashio::config "BIRDSONGS_FOLDER")"
BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER:-clips/}" 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 [[ ! "$BIRDSONGS_FOLDER" == /* ]]; then
if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then
mkdir -p "/config/$BIRDSONGS_FOLDER" mkdir -p "/config/$BIRDSONGS_FOLDER"
fi fi
if [ -d "/data/$BIRDSONGS_FOLDER" ]; then if [ -d "/data/$BIRDSONGS_FOLDER" ]; then
if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2>/dev/null)" ]; then if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2> /dev/null)" ]; then
cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/ cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/
fi fi
rm -r "/data/$BIRDSONGS_FOLDER" rm -r "/data/$BIRDSONGS_FOLDER"
fi fi
ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER" ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER"
fi fi
bashio::log.info "... audio clips saved to $BIRDSONGS_FOLDER according to addon options" bashio::log.info "... audio clips saved to $BIRDSONGS_FOLDER according to addon options"
# Migrate data if the folder has changed # Migrate data if the folder has changed
if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then
bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER" bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
# Update config files with the new birdsongs folder path # Update config files with the new birdsongs folder path
yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION" yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION"
# Move files only if sqlite paths changed # Move files only if sqlite paths changed
if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then
bashio::log.warning "Migrating files from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER" bashio::log.warning "Migrating files from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/ cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/
mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated" mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated"
fi fi
# Adapt the database # Adapt the database
if [ -f /config/birdnet.db ]; then if [ -f /config/birdnet.db ]; then
# Prepare # Prepare
backup="$(date +%Y%m%d_%H%M%S)" 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 "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup named birdnet.db_$backup will be created before"
# Create backup # Create backup
if ! cp /config/birdnet.db "birdnet.db_$backup"; then if ! cp /config/birdnet.db "birdnet.db_$backup"; then
bashio::log.error "Failed to create a backup of the database. Aborting path modification." bashio::log.error "Failed to create a backup of the database. Aborting path modification."
exit 1 exit 1
fi fi
# Execute the query using sqlite3 # 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%/}/%';" 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 if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then
bashio::log.warning "An error occurred while updating the paths. The database backup will be restored." 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 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 if [ -f "$BACKUP_FILE" ]; then
mv "$BACKUP_FILE" /config/birdnet.db mv "$BACKUP_FILE" /config/birdnet.db
bashio::log.info "The database backup has been restored." bashio::log.info "The database backup has been restored."
else else
bashio::log.error "Backup file not found! Manual intervention required." bashio::log.error "Backup file not found! Manual intervention required."
fi fi
else else
echo "Paths have been successfully updated." echo "Paths have been successfully updated."
fi fi
fi fi
fi fi
#################### ####################

View File

@@ -5,12 +5,12 @@ set -e
# Gives mariadb information # Gives mariadb information
if bashio::services.available 'mysql'; then if bashio::services.available 'mysql'; then
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.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 user : $(bashio::services "mysql" "username")"
bashio::log.blue "Database password : $(bashio::services "mysql" "password")" bashio::log.blue "Database password : $(bashio::services "mysql" "password")"
bashio::log.blue "Database name : birdnet" bashio::log.blue "Database name : birdnet"
bashio::log.blue "Host-name : $(bashio::services "mysql" "host")" bashio::log.blue "Host-name : $(bashio::services "mysql" "host")"
bashio::log.blue "Port : $(bashio::services "mysql" "port")" bashio::log.blue "Port : $(bashio::services "mysql" "port")"
bashio::log.green "---" bashio::log.green "---"
fi fi

View File

@@ -5,10 +5,10 @@ set -e
# Gives mqtt information # Gives mqtt information
if bashio::services.available 'mqtt'; then if bashio::services.available 'mqtt'; then
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.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 user : $(bashio::services "mqtt" "username")"
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")" 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.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
bashio::log.green "---" bashio::log.green "---"
fi fi

View File

@@ -10,12 +10,12 @@ bashio::log.info "ALSA_CARD option is set to $(bashio::config "ALSA_CARD"). If t
echo " " echo " "
# Adjust microphone volume if needed # Adjust microphone volume if needed
if command -v amixer >/dev/null 2>/dev/null; then 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 current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2> /dev/null || echo "100")" || true
if [[ "$current_volume" -eq 0 ]]; then if [[ "$current_volume" -eq 0 ]]; then
amixer sset Capture 70% amixer sset Capture 70%
bashio::log.warning "Microphone was off, volume set to 70%." bashio::log.warning "Microphone was off, volume set to 70%."
fi || true fi || true
fi fi
######################## ########################

View File

@@ -6,7 +6,7 @@ chown pi:pi /config
# Waiting for dbus # Waiting for dbus
until [[ -e /var/run/dbus/system_bus_socket ]]; do until [[ -e /var/run/dbus/system_bus_socket ]]; do
sleep 1s sleep 1s
done done
TZ_VALUE="$(timedatectl show -p Timezone --value)" TZ_VALUE="$(timedatectl show -p Timezone --value)"

View File

@@ -2,7 +2,7 @@
# shellcheck shell=bash # shellcheck shell=bash
# Waiting for dbus # Waiting for dbus
until [[ -e /var/run/dbus/system_bus_socket ]]; do until [[ -e /var/run/dbus/system_bus_socket ]]; do
sleep 1s sleep 1s
done done
TZ_VALUE="$(timedatectl show -p Timezone --value)" TZ_VALUE="$(timedatectl show -p Timezone --value)"
@@ -10,4 +10,4 @@ export TZ="$TZ_VALUE"
echo "Starting service: avahi daemon" echo "Starting service: avahi daemon"
exec \ exec \
avahi-daemon --no-chroot avahi-daemon --no-chroot

View File

@@ -4,8 +4,8 @@
# Dependencies # Dependencies
sockfile="empty" sockfile="empty"
until [[ -e /var/run/dbus/system_bus_socket ]] && [[ -e "$sockfile" ]]; do until [[ -e /var/run/dbus/system_bus_socket ]] && [[ -e "$sockfile" ]]; do
sleep 1s sleep 1s
sockfile="$(find /run/php -name "*.sock")" sockfile="$(find /run/php -name "*.sock")"
done done
# Correct fpm.sock # Correct fpm.sock
@@ -19,7 +19,7 @@ TZ_VALUE="$(timedatectl show -p Timezone --value)"
export TZ="$TZ_VALUE" export TZ="$TZ_VALUE"
# Update caddyfile with password # Update caddyfile with password
/."$HOME"/BirdNET-Pi/scripts/update_caddyfile.sh &>/dev/null || true /."$HOME"/BirdNET-Pi/scripts/update_caddyfile.sh &> /dev/null || true
echo "Starting service: caddy" echo "Starting service: caddy"
/usr/bin/caddy run --config /etc/caddy/Caddyfile /usr/bin/caddy run --config /etc/caddy/Caddyfile

View File

@@ -36,8 +36,8 @@ BIRDSONGS_DIR="$(readlink -f "$HOME/BirdSongs/Extracted/By_Date")"
# Ensure directories and set permissions # Ensure directories and set permissions
mkdir -p "$INGEST_DIR" || { mkdir -p "$INGEST_DIR" || {
log_red "Failed to create directory: $INGEST_DIR" log_red "Failed to create directory: $INGEST_DIR"
exit 1 exit 1
} }
chown -R pi:pi "$INGEST_DIR" || log_yellow "Could not change ownership for $INGEST_DIR" 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" chmod -R 755 "$INGEST_DIR" || log_yellow "Could not set permissions for $INGEST_DIR"
@@ -61,71 +61,71 @@ DISK_USAGE_THRESHOLD=95
same_file_counter=0 same_file_counter=0
SAME_FILE_THRESHOLD=2 SAME_FILE_THRESHOLD=2
if [[ -f "$ANALYZING_NOW_FILE" ]]; then if [[ -f "$ANALYZING_NOW_FILE" ]]; then
analyzing_now=$(<"$ANALYZING_NOW_FILE") analyzing_now=$(< "$ANALYZING_NOW_FILE")
else else
analyzing_now="" analyzing_now=""
fi fi
######################################## ########################################
# Notification Functions # Notification Functions
######################################## ########################################
apprisealert() { apprisealert() {
local issue_message="$1" local issue_message="$1"
local current_time local current_time
current_time=$(date +%s) current_time=$(date +%s)
# Calculate time_diff in minutes since last notification # Calculate time_diff in minutes since last notification
local time_diff=$(((current_time - last_notification_time) / 60)) local time_diff=$(((current_time - last_notification_time) / 60))
# Throttle notifications # Throttle notifications
if ((time_diff < NOTIFICATION_INTERVAL_IN_MINUTES)); then if ((time_diff < NOTIFICATION_INTERVAL_IN_MINUTES)); then
log_yellow "Notification suppressed (last sent ${time_diff} minutes ago)." log_yellow "Notification suppressed (last sent ${time_diff} minutes ago)."
return return
fi fi
local stopped_service="<br><b>Stopped services:</b> " local stopped_service="<br><b>Stopped services:</b> "
for service in "${SERVICES[@]}"; do for service in "${SERVICES[@]}"; do
if [[ "$(systemctl is-active "$service")" != "active" ]]; then if [[ "$(systemctl is-active "$service")" != "active" ]]; then
stopped_service+="$service; " stopped_service+="$service; "
fi fi
done done
local notification="<b>Issue:</b> $issue_message" local notification="<b>Issue:</b> $issue_message"
notification+="$stopped_service" notification+="$stopped_service"
notification+="<br><b>System:</b> ${SITE_NAME:-$(hostname)}" notification+="<br><b>System:</b> ${SITE_NAME:-$(hostname)}"
notification+="<br>Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')" notification+="<br>Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')"
notification+="<br>----Last log lines----" notification+="<br>----Last log lines----"
notification+="<br> $(timeout 15 cat /proc/1/fd/1 | head -n 5)" notification+="<br> $(timeout 15 cat /proc/1/fd/1 | head -n 5)"
notification+="<br>----------------------" notification+="<br>----------------------"
[[ -n "$BIRDNETPI_URL" ]] && notification+="<br><a href=\"$BIRDNETPI_URL\">Access your BirdNET-Pi</a>" [[ -n "$BIRDNETPI_URL" ]] && notification+="<br><a href=\"$BIRDNETPI_URL\">Access your BirdNET-Pi</a>"
local TITLE="BirdNET-Analyzer Alert" local TITLE="BirdNET-Analyzer Alert"
if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then 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" \ "$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \
--input-format=html --config="$HOME/BirdNET-Pi/apprise.txt" --input-format=html --config="$HOME/BirdNET-Pi/apprise.txt"
last_notification_time=$current_time last_notification_time=$current_time
issue_reported=1 issue_reported=1
else else
log_red "Apprise not configured or missing!" log_red "Apprise not configured or missing!"
fi fi
} }
apprisealert_recovery() { apprisealert_recovery() {
# Only send a recovery message if we had previously reported an issue # Only send a recovery message if we had previously reported an issue
if ((issue_reported == 1)); then if ((issue_reported == 1)); then
log_green "$(date) INFO: System is back to normal. Sending recovery notification." log_green "$(date) INFO: System is back to normal. Sending recovery notification."
local TITLE="BirdNET-Pi System Recovered" local TITLE="BirdNET-Pi System Recovered"
local notification="<b>All monitored services are back to normal.</b><br>" local notification="<b>All monitored services are back to normal.</b><br>"
notification+="<b>System:</b> ${SITE_NAME:-$(hostname)}<br>" notification+="<b>System:</b> ${SITE_NAME:-$(hostname)}<br>"
notification+="Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')" 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 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" \ "$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \
--input-format=html --config="$HOME/BirdNET-Pi/apprise.txt" --input-format=html --config="$HOME/BirdNET-Pi/apprise.txt"
fi fi
issue_reported=0 issue_reported=0
fi fi
} }
######################################## ########################################
@@ -133,115 +133,115 @@ apprisealert_recovery() {
######################################## ########################################
check_disk_space() { check_disk_space() {
local current_usage local current_usage
current_usage=$(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $5}' | sed 's/%//') current_usage=$(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $5}' | sed 's/%//')
if ((current_usage >= DISK_USAGE_THRESHOLD)); then if ((current_usage >= DISK_USAGE_THRESHOLD)); then
log_red "$(date) INFO: Disk usage is at ${current_usage}% (CRITICAL!)" log_red "$(date) INFO: Disk usage is at ${current_usage}% (CRITICAL!)"
apprisealert "Disk usage critical: ${current_usage}%" apprisealert "Disk usage critical: ${current_usage}%"
return 1 return 1
else else
log_green "$(date) INFO: Disk usage is within acceptable limits (${current_usage}%)." log_green "$(date) INFO: Disk usage is within acceptable limits (${current_usage}%)."
return 0 return 0
fi fi
} }
check_analyzing_now() { check_analyzing_now() {
local current_file local current_file
current_file=$(cat "$ANALYZING_NOW_FILE" 2>/dev/null) current_file=$(cat "$ANALYZING_NOW_FILE" 2> /dev/null)
if [[ "$current_file" == "$analyzing_now" ]]; then if [[ "$current_file" == "$analyzing_now" ]]; then
((same_file_counter++)) ((same_file_counter++))
else else
same_file_counter=0 same_file_counter=0
analyzing_now="$current_file" analyzing_now="$current_file"
fi fi
if ((same_file_counter >= SAME_FILE_THRESHOLD)); then if ((same_file_counter >= SAME_FILE_THRESHOLD)); then
log_red "$(date) INFO: 'analyzing_now' file unchanged for $SAME_FILE_THRESHOLD iterations." log_red "$(date) INFO: 'analyzing_now' file unchanged for $SAME_FILE_THRESHOLD iterations."
apprisealert "No change in analyzing_now for ${SAME_FILE_THRESHOLD} iterations" apprisealert "No change in analyzing_now for ${SAME_FILE_THRESHOLD} iterations"
"$HOME/BirdNET-Pi/scripts/restart_services.sh" "$HOME/BirdNET-Pi/scripts/restart_services.sh"
same_file_counter=0 same_file_counter=0
return 1 return 1
else else
# Only log if it changed this iteration # Only log if it changed this iteration
if ((same_file_counter == 0)); then if ((same_file_counter == 0)); then
log_green "$(date) INFO: 'analyzing_now' file has been updated." log_green "$(date) INFO: 'analyzing_now' file has been updated."
fi fi
return 0 return 0
fi fi
} }
check_queue() { check_queue() {
local wav_count local wav_count
wav_count=$(find -L "$INGEST_DIR" -maxdepth 1 -name '*.wav' | wc -l) 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 if ((wav_count > 50)); then
log_red "$(date) INFO: Queue >50. Stopping recorder + restarting analyzer." log_red "$(date) INFO: Queue >50. Stopping recorder + restarting analyzer."
apprisealert "Queue exceeded 50: stopping recorder, restarting analyzer." apprisealert "Queue exceeded 50: stopping recorder, restarting analyzer."
sudo systemctl stop birdnet_recording sudo systemctl stop birdnet_recording
sudo systemctl restart birdnet_analysis sudo systemctl restart birdnet_analysis
return 1 return 1
elif ((wav_count > 30)); then elif ((wav_count > 30)); then
log_red "$(date) INFO: Queue >30. Restarting analyzer." log_red "$(date) INFO: Queue >30. Restarting analyzer."
apprisealert "Queue exceeded 30: restarting analyzer." apprisealert "Queue exceeded 30: restarting analyzer."
sudo systemctl restart birdnet_analysis sudo systemctl restart birdnet_analysis
return 1 return 1
fi fi
return 0 return 0
} }
check_services() { check_services() {
local any_inactive=0 local any_inactive=0
for service in "${SERVICES[@]}"; do for service in "${SERVICES[@]}"; do
if [[ "$(systemctl is-active "$service")" != "active" ]]; then if [[ "$(systemctl is-active "$service")" != "active" ]]; then
SERVICE_INACTIVE_COUNT["$service"]=$((SERVICE_INACTIVE_COUNT["$service"] + 1)) SERVICE_INACTIVE_COUNT["$service"]=$((SERVICE_INACTIVE_COUNT["$service"] + 1))
if ((SERVICE_INACTIVE_COUNT["$service"] == 1)); then if ((SERVICE_INACTIVE_COUNT["$service"] == 1)); then
# First time inactive => Try to start # First time inactive => Try to start
log_yellow "$(date) INFO: Service '$service' is inactive. Attempting to start..." log_yellow "$(date) INFO: Service '$service' is inactive. Attempting to start..."
systemctl start "$service" systemctl start "$service"
any_inactive=1 any_inactive=1
elif ((SERVICE_INACTIVE_COUNT["$service"] == 2)); then elif ((SERVICE_INACTIVE_COUNT["$service"] == 2)); then
# Second consecutive time => Send an alert # Second consecutive time => Send an alert
log_red "$(date) INFO: Service '$service' is still inactive after restart attempt." log_red "$(date) INFO: Service '$service' is still inactive after restart attempt."
apprisealert "Service '$service' remains inactive after restart attempt." apprisealert "Service '$service' remains inactive after restart attempt."
any_inactive=1 any_inactive=1
else else
# Beyond second check => keep logging or do advanced actions # 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." log_red "$(date) INFO: Service '$service' inactive for ${SERVICE_INACTIVE_COUNT["$service"]} checks in a row."
any_inactive=1 any_inactive=1
fi fi
else else
# Service is active => reset counter # Service is active => reset counter
if ((SERVICE_INACTIVE_COUNT["$service"] > 0)); then if ((SERVICE_INACTIVE_COUNT["$service"] > 0)); then
log_green "$(date) INFO: Service '$service' is back to active. Resetting counter." log_green "$(date) INFO: Service '$service' is back to active. Resetting counter."
fi fi
SERVICE_INACTIVE_COUNT["$service"]=0 SERVICE_INACTIVE_COUNT["$service"]=0
fi fi
done done
if ((any_inactive == 0)); then if ((any_inactive == 0)); then
log_green "$(date) INFO: All services are active" log_green "$(date) INFO: All services are active"
return 0 return 0
else else
log_red "$(date) INFO: One or more services are inactive" log_red "$(date) INFO: One or more services are inactive"
return 1 return 1
fi fi
} }
check_for_empty_stream() { check_for_empty_stream() {
local log_tail local log_tail
log_tail=$(timeout 15 cat /proc/1/fd/1 | tail -n 5) log_tail=$(timeout 15 cat /proc/1/fd/1 | tail -n 5)
if echo "$log_tail" | grep -q "Haliastur indus"; then if echo "$log_tail" | grep -q "Haliastur indus"; then
log_red "$(date) INFO: Potential empty stream detected (frequent 'Haliastur indus')." log_red "$(date) INFO: Potential empty stream detected (frequent 'Haliastur indus')."
apprisealert "Potential empty stream detected — frequent 'Haliastur indus' in log" apprisealert "Potential empty stream detected — frequent 'Haliastur indus' in log"
return 1 return 1
fi fi
return 0 return 0
} }
######################################## ########################################
@@ -251,32 +251,32 @@ TZ_VALUE="$(timedatectl show -p Timezone --value)"
export TZ="$TZ_VALUE" export TZ="$TZ_VALUE"
while true; do while true; do
sleep 61 sleep 61
log_blue "----------------------------------------" log_blue "----------------------------------------"
log_blue "$(date) INFO: Starting monitoring check" log_blue "$(date) INFO: Starting monitoring check"
any_issue=0 any_issue=0
# 1) Disk usage # 1) Disk usage
check_disk_space || any_issue=1 check_disk_space || any_issue=1
# 2) 'analyzing_now' file # 2) 'analyzing_now' file
check_analyzing_now || any_issue=1 check_analyzing_now || any_issue=1
# 3) Queue check # 3) Queue check
check_queue || any_issue=1 check_queue || any_issue=1
# 4) Services check # 4) Services check
check_services || any_issue=1 check_services || any_issue=1
# 5) Check for potential empty stream # 5) Check for potential empty stream
check_for_empty_stream || any_issue=1 check_for_empty_stream || any_issue=1
# Final summary # Final summary
if ((any_issue == 0)); then if ((any_issue == 0)); then
log_green "$(date) INFO: All systems are functioning normally" log_green "$(date) INFO: All systems are functioning normally"
apprisealert_recovery apprisealert_recovery
else else
log_red "$(date) INFO: Issues detected. System status is not fully operational." log_red "$(date) INFO: Issues detected. System status is not fully operational."
fi fi
log_blue "----------------------------------------" log_blue "----------------------------------------"
done done

View File

@@ -6,46 +6,46 @@ MAX_SIZE=$((50 * 1024 * 1024))
# Function to check if a file is a valid WAV # Function to check if a file is a valid WAV
is_valid_wav() { is_valid_wav() {
local file="$1" local file="$1"
# Check if the file contains a valid WAV header # Check if the file contains a valid WAV header
file "$file" | grep -qE 'WAVE audio' file "$file" | grep -qE 'WAVE audio'
} }
if [ -d "$HOME"/BirdSongs/StreamData ]; then 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 # Stop the services in parallel
if systemctl is-active --quiet birdnet_analysis; then if systemctl is-active --quiet birdnet_analysis; then
bashio::log.info "Stopping birdnet_analysis service." bashio::log.info "Stopping birdnet_analysis service."
systemctl stop birdnet_analysis & systemctl stop birdnet_analysis &
fi fi
if systemctl is-active --quiet birdnet_recording; then if systemctl is-active --quiet birdnet_recording; then
bashio::log.info "Stopping birdnet_recording service." bashio::log.info "Stopping birdnet_recording service."
systemctl stop birdnet_recording & systemctl stop birdnet_recording &
fi fi
# Wait for both services to stop # Wait for both services to stop
wait wait
# Create the destination directory # Create the destination directory
mkdir -p /config/TemporaryFiles mkdir -p /config/TemporaryFiles
# Move only valid WAV files under 50MB # Move only valid WAV files under 50MB
shopt -s nullglob # Prevent errors if no files match shopt -s nullglob # Prevent errors if no files match
for file in "$HOME"/BirdSongs/StreamData/*.wav; do for file in "$HOME"/BirdSongs/StreamData/*.wav; do
if [ -f "$file" ] && [ "$(stat --format="%s" "$file")" -lt "$MAX_SIZE" ] && is_valid_wav "$file"; then if [ -f "$file" ] && [ "$(stat --format="%s" "$file")" -lt "$MAX_SIZE" ] && is_valid_wav "$file"; then
if mv -v "$file" /config/TemporaryFiles/; then if mv -v "$file" /config/TemporaryFiles/; then
bashio::log.info "Moved valid WAV file: $(basename "$file")" bashio::log.info "Moved valid WAV file: $(basename "$file")"
else else
bashio::log.error "Failed to move: $(basename "$file")" bashio::log.error "Failed to move: $(basename "$file")"
fi fi
else else
bashio::log.warning "Skipping invalid or large file: $(basename "$file")" bashio::log.warning "Skipping invalid or large file: $(basename "$file")"
fi fi
done done
bashio::log.info "... files safe, allowing container to stop." bashio::log.info "... files safe, allowing container to stop."
else else
bashio::log.info "No StreamData directory to process." bashio::log.info "No StreamData directory to process."
fi fi

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
############### ###############
@@ -23,24 +23,24 @@ bashio::log.info "Ensuring the file structure is correct:"
echo "... creating default files" 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") 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 for file in "${DEFAULT_FILES[@]}"; do
if [ ! -f "/config/$file" ]; then if [ ! -f "/config/$file" ]; then
echo "" >"/config/$file" echo "" > "/config/$file"
fi fi
done done
touch /config/include_species_list.txt # Ensure this is always created touch /config/include_species_list.txt # Ensure this is always created
# Set BirdSongs folder location from configuration if specified # Set BirdSongs folder location from configuration if specified
BIRDSONGS_FOLDER="/config/BirdSongs" BIRDSONGS_FOLDER="/config/BirdSongs"
if bashio::config.has_value "BIRDSONGS_FOLDER"; then if bashio::config.has_value "BIRDSONGS_FOLDER"; then
BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")" BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")"
echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION" echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION"
mkdir -p "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be created" 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" 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 if [ -d "$BIRDSONGS_FOLDER_OPTION" ] && [ "$(stat -c '%u:%g' "$BIRDSONGS_FOLDER_OPTION")" == "1000:1000" ]; then
BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION" BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION"
else else
bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs" bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs"
fi fi
fi fi
# Create default folders # Create default folders
@@ -49,12 +49,12 @@ mkdir -p "$BIRDSONGS_FOLDER/By_Date" "$BIRDSONGS_FOLDER/Charts"
# Use tmpfs if installed # Use tmpfs if installed
if df -T /tmp | grep -q "tmpfs"; then if df -T /tmp | grep -q "tmpfs"; then
echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear" echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear"
mkdir -p /tmp/StreamData /tmp/Processed mkdir -p /tmp/StreamData /tmp/Processed
[ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData" [ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData"
[ -d "$HOME/BirdSongs/Processed" ] && rm -r "$HOME/BirdSongs/Processed" [ -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/StreamData "$HOME/BirdSongs/StreamData"
sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed" sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed"
fi fi
# Set permissions for created files and folders # 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 # Create default birdnet.conf if not existing
if [ ! -f /config/birdnet.conf ]; then if [ ! -f /config/birdnet.conf ]; then
cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/ cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/
fi fi
# Create default birds.db # Create default birds.db
if [ ! -f /config/birds.db ]; then if [ ! -f /config/birds.db ]; then
echo "... creating initial db" echo "... creating initial db"
"$HOME/BirdNET-Pi/scripts/createdb.sh" "$HOME/BirdNET-Pi/scripts/createdb.sh"
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/ cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
elif [ "$(stat -c%s /config/birds.db)" -lt 10240 ]; then elif [ "$(stat -c%s /config/birds.db)" -lt 10240 ]; then
echo "... your db is corrupted, creating new one" echo "... your db is corrupted, creating new one"
rm /config/birds.db rm /config/birds.db
"$HOME/BirdNET-Pi/scripts/createdb.sh" "$HOME/BirdNET-Pi/scripts/createdb.sh"
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/ cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
fi fi
# Symlink configuration files # 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") 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 for file in "${CONFIG_FILES[@]}"; do
filename="${file##*/}" filename="${file##*/}"
[ ! -f "/config/$filename" ] && touch "/config/$filename" [ ! -f "/config/$filename" ] && touch "/config/$filename"
[ -e "$file" ] && rm "$file" [ -e "$file" ] && rm "$file"
sudo -u pi ln -fs "/config/$filename" "$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" "$HOME/BirdNET-Pi/scripts/$filename"
sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename" sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename"
done done
# Create thisrun.txt for legacy modes # Create thisrun.txt for legacy modes
@@ -106,9 +106,9 @@ chown pi:pi /usr/local/bin/*
# Symlink BirdSongs folders # Symlink BirdSongs folders
for folder in By_Date Charts; do for folder in By_Date Charts; do
echo "... creating symlink for $BIRDSONGS_FOLDER/$folder" echo "... creating symlink for $BIRDSONGS_FOLDER/$folder"
[ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder" [ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder"
sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder" sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder"
done done
# Set permissions for newly created files and folders # Set permissions for newly created files and folders

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
###################### ######################
@@ -19,32 +19,32 @@ fi
if [ -d /config/TemporaryFiles ]; then if [ -d /config/TemporaryFiles ]; then
# Check if there are .wav files in /config/TemporaryFiles # Check if there are .wav files in /config/TemporaryFiles
if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then
bashio::log.warning "Container was stopped while files were still being analyzed." bashio::log.warning "Container was stopped while files were still being analyzed."
echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData." echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData."
# Create the destination directory if it does not exist # Create the destination directory if it does not exist
mkdir -p "$HOME"/BirdSongs/StreamData mkdir -p "$HOME"/BirdSongs/StreamData
# Count the number of .wav files to be moved # Count the number of .wav files to be moved
file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l) file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l)
echo "... found $file_count .wav files to restore." echo "... found $file_count .wav files to restore."
# Move the .wav files using `mv` to avoid double log entries # Move the .wav files using `mv` to avoid double log entries
mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/ mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/
# Update permissions only if files were moved successfully # Update permissions only if files were moved successfully
if [ "$file_count" -gt 0 ]; then if [ "$file_count" -gt 0 ]; then
chown -R pi:pi "$HOME"/BirdSongs/StreamData chown -R pi:pi "$HOME"/BirdSongs/StreamData
fi fi
echo "... $file_count files restored successfully." echo "... $file_count files restored successfully."
else else
echo "... no .wav files found to restore." echo "... no .wav files found to restore."
fi fi
# Clean up the source folder if it is empty # Clean up the source folder if it is empty
rm -r /config/TemporaryFiles rm -r /config/TemporaryFiles
fi fi

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
###################### ######################
@@ -25,22 +25,22 @@ configtemplate="$HOME"/BirdNET-Pi/birdnet.bak
# Ensure both files exist before proceeding # Ensure both files exist before proceeding
if [ ! -f "$configcurrent" ] || [ ! -f "$configtemplate" ]; then if [ ! -f "$configcurrent" ] || [ ! -f "$configtemplate" ]; then
bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present." bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present."
exit 1 exit 1
fi fi
# Extract variable names from config template and read each one # Extract variable names from config template and read each one
grep -o '^[^#=]*=' "$configtemplate" | sed 's/=//' | while read -r var; do grep -o '^[^#=]*=' "$configtemplate" | sed 's/=//' | while read -r var; do
# Check if the variable is in configcurrent, if not, append it # Check if the variable is in configcurrent, if not, append it
if ! grep -q "^$var=" "$configcurrent"; then if ! grep -q "^$var=" "$configcurrent"; then
bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added" bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added"
grep "^$var=" "$configtemplate" >>"$configcurrent" grep "^$var=" "$configtemplate" >> "$configcurrent"
fi fi
# Check for duplicates # Check for duplicates
if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then 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" 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" sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent"
fi fi
done done
############## ##############
@@ -48,8 +48,8 @@ done
############## ##############
if [[ "$(bashio::addon.port "80")" == 3000 ]]; then 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" 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 sleep infinity
fi fi
################## ##################

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
############ ############
@@ -19,66 +19,66 @@ fi
# Function to perform common setup steps # Function to perform common setup steps
common_steps() { common_steps() {
# Attempt to connect to the MQTT broker # Attempt to connect to the MQTT broker
TOPIC="birdnet" 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 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 # Adapt script with MQTT settings
sed -i "s|%%mqtt_server%%|$MQTT_HOST|g" /helpers/birdnet_to_mqtt.py 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_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_user%%|$MQTT_USER|g" /helpers/birdnet_to_mqtt.py
sed -i "s|%%mqtt_pass%%|$MQTT_PASS|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 # Copy script to the appropriate directory
cp /helpers/birdnet_to_mqtt.py "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py 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 chown pi:pi "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
chmod +x "$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 # 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 "/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 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 else
bashio::log.fatal "MQTT connection failed, it will not be configured" bashio::log.fatal "MQTT connection failed, it will not be configured"
fi fi
} }
# Check if MQTT service is available and not disabled # 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 if [[ -f "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py ]] && bashio::services.available 'mqtt' && ! bashio::config.true 'MQTT_DISABLED'; then
bashio::log.green "---" 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 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 user : $(bashio::services "mqtt" "username")"
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")" 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.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
bashio::log.green "---" bashio::log.green "---"
bashio::log.blue "Data will be posted to the topic : 'birdnet'" 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 "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
bashio::log.blue "---" bashio::log.blue "---"
# Apply MQTT settings # Apply MQTT settings
MQTT_HOST="$(bashio::services "mqtt" "host")" MQTT_HOST="$(bashio::services "mqtt" "host")"
MQTT_PORT="$(bashio::services "mqtt" "port")" MQTT_PORT="$(bashio::services "mqtt" "port")"
MQTT_USER="$(bashio::services "mqtt" "username")" MQTT_USER="$(bashio::services "mqtt" "username")"
MQTT_PASS="$(bashio::services "mqtt" "password")" MQTT_PASS="$(bashio::services "mqtt" "password")"
# Perform common setup steps # Perform common setup steps
common_steps common_steps
# Check if manual MQTT configuration is provided # 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 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.green "---"
bashio::log.blue "MQTT is manually configured in the addon options" 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.blue "Birdnet-pi is now automatically configured to send its output to MQTT"
bashio::log.green "---" bashio::log.green "---"
bashio::log.blue "Data will be posted to the topic : 'birdnet'" 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 "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
bashio::log.blue "---" bashio::log.blue "---"
# Apply manual MQTT settings # Apply manual MQTT settings
MQTT_HOST="$(bashio::config "MQTT_HOST_manual")" MQTT_HOST="$(bashio::config "MQTT_HOST_manual")"
MQTT_PORT="$(bashio::config "MQTT_PORT_manual")" MQTT_PORT="$(bashio::config "MQTT_PORT_manual")"
MQTT_USER="$(bashio::config "MQTT_USER_manual")" MQTT_USER="$(bashio::config "MQTT_USER_manual")"
MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")" MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")"
# Perform common setup steps # Perform common setup steps
common_steps common_steps
fi fi

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
################ ################
@@ -22,21 +22,21 @@ bashio::log.info "Adapting webui"
# HA specific elements # HA specific elements
###################### ######################
if bashio::supervisor.ping 2>/dev/null; then if bashio::supervisor.ping 2> /dev/null; then
# Remove services tab from webui # Remove services tab from webui
echo "... removing System Controls from webui as should be used from HA" echo "... removing System Controls from webui as should be used from HA"
sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php" sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php"
# Remove pulseaudio # Remove pulseaudio
echo "... disabling pulseaudio as managed by HomeAssistant" echo "... disabling pulseaudio as managed by HomeAssistant"
grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do
sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file" sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file"
done done
# Check if port 80 is correctly configured # Check if port 80 is correctly configured
if [ -n "$(bashio::addon.port "80")" ] && [ "$(bashio::addon.port "80")" != 80 ]; then 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." bashio::log.fatal "The port 80 is enabled, but should still be 80 if you want automatic SSL certificates generation to work."
fi fi
fi fi
# General elements # General elements
@@ -45,25 +45,25 @@ fi
# Remove Ram drive option from webui # Remove Ram drive option from webui
echo "... removing Ram drive from webui as it is handled from HA" 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 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/{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/d' "$HOME/BirdNET-Pi/scripts/service_controls.php"
fi fi
# Allow symlinks # Allow symlinks
echo "... ensuring symlinks work" echo "... ensuring symlinks work"
for files in "$HOME"/BirdNET-Pi/scripts/*.sh; do for files in "$HOME"/BirdNET-Pi/scripts/*.sh; do
sed -i "s|find |find -L |g" "$files" sed -i "s|find |find -L |g" "$files"
sed -i "s|find -L -L |find -L |g" "$files" sed -i "s|find -L -L |find -L |g" "$files"
done done
# Correct services to start as user pi # Correct services to start as user pi
echo "... updating 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 if ! grep -q "/usr/bin/sudo" "$HOME/BirdNET-Pi/templates/birdnet_analysis.service"; then
while IFS= read -r file; do while IFS= read -r file; do
if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then
sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file" sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file"
fi fi
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print) done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print)
fi fi
# Allow pulseaudio system # 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 # Send services log to container logs
echo "... redirecting services logs to container logs" echo "... redirecting services logs to container logs"
while IFS= read -r file; do while IFS= read -r file; do
sed -i "/StandardError/d" "$file" sed -i "/StandardError/d" "$file"
sed -i "/StandardOutput/d" "$file" sed -i "/StandardOutput/d" "$file"
sed -i "/\[Service/a StandardError=append:/proc/1/fd/1" "$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 "/\[Service/a StandardOutput=append:/proc/1/fd/1" "$file"
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*.service" -print) done < <(find "$HOME/BirdNET-Pi/templates/" -name "*.service" -print)
# Preencode API key # Preencode API key
if [[ -f "$HOME/BirdNET-Pi/scripts/common.php" ]] && ! grep -q "221160312" "$HOME/BirdNET-Pi/scripts/common.php"; then 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 "/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 "s|e1c22|e1c22ec60ecf336951b0e77|g" "$HOME"/BirdNET-Pi/scripts/common.php
fi fi
# Correct log services to show /proc/1/fd/1 # 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 # Correct backup script
if [[ -f "$HOME/BirdNET-Pi/scripts/backup_data.sh" ]]; then if [[ -f "$HOME/BirdNET-Pi/scripts/backup_data.sh" ]]; then
echo "... correct backup script" 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" 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 fi
# Caddyfile modifications # Caddyfile modifications
@@ -101,27 +101,27 @@ echo "... modifying Caddyfile configurations"
caddy fmt --overwrite /etc/caddy/Caddyfile caddy fmt --overwrite /etc/caddy/Caddyfile
#Change port to leave 80 free for certificate requests #Change port to leave 80 free for certificate requests
if ! grep -q "http://:8081" /etc/caddy/Caddyfile; then 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" /etc/caddy/Caddyfile
sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
if [ -f /etc/caddy/Caddyfile.original ]; then if [ -f /etc/caddy/Caddyfile.original ]; then
rm /etc/caddy/Caddyfile.original rm /etc/caddy/Caddyfile.original
fi fi
fi fi
# Correct webui paths # Correct webui paths
echo "... correcting webui paths" echo "... correcting webui paths"
if ! grep -q "/stats/" "$HOME/BirdNET-Pi/homepage/views.php"; then 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|/stats|/stats/|g" "$HOME/BirdNET-Pi/homepage/views.php"
sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php" sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php"
fi fi
# Correct systemctl path # Correct systemctl path
if [ -f /helpers/systemctl ] && [ -f /helpers/journalctl ]; then if [ -f /helpers/systemctl ] && [ -f /helpers/journalctl ]; then
echo "... updating systemctl and journalctl" echo "... updating systemctl and journalctl"
cp -rf /helpers/systemctl /bin/systemctl cp -rf /helpers/systemctl /bin/systemctl
cp -rf /helpers/journalctl /bin/journalctl cp -rf /helpers/journalctl /bin/journalctl
chown pi:pi /bin/systemctl /bin/journalctl chown pi:pi /bin/systemctl /bin/journalctl
chmod a+x /bin/systemctl /bin/journalctl chmod a+x /bin/systemctl /bin/journalctl
fi fi
# Allow reverse proxy for streamlit # 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 # Clean saved mp3 files
if [[ -f "$HOME/BirdNET-Pi/scripts/utils/reporting.py" ]]; then if [[ -f "$HOME/BirdNET-Pi/scripts/utils/reporting.py" ]]; then
echo ".. add highpass and lowpass to sox extracts" 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" sed -i "s|f'={stop}']|f'={stop}', 'highpass', '250']|g" "$HOME/BirdNET-Pi/scripts/utils/reporting.py"
fi fi
# Correct timedatectl path # Correct timedatectl path
echo "... updating timedatectl path" echo "... updating timedatectl path"
if [[ -f /helpers/timedatectl ]]; then if [[ -f /helpers/timedatectl ]]; then
mv /helpers/timedatectl /usr/bin/timedatectl mv /helpers/timedatectl /usr/bin/timedatectl
chown pi:pi /usr/bin/timedatectl chown pi:pi /usr/bin/timedatectl
chmod a+x /usr/bin/timedatectl chmod a+x /usr/bin/timedatectl
fi fi
# Set RECS_DIR # Set RECS_DIR
echo "... setting RECS_DIR to /tmp" echo "... setting RECS_DIR to /tmp"
grep -rl "RECS_DIR" "$HOME" --exclude="*.php" | while read -r file; do grep -rl "RECS_DIR" "$HOME" --exclude="*.php" | while read -r file; do
sed -i "s|conf\['RECS_DIR'\]|'/tmp'|g" "$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 "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 "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file" sed -i "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file"
done done
mkdir -p /tmp mkdir -p /tmp
# Correct language labels according to birdnet.conf # Correct language labels according to birdnet.conf
echo "... adapting labels according to birdnet.conf" echo "... adapting labels according to birdnet.conf"
if export "$(grep "^DATABASE_LANG" /config/birdnet.conf)"; then if export "$(grep "^DATABASE_LANG" /config/birdnet.conf)"; then
bashio::log.info "Setting language to ${DATABASE_LANG:-en}" 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" "$HOME/BirdNET-Pi/scripts/install_language_label_nm.sh" -l "${DATABASE_LANG:-}" &> /dev/null || bashio::log.warning "Failed to update language labels"
else 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 fi

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
################# #################
@@ -24,9 +24,9 @@ ingress_entry=$(bashio::addon.ingress_entry)
# Quits if ingress is not active # Quits if ingress is not active
if [[ "$ingress_entry" != "/api"* ]]; then if [[ "$ingress_entry" != "/api"* ]]; then
bashio::log.info "Ingress entry is not set, exiting configuration." bashio::log.info "Ingress entry is not set, exiting configuration."
sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh
exit 0 exit 0
fi fi
bashio::log.info "Adapting for ingress" bashio::log.info "Adapting for ingress"
@@ -35,26 +35,26 @@ echo "... setting up nginx"
# Check if the NGINX configuration file exists # Check if the NGINX configuration file exists
nginx_conf="/etc/nginx/servers/ingress.conf" nginx_conf="/etc/nginx/servers/ingress.conf"
if [ -f "$nginx_conf" ]; then if [ -f "$nginx_conf" ]; then
sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf" sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf"
sed -i "s/%%interface%%/${ingress_interface}/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|%%ingress_entry%%|${ingress_entry}|g" "$nginx_conf"
else else
bashio::log.error "NGINX configuration file not found: $nginx_conf" bashio::log.error "NGINX configuration file not found: $nginx_conf"
exit 1 exit 1
fi fi
# Disable log # Disable log
sed -i "/View Log/d" "$HOME/BirdNET-Pi/homepage/views.php" sed -i "/View Log/d" "$HOME/BirdNET-Pi/homepage/views.php"
echo "... ensuring restricted area access" echo "... ensuring restricted area access"
echo "${ingress_entry}" >/ingress_url echo "${ingress_entry}" > /ingress_url
# Modify PHP file safely # Modify PHP file safely
php_file="$HOME/BirdNET-Pi/scripts/common.php" php_file="$HOME/BirdNET-Pi/scripts/common.php"
if [ -f "$php_file" ]; then 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 else
bashio::log.warning "PHP file not found: $php_file" bashio::log.warning "PHP file not found: $php_file"
fi fi
echo "... adapting Caddyfile for ingress" echo "... adapting Caddyfile for ingress"
@@ -66,8 +66,8 @@ chmod +x /helpers/caddy_ingress.sh
# Update the Caddyfile if update script exists # Update the Caddyfile if update script exists
caddy_update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" caddy_update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
if [ -f "$caddy_update_script" ]; then 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 else
bashio::log.error "Caddy update script not found: $caddy_update_script" bashio::log.error "Caddy update script not found: $caddy_update_script"
exit 1 exit 1
fi fi

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
############### ###############
@@ -18,32 +18,32 @@ fi
############### ###############
if bashio::config.true 'ssl'; then 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 # Check required SSL configurations
bashio::config.require.ssl bashio::config.require.ssl
certfile=$(bashio::config 'certfile') certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile') keyfile=$(bashio::config 'keyfile')
# Ensure Caddyfile exists before modifying # Ensure Caddyfile exists before modifying
caddyfile="/etc/caddy/Caddyfile" caddyfile="/etc/caddy/Caddyfile"
if [ -f "$caddyfile" ]; then if [ -f "$caddyfile" ]; then
sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile" sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile"
sed -i "s|http://:8081|https://:8081|g" "$caddyfile" sed -i "s|http://:8081|https://:8081|g" "$caddyfile"
else else
bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration." bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration."
exit 1 exit 1
fi fi
# Ensure update_caddyfile.sh exists before modifying # Ensure update_caddyfile.sh exists before modifying
update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
if [ -f "$update_script" ]; then if [ -f "$update_script" ]; then
sed -i "s|http://:8081|https://:8081|g" "$update_script" sed -i "s|http://:8081|https://:8081|g" "$update_script"
if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then
sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script" sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"
fi fi
else else
bashio::log.error "Update script not found: $update_script, skipping SSL setup for update." bashio::log.error "Update script not found: $update_script, skipping SSL setup for update."
exit 1 exit 1
fi fi
fi fi

View File

@@ -7,10 +7,10 @@ set -e
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
###################### ######################
@@ -19,19 +19,19 @@ fi
# Check if the CPU supports AVX2 # Check if the CPU supports AVX2
if [[ "$(uname -m)" = "x86_64" ]]; then if [[ "$(uname -m)" = "x86_64" ]]; then
if lscpu | grep -q "Flags"; then if lscpu | grep -q "Flags"; then
if ! lscpu | grep -q "avx2"; then if ! lscpu | grep -q "avx2"; then
bashio::log.warning "NON SUPPORTED CPU DETECTED" 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 "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 "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" bashio::log.warning "You could try also Birdnet-Go which should supports your cpu"
source /home/pi/BirdNET-Pi/birdnet/bin/activate source /home/pi/BirdNET-Pi/birdnet/bin/activate
mkdir -p /home/pi/.cache/pip || true &>/dev/null mkdir -p /home/pi/.cache/pip || true &> /dev/null
chmod 777 /home/pi/.cache/pip || true &>/dev/null chmod 777 /home/pi/.cache/pip || true &> /dev/null
pip3 uninstall -y tflite_runtime pip3 uninstall -y tflite_runtime
pip install --upgrade packaging==23.2 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" 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 deactivate
fi fi
fi fi
fi fi

View File

@@ -8,10 +8,10 @@ set -eu
################## ##################
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
mkdir -p /etc/scripts-init mkdir -p /etc/scripts-init
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
sed -i "/ rm/d" /ha_entrypoint.sh sed -i "/ rm/d" /ha_entrypoint.sh
cp "${BASH_SOURCE[0]}" /etc/scripts-init/ cp "${BASH_SOURCE[0]}" /etc/scripts-init/
fi fi
############## ##############
@@ -21,71 +21,71 @@ fi
# Set password # Set password
bashio::log.info "Setting password for the user pi" bashio::log.info "Setting password for the user pi"
if bashio::config.has_value "pi_password"; then if bashio::config.has_value "pi_password"; then
echo "pi:$(bashio::config "pi_password")" | chpasswd echo "pi:$(bashio::config "pi_password")" | chpasswd
fi fi
bashio::log.info "Password set successfully for user pi." bashio::log.info "Password set successfully for user pi."
# Use timezone defined in add-on options if available # Use timezone defined in add-on options if available
bashio::log.info "Setting timezone :" bashio::log.info "Setting timezone :"
if bashio::config.has_value 'TZ'; then if bashio::config.has_value 'TZ'; then
TZ_VALUE="$(bashio::config 'TZ')" TZ_VALUE="$(bashio::config 'TZ')"
if timedatectl set-timezone "$TZ_VALUE"; then if timedatectl set-timezone "$TZ_VALUE"; then
echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)." echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)."
else 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" 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 timedatectl set-ntp true &> /dev/null
fi fi
# Use BirdNET-defined timezone if no add-on option is provided # Use BirdNET-defined timezone if no add-on option is provided
elif [ -f /data/timezone ]; then elif [ -f /data/timezone ]; then
BIRDN_CONFIG_TZ="$(cat /data/timezone)" BIRDN_CONFIG_TZ="$(cat /data/timezone)"
timedatectl set-ntp false &>/dev/null timedatectl set-ntp false &> /dev/null
if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then
echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config." echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config."
else else
bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone." bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone."
timedatectl set-ntp true &>/dev/null timedatectl set-ntp true &> /dev/null
fi fi
# Fallback to automatic timezone if no manual settings are found # Fallback to automatic timezone if no manual settings are found
else else
if timedatectl set-ntp true &>/dev/null; then if timedatectl set-ntp true &> /dev/null; then
bashio::log.info "... automatic timezone enabled." bashio::log.info "... automatic timezone enabled."
else else
bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options." bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options."
fi fi
fi || true fi || true
# Use ALSA CARD defined in add-on options if available # Use ALSA CARD defined in add-on options if available
if [ -n "${ALSA_CARD:-}" ]; then if [ -n "${ALSA_CARD:-}" ]; then
bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD" 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 for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do
if [ -f "$file" ]; then if [ -f "$file" ]; then
sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file" sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file"
fi fi
done done
fi fi
# Fix timezone as per installer # Fix timezone as per installer
CURRENT_TIMEZONE="$(timedatectl show --value --property=Timezone)" 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" bashio::log.info "Starting system services"
bashio::log.info "Starting cron service" bashio::log.info "Starting cron service"
systemctl start cron >/dev/null systemctl start cron > /dev/null
bashio::log.info "Starting dbus service" bashio::log.info "Starting dbus service"
service dbus start >/dev/null service dbus start > /dev/null
bashio::log.info "Starting BirdNET-Pi services" bashio::log.info "Starting BirdNET-Pi services"
chmod +x "$HOME/BirdNET-Pi/scripts/restart_services.sh" >/dev/null chmod +x "$HOME/BirdNET-Pi/scripts/restart_services.sh" > /dev/null
"$HOME/BirdNET-Pi/scripts/restart_services.sh" >/dev/null "$HOME/BirdNET-Pi/scripts/restart_services.sh" > /dev/null
# Start livestream services if enabled in configuration # Start livestream services if enabled in configuration
if bashio::config.true "LIVESTREAM_BOOT_ENABLED"; then if bashio::config.true "LIVESTREAM_BOOT_ENABLED"; then
echo "... starting livestream services" echo "... starting livestream services"
systemctl enable icecast2 >/dev/null systemctl enable icecast2 > /dev/null
systemctl start icecast2.service >/dev/null systemctl start icecast2.service > /dev/null
systemctl enable --now livestream.service >/dev/null systemctl enable --now livestream.service > /dev/null
fi fi
# Start # Start

View File

@@ -7,7 +7,7 @@ set +u
source /etc/birdnet/birdnet.conf source /etc/birdnet/birdnet.conf
# Create ingress configuration for Caddyfile # Create ingress configuration for Caddyfile
cat <<EOF >>/etc/caddy/Caddyfile cat << EOF >> /etc/caddy/Caddyfile
:8082 { :8082 {
root * ${EXTRACTED} root * ${EXTRACTED}
file_server browse file_server browse

View File

@@ -7,9 +7,9 @@ set -e
#################### ####################
if [ -d /homeassistant/addons_config/calibre ]; then if [ -d /homeassistant/addons_config/calibre ]; then
echo "Moving database to new location /config" echo "Moving database to new location /config"
cp -rf /homeassistant/addons_config/calibre/* /config/ cp -rf /homeassistant/addons_config/calibre/* /config/
rm -r /homeassistant/addons_config/calibre rm -r /homeassistant/addons_config/calibre
fi fi
# Legacy path # Legacy path

View File

@@ -11,23 +11,23 @@ PGID=$(bashio::config "PGID")
LOCATION=$(bashio::config 'data_location') LOCATION=$(bashio::config 'data_location')
if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then
# Default location # Default location
LOCATION="/config" LOCATION="/config"
else 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 # Check if config is located in an acceptable location
LOCATIONOK="" LOCATIONOK=""
for location in "/share" "/config" "/data" "/mnt"; do for location in "/share" "/config" "/data" "/mnt"; do
if [[ "$LOCATION" == "$location"* ]]; then if [[ "$LOCATION" == "$location"* ]]; then
LOCATIONOK=true LOCATIONOK=true
fi fi
done done
if [ -z "$LOCATIONOK" ]; then if [ -z "$LOCATIONOK" ]; then
LOCATION="/config" 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" 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
fi fi
@@ -36,29 +36,29 @@ bashio::log.info "Setting data location to $LOCATION"
# Correct home locations # Correct home locations
for file in /etc/s6-overlay/s6-rc.d/*/run; do for file in /etc/s6-overlay/s6-rc.d/*/run; do
if [ "$(sed -n '1{/bash/p};q' "$file")" ]; then if [ "$(sed -n '1{/bash/p};q' "$file")" ]; then
sed -i "1a export HOME=$LOCATION" "$file" sed -i "1a export HOME=$LOCATION" "$file"
sed -i "1a export FM_HOME=$LOCATION" "$file" sed -i "1a export FM_HOME=$LOCATION" "$file"
fi fi
done done
# Correct home location # Correct home location
for folders in /defaults /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d; do for folders in /defaults /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d; do
if [ -d "$folders" ]; then if [ -d "$folders" ]; then
sed -i "s|/config|$LOCATION|g" $(find "$folders" -type f) &>/dev/null || true sed -i "s|/config|$LOCATION|g" $(find "$folders" -type f) &> /dev/null || true
fi fi
done done
# Change user home # Change user home
usermod --home "$LOCATION" abc usermod --home "$LOCATION" abc
# Add environment variables # 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/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/FM_HOME; fi
{ {
printf "%s\n" "HOME=\"$LOCATION\"" printf "%s\n" "HOME=\"$LOCATION\""
printf "%s\n" "FM_HOME=\"$LOCATION\"" printf "%s\n" "FM_HOME=\"$LOCATION\""
} >>~/.bashrc } >> ~/.bashrc
# Create folder # Create folder
echo "Creating $LOCATION" echo "Creating $LOCATION"

View File

@@ -5,50 +5,50 @@ set -e
# Install specific apps # Install specific apps
if bashio::config.has_value 'additional_apps'; then if bashio::config.has_value 'additional_apps'; then
bashio::log.info "Installing additional apps :" bashio::log.info "Installing additional apps :"
# hadolint ignore=SC2005 # hadolint ignore=SC2005
NEWAPPS=$(bashio::config 'additional_apps') NEWAPPS=$(bashio::config 'additional_apps')
for packagestoinstall in ${NEWAPPS//,/ }; do for packagestoinstall in ${NEWAPPS//,/ }; do
bashio::log.green "... $packagestoinstall" bashio::log.green "... $packagestoinstall"
if command -v "apk" &>/dev/null; then if command -v "apk" &> /dev/null; then
apk add --no-cache "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") apk add --no-cache "$packagestoinstall" &> /dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
elif command -v "apt" &>/dev/null; then elif command -v "apt" &> /dev/null; then
apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") apt-get install -yqq --no-install-recommends "$packagestoinstall" &> /dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
elif command -v "pacman" &>/dev/null; then elif command -v "pacman" &> /dev/null; then
pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found") pacman --noconfirm -S "$packagestoinstall" &> /dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
fi fi
done done
fi fi
# Set TZ # Set TZ
if bashio::config.has_value 'TZ'; then if bashio::config.has_value 'TZ'; then
TIMEZONE=$(bashio::config 'TZ') TIMEZONE=$(bashio::config 'TZ')
bashio::log.info "Setting timezone to $TIMEZONE" bashio::log.info "Setting timezone to $TIMEZONE"
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
echo "$TIMEZONE" >/etc/timezone 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") 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 # Set cli args
if bashio::config.has_value 'CLI_ARGS'; then if bashio::config.has_value 'CLI_ARGS'; then
bashio::log.info "Setting password to the value defined in options" bashio::log.info "Setting password to the value defined in options"
CLI_ARGS=$(bashio::config 'CLI_ARGS') CLI_ARGS=$(bashio::config 'CLI_ARGS')
bashio::log.info "Setting arguments to $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 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 printf "%s\n" "CLI_ARGS=\"$CLI_ARGS\"" >> ~/.bashrc
fi || true fi || true
# Set keyboard # Set keyboard
if bashio::config.has_value 'KEYBOARD'; then if bashio::config.has_value 'KEYBOARD'; then
KEYBOARD=$(bashio::config 'KEYBOARD') KEYBOARD=$(bashio::config 'KEYBOARD')
bashio::log.info "Setting keyboard to $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 if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" > /var/run/s6/container_environment/KEYBOARD; fi
printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >>~/.bashrc printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >> ~/.bashrc
fi || true fi || true
# Set password # Set password
if bashio::config.has_value 'PASSWORD'; then if bashio::config.has_value 'PASSWORD'; then
bashio::log.info "Setting password to the value defined in options" bashio::log.info "Setting password to the value defined in options"
PASSWORD=$(bashio::config 'PASSWORD') PASSWORD=$(bashio::config 'PASSWORD')
passwd -d abc passwd -d abc
echo -e "$PASSWORD\n$PASSWORD" | passwd abc echo -e "$PASSWORD\n$PASSWORD" | passwd abc
fi || true fi || true

View File

@@ -9,7 +9,7 @@ SUBFOLDER="$(bashio::addon.ingress_entry)"
# Copy template # Copy template
cp /defaults/default.conf "${NGINX_CONFIG}" cp /defaults/default.conf "${NGINX_CONFIG}"
# Remove ssl part # Remove ssl part
awk -v n=4 '/server/{n--}; n > 0' "${NGINX_CONFIG}" >tmpfile awk -v n=4 '/server/{n--}; n > 0' "${NGINX_CONFIG}" > tmpfile
mv tmpfile "${NGINX_CONFIG}" mv tmpfile "${NGINX_CONFIG}"
# Remove ipv6 # Remove ipv6

View File

@@ -7,9 +7,9 @@ set -e
#################### ####################
if [ -d /homeassistant/addons_config/calibre-web ] && [ ! -L /homeassistant/addons_config/calibre-web ]; then if [ -d /homeassistant/addons_config/calibre-web ] && [ ! -L /homeassistant/addons_config/calibre-web ]; then
if [ "$(ls -A /homeassistant/addons_config/calibre-web)" ]; then if [ "$(ls -A /homeassistant/addons_config/calibre-web)" ]; then
echo "Moving database to new location /config" echo "Moving database to new location /config"
cp -rf /homeassistant/addons_config/calibre-web/* "$LOCATION"/ cp -rf /homeassistant/addons_config/calibre-web/* "$LOCATION"/
fi fi
rm -r /homeassistant/addons_config/calibre-web rm -r /homeassistant/addons_config/calibre-web
fi fi

View File

@@ -10,23 +10,23 @@ PGID=$(bashio::config "PGID")
LOCATION=$(bashio::config 'data_location') LOCATION=$(bashio::config 'data_location')
if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then
# Default location # Default location
LOCATION="/config" LOCATION="/config"
else 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 # Check if config is located in an acceptable location
LOCATIONOK="" LOCATIONOK=""
for location in "/share" "/config" "/data" "/mnt"; do for location in "/share" "/config" "/data" "/mnt"; do
if [[ "$LOCATION" == "$location"* ]]; then if [[ "$LOCATION" == "$location"* ]]; then
LOCATIONOK=true LOCATIONOK=true
fi fi
done done
if [ -z "$LOCATIONOK" ]; then if [ -z "$LOCATIONOK" ]; then
LOCATION=/config 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" 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
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" /defaults/*
sed -i "s|/config|$LOCATION|g" /etc/cont-init.d/* sed -i "s|/config|$LOCATION|g" /etc/cont-init.d/*
sed -i "s|/config|$LOCATION|g" /etc/services.d/*/run 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/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/FM_HOME; fi
printf "%s\n" "HOME=\"$LOCATION\"" >>~/.bashrc printf "%s\n" "HOME=\"$LOCATION\"" >> ~/.bashrc
printf "%s\n" "FM_HOME=\"$LOCATION\"" >>~/.bashrc printf "%s\n" "FM_HOME=\"$LOCATION\"" >> ~/.bashrc
usermod --home "$LOCATION" abc usermod --home "$LOCATION" abc

View File

@@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
if [ ! -d /config ]; then if [ ! -d /config ]; then
echo "Creating /config" echo "Creating /config"
mkdir -p /config mkdir -p /config
fi fi
chown -R "$PUID:$PGID" /config chown -R "$PUID:$PGID" /config

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
if [ -f /etc/cont-init.d/00-smb_mounts.sh ]; then 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 fi

View File

@@ -42,7 +42,7 @@ declare ingress_port
ingress_user='admin' ingress_user='admin'
if bashio::config.has_value 'ingress_user'; then if bashio::config.has_value 'ingress_user'; then
ingress_user=$(bashio::config 'ingress_user') ingress_user=$(bashio::config 'ingress_user')
fi fi
ingress_port=$(bashio::addon.ingress_port) ingress_port=$(bashio::addon.ingress_port)

View File

@@ -5,19 +5,19 @@ set -e
# Set TZ # Set TZ
if bashio::config.has_value 'TZ'; then if bashio::config.has_value 'TZ'; then
TIMEZONE=$(bashio::config 'TZ') TIMEZONE=$(bashio::config 'TZ')
bashio::log.info "Setting timezone to $TIMEZONE" bashio::log.info "Setting timezone to $TIMEZONE"
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime && echo "$TIMEZONE" >/etc/timezone ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime && echo "$TIMEZONE" > /etc/timezone
fi fi
bashio::log.info "Install libnss3" bashio::log.info "Install libnss3"
apt-get update && apt-get install libnss3 &>/dev/null apt-get update && apt-get install libnss3 &> /dev/null
# Set Ingress login # Set Ingress login
if [ ! -f /config/app.db ]; then 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 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 fi
bashio::log.info "Default username:password is admin:admin123" bashio::log.info "Default username:password is admin:admin123"

0
calibre_web/rootfs/etc/services.d/nginx/run Normal file → Executable file
View File

View File

@@ -7,9 +7,9 @@ set -e
#################### ####################
if [ -f /homeassistant/addons_config/cloudcommander ]; then if [ -f /homeassistant/addons_config/cloudcommander ]; then
echo "Moving database to new location /config" echo "Moving database to new location /config"
cp -rnf /homeassistant/addons_config/cloudcommander/* /config/ || true cp -rnf /homeassistant/addons_config/cloudcommander/* /config/ || true
rm -r /homeassistant/addons_config/cloudcommander rm -r /homeassistant/addons_config/cloudcommander
fi fi
###################### ######################
@@ -22,12 +22,12 @@ find /homeassistant/addons_config -maxdepth 1 -type l -delete
# Remove erroneous folders # Remove erroneous folders
if [ -d /homeassistant ]; then if [ -d /homeassistant ]; then
if [ -d /config/addons_config ]; then if [ -d /config/addons_config ]; then
rm -r /config/addons_config rm -r /config/addons_config
fi fi
if [ -d /config/addons_autoscripts ]; then if [ -d /config/addons_autoscripts ]; then
rm -r /config/addons_autoscripts rm -r /config/addons_autoscripts
fi fi
fi fi
# Create symlinks # Create symlinks
@@ -50,8 +50,8 @@ export CLOUDCMD_PREFIX
declare ADDON_PROTOCOL=http declare ADDON_PROTOCOL=http
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
ADDON_PROTOCOL=https ADDON_PROTOCOL=https
bashio::config.require.ssl bashio::config.require.ssl
fi fi
# port=$(bashio::addon.port 80) # 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 if bashio::config.has_value 'CUSTOM_OPTIONS'; then
CUSTOMOPTIONS=" $(bashio::config 'CUSTOM_OPTIONS')" CUSTOMOPTIONS=" $(bashio::config 'CUSTOM_OPTIONS')"
else else
CUSTOMOPTIONS="" CUSTOMOPTIONS=""
fi fi
if bashio::config.has_value 'DROPBOX_TOKEN'; then 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 else
DROPBOX_TOKEN="" DROPBOX_TOKEN=""
fi fi
bashio::log.info "Starting..." bashio::log.info "Starting..."

View File

@@ -19,39 +19,39 @@ urls+=("$(bashio::jq "$result" '.external_url' | cut -d'/' -f3 | cut -d':' -f1)"
# Get supported interfaces # Get supported interfaces
for interface in $(bashio::network.interfaces); do for interface in $(bashio::network.interfaces); do
urls+=("$(bashio::network.ipv6_address "${interface}" | cut -d'/' -f1)") urls+=("$(bashio::network.ipv6_address "${interface}" | cut -d'/' -f1)")
urls+=("$(bashio::network.ipv4_address "${interface}" | cut -d'/' -f1)") urls+=("$(bashio::network.ipv4_address "${interface}" | cut -d'/' -f1)")
done done
if bashio::config.has_value 'csrf_allowed'; then 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 while read -r line; do
urls+=("$line") urls+=("$line")
done <<<"$(bashio::config 'csrf_allowed')" done <<< "$(bashio::config 'csrf_allowed')"
fi fi
# Add internal and external URL as it # Add internal and external URL as it
if [[ "$(bashio::jq "$result" '.external_url')" != "null" ]]; then if [[ "$(bashio::jq "$result" '.external_url')" != "null" ]]; then
CSRF=$(bashio::jq "$result" '.external_url') CSRF=$(bashio::jq "$result" '.external_url')
fi fi
if [[ "$(bashio::jq "$result" '.internal_url')" != "null" ]]; then if [[ "$(bashio::jq "$result" '.internal_url')" != "null" ]]; then
CSRF=$(bashio::jq "$result" '.internal_url'),${CSRF} CSRF=$(bashio::jq "$result" '.internal_url'),${CSRF}
fi fi
# Loop through URls to add them in the CSRF string # Loop through URls to add them in the CSRF string
for url in "${urls[@]}"; do for url in "${urls[@]}"; do
if bashio::var.has_value "${url}"; then if bashio::var.has_value "${url}"; then
if [[ "${url}" != "null" ]] && [[ "${url}" != "null.local" ]]; then if [[ "${url}" != "null" ]] && [[ "${url}" != "null.local" ]]; then
CSRF="https://${url}:${port},http://${url}:${port},https://${url},http://${url}",${CSRF} CSRF="https://${url}:${port},http://${url}:${port},https://${url},http://${url}",${CSRF}
if bashio::var.has_value "$(bashio::addon.port 9810)"; then if bashio::var.has_value "$(bashio::addon.port 9810)"; then
CSRF="https://${url}:${addon_port},http://${url}:${addon_port}",${CSRF} CSRF="https://${url}:${addon_port},http://${url}:${addon_port}",${CSRF}
fi fi
fi fi
fi fi
done done
CSRF=${CSRF::-1} CSRF=${CSRF::-1}
# Save CSFR # 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}" bashio::log.blue "PAPERLESS_CSRF_TRUSTED_ORIGINS is set to ${CSRF}"

View File

@@ -6,14 +6,14 @@
############ ############
if bashio::config.has_value 'TZ'; then if bashio::config.has_value 'TZ'; then
TIMEZONE=$(bashio::config 'TZ') TIMEZONE=$(bashio::config 'TZ')
bashio::log.info "Setting timezone to $TIMEZONE" bashio::log.info "Setting timezone to $TIMEZONE"
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
echo "$TIMEZONE" >/etc/timezone echo "$TIMEZONE" > /etc/timezone
else else
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
fi fi
fi fi
################# #################
@@ -32,7 +32,7 @@ export FB_BASEURL
declare ADDON_PROTOCOL=http declare ADDON_PROTOCOL=http
# Generate Ingress configuration # Generate Ingress configuration
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
ADDON_PROTOCOL=https ADDON_PROTOCOL=https
fi fi
#port=$(bashio::addon.port 80) #port=$(bashio::addon.port 80)
@@ -46,10 +46,10 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
# Correct baseurl # Correct baseurl
for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do
if [ -f "$file" ]; then if [ -f "$file" ]; then
sed -i "/root_path/d" "$file" sed -i "/root_path/d" "$file"
sed -i "1a root_path = \"${FB_BASEURL}\"" "$file" sed -i "1a root_path = \"${FB_BASEURL}\"" "$file"
fi fi
done done
############## ##############

View File

@@ -6,14 +6,14 @@
############ ############
if bashio::config.has_value 'TZ'; then if bashio::config.has_value 'TZ'; then
TIMEZONE=$(bashio::config 'TZ') TIMEZONE=$(bashio::config 'TZ')
bashio::log.info "Setting timezone to $TIMEZONE" bashio::log.info "Setting timezone to $TIMEZONE"
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
echo "$TIMEZONE" >/etc/timezone echo "$TIMEZONE" > /etc/timezone
else else
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
fi fi
fi fi
################# #################
@@ -22,37 +22,37 @@ fi
INGRESS="false" INGRESS="false"
if [[ "$INGRESS" == "true" ]]; then if [[ "$INGRESS" == "true" ]]; then
#declare port #declare port
#declare certfile #declare certfile
declare ingress_interface declare ingress_interface
declare ingress_port declare ingress_port
#declare keyfile #declare keyfile
FB_BASEURL="$(bashio::addon.ingress_entry)" FB_BASEURL="$(bashio::addon.ingress_entry)"
export FB_BASEURL export FB_BASEURL
declare ADDON_PROTOCOL=http declare ADDON_PROTOCOL=http
# Generate Ingress configuration # Generate Ingress configuration
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
ADDON_PROTOCOL=https ADDON_PROTOCOL=https
fi fi
#port=$(bashio::addon.port 80) #port=$(bashio::addon.port 80)
ingress_port=$(bashio::addon.ingress_port) ingress_port=$(bashio::addon.ingress_port)
ingress_interface=$(bashio::addon.ip_address) ingress_interface=$(bashio::addon.ip_address)
sed -i "s|%%protocol%%|${ADDON_PROTOCOL}|g" /etc/nginx/servers/ingress.conf 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|%%port%%|${ingress_port}|g" /etc/nginx/servers/ingress.conf
sed -i "s|%%interface%%|${ingress_interface}|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 sed -i "s|%%subpath%%|${FB_BASEURL}/|g" /etc/nginx/servers/ingress.conf
mkdir -p /var/log/nginx && touch /var/log/nginx/error.log mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
# Correct baseurl # Correct baseurl
for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do
if [ -f "$file" ]; then if [ -f "$file" ]; then
sed -i "/root_path/d" "$file" sed -i "/root_path/d" "$file"
sed -i "1a root_path = \"${FB_BASEURL}\"" "$file" sed -i "1a root_path = \"${FB_BASEURL}\"" "$file"
fi fi
done done
fi fi
########### ###########

View File

@@ -5,52 +5,52 @@ set -e
data_location="${data_location:-/share/emby}" data_location="${data_location:-/share/emby}"
config_location="/config/emby" config_location="/config/emby"
log() { log() {
bashio::log.info "$1" bashio::log.info "$1"
} }
log "Updating folder structure and permission : data stored in $data_location" log "Updating folder structure and permission : data stored in $data_location"
declare -A directories=( declare -A directories=(
["/emby"]="" ["/emby"]=""
["/share/storage/tv"]="" ["/share/storage/tv"]=""
["/share/storage/movies"]="" ["/share/storage/movies"]=""
["$data_location"]="" ["$data_location"]=""
["$config_location"]="" ["$config_location"]=""
) )
for dir in "${!directories[@]}"; do for dir in "${!directories[@]}"; do
log "Creating directory: $dir" log "Creating directory: $dir"
mkdir -p "$dir" mkdir -p "$dir"
chown -R "$PUID:$PGID" "$dir" chown -R "$PUID:$PGID" "$dir"
done done
if [ -d /homeassistant/emby ]; then if [ -d /homeassistant/emby ]; then
log "Migrate previous config location" log "Migrate previous config location"
cp -rf /homeassistant/emby/* "$config_location"/ cp -rf /homeassistant/emby/* "$config_location"/
mv /homeassistant/emby /homeassistant/emby_migrated mv /homeassistant/emby /homeassistant/emby_migrated
chown -R "$PUID:$PGID" "$config_location" chown -R "$PUID:$PGID" "$config_location"
fi fi
if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then
cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/ cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/
mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh
fi fi
declare -A links=( declare -A links=(
["/emby/cache"]="$data_location/cache" ["/emby/cache"]="$data_location/cache"
["/emby/config"]="$config_location" ["/emby/config"]="$config_location"
["/emby/data"]="$data_location/data" ["/emby/data"]="$data_location/data"
["/emby/logs"]="$data_location/logs" ["/emby/logs"]="$data_location/logs"
["/emby/metadata"]="$data_location/metadata" ["/emby/metadata"]="$data_location/metadata"
["/emby/plugins"]="$data_location/plugins" ["/emby/plugins"]="$data_location/plugins"
["/emby/root"]="$data_location/root" ["/emby/root"]="$data_location/root"
) )
for link in "${!links[@]}"; do for link in "${!links[@]}"; do
if [ ! -d "$link" ]; then if [ ! -d "$link" ]; then
log "Creating link for $link" log "Creating link for $link"
mkdir -p "${links[$link]}" mkdir -p "${links[$link]}"
chown -R "$PUID:$PGID" "${links[$link]}" chown -R "$PUID:$PGID" "${links[$link]}"
ln -s "${links[$link]}" "$link" ln -s "${links[$link]}" "$link"
fi fi
done done

View File

@@ -7,7 +7,7 @@ set -e
############### ###############
if bashio::config.true 'silent'; then if bashio::config.true 'silent'; then
APPEND=' >/dev/null' APPEND=' >/dev/null'
sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run 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.' bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
fi fi

0
emby/rootfs/etc/services.d/nginx/run Normal file → Executable file
View File

View File

@@ -5,52 +5,52 @@ set -e
data_location="${data_location:-/share/emby}" data_location="${data_location:-/share/emby}"
config_location="/config/emby" config_location="/config/emby"
log() { log() {
bashio::log.info "$1" bashio::log.info "$1"
} }
log "Updating folder structure and permission : data stored in $data_location" log "Updating folder structure and permission : data stored in $data_location"
declare -A directories=( declare -A directories=(
["/emby"]="" ["/emby"]=""
["/share/storage/tv"]="" ["/share/storage/tv"]=""
["/share/storage/movies"]="" ["/share/storage/movies"]=""
["$data_location"]="" ["$data_location"]=""
["$config_location"]="" ["$config_location"]=""
) )
for dir in "${!directories[@]}"; do for dir in "${!directories[@]}"; do
log "Creating directory: $dir" log "Creating directory: $dir"
mkdir -p "$dir" mkdir -p "$dir"
chown -R "$PUID:$PGID" "$dir" chown -R "$PUID:$PGID" "$dir"
done done
if [ -d /homeassistant/emby ]; then if [ -d /homeassistant/emby ]; then
log "Migrate previous config location" log "Migrate previous config location"
cp -rf /homeassistant/emby/* "$config_location"/ cp -rf /homeassistant/emby/* "$config_location"/
mv /homeassistant/emby /homeassistant/emby_migrated mv /homeassistant/emby /homeassistant/emby_migrated
chown -R "$PUID:$PGID" "$config_location" chown -R "$PUID:$PGID" "$config_location"
fi fi
if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then
cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/ cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/
mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh
fi fi
declare -A links=( declare -A links=(
["/emby/cache"]="$data_location/cache" ["/emby/cache"]="$data_location/cache"
["/emby/config"]="$config_location" ["/emby/config"]="$config_location"
["/emby/data"]="$data_location/data" ["/emby/data"]="$data_location/data"
["/emby/logs"]="$data_location/logs" ["/emby/logs"]="$data_location/logs"
["/emby/metadata"]="$data_location/metadata" ["/emby/metadata"]="$data_location/metadata"
["/emby/plugins"]="$data_location/plugins" ["/emby/plugins"]="$data_location/plugins"
["/emby/root"]="$data_location/root" ["/emby/root"]="$data_location/root"
) )
for link in "${!links[@]}"; do for link in "${!links[@]}"; do
if [ ! -d "$link" ]; then if [ ! -d "$link" ]; then
log "Creating link for $link" log "Creating link for $link"
mkdir -p "${links[$link]}" mkdir -p "${links[$link]}"
chown -R "$PUID:$PGID" "${links[$link]}" chown -R "$PUID:$PGID" "${links[$link]}"
ln -s "${links[$link]}" "$link" ln -s "${links[$link]}" "$link"
fi fi
done done

View File

@@ -7,7 +7,7 @@ set -e
############### ###############
if bashio::config.true 'silent'; then if bashio::config.true 'silent'; then
APPEND=' >/dev/null' APPEND=' >/dev/null'
sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run 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.' bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
fi fi

0
emby_beta/rootfs/etc/services.d/nginx/run Normal file → Executable file
View File

View File

@@ -8,21 +8,21 @@ set -e
##################### #####################
if bashio::config.true 'mqtt_autodiscover'; then if bashio::config.true 'mqtt_autodiscover'; then
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
# Check if available # Check if available
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
# Get variables # Get variables
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." 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_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_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_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_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 MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'"
# Export variables # 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 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 sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2> /dev/null || true
# Log # Log
bashio::log.blue "$variables" bashio::log.blue "$variables"
done done
fi fi

View File

@@ -10,7 +10,7 @@ set -e
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
# Check CONFIGSOURCE ends with config.yaml # Check CONFIGSOURCE ends with config.yaml
if [ "$(basename "$CONFIGSOURCE")" != "config.yaml" ]; then 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 fi
DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db" DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db"
@@ -22,8 +22,8 @@ chmod 777 -R "$(dirname "${DATABASESOURCE}")"
# Check absence of config file # Check absence of config file
if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then 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" bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
mv /data/config.yaml "$CONFIGSOURCE".bak mv /data/config.yaml "$CONFIGSOURCE".bak
fi fi
######################################################### #########################################################
@@ -31,24 +31,24 @@ fi
######################################################### #########################################################
if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then
mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/ mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/
rm -r /config/addons_config/enedisgateway2mqtt_dev rm -r /config/addons_config/enedisgateway2mqtt_dev
fi fi
# If migration was performed, save file in config folder # If migration was performed, save file in config folder
if [ -f /data/enedisgateway.db.migrate ]; then if [ -f /data/enedisgateway.db.migrate ]; then
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")" bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")" mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
fi fi
# If migration was performed, save file in config folder # If migration was performed, save file in config folder
if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")" mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
fi fi
# If migration was not performed, enable migration # If migration was not performed, enable migration
if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then
mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data
fi fi
############ ############
@@ -57,15 +57,15 @@ fi
# Check if database is here or create symlink # Check if database is here or create symlink
if [ -f "$DATABASESOURCE" ]; then if [ -f "$DATABASESOURCE" ]; then
# Create symlink if not existing yet # Create symlink if not existing yet
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink" ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")" bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
else else
# Create symlink for addon to create database # Create symlink for addon to create database
mkdir -p "$(dirname "$DATABASESOURCE")" mkdir -p "$(dirname "$DATABASESOURCE")"
touch "${DATABASESOURCE}" touch "${DATABASESOURCE}"
ln -sf "$DATABASESOURCE" /data ln -sf "$DATABASESOURCE" /data
rm "$DATABASESOURCE" rm "$DATABASESOURCE"
fi fi
########## ##########
@@ -74,28 +74,28 @@ fi
# Check if config file is there, or create one from template # Check if config file is there, or create one from template
if [ -f "$CONFIGSOURCE" ]; then if [ -f "$CONFIGSOURCE" ]; then
# Create symlink if not existing yet # Create symlink if not existing yet
# shellcheck disable=SC2015 # shellcheck disable=SC2015
[ -f /data/config.yaml ] && rm /data/config.yaml || true [ -f /data/config.yaml ] && rm /data/config.yaml || true
ln -sf "$CONFIGSOURCE" /data || true ln -sf "$CONFIGSOURCE" /data || true
bashio::log.info "Using config file found in $CONFIGSOURCE" bashio::log.info "Using config file found in $CONFIGSOURCE"
# Check if yaml is valid # Check if yaml is valid
EXIT_CODE=0 EXIT_CODE=0
yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$? yamllint -d relaxed "$CONFIGSOURCE" &> ERROR || EXIT_CODE=$?
if [ "$EXIT_CODE" = 0 ]; then if [ "$EXIT_CODE" = 0 ]; then
echo "Config file is a valid yaml" echo "Config file is a valid yaml"
else else
cat ERROR 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" 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 fi
else else
# Create symlink for addon to create config # Create symlink for addon to create config
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/ cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/
ln -sf "$CONFIGSOURCE" /data ln -sf "$CONFIGSOURCE" /data
rm "$CONFIGSOURCE" rm "$CONFIGSOURCE"
# Need to restart # 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." 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 fi
############## ##############

View File

@@ -8,21 +8,21 @@ set -e
##################### #####################
if bashio::config.true 'mqtt_autodiscover'; then if bashio::config.true 'mqtt_autodiscover'; then
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
# Check if available # Check if available
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
# Get variables # Get variables
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." 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_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_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_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_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 MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'"
# Export variables # 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 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 sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2> /dev/null || true
# Log # Log
bashio::log.blue "$variables" bashio::log.blue "$variables"
done done
fi fi

View File

@@ -10,7 +10,7 @@ set -e
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
# Check CONFIGSOURCE ends with config.yaml # Check CONFIGSOURCE ends with config.yaml
if [ "$(basename "$CONFIGSOURCE")" != "config.yaml" ]; then 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 fi
DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db" DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db"
@@ -22,8 +22,8 @@ chmod 777 -R "$(dirname "${DATABASESOURCE}")"
# Check absence of config file # Check absence of config file
if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then 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" bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
mv /data/config.yaml "$CONFIGSOURCE".bak mv /data/config.yaml "$CONFIGSOURCE".bak
fi fi
######################################################### #########################################################
@@ -31,24 +31,24 @@ fi
######################################################### #########################################################
if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then
mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/ mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/
rm -r /config/addons_config/enedisgateway2mqtt_dev rm -r /config/addons_config/enedisgateway2mqtt_dev
fi fi
# If migration was performed, save file in config folder # If migration was performed, save file in config folder
if [ -f /data/enedisgateway.db.migrate ]; then if [ -f /data/enedisgateway.db.migrate ]; then
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")" bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")" mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
fi fi
# If migration was performed, save file in config folder # If migration was performed, save file in config folder
if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")" mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
fi fi
# If migration was not performed, enable migration # If migration was not performed, enable migration
if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then
mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data
fi fi
############ ############
@@ -57,15 +57,15 @@ fi
# Check if database is here or create symlink # Check if database is here or create symlink
if [ -f "$DATABASESOURCE" ]; then if [ -f "$DATABASESOURCE" ]; then
# Create symlink if not existing yet # Create symlink if not existing yet
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink" ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")" bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
else else
# Create symlink for addon to create database # Create symlink for addon to create database
mkdir -p "$(dirname "$DATABASESOURCE")" mkdir -p "$(dirname "$DATABASESOURCE")"
touch "${DATABASESOURCE}" touch "${DATABASESOURCE}"
ln -sf "$DATABASESOURCE" /data ln -sf "$DATABASESOURCE" /data
rm "$DATABASESOURCE" rm "$DATABASESOURCE"
fi fi
########## ##########
@@ -74,28 +74,28 @@ fi
# Check if config file is there, or create one from template # Check if config file is there, or create one from template
if [ -f "$CONFIGSOURCE" ]; then if [ -f "$CONFIGSOURCE" ]; then
# Create symlink if not existing yet # Create symlink if not existing yet
# shellcheck disable=SC2015 # shellcheck disable=SC2015
[ -f /data/config.yaml ] && rm /data/config.yaml || true [ -f /data/config.yaml ] && rm /data/config.yaml || true
ln -sf "$CONFIGSOURCE" /data || true ln -sf "$CONFIGSOURCE" /data || true
bashio::log.info "Using config file found in $CONFIGSOURCE" bashio::log.info "Using config file found in $CONFIGSOURCE"
# Check if yaml is valid # Check if yaml is valid
EXIT_CODE=0 EXIT_CODE=0
yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$? yamllint -d relaxed "$CONFIGSOURCE" &> ERROR || EXIT_CODE=$?
if [ "$EXIT_CODE" = 0 ]; then if [ "$EXIT_CODE" = 0 ]; then
echo "Config file is a valid yaml" echo "Config file is a valid yaml"
else else
cat ERROR 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" 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 fi
else else
# Create symlink for addon to create config # Create symlink for addon to create config
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/ cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/
ln -sf "$CONFIGSOURCE" /data ln -sf "$CONFIGSOURCE" /data
rm "$CONFIGSOURCE" rm "$CONFIGSOURCE"
# Need to restart # 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." 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 fi
############## ##############

View File

@@ -104,11 +104,6 @@
"DAC_READ_SEARCH" "DAC_READ_SEARCH"
], ],
"schema": { "schema": {
"cifsdomain": "str?",
"cifspassword": "str?",
"cifsusername": "str?",
"localdisks": "str?",
"networkdisks": "str?",
"DB_DATABASE_NAME": "str?", "DB_DATABASE_NAME": "str?",
"DB_HOSTNAME": "str?", "DB_HOSTNAME": "str?",
"DB_PASSWORD": "str", "DB_PASSWORD": "str",
@@ -120,7 +115,12 @@
"MINIO_ROOT_PASSWORD": "str", "MINIO_ROOT_PASSWORD": "str",
"MINIO_ROOT_USER": "str", "MINIO_ROOT_USER": "str",
"TZ": "str?", "TZ": "str?",
"USE_EXTERNAL_DB": "bool?" "USE_EXTERNAL_DB": "bool?",
"cifsdomain": "str?",
"cifspassword": "str?",
"cifsusername": "str?",
"localdisks": "str?",
"networkdisks": "str?"
}, },
"slug": "ente", "slug": "ente",
"udev": true, "udev": true,

240
ente/rootfs/etc/cont-init.d/99-run.sh Executable file → Normal file
View File

@@ -36,34 +36,34 @@ DB_PORT_EXT="$(bashio::config 'DB_PORT' || echo '')"
USE_EXTERNAL_DB=false USE_EXTERNAL_DB=false
if bashio::config.true 'USE_EXTERNAL_DB'; then if bashio::config.true 'USE_EXTERNAL_DB'; then
USE_EXTERNAL_DB=true USE_EXTERNAL_DB=true
bashio::log.warning "USE_EXTERNAL_DB enabled: will connect to external Postgres." bashio::log.warning "USE_EXTERNAL_DB enabled: will connect to external Postgres."
else else
bashio::log.info "Using internal Postgres." bashio::log.info "Using internal Postgres."
fi fi
DISABLE_WEB_UI=false DISABLE_WEB_UI=false
if bashio::config.true 'DISABLE_WEB_UI'; then if bashio::config.true 'DISABLE_WEB_UI'; then
DISABLE_WEB_UI=true DISABLE_WEB_UI=true
fi fi
# Active DB connection target (may be overridden below) # Active DB connection target (may be overridden below)
if $USE_EXTERNAL_DB; then if $USE_EXTERNAL_DB; then
DB_HOST="$DB_HOST_EXT" DB_HOST="$DB_HOST_EXT"
DB_PORT="$DB_PORT_EXT" DB_PORT="$DB_PORT_EXT"
else else
DB_HOST="$DB_HOST_INTERNAL" DB_HOST="$DB_HOST_INTERNAL"
DB_PORT="$DB_PORT_INTERNAL" DB_PORT="$DB_PORT_INTERNAL"
fi fi
############################################ ############################################
# Ensure persistent dirs # Ensure persistent dirs
############################################ ############################################
mkdir -p /config/ente/custom-logs \ mkdir -p /config/ente/custom-logs \
/config/data \ /config/data \
/config/minio-data \ /config/minio-data \
"$PGDATA" \ "$PGDATA" \
/config/scripts/compose /config/scripts/compose
############################################ ############################################
# Locate binaries # Locate binaries
@@ -75,18 +75,18 @@ MC_BIN="/usr/local/bin/mc"
MUSEUM_BIN="$(command -v museum || true)" MUSEUM_BIN="$(command -v museum || true)"
[ -z "$MUSEUM_BIN" ] && [ -x /app/museum ] && MUSEUM_BIN=/app/museum [ -z "$MUSEUM_BIN" ] && [ -x /app/museum ] && MUSEUM_BIN=/app/museum
[ -z "$MUSEUM_BIN" ] && [ -x /museum ] && MUSEUM_BIN=/museum [ -z "$MUSEUM_BIN" ] && [ -x /museum ] && MUSEUM_BIN=/museum
[ -z "$MUSEUM_BIN" ] && MUSEUM_BIN=museum # fallback in PATH [ -z "$MUSEUM_BIN" ] && MUSEUM_BIN=museum # fallback in PATH
############################################ ############################################
# Config generation # Config generation
############################################ ############################################
create_config() { create_config() {
bashio::log.info "Generating new museum config at $CFG" bashio::log.info "Generating new museum config at $CFG"
_rand_b64() { head -c "$1" /dev/urandom | base64 | tr -d '\n'; } _rand_b64() { head -c "$1" /dev/urandom | base64 | tr -d '\n'; }
_rand_b64url() { head -c "$1" /dev/urandom | base64 | tr '+/' '-_' | tr -d '\n'; } _rand_b64url() { head -c "$1" /dev/urandom | base64 | tr '+/' '-_' | tr -d '\n'; }
cat >"$CFG" <<EOF cat > "$CFG" << EOF
key: key:
encryption: $(_rand_b64 32) encryption: $(_rand_b64 32)
hash: $(_rand_b64 64) hash: $(_rand_b64 64)
@@ -116,146 +116,148 @@ EOF
# Postgres # Postgres
############################################ ############################################
start_postgres() { start_postgres() {
if $USE_EXTERNAL_DB; then if $USE_EXTERNAL_DB; then
bashio::log.info "External DB in use; not starting internal Postgres." bashio::log.info "External DB in use; not starting internal Postgres."
return 0 return 0
fi fi
mkdir -p /run/postgresql mkdir -p /run/postgresql
chown postgres:postgres /run/postgresql chown postgres:postgres /run/postgresql
chmod 775 /run/postgresql chmod 775 /run/postgresql
chown -R postgres:postgres "$PGDATA" chown -R postgres:postgres "$PGDATA"
chmod 0700 "$PGDATA" chmod 0700 "$PGDATA"
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
bashio::log.info "Initializing Postgres data directory..." bashio::log.info "Initializing Postgres data directory..."
su - postgres -c "$INITDB -D $PGDATA" su - postgres -c "$INITDB -D $PGDATA"
fi fi
bashio::log.info "Starting Postgres (${DB_HOST_INTERNAL}:${DB_PORT_INTERNAL})..." bashio::log.info "Starting Postgres (${DB_HOST_INTERNAL}:${DB_PORT_INTERNAL})..."
su - postgres -c "$POSTGRES_BIN -D $PGDATA -c listen_addresses='127.0.0.1'" & su - postgres -c "$POSTGRES_BIN -D $PGDATA -c listen_addresses='127.0.0.1'" &
PG_PID=$! PG_PID=$!
} }
wait_postgres_ready() { wait_postgres_ready() {
local host port local host port
if $USE_EXTERNAL_DB; then if $USE_EXTERNAL_DB; then
host="$DB_HOST_EXT"; port="$DB_PORT_EXT" host="$DB_HOST_EXT"
bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..." port="$DB_PORT_EXT"
else bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..."
host="$DB_HOST_INTERNAL"; port="$DB_PORT_INTERNAL" else
bashio::log.info "Waiting for internal Postgres..." host="$DB_HOST_INTERNAL"
fi port="$DB_PORT_INTERNAL"
until pg_isready -q -h "$host" -p "$port"; do sleep 1; done bashio::log.info "Waiting for internal Postgres..."
bashio::log.info "Postgres reachable." fi
until pg_isready -q -h "$host" -p "$port"; do sleep 1; done
bashio::log.info "Postgres reachable."
} }
bootstrap_internal_db() { bootstrap_internal_db() {
if $USE_EXTERNAL_DB; then if $USE_EXTERNAL_DB; then
return 0 return 0
fi fi
bashio::log.info "Ensuring role & database exist..." bashio::log.info "Ensuring role & database exist..."
local esc_pass="${DB_PASS//\'/\'\'}" local esc_pass="${DB_PASS//\'/\'\'}"
# role # role
if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \ if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
"SELECT 1 FROM pg_roles WHERE rolname = '${DB_USER}'" | grep -q 1; then "SELECT 1 FROM pg_roles WHERE rolname = '${DB_USER}'" | grep -q 1; then
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \ psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
-c "CREATE ROLE \"${DB_USER}\" LOGIN PASSWORD '${esc_pass}';" -c "CREATE ROLE \"${DB_USER}\" LOGIN PASSWORD '${esc_pass}';"
else else
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \ psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
-c "ALTER ROLE \"${DB_USER}\" PASSWORD '${esc_pass}';" -c "ALTER ROLE \"${DB_USER}\" PASSWORD '${esc_pass}';"
fi fi
# db # db
if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \ if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
"SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}'" | grep -q 1; then "SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}'" | grep -q 1; then
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \ psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
-c "CREATE DATABASE \"${DB_NAME}\" OWNER \"${DB_USER}\";" -c "CREATE DATABASE \"${DB_NAME}\" OWNER \"${DB_USER}\";"
else else
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \ psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
-c "ALTER DATABASE \"${DB_NAME}\" OWNER TO \"${DB_USER}\";" -c "ALTER DATABASE \"${DB_NAME}\" OWNER TO \"${DB_USER}\";"
fi fi
} }
############################################ ############################################
# MinIO # MinIO
############################################ ############################################
start_minio() { start_minio() {
bashio::log.info "Starting MinIO (:3200)..." bashio::log.info "Starting MinIO (:3200)..."
mkdir -p /config/minio-data mkdir -p /config/minio-data
"$MINIO_BIN" server /config/minio-data --address ":3200" & "$MINIO_BIN" server /config/minio-data --address ":3200" &
MINIO_PID=$! MINIO_PID=$!
} }
wait_minio_ready_and_bucket() { wait_minio_ready_and_bucket() {
bashio::log.info "Waiting for MinIO API..." bashio::log.info "Waiting for MinIO API..."
until "$MC_BIN" alias set h0 http://127.0.0.1:3200 "$MINIO_USER" "$MINIO_PASS" 2>/dev/null; do until "$MC_BIN" alias set h0 http://127.0.0.1:3200 "$MINIO_USER" "$MINIO_PASS" 2> /dev/null; do
sleep 1 sleep 1
done done
bashio::log.info "Ensuring buckets..." bashio::log.info "Ensuring buckets..."
"$MC_BIN" mb -p "h0/${S3_BUCKET}" || true "$MC_BIN" mb -p "h0/${S3_BUCKET}" || true
bashio::log.info "MinIO buckets ready." bashio::log.info "MinIO buckets ready."
} }
############################################ ############################################
# Web (static nginx bundle) # Web (static nginx bundle)
############################################ ############################################
start_web() { start_web() {
if $DISABLE_WEB_UI; then if $DISABLE_WEB_UI; then
bashio::log.info "Web UI disabled." bashio::log.info "Web UI disabled."
return 0 return 0
fi fi
ENTE_API_ORIGIN=http://localhost:8080 ENTE_API_ORIGIN=http://localhost:8080
ENTE_ALBUMS_ORIGIN=http://localhost:3002 ENTE_ALBUMS_ORIGIN=http://localhost:3002
export ENTE_API_ORIGIN ENTE_ALBUMS_ORIGIN export ENTE_API_ORIGIN ENTE_ALBUMS_ORIGIN
# Running ente-web-prepare # Running ente-web-prepare
echo "[ente-web-prepare] Substituting origins…" echo "[ente-web-prepare] Substituting origins…"
find /www -name '*.js' | xargs sed -i "s#ENTE_API_ORIGIN_PLACEHOLDER#${ENTE_API_ORIGIN}#g" find /www -name '*.js' | xargs sed -i "s#ENTE_API_ORIGIN_PLACEHOLDER#${ENTE_API_ORIGIN}#g"
find /www/photos -name '*.js'| xargs sed -i "s#ENTE_ALBUMS_ORIGIN_PLACEHOLDER#${ENTE_ALBUMS_ORIGIN}#g" find /www/photos -name '*.js' | xargs sed -i "s#ENTE_ALBUMS_ORIGIN_PLACEHOLDER#${ENTE_ALBUMS_ORIGIN}#g"
mkdir -p /run/nginx /var/log/nginx mkdir -p /run/nginx /var/log/nginx
# Set nginx # Set nginx
mv /etc/nginx/http.d/web.bak /etc/nginx/http.d/web.conf mv /etc/nginx/http.d/web.bak /etc/nginx/http.d/web.conf
bashio::log.info "Starting Ente web (nginx, ports 30003004)..." bashio::log.info "Starting Ente web (nginx, ports 30003004)..."
exec nginx -g 'daemon off;' & exec nginx -g 'daemon off;' &
WEB_PID=$! WEB_PID=$!
} }
############################################ ############################################
# Museum (API) # Museum (API)
############################################ ############################################
start_museum_foreground() { start_museum_foreground() {
if [ ! -f "$CFG" ]; then if [ ! -f "$CFG" ]; then
bashio::log.error "$CFG missing; cannot start museum." bashio::log.error "$CFG missing; cannot start museum."
return 1 return 1
fi fi
if [ ! -x "$MUSEUM_BIN" ] && ! command -v "$MUSEUM_BIN" >/dev/null 2>&1; then if [ ! -x "$MUSEUM_BIN" ] && ! command -v "$MUSEUM_BIN" > /dev/null 2>&1; then
bashio::log.error "Museum binary not found; cannot launch Ente API." bashio::log.error "Museum binary not found; cannot launch Ente API."
return 1 return 1
fi fi
# Force env overrides (museum merges env > yaml) # Force env overrides (museum merges env > yaml)
if $USE_EXTERNAL_DB; then if $USE_EXTERNAL_DB; then
export ENTE_DB_HOST="$DB_HOST_EXT" export ENTE_DB_HOST="$DB_HOST_EXT"
export ENTE_DB_PORT="$DB_PORT_EXT" export ENTE_DB_PORT="$DB_PORT_EXT"
else else
export ENTE_DB_HOST="$DB_HOST_INTERNAL" export ENTE_DB_HOST="$DB_HOST_INTERNAL"
export ENTE_DB_PORT="$DB_PORT_INTERNAL" export ENTE_DB_PORT="$DB_PORT_INTERNAL"
fi fi
export ENTE_DB_USER="$DB_USER" export ENTE_DB_USER="$DB_USER"
export ENTE_DB_PASSWORD="$DB_PASS" export ENTE_DB_PASSWORD="$DB_PASS"
export ENTE_DB_NAME="$DB_NAME" export ENTE_DB_NAME="$DB_NAME"
export ENTE_DB_SSLMODE=disable export ENTE_DB_SSLMODE=disable
bashio::log.info "Starting museum (foreground)..." bashio::log.info "Starting museum (foreground)..."
exec "$MUSEUM_BIN" --config "$CFG" exec "$MUSEUM_BIN" --config "$CFG"
} }
############################################ ############################################
@@ -264,9 +266,9 @@ start_museum_foreground() {
bashio::log.info "=== Ente startup sequence ===" bashio::log.info "=== Ente startup sequence ==="
if [ ! -f "$CFG" ]; then if [ ! -f "$CFG" ]; then
create_config create_config
else else
bashio::log.info "Using existing $CFG." bashio::log.info "Using existing $CFG."
fi fi
start_postgres start_postgres

View File

@@ -8,14 +8,14 @@ set -e
HOME="/config/addons_config/epicgamesfree" HOME="/config/addons_config/epicgamesfree"
if [ ! -f "$HOME"/config.json ]; then if [ ! -f "$HOME"/config.json ]; then
# Copy default config.json # Copy default config.json
cp /templates/config.json "$HOME"/config.json cp /templates/config.json "$HOME"/config.json
chmod 777 "$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" 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 sleep 5
bashio::exit.nok bashio::exit.nok
else 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 fi
# Permissions # Permissions

View File

@@ -7,9 +7,9 @@ set -e
#################### ####################
if [ -f /homeassistant/addons_config/filebrowser/filebrowser.dB ]; then if [ -f /homeassistant/addons_config/filebrowser/filebrowser.dB ]; then
echo "Moving database to new location /config" echo "Moving database to new location /config"
cp -rnf /homeassistant/addons_config/filebrowser/* /config/ cp -rnf /homeassistant/addons_config/filebrowser/* /config/
rm -r /homeassistant/addons_config/filebrowser rm -r /homeassistant/addons_config/filebrowser
fi fi
###################### ######################
@@ -19,24 +19,24 @@ fi
# Clean symlinks # Clean symlinks
find /config -maxdepth 1 -type l -delete find /config -maxdepth 1 -type l -delete
if [ -d /homeassistant/addons_config ]; then 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 fi
# Remove erroneous folders # Remove erroneous folders
if [ -d /homeassistant ]; then if [ -d /homeassistant ]; then
if [ -d /config/addons_config ]; then if [ -d /config/addons_config ]; then
rm -r /config/addons_config rm -r /config/addons_config
fi fi
if [ -d /config/addons_autoscripts ]; then if [ -d /config/addons_autoscripts ]; then
rm -r /config/addons_autoscripts rm -r /config/addons_autoscripts
fi fi
fi fi
# Create symlinks with legacy folders # Create symlinks with legacy folders
if [ -d /homeassistant/addons_config ]; then if [ -d /homeassistant/addons_config ]; then
ln -s /homeassistant/addons_config /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/ \; find /addon_configs/ -maxdepth 1 -mindepth 1 -type d -not -name "*filebrowser*" -exec ln -s {} /config/addons_config/ \;
fi fi
if [ -d /homeassistant/addons_autoscripts ]; then if [ -d /homeassistant/addons_autoscripts ]; then
ln -s /homeassistant/addons_autoscripts /config ln -s /homeassistant/addons_autoscripts /config
fi fi

View File

@@ -7,14 +7,14 @@ set -e
############ ############
if bashio::config.has_value 'TZ'; then if bashio::config.has_value 'TZ'; then
TIMEZONE=$(bashio::config 'TZ') TIMEZONE=$(bashio::config 'TZ')
bashio::log.info "Setting timezone to $TIMEZONE" bashio::log.info "Setting timezone to $TIMEZONE"
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
echo "$TIMEZONE" >/etc/timezone echo "$TIMEZONE" > /etc/timezone
else else
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?" bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
fi fi
fi fi
################### ###################
@@ -23,13 +23,13 @@ fi
bashio::config.require.ssl bashio::config.require.ssl
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths" bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths"
#set variables #set variables
CERTFILE="-t /ssl/$(bashio::config 'certfile')" CERTFILE="-t /ssl/$(bashio::config 'certfile')"
KEYFILE="-k /ssl/$(bashio::config 'keyfile')" KEYFILE="-k /ssl/$(bashio::config 'keyfile')"
else else
CERTFILE="" CERTFILE=""
KEYFILE="" KEYFILE=""
fi fi
################# #################
@@ -48,7 +48,7 @@ export FB_BASEURL
declare ADDON_PROTOCOL=http declare ADDON_PROTOCOL=http
# Generate Ingress configuration # Generate Ingress configuration
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
ADDON_PROTOCOL=https ADDON_PROTOCOL=https
fi fi
#port=$(bashio::addon.port 80) #port=$(bashio::addon.port 80)
@@ -67,41 +67,41 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
NOAUTH="" NOAUTH=""
if bashio::config.true 'NoAuth'; then if bashio::config.true 'NoAuth'; then
if ! bashio::fs.file_exists "/data/noauth"; then if ! bashio::fs.file_exists "/data/noauth"; then
rm /data/auth &>/dev/null || true rm /data/auth &> /dev/null || true
rm /config/filebrowser.dB &>/dev/null || true rm /config/filebrowser.dB &> /dev/null || true
touch /data/noauth touch /data/noauth
NOAUTH="--noauth" NOAUTH="--noauth"
bashio::log.warning "Auth method change, database reset" bashio::log.warning "Auth method change, database reset"
fi fi
bashio::log.info "NoAuth option selected" bashio::log.info "NoAuth option selected"
else else
if ! bashio::fs.file_exists "/data/auth"; then if ! bashio::fs.file_exists "/data/auth"; then
rm /data/noauth &>/dev/null || true rm /data/noauth &> /dev/null || true
rm /config/filebrowser.dB &>/dev/null || true rm /config/filebrowser.dB &> /dev/null || true
touch /data/auth touch /data/auth
bashio::log.warning "Auth method change, database reset" bashio::log.warning "Auth method change, database reset"
fi fi
bashio::log.info "Default username/password : admin/admin" bashio::log.info "Default username/password : admin/admin"
fi fi
# Set base folder # Set base folder
if bashio::config.has_value 'base_folder'; then if bashio::config.has_value 'base_folder'; then
BASE_FOLDER=$(bashio::config 'base_folder') BASE_FOLDER=$(bashio::config 'base_folder')
else else
BASE_FOLDER=/ BASE_FOLDER=/
fi fi
# Disable thumbnails # Disable thumbnails
if bashio::config.true 'disable_thumbnails'; then if bashio::config.true 'disable_thumbnails'; then
DISABLE_THUMBNAILS="--disable-thumbnails" DISABLE_THUMBNAILS="--disable-thumbnails"
else else
DISABLE_THUMBNAILS="" DISABLE_THUMBNAILS=""
fi fi
# Remove configuration file # Remove configuration file
if [ -f /.filebrowser.json ]; then if [ -f /.filebrowser.json ]; then
rm /.filebrowser.json rm /.filebrowser.json
fi fi
bashio::log.info "Starting..." bashio::log.info "Starting..."

View File

@@ -12,8 +12,8 @@ APP_KEY="$(bashio::config 'APP_KEY')"
# If not base64 # If not base64
if [[ ! "$APP_KEY" == *"base64"* ]]; then if [[ ! "$APP_KEY" == *"base64"* ]]; then
# Check APP_KEY format # Check APP_KEY format
if [ ! "${#APP_KEY}" = 32 ]; then bashio::exit.nok "Your APP_KEY has ${#APP_KEY} instead of 32 characters"; fi if [ ! "${#APP_KEY}" = 32 ]; then bashio::exit.nok "Your APP_KEY has ${#APP_KEY} instead of 32 characters"; fi
fi fi
# Backup APP_KEY file # Backup APP_KEY file
@@ -27,7 +27,7 @@ CURRENT=$(sed -e '/^[<blank><tab>]*$/d' /config/addons_config/fireflyiii/APP_KEY
# Save if new # Save if new
if [ "$CURRENT" != "$APP_KEY" ]; then 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 fi
# Update permissions # Update permissions
@@ -43,83 +43,83 @@ chmod -R 775 /config/addons_config/fireflyiii
bashio::log.info "Defining database" bashio::log.info "Defining database"
case $(bashio::config 'DB_CONNECTION') in case $(bashio::config 'DB_CONNECTION') in
# Use sqlite # Use sqlite
sqlite_internal) sqlite_internal)
bashio::log.info "Using built in sqlite" bashio::log.info "Using built in sqlite"
# Set variable # Set variable
export DB_CONNECTION=sqlite export DB_CONNECTION=sqlite
export DB_DATABASE=/config/addons_config/fireflyiii/database/database.sqlite export DB_DATABASE=/config/addons_config/fireflyiii/database/database.sqlite
# Creating folders # Creating folders
mkdir -p /config/addons_config/fireflyiii/database mkdir -p /config/addons_config/fireflyiii/database
chown -R www-data:www-data /config/addons_config/fireflyiii/database chown -R www-data:www-data /config/addons_config/fireflyiii/database
# Creating database # Creating database
if [ ! -f /config/addons_config/fireflyiii/database/database.sqlite ]; then if [ ! -f /config/addons_config/fireflyiii/database/database.sqlite ]; then
# Create database # Create database
touch /config/addons_config/fireflyiii/database/database.sqlite touch /config/addons_config/fireflyiii/database/database.sqlite
# Install database # Install database
echo "updating database" echo "updating database"
php artisan migrate:refresh --seed --quiet php artisan migrate:refresh --seed --quiet
php artisan firefly-iii:upgrade-database --quiet php artisan firefly-iii:upgrade-database --quiet
php artisan passport:install --quiet php artisan passport:install --quiet
fi fi
# Creating symlink # Creating symlink
rm -r /var/www/html/storage/database rm -r /var/www/html/storage/database
ln -s /config/addons_config/fireflyiii/database /var/www/html/storage ln -s /config/addons_config/fireflyiii/database /var/www/html/storage
# Updating permissions # Updating permissions
chmod 775 /config/addons_config/fireflyiii/database/database.sqlite 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 /config/addons_config/fireflyiii
chown -R www-data:www-data /var/www/html/storage chown -R www-data:www-data /var/www/html/storage
;; ;;
# Use MariaDB # Use MariaDB
mariadb_addon) mariadb_addon)
bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..." bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..."
if ! bashio::services.available 'mysql'; then if ! bashio::services.available 'mysql'; then
bashio::log.fatal \ bashio::log.fatal \
"Local database access should be provided by the MariaDB addon" "Local database access should be provided by the MariaDB addon"
bashio::exit.nok \ bashio::exit.nok \
"Please ensure it is installed and started" "Please ensure it is installed and started"
fi fi
# Use values # Use values
DB_CONNECTION=mysql DB_CONNECTION=mysql
DB_HOST=$(bashio::services "mysql" "host") DB_HOST=$(bashio::services "mysql" "host")
DB_PORT=$(bashio::services "mysql" "port") DB_PORT=$(bashio::services "mysql" "port")
DB_DATABASE=firefly DB_DATABASE=firefly
DB_USERNAME=$(bashio::services "mysql" "username") DB_USERNAME=$(bashio::services "mysql" "username")
DB_PASSWORD=$(bashio::services "mysql" "password") DB_PASSWORD=$(bashio::services "mysql" "password")
export DB_CONNECTION export DB_CONNECTION
export DB_HOST && bashio::log.blue "DB_HOST=$DB_HOST" export DB_HOST && bashio::log.blue "DB_HOST=$DB_HOST"
export DB_PORT && bashio::log.blue "DB_PORT=$DB_PORT" export DB_PORT && bashio::log.blue "DB_PORT=$DB_PORT"
export DB_DATABASE && bashio::log.blue "DB_DATABASE=$DB_DATABASE" export DB_DATABASE && bashio::log.blue "DB_DATABASE=$DB_DATABASE"
export DB_USERNAME && bashio::log.blue "DB_USERNAME=$DB_USERNAME" export DB_USERNAME && bashio::log.blue "DB_USERNAME=$DB_USERNAME"
export DB_PASSWORD && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD" export DB_PASSWORD && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD"
bashio::log.warning "Firefly-iii is using the Maria DB addon" 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 "Please ensure this is included in your backups"
bashio::log.warning "Uninstalling the MariaDB addon will remove any data" bashio::log.warning "Uninstalling the MariaDB addon will remove any data"
bashio::log.info "Creating database for Firefly-iii if required" bashio::log.info "Creating database for Firefly-iii if required"
mysql \ mysql \
-u "${DB_USERNAME}" -p"${DB_PASSWORD}" \ -u "${DB_USERNAME}" -p"${DB_PASSWORD}" \
-h "${DB_HOST}" -P "${DB_PORT}" \ -h "${DB_HOST}" -P "${DB_PORT}" \
-e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;" -e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;"
;; ;;
# Use remote # Use remote
*) *)
bashio::log.info "Using remote database. Requirement : filling all addon options fields, and making sure the database already exists" 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 for conditions in "DB_HOST" "DB_PORT" "DB_DATABASE" "DB_USERNAME" "DB_PASSWORD"; do
if ! bashio::config.has_value "$conditions"; then if ! bashio::config.has_value "$conditions"; then
bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options" bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options"
fi fi
done done
;; ;;
esac esac
@@ -131,13 +131,13 @@ bashio::log.info "Defining upload folder"
# Creating folder # Creating folder
if [ ! -d /config/addons_config/fireflyiii/upload ]; then if [ ! -d /config/addons_config/fireflyiii/upload ]; then
mkdir -p /config/addons_config/fireflyiii/upload mkdir -p /config/addons_config/fireflyiii/upload
chown -R www-data:www-data /config/addons_config/fireflyiii/upload chown -R www-data:www-data /config/addons_config/fireflyiii/upload
fi fi
# Creating symlink # Creating symlink
if [ -d /var/www/html/storage/ha_upload ]; then 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 fi
ln -s /config/addons_config/fireflyiii/upload /var/www/html/storage/ha_upload ln -s /config/addons_config/fireflyiii/upload /var/www/html/storage/ha_upload
@@ -149,8 +149,8 @@ chmod -R 775 /config/addons_config/fireflyiii
# Test # Test
f=/config/addons_config/fireflyiii f=/config/addons_config/fireflyiii
while [[ $f != / ]]; do while [[ $f != / ]]; do
chmod 777 "$f" chmod 777 "$f"
f=$(dirname "$f") f=$(dirname "$f")
done done
################ ################
@@ -158,21 +158,21 @@ done
################ ################
if bashio::config.has_value 'Updates'; then if bashio::config.has_value 'Updates'; then
# Align update with options # Align update with options
echo "" echo ""
FREQUENCY=$(bashio::config 'Updates') FREQUENCY=$(bashio::config 'Updates')
bashio::log.info "$FREQUENCY updates" bashio::log.info "$FREQUENCY updates"
echo "" echo ""
# Sets cron // do not delete this message # Sets cron // do not delete this message
cp /templates/cronupdate /etc/cron."${FREQUENCY}"/ cp /templates/cronupdate /etc/cron."${FREQUENCY}"/
chmod 777 /etc/cron."${FREQUENCY}"/cronupdate chmod 777 /etc/cron."${FREQUENCY}"/cronupdate
# Sets cron to run with www-data user # Sets cron to run with www-data user
# sed -i 's|root|www-data|g' /etc/crontab # sed -i 's|root|www-data|g' /etc/crontab
# Starts cron # Starts cron
service cron start service cron start
fi fi
############## ##############
@@ -182,8 +182,8 @@ fi
bashio::log.info "Please wait while the app is loading !" bashio::log.info "Please wait while the app is loading !"
if bashio::config.true 'silent'; then 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" 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' sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh >/dev/null'
else 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 fi

View File

@@ -5,17 +5,17 @@ set -e
slug=fireflyiii_data_importer slug=fireflyiii_data_importer
if [[ "$(bashio::config "CONFIG_LOCATION")" == *"/addons_config/fireflyiii_data_importer"* ]]; then if [[ "$(bashio::config "CONFIG_LOCATION")" == *"/addons_config/fireflyiii_data_importer"* ]]; then
bashio::log.warning "Reset CONFIG_LOCATION to /config" bashio::log.warning "Reset CONFIG_LOCATION to /config"
bashio::addon.option "CONFIG_LOCATION" "/config" bashio::addon.option "CONFIG_LOCATION" "/config"
bashio::addon.restart bashio::addon.restart
fi fi
CONFIGSOURCE="$(bashio::config "CONFIG_LOCATION")" CONFIGSOURCE="$(bashio::config "CONFIG_LOCATION")"
if [ -d "/homeassistant/addons_config/$slug" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then if [ -d "/homeassistant/addons_config/$slug" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then
echo "Migrating /homeassistant/addons_config/$slug" echo "Migrating /homeassistant/addons_config/$slug"
mv /homeassistant/addons_config/"$slug"/* "$CONFIGSOURCE"/ mv /homeassistant/addons_config/"$slug"/* "$CONFIGSOURCE"/
touch /homeassistant/addons_config/$slug/migrated touch /homeassistant/addons_config/$slug/migrated
fi fi
# Create directory # Create directory

View File

@@ -9,9 +9,9 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
################# #################
if [ "$(ls -A "$CONFIGSOURCE/configurations")" ]; then if [ "$(ls -A "$CONFIGSOURCE/configurations")" ]; then
bashio::log.info "Configurations were found in $CONFIGSOURCE/configurations, they will be loaded." bashio::log.info "Configurations were found in $CONFIGSOURCE/configurations, they will be loaded."
JSON_CONFIGURATION_DIR="$CONFIGSOURCE/configurations" JSON_CONFIGURATION_DIR="$CONFIGSOURCE/configurations"
export JSON_CONFIGURATION_DIR export JSON_CONFIGURATION_DIR
fi fi
# Allow config dir # Allow config dir
@@ -31,36 +31,36 @@ export CAN_POST_AUTOIMPORT="$(bashio::config "CAN_POST_AUTOIMPORT")"
if bashio::config.has_value 'Updates'; then if bashio::config.has_value 'Updates'; then
# Align update with options # Align update with options
echo "" echo ""
FREQUENCY=$(bashio::config 'Updates') FREQUENCY=$(bashio::config 'Updates')
bashio::log.info "$FREQUENCY updates" bashio::log.info "$FREQUENCY updates"
echo "" echo ""
# Sets cron // do not delete this message # Sets cron // do not delete this message
cp /templates/cronupdate /etc/cron."${FREQUENCY}"/ cp /templates/cronupdate /etc/cron."${FREQUENCY}"/
chmod 777 /etc/cron."${FREQUENCY}"/cronupdate chmod 777 /etc/cron."${FREQUENCY}"/cronupdate
# Sets cron to run with www-data user # Sets cron to run with www-data user
# sed -i 's|root|www-data|g' /etc/crontab # sed -i 's|root|www-data|g' /etc/crontab
# Starts cron # Starts cron
service cron start service cron start
# Export variables # Export variables
IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files" IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
export IMPORT_DIR_WHITELIST 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 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." 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 true
fi fi
else 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 fi

View File

@@ -9,13 +9,13 @@ mkdir -p "$CONFIGSOURCE"
# If no file, provide example # If no file, provide example
if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /data/configurations ]; then if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /data/configurations ]; then
cp -r /data/configurations/* "$CONFIGSOURCE"/ || true cp -r /data/configurations/* "$CONFIGSOURCE"/ || true
rm -r /data/configurations rm -r /data/configurations
fi fi
if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /app/configurations ]; then if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /app/configurations ]; then
cp -r /app/configurations/* "$CONFIGSOURCE"/ || true cp -r /app/configurations/* "$CONFIGSOURCE"/ || true
rm -r /app/configurations rm -r /app/configurations
fi fi
ln -sf "$CONFIGSOURCE" /data/configurations ln -sf "$CONFIGSOURCE" /data/configurations

View File

@@ -9,9 +9,9 @@ CONFIGSOURCE="/config/addons_config/fireflyiii_fints_importer"
################# #################
if [ "$(ls -A "$CONFIGSOURCE")" ]; then 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 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 fi
################ ################
@@ -20,43 +20,43 @@ fi
if bashio::config.has_value 'Updates'; then if bashio::config.has_value 'Updates'; then
if [ "$(ls -A "${CONFIGSOURCE}")" ]; then if [ "$(ls -A "${CONFIGSOURCE}")" ]; then
# Align update with options # Align update with options
echo "" echo ""
FREQUENCY=$(bashio::config 'Updates') FREQUENCY=$(bashio::config 'Updates')
bashio::log.info "$FREQUENCY updates" bashio::log.info "$FREQUENCY updates"
echo "" echo ""
for i in $(seq 4 2 12); do for i in $(seq 4 2 12); do
hour=" $i" hour=" $i"
freqDir="/etc/periodic/daily$i" freqDir="/etc/periodic/daily$i"
echo "0 ${hour:(-4)} * * * run-parts \"$freqDir\"" >>/etc/crontabs/root echo "0 ${hour:(-4)} * * * run-parts \"$freqDir\"" >> /etc/crontabs/root
mkdir "$freqDir" mkdir "$freqDir"
done done
# Sets cron // do not delete this message # Sets cron // do not delete this message
freqDir="/etc/periodic/${FREQUENCY}" freqDir="/etc/periodic/${FREQUENCY}"
cp /templates/cronupdate "$freqDir/" cp /templates/cronupdate "$freqDir/"
chmod 777 "$freqDir/cronupdate" chmod 777 "$freqDir/cronupdate"
# Sets cron to run with www-data user # Sets cron to run with www-data user
# sed -i 's|root|www-data|g' /etc/crontab # sed -i 's|root|www-data|g' /etc/crontab
# Starts cron # Starts cron
echo "Timezone $TZ" echo "Timezone $TZ"
export TZ export TZ
crond -l 2 -f >/dev/stdout 2>/dev/stderr & crond -l 2 -f > /dev/stdout 2> /dev/stderr &
# Export variables # Export variables
IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files" IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
export IMPORT_DIR_WHITELIST 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 else
bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}. There will therefore be be no automatic updates." 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
fi fi
@@ -67,8 +67,8 @@ fi
bashio::log.info "Please wait while the app is loading !" bashio::log.info "Please wait while the app is loading !"
if bashio::config.true 'silent'; then 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" 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 php -S 0.0.0.0:8080 /app/index.php > /dev/null
else else
php -S 0.0.0.0:8080 /app/index.php php -S 0.0.0.0:8080 /app/index.php
fi fi

View File

@@ -5,15 +5,15 @@ set -e
slug=flexget slug=flexget
if [ -d /config/$slug ]; then if [ -d /config/$slug ]; then
echo "Moving to new location /config/addons_config/$slug" echo "Moving to new location /config/addons_config/$slug"
mkdir -p /config/addons_config/$slug mkdir -p /config/addons_config/$slug
chmod 777 /config/addons_config/$slug chmod 777 /config/addons_config/$slug
mv /config/$slug/* /config/addons_config/$slug/ mv /config/$slug/* /config/addons_config/$slug/
rm -r /config/$slug rm -r /config/$slug
fi fi
if [ ! -d /config/addons_config/$slug ]; then if [ ! -d /config/addons_config/$slug ]; then
echo "Creating /config/addons_config/$slug" echo "Creating /config/addons_config/$slug"
mkdir -p /config/addons_config/$slug mkdir -p /config/addons_config/$slug
chmod 777 /config/addons_config/$slug chmod 777 /config/addons_config/$slug
fi fi

View File

@@ -3,12 +3,12 @@
# Migrate files for new config location # Migrate files for new config location
slug="free_games_claimer" slug="free_games_claimer"
if [ -f "/homeassistant/addons_config/$slug/config.yaml" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then if [ -f "/homeassistant/addons_config/$slug/config.yaml" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then
bashio::log.warning "Migrating config.yaml" bashio::log.warning "Migrating config.yaml"
mv "/homeassistant/addons_config/$slug"/* /config/ || true mv "/homeassistant/addons_config/$slug"/* /config/ || true
echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" >"/homeassistant/addons_config/$slug/migrated" echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" > "/homeassistant/addons_config/$slug/migrated"
fi fi
if [ -f "/homeassistant/addons_autoscripts/$slug.sh" ]; then if [ -f "/homeassistant/addons_autoscripts/$slug.sh" ]; then
bashio::log.warning "Migrating autoscript" bashio::log.warning "Migrating autoscript"
mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true
fi fi

View File

@@ -11,20 +11,20 @@ CONFIG_HOME="$(dirname "$CONFIG_HOME")"
# Use new config file # Use new config file
if [ ! -f "$CONFIG_HOME/config.env" ]; then if [ ! -f "$CONFIG_HOME/config.env" ]; then
# Copy default config.env # Copy default config.env
cp /templates/config.env "$CONFIG_HOME/" cp /templates/config.env "$CONFIG_HOME/"
chmod 755 "$CONFIG_HOME/config.env" 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" 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 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 fi
# Remove erroneous folder named config.env (bug fix for looping issue) # Remove erroneous folder named config.env (bug fix for looping issue)
if [ -d "$CONFIG_HOME/config.env" ]; then if [ -d "$CONFIG_HOME/config.env" ]; then
bashio::log.warning "Found directory named config.env, deleting it..." bashio::log.warning "Found directory named config.env, deleting it..."
rm -rf "$CONFIG_HOME/config.env" # Fix: Ensures directory removal even if it exists 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 cp /templates/config.env "$CONFIG_HOME/config.env" # Recreate as a valid file
chmod 755 "$CONFIG_HOME/config.env" chmod 755 "$CONFIG_HOME/config.env"
fi fi
# Copy new file # Copy new file
@@ -61,23 +61,23 @@ cd /data || true
# Fetch commands # Fetch commands
CMD_ARGUMENTS="$(bashio::config "CMD_ARGUMENTS")" CMD_ARGUMENTS="$(bashio::config "CMD_ARGUMENTS")"
IFS=';' IFS=';'
read -ar strarr <<<"$CMD_ARGUMENTS" read -ar strarr <<< "$CMD_ARGUMENTS"
# Sanitizes commands # Sanitizes commands
trim() { trim() {
local var="$*" local var="$*"
var="${var#"${var%%[![:space:]]*}"}" var="${var#"${var%%[![:space:]]*}"}"
var="${var%"${var##*[![:space:]]}"}" var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var" printf '%s' "$var"
} }
# Add docker-entrypoint command # Add docker-entrypoint command
for val in "${strarr[@]}"; do for val in "${strarr[@]}"; do
val="$(trim "$val")" val="$(trim "$val")"
echo " " echo " "
bashio::log.info "Starting the app with arguments \"$val\"" bashio::log.info "Starting the app with arguments \"$val\""
echo " " echo " "
echo "$val" | xargs docker-entrypoint.sh || true echo "$val" | xargs docker-entrypoint.sh || true
done done
bashio::log.info "All actions concluded. Stopping in 10 seconds." bashio::log.info "All actions concluded. Stopping in 10 seconds."

View File

@@ -7,26 +7,26 @@ set -e
##################### #####################
if bashio::config.true 'mqtt_autodiscover'; then if bashio::config.true 'mqtt_autodiscover'; then
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..." bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
# Check if available # Check if available
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
# Get variables # Get variables
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..." bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..."
MQTT_HOST=$(bashio::services mqtt "host") MQTT_HOST=$(bashio::services mqtt "host")
export MQTT_HOST export MQTT_HOST
MQTT_PORT=$(bashio::services mqtt "port") MQTT_PORT=$(bashio::services mqtt "port")
export MQTT_PORT export MQTT_PORT
MQTT_SSL=$(bashio::services mqtt "ssl") MQTT_SSL=$(bashio::services mqtt "ssl")
export MQTT_SSL export MQTT_SSL
MQTT_USERNAME=$(bashio::services mqtt "username") MQTT_USERNAME=$(bashio::services mqtt "username")
export MQTT_USERNAME export MQTT_USERNAME
MQTT_PASSWORD=$(bashio::services mqtt "password") MQTT_PASSWORD=$(bashio::services mqtt "password")
export MQTT_PASSWORD export MQTT_PASSWORD
# Export variables # 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 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 sed -i "1a export $variables" /etc/services.d/*/*run* 2> /dev/null || true
# Log # Log
bashio::log.blue "$variables" bashio::log.blue "$variables"
done done
fi fi

View File

@@ -4,64 +4,64 @@ set -e
for file in /data/gitea/conf/app.ini /etc/templates/app.ini; do for file in /data/gitea/conf/app.ini /etc/templates/app.ini; do
if [ ! -f "$file" ]; then if [ ! -f "$file" ]; then
continue continue
fi fi
############## ##############
# SSL CONFIG # # SSL CONFIG #
############## ##############
# Clean values # Clean values
sed -i "/PROTOCOL/d" "$file" sed -i "/PROTOCOL/d" "$file"
sed -i "/CERT_FILE/d" "$file" sed -i "/CERT_FILE/d" "$file"
sed -i "/KEY_FILE/d" "$file" sed -i "/KEY_FILE/d" "$file"
# Add ssl # Add ssl
bashio::config.require.ssl bashio::config.require.ssl
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
PROTOCOL=https PROTOCOL=https
bashio::log.info "ssl is enabled" bashio::log.info "ssl is enabled"
sed -i "/server/a PROTOCOL=https" "$file" sed -i "/server/a PROTOCOL=https" "$file"
sed -i "/server/a CERT_FILE=/ssl/$(bashio::config 'certfile')" "$file" sed -i "/server/a CERT_FILE=/ssl/$(bashio::config 'certfile')" "$file"
sed -i "/server/a KEY_FILE=/ssl/$(bashio::config 'keyfile')" "$file" sed -i "/server/a KEY_FILE=/ssl/$(bashio::config 'keyfile')" "$file"
chmod 744 /ssl/* chmod 744 /ssl/*
else else
PROTOCOL=http PROTOCOL=http
sed -i "/server/a PROTOCOL=http" "$file" sed -i "/server/a PROTOCOL=http" "$file"
fi fi
################## ##################
# ADAPT ROOT_URL # # ADAPT ROOT_URL #
################## ##################
if bashio::config.has_value 'ROOT_URL'; then if bashio::config.has_value 'ROOT_URL'; then
bashio::log.blue "ROOT_URL set, using value : $(bashio::config 'ROOT_URL')" bashio::log.blue "ROOT_URL set, using value : $(bashio::config 'ROOT_URL')"
else else
ROOT_URL="$PROTOCOL://$(bashio::config 'DOMAIN'):$(bashio::addon.port 3000)" ROOT_URL="$PROTOCOL://$(bashio::config 'DOMAIN'):$(bashio::addon.port 3000)"
bashio::log.blue "ROOT_URL not set, using extrapolated value : $ROOT_URL" bashio::log.blue "ROOT_URL not set, using extrapolated value : $ROOT_URL"
sed -i "/server/a ROOT_URL=$ROOT_URL" "$file" sed -i "/server/a ROOT_URL=$ROOT_URL" "$file"
fi fi
#################### ####################
# ADAPT PARAMETERS # # ADAPT PARAMETERS #
#################### ####################
for param in APP_NAME DOMAIN ROOT_URL; do for param in APP_NAME DOMAIN ROOT_URL; do
# Remove parameter # Remove parameter
sed -i "/$param/d" "$file" sed -i "/$param/d" "$file"
# Define parameter # Define parameter
if bashio::config.has_value "$param"; then if bashio::config.has_value "$param"; then
echo "parameter set : $param=$(bashio::config "$param")" echo "parameter set : $param=$(bashio::config "$param")"
sed -i "/server/a $param = \"$(bashio::config "$param")\"" "$file" sed -i "/server/a $param = \"$(bashio::config "$param")\"" "$file"
# Allow at setup # Allow at setup
sed -i "1a $param=\"$(bashio::config "$param")\"" /etc/s6/gitea/setup sed -i "1a $param=\"$(bashio::config "$param")\"" /etc/s6/gitea/setup
fi fi
done done
done done

View File

@@ -16,18 +16,18 @@ sed -i "s|%%interface%%|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ssl.co
# Ssl values # Ssl values
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
echo "Defining ssl configuration" echo "Defining ssl configuration"
bashio::config.require.ssl bashio::config.require.ssl
certfile=$(bashio::config 'certfile') certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile') keyfile=$(bashio::config 'keyfile')
#Check if files exist #Check if files exist
echo "... checking if referenced certificates 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/"$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 /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 "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 /ssl/$certfile;" /etc/nginx/servers/ssl.conf
sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /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")" bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port "$port")"
fi fi

View File

@@ -6,21 +6,21 @@ set -e
# Set structure # # Set structure #
################# #################
for folders in config users indexdir secret media cache thumbnail_cache persist; do for folders in config users indexdir secret media cache thumbnail_cache persist; do
mkdir -p /config/"$folders" mkdir -p /config/"$folders"
if [ -d /app/"$folders" ] && [ "$(ls -A /app/"$folders")" ]; then if [ -d /app/"$folders" ] && [ "$(ls -A /app/"$folders")" ]; then
cp -rn /app/"$folders"/* /config/"$folders" cp -rn /app/"$folders"/* /config/"$folders"
fi fi
rm -rf /app/"$folders" rm -rf /app/"$folders"
ln -sf /config/"$folders" /app/"$folders" ln -sf /config/"$folders" /app/"$folders"
done done
# Persist database and plugins # Persist database and plugins
mkdir -p /config/gramps mkdir -p /config/gramps
if [ -d /root/.gramps ]; then if [ -d /root/.gramps ]; then
if [ "$(ls -A /root/.gramps)" ]; then if [ "$(ls -A /root/.gramps)" ]; then
cp -rf /root/.gramps/* /config/gramps cp -rf /root/.gramps/* /config/gramps
fi fi
rm -rf /root/.gramps rm -rf /root/.gramps
fi fi
ln -sf /config/gramps /root/.gramps 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 # Check if the secret key is defined in addon options
if bashio::config.has_value "GRAMPSWEB_SECRET_KEY"; then if bashio::config.has_value "GRAMPSWEB_SECRET_KEY"; then
bashio::log.warning "Using the secret key defined in the addon options." bashio::log.warning "Using the secret key defined in the addon options."
GRAMPSWEB_SECRET_KEY="$(bashio::config "GRAMPSWEB_SECRET_KEY")" GRAMPSWEB_SECRET_KEY="$(bashio::config "GRAMPSWEB_SECRET_KEY")"
export GRAMPSWEB_SECRET_KEY export GRAMPSWEB_SECRET_KEY
else else
# Check if the secret file exists; if not, create a new one # Check if the secret file exists; if not, create a new one
if [ ! -s /config/secret/secret ]; then if [ ! -s /config/secret/secret ]; then
bashio::log.warning "No secret key found in /config/secret/secret, generating a new one." bashio::log.warning "No secret key found in /config/secret/secret, generating a new one."
mkdir -p /config/secret mkdir -p /config/secret
python3 -c "import secrets; print(secrets.token_urlsafe(32))" | tr -d "\n" >/config/secret/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" bashio::log.warning "New secret key generated and stored in /config/secret/secret"
fi fi
bashio::log.warning "Using existing secret key from /config/secret/secret." bashio::log.warning "Using existing secret key from /config/secret/secret."
bashio::log.warning "Secret key saved to addon options." bashio::log.warning "Secret key saved to addon options."
GRAMPSWEB_SECRET_KEY="$(cat /config/secret/secret)" GRAMPSWEB_SECRET_KEY="$(cat /config/secret/secret)"
export GRAMPSWEB_SECRET_KEY export GRAMPSWEB_SECRET_KEY
bashio::addon.option "GRAMPSWEB_SECRET_KEY" "$GRAMPSWEB_SECRET_KEY" bashio::addon.option "GRAMPSWEB_SECRET_KEY" "$GRAMPSWEB_SECRET_KEY"
fi fi
################## ##################

View File

@@ -5,9 +5,9 @@ set -e
echo "Updating folders..." echo "Updating folders..."
for FOLDERS in "/share/grav" "/app/grav-admin/backup"; do for FOLDERS in "/share/grav" "/app/grav-admin/backup"; do
echo "... $FOLDERS" echo "... $FOLDERS"
mkdir -p $FOLDERS mkdir -p $FOLDERS
chown -R "$PUID:$PGID" $FOLDERS chown -R "$PUID:$PGID" $FOLDERS
done done
bashio::log.warning "If error of missing folder when loading addon, just restart" bashio::log.warning "If error of missing folder when loading addon, just restart"

View File

@@ -68,8 +68,8 @@
"/dev/nvme2" "/dev/nvme2"
], ],
"environment": { "environment": {
"PGDATA": "/config/postgres", "GUACAMOLE_HOME": "/config",
"GUACAMOLE_HOME": "/config" "PGDATA": "/config/postgres"
}, },
"image": "ghcr.io/alexbelgium/guacamole-{arch}", "image": "ghcr.io/alexbelgium/guacamole-{arch}",
"ingress": true, "ingress": true,

View File

@@ -9,6 +9,6 @@ set -e
slug=guacamole slug=guacamole
if [ -d /homeassistant/addons_config/"$slug" ] && [ ! -d /config/postgres ]; then if [ -d /homeassistant/addons_config/"$slug" ] && [ ! -d /config/postgres ]; then
echo "Moving database to new location /config" echo "Moving database to new location /config"
cp -rf /homeassistant/addons_config/"$slug"/* /config/ cp -rf /homeassistant/addons_config/"$slug"/* /config/
fi fi

View File

@@ -13,19 +13,19 @@ declare keyfile
port=$(bashio::addon.port 80) port=$(bashio::addon.port 80)
if bashio::var.has_value "${port}"; then if bashio::var.has_value "${port}"; then
bashio::config.require.ssl bashio::config.require.ssl
if bashio::config.true 'ssl'; then if bashio::config.true 'ssl'; then
certfile=$(bashio::config 'certfile') certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile') keyfile=$(bashio::config 'keyfile')
mv /etc/nginx/servers/direct-ssl.disabled /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/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf
else else
mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf
fi fi
fi fi
ingress_port=$(bashio::addon.ingress_port) ingress_port=$(bashio::addon.ingress_port)

0
guacamole/rootfs/etc/services.d/nginx/run Normal file → Executable file
View File

View File

@@ -5,17 +5,17 @@ PREVIOUS_FOLDER="immich"
# Move main folder # Move main folder
if [ -f /homeassistant/addons_config/"$PREVIOUS_FOLDER"/config.yaml ]; then if [ -f /homeassistant/addons_config/"$PREVIOUS_FOLDER"/config.yaml ]; then
bashio::log.warning "----------------------------------------" bashio::log.warning "----------------------------------------"
bashio::log.warning "Migrating configuration to the new addon" bashio::log.warning "Migrating configuration to the new addon"
bashio::log.warning "----------------------------------------" bashio::log.warning "----------------------------------------"
cp -rnp /homeassistant/addons_config/"$PREVIOUS_FOLDER"/ /config/ cp -rnp /homeassistant/addons_config/"$PREVIOUS_FOLDER"/ /config/
mv /homeassistant/addons_config/"$PREVIOUS_FOLDER" "$PREVIOUS_FOLDER"_migrated mv /homeassistant/addons_config/"$PREVIOUS_FOLDER" "$PREVIOUS_FOLDER"_migrated
if [ -d /config/addons_config ]; then rm -r /config/addons_config; fi if [ -d /config/addons_config ]; then rm -r /config/addons_config; fi
echo "Files moved to /addon_configs/$HOSTNAME" echo "Files moved to /addon_configs/$HOSTNAME"
fi fi
# Move autoscript # Move autoscript
if [ -f /homeassistant/addons_autoscrips/immich.sh ]; then if [ -f /homeassistant/addons_autoscrips/immich.sh ]; then
cp -rnf /homeassistant/addons_autoscrips/"$PREVIOUS_FOLDER".sh /config/ &>/dev/null || true 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" bashio::log.yellow "... moved $PREVIOUS_FOLDER.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME"
fi fi

View File

@@ -7,14 +7,14 @@ set -e
###################### ######################
if bashio::config.has_value "PUID"; then if bashio::config.has_value "PUID"; then
PUID="$(bashio::config 'PUID')" PUID="$(bashio::config 'PUID')"
else else
PUID=0 PUID=0
fi fi
if bashio::config.has_value "PGID"; then if bashio::config.has_value "PGID"; then
PGID="$(bashio::config 'PGID')" PGID="$(bashio::config 'PGID')"
else else
PGID=0 PGID=0
fi fi
########################## ##########################
@@ -23,7 +23,7 @@ fi
# Clean typesense # Clean typesense
if [ -d /data/typesense ]; then if [ -d /data/typesense ]; then
rm -r /data/typesense rm -r /data/typesense
fi fi
################# #################
@@ -34,9 +34,9 @@ bashio::log.info "Setting data location"
DATA_LOCATION="$(bashio::config 'data_location')" DATA_LOCATION="$(bashio::config 'data_location')"
export IMMICH_MEDIA_LOCATION="$DATA_LOCATION" export IMMICH_MEDIA_LOCATION="$DATA_LOCATION"
if [ -d /var/run/s6/container_environment ]; then 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 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" echo "... check $DATA_LOCATION folder exists"
mkdir -p "$DATA_LOCATION" mkdir -p "$DATA_LOCATION"
@@ -63,32 +63,32 @@ chmod 777 /data
#################### ####################
if bashio::config.has_value "library_location"; then if bashio::config.has_value "library_location"; then
LIBRARY_LOCATION="$(bashio::config 'library_location')" 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" 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" mkdir -p "$LIBRARY_LOCATION"
chown -R "$PUID":"$PGID" "$LIBRARY_LOCATION" chown -R "$PUID":"$PGID" "$LIBRARY_LOCATION"
# Check if the existing library is a directory and not a symlink and has contents # 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 if [ -d "$DATA_LOCATION/library" ] && [ ! -L "$DATA_LOCATION/library" ] && [ "$(ls -A "$DATA_LOCATION/library")" ]; then
bashio::log.yellow "-------------------------------" 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.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 "-------------------------------" bashio::log.yellow "-------------------------------"
mv "$DATA_LOCATION/library" "$DATA_LOCATION/library_old" mv "$DATA_LOCATION/library" "$DATA_LOCATION/library_old"
sleep 5 sleep 5
fi fi
# Create symbolic link only if it doesn't already exist or is incorrect # 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 if [ ! -L "$DATA_LOCATION/library" ] || [ "$(readlink -f "$DATA_LOCATION/library")" != "$LIBRARY_LOCATION" ]; then
ln -sf "$LIBRARY_LOCATION" "$DATA_LOCATION/library" ln -sf "$LIBRARY_LOCATION" "$DATA_LOCATION/library"
fi fi
fi fi
################## ##################
# REDIS LOCATION # # REDIS LOCATION #
################## ##################
echo "sed -i \"s=/config/redis=/data/redis=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 echo "sed -i \"s=/config/log/redis=/data/log=g\" /etc/s6*/s6*/*/run" >> /docker-mods
mkdir -p /data/redis mkdir -p /data/redis
mkdir -p /data/log mkdir -p /data/log
chmod 777 /data/redis chmod 777 /data/redis

View File

@@ -5,134 +5,134 @@ set -e
# Function to export options from JSON to env variables # Function to export options from JSON to env variables
export_options() { export_options() {
local json_source="/data/options.json" local json_source="/data/options.json"
bashio::log.info "Exporting addon options from ${json_source}" bashio::log.info "Exporting addon options from ${json_source}"
# WARNING: Exporting all keys can cause trouble if your config contains unsafe or untrusted keys! # WARNING: Exporting all keys can cause trouble if your config contains unsafe or untrusted keys!
mapfile -t keys < <(jq -r 'keys[]' "${json_source}") mapfile -t keys < <(jq -r 'keys[]' "${json_source}")
for key in "${keys[@]}"; do for key in "${keys[@]}"; do
local value local value
value=$(jq -r ".${key}" "${json_source}") value=$(jq -r ".${key}" "${json_source}")
if bashio::config.false "verbose" || [[ "$key" == *"PASS"* ]]; then if bashio::config.false "verbose" || [[ "$key" == *"PASS"* ]]; then
bashio::log.blue "${key}=******" bashio::log.blue "${key}=******"
else else
bashio::log.blue "${key}='${value}'" bashio::log.blue "${key}='${value}'"
fi fi
export "${key}=${value}" export "${key}=${value}"
done done
} }
# Function to check and adjust DB_HOSTNAME if necessary # Function to check and adjust DB_HOSTNAME if necessary
check_db_hostname() { check_db_hostname() {
if [[ "${DB_HOSTNAME}" == "homeassistant.local" ]]; then if [[ "${DB_HOSTNAME}" == "homeassistant.local" ]]; then
local host_ip local host_ip
host_ip=$(bashio::network.ipv4_address) host_ip=$(bashio::network.ipv4_address)
host_ip=${host_ip%/*} host_ip=${host_ip%/*}
export DB_HOSTNAME="$host_ip" export DB_HOSTNAME="$host_ip"
bashio::log.warning "DB_HOSTNAME was set to homeassistant.local. Using detected IP: $DB_HOSTNAME" bashio::log.warning "DB_HOSTNAME was set to homeassistant.local. Using detected IP: $DB_HOSTNAME"
fi fi
if ! ping -c 1 -W 3 "$DB_HOSTNAME" >/dev/null 2>&1; then if ! ping -c 1 -W 3 "$DB_HOSTNAME" > /dev/null 2>&1; then
bashio::log.warning "------------------------------------" bashio::log.warning "------------------------------------"
bashio::log.warning "DB_HOSTNAME ($DB_HOSTNAME) is not reachable." 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 "Please set it to the IP address of your database."
bashio::log.warning "The addon will stop until this is fixed." bashio::log.warning "The addon will stop until this is fixed."
bashio::log.warning "------------------------------------" bashio::log.warning "------------------------------------"
sleep 30 sleep 30
bashio::addon.stop bashio::addon.stop
else else
echo "$DB_HOSTNAME is reachable." echo "$DB_HOSTNAME is reachable."
fi fi
} }
# Function to migrate internal database to external storage if needed # Function to migrate internal database to external storage if needed
migrate_database() { migrate_database() {
if [ -f /share/postgresql_immich.tar.gz ]; then if [ -f /share/postgresql_immich.tar.gz ]; then
bashio::log.warning "Previous database export found at /share/postgresql_immich.tar.gz" bashio::log.warning "Previous database export found at /share/postgresql_immich.tar.gz"
elif [ -d /data/postgresql ]; then elif [ -d /data/postgresql ]; then
bashio::log.warning "Internal Postgres database detected. Migrating to /share/postgresql_immich.tar.gz" bashio::log.warning "Internal Postgres database detected. Migrating to /share/postgresql_immich.tar.gz"
tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql
rm -rf /data/postgresql rm -rf /data/postgresql
fi fi
} }
# Function to validate required configuration values # Function to validate required configuration values
validate_config() { validate_config() {
local missing=false local missing=false
for var in DB_USERNAME DB_HOSTNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT JWT_SECRET; do for var in DB_USERNAME DB_HOSTNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT JWT_SECRET; do
if ! bashio::config.has_value "${var}"; then if ! bashio::config.has_value "${var}"; then
bashio::log.error "Missing required configuration: ${var}" bashio::log.error "Missing required configuration: ${var}"
missing=true missing=true
fi fi
done done
if [ "$missing" = true ]; then if [ "$missing" = true ]; then
bashio::exit.nok "Please ensure all required options are set." bashio::exit.nok "Please ensure all required options are set."
fi fi
} }
# Function to export DB variables to s6 environment if applicable # Function to export DB variables to s6 environment if applicable
export_db_env() { export_db_env() {
if [ -d /var/run/s6/container_environment ]; then 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 for var in DB_USERNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT DB_HOSTNAME JWT_SECRET; do
if [ -n "${!var:-}" ]; then if [ -n "${!var:-}" ]; then
printf "%s" "${!var}" >"/var/run/s6/container_environment/${var}" printf "%s" "${!var}" > "/var/run/s6/container_environment/${var}"
fi fi
done done
fi fi
} }
# Function to set up the root user with a secure password # Function to set up the root user with a secure password
setup_root_user() { setup_root_user() {
# Generate DB_ROOT_PASSWORD if not set (12-character alphanumeric). # Generate DB_ROOT_PASSWORD if not set (12-character alphanumeric).
if bashio::config.has_value "DB_ROOT_PASSWORD"; then if bashio::config.has_value "DB_ROOT_PASSWORD"; then
export DB_ROOT_PASSWORD="$(bashio::config 'DB_ROOT_PASSWORD')" export DB_ROOT_PASSWORD="$(bashio::config 'DB_ROOT_PASSWORD')"
else else
bashio::log.warning "DB_ROOT_PASSWORD not set. Generating a random 12-character alphanumeric password and storing it in the addon options." 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' </dev/urandom | head -c12)" export DB_ROOT_PASSWORD="$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c12)"
bashio::addon.option "DB_ROOT_PASSWORD" "${DB_ROOT_PASSWORD}" bashio::addon.option "DB_ROOT_PASSWORD" "${DB_ROOT_PASSWORD}"
# Store generated password in the s6 environment if available # Store generated password in the s6 environment if available
if [ -d /var/run/s6/container_environment ]; then if [ -d /var/run/s6/container_environment ]; then
printf "%s" "${DB_ROOT_PASSWORD}" >"/var/run/s6/container_environment/DB_ROOT_PASSWORD" printf "%s" "${DB_ROOT_PASSWORD}" > "/var/run/s6/container_environment/DB_ROOT_PASSWORD"
fi fi
fi fi
# Try to connect as root using the default insecure password. # 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 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..." 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}" <<EOF psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
ALTER ROLE root WITH PASSWORD '${DB_ROOT_PASSWORD}'; ALTER ROLE root WITH PASSWORD '${DB_ROOT_PASSWORD}';
EOF EOF
else else
# Check if the root user exists. # Check if the root user exists.
if ! psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" -tAc "SELECT 1 FROM pg_roles WHERE rolname='root'" | grep -q 1; then if ! psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" -tAc "SELECT 1 FROM pg_roles WHERE rolname='root'" | grep -q 1; then
bashio::log.info "Root user does not exist. Creating root user with DB_ROOT_PASSWORD..." bashio::log.info "Root user does not exist. Creating root user with DB_ROOT_PASSWORD..."
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD '${DB_ROOT_PASSWORD}'; CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD '${DB_ROOT_PASSWORD}';
EOF EOF
else else
bashio::log.info "Root user exists with a non-default password. No migration needed." bashio::log.info "Root user exists with a non-default password. No migration needed."
fi fi
fi fi
} }
# Function to set up the database # Function to set up the database
setup_database() { setup_database() {
bashio::log.info "Setting up external PostgreSQL database..." bashio::log.info "Setting up external PostgreSQL database..."
# Create the database if it does not exist # Create the database if it does not exist
if ! psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}/postgres" -tAc \ if ! psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}/postgres" -tAc \
"SELECT 1 FROM pg_database WHERE datname='${DB_DATABASE_NAME}';" | grep -q 1; then "SELECT 1 FROM pg_database WHERE datname='${DB_DATABASE_NAME}';" | grep -q 1; then
bashio::log.info "Database does not exist. Creating it now..." bashio::log.info "Database does not exist. Creating it now..."
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
CREATE DATABASE ${DB_DATABASE_NAME}; CREATE DATABASE ${DB_DATABASE_NAME};
EOF EOF
else else
bashio::log.info "Database ${DB_DATABASE_NAME} already exists. Ensuring it is configured correctly." bashio::log.info "Database ${DB_DATABASE_NAME} already exists. Ensuring it is configured correctly."
fi fi
# Ensure the user exists and update its password # Ensure the user exists and update its password
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
DO \$\$ DO \$\$
BEGIN BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${DB_USERNAME}') THEN IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${DB_USERNAME}') THEN
@@ -144,38 +144,38 @@ END
\$\$; \$\$;
EOF EOF
# Ensure the user has full privileges on the database # Ensure the user has full privileges on the database
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
GRANT ALL PRIVILEGES ON DATABASE ${DB_DATABASE_NAME} TO ${DB_USERNAME}; GRANT ALL PRIVILEGES ON DATABASE ${DB_DATABASE_NAME} TO ${DB_USERNAME};
EOF EOF
bashio::log.info "Database setup completed successfully." bashio::log.info "Database setup completed successfully."
} }
# Function to check if vectors extension is enabled # Function to check if vectors extension is enabled
check_vector_extension() { check_vector_extension() {
echo "Checking if 'vectors' extension is enabled..." echo "Checking if 'vectors' extension is enabled..."
RESULT=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -tAc "SELECT extname FROM pg_extension WHERE extname = 'vectors';") RESULT=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -tAc "SELECT extname FROM pg_extension WHERE extname = 'vectors';")
if [[ "$RESULT" == "vectors" ]]; then if [[ "$RESULT" == "vectors" ]]; then
echo "✅ 'vectors' extension is enabled." echo "✅ 'vectors' extension is enabled."
return 0 return 0
else else
bashio::log.warning "❌ 'vectors' extension is NOT enabled." bashio::log.warning "❌ 'vectors' extension is NOT enabled."
return 1 return 1
fi fi
} }
# Function to check if vchord extension is enabled # Function to check if vchord extension is enabled
check_vchord_extension() { check_vchord_extension() {
echo "Checking if 'vchord' extension is enabled..." echo "Checking if 'vchord' extension is enabled..."
RESULT=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -tAc "SELECT extname FROM pg_extension WHERE extname = 'vchord';") RESULT=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -tAc "SELECT extname FROM pg_extension WHERE extname = 'vchord';")
if [[ "$RESULT" == "vchord" ]]; then if [[ "$RESULT" == "vchord" ]]; then
echo "✅ 'vchord' extension is enabled." echo "✅ 'vchord' extension is enabled."
return 0 return 0
else else
bashio::log.warning "❌ 'vchord' extension is NOT enabled." bashio::log.warning "❌ 'vchord' extension is NOT enabled."
return 1 return 1
fi fi
} }
######################### #########################

View File

@@ -4,7 +4,7 @@ bashio::log.info "Starting Immich Frame"
mkdir -p /config/Config mkdir -p /config/Config
if [ -f /app/Config ]; then if [ -f /app/Config ]; then
rm -r /app/Config rm -r /app/Config
fi fi
ln -sf /app/Config /config/Config ln -sf /app/Config /config/Config

View File

@@ -4,24 +4,24 @@ bashio::log.info "Starting Immich Power Tools"
# Ensure DB_HOST has no proto in front # Ensure DB_HOST has no proto in front
extract_ip_or_domain() { extract_ip_or_domain() {
local url="$1" local url="$1"
if [[ ! "$url" =~ ^https?:// ]]; then if [[ ! "$url" =~ ^https?:// ]]; then
bashio::log.warning "URL $url has a http:// or https:// prefix. This should not be, it is removed automatically" bashio::log.warning "URL $url has a http:// or https:// prefix. This should not be, it is removed automatically"
echo "$url" | sed -E 's|https?://([^/]+).*|\1|' echo "$url" | sed -E 's|https?://([^/]+).*|\1|'
fi fi
} }
DB_HOST="$(extract_ip_or_domain "$DB_HOST")" DB_HOST="$(extract_ip_or_domain "$DB_HOST")"
export DB_HOST export DB_HOST
# Function to ensure URL has http:// or https:// prefix # Function to ensure URL has http:// or https:// prefix
ensure_http_prefix() { ensure_http_prefix() {
local url="$1" local url="$1"
if [[ ! "$url" =~ ^https?:// ]]; then if [[ ! "$url" =~ ^https?:// ]]; then
bashio::log.warning "URL $url does not have http:// or https:// prefix. Adding http:// by default. If cannot connect to immich, please adapt in your addon options" bashio::log.warning "URL $url does not have http:// or https:// prefix. Adding http:// by default. If cannot connect to immich, please adapt in your addon options"
echo "http://$url" echo "http://$url"
else else
echo "$url" echo "$url"
fi fi
} }
# Ensure IMMICH_URL and EXTERNAL_IMMICH_URL have http:// or https:// prefix # Ensure IMMICH_URL and EXTERNAL_IMMICH_URL have http:// or https:// prefix

View File

@@ -5,7 +5,7 @@ set -e
################# #################
# Create config # # Create config #
################# #################
mustache-cli /data/options.json /templates/inadyn.mustache >/etc/inadyn.conf mustache-cli /data/options.json /templates/inadyn.mustache > /etc/inadyn.conf
# Check it # Check it
/usr/sbin/inadyn --check-config /usr/sbin/inadyn --check-config

View File

@@ -1,22 +1,22 @@
#!/bin/bash #!/bin/bash
if [ ! -d /share/downloads ]; then if [ ! -d /share/downloads ]; then
echo "Creating /share/downloads" echo "Creating /share/downloads"
mkdir -p /share/downloads mkdir -p /share/downloads
chown -R "$PUID:$PGID" /share/downloads chown -R "$PUID:$PGID" /share/downloads
fi fi
if [ -d /config/Jackett ] && [ ! -d /config/addons_config/Jackett ]; then if [ -d /config/Jackett ] && [ ! -d /config/addons_config/Jackett ]; then
echo "Moving to new location /config/addons_config/Jackett" echo "Moving to new location /config/addons_config/Jackett"
mkdir -p /config/addons_config/Jackett mkdir -p /config/addons_config/Jackett
chown -R "$PUID:$PGID" /config/addons_config/Jackett chown -R "$PUID:$PGID" /config/addons_config/Jackett
mv /config/Jackett/* /config/addons_config/Jackett/ mv /config/Jackett/* /config/addons_config/Jackett/
rm -r /config/Jackett rm -r /config/Jackett
rm -r /config/jackett rm -r /config/jackett
fi fi
if [ ! -d /config/addons_config/Jackett ]; then if [ ! -d /config/addons_config/Jackett ]; then
echo "Creating /config/addons_config/Jackett" echo "Creating /config/addons_config/Jackett"
mkdir -p /config/addons_config/Jackett mkdir -p /config/addons_config/Jackett
chown -R "$PUID:$PGID" /config/addons_config/Jackett chown -R "$PUID:$PGID" /config/addons_config/Jackett
fi fi

Some files were not shown because too many files have changed in this diff Show More