mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-09 01:11:04 +01:00
fix: auto-fix linting issues
This commit is contained in:
committed by
github-actions[bot]
parent
3539f328fb
commit
f5428e0950
@@ -7,41 +7,41 @@ set -e
|
||||
# Automatic modules download #
|
||||
##############################
|
||||
if [ -e "/MODULESFILE" ]; then
|
||||
MODULES=$(</MODULESFILE)
|
||||
MODULES="${MODULES:-00-banner.sh}"
|
||||
echo "Executing modules script : $MODULES"
|
||||
MODULES=$(< /MODULESFILE)
|
||||
MODULES="${MODULES:-00-banner.sh}"
|
||||
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 curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi &&
|
||||
apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates >/dev/null || true &&
|
||||
mkdir -p /etc/cont-init.d &&
|
||||
for scripts in $MODULES; do echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || (echo "script failed to install $scripts" && exit 1); done &&
|
||||
chmod -R 755 /etc/cont-init.d
|
||||
if ! command -v bash > /dev/null 2> /dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) > /dev/null; fi \
|
||||
&& if ! command -v curl > /dev/null 2> /dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) > /dev/null; fi \
|
||||
&& apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates > /dev/null || true \
|
||||
&& mkdir -p /etc/cont-init.d \
|
||||
&& for scripts in $MODULES; do echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || (echo "script failed to install $scripts" && exit 1); done \
|
||||
&& chmod -R 755 /etc/cont-init.d
|
||||
fi
|
||||
|
||||
#######################
|
||||
# Automatic installer #
|
||||
#######################
|
||||
if [ -e "/ENVFILE" ]; then
|
||||
PACKAGES=$(</ENVFILE)
|
||||
echo "Executing dependency script with custom elements : $PACKAGES"
|
||||
PACKAGES=$(< /ENVFILE)
|
||||
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 curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi &&
|
||||
curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_automatic_packages.sh" --output /ha_automatic_packages.sh &&
|
||||
chmod 777 /ha_automatic_packages.sh &&
|
||||
eval /./ha_automatic_packages.sh "${PACKAGES:-}" &&
|
||||
rm /ha_automatic_packages.sh
|
||||
if ! command -v bash > /dev/null 2> /dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) > /dev/null; fi \
|
||||
&& if ! command -v curl > /dev/null 2> /dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) > /dev/null; fi \
|
||||
&& curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_automatic_packages.sh" --output /ha_automatic_packages.sh \
|
||||
&& chmod 777 /ha_automatic_packages.sh \
|
||||
&& eval /./ha_automatic_packages.sh "${PACKAGES:-}" \
|
||||
&& rm /ha_automatic_packages.sh
|
||||
fi
|
||||
|
||||
if [ -e "/MODULESFILE" ] && [ ! -f /ha_entrypoint.sh ]; then
|
||||
for scripts in $MODULES; do
|
||||
echo "$scripts : executing"
|
||||
chown "$(id -u)":"$(id -g)" /etc/cont-init.d/"$scripts"
|
||||
chmod a+x /etc/cont-init.d/"$scripts"
|
||||
/./etc/cont-init.d/"$scripts" || echo "/etc/cont-init.d/$scripts: exiting $?"
|
||||
rm /etc/cont-init.d/"$scripts"
|
||||
done | tac
|
||||
for scripts in $MODULES; do
|
||||
echo "$scripts : executing"
|
||||
chown "$(id -u)":"$(id -g)" /etc/cont-init.d/"$scripts"
|
||||
chmod a+x /etc/cont-init.d/"$scripts"
|
||||
/./etc/cont-init.d/"$scripts" || echo "/etc/cont-init.d/$scripts: exiting $?"
|
||||
rm /etc/cont-init.d/"$scripts"
|
||||
done | tac
|
||||
fi
|
||||
|
||||
#######################
|
||||
|
||||
@@ -5,45 +5,45 @@ set -e
|
||||
# Displays a simple add-on banner on startup
|
||||
# ==============================================================================
|
||||
|
||||
if ! bashio::supervisor.ping 2>/dev/null; then
|
||||
# Degraded mode if no homeassistant
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue "Starting addon without HA support"
|
||||
bashio::log.blue "Version : ${BUILD_VERSION:-1.0}"
|
||||
bashio::log.blue "Please use Docker Compose for env variables"
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
# Use environment variables instead of addon options
|
||||
echo "... convert scripts to use environment variables instead of addon options"
|
||||
while IFS= read -r scripts; do
|
||||
sed -i -e 's/bashio::config.has_value[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ]/g' \
|
||||
-e 's/bashio::config.true[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ] \&\& [ "${\1:-}" = "true" ]/g' \
|
||||
-e 's/\$(bashio::config[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"'])/${\1:-}/g' \
|
||||
-e 's/\$(bashio::addon.port[[:space:]]*["'"'"']\([0-9]*\)["'"'"'])/${\1:-}/g' \
|
||||
-e 's/bashio::config.require.ssl/true/g' \
|
||||
-e 's/\$(bashio::addon.ingress_port)/""/g' \
|
||||
-e 's/\$(bashio::addon.ingress_entry)/""/g' \
|
||||
-e 's/\$(bashio::addon.ip_address)/""/g' "$scripts"
|
||||
done < <(grep -srl "bashio" /etc/cont-init.d /custom-services.d)
|
||||
exit 0
|
||||
if ! bashio::supervisor.ping 2> /dev/null; then
|
||||
# Degraded mode if no homeassistant
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue "Starting addon without HA support"
|
||||
bashio::log.blue "Version : ${BUILD_VERSION:-1.0}"
|
||||
bashio::log.blue "Please use Docker Compose for env variables"
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
# Use environment variables instead of addon options
|
||||
echo "... convert scripts to use environment variables instead of addon options"
|
||||
while IFS= read -r scripts; do
|
||||
sed -i -e 's/bashio::config.has_value[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ]/g' \
|
||||
-e 's/bashio::config.true[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']/[ ! -z "${\1:-}" ] \&\& [ "${\1:-}" = "true" ]/g' \
|
||||
-e 's/\$(bashio::config[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"'])/${\1:-}/g' \
|
||||
-e 's/\$(bashio::addon.port[[:space:]]*["'"'"']\([0-9]*\)["'"'"'])/${\1:-}/g' \
|
||||
-e 's/bashio::config.require.ssl/true/g' \
|
||||
-e 's/\$(bashio::addon.ingress_port)/""/g' \
|
||||
-e 's/\$(bashio::addon.ingress_entry)/""/g' \
|
||||
-e 's/\$(bashio::addon.ip_address)/""/g' "$scripts"
|
||||
done < <(grep -srl "bashio" /etc/cont-init.d /custom-services.d)
|
||||
exit 0
|
||||
fi
|
||||
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue " Add-on: $(bashio::addon.name)"
|
||||
bashio::log.blue " $(bashio::addon.description)"
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
'-----------------------------------------------------------'
|
||||
|
||||
bashio::log.blue " Add-on version: $(bashio::addon.version)"
|
||||
if bashio::var.true "$(bashio::addon.update_available)"; then
|
||||
bashio::log.magenta ' There is an update available for this add-on!'
|
||||
bashio::log.magenta \
|
||||
" Latest add-on version: $(bashio::addon.version_latest)"
|
||||
bashio::log.magenta ' Please consider upgrading as soon as possible.'
|
||||
bashio::log.magenta ' There is an update available for this add-on!'
|
||||
bashio::log.magenta \
|
||||
" Latest add-on version: $(bashio::addon.version_latest)"
|
||||
bashio::log.magenta ' Please consider upgrading as soon as possible.'
|
||||
else
|
||||
bashio::log.green ' You are running the latest version of this add-on.'
|
||||
bashio::log.green ' You are running the latest version of this add-on.'
|
||||
fi
|
||||
|
||||
bashio::log.blue " System: $(bashio::info.operating_system)"
|
||||
@@ -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 \
|
||||
'-----------------------------------------------------------'
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue \
|
||||
' Please, share the above information when looking for help'
|
||||
' Please, share the above information when looking for help'
|
||||
bashio::log.blue \
|
||||
' or support in, e.g., GitHub, forums'
|
||||
' or support in, e.g., GitHub, forums'
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.green \
|
||||
' Provided by: https://github.com/alexbelgium/hassio-addons '
|
||||
' Provided by: https://github.com/alexbelgium/hassio-addons '
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
'-----------------------------------------------------------'
|
||||
|
||||
# ==============================================================================
|
||||
# Global actions for all addons
|
||||
# ==============================================================================
|
||||
if bashio::config.has_value "PUID" && bashio::config.has_value "PGID" && id abc &>/dev/null; then
|
||||
bashio::log.green ' Defining permissions for main user : '
|
||||
PUID="$(bashio::config "PUID")"
|
||||
PGID="$(bashio::config "PGID")"
|
||||
usermod -o -u "$PUID" abc
|
||||
groupmod -o -g "$PGID" abc
|
||||
bashio::log.blue "User UID: $(id -u abc)"
|
||||
bashio::log.blue "User GID: $(id -g abc)"
|
||||
if bashio::config.has_value "PUID" && bashio::config.has_value "PGID" && id abc &> /dev/null; then
|
||||
bashio::log.green ' Defining permissions for main user : '
|
||||
PUID="$(bashio::config "PUID")"
|
||||
PGID="$(bashio::config "PGID")"
|
||||
usermod -o -u "$PUID" abc
|
||||
groupmod -o -g "$PGID" abc
|
||||
bashio::log.blue "User UID: $(id -u abc)"
|
||||
bashio::log.blue "User GID: $(id -g abc)"
|
||||
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
fi
|
||||
|
||||
# Clean bashrc file safely
|
||||
if [ -f ~/.bashrc ]; then : >~/.bashrc; fi
|
||||
if [ -f ~/.bashrc ]; then : > ~/.bashrc; fi
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
if ! bashio::supervisor.ping 2>/dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
if ! bashio::supervisor.ping 2> /dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
###################################
|
||||
@@ -16,11 +16,11 @@ JSONSOURCE="/data/options.json"
|
||||
|
||||
# Define secrets location
|
||||
if [ -f /homeassistant/secrets.yaml ]; then
|
||||
SECRETSOURCE="/homeassistant/secrets.yaml"
|
||||
SECRETSOURCE="/homeassistant/secrets.yaml"
|
||||
elif [ -f /config/secrets.yaml ]; then
|
||||
SECRETSOURCE="/config/secrets.yaml"
|
||||
SECRETSOURCE="/config/secrets.yaml"
|
||||
else
|
||||
SECRETSOURCE="false"
|
||||
SECRETSOURCE="false"
|
||||
fi
|
||||
|
||||
# Export keys as env variables
|
||||
@@ -29,89 +29,89 @@ mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
|
||||
|
||||
# Escape special characters using printf and enclose in double quotes
|
||||
sanitize_variable() {
|
||||
local raw="$1" # original value
|
||||
local escaped # value after printf %q
|
||||
# Check if the value is an array
|
||||
if [[ "$raw" == \[* ]]; then
|
||||
echo "One of your options is an array, skipping"
|
||||
return
|
||||
fi
|
||||
printf -v escaped '%q' "$raw"
|
||||
# If nothing changed, return the original.
|
||||
if [[ "$raw" == "$escaped" ]]; then
|
||||
printf '%s' "$raw"
|
||||
return
|
||||
fi
|
||||
# Otherwise protect the escaped string with double quotes.
|
||||
printf '"%s"' "$escaped"
|
||||
local raw="$1" # original value
|
||||
local escaped # value after printf %q
|
||||
# Check if the value is an array
|
||||
if [[ "$raw" == \[* ]]; then
|
||||
echo "One of your options is an array, skipping"
|
||||
return
|
||||
fi
|
||||
printf -v escaped '%q' "$raw"
|
||||
# If nothing changed, return the original.
|
||||
if [[ "$raw" == "$escaped" ]]; then
|
||||
printf '%s' "$raw"
|
||||
return
|
||||
fi
|
||||
# Otherwise protect the escaped string with double quotes.
|
||||
printf '"%s"' "$escaped"
|
||||
}
|
||||
|
||||
for KEYS in "${arr[@]}"; do
|
||||
# export key
|
||||
VALUE=$(jq -r --raw-output ".\"$KEYS\"" "$JSONSOURCE")
|
||||
# Check if the value is an array
|
||||
if [[ "$VALUE" == \[* ]]; then
|
||||
bashio::log.warning "One of your option is an array, skipping"
|
||||
else
|
||||
# Sanitize variable
|
||||
VALUE=$(sanitize_variable "$VALUE")
|
||||
# Continue for single values
|
||||
line="${KEYS}=${VALUE}"
|
||||
# Check if secret
|
||||
if [[ "${line}" == *"!secret "* ]]; then
|
||||
echo "secret detected"
|
||||
# Get argument
|
||||
secret=${line#*secret }
|
||||
# Remove trailing ' or "
|
||||
secret="${secret%[\"\']}"
|
||||
# Stop if secret file not mounted
|
||||
if [[ "$SECRETSOURCE" == "false" ]]; then
|
||||
bashio::log.warning "Homeassistant config not mounted, secrets are not supported"
|
||||
continue
|
||||
fi
|
||||
# Check if single match
|
||||
secretnum=$(sed -n "/$secret:/=" "$SECRETSOURCE")
|
||||
[[ "$secretnum" == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
|
||||
# Get text
|
||||
secret=$(sed -n "/$secret:/p" "$SECRETSOURCE")
|
||||
secret=${secret#*: }
|
||||
line="${line%%=*}='$secret'"
|
||||
VALUE="$secret"
|
||||
fi
|
||||
# text
|
||||
if bashio::config.false "verbose" || [[ "${KEYS,,}" == *"pass"* ]]; then
|
||||
bashio::log.blue "${KEYS}=******"
|
||||
else
|
||||
bashio::log.blue "$line"
|
||||
fi
|
||||
# export key
|
||||
VALUE=$(jq -r --raw-output ".\"$KEYS\"" "$JSONSOURCE")
|
||||
# Check if the value is an array
|
||||
if [[ "$VALUE" == \[* ]]; then
|
||||
bashio::log.warning "One of your option is an array, skipping"
|
||||
else
|
||||
# Sanitize variable
|
||||
VALUE=$(sanitize_variable "$VALUE")
|
||||
# Continue for single values
|
||||
line="${KEYS}=${VALUE}"
|
||||
# Check if secret
|
||||
if [[ "${line}" == *"!secret "* ]]; then
|
||||
echo "secret detected"
|
||||
# Get argument
|
||||
secret=${line#*secret }
|
||||
# Remove trailing ' or "
|
||||
secret="${secret%[\"\']}"
|
||||
# Stop if secret file not mounted
|
||||
if [[ "$SECRETSOURCE" == "false" ]]; then
|
||||
bashio::log.warning "Homeassistant config not mounted, secrets are not supported"
|
||||
continue
|
||||
fi
|
||||
# Check if single match
|
||||
secretnum=$(sed -n "/$secret:/=" "$SECRETSOURCE")
|
||||
[[ "$secretnum" == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
|
||||
# Get text
|
||||
secret=$(sed -n "/$secret:/p" "$SECRETSOURCE")
|
||||
secret=${secret#*: }
|
||||
line="${line%%=*}='$secret'"
|
||||
VALUE="$secret"
|
||||
fi
|
||||
# text
|
||||
if bashio::config.false "verbose" || [[ "${KEYS,,}" == *"pass"* ]]; then
|
||||
bashio::log.blue "${KEYS}=******"
|
||||
else
|
||||
bashio::log.blue "$line"
|
||||
fi
|
||||
|
||||
######################################
|
||||
# Export the variable to run scripts #
|
||||
######################################
|
||||
# shellcheck disable=SC2163
|
||||
export "$line"
|
||||
# export to python
|
||||
if command -v "python3" &>/dev/null; then
|
||||
[ ! -f /env.py ] && echo "import os" >/env.py
|
||||
# Escape \
|
||||
VALUEPY="${VALUE//\\/\\\\}"
|
||||
# Avoid " and '
|
||||
VALUEPY="${VALUEPY//[\"\']/}"
|
||||
echo "os.environ['${KEYS}'] = '$VALUEPY'" >>/env.py
|
||||
python3 /env.py
|
||||
fi
|
||||
# set .env
|
||||
echo "$line" >>/.env || true
|
||||
# set /etc/environment
|
||||
mkdir -p /etc
|
||||
echo "$line" >>/etc/environment
|
||||
# For non s6
|
||||
if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi
|
||||
if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi
|
||||
# For s6
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi
|
||||
echo "export ${KEYS}='${VALUE}'" >>~/.bashrc
|
||||
fi
|
||||
######################################
|
||||
# Export the variable to run scripts #
|
||||
######################################
|
||||
# shellcheck disable=SC2163
|
||||
export "$line"
|
||||
# export to python
|
||||
if command -v "python3" &> /dev/null; then
|
||||
[ ! -f /env.py ] && echo "import os" > /env.py
|
||||
# Escape \
|
||||
VALUEPY="${VALUE//\\/\\\\}"
|
||||
# Avoid " and '
|
||||
VALUEPY="${VALUEPY//[\"\']/}"
|
||||
echo "os.environ['${KEYS}'] = '$VALUEPY'" >> /env.py
|
||||
python3 /env.py
|
||||
fi
|
||||
# set .env
|
||||
echo "$line" >> /.env || true
|
||||
# set /etc/environment
|
||||
mkdir -p /etc
|
||||
echo "$line" >> /etc/environment
|
||||
# For non s6
|
||||
if cat /etc/services.d/*/*run* &> /dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2> /dev/null; fi
|
||||
if cat /etc/cont-init.d/*run* &> /dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2> /dev/null; fi
|
||||
# For s6
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" > /var/run/s6/container_environment/"${KEYS}"; fi
|
||||
echo "export ${KEYS}='${VALUE}'" >> ~/.bashrc
|
||||
fi
|
||||
done
|
||||
|
||||
################
|
||||
@@ -120,8 +120,8 @@ done
|
||||
set +eu
|
||||
|
||||
if [ -n "$TZ" ] && [ -f /etc/localtime ]; then
|
||||
if [ -f /usr/share/zoneinfo/"$TZ" ]; then
|
||||
echo "Timezone set from $(cat /etc/timezone) to $TZ"
|
||||
ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime && echo "$TZ" >/etc/timezone
|
||||
fi
|
||||
if [ -f /usr/share/zoneinfo/"$TZ" ]; then
|
||||
echo "Timezone set from $(cat /etc/timezone) to $TZ"
|
||||
ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
if ! bashio::supervisor.ping 2>/dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
if ! bashio::supervisor.ping 2> /dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
######################
|
||||
@@ -14,97 +14,97 @@ fi
|
||||
# Mount local Share if configured
|
||||
if bashio::config.has_value 'localdisks'; then
|
||||
|
||||
# Available devices
|
||||
blkid | awk '{print substr($1, 0, length($1) - 1)}' | awk -F'/' '{print $NF}' >availabledisks
|
||||
echo "NAME" >>availabledisks
|
||||
# Available devices
|
||||
blkid | awk '{print substr($1, 0, length($1) - 1)}' | awk -F'/' '{print $NF}' > availabledisks
|
||||
echo "NAME" >> availabledisks
|
||||
|
||||
## List available Disk with Labels and Id
|
||||
bashio::log.blue "---------------------------------------------------"
|
||||
bashio::log.info "Available Disks for mounting :"
|
||||
lsblk -o name,label,size,fstype,ro | awk '$4 != "" { print $0 }' | grep -f availabledisks
|
||||
bashio::log.blue "---------------------------------------------------"
|
||||
rm availabledisks
|
||||
## List available Disk with Labels and Id
|
||||
bashio::log.blue "---------------------------------------------------"
|
||||
bashio::log.info "Available Disks for mounting :"
|
||||
lsblk -o name,label,size,fstype,ro | awk '$4 != "" { print $0 }' | grep -f availabledisks
|
||||
bashio::log.blue "---------------------------------------------------"
|
||||
rm availabledisks
|
||||
|
||||
# Show support fs https://github.com/dianlight/hassio-addons/blob/2e903184254617ac2484fe7c03a6e33e6987151c/sambanas/rootfs/etc/s6-overlay/s6-rc.d/init-automount/run#L106
|
||||
fstypessupport=$(grep -v nodev </proc/filesystems | awk '{$1=" "$1}1' | tr -d '\n\t')
|
||||
bashio::log.green "Supported fs : ${fstypessupport}"
|
||||
bashio::log.green "Inspired from : github.com/dianlight"
|
||||
bashio::log.blue "---------------------------------------------------"
|
||||
# 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')
|
||||
bashio::log.green "Supported fs : ${fstypessupport}"
|
||||
bashio::log.green "Inspired from : github.com/dianlight"
|
||||
bashio::log.blue "---------------------------------------------------"
|
||||
|
||||
MOREDISKS=$(bashio::config 'localdisks')
|
||||
echo "Local Disks mounting..."
|
||||
MOREDISKS=$(bashio::config 'localdisks')
|
||||
echo "Local Disks mounting..."
|
||||
|
||||
# Separate comma separated values
|
||||
# shellcheck disable=SC2086
|
||||
for disk in ${MOREDISKS//,/ }; do
|
||||
# Separate comma separated values
|
||||
# shellcheck disable=SC2086
|
||||
for disk in ${MOREDISKS//,/ }; do
|
||||
|
||||
# Remove text until last slash
|
||||
disk="${disk##*/}"
|
||||
# Remove text until last slash
|
||||
disk="${disk##*/}"
|
||||
|
||||
# Function to check what is the type of device
|
||||
if [ -e /dev/"$disk" ]; then
|
||||
echo "... $disk is a physical device"
|
||||
devpath=/dev
|
||||
elif [ -e /dev/disk/by-uuid/"$disk" ] || lsblk -o UUID | grep -q "$disk"; then
|
||||
echo "... $disk is a device by UUID"
|
||||
devpath=/dev/disk/by-uuid
|
||||
elif [ -e /dev/disk/by-label/"$disk" ] || lsblk -o LABEL | grep -q "$disk"; then
|
||||
echo "... $disk is a device by label"
|
||||
devpath=/dev/disk/by-label
|
||||
else
|
||||
bashio::log.fatal "$disk does not match any known physical device, UUID, or label. "
|
||||
continue
|
||||
fi
|
||||
# Function to check what is the type of device
|
||||
if [ -e /dev/"$disk" ]; then
|
||||
echo "... $disk is a physical device"
|
||||
devpath=/dev
|
||||
elif [ -e /dev/disk/by-uuid/"$disk" ] || lsblk -o UUID | grep -q "$disk"; then
|
||||
echo "... $disk is a device by UUID"
|
||||
devpath=/dev/disk/by-uuid
|
||||
elif [ -e /dev/disk/by-label/"$disk" ] || lsblk -o LABEL | grep -q "$disk"; then
|
||||
echo "... $disk is a device by label"
|
||||
devpath=/dev/disk/by-label
|
||||
else
|
||||
bashio::log.fatal "$disk does not match any known physical device, UUID, or label. "
|
||||
continue
|
||||
fi
|
||||
|
||||
# Creates dir
|
||||
mkdir -p /mnt/"$disk"
|
||||
if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then
|
||||
PUID="$(bashio::config 'PUID')"
|
||||
PGID="$(bashio::config 'PGID')"
|
||||
chown "$PUID:$PGID" /mnt/"$disk"
|
||||
fi
|
||||
# Creates dir
|
||||
mkdir -p /mnt/"$disk"
|
||||
if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then
|
||||
PUID="$(bashio::config 'PUID')"
|
||||
PGID="$(bashio::config 'PGID')"
|
||||
chown "$PUID:$PGID" /mnt/"$disk"
|
||||
fi
|
||||
|
||||
# Check FS type and set relative options (thanks @https://github.com/dianlight/hassio-addons)
|
||||
fstype=$(lsblk "$devpath"/"$disk" -no fstype)
|
||||
options="nosuid,relatime,noexec"
|
||||
type="auto"
|
||||
# Check FS type and set relative options (thanks @https://github.com/dianlight/hassio-addons)
|
||||
fstype=$(lsblk "$devpath"/"$disk" -no fstype)
|
||||
options="nosuid,relatime,noexec"
|
||||
type="auto"
|
||||
|
||||
# Check if supported
|
||||
if [[ "${fstypessupport}" != *"${fstype}"* ]]; then
|
||||
bashio::log.fatal : "${fstype} type for ${disk} is not supported"
|
||||
break
|
||||
fi
|
||||
# Check if supported
|
||||
if [[ "${fstypessupport}" != *"${fstype}"* ]]; then
|
||||
bashio::log.fatal : "${fstype} type for ${disk} is not supported"
|
||||
break
|
||||
fi
|
||||
|
||||
# Mount drive
|
||||
bashio::log.info "Mounting ${disk} of type ${fstype}"
|
||||
case "$fstype" in
|
||||
exfat | vfat | msdos)
|
||||
bashio::log.warning "${fstype} permissions and ACL don't works and this is an EXPERIMENTAL support"
|
||||
options="${options},umask=000"
|
||||
;;
|
||||
ntfs)
|
||||
bashio::log.warning "${fstype} is an EXPERIMENTAL support"
|
||||
options="${options},umask=000"
|
||||
type="ntfs"
|
||||
;;
|
||||
squashfs)
|
||||
bashio::log.warning "${fstype} is an EXPERIMENTAL support"
|
||||
options="loop"
|
||||
type="squashfs"
|
||||
;;
|
||||
esac
|
||||
# Mount drive
|
||||
bashio::log.info "Mounting ${disk} of type ${fstype}"
|
||||
case "$fstype" in
|
||||
exfat | vfat | msdos)
|
||||
bashio::log.warning "${fstype} permissions and ACL don't works and this is an EXPERIMENTAL support"
|
||||
options="${options},umask=000"
|
||||
;;
|
||||
ntfs)
|
||||
bashio::log.warning "${fstype} is an EXPERIMENTAL support"
|
||||
options="${options},umask=000"
|
||||
type="ntfs"
|
||||
;;
|
||||
squashfs)
|
||||
bashio::log.warning "${fstype} is an EXPERIMENTAL support"
|
||||
options="loop"
|
||||
type="squashfs"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Legacy mounting : mount to share if still exists (avoid breaking changes)
|
||||
dirpath="/mnt"
|
||||
if [ -d /share/"$disk" ]; then dirpath="/share"; fi
|
||||
# Legacy mounting : mount to share if still exists (avoid breaking changes)
|
||||
dirpath="/mnt"
|
||||
if [ -d /share/"$disk" ]; then dirpath="/share"; fi
|
||||
|
||||
# shellcheck disable=SC2015
|
||||
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."
|
||||
rmdir /mnt/"$disk"
|
||||
bashio::addon.stop
|
||||
)
|
||||
done
|
||||
# shellcheck disable=SC2015
|
||||
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."
|
||||
rmdir /mnt/"$disk"
|
||||
bashio::addon.stop
|
||||
)
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
# shellcheck disable=
|
||||
set -e
|
||||
|
||||
if ! bashio::supervisor.ping 2>/dev/null; then
|
||||
bashio::log.blue "Disabled : please use another method"
|
||||
exit 0
|
||||
if ! bashio::supervisor.ping 2> /dev/null; then
|
||||
bashio::log.blue "Disabled : please use another method"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
####################
|
||||
@@ -14,51 +14,51 @@ fi
|
||||
|
||||
test_mount() {
|
||||
|
||||
# Set initial test
|
||||
MOUNTED=false
|
||||
ERROR_MOUNT=false
|
||||
# Set initial test
|
||||
MOUNTED=false
|
||||
ERROR_MOUNT=false
|
||||
|
||||
# Exit if not mounted
|
||||
if ! mountpoint -q /mnt/"$diskname"; then
|
||||
return 0
|
||||
fi
|
||||
# Exit if not mounted
|
||||
if ! mountpoint -q /mnt/"$diskname"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Exit if can't write
|
||||
[[ -e "/mnt/$diskname/testaze" ]] && rm -r "/mnt/$diskname/testaze"
|
||||
# shellcheck disable=SC2015
|
||||
mkdir "/mnt/$diskname/testaze" && touch "/mnt/$diskname/testaze/testaze" && rm -r "/mnt/$diskname/testaze" || ERROR_MOUNT=true
|
||||
if [[ "$ERROR_MOUNT" == "true" ]]; then
|
||||
# Test write permissions
|
||||
if [[ "$MOUNTOPTIONS" == *"noserverino"* ]]; then
|
||||
bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check UID/GID for permissions, and if the share is rw"
|
||||
else
|
||||
MOUNTOPTIONS="$MOUNTOPTIONS,noserverino"
|
||||
echo "... testing with noserverino"
|
||||
mount_drive "$MOUNTOPTIONS"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
# Exit if can't write
|
||||
[[ -e "/mnt/$diskname/testaze" ]] && rm -r "/mnt/$diskname/testaze"
|
||||
# shellcheck disable=SC2015
|
||||
mkdir "/mnt/$diskname/testaze" && touch "/mnt/$diskname/testaze/testaze" && rm -r "/mnt/$diskname/testaze" || ERROR_MOUNT=true
|
||||
if [[ "$ERROR_MOUNT" == "true" ]]; then
|
||||
# Test write permissions
|
||||
if [[ "$MOUNTOPTIONS" == *"noserverino"* ]]; then
|
||||
bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check UID/GID for permissions, and if the share is rw"
|
||||
else
|
||||
MOUNTOPTIONS="$MOUNTOPTIONS,noserverino"
|
||||
echo "... testing with noserverino"
|
||||
mount_drive "$MOUNTOPTIONS"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set correctly mounted bit
|
||||
MOUNTED=true
|
||||
return 0
|
||||
# Set correctly mounted bit
|
||||
MOUNTED=true
|
||||
return 0
|
||||
|
||||
}
|
||||
|
||||
mount_drive() {
|
||||
|
||||
# Define options
|
||||
MOUNTED=true
|
||||
MOUNTOPTIONS="$1"
|
||||
# Define options
|
||||
MOUNTED=true
|
||||
MOUNTOPTIONS="$1"
|
||||
|
||||
# Try mounting
|
||||
mount -t cifs -o "$MOUNTOPTIONS" "$disk" /mnt/"$diskname" 2>ERRORCODE || MOUNTED=false
|
||||
# Try mounting
|
||||
mount -t cifs -o "$MOUNTOPTIONS" "$disk" /mnt/"$diskname" 2> ERRORCODE || MOUNTED=false
|
||||
|
||||
# Test if succesful
|
||||
if [[ "$MOUNTED" == "true" ]]; then
|
||||
# shellcheck disable=SC2015
|
||||
test_mount
|
||||
fi
|
||||
# Test if succesful
|
||||
if [[ "$MOUNTED" == "true" ]]; then
|
||||
# shellcheck disable=SC2015
|
||||
test_mount
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
@@ -68,215 +68,215 @@ mount_drive() {
|
||||
|
||||
if bashio::config.has_value 'networkdisks'; then
|
||||
|
||||
# Alert message that it is a new code
|
||||
if [[ "$(date +"%Y%m%d")" -lt "20240201" ]]; then
|
||||
bashio::log.warning "------------------------"
|
||||
bashio::log.warning "This is a new code, please report any issues on https://github.com/alexbelgium/hassio-addons"
|
||||
bashio::log.warning "------------------------"
|
||||
fi
|
||||
# Alert message that it is a new code
|
||||
if [[ "$(date +"%Y%m%d")" -lt "20240201" ]]; then
|
||||
bashio::log.warning "------------------------"
|
||||
bashio::log.warning "This is a new code, please report any issues on https://github.com/alexbelgium/hassio-addons"
|
||||
bashio::log.warning "------------------------"
|
||||
fi
|
||||
|
||||
echo 'Mounting smb share(s)...'
|
||||
echo 'Mounting smb share(s)...'
|
||||
|
||||
####################
|
||||
# Define variables #
|
||||
####################
|
||||
####################
|
||||
# Define variables #
|
||||
####################
|
||||
|
||||
# Set variables
|
||||
MOREDISKS=$(bashio::config 'networkdisks')
|
||||
USERNAME=$(bashio::config 'cifsusername')
|
||||
PASSWORD=$(bashio::config 'cifspassword')
|
||||
SMBVERS=""
|
||||
SECVERS=""
|
||||
CHARSET=",iocharset=utf8"
|
||||
# Set variables
|
||||
MOREDISKS=$(bashio::config 'networkdisks')
|
||||
USERNAME=$(bashio::config 'cifsusername')
|
||||
PASSWORD=$(bashio::config 'cifspassword')
|
||||
SMBVERS=""
|
||||
SECVERS=""
|
||||
CHARSET=",iocharset=utf8"
|
||||
|
||||
# Clean data
|
||||
MOREDISKS=${MOREDISKS// \/\//,\/\/}
|
||||
MOREDISKS=${MOREDISKS//, /,}
|
||||
MOREDISKS=${MOREDISKS// /"\040"}
|
||||
# Clean data
|
||||
MOREDISKS=${MOREDISKS// \/\//,\/\/}
|
||||
MOREDISKS=${MOREDISKS//, /,}
|
||||
MOREDISKS=${MOREDISKS// /"\040"}
|
||||
|
||||
# Is domain set
|
||||
DOMAIN=""
|
||||
DOMAINCLIENT=""
|
||||
if bashio::config.has_value 'cifsdomain'; then
|
||||
echo "... using domain $(bashio::config 'cifsdomain')"
|
||||
DOMAIN=",domain=$(bashio::config 'cifsdomain')"
|
||||
DOMAINCLIENT="--workgroup=$(bashio::config 'cifsdomain')"
|
||||
fi
|
||||
# Is domain set
|
||||
DOMAIN=""
|
||||
DOMAINCLIENT=""
|
||||
if bashio::config.has_value 'cifsdomain'; then
|
||||
echo "... using domain $(bashio::config 'cifsdomain')"
|
||||
DOMAIN=",domain=$(bashio::config 'cifsdomain')"
|
||||
DOMAINCLIENT="--workgroup=$(bashio::config 'cifsdomain')"
|
||||
fi
|
||||
|
||||
# Is UID/GID set
|
||||
PUID=",uid=$(id -u)"
|
||||
PGID=",gid=$(id -g)"
|
||||
if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then
|
||||
echo "... using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')"
|
||||
PUID=",uid=$(bashio::config 'PUID')"
|
||||
PGID=",gid=$(bashio::config 'PGID')"
|
||||
fi
|
||||
# Is UID/GID set
|
||||
PUID=",uid=$(id -u)"
|
||||
PGID=",gid=$(id -g)"
|
||||
if bashio::config.has_value 'PUID' && bashio::config.has_value 'PGID'; then
|
||||
echo "... using PUID $(bashio::config 'PUID') and PGID $(bashio::config 'PGID')"
|
||||
PUID=",uid=$(bashio::config 'PUID')"
|
||||
PGID=",gid=$(bashio::config 'PGID')"
|
||||
fi
|
||||
|
||||
##################
|
||||
# Mounting disks #
|
||||
##################
|
||||
##################
|
||||
# Mounting disks #
|
||||
##################
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
for disk in ${MOREDISKS//,/ }; do # Separate comma separated values
|
||||
# shellcheck disable=SC2086
|
||||
for disk in ${MOREDISKS//,/ }; do # Separate comma separated values
|
||||
|
||||
# Clean name of network share
|
||||
# shellcheck disable=SC2116,SC2001
|
||||
disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name
|
||||
disk="${disk//"\040"/ }" #replace \040 with
|
||||
diskname="${disk//\\//}" #replace \ with /
|
||||
diskname="${diskname##*/}" # Get only last part of the name
|
||||
MOUNTED=false
|
||||
# Clean name of network share
|
||||
# shellcheck disable=SC2116,SC2001
|
||||
disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name
|
||||
disk="${disk//"\040"/ }" #replace \040 with
|
||||
diskname="${disk//\\//}" #replace \ with /
|
||||
diskname="${diskname##*/}" # Get only last part of the name
|
||||
MOUNTED=false
|
||||
|
||||
# Start
|
||||
echo "... mounting $disk"
|
||||
# Start
|
||||
echo "... mounting $disk"
|
||||
|
||||
# Data validation
|
||||
if [[ ! "$disk" =~ ^.*+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[/]+.*+$ ]]; then
|
||||
bashio::log.fatal "...... the structure of your \"networkdisks\" option : \"$disk\" doesn't seem correct, please use a structure like //123.12.12.12/sharedfolder,//123.12.12.12/sharedfolder2. If you don't use it, you can simply remove the text, this will avoid this error message in the future."
|
||||
touch ERRORCODE
|
||||
continue
|
||||
fi
|
||||
# Data validation
|
||||
if [[ ! "$disk" =~ ^.*+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[/]+.*+$ ]]; then
|
||||
bashio::log.fatal "...... the structure of your \"networkdisks\" option : \"$disk\" doesn't seem correct, please use a structure like //123.12.12.12/sharedfolder,//123.12.12.12/sharedfolder2. If you don't use it, you can simply remove the text, this will avoid this error message in the future."
|
||||
touch ERRORCODE
|
||||
continue
|
||||
fi
|
||||
|
||||
# Prepare mount point
|
||||
mkdir -p /mnt/"$diskname"
|
||||
chown root:root /mnt/"$diskname"
|
||||
# Prepare mount point
|
||||
mkdir -p /mnt/"$diskname"
|
||||
chown root:root /mnt/"$diskname"
|
||||
|
||||
# Quickly try to mount with defaults
|
||||
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
|
||||
# Quickly try to mount with defaults
|
||||
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
|
||||
|
||||
# Deeper analysis if failed
|
||||
if [ "$MOUNTED" = false ]; then
|
||||
# Deeper analysis if failed
|
||||
if [ "$MOUNTED" = false ]; then
|
||||
|
||||
# Extract ip part of server for further manipulation
|
||||
server="$(echo "$disk" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")"
|
||||
# Extract ip part of server for further manipulation
|
||||
server="$(echo "$disk" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")"
|
||||
|
||||
# Does server exists
|
||||
output="$(nmap -F $server -T5 -oG -)"
|
||||
if ! echo "$output" | grep 445/open &>/dev/null; then
|
||||
if echo "$output" | grep /open &>/dev/null; then
|
||||
bashio::log.fatal "...... $server is reachable but SMB port not opened, stopping script"
|
||||
touch ERRORCODE
|
||||
continue
|
||||
else
|
||||
bashio::log.fatal "...... fatal : $server not reachable, is it correct"
|
||||
touch ERRORCODE
|
||||
continue
|
||||
fi
|
||||
else
|
||||
echo "...... $server is confirmed reachable"
|
||||
fi
|
||||
# Does server exists
|
||||
output="$(nmap -F $server -T5 -oG -)"
|
||||
if ! echo "$output" | grep 445/open &> /dev/null; then
|
||||
if echo "$output" | grep /open &> /dev/null; then
|
||||
bashio::log.fatal "...... $server is reachable but SMB port not opened, stopping script"
|
||||
touch ERRORCODE
|
||||
continue
|
||||
else
|
||||
bashio::log.fatal "...... fatal : $server not reachable, is it correct"
|
||||
touch ERRORCODE
|
||||
continue
|
||||
fi
|
||||
else
|
||||
echo "...... $server is confirmed reachable"
|
||||
fi
|
||||
|
||||
# Are credentials correct
|
||||
OUTPUT="$(smbclient -t 2 -L "$disk" -U "$USERNAME"%"$PASSWORD" -c "exit" $DOMAINCLIENT 2>&1 || true)"
|
||||
if echo "$OUTPUT" | grep -q "LOGON_FAILURE"; then
|
||||
bashio::log.fatal "...... incorrect Username, Password, or Domain! Script will stop."
|
||||
touch ERRORCODE
|
||||
# Should there be a workgroup
|
||||
if ! smbclient -t 2 -L $disk -N $DOMAINCLIENT -c "exit" &>/dev/null; then
|
||||
bashio::log.fatal "...... perhaps a workgroup must be specified"
|
||||
touch ERRORCODE
|
||||
fi
|
||||
continue
|
||||
elif echo "$OUTPUT" | grep -q "tree connect failed" || echo "$OUTPUT" | grep -q "NT_STATUS_CONNECTION_DISCONNECTED"; then
|
||||
echo "... testing path"
|
||||
bashio::log.fatal "...... invalid or inaccessible SMB path. Script will stop."
|
||||
touch ERRORCODE
|
||||
continue
|
||||
elif ! echo "$OUTPUT" | grep -q "Disk"; then
|
||||
echo "... testing path"
|
||||
bashio::log.fatal "...... no shares found. Invalid or inaccessible SMB path?"
|
||||
else
|
||||
echo "...... credentials are valid"
|
||||
fi
|
||||
# Are credentials correct
|
||||
OUTPUT="$(smbclient -t 2 -L "$disk" -U "$USERNAME"%"$PASSWORD" -c "exit" $DOMAINCLIENT 2>&1 || true)"
|
||||
if echo "$OUTPUT" | grep -q "LOGON_FAILURE"; then
|
||||
bashio::log.fatal "...... incorrect Username, Password, or Domain! Script will stop."
|
||||
touch ERRORCODE
|
||||
# Should there be a workgroup
|
||||
if ! smbclient -t 2 -L $disk -N $DOMAINCLIENT -c "exit" &> /dev/null; then
|
||||
bashio::log.fatal "...... perhaps a workgroup must be specified"
|
||||
touch ERRORCODE
|
||||
fi
|
||||
continue
|
||||
elif echo "$OUTPUT" | grep -q "tree connect failed" || echo "$OUTPUT" | grep -q "NT_STATUS_CONNECTION_DISCONNECTED"; then
|
||||
echo "... testing path"
|
||||
bashio::log.fatal "...... invalid or inaccessible SMB path. Script will stop."
|
||||
touch ERRORCODE
|
||||
continue
|
||||
elif ! echo "$OUTPUT" | grep -q "Disk"; then
|
||||
echo "... testing path"
|
||||
bashio::log.fatal "...... no shares found. Invalid or inaccessible SMB path?"
|
||||
else
|
||||
echo "...... credentials are valid"
|
||||
fi
|
||||
|
||||
# Extracting SMB versions and normalize output
|
||||
# shellcheck disable=SC2210,SC2094
|
||||
SMBVERS="$(nmap --script smb-protocols "$server" -p 445 2>1 | awk '/ [0-9]/' | awk '{print $NF}' | cut -c -3 | sort -V | tail -n 1 || true)"
|
||||
# Avoid :
|
||||
SMBVERS="${SMBVERS/:/.}"
|
||||
# Manage output
|
||||
if [ -n "$SMBVERS" ]; then
|
||||
case $SMBVERS in
|
||||
"202" | "200" | "20")
|
||||
SMBVERS="2.0"
|
||||
;;
|
||||
21)
|
||||
SMBVERS="2.1"
|
||||
;;
|
||||
302)
|
||||
SMBVERS="3.02"
|
||||
;;
|
||||
311)
|
||||
SMBVERS="3.1.1"
|
||||
;;
|
||||
"3.1")
|
||||
echo "SMB 3.1 detected, converting to 3.0"
|
||||
SMBVERS="3.0"
|
||||
;;
|
||||
esac
|
||||
echo "...... SMB version detected : $SMBVERS"
|
||||
SMBVERS=",vers=$SMBVERS"
|
||||
elif smbclient -t 2 -L "$server" -m NT1 -N $DOMAINCLIENT &>/dev/null; then
|
||||
echo "...... SMB version : only SMBv1 is supported, this can lead to issues"
|
||||
SECVERS=",sec=ntlm"
|
||||
SMBVERS=",vers=1.0"
|
||||
else
|
||||
echo "...... SMB version : couldn't detect, default used"
|
||||
SMBVERS=""
|
||||
fi
|
||||
# Extracting SMB versions and normalize output
|
||||
# shellcheck disable=SC2210,SC2094
|
||||
SMBVERS="$(nmap --script smb-protocols "$server" -p 445 2> 1 | awk '/ [0-9]/' | awk '{print $NF}' | cut -c -3 | sort -V | tail -n 1 || true)"
|
||||
# Avoid :
|
||||
SMBVERS="${SMBVERS/:/.}"
|
||||
# Manage output
|
||||
if [ -n "$SMBVERS" ]; then
|
||||
case $SMBVERS in
|
||||
"202" | "200" | "20")
|
||||
SMBVERS="2.0"
|
||||
;;
|
||||
21)
|
||||
SMBVERS="2.1"
|
||||
;;
|
||||
302)
|
||||
SMBVERS="3.02"
|
||||
;;
|
||||
311)
|
||||
SMBVERS="3.1.1"
|
||||
;;
|
||||
"3.1")
|
||||
echo "SMB 3.1 detected, converting to 3.0"
|
||||
SMBVERS="3.0"
|
||||
;;
|
||||
esac
|
||||
echo "...... SMB version detected : $SMBVERS"
|
||||
SMBVERS=",vers=$SMBVERS"
|
||||
elif smbclient -t 2 -L "$server" -m NT1 -N $DOMAINCLIENT &> /dev/null; then
|
||||
echo "...... SMB version : only SMBv1 is supported, this can lead to issues"
|
||||
SECVERS=",sec=ntlm"
|
||||
SMBVERS=",vers=1.0"
|
||||
else
|
||||
echo "...... SMB version : couldn't detect, default used"
|
||||
SMBVERS=""
|
||||
fi
|
||||
|
||||
# Test with different security versions
|
||||
#######################################
|
||||
for SECVERS in "$SECVERS" ",sec=ntlmv2" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=krb5i" ",sec=krb5" ",sec=ntlm" ",sec=ntlmv2i"; do
|
||||
if [ "$MOUNTED" = false ]; then
|
||||
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
|
||||
fi
|
||||
done
|
||||
# Test with different security versions
|
||||
#######################################
|
||||
for SECVERS in "$SECVERS" ",sec=ntlmv2" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=krb5i" ",sec=krb5" ",sec=ntlm" ",sec=ntlmv2i"; do
|
||||
if [ "$MOUNTED" = false ]; then
|
||||
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
|
||||
fi
|
||||
done
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# Messages
|
||||
if [ "$MOUNTED" = true ]; then
|
||||
# Messages
|
||||
if [ "$MOUNTED" = true ]; then
|
||||
|
||||
bashio::log.info "...... $disk successfully mounted to /mnt/$diskname with options ${MOUNTOPTIONS/$PASSWORD/XXXXXXXXXX}"
|
||||
# Remove errorcode
|
||||
if [ -f ERRORCODE ]; then
|
||||
rm ERRORCODE
|
||||
fi
|
||||
bashio::log.info "...... $disk successfully mounted to /mnt/$diskname with options ${MOUNTOPTIONS/$PASSWORD/XXXXXXXXXX}"
|
||||
# Remove errorcode
|
||||
if [ -f ERRORCODE ]; then
|
||||
rm ERRORCODE
|
||||
fi
|
||||
|
||||
# Alert if smbv1
|
||||
if [[ "$MOUNTOPTIONS" == *"1.0"* ]]; then
|
||||
bashio::log.warning ""
|
||||
bashio::log.warning "Your smb system requires smbv1. This is an obsolete protocol. Please correct this to prevent issues."
|
||||
bashio::log.warning ""
|
||||
fi
|
||||
# Alert if smbv1
|
||||
if [[ "$MOUNTOPTIONS" == *"1.0"* ]]; then
|
||||
bashio::log.warning ""
|
||||
bashio::log.warning "Your smb system requires smbv1. This is an obsolete protocol. Please correct this to prevent issues."
|
||||
bashio::log.warning ""
|
||||
fi
|
||||
|
||||
else
|
||||
# Mounting failed messages
|
||||
bashio::log.fatal "Error, unable to mount $disk to /mnt/$diskname with username $USERNAME, $PASSWORD. Please check your remote share path, username, password, domain, try putting 0 in UID and GID"
|
||||
bashio::log.fatal "Here is some debugging info :"
|
||||
else
|
||||
# Mounting failed messages
|
||||
bashio::log.fatal "Error, unable to mount $disk to /mnt/$diskname with username $USERNAME, $PASSWORD. Please check your remote share path, username, password, domain, try putting 0 in UID and GID"
|
||||
bashio::log.fatal "Here is some debugging info :"
|
||||
|
||||
# Provide debugging info
|
||||
smbclient -t 2 -L $disk -U "$USERNAME%$PASSWORD" -c "exit"
|
||||
# Provide debugging info
|
||||
smbclient -t 2 -L $disk -U "$USERNAME%$PASSWORD" -c "exit"
|
||||
|
||||
# Error code
|
||||
SMBVERS=""
|
||||
SECVERS=""
|
||||
PUID=""
|
||||
PGID=""
|
||||
CHARSET=""
|
||||
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
|
||||
bashio::log.fatal "Error read : $(<ERRORCODE), addon will stop in 1 min"
|
||||
# Error code
|
||||
SMBVERS=""
|
||||
SECVERS=""
|
||||
PUID=""
|
||||
PGID=""
|
||||
CHARSET=""
|
||||
mount_drive "rw,file_mode=0775,dir_mode=0775,username=${USERNAME},password=${PASSWORD},nobrl${SMBVERS}${SECVERS}${PUID}${PGID}${CHARSET}${DOMAIN}"
|
||||
bashio::log.fatal "Error read : $(< ERRORCODE), addon will stop in 1 min"
|
||||
|
||||
# clean folder
|
||||
umount "/mnt/$diskname" 2>/dev/null || true
|
||||
rmdir "/mnt/$diskname" || true
|
||||
# clean folder
|
||||
umount "/mnt/$diskname" 2> /dev/null || true
|
||||
rmdir "/mnt/$diskname" || true
|
||||
|
||||
# Stop addon
|
||||
bashio::addon.stop
|
||||
# Stop addon
|
||||
bashio::addon.stop
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
##################
|
||||
|
||||
# Disable if config not present
|
||||
if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
if [ ! -d /config ] || ! bashio::supervisor.ping 2> /dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Define slug
|
||||
@@ -17,13 +17,13 @@ slug="${slug#*_}"
|
||||
|
||||
# Check type of config folder
|
||||
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
|
||||
# New config location
|
||||
CONFIGLOCATION="/config"
|
||||
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml"
|
||||
# New config location
|
||||
CONFIGLOCATION="/config"
|
||||
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml"
|
||||
else
|
||||
# Legacy config location
|
||||
CONFIGLOCATION="/config/addons_config/${slug}"
|
||||
CONFIGFILEBROWSER="/homeassistant/addons_config/$slug/config.yaml"
|
||||
# Legacy config location
|
||||
CONFIGLOCATION="/config/addons_config/${slug}"
|
||||
CONFIGFILEBROWSER="/homeassistant/addons_config/$slug/config.yaml"
|
||||
fi
|
||||
|
||||
# Default location
|
||||
@@ -32,51 +32,51 @@ CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
|
||||
|
||||
# Is there a custom path
|
||||
if bashio::config.has_value 'CONFIG_LOCATION'; then
|
||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
if [[ "$CONFIGSOURCE" == *"."* ]]; then
|
||||
CONFIGSOURCE=$(dirname "$CONFIGSOURCE")
|
||||
fi
|
||||
# If does not end by config.yaml, remove trailing slash and add config.yaml
|
||||
if [[ "$CONFIGSOURCE" != *".yaml" ]]; then
|
||||
CONFIGSOURCE="${CONFIGSOURCE%/}"/config.yaml
|
||||
fi
|
||||
# Check if config is located in an acceptable location
|
||||
LOCATIONOK=""
|
||||
for location in "/share" "/config" "/data"; do
|
||||
if [[ "$CONFIGSOURCE" == "$location"* ]]; then
|
||||
LOCATIONOK=true
|
||||
fi
|
||||
done
|
||||
if [ -z "$LOCATIONOK" ]; then
|
||||
bashio::log.red "Watch-out: your CONFIG_LOCATION values can only be set in /share, /config or /data (internal to addon). It will be reset to the default location: $CONFIGLOCATION/config.yaml"
|
||||
CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
|
||||
fi
|
||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
if [[ "$CONFIGSOURCE" == *"."* ]]; then
|
||||
CONFIGSOURCE=$(dirname "$CONFIGSOURCE")
|
||||
fi
|
||||
# If does not end by config.yaml, remove trailing slash and add config.yaml
|
||||
if [[ "$CONFIGSOURCE" != *".yaml" ]]; then
|
||||
CONFIGSOURCE="${CONFIGSOURCE%/}"/config.yaml
|
||||
fi
|
||||
# Check if config is located in an acceptable location
|
||||
LOCATIONOK=""
|
||||
for location in "/share" "/config" "/data"; do
|
||||
if [[ "$CONFIGSOURCE" == "$location"* ]]; then
|
||||
LOCATIONOK=true
|
||||
fi
|
||||
done
|
||||
if [ -z "$LOCATIONOK" ]; then
|
||||
bashio::log.red "Watch-out: your CONFIG_LOCATION values can only be set in /share, /config or /data (internal to addon). It will be reset to the default location: $CONFIGLOCATION/config.yaml"
|
||||
CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
|
||||
fi
|
||||
fi
|
||||
|
||||
# Migrate if needed
|
||||
if [[ "$CONFIGLOCATION" == "/config" ]]; then
|
||||
# Migrate file
|
||||
if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then
|
||||
echo "Migrating config.yaml to new config location"
|
||||
mv "/homeassistant/addons_config/${slug}/config.yaml" /config/config.yaml
|
||||
fi
|
||||
# Migrate option
|
||||
if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then
|
||||
bashio::addon.option "CONFIG_LOCATION" "/config/config.yaml"
|
||||
CONFIGSOURCE="/config/config.yaml"
|
||||
fi
|
||||
# Migrate file
|
||||
if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then
|
||||
echo "Migrating config.yaml to new config location"
|
||||
mv "/homeassistant/addons_config/${slug}/config.yaml" /config/config.yaml
|
||||
fi
|
||||
# Migrate option
|
||||
if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then
|
||||
bashio::addon.option "CONFIG_LOCATION" "/config/config.yaml"
|
||||
CONFIGSOURCE="/config/config.yaml"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$CONFIGSOURCE" != *".yaml" ]]; then
|
||||
bashio::log.error "Something is going wrong in the config location, quitting"
|
||||
exit 1
|
||||
bashio::log.error "Something is going wrong in the config location, quitting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Permissions
|
||||
if [[ "$CONFIGSOURCE" == *".yaml" ]]; then
|
||||
echo "Setting permissions for the config.yaml directory"
|
||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||
chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2>/dev/null
|
||||
echo "Setting permissions for the config.yaml directory"
|
||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||
chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2> /dev/null
|
||||
fi
|
||||
|
||||
####################
|
||||
@@ -86,9 +86,9 @@ fi
|
||||
echo ""
|
||||
bashio::log.green "Load environment variables from $CONFIGSOURCE if existing"
|
||||
if [[ "$CONFIGSOURCE" == "/config"* ]]; then
|
||||
bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGFILEBROWSER"
|
||||
bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGFILEBROWSER"
|
||||
else
|
||||
bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGSOURCE"
|
||||
bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGSOURCE"
|
||||
fi
|
||||
bashio::log.green "---------------------------------------------------------"
|
||||
bashio::log.green "Wiki here on how to use: 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
|
||||
if [ ! -f "$CONFIGSOURCE" ]; then
|
||||
echo "... no config file, creating one from template. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
# Create folder
|
||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||
# Placing template in config
|
||||
if [ -f /templates/config.yaml ]; then
|
||||
# Use available template
|
||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"
|
||||
else
|
||||
# Download template
|
||||
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template"
|
||||
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE"
|
||||
fi
|
||||
echo "... no config file, creating one from template. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
# Create folder
|
||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||
# Placing template in config
|
||||
if [ -f /templates/config.yaml ]; then
|
||||
# Use available template
|
||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"
|
||||
else
|
||||
# Download template
|
||||
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template"
|
||||
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if there are lines to read
|
||||
@@ -115,20 +115,20 @@ cp "$CONFIGSOURCE" /tempenv
|
||||
sed -i '/^#/d' /tempenv
|
||||
sed -i '/^[[:space:]]*$/d' /tempenv
|
||||
sed -i '/^$/d' /tempenv
|
||||
echo "" >>/tempenv
|
||||
echo "" >> /tempenv
|
||||
|
||||
# Exit if empty
|
||||
if [ ! -s /tempenv ]; then
|
||||
bashio::log.green "... no env variables found, exiting"
|
||||
exit 0
|
||||
bashio::log.green "... no env variables found, exiting"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed /tempenv &>ERROR || EXIT_CODE=$?
|
||||
yamllint -d relaxed /tempenv &> ERROR || EXIT_CODE=$?
|
||||
if [ "$EXIT_CODE" != 0 ]; then
|
||||
cat ERROR
|
||||
bashio::log.yellow "... config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above."
|
||||
cat ERROR
|
||||
bashio::log.yellow "... config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above."
|
||||
fi
|
||||
|
||||
# converts yaml to variables
|
||||
@@ -139,64 +139,64 @@ SECRETSFILE="/config/secrets.yaml"
|
||||
if [ ! -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi
|
||||
|
||||
while IFS= read -r line; do
|
||||
# Skip empty lines
|
||||
if [[ -z "$line" ]]; then
|
||||
continue
|
||||
fi
|
||||
# Skip empty lines
|
||||
if [[ -z "$line" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if secret
|
||||
if [[ "$line" == *!secret* ]]; then
|
||||
echo "Secret detected"
|
||||
if [ ! -f "$SECRETSFILE" ]; then
|
||||
bashio::log.fatal "Secrets file not found in $SECRETSFILE, $line skipped"
|
||||
continue
|
||||
fi
|
||||
secret=$(echo "$line" | sed 's/.*!secret \(.*\)/\1/')
|
||||
# Check if single match
|
||||
secretnum=$(sed -n "/$secret:/=" "$SECRETSFILE")
|
||||
if [[ $(echo "$secretnum" | grep -q ' ') ]]; then
|
||||
bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
|
||||
fi
|
||||
# Get text
|
||||
secret_value=$(sed -n "/$secret:/s/.*: //p" "$SECRETSFILE")
|
||||
line="${line%%=*}='$secret_value'"
|
||||
fi
|
||||
# Check if secret
|
||||
if [[ "$line" == *!secret* ]]; then
|
||||
echo "Secret detected"
|
||||
if [ ! -f "$SECRETSFILE" ]; then
|
||||
bashio::log.fatal "Secrets file not found in $SECRETSFILE, $line skipped"
|
||||
continue
|
||||
fi
|
||||
secret=$(echo "$line" | sed 's/.*!secret \(.*\)/\1/')
|
||||
# Check if single match
|
||||
secretnum=$(sed -n "/$secret:/=" "$SECRETSFILE")
|
||||
if [[ $(echo "$secretnum" | grep -q ' ') ]]; then
|
||||
bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
|
||||
fi
|
||||
# Get text
|
||||
secret_value=$(sed -n "/$secret:/s/.*: //p" "$SECRETSFILE")
|
||||
line="${line%%=*}='$secret_value'"
|
||||
fi
|
||||
|
||||
# Data validation
|
||||
if [[ "$line" =~ ^[^[:space:]]+.+[=].+$ ]]; then
|
||||
# extract keys and values
|
||||
KEYS="${line%%=*}"
|
||||
VALUE="${line#*=}"
|
||||
# Check if VALUE is quoted
|
||||
#if [[ "$VALUE" != \"*\" ]] && [[ "$VALUE" != \'*\' ]]; then
|
||||
# VALUE="\"$VALUE\""
|
||||
#fi
|
||||
line="${KEYS}=${VALUE}"
|
||||
export "$line"
|
||||
# export to python
|
||||
if command -v "python3" &>/dev/null; then
|
||||
[ ! -f /env.py ] && echo "import os" >/env.py
|
||||
# Escape single quotes in VALUE
|
||||
VALUE_ESCAPED="${VALUE//\'/\'\"\'\"\'}"
|
||||
echo "os.environ['${KEYS}'] = '${VALUE_ESCAPED}'" >>/env.py
|
||||
python3 /env.py
|
||||
fi
|
||||
# set .env
|
||||
echo "$line" >>/.env
|
||||
# set environment
|
||||
mkdir -p /etc
|
||||
echo "$line" >>/etc/environment
|
||||
# Export to scripts
|
||||
if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi
|
||||
if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi
|
||||
# For s6
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi
|
||||
echo "export $line" >>~/.bashrc
|
||||
# Show in log
|
||||
if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi
|
||||
else
|
||||
bashio::log.red "Skipping line that does not follow the correct structure: $line"
|
||||
fi
|
||||
done <"/tempenv"
|
||||
# Data validation
|
||||
if [[ "$line" =~ ^[^[:space:]]+.+[=].+$ ]]; then
|
||||
# extract keys and values
|
||||
KEYS="${line%%=*}"
|
||||
VALUE="${line#*=}"
|
||||
# Check if VALUE is quoted
|
||||
#if [[ "$VALUE" != \"*\" ]] && [[ "$VALUE" != \'*\' ]]; then
|
||||
# VALUE="\"$VALUE\""
|
||||
#fi
|
||||
line="${KEYS}=${VALUE}"
|
||||
export "$line"
|
||||
# export to python
|
||||
if command -v "python3" &> /dev/null; then
|
||||
[ ! -f /env.py ] && echo "import os" > /env.py
|
||||
# Escape single quotes in VALUE
|
||||
VALUE_ESCAPED="${VALUE//\'/\'\"\'\"\'}"
|
||||
echo "os.environ['${KEYS}'] = '${VALUE_ESCAPED}'" >> /env.py
|
||||
python3 /env.py
|
||||
fi
|
||||
# set .env
|
||||
echo "$line" >> /.env
|
||||
# set environment
|
||||
mkdir -p /etc
|
||||
echo "$line" >> /etc/environment
|
||||
# Export to scripts
|
||||
if cat /etc/services.d/*/*run* &> /dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2> /dev/null; fi
|
||||
if cat /etc/cont-init.d/*run* &> /dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2> /dev/null; fi
|
||||
# For s6
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" > /var/run/s6/container_environment/"${KEYS}"; fi
|
||||
echo "export $line" >> ~/.bashrc
|
||||
# Show in log
|
||||
if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi
|
||||
else
|
||||
bashio::log.red "Skipping line that does not follow the correct structure: $line"
|
||||
fi
|
||||
done < "/tempenv"
|
||||
|
||||
rm /tempenv
|
||||
|
||||
@@ -7,9 +7,9 @@ set -e
|
||||
##################
|
||||
|
||||
# Exit if /config is not mounted or HA not used
|
||||
if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
if [ ! -d /config ] || ! bashio::supervisor.ping 2> /dev/null; then
|
||||
echo "..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Define slug
|
||||
@@ -18,13 +18,13 @@ slug="${slug#*_}"
|
||||
|
||||
# Check type of config folder
|
||||
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
|
||||
# New config location
|
||||
CONFIGLOCATION="/config"
|
||||
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh"
|
||||
# New config location
|
||||
CONFIGLOCATION="/config"
|
||||
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh"
|
||||
else
|
||||
# Legacy config location
|
||||
CONFIGLOCATION="/config/addons_autoscripts"
|
||||
CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh"
|
||||
# Legacy config location
|
||||
CONFIGLOCATION="/config/addons_autoscripts"
|
||||
CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh"
|
||||
fi
|
||||
|
||||
# Default location
|
||||
@@ -36,31 +36,31 @@ bashio::log.green "Wiki here : github.com/alexbelgium/hassio-addons/wiki/Add-ons
|
||||
|
||||
# Download template if no script found and exit
|
||||
if [ ! -f "$CONFIGSOURCE" ]; then
|
||||
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template"
|
||||
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true
|
||||
exit 0
|
||||
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template"
|
||||
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Convert scripts to linux
|
||||
dos2unix "$CONFIGSOURCE" &>/dev/null || true
|
||||
dos2unix "$CONFIGSOURCE" &> /dev/null || true
|
||||
chmod +x "$CONFIGSOURCE"
|
||||
|
||||
# Get current shebang, if not available use another
|
||||
currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$CONFIGSOURCE")"
|
||||
if [ ! -f "${currentshebang%% *}" ]; then
|
||||
for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done
|
||||
sed -i "s|$currentshebang|$shebang|g" "$CONFIGSOURCE"
|
||||
for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done
|
||||
sed -i "s|$currentshebang|$shebang|g" "$CONFIGSOURCE"
|
||||
fi
|
||||
|
||||
# Check if there is actual commands
|
||||
while IFS= read -r line; do
|
||||
# Remove leading and trailing whitespaces
|
||||
line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
# Remove leading and trailing whitespaces
|
||||
line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
|
||||
# Check if line is not empty and does not start with #
|
||||
if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then
|
||||
bashio::log.green "... script found, executing"
|
||||
/."$CONFIGSOURCE"
|
||||
break
|
||||
fi
|
||||
done <"$CONFIGSOURCE"
|
||||
# Check if line is not empty and does not start with #
|
||||
if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then
|
||||
bashio::log.green "... script found, executing"
|
||||
/."$CONFIGSOURCE"
|
||||
break
|
||||
fi
|
||||
done < "$CONFIGSOURCE"
|
||||
|
||||
@@ -8,39 +8,39 @@ JSONSOURCE='/defaults/settings.json'
|
||||
|
||||
# If json already exists
|
||||
if [ -f "${JSONTOCHECK}" ]; then
|
||||
# Variables
|
||||
echo "Checking settings.json format"
|
||||
# Variables
|
||||
echo "Checking settings.json format"
|
||||
|
||||
# Check if json file valid or not
|
||||
jq . -S "${JSONTOCHECK}" &>/dev/null && ERROR=false || ERROR=true
|
||||
if [ "$ERROR" = true ]; then
|
||||
bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old"
|
||||
mv "${JSONSOURCE}" "${JSONSOURCE}"_old
|
||||
cp "${JSONSOURCE}" "${JSONTOCHECK}"
|
||||
exit 0
|
||||
fi
|
||||
# Check if json file valid or not
|
||||
jq . -S "${JSONTOCHECK}" &> /dev/null && ERROR=false || ERROR=true
|
||||
if [ "$ERROR" = true ]; then
|
||||
bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old"
|
||||
mv "${JSONSOURCE}" "${JSONSOURCE}"_old
|
||||
cp "${JSONSOURCE}" "${JSONTOCHECK}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get the default keys from the original file
|
||||
mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
|
||||
# Get the default keys from the original file
|
||||
mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
|
||||
|
||||
# Check if all keys are still there, or add them
|
||||
# spellcheck disable=SC2068
|
||||
for KEYS in "${arr[@]}"; do
|
||||
# Check if key exists
|
||||
KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}")
|
||||
if [ "$KEYSTHERE" != "true" ]; then
|
||||
#Fetch initial value
|
||||
JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}")
|
||||
#Add key
|
||||
sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}"
|
||||
# Message
|
||||
bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}"
|
||||
fi
|
||||
done
|
||||
# Check if all keys are still there, or add them
|
||||
# spellcheck disable=SC2068
|
||||
for KEYS in "${arr[@]}"; do
|
||||
# Check if key exists
|
||||
KEYSTHERE=$(jq "has(\"${KEYS}\")" "${JSONTOCHECK}")
|
||||
if [ "$KEYSTHERE" != "true" ]; then
|
||||
#Fetch initial value
|
||||
JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" "${JSONSOURCE}")
|
||||
#Add key
|
||||
sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," "${JSONTOCHECK}"
|
||||
# Message
|
||||
bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}"
|
||||
fi
|
||||
done
|
||||
|
||||
# Show structure in a nice way
|
||||
jq . -S "${JSONTOCHECK}" | cat >temp.json && mv temp.json "${JSONTOCHECK}"
|
||||
# Show structure in a nice way
|
||||
jq . -S "${JSONTOCHECK}" | cat > temp.json && mv temp.json "${JSONTOCHECK}"
|
||||
|
||||
# Message
|
||||
bashio::log.info "Your settings.json was checked and seems perfectly normal!"
|
||||
# Message
|
||||
bashio::log.info "Your settings.json was checked and seems perfectly normal!"
|
||||
fi
|
||||
|
||||
@@ -6,17 +6,17 @@ set -e
|
||||
|
||||
# Disable Ingress
|
||||
if bashio::config.true "ingress_disabled"; then
|
||||
bashio::log.warning "Ingress is disabled. You'll need to connect using ip:port"
|
||||
bashio::log.warning "Ingress is disabled. You'll need to connect using ip:port"
|
||||
|
||||
# Adapt ingress.conf
|
||||
sed -i "/root/d" /etc/nginx/servers/ingress.conf
|
||||
sed -i "/proxy_pass/i root /etc;" /etc/nginx/servers/ingress.conf
|
||||
sed -i "/proxy_pass/i try_files '' /ingress.html =404;" /etc/nginx/servers/ingress.conf
|
||||
sed -i "/proxy_pass/d" /etc/nginx/servers/ingress.conf
|
||||
# Adapt ingress.conf
|
||||
sed -i "/root/d" /etc/nginx/servers/ingress.conf
|
||||
sed -i "/proxy_pass/i root /etc;" /etc/nginx/servers/ingress.conf
|
||||
sed -i "/proxy_pass/i try_files '' /ingress.html =404;" /etc/nginx/servers/ingress.conf
|
||||
sed -i "/proxy_pass/d" /etc/nginx/servers/ingress.conf
|
||||
|
||||
# Create index.html
|
||||
touch /etc/ingress.html
|
||||
cat >/etc/ingress.html <<EOF
|
||||
# Create index.html
|
||||
touch /etc/ingress.html
|
||||
cat > /etc/ingress.html << EOF
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@@ -9,35 +9,35 @@ set -e
|
||||
# Avoid usage of local dns such as adguard home or pihole\n"
|
||||
|
||||
if bashio::config.has_value 'DNS_server'; then
|
||||
# Define variables
|
||||
DNSSERVER=$(bashio::config 'DNS_server')
|
||||
DNS=""
|
||||
DNSLIST=""
|
||||
# Define variables
|
||||
DNSSERVER=$(bashio::config 'DNS_server')
|
||||
DNS=""
|
||||
DNSLIST=""
|
||||
|
||||
# Get DNS servers
|
||||
# shellcheck disable=SC2086
|
||||
for server in ${DNSSERVER//,/ }; do # Separate comma separated values
|
||||
# Only add DNS if successful
|
||||
if ping -c 1 "$server" &>/dev/null; then
|
||||
DNS="${DNS}nameserver $server\n"
|
||||
DNSLIST="$server $DNSLIST"
|
||||
else
|
||||
bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used"
|
||||
fi
|
||||
done
|
||||
# Get DNS servers
|
||||
# shellcheck disable=SC2086
|
||||
for server in ${DNSSERVER//,/ }; do # Separate comma separated values
|
||||
# Only add DNS if successful
|
||||
if ping -c 1 "$server" &> /dev/null; then
|
||||
DNS="${DNS}nameserver $server\n"
|
||||
DNSLIST="$server $DNSLIST"
|
||||
else
|
||||
bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used"
|
||||
fi
|
||||
done
|
||||
|
||||
# Only add DNS if there are DNS set
|
||||
# shellcheck disable=SC2236
|
||||
if [[ -n "${DNS:-}" ]]; then
|
||||
# Write resolv.conf
|
||||
# shellcheck disable=SC2059
|
||||
printf "${DNS}" >/etc/resolv.conf
|
||||
chmod 644 /etc/resolv.conf
|
||||
bashio::log.info "DNS SERVERS set to $DNSLIST"
|
||||
else
|
||||
bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers."
|
||||
fi
|
||||
# Only add DNS if there are DNS set
|
||||
# shellcheck disable=SC2236
|
||||
if [[ -n "${DNS:-}" ]]; then
|
||||
# Write resolv.conf
|
||||
# shellcheck disable=SC2059
|
||||
printf "${DNS}" > /etc/resolv.conf
|
||||
chmod 644 /etc/resolv.conf
|
||||
bashio::log.info "DNS SERVERS set to $DNSLIST"
|
||||
else
|
||||
bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers."
|
||||
fi
|
||||
|
||||
else
|
||||
bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers."
|
||||
bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers."
|
||||
fi
|
||||
|
||||
@@ -7,8 +7,8 @@ set -e
|
||||
###############
|
||||
|
||||
if bashio::config.true 'silent'; then
|
||||
APPEND=' > /dev/null'
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/services.d/*/run &>/dev/null || true
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/cont-init.d/*/*run* &>/dev/null || true
|
||||
bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
|
||||
APPEND=' > /dev/null'
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/services.d/*/run &> /dev/null || true
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/cont-init.d/*/*run* &> /dev/null || true
|
||||
bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
|
||||
fi
|
||||
|
||||
@@ -3,170 +3,170 @@ set -e
|
||||
|
||||
if bashio::config.has_value "graphic_driver"; then
|
||||
|
||||
# Origin : https://github.com/wumingjieno1/photoprism-test/blob/main/scripts/dist/install-gpu.sh
|
||||
# abort if not executed as root
|
||||
if [[ $(id -u) != "0" ]]; then
|
||||
# shellcheck disable=SC2128
|
||||
bashio::log.fatal "Error: Run $(basename "${BASH_SOURCE}") as root" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
# Origin : https://github.com/wumingjieno1/photoprism-test/blob/main/scripts/dist/install-gpu.sh
|
||||
# abort if not executed as root
|
||||
if [[ $(id -u) != "0" ]]; then
|
||||
# shellcheck disable=SC2128
|
||||
bashio::log.fatal "Error: Run $(basename "${BASH_SOURCE}") as root" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get installer type
|
||||
if [ -f /usr/bin/apt ]; then
|
||||
bashio::log.info "... Distribution detected : Debian/Ubuntu"
|
||||
apt-get install -yqq software-properties-common >/dev/null
|
||||
add-apt-repository ppa:kisak/kisak-mesa >/dev/null
|
||||
apt-get update >/dev/null
|
||||
apt-get install -yqq mesa
|
||||
elif [ -f /usr/bin/apk ]; then
|
||||
bashio::log.info "... Distribution detected : Alpine"
|
||||
fi
|
||||
# Get installer type
|
||||
if [ -f /usr/bin/apt ]; then
|
||||
bashio::log.info "... Distribution detected : Debian/Ubuntu"
|
||||
apt-get install -yqq software-properties-common > /dev/null
|
||||
add-apt-repository ppa:kisak/kisak-mesa > /dev/null
|
||||
apt-get update > /dev/null
|
||||
apt-get install -yqq mesa
|
||||
elif [ -f /usr/bin/apk ]; then
|
||||
bashio::log.info "... Distribution detected : Alpine"
|
||||
fi
|
||||
|
||||
# Detect GPU
|
||||
# shellcheck disable=SC2207
|
||||
GPU_DETECTED=($(lshw -c display -json 2>/dev/null | jq -r '.[].configuration.driver'))
|
||||
bashio::log.info "... GPU detected: ${GPU_DETECTED[*]}"
|
||||
graphic_driver=""
|
||||
# Detect GPU
|
||||
# shellcheck disable=SC2207
|
||||
GPU_DETECTED=($(lshw -c display -json 2> /dev/null | jq -r '.[].configuration.driver'))
|
||||
bashio::log.info "... GPU detected: ${GPU_DETECTED[*]}"
|
||||
graphic_driver=""
|
||||
|
||||
# Get arch type
|
||||
BUILD_ARCH="$(uname -m)"
|
||||
case "$BUILD_ARCH" in
|
||||
amd64 | AMD64 | x86_64 | x86-64)
|
||||
BUILD_ARCH=amd64
|
||||
;;
|
||||
# Get arch type
|
||||
BUILD_ARCH="$(uname -m)"
|
||||
case "$BUILD_ARCH" in
|
||||
amd64 | AMD64 | x86_64 | x86-64)
|
||||
BUILD_ARCH=amd64
|
||||
;;
|
||||
|
||||
arm64 | ARM64 | aarch64)
|
||||
BUILD_ARCH=arm64
|
||||
graphic_driver=aarch64_rpi
|
||||
;;
|
||||
arm64 | ARM64 | aarch64)
|
||||
BUILD_ARCH=arm64
|
||||
graphic_driver=aarch64_rpi
|
||||
;;
|
||||
|
||||
arm | ARM | aarch | armv7l | armhf)
|
||||
bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
arm | ARM | aarch | armv7l | armhf)
|
||||
bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
|
||||
*)
|
||||
bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
bashio::log.info "... architecture detected: ${BUILD_ARCH}"
|
||||
*)
|
||||
bashio::log.fatal "Unsupported Machine Architecture: $BUILD_ARCH" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
bashio::log.info "... architecture detected: ${BUILD_ARCH}"
|
||||
|
||||
#graphic_driver="$(bashio::config "graphic_driver")"
|
||||
case "$graphic_driver" in
|
||||
x64_AMD)
|
||||
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
[ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-amd && run_mods >/dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-classic mesa-vdpau-gallium linux-firmware-radeon >/dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
#graphic_driver="$(bashio::config "graphic_driver")"
|
||||
case "$graphic_driver" in
|
||||
x64_AMD)
|
||||
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
[ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-amd && run_mods > /dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-classic mesa-vdpau-gallium linux-firmware-radeon > /dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
|
||||
x64_NVIDIA)
|
||||
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache linux-firmware-radeon >/dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apt ] && apt-get -yqq install libcuda1 libnvcuvid1 libnvidia-encode1 nvidia-opencl-icd nvidia-vdpau-driver nvidia-driver-libs nvidia-kernel-dkms libva2 vainfo libva-wayland2 >/dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
x64_NVIDIA)
|
||||
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache linux-firmware-radeon > /dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apt ] && apt-get -yqq install libcuda1 libnvcuvid1 libnvidia-encode1 nvidia-opencl-icd nvidia-vdpau-driver nvidia-driver-libs nvidia-kernel-dkms libva2 vainfo libva-wayland2 > /dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
|
||||
x64_Intel)
|
||||
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache opencl mesa-dri-gallium mesa-vulkan-intel mesa-dri-intel intel-media-driver >/dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-opencl-intel && run_mods && apt-get -yqq install intel-opencl-icd intel-media-va-driver-non-free i965-va-driver-shaders mesa-va-drivers libmfx1 libva2 vainfo libva-wayland2 >/dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
x64_Intel)
|
||||
if [[ "$BUILD_ARCH" != amd64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache opencl mesa-dri-gallium mesa-vulkan-intel mesa-dri-intel intel-media-driver > /dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apt ] && DOCKER_MODS=linuxserver/mods:jellyfin-opencl-intel && run_mods && apt-get -yqq install intel-opencl-icd intel-media-va-driver-non-free i965-va-driver-shaders mesa-va-drivers libmfx1 libva2 vainfo libva-wayland2 > /dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
|
||||
aarch64_rpi)
|
||||
if [[ "$BUILD_ARCH" != arm64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
bashio::log.info "Installing Rpi graphic drivers"
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-vc4 mesa-dri-swrast mesa-gbm xf86-video-fbdev >/dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apt ] && apt-get -yqq install libgles2-mesa libgles2-mesa-dev xorg-dev >/dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
aarch64_rpi)
|
||||
if [[ "$BUILD_ARCH" != arm64 ]]; then bashio::log.fatal "Wrong architecture, $graphic_driver doesn't support $BUILD_ARCH"; fi
|
||||
bashio::log.info "Installing Rpi graphic drivers"
|
||||
[ -f /usr/bin/apk ] && apk add --no-cache mesa-dri-vc4 mesa-dri-swrast mesa-gbm xf86-video-fbdev > /dev/null && bashio::log.green "... done"
|
||||
[ -f /usr/bin/apt ] && apt-get -yqq install libgles2-mesa libgles2-mesa-dev xorg-dev > /dev/null && bashio::log.green "... done"
|
||||
;;
|
||||
|
||||
esac
|
||||
esac
|
||||
|
||||
# Main run logic
|
||||
run_mods() {
|
||||
echo "[mod-init] Attempting to run Docker Modification Logic"
|
||||
for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do
|
||||
# Support alternative endpoints
|
||||
if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then
|
||||
DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}"
|
||||
ENDPOINT="${DOCKER_MOD%%:*}"
|
||||
USERNAME="${DOCKER_MOD%%/*}"
|
||||
REPO="${ENDPOINT#*/}"
|
||||
TAG="${DOCKER_MOD#*:}"
|
||||
if [[ ${TAG} == "${DOCKER_MOD}" ]]; then
|
||||
TAG="latest"
|
||||
fi
|
||||
FILENAME="${USERNAME}.${REPO}.${TAG}"
|
||||
AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull"
|
||||
MANIFEST_URL="https://ghcr.io/v2/${ENDPOINT}/manifests/${TAG}"
|
||||
BLOB_URL="https://ghcr.io/v2/${ENDPOINT}/blobs/"
|
||||
MODE="ghcr"
|
||||
else
|
||||
ENDPOINT="${DOCKER_MOD%%:*}"
|
||||
USERNAME="${DOCKER_MOD%%/*}"
|
||||
REPO="${ENDPOINT#*/}"
|
||||
TAG="${DOCKER_MOD#*:}"
|
||||
if [[ ${TAG} == "${DOCKER_MOD}" ]]; then
|
||||
TAG="latest"
|
||||
fi
|
||||
FILENAME="${USERNAME}.${REPO}.${TAG}"
|
||||
AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull"
|
||||
MANIFEST_URL="https://registry-1.docker.io/v2/${ENDPOINT}/manifests/${TAG}"
|
||||
BLOB_URL="https://registry-1.docker.io/v2/${ENDPOINT}/blobs/"
|
||||
MODE="dockerhub"
|
||||
fi
|
||||
# Kill off modification logic if any of the usernames are banned
|
||||
for BANNED in $(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt); do
|
||||
if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then
|
||||
if [[ -z ${RUN_BANNED_MODS+x} ]]; then
|
||||
echo "[mod-init] ${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic"
|
||||
return
|
||||
else
|
||||
echo "[mod-init] You have chosen to run banned mods ${DOCKER_MOD} will be applied"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "[mod-init] Applying ${DOCKER_MOD} files to container"
|
||||
# Get Dockerhub token for api operations
|
||||
TOKEN="$(
|
||||
curl -f --retry 10 --retry-max-time 60 --retry-connrefused \
|
||||
--silent \
|
||||
--header 'GET' \
|
||||
"${AUTH_URL}" |
|
||||
jq -r '.token'
|
||||
)"
|
||||
# Determine first and only layer of image
|
||||
SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}")
|
||||
# Check if we have allready applied this layer
|
||||
if [[ -f "/${FILENAME}" ]] && [[ "${SHALAYER}" == "$(cat /"${FILENAME}")" ]]; then
|
||||
echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping"
|
||||
else
|
||||
# Download and extract layer to /
|
||||
curl -f --retry 10 --retry-max-time 60 --retry-connrefused \
|
||||
--silent \
|
||||
--location \
|
||||
--request GET \
|
||||
--header "Authorization: Bearer ${TOKEN}" \
|
||||
"${BLOB_URL}${SHALAYER}" -o \
|
||||
/modtarball.tar.xz
|
||||
mkdir -p /tmp/mod
|
||||
tar xzf /modtarball.tar.xz -C /tmp/mod
|
||||
if [[ -d /tmp/mod/etc/s6-overlay ]]; then
|
||||
if [[ -d /tmp/mod/etc/cont-init.d ]]; then
|
||||
rm -rf /tmp/mod/etc/cont-init.d
|
||||
fi
|
||||
if [[ -d /tmp/mod/etc/services.d ]]; then
|
||||
rm -rf /tmp/mod/etc/services.d
|
||||
fi
|
||||
fi
|
||||
shopt -s dotglob
|
||||
cp -R /tmp/mod/* /
|
||||
shopt -u dotglob
|
||||
rm -rf /tmp/mod
|
||||
rm -rf /modtarball.tar.xz
|
||||
echo "${SHALAYER}" >"/${FILENAME}"
|
||||
echo "[mod-init] ${DOCKER_MOD} applied to container"
|
||||
fi
|
||||
done
|
||||
}
|
||||
# Main run logic
|
||||
run_mods() {
|
||||
echo "[mod-init] Attempting to run Docker Modification Logic"
|
||||
for DOCKER_MOD in $(echo "${DOCKER_MODS}" | tr '|' '\n'); do
|
||||
# Support alternative endpoints
|
||||
if [[ ${DOCKER_MOD} == ghcr.io/* ]] || [[ ${DOCKER_MOD} == linuxserver/* ]]; then
|
||||
DOCKER_MOD="${DOCKER_MOD#ghcr.io/*}"
|
||||
ENDPOINT="${DOCKER_MOD%%:*}"
|
||||
USERNAME="${DOCKER_MOD%%/*}"
|
||||
REPO="${ENDPOINT#*/}"
|
||||
TAG="${DOCKER_MOD#*:}"
|
||||
if [[ ${TAG} == "${DOCKER_MOD}" ]]; then
|
||||
TAG="latest"
|
||||
fi
|
||||
FILENAME="${USERNAME}.${REPO}.${TAG}"
|
||||
AUTH_URL="https://ghcr.io/token?scope=repository%3A${USERNAME}%2F${REPO}%3Apull"
|
||||
MANIFEST_URL="https://ghcr.io/v2/${ENDPOINT}/manifests/${TAG}"
|
||||
BLOB_URL="https://ghcr.io/v2/${ENDPOINT}/blobs/"
|
||||
MODE="ghcr"
|
||||
else
|
||||
ENDPOINT="${DOCKER_MOD%%:*}"
|
||||
USERNAME="${DOCKER_MOD%%/*}"
|
||||
REPO="${ENDPOINT#*/}"
|
||||
TAG="${DOCKER_MOD#*:}"
|
||||
if [[ ${TAG} == "${DOCKER_MOD}" ]]; then
|
||||
TAG="latest"
|
||||
fi
|
||||
FILENAME="${USERNAME}.${REPO}.${TAG}"
|
||||
AUTH_URL="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${ENDPOINT}:pull"
|
||||
MANIFEST_URL="https://registry-1.docker.io/v2/${ENDPOINT}/manifests/${TAG}"
|
||||
BLOB_URL="https://registry-1.docker.io/v2/${ENDPOINT}/blobs/"
|
||||
MODE="dockerhub"
|
||||
fi
|
||||
# Kill off modification logic if any of the usernames are banned
|
||||
for BANNED in $(curl -s https://raw.githubusercontent.com/linuxserver/docker-mods/master/blacklist.txt); do
|
||||
if [[ "${BANNED,,}" == "${USERNAME,,}" ]]; then
|
||||
if [[ -z ${RUN_BANNED_MODS+x} ]]; then
|
||||
echo "[mod-init] ${DOCKER_MOD} is banned from use due to reported abuse aborting mod logic"
|
||||
return
|
||||
else
|
||||
echo "[mod-init] You have chosen to run banned mods ${DOCKER_MOD} will be applied"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "[mod-init] Applying ${DOCKER_MOD} files to container"
|
||||
# Get Dockerhub token for api operations
|
||||
TOKEN="$(
|
||||
curl -f --retry 10 --retry-max-time 60 --retry-connrefused \
|
||||
--silent \
|
||||
--header 'GET' \
|
||||
"${AUTH_URL}" \
|
||||
| jq -r '.token'
|
||||
)"
|
||||
# Determine first and only layer of image
|
||||
SHALAYER=$(get_blob_sha "${MODE}" "${TOKEN}" "${MANIFEST_URL}")
|
||||
# Check if we have allready applied this layer
|
||||
if [[ -f "/${FILENAME}" ]] && [[ "${SHALAYER}" == "$(cat /"${FILENAME}")" ]]; then
|
||||
echo "[mod-init] ${DOCKER_MOD} at ${SHALAYER} has been previously applied skipping"
|
||||
else
|
||||
# Download and extract layer to /
|
||||
curl -f --retry 10 --retry-max-time 60 --retry-connrefused \
|
||||
--silent \
|
||||
--location \
|
||||
--request GET \
|
||||
--header "Authorization: Bearer ${TOKEN}" \
|
||||
"${BLOB_URL}${SHALAYER}" -o \
|
||||
/modtarball.tar.xz
|
||||
mkdir -p /tmp/mod
|
||||
tar xzf /modtarball.tar.xz -C /tmp/mod
|
||||
if [[ -d /tmp/mod/etc/s6-overlay ]]; then
|
||||
if [[ -d /tmp/mod/etc/cont-init.d ]]; then
|
||||
rm -rf /tmp/mod/etc/cont-init.d
|
||||
fi
|
||||
if [[ -d /tmp/mod/etc/services.d ]]; then
|
||||
rm -rf /tmp/mod/etc/services.d
|
||||
fi
|
||||
fi
|
||||
shopt -s dotglob
|
||||
cp -R /tmp/mod/* /
|
||||
shopt -u dotglob
|
||||
rm -rf /tmp/mod
|
||||
rm -rf /modtarball.tar.xz
|
||||
echo "${SHALAYER}" > "/${FILENAME}"
|
||||
echo "[mod-init] ${DOCKER_MOD} applied to container"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
fi
|
||||
|
||||
@@ -6,5 +6,5 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
CONFIGSOURCE="$(dirname "${CONFIGSOURCE}")"
|
||||
|
||||
if [ -f "$CONFIGSOURCE"/script.sh ]; then
|
||||
"$CONFIGSOURCE"./script.sh
|
||||
"$CONFIGSOURCE"./script.sh
|
||||
fi
|
||||
|
||||
@@ -10,13 +10,13 @@ PACKAGES="$1"
|
||||
echo "To install : $PACKAGES"
|
||||
|
||||
# Install bash if needed
|
||||
if ! command -v bash >/dev/null 2>/dev/null; then
|
||||
(apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null
|
||||
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
|
||||
|
||||
# Install curl if needed
|
||||
if ! command -v curl >/dev/null 2>/dev/null; then
|
||||
(apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null
|
||||
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
|
||||
|
||||
# Call apps installer script if needed
|
||||
|
||||
@@ -8,11 +8,11 @@ set -e
|
||||
#Verbose or not
|
||||
VERBOSE=false
|
||||
#Avoid fails on non declared variables
|
||||
set +u 2>/dev/null || true
|
||||
set +u 2> /dev/null || true
|
||||
#If no packages, empty
|
||||
PACKAGES="${*:-}"
|
||||
#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"
|
||||
|
||||
@@ -20,18 +20,18 @@ PACKAGES="${*:-}"
|
||||
# CHECK WHICH BASE IS USED #
|
||||
############################
|
||||
|
||||
if command -v "apk" &>/dev/null; then
|
||||
# If apk based
|
||||
[ "$VERBOSE" = true ] && echo "apk based"
|
||||
PACKMANAGER="apk"
|
||||
elif command -v "apt" &>/dev/null; then
|
||||
# If apt-get based
|
||||
[ "$VERBOSE" = true ] && echo "apt based"
|
||||
PACKMANAGER="apt"
|
||||
elif command -v "pacman" &>/dev/null; then
|
||||
# If apt-get based
|
||||
[ "$VERBOSE" = true ] && echo "pacman based"
|
||||
PACKMANAGER="pacman"
|
||||
if command -v "apk" &> /dev/null; then
|
||||
# If apk based
|
||||
[ "$VERBOSE" = true ] && echo "apk based"
|
||||
PACKMANAGER="apk"
|
||||
elif command -v "apt" &> /dev/null; then
|
||||
# If apt-get based
|
||||
[ "$VERBOSE" = true ] && echo "apt based"
|
||||
PACKMANAGER="apt"
|
||||
elif command -v "pacman" &> /dev/null; then
|
||||
# If apt-get based
|
||||
[ "$VERBOSE" = true ] && echo "pacman based"
|
||||
PACKMANAGER="pacman"
|
||||
fi
|
||||
|
||||
###################
|
||||
@@ -48,130 +48,130 @@ PACKAGES="$PACKAGES jq curl ca-certificates"
|
||||
|
||||
# Scripts
|
||||
for files in "/etc/cont-init.d" "/etc/services.d"; do
|
||||
# Next directory if does not exists
|
||||
if ! ls $files 1>/dev/null 2>&1; then continue; fi
|
||||
# Next directory if does not exists
|
||||
if ! ls $files 1> /dev/null 2>&1; then continue; fi
|
||||
|
||||
# Test each possible command
|
||||
COMMAND="nginx"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nginx"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nginx"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES nginx"
|
||||
if ls /etc/nginx 1>/dev/null 2>&1; then mv /etc/nginx /etc/nginx2; fi
|
||||
fi
|
||||
# Test each possible command
|
||||
COMMAND="nginx"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nginx"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nginx"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES nginx"
|
||||
if ls /etc/nginx 1> /dev/null 2>&1; then mv /etc/nginx /etc/nginx2; fi
|
||||
fi
|
||||
|
||||
COMMAND="mount"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND"; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES exfatprogs ntfs-3g ntfs-3g-progs squashfs-tools fuse lsblk"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES exfat* ntfs* squashfs-tools util-linux"
|
||||
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES ntfs-3g"
|
||||
fi
|
||||
COMMAND="mount"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND"; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES exfatprogs ntfs-3g ntfs-3g-progs squashfs-tools fuse lsblk"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES exfat* ntfs* squashfs-tools util-linux"
|
||||
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES ntfs-3g"
|
||||
fi
|
||||
|
||||
COMMAND="ping"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES iputils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES iputils-ping"
|
||||
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils"
|
||||
fi
|
||||
COMMAND="ping"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES iputils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES iputils-ping"
|
||||
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils"
|
||||
fi
|
||||
|
||||
COMMAND="nmap"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND"; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nmap nmap-scripts"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nmap"
|
||||
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils"
|
||||
fi
|
||||
COMMAND="nmap"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND"; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nmap nmap-scripts"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nmap"
|
||||
#[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES iputils"
|
||||
fi
|
||||
|
||||
COMMAND="cifs"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND"; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
fi
|
||||
COMMAND="cifs"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND"; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
fi
|
||||
|
||||
COMMAND="smbclient"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES samba samba-client ntfs-3g"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES samba smbclient ntfs-3g"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES samba smbclient"
|
||||
fi
|
||||
COMMAND="smbclient"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES samba samba-client ntfs-3g"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES samba smbclient ntfs-3g"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES samba smbclient"
|
||||
fi
|
||||
|
||||
COMMAND="dos2unix"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES dos2unix"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES dos2unix"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES dos2unix"
|
||||
fi
|
||||
COMMAND="dos2unix"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES dos2unix"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES dos2unix"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES dos2unix"
|
||||
fi
|
||||
|
||||
COMMAND="openvpn"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
fi
|
||||
COMMAND="openvpn"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
fi
|
||||
|
||||
COMMAND="jq"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES jq"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES jq"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES jq"
|
||||
fi
|
||||
COMMAND="jq"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES jq"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES jq"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES jq"
|
||||
fi
|
||||
|
||||
COMMAND="yamllint"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES yamllint"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES yamllint"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES yamllint"
|
||||
fi
|
||||
COMMAND="yamllint"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES yamllint"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES yamllint"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES yamllint"
|
||||
fi
|
||||
|
||||
COMMAND="git"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES git"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES git"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES git"
|
||||
fi
|
||||
COMMAND="git"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES git"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES git"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES git"
|
||||
fi
|
||||
|
||||
COMMAND="sponge"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES moreutils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES moreutils"
|
||||
[ "$PACKMANAGER" = "pacman " ] && PACKAGES="$PACKAGES moreutils"
|
||||
fi
|
||||
COMMAND="sponge"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES moreutils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES moreutils"
|
||||
[ "$PACKMANAGER" = "pacman " ] && PACKAGES="$PACKAGES moreutils"
|
||||
fi
|
||||
|
||||
COMMAND="sqlite3"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES sqlite"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES sqlite3"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES sqlite3"
|
||||
fi
|
||||
COMMAND="sqlite3"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES sqlite"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES sqlite3"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES sqlite3"
|
||||
fi
|
||||
|
||||
COMMAND="pip"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES py3-pip"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES pip"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES pip"
|
||||
fi
|
||||
COMMAND="pip"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES py3-pip"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES pip"
|
||||
[ "$PACKMANAGER" = "pacman" ] && PACKAGES="$PACKAGES pip"
|
||||
fi
|
||||
|
||||
COMMAND="wget"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES wget"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES wget"
|
||||
[ "$PACKMANAGER" = "wget" ] && PACKAGES="$PACKAGES wget"
|
||||
fi
|
||||
COMMAND="wget"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES wget"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES wget"
|
||||
[ "$PACKMANAGER" = "wget" ] && PACKAGES="$PACKAGES wget"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
@@ -181,34 +181,34 @@ done
|
||||
|
||||
# Install apps
|
||||
[ "$VERBOSE" = true ] && echo "installing packages $PACKAGES"
|
||||
if [ "$PACKMANAGER" = "apt" ]; then apt-get update >/dev/null; fi
|
||||
if [ "$PACKMANAGER" = "pacman" ]; then pacman -Sy >/dev/null; fi
|
||||
if [ "$PACKMANAGER" = "apt" ]; then apt-get update > /dev/null; fi
|
||||
if [ "$PACKMANAGER" = "pacman" ]; then pacman -Sy > /dev/null; fi
|
||||
|
||||
# Install apps one by one to allow failures
|
||||
# shellcheck disable=SC2086
|
||||
for packagestoinstall in $PACKAGES; do
|
||||
[ "$VERBOSE" = true ] && echo "... $packagestoinstall"
|
||||
if [ "$PACKMANAGER" = "apk" ]; then
|
||||
apk add --no-cache "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
|
||||
elif [ "$PACKMANAGER" = "apt" ]; then
|
||||
apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
|
||||
elif [ "$PACKMANAGER" = "pacman" ]; then
|
||||
pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
|
||||
fi
|
||||
[ "$VERBOSE" = true ] && echo "... $packagestoinstall done"
|
||||
[ "$VERBOSE" = true ] && echo "... $packagestoinstall"
|
||||
if [ "$PACKMANAGER" = "apk" ]; then
|
||||
apk add --no-cache "$packagestoinstall" &> /dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
|
||||
elif [ "$PACKMANAGER" = "apt" ]; then
|
||||
apt-get install -yqq --no-install-recommends "$packagestoinstall" &> /dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
|
||||
elif [ "$PACKMANAGER" = "pacman" ]; then
|
||||
pacman --noconfirm -S "$packagestoinstall" &> /dev/null || (echo "Error : $packagestoinstall not found" && touch /ERROR)
|
||||
fi
|
||||
[ "$VERBOSE" = true ] && echo "... $packagestoinstall done"
|
||||
done
|
||||
|
||||
# Clean after install
|
||||
[ "$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
|
||||
if ls /etc/nginx2 1>/dev/null 2>&1; then
|
||||
[ "$VERBOSE" = true ] && echo "replace nginx2"
|
||||
rm -r /etc/nginx
|
||||
mv /etc/nginx2 /etc/nginx
|
||||
mkdir -p /var/log/nginx
|
||||
touch /var/log/nginx/error.log
|
||||
if ls /etc/nginx2 1> /dev/null 2>&1; then
|
||||
[ "$VERBOSE" = true ] && echo "replace nginx2"
|
||||
rm -r /etc/nginx
|
||||
mv /etc/nginx2 /etc/nginx
|
||||
mkdir -p /var/log/nginx
|
||||
touch /var/log/nginx/error.log
|
||||
fi
|
||||
|
||||
#######################
|
||||
@@ -223,53 +223,53 @@ micro -plugin install filemanager || true
|
||||
|
||||
for files in "/etc/services.d" "/etc/cont-init.d"; do
|
||||
|
||||
# Next directory if does not exists
|
||||
if ! ls $files 1>/dev/null 2>&1; then continue; fi
|
||||
# Next directory if does not exists
|
||||
if ! ls $files 1> /dev/null 2>&1; then continue; fi
|
||||
|
||||
# Bashio
|
||||
if grep -q -rnw "$files/" -e 'bashio' && [ ! -f "/usr/bin/bashio" ]; then
|
||||
[ "$VERBOSE" = true ] && echo "install bashio"
|
||||
BASHIO_VERSION="0.14.3"
|
||||
mkdir -p /tmp/bashio
|
||||
curl -f -L -s -S "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar -xzf - --strip 1 -C /tmp/bashio
|
||||
mv /tmp/bashio/lib /usr/lib/bashio
|
||||
ln -s /usr/lib/bashio/bashio /usr/bin/bashio
|
||||
rm -rf /tmp/bashio
|
||||
fi
|
||||
# Bashio
|
||||
if grep -q -rnw "$files/" -e 'bashio' && [ ! -f "/usr/bin/bashio" ]; then
|
||||
[ "$VERBOSE" = true ] && echo "install bashio"
|
||||
BASHIO_VERSION="0.14.3"
|
||||
mkdir -p /tmp/bashio
|
||||
curl -f -L -s -S "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar -xzf - --strip 1 -C /tmp/bashio
|
||||
mv /tmp/bashio/lib /usr/lib/bashio
|
||||
ln -s /usr/lib/bashio/bashio /usr/bin/bashio
|
||||
rm -rf /tmp/bashio
|
||||
fi
|
||||
|
||||
# Lastversion
|
||||
COMMAND="lastversion"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "install $COMMAND"
|
||||
pip install $COMMAND
|
||||
fi
|
||||
# Lastversion
|
||||
COMMAND="lastversion"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "install $COMMAND"
|
||||
pip install $COMMAND
|
||||
fi
|
||||
|
||||
# Tempio
|
||||
if grep -q -rnw "$files/" -e 'tempio' && [ ! -f "/usr/bin/tempio" ]; then
|
||||
[ "$VERBOSE" = true ] && echo "install tempio"
|
||||
TEMPIO_VERSION="2021.09.0"
|
||||
BUILD_ARCH="$(bashio::info.arch)"
|
||||
curl -f -L -f -s -o /usr/bin/tempio "https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}"
|
||||
chmod a+x /usr/bin/tempio
|
||||
fi
|
||||
# Tempio
|
||||
if grep -q -rnw "$files/" -e 'tempio' && [ ! -f "/usr/bin/tempio" ]; then
|
||||
[ "$VERBOSE" = true ] && echo "install tempio"
|
||||
TEMPIO_VERSION="2021.09.0"
|
||||
BUILD_ARCH="$(bashio::info.arch)"
|
||||
curl -f -L -f -s -o /usr/bin/tempio "https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}"
|
||||
chmod a+x /usr/bin/tempio
|
||||
fi
|
||||
|
||||
# Mustache
|
||||
COMMAND="mustache"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && apk add --no-cache go npm &&
|
||||
apk upgrade --no-cache &&
|
||||
apk add --no-cache --virtual .build-deps build-base git go &&
|
||||
go get -u github.com/quantumew/mustache-cli &&
|
||||
cp "$GOPATH"/bin/* /usr/bin/ &&
|
||||
rm -rf "$GOPATH" /var/cache/apk/* /tmp/src &&
|
||||
apk del .build-deps xz build-base
|
||||
[ "$PACKMANAGER" = "apt" ] && apt-get update &&
|
||||
apt-get install -yqq go npm node-mustache
|
||||
fi
|
||||
# Mustache
|
||||
COMMAND="mustache"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &> /dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && apk add --no-cache go npm \
|
||||
&& apk upgrade --no-cache \
|
||||
&& apk add --no-cache --virtual .build-deps build-base git go \
|
||||
&& go get -u github.com/quantumew/mustache-cli \
|
||||
&& cp "$GOPATH"/bin/* /usr/bin/ \
|
||||
&& rm -rf "$GOPATH" /var/cache/apk/* /tmp/src \
|
||||
&& apk del .build-deps xz build-base
|
||||
[ "$PACKMANAGER" = "apt" ] && apt-get update \
|
||||
&& apt-get install -yqq go npm node-mustache
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
if [ -f /ERROR ]; then
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -11,26 +11,26 @@ MODULES="$MODULES 00-banner.sh 01-custom_script.sh 01-config_yaml.sh 00-global_v
|
||||
echo "To download : $MODULES"
|
||||
|
||||
# Install bash if not available
|
||||
if ! command -v bash >/dev/null 2>/dev/null; then
|
||||
(apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null
|
||||
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
|
||||
|
||||
# Install curl if not available
|
||||
if ! command -v curl >/dev/null 2>/dev/null; then
|
||||
(apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null
|
||||
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
|
||||
|
||||
# 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
|
||||
mkdir -p /etc/cont-init.d
|
||||
|
||||
# Download scripts
|
||||
for scripts in $MODULES; do
|
||||
echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" &&
|
||||
[ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] ||
|
||||
(echo "script failed to install $scripts" && exit 1)
|
||||
echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" \
|
||||
&& [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] \
|
||||
|| (echo "script failed to install $scripts" && exit 1)
|
||||
done
|
||||
|
||||
chmod -R 755 /etc/cont-init.d
|
||||
|
||||
15
.templates/ha_entrypoint.sh
Executable file → Normal file
15
.templates/ha_entrypoint.sh
Executable file → Normal file
@@ -30,7 +30,7 @@ for SCRIPTS in /etc/cont-init.d/*; do
|
||||
if [ ! -f "${currentshebang%% *}" ]; then
|
||||
for shebang in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/usr/bin/bash" "/usr/bin/sh" "/bin/bash" "/bin/sh"; do
|
||||
command_path="${shebang%% *}"
|
||||
if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then
|
||||
if [ -x "$command_path" ] && "$command_path" echo "yes" > /dev/null 2>&1; then
|
||||
echo "Valid shebang: $shebang"
|
||||
break
|
||||
fi
|
||||
@@ -39,7 +39,7 @@ for SCRIPTS in /etc/cont-init.d/*; do
|
||||
fi
|
||||
|
||||
# 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/bashio::exit.nok/return 1/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
|
||||
sed -i -E 's|^s6-setuidgid[[:space:]]+([a-zA-Z0-9._-]+)[[:space:]]+(.*)$|su -s /bin/bash \1 -c "\2"|g' "$runfile"
|
||||
chmod +x "$runfile"
|
||||
( exec "$runfile" ) & true
|
||||
(exec "$runfile") &
|
||||
true
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -76,19 +77,19 @@ if [ "$$" -eq 1 ]; then
|
||||
terminate() {
|
||||
echo "Termination signal received, forwarding to subprocesses..."
|
||||
# Terminate all subprocesses
|
||||
if command -v pgrep &>/dev/null; then
|
||||
if command -v pgrep &> /dev/null; then
|
||||
for pid in $(pgrep -P $$); do
|
||||
echo "Terminating child PID $pid"
|
||||
kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid"
|
||||
kill -TERM "$pid" 2> /dev/null || echo "Failed to terminate PID $pid"
|
||||
done
|
||||
else
|
||||
# Fallback to iterating through /proc if pgrep is not available
|
||||
for pid in /proc/[0-9]*/; do
|
||||
pid=${pid#/proc/}
|
||||
pid=${pid%/}
|
||||
if [[ "$pid" -ne 1 ]] && grep -q "^PPid:\s*$$" "/proc/$pid/status" 2>/dev/null; then
|
||||
if [[ "$pid" -ne 1 ]] && grep -q "^PPid:\s*$$" "/proc/$pid/status" 2> /dev/null; then
|
||||
echo "Terminating child PID $pid"
|
||||
kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid"
|
||||
kill -TERM "$pid" 2> /dev/null || echo "Failed to terminate PID $pid"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -12,23 +12,23 @@ PUID="${PUID:-0}"
|
||||
PGID="${PGID:-0}"
|
||||
|
||||
if [ -f /ha_entrypoint.sh ]; then
|
||||
chown -R "$PUID:$PGID" /ha_entrypoint.sh
|
||||
chmod -R 755 /ha_entrypoint.sh
|
||||
chown -R "$PUID:$PGID" /ha_entrypoint.sh
|
||||
chmod -R 755 /ha_entrypoint.sh
|
||||
fi
|
||||
|
||||
if [ -d /etc/cont-init.d ]; then
|
||||
chown -R "$PUID:$PGID" /etc/cont-init.d
|
||||
chmod -R 755 /etc/cont-init.d
|
||||
chown -R "$PUID:$PGID" /etc/cont-init.d
|
||||
chmod -R 755 /etc/cont-init.d
|
||||
fi
|
||||
|
||||
if [ -d /etc/services.d ]; then
|
||||
chown -R "$PUID:$PGID" /etc/services.d
|
||||
chmod -R 755 /etc/services.d
|
||||
chown -R "$PUID:$PGID" /etc/services.d
|
||||
chmod -R 755 /etc/services.d
|
||||
fi
|
||||
|
||||
if [ -d /etc/s6-rc.d ]; then
|
||||
chown -R "$PUID:$PGID" /etc/s6-rc.d
|
||||
chmod -R 755 /etc/s6-rc.d
|
||||
chown -R "$PUID:$PGID" /etc/s6-rc.d
|
||||
chmod -R 755 /etc/s6-rc.d
|
||||
fi
|
||||
|
||||
# Correct shebang in entrypoint
|
||||
@@ -39,11 +39,11 @@ mkdir -p /run/s6/container_environment
|
||||
|
||||
# Check if shebang exists
|
||||
for shebang in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/usr/bin/bash" "/usr/bin/sh" "/bin/bash" "/bin/sh"; do
|
||||
command_path="${shebang%% *}"
|
||||
if [ -x "$command_path" ] && "$command_path" echo "yes" >/dev/null 2>&1; then
|
||||
echo "Valid shebang: $shebang"
|
||||
break
|
||||
fi
|
||||
command_path="${shebang%% *}"
|
||||
if [ -x "$command_path" ] && "$command_path" echo "yes" > /dev/null 2>&1; then
|
||||
echo "Valid shebang: $shebang"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Define shebang
|
||||
@@ -51,12 +51,12 @@ sed -i "s|/command/with-contenv bashio|$shebang|g" /ha_entrypoint.sh
|
||||
|
||||
# Correct for scripts
|
||||
for string in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio"; do
|
||||
grep -sril "$string" /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d | while read -r files; do
|
||||
sed -i "s|$string|$shebang|g" "$files"
|
||||
done
|
||||
grep -sril "$string" /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d | while read -r files; do
|
||||
sed -i "s|$string|$shebang|g" "$files"
|
||||
done
|
||||
done
|
||||
|
||||
# Avoid interference with LOG_LEVEL used in the app
|
||||
if [ -f /usr/lib/bashio/bashio.sh ]; then
|
||||
sed -i 's|{LOG_LEVEL:|{BASHIO_LOG_LEVEL:|g' /usr/lib/bashio/bashio.sh
|
||||
sed -i 's|{LOG_LEVEL:|{BASHIO_LOG_LEVEL:|g' /usr/lib/bashio/bashio.sh
|
||||
fi
|
||||
|
||||
@@ -12,48 +12,48 @@ echo "Setting config to $CONFIGLOCATION"
|
||||
|
||||
# Avoid custom-init.d duplications
|
||||
for file in $(grep -sril 'Potential tampering with custom' /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d); do
|
||||
rm -f "$file"
|
||||
rm -f "$file"
|
||||
done
|
||||
|
||||
# If custom config
|
||||
if [ "$CONFIGLOCATION" != "/config" ]; then
|
||||
|
||||
# Create new config folder if needed
|
||||
for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do
|
||||
sed -i "1a mkdir -p $CONFIGLOCATION" "$file"
|
||||
done
|
||||
# Create new config folder if needed
|
||||
for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do
|
||||
sed -i "1a mkdir -p $CONFIGLOCATION" "$file"
|
||||
done
|
||||
|
||||
# Correct config location
|
||||
for file in $(grep -Esril "/config[ '\"/]|/config\$" /etc /defaults); do
|
||||
sed -Ei "s=(/config)+(/| |$|\"|\')=$CONFIGLOCATION\2=g" "$file"
|
||||
done
|
||||
# Correct config location
|
||||
for file in $(grep -Esril "/config[ '\"/]|/config\$" /etc /defaults); do
|
||||
sed -Ei "s=(/config)+(/| |$|\"|\')=$CONFIGLOCATION\2=g" "$file"
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
# Allow UID and GID setting
|
||||
for file in $(grep -srl "PUID" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do
|
||||
sed -i 's/bash/bashio/g' "$file" && sed -i '1a PUID="$(if bashio::config.has_value "PUID"; then bashio::config "PUID"; else echo "0"; fi)"' "$file"
|
||||
sed -i '1a PGID="$(if bashio::config.has_value "PGID"; then bashio::config "PGID"; else echo "0"; fi)"' "$file"
|
||||
sed -i 's/bash/bashio/g' "$file" && sed -i '1a PUID="$(if bashio::config.has_value "PUID"; then bashio::config "PUID"; else echo "0"; fi)"' "$file"
|
||||
sed -i '1a PGID="$(if bashio::config.has_value "PGID"; then bashio::config "PGID"; else echo "0"; fi)"' "$file"
|
||||
done
|
||||
|
||||
# Avoid chmod /config if ha config mounted
|
||||
if [ -f /config/configuration.yaml ] || [ -f /config/configuration.json ]; then
|
||||
for file in /etc/services.d/*/* /etc/cont-init.d/* /etc/s6-overlay/s6-rc.d/*/*; do
|
||||
if [ -f "$file" ] && [ -n "$(awk '/chown.*abc:abc.*\\/,/.*\/config( |$)/{print FILENAME}' "$file")" ]; then
|
||||
sed -i "s|/config$|/data|g" "$file"
|
||||
fi
|
||||
done
|
||||
for file in /etc/services.d/*/* /etc/cont-init.d/* /etc/s6-overlay/s6-rc.d/*/*; do
|
||||
if [ -f "$file" ] && [ -n "$(awk '/chown.*abc:abc.*\\/,/.*\/config( |$)/{print FILENAME}' "$file")" ]; then
|
||||
sed -i "s|/config$|/data|g" "$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Send crond logs to addon logs
|
||||
if [ -f /etc/s6-overlay/s6-rc.d/svc-cron/run ]; then
|
||||
sed -i "/exec busybox crond/c exec busybox crond -f -S -L /proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run
|
||||
sed -i "/exec \/usr\/sbin\/cron/c exec /usr/sbin/cron -f &>/proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run
|
||||
sed -i "/exec busybox crond/c exec busybox crond -f -S -L /proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run
|
||||
sed -i "/exec \/usr\/sbin\/cron/c exec /usr/sbin/cron -f &>/proc/1/fd/1" /etc/s6-overlay/s6-rc.d/svc-cron/run
|
||||
fi
|
||||
|
||||
# variables not found
|
||||
for file in $(grep -srl "/usr/bin" /etc/cont-init.d /etc/s6-overlay/s6-rc.d); do
|
||||
sed -i "1a set +u" "$file"
|
||||
sed -i "1a set +u" "$file"
|
||||
done
|
||||
|
||||
# Allow running abc as user 1
|
||||
@@ -62,7 +62,7 @@ sed -i '/groupmod/ s/$/ 2>\/dev\/null || true/' /etc/s6-overlay/s6-rc.d/init-add
|
||||
|
||||
# Replace lsiown if not found
|
||||
if [ ! -f /usr/bin/lsiown ]; then
|
||||
for file in $(grep -sril "lsiown" /etc); do
|
||||
sed -i "s|lsiown|chown|g" "$file"
|
||||
done
|
||||
for file in $(grep -sril "lsiown" /etc); do
|
||||
sed -i "s|lsiown|chown|g" "$file"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -9,7 +9,7 @@ set -e
|
||||
bashio::log.info "Starting $(lastversion --version)"
|
||||
|
||||
if bashio::config.true "dry_run"; then
|
||||
bashio::log.warning "Dry run mode : on"
|
||||
bashio::log.warning "Dry run mode : on"
|
||||
fi
|
||||
|
||||
bashio::log.info "Checking status of referenced repositoriess..."
|
||||
@@ -26,9 +26,9 @@ git config --system user.name "${GITUSER}"
|
||||
if [[ "$GITMAIL" != "null" ]]; then git config --system user.email "${GITMAIL}"; fi
|
||||
|
||||
if bashio::config.has_value 'gitapi'; then
|
||||
LOGINFO="... setting github API" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
GITHUB_API_TOKEN=$(bashio::config 'gitapi')
|
||||
export GITHUB_API_TOKEN
|
||||
LOGINFO="... setting github API" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
GITHUB_API_TOKEN=$(bashio::config 'gitapi')
|
||||
export GITHUB_API_TOKEN
|
||||
fi
|
||||
|
||||
#Create or update local version
|
||||
@@ -36,14 +36,14 @@ REPOSITORY=$(bashio::config 'repository')
|
||||
BASENAME=$(basename "https://github.com/$REPOSITORY")
|
||||
|
||||
if [ ! -d "/data/$BASENAME" ]; then
|
||||
LOGINFO="... cloning ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd /data/ || exit
|
||||
git clone "https://github.com/${REPOSITORY}"
|
||||
LOGINFO="... cloning ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd /data/ || exit
|
||||
git clone "https://github.com/${REPOSITORY}"
|
||||
else
|
||||
LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd "/data/$BASENAME" || exit
|
||||
git pull --rebase origin >/dev/null || git reset --hard origin/master >/dev/null
|
||||
git pull --rebase origin >/dev/null || (rm -r "/data/$BASENAME" && git clone "https://github.com/${REPOSITORY}")
|
||||
LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd "/data/$BASENAME" || exit
|
||||
git pull --rebase origin > /dev/null || git reset --hard origin/master > /dev/null
|
||||
git pull --rebase origin > /dev/null || (rm -r "/data/$BASENAME" && git clone "https://github.com/${REPOSITORY}")
|
||||
fi
|
||||
|
||||
LOGINFO="... parse addons" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
@@ -53,282 +53,282 @@ LOGINFO="... parse addons" && if [ "$VERBOSE" = true ]; then bashio::log.info "$
|
||||
cd /data/"$BASENAME" || exit
|
||||
for f in */; do
|
||||
|
||||
if [ -f /data/"$BASENAME"/"$f"/updater.json ]; then
|
||||
SLUG=${f//\//}
|
||||
if [ -f /data/"$BASENAME"/"$f"/updater.json ]; then
|
||||
SLUG=${f//\//}
|
||||
|
||||
# Rebase
|
||||
LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd "/data/$BASENAME" || exit
|
||||
git pull --rebase &>/dev/null || git reset --hard &>/dev/null
|
||||
git pull --rebase &>/dev/null
|
||||
# Rebase
|
||||
LOGINFO="... updating ${REPOSITORY}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd "/data/$BASENAME" || exit
|
||||
git pull --rebase &> /dev/null || git reset --hard &> /dev/null
|
||||
git pull --rebase &> /dev/null
|
||||
|
||||
#Define the folder addon
|
||||
LOGINFO="... $SLUG : checking slug exists in repo" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd /data/"${BASENAME}"/"${SLUG}" || {
|
||||
bashio::log.error "$SLUG addon not found in this repository. Exiting."
|
||||
continue
|
||||
}
|
||||
#Define the folder addon
|
||||
LOGINFO="... $SLUG : checking slug exists in repo" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
cd /data/"${BASENAME}"/"${SLUG}" || {
|
||||
bashio::log.error "$SLUG addon not found in this repository. Exiting."
|
||||
continue
|
||||
}
|
||||
|
||||
# Get variables
|
||||
UPSTREAM=$(jq -r .upstream_repo updater.json)
|
||||
BETA=$(jq -r .github_beta updater.json)
|
||||
FULLTAG=$(jq -r .github_fulltag updater.json)
|
||||
HAVINGASSET=$(jq -r .github_havingasset updater.json)
|
||||
SOURCE=$(jq -r .source updater.json)
|
||||
FILTER_TEXT=$(jq -r .github_tagfilter updater.json)
|
||||
EXCLUDE_TEXT=$(jq -r .github_exclude updater.json)
|
||||
EXCLUDE_TEXT="${EXCLUDE_TEXT:-zzzzzzzzzzzzzzzz}"
|
||||
PAUSED=$(jq -r .paused updater.json)
|
||||
DATE="$(date '+%d-%m-%Y')"
|
||||
BYDATE=$(jq -r .dockerhub_by_date updater.json)
|
||||
# Get variables
|
||||
UPSTREAM=$(jq -r .upstream_repo updater.json)
|
||||
BETA=$(jq -r .github_beta updater.json)
|
||||
FULLTAG=$(jq -r .github_fulltag updater.json)
|
||||
HAVINGASSET=$(jq -r .github_havingasset updater.json)
|
||||
SOURCE=$(jq -r .source updater.json)
|
||||
FILTER_TEXT=$(jq -r .github_tagfilter updater.json)
|
||||
EXCLUDE_TEXT=$(jq -r .github_exclude updater.json)
|
||||
EXCLUDE_TEXT="${EXCLUDE_TEXT:-zzzzzzzzzzzzzzzz}"
|
||||
PAUSED=$(jq -r .paused updater.json)
|
||||
DATE="$(date '+%d-%m-%Y')"
|
||||
BYDATE=$(jq -r .dockerhub_by_date updater.json)
|
||||
|
||||
# Number of elements to check in dockerhub
|
||||
if grep -q "dockerhub_list_size" updater.json; then
|
||||
LISTSIZE=$(jq -r .dockerhub_list_size updater.json)
|
||||
else
|
||||
LISTSIZE=100
|
||||
fi
|
||||
# Number of elements to check in dockerhub
|
||||
if grep -q "dockerhub_list_size" updater.json; then
|
||||
LISTSIZE=$(jq -r .dockerhub_list_size updater.json)
|
||||
else
|
||||
LISTSIZE=100
|
||||
fi
|
||||
|
||||
#Skip if paused
|
||||
if [[ "$PAUSED" = true ]]; then
|
||||
bashio::log.magenta "... $SLUG addon updates are paused, skipping"
|
||||
continue
|
||||
fi
|
||||
#Skip if paused
|
||||
if [[ "$PAUSED" = true ]]; then
|
||||
bashio::log.magenta "... $SLUG addon updates are paused, skipping"
|
||||
continue
|
||||
fi
|
||||
|
||||
#Find current version
|
||||
LOGINFO="... $SLUG : get current version" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
CURRENT=$(jq .upstream_version updater.json) ||
|
||||
{
|
||||
bashio::log.error "$SLUG addon upstream tag not found in updater.json. Exiting."
|
||||
continue
|
||||
}
|
||||
#Find current version
|
||||
LOGINFO="... $SLUG : get current version" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
CURRENT=$(jq .upstream_version updater.json) \
|
||||
|| {
|
||||
bashio::log.error "$SLUG addon upstream tag not found in updater.json. Exiting."
|
||||
continue
|
||||
}
|
||||
|
||||
if [[ "$SOURCE" = dockerhub ]]; then
|
||||
# Use dockerhub as upstream
|
||||
# shellcheck disable=SC2116
|
||||
LOGINFO="... Source is dockerhub" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
if [[ "$SOURCE" = dockerhub ]]; then
|
||||
# Use dockerhub as upstream
|
||||
# shellcheck disable=SC2116
|
||||
LOGINFO="... Source is dockerhub" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
|
||||
#Prepare tag flag
|
||||
if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then
|
||||
FILTER_TEXT=""
|
||||
else
|
||||
LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
FILTER_TEXT="&name=$FILTER_TEXT"
|
||||
fi
|
||||
#Prepare tag flag
|
||||
if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then
|
||||
FILTER_TEXT=""
|
||||
else
|
||||
LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
FILTER_TEXT="&name=$FILTER_TEXT"
|
||||
fi
|
||||
|
||||
#Prepare tag flag
|
||||
if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then
|
||||
EXCLUDE_TEXT="zzzzzzzzzzzzzzzzzz"
|
||||
fi
|
||||
#Prepare tag flag
|
||||
if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then
|
||||
EXCLUDE_TEXT="zzzzzzzzzzzzzzzzzz"
|
||||
fi
|
||||
|
||||
DOCKERHUB_REPO="${UPSTREAM%%/*}"
|
||||
DOCKERHUB_IMAGE=$(echo "$UPSTREAM" | cut -d "/" -f2)
|
||||
LASTVERSION=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" |
|
||||
jq '.results | .[] | .name' -r |
|
||||
sed -e '/.*latest.*/d' |
|
||||
sed -e '/.*dev.*/d' |
|
||||
sed -e '/.*nightly.*/d' |
|
||||
sed -e '/.*beta.*/d' |
|
||||
sed -e "/.*$EXCLUDE_TEXT.*/d" |
|
||||
sort -V |
|
||||
tail -n 1
|
||||
)
|
||||
DOCKERHUB_REPO="${UPSTREAM%%/*}"
|
||||
DOCKERHUB_IMAGE=$(echo "$UPSTREAM" | cut -d "/" -f2)
|
||||
LASTVERSION=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" \
|
||||
| jq '.results | .[] | .name' -r \
|
||||
| sed -e '/.*latest.*/d' \
|
||||
| sed -e '/.*dev.*/d' \
|
||||
| sed -e '/.*nightly.*/d' \
|
||||
| sed -e '/.*beta.*/d' \
|
||||
| sed -e "/.*$EXCLUDE_TEXT.*/d" \
|
||||
| sort -V \
|
||||
| tail -n 1
|
||||
)
|
||||
|
||||
[ "${BETA}" = true ] &&
|
||||
LASTVERSION=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" |
|
||||
jq '.results | .[] | .name' -r |
|
||||
sed -e '/.*latest.*/d' |
|
||||
sed -e '/.*dev.*/!d' |
|
||||
sed -e "/.*$EXCLUDE_TEXT.*/d" |
|
||||
sort -V |
|
||||
tail -n 1
|
||||
)
|
||||
[ "${BETA}" = true ] \
|
||||
&& LASTVERSION=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=$LISTSIZE$FILTER_TEXT" \
|
||||
| jq '.results | .[] | .name' -r \
|
||||
| sed -e '/.*latest.*/d' \
|
||||
| sed -e '/.*dev.*/!d' \
|
||||
| sed -e "/.*$EXCLUDE_TEXT.*/d" \
|
||||
| sort -V \
|
||||
| tail -n 1
|
||||
)
|
||||
|
||||
[ "${BYDATE}" = true ] &&
|
||||
LASTVERSION=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" |
|
||||
jq '.results | .[] | .name' -r |
|
||||
sed -e '/.*latest.*/d' |
|
||||
sed -e '/.*dev.*/d' |
|
||||
sed -e '/.*nightly.*/d' |
|
||||
sed -e "/.*$EXCLUDE_TEXT.*/d" |
|
||||
sort -V |
|
||||
tail -n 1
|
||||
) &&
|
||||
DATE=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags/?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" |
|
||||
jq '.results[] | select(.name==$LASTVERSION) | .last_updated' -r --arg LASTVERSION "$LASTVERSION"
|
||||
) &&
|
||||
DATE="${DATE%T*}" &&
|
||||
LASTVERSION="$LASTVERSION-$DATE"
|
||||
LOGINFO="... $SLUG : bydate is true, version is $LASTVERSION" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
[ "${BYDATE}" = true ] \
|
||||
&& LASTVERSION=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" \
|
||||
| jq '.results | .[] | .name' -r \
|
||||
| sed -e '/.*latest.*/d' \
|
||||
| sed -e '/.*dev.*/d' \
|
||||
| sed -e '/.*nightly.*/d' \
|
||||
| sed -e "/.*$EXCLUDE_TEXT.*/d" \
|
||||
| sort -V \
|
||||
| tail -n 1
|
||||
) \
|
||||
&& DATE=$(
|
||||
curl -f -L -s --fail "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${DOCKERHUB_IMAGE}/tags/?page_size=${LISTSIZE}&ordering=last_updated$FILTER_TEXT" \
|
||||
| jq '.results[] | select(.name==$LASTVERSION) | .last_updated' -r --arg LASTVERSION "$LASTVERSION"
|
||||
) \
|
||||
&& DATE="${DATE%T*}" \
|
||||
&& LASTVERSION="$LASTVERSION-$DATE"
|
||||
LOGINFO="... $SLUG : bydate is true, version is $LASTVERSION" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
|
||||
else
|
||||
else
|
||||
|
||||
# Use source as upstream
|
||||
ARGUMENTS="--at $SOURCE"
|
||||
LOGINFO="... $SLUG : source is $SOURCE" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
# Use source as upstream
|
||||
ARGUMENTS="--at $SOURCE"
|
||||
LOGINFO="... $SLUG : source is $SOURCE" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
|
||||
#Prepare tag flag
|
||||
if [ "${FULLTAG}" = true ]; then
|
||||
LOGINFO="... $SLUG : github_fulltag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --format tag"
|
||||
else
|
||||
LOGINFO="... $SLUG : github_fulltag is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
fi
|
||||
#Prepare tag flag
|
||||
if [ "${FULLTAG}" = true ]; then
|
||||
LOGINFO="... $SLUG : github_fulltag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --format tag"
|
||||
else
|
||||
LOGINFO="... $SLUG : github_fulltag is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
fi
|
||||
|
||||
#Prepare tag flag
|
||||
if [ "${HAVINGASSET}" = true ]; then
|
||||
LOGINFO="... $SLUG : asset_only tag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --having-asset"
|
||||
else
|
||||
LOGINFO="... $SLUG : asset_only is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
fi
|
||||
#Prepare tag flag
|
||||
if [ "${HAVINGASSET}" = true ]; then
|
||||
LOGINFO="... $SLUG : asset_only tag is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --having-asset"
|
||||
else
|
||||
LOGINFO="... $SLUG : asset_only is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
fi
|
||||
|
||||
#Prepare tag flag
|
||||
if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then
|
||||
FILTER_TEXT=""
|
||||
else
|
||||
LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --only $FILTER_TEXT"
|
||||
fi
|
||||
#Prepare tag flag
|
||||
if [ "${FILTER_TEXT}" = "null" ] || [ "${FILTER_TEXT}" = "" ]; then
|
||||
FILTER_TEXT=""
|
||||
else
|
||||
LOGINFO="... $SLUG : filter_text is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --only $FILTER_TEXT"
|
||||
fi
|
||||
|
||||
#Prepare tag flag
|
||||
if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then
|
||||
EXCLUDE_TEXT=""
|
||||
else
|
||||
LOGINFO="... $SLUG : github_exclude is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --exclude $EXCLUDE_TEXT"
|
||||
fi
|
||||
#Prepare tag flag
|
||||
if [ "${EXCLUDE_TEXT}" = "null" ] || [ "${EXCLUDE_TEXT}" = "" ]; then
|
||||
EXCLUDE_TEXT=""
|
||||
else
|
||||
LOGINFO="... $SLUG : github_exclude is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --exclude $EXCLUDE_TEXT"
|
||||
fi
|
||||
|
||||
#If beta flag, select beta version
|
||||
if [ "${BETA}" = true ]; then
|
||||
LOGINFO="... $SLUG : beta is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --pre"
|
||||
else
|
||||
LOGINFO="... $SLUG : beta is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
fi
|
||||
#If beta flag, select beta version
|
||||
if [ "${BETA}" = true ]; then
|
||||
LOGINFO="... $SLUG : beta is on" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
ARGUMENTS="$ARGUMENTS --pre"
|
||||
else
|
||||
LOGINFO="... $SLUG : beta is off" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
fi
|
||||
|
||||
# If failure, checks if there is packages that could be used
|
||||
function test_packages() {
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
# shellcheck disable=SC2086
|
||||
bashio::log.info "source : $SOURCE and LASTVERSION : $(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)"
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
if [[ "$SOURCE" == *"github"* ]] && [[ "$(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" == *"No release"* ]]; then
|
||||
# Is there a package
|
||||
bashio::log.warning "No version found, looking if packages available"
|
||||
last_packages="$(curl -s -L https://github.com/"$UPSTREAM"/packages | sed -n "s/.*\/container\/package\/\([^\"]*\).*/\1/p")" || true
|
||||
last_package="$(echo "$last_packages" | head -n 1)" || true
|
||||
if [[ "$(echo -n "$last_packages" | grep -c '^')" -gt 0 ]]; then
|
||||
bashio::log.warning "A total of $(echo -n "$last_packages" | grep -c '^') packages were found, using $last_package"
|
||||
LASTVERSION=""
|
||||
LASTVERSION="$(curl -s -L https://github.com/"$UPSTREAM"/pkgs/container/"$last_package" | sed -n "s/.*?tag=\([^\"]*\)\">.*/\1/p" |
|
||||
sed -e '/.*latest.*/d' |
|
||||
sed -e '/.*dev.*/d' |
|
||||
sed -e '/.*nightly.*/d' |
|
||||
sed -e '/.*beta.*/d' |
|
||||
sort -V |
|
||||
tail -n 1)" || true
|
||||
if [[ "$LASTVERSION" == "" ]]; then
|
||||
# Continue to next
|
||||
bashio::log.warning "No packages found"
|
||||
set_continue=true
|
||||
else
|
||||
bashio::log.info "Found tag $LASTVERSION"
|
||||
echo "$LASTVERSION"
|
||||
fi
|
||||
else
|
||||
# Continue to next
|
||||
bashio::log.warning "No packages found"
|
||||
set_continue=true
|
||||
fi
|
||||
else
|
||||
# Continue to next
|
||||
set_continue=true
|
||||
fi
|
||||
}
|
||||
# If failure, checks if there is packages that could be used
|
||||
function test_packages() {
|
||||
if [ "$VERBOSE" = true ]; then
|
||||
# shellcheck disable=SC2086
|
||||
bashio::log.info "source : $SOURCE and LASTVERSION : $(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)"
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
if [[ "$SOURCE" == *"github"* ]] && [[ "$(lastversion "$UPSTREAM" $ARGUMENTS 2>&1 || true)" == *"No release"* ]]; then
|
||||
# Is there a package
|
||||
bashio::log.warning "No version found, looking if packages available"
|
||||
last_packages="$(curl -s -L https://github.com/"$UPSTREAM"/packages | sed -n "s/.*\/container\/package\/\([^\"]*\).*/\1/p")" || true
|
||||
last_package="$(echo "$last_packages" | head -n 1)" || true
|
||||
if [[ "$(echo -n "$last_packages" | grep -c '^')" -gt 0 ]]; then
|
||||
bashio::log.warning "A total of $(echo -n "$last_packages" | grep -c '^') packages were found, using $last_package"
|
||||
LASTVERSION=""
|
||||
LASTVERSION="$(curl -s -L https://github.com/"$UPSTREAM"/pkgs/container/"$last_package" | sed -n "s/.*?tag=\([^\"]*\)\">.*/\1/p" \
|
||||
| sed -e '/.*latest.*/d' \
|
||||
| sed -e '/.*dev.*/d' \
|
||||
| sed -e '/.*nightly.*/d' \
|
||||
| sed -e '/.*beta.*/d' \
|
||||
| sort -V \
|
||||
| tail -n 1)" || true
|
||||
if [[ "$LASTVERSION" == "" ]]; then
|
||||
# Continue to next
|
||||
bashio::log.warning "No packages found"
|
||||
set_continue=true
|
||||
else
|
||||
bashio::log.info "Found tag $LASTVERSION"
|
||||
echo "$LASTVERSION"
|
||||
fi
|
||||
else
|
||||
# Continue to next
|
||||
bashio::log.warning "No packages found"
|
||||
set_continue=true
|
||||
fi
|
||||
else
|
||||
# Continue to next
|
||||
set_continue=true
|
||||
fi
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
LASTVERSION="$(lastversion "$UPSTREAM" $ARGUMENTS || test_packages)"
|
||||
# shellcheck disable=SC2086
|
||||
LASTVERSION="$(lastversion "$UPSTREAM" $ARGUMENTS || test_packages)"
|
||||
|
||||
# Continue if issue
|
||||
if [[ "${set_continue:-false}" == true ]]; then
|
||||
continue
|
||||
fi
|
||||
# Continue if issue
|
||||
if [[ "${set_continue:-false}" == true ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# Add brackets
|
||||
LASTVERSION='"'${LASTVERSION}'"'
|
||||
# Add brackets
|
||||
LASTVERSION='"'${LASTVERSION}'"'
|
||||
|
||||
# Avoid characters incompatible with HomeAssistant version name
|
||||
LASTVERSION2=${LASTVERSION//+/-}
|
||||
CURRENT2=${CURRENT//+/-}
|
||||
# Avoid characters incompatible with HomeAssistant version name
|
||||
LASTVERSION2=${LASTVERSION//+/-}
|
||||
CURRENT2=${CURRENT//+/-}
|
||||
|
||||
# Update if needed
|
||||
if [ "${CURRENT2}" != "${LASTVERSION2}" ]; then
|
||||
LOGINFO="... $SLUG : update from ${CURRENT} to ${LASTVERSION}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
# Update if needed
|
||||
if [ "${CURRENT2}" != "${LASTVERSION2}" ]; then
|
||||
LOGINFO="... $SLUG : update from ${CURRENT} to ${LASTVERSION}" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
|
||||
#Change all instances of version
|
||||
LOGINFO="... $SLUG : updating files" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
for files in "config.json" "config.yaml" "Dockerfile" "build.json" "build.yaml"; do
|
||||
if [ -f /data/"${BASENAME}"/"${SLUG}"/$files ]; then
|
||||
sed -i "s/${CURRENT}/${LASTVERSION}/g" /data/"${BASENAME}"/"${SLUG}"/"$files"
|
||||
fi
|
||||
done
|
||||
#Change all instances of version
|
||||
LOGINFO="... $SLUG : updating files" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
for files in "config.json" "config.yaml" "Dockerfile" "build.json" "build.yaml"; do
|
||||
if [ -f /data/"${BASENAME}"/"${SLUG}"/$files ]; then
|
||||
sed -i "s/${CURRENT}/${LASTVERSION}/g" /data/"${BASENAME}"/"${SLUG}"/"$files"
|
||||
fi
|
||||
done
|
||||
|
||||
# Remove " and modify version
|
||||
LASTVERSION=${LASTVERSION//\"/}
|
||||
CURRENT=${CURRENT//\"/}
|
||||
if [ -f /data/"${BASENAME}"/"${SLUG}"/config.json ]; then
|
||||
jq --arg variable "$LASTVERSION" '.version = $variable' /data/"${BASENAME}"/"${SLUG}"/config.json | sponge /data/"${BASENAME}"/"${SLUG}"/config.json # Replace version tag
|
||||
elif [ -f /data/"${BASENAME}"/"${SLUG}"/config.yaml ]; then
|
||||
sed -i "/version:/c\version: \"$LASTVERSION\"" /data/"${BASENAME}"/"${SLUG}"/config.yaml
|
||||
fi
|
||||
jq --arg variable "$LASTVERSION" '.upstream_version = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace upstream tag
|
||||
jq --arg variable "$DATE" '.last_update = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace date tag
|
||||
# Remove " and modify version
|
||||
LASTVERSION=${LASTVERSION//\"/}
|
||||
CURRENT=${CURRENT//\"/}
|
||||
if [ -f /data/"${BASENAME}"/"${SLUG}"/config.json ]; then
|
||||
jq --arg variable "$LASTVERSION" '.version = $variable' /data/"${BASENAME}"/"${SLUG}"/config.json | sponge /data/"${BASENAME}"/"${SLUG}"/config.json # Replace version tag
|
||||
elif [ -f /data/"${BASENAME}"/"${SLUG}"/config.yaml ]; then
|
||||
sed -i "/version:/c\version: \"$LASTVERSION\"" /data/"${BASENAME}"/"${SLUG}"/config.yaml
|
||||
fi
|
||||
jq --arg variable "$LASTVERSION" '.upstream_version = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace upstream tag
|
||||
jq --arg variable "$DATE" '.last_update = $variable' /data/"${BASENAME}"/"${SLUG}"/updater.json | sponge /data/"${BASENAME}"/"${SLUG}"/updater.json # Replace date tag
|
||||
|
||||
#Update changelog
|
||||
touch "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
if [[ "$SOURCE" == *"github"* ]]; then
|
||||
sed -i "1i - Update to latest version from $UPSTREAM (changelog : https://github.com/${UPSTREAM%/}/releases)" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
else
|
||||
sed -i "1i - Update to latest version from $UPSTREAM" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
fi
|
||||
sed -i "1i ## ${LASTVERSION} (${DATE})" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
sed -i "1i " "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
LOGINFO="... $SLUG : files updated" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
#Update changelog
|
||||
touch "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
if [[ "$SOURCE" == *"github"* ]]; then
|
||||
sed -i "1i - Update to latest version from $UPSTREAM (changelog : https://github.com/${UPSTREAM%/}/releases)" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
else
|
||||
sed -i "1i - Update to latest version from $UPSTREAM" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
fi
|
||||
sed -i "1i ## ${LASTVERSION} (${DATE})" "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
sed -i "1i " "/data/${BASENAME}/${SLUG}/CHANGELOG.md"
|
||||
LOGINFO="... $SLUG : files updated" && if [ "$VERBOSE" = true ]; then bashio::log.info "$LOGINFO"; fi
|
||||
|
||||
#Git commit and push
|
||||
git add -A # add all modified files
|
||||
#Git commit and push
|
||||
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
|
||||
if ! bashio::config.true "dry_run"; then
|
||||
git push &>/dev/null
|
||||
fi
|
||||
# Push
|
||||
if ! bashio::config.true "dry_run"; then
|
||||
git push &> /dev/null
|
||||
fi
|
||||
|
||||
#Log
|
||||
bashio::log.yellow "... $SLUG updated from ${CURRENT} to ${LASTVERSION}"
|
||||
#Log
|
||||
bashio::log.yellow "... $SLUG updated from ${CURRENT} to ${LASTVERSION}"
|
||||
|
||||
else
|
||||
bashio::log.green "... $SLUG is up-to-date ${CURRENT}"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
bashio::log.green "... $SLUG is up-to-date ${CURRENT}"
|
||||
fi
|
||||
fi
|
||||
done || true # Continue even if issue
|
||||
|
||||
# Clean dry run
|
||||
if bashio::config.true "dry_run"; then
|
||||
rm -r /data/*
|
||||
rm -r /data/*
|
||||
fi
|
||||
|
||||
bashio::log.info "Addons update completed"
|
||||
|
||||
@@ -7,9 +7,9 @@ set +u
|
||||
|
||||
# Autodefine if not defined
|
||||
if [ -n "$INTERFACE_NAME" ]; then
|
||||
# shellcheck disable=SC2155
|
||||
export INTERFACE_NAME="$(ip route get 8.8.8.8 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')"
|
||||
bashio::log.blue "Autodetection : INTERFACE_NAME=$INTERFACE_NAME"
|
||||
# shellcheck disable=SC2155
|
||||
export INTERFACE_NAME="$(ip route get 8.8.8.8 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')"
|
||||
bashio::log.blue "Autodetection : INTERFACE_NAME=$INTERFACE_NAME"
|
||||
fi
|
||||
|
||||
bashio::log.info "Starting..."
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
set -e
|
||||
|
||||
if [ ! -d /data/autobrr ]; then
|
||||
echo "Creating /data/autobrr"
|
||||
mkdir -p /data/autobrr
|
||||
chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /data/autobrr
|
||||
echo "Creating /data/autobrr"
|
||||
mkdir -p /data/autobrr
|
||||
chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /data/autobrr
|
||||
fi
|
||||
|
||||
if [ ! -d /config/addons_config/autobrr ]; then
|
||||
echo "Creating /config/addons_config/autobrr"
|
||||
mkdir -p /config/addons_config/autobrr
|
||||
chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /config/addons_config/autobrr
|
||||
echo "Creating /config/addons_config/autobrr"
|
||||
mkdir -p /config/addons_config/autobrr
|
||||
chown -R "$(bashio::config "PUID"):$(bashio::config "PGID")" /config/addons_config/autobrr
|
||||
fi
|
||||
|
||||
@@ -7,7 +7,7 @@ set -e
|
||||
####################
|
||||
|
||||
if [ -d /homeassistant/addons_config/baikal ]; then
|
||||
echo "Moving database to new location /config, you won't be able to restore previous versions of the addon"
|
||||
cp -rf /homeassistant/addons_config/baikal/* /config/
|
||||
rm -r /homeassistant/addons_config/baikal
|
||||
echo "Moving database to new location /config, you won't be able to restore previous versions of the addon"
|
||||
cp -rf /homeassistant/addons_config/baikal/* /config/
|
||||
rm -r /homeassistant/addons_config/baikal
|
||||
fi
|
||||
|
||||
@@ -8,6 +8,6 @@ chown -R nginx:nginx /data
|
||||
|
||||
# Start app
|
||||
# Find the PHP FPM service script and start it
|
||||
find /etc/init.d -type f -name "php*-fpm" -exec {} start \; &&
|
||||
chown -R nginx:nginx /data/Specific &&
|
||||
nginx -g "daemon off;"
|
||||
find /etc/init.d -type f -name "php*-fpm" -exec {} start \; \
|
||||
&& chown -R nginx:nginx /data/Specific \
|
||||
&& nginx -g "daemon off;"
|
||||
|
||||
@@ -4,8 +4,8 @@ set -e
|
||||
|
||||
# Remove not working elements
|
||||
if bashio::config.true "NO_NOISE_MODEL"; then
|
||||
bashio::log.info "Activating the no_noise models as NO_NOISE_MODEL is true"
|
||||
sed -i "s|server.py --area|server.py --no_noise on --area|g" "$HOME"/BirdNET-Pi/scripts/batnet_analysis.sh
|
||||
bashio::log.info "Activating the no_noise models as NO_NOISE_MODEL is true"
|
||||
sed -i "s|server.py --area|server.py --no_noise on --area|g" "$HOME"/BirdNET-Pi/scripts/batnet_analysis.sh
|
||||
fi
|
||||
|
||||
# Add batnet service to monitoring service
|
||||
@@ -14,15 +14,15 @@ sed -i "s|spectrogram_viewer |spectrogram_viewer batnet_server |g" /custom-servi
|
||||
|
||||
# Install gotty for amd64
|
||||
if [ "$(uname -m)" == "x86_64" ]; then
|
||||
bashio::log.info "Install gotty for amd64"
|
||||
curl -L https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_amd64.tar.gz | tar xz -C /tmp
|
||||
mv /tmp/gotty /usr/local/bin/gotty
|
||||
chmod +x /usr/local/bin/gotty
|
||||
sed -i "s| -P log| log|g" "$HOME"/BirdNET-Pi/templates/birdnet_log.service
|
||||
bashio::log.info "Install gotty for amd64"
|
||||
curl -L https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_amd64.tar.gz | tar xz -C /tmp
|
||||
mv /tmp/gotty /usr/local/bin/gotty
|
||||
chmod +x /usr/local/bin/gotty
|
||||
sed -i "s| -P log| log|g" "$HOME"/BirdNET-Pi/templates/birdnet_log.service
|
||||
fi
|
||||
|
||||
# Make sure bats model is on
|
||||
echo 'sed -i "/BATS_ANALYSIS=/c\BATS_ANALYSIS=1" /config/birdnet.conf' >>/etc/cont-init.d/81-modifications.sh
|
||||
echo 'sed -i "/BATS_ANALYSIS=/c\BATS_ANALYSIS=1" /config/birdnet.conf' >> /etc/cont-init.d/81-modifications.sh
|
||||
|
||||
# Disable monitoring service
|
||||
sed -i "1a sleep infinity" /custom-services.d/30-monitoring.sh
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -d /share/storage/movies ]; then
|
||||
echo "Creating /share/storage/movies"
|
||||
mkdir -p /share/storage/movies
|
||||
chown -R "$PUID:$PGID" /share/storage/movies
|
||||
echo "Creating /share/storage/movies"
|
||||
mkdir -p /share/storage/movies
|
||||
chown -R "$PUID:$PGID" /share/storage/movies
|
||||
fi
|
||||
|
||||
if [ ! -d /share/storage/tv ]; then
|
||||
echo "Creating /share/storage/tv"
|
||||
mkdir -p /share/storage/tv
|
||||
chown -R "$PUID:$PGID" /share/storage/tv
|
||||
echo "Creating /share/storage/tv"
|
||||
mkdir -p /share/storage/tv
|
||||
chown -R "$PUID:$PGID" /share/storage/tv
|
||||
fi
|
||||
|
||||
if [ ! -d /share/downloads ]; then
|
||||
echo "Creating /share/downloads"
|
||||
mkdir -p /share/downloads
|
||||
chown -R "$PUID:$PGID" /share/downloads
|
||||
echo "Creating /share/downloads"
|
||||
mkdir -p /share/downloads
|
||||
chown -R "$PUID:$PGID" /share/downloads
|
||||
fi
|
||||
|
||||
if [ -d /config/bazarr ] && [ ! -d /config/addons_config/bazarr ]; then
|
||||
echo "Moving to new location /config/addons_config/bazarr"
|
||||
mkdir -p /config/addons_config/bazarr
|
||||
chown -R "$PUID:$PGID" /config/addons_config/bazarr
|
||||
mv /config/bazarr/* /config/addons_config/bazarr/
|
||||
rm -r /config/bazarr
|
||||
echo "Moving to new location /config/addons_config/bazarr"
|
||||
mkdir -p /config/addons_config/bazarr
|
||||
chown -R "$PUID:$PGID" /config/addons_config/bazarr
|
||||
mv /config/bazarr/* /config/addons_config/bazarr/
|
||||
rm -r /config/bazarr
|
||||
fi
|
||||
|
||||
if [ ! -d /config/addons_config/bazarr ]; then
|
||||
echo "Creating /config/addons_config/bazarr"
|
||||
mkdir -p /config/addons_config/bazarr
|
||||
chown -R "$PUID:$PGID" /config/addons_config/bazarr
|
||||
echo "Creating /config/addons_config/bazarr"
|
||||
mkdir -p /config/addons_config/bazarr
|
||||
chown -R "$PUID:$PGID" /config/addons_config/bazarr
|
||||
fi
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
set -e
|
||||
|
||||
if [ -d /config/binance-trading-bot ]; then
|
||||
echo "Moving to new location /config/addons_config/binance-trading-bot"
|
||||
mkdir -p /config/addons_config/binance-trading-bot
|
||||
chmod 777 /config/addons_config/binance-trading-bot
|
||||
mv /config/binance-trading-bot/* /config/addons_config/binance-trading-bot/
|
||||
rm -r /config/binance-trading-bot
|
||||
echo "Moving to new location /config/addons_config/binance-trading-bot"
|
||||
mkdir -p /config/addons_config/binance-trading-bot
|
||||
chmod 777 /config/addons_config/binance-trading-bot
|
||||
mv /config/binance-trading-bot/* /config/addons_config/binance-trading-bot/
|
||||
rm -r /config/binance-trading-bot
|
||||
fi
|
||||
|
||||
if [ ! -d /config/addons_config/binance-trading-bot ]; then
|
||||
echo "Creating /config/addons_config/binance-trading-bot"
|
||||
mkdir -p /config/addons_config/binance-trading-bot
|
||||
chmod 777 /config/addons_config/binance-trading-bot
|
||||
echo "Creating /config/addons_config/binance-trading-bot"
|
||||
mkdir -p /config/addons_config/binance-trading-bot
|
||||
chmod 777 /config/addons_config/binance-trading-bot
|
||||
fi
|
||||
|
||||
@@ -7,16 +7,16 @@ DEFAULT_BIRDSONGS_FOLDER="/data/clips/"
|
||||
CONFIG_LOCATION="/config/config.yaml"
|
||||
|
||||
if [ ! -f "$CONFIG_LOCATION" ]; then
|
||||
bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize"
|
||||
curl -L -s -S https://raw.githubusercontent.com/tphakala/birdnet-go/refs/heads/main/internal/conf/config.yaml -o "$CONFIG_LOCATION"
|
||||
bashio::log.warning "There is no config.yaml yet in the config folder, downloading a default one. Please customize"
|
||||
curl -L -s -S https://raw.githubusercontent.com/tphakala/birdnet-go/refs/heads/main/internal/conf/config.yaml -o "$CONFIG_LOCATION"
|
||||
fi
|
||||
|
||||
#################
|
||||
# Migrate Database
|
||||
#################
|
||||
if [ -f /data/birdnet.db ]; then
|
||||
bashio::log.warning "Moving birdnet.db to /config/birdnet.db"
|
||||
mv /data/birdnet.db /config
|
||||
bashio::log.warning "Moving birdnet.db to /config/birdnet.db"
|
||||
mv /data/birdnet.db /config
|
||||
fi
|
||||
|
||||
######################
|
||||
@@ -29,7 +29,7 @@ CURRENT_BIRDSONGS_FOLDER="${CURRENT_BIRDSONGS_FOLDER:-$DEFAULT_BIRDSONGS_FOLDER}
|
||||
|
||||
# Adjust default path if it matches the default string
|
||||
if [[ "$CURRENT_BIRDSONGS_FOLDER" == "clips/" ]]; then
|
||||
CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER"
|
||||
CURRENT_BIRDSONGS_FOLDER="$DEFAULT_BIRDSONGS_FOLDER"
|
||||
fi
|
||||
|
||||
# Set the new birdsongs folder
|
||||
@@ -37,59 +37,59 @@ BIRDSONGS_FOLDER="$(bashio::config "BIRDSONGS_FOLDER")"
|
||||
BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER:-clips/}"
|
||||
BIRDSONGS_FOLDER="${BIRDSONGS_FOLDER%/}" # Remove trailing slash if present
|
||||
if [[ ! "$BIRDSONGS_FOLDER" == /* ]]; then
|
||||
if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then
|
||||
mkdir -p "/config/$BIRDSONGS_FOLDER"
|
||||
fi
|
||||
if [ -d "/data/$BIRDSONGS_FOLDER" ]; then
|
||||
if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2>/dev/null)" ]; then
|
||||
cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/
|
||||
fi
|
||||
rm -r "/data/$BIRDSONGS_FOLDER"
|
||||
fi
|
||||
ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER"
|
||||
if [ ! -d "/config/$BIRDSONGS_FOLDER" ]; then
|
||||
mkdir -p "/config/$BIRDSONGS_FOLDER"
|
||||
fi
|
||||
if [ -d "/data/$BIRDSONGS_FOLDER" ]; then
|
||||
if [ -n "$(ls -A /data/"$BIRDSONGS_FOLDER" 2> /dev/null)" ]; then
|
||||
cp -rf /data/"$BIRDSONGS_FOLDER"/* "/config/$BIRDSONGS_FOLDER"/
|
||||
fi
|
||||
rm -r "/data/$BIRDSONGS_FOLDER"
|
||||
fi
|
||||
ln -sf "/config/$BIRDSONGS_FOLDER" "/data/$BIRDSONGS_FOLDER"
|
||||
fi
|
||||
|
||||
bashio::log.info "... audio clips saved to $BIRDSONGS_FOLDER according to addon options"
|
||||
|
||||
# Migrate data if the folder has changed
|
||||
if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then
|
||||
bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
|
||||
# Update config files with the new birdsongs folder path
|
||||
yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION"
|
||||
# Move files only if sqlite paths changed
|
||||
if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then
|
||||
bashio::log.warning "Migrating files from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
|
||||
cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/
|
||||
mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated"
|
||||
fi
|
||||
# Adapt the database
|
||||
if [ -f /config/birdnet.db ]; then
|
||||
# Prepare
|
||||
backup="$(date +%Y%m%d_%H%M%S)"
|
||||
bashio::log.warning "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup named birdnet.db_$backup will be created before"
|
||||
bashio::log.warning "Birdsongs folder changed from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
|
||||
# Update config files with the new birdsongs folder path
|
||||
yq -i -y ".realtime.audio.export.path = \"$BIRDSONGS_FOLDER/\"" "$CONFIG_LOCATION"
|
||||
# Move files only if sqlite paths changed
|
||||
if [[ -d "$CURRENT_BIRDSONGS_FOLDER" && "$(ls -A "$CURRENT_BIRDSONGS_FOLDER")" ]]; then
|
||||
bashio::log.warning "Migrating files from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER"
|
||||
cp -rnf "$CURRENT_BIRDSONGS_FOLDER"/* "$BIRDSONGS_FOLDER"/
|
||||
mv "${CURRENT_BIRDSONGS_FOLDER%/}" "${CURRENT_BIRDSONGS_FOLDER%/}_migrated"
|
||||
fi
|
||||
# Adapt the database
|
||||
if [ -f /config/birdnet.db ]; then
|
||||
# Prepare
|
||||
backup="$(date +%Y%m%d_%H%M%S)"
|
||||
bashio::log.warning "Modifying database paths from $CURRENT_BIRDSONGS_FOLDER to $BIRDSONGS_FOLDER. A backup named birdnet.db_$backup will be created before"
|
||||
|
||||
# Create backup
|
||||
if ! cp /config/birdnet.db "birdnet.db_$backup"; then
|
||||
bashio::log.error "Failed to create a backup of the database. Aborting path modification."
|
||||
exit 1
|
||||
fi
|
||||
# Create backup
|
||||
if ! cp /config/birdnet.db "birdnet.db_$backup"; then
|
||||
bashio::log.error "Failed to create a backup of the database. Aborting path modification."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Execute the query using sqlite3
|
||||
SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';"
|
||||
# Execute the query using sqlite3
|
||||
SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';"
|
||||
|
||||
if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then
|
||||
bashio::log.warning "An error occurred while updating the paths. The database backup will be restored."
|
||||
BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename
|
||||
if [ -f "$BACKUP_FILE" ]; then
|
||||
mv "$BACKUP_FILE" /config/birdnet.db
|
||||
bashio::log.info "The database backup has been restored."
|
||||
else
|
||||
bashio::log.error "Backup file not found! Manual intervention required."
|
||||
fi
|
||||
else
|
||||
echo "Paths have been successfully updated."
|
||||
fi
|
||||
fi
|
||||
if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then
|
||||
bashio::log.warning "An error occurred while updating the paths. The database backup will be restored."
|
||||
BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename
|
||||
if [ -f "$BACKUP_FILE" ]; then
|
||||
mv "$BACKUP_FILE" /config/birdnet.db
|
||||
bashio::log.info "The database backup has been restored."
|
||||
else
|
||||
bashio::log.error "Backup file not found! Manual intervention required."
|
||||
fi
|
||||
else
|
||||
echo "Paths have been successfully updated."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
####################
|
||||
|
||||
@@ -5,12 +5,12 @@ set -e
|
||||
# Gives mariadb information
|
||||
|
||||
if bashio::services.available 'mysql'; then
|
||||
bashio::log.green "---"
|
||||
bashio::log.yellow "MariaDB addon is active on your system! If you want to use it instead of sqlite, here are the informations to encode :"
|
||||
bashio::log.blue "Database user : $(bashio::services "mysql" "username")"
|
||||
bashio::log.blue "Database password : $(bashio::services "mysql" "password")"
|
||||
bashio::log.blue "Database name : birdnet"
|
||||
bashio::log.blue "Host-name : $(bashio::services "mysql" "host")"
|
||||
bashio::log.blue "Port : $(bashio::services "mysql" "port")"
|
||||
bashio::log.green "---"
|
||||
bashio::log.green "---"
|
||||
bashio::log.yellow "MariaDB addon is active on your system! If you want to use it instead of sqlite, here are the informations to encode :"
|
||||
bashio::log.blue "Database user : $(bashio::services "mysql" "username")"
|
||||
bashio::log.blue "Database password : $(bashio::services "mysql" "password")"
|
||||
bashio::log.blue "Database name : birdnet"
|
||||
bashio::log.blue "Host-name : $(bashio::services "mysql" "host")"
|
||||
bashio::log.blue "Port : $(bashio::services "mysql" "port")"
|
||||
bashio::log.green "---"
|
||||
fi
|
||||
|
||||
@@ -5,10 +5,10 @@ set -e
|
||||
# Gives mqtt information
|
||||
|
||||
if bashio::services.available 'mqtt'; then
|
||||
bashio::log.green "---"
|
||||
bashio::log.yellow "MQTT addon is active on your system! Add the MQTT details below to the Birdnet-go config.yaml :"
|
||||
bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")"
|
||||
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")"
|
||||
bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
|
||||
bashio::log.green "---"
|
||||
bashio::log.green "---"
|
||||
bashio::log.yellow "MQTT addon is active on your system! Add the MQTT details below to the Birdnet-go config.yaml :"
|
||||
bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")"
|
||||
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")"
|
||||
bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
|
||||
bashio::log.green "---"
|
||||
fi
|
||||
|
||||
@@ -10,12 +10,12 @@ bashio::log.info "ALSA_CARD option is set to $(bashio::config "ALSA_CARD"). If t
|
||||
echo " "
|
||||
|
||||
# Adjust microphone volume if needed
|
||||
if command -v amixer >/dev/null 2>/dev/null; then
|
||||
current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2>/dev/null || echo "100")" || true
|
||||
if [[ "$current_volume" -eq 0 ]]; then
|
||||
amixer sset Capture 70%
|
||||
bashio::log.warning "Microphone was off, volume set to 70%."
|
||||
fi || true
|
||||
if command -v amixer > /dev/null 2> /dev/null; then
|
||||
current_volume="$(amixer sget Capture | grep -oP '\[\d+%\]' | tr -d '[]%' | head -1 2> /dev/null || echo "100")" || true
|
||||
if [[ "$current_volume" -eq 0 ]]; then
|
||||
amixer sset Capture 70%
|
||||
bashio::log.warning "Microphone was off, volume set to 70%."
|
||||
fi || true
|
||||
fi
|
||||
|
||||
########################
|
||||
|
||||
@@ -6,7 +6,7 @@ chown pi:pi /config
|
||||
|
||||
# Waiting for dbus
|
||||
until [[ -e /var/run/dbus/system_bus_socket ]]; do
|
||||
sleep 1s
|
||||
sleep 1s
|
||||
done
|
||||
|
||||
TZ_VALUE="$(timedatectl show -p Timezone --value)"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# shellcheck shell=bash
|
||||
# Waiting for dbus
|
||||
until [[ -e /var/run/dbus/system_bus_socket ]]; do
|
||||
sleep 1s
|
||||
sleep 1s
|
||||
done
|
||||
|
||||
TZ_VALUE="$(timedatectl show -p Timezone --value)"
|
||||
@@ -10,4 +10,4 @@ export TZ="$TZ_VALUE"
|
||||
|
||||
echo "Starting service: avahi daemon"
|
||||
exec \
|
||||
avahi-daemon --no-chroot
|
||||
avahi-daemon --no-chroot
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
# Dependencies
|
||||
sockfile="empty"
|
||||
until [[ -e /var/run/dbus/system_bus_socket ]] && [[ -e "$sockfile" ]]; do
|
||||
sleep 1s
|
||||
sockfile="$(find /run/php -name "*.sock")"
|
||||
sleep 1s
|
||||
sockfile="$(find /run/php -name "*.sock")"
|
||||
done
|
||||
|
||||
# Correct fpm.sock
|
||||
@@ -19,7 +19,7 @@ TZ_VALUE="$(timedatectl show -p Timezone --value)"
|
||||
export TZ="$TZ_VALUE"
|
||||
|
||||
# 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"
|
||||
/usr/bin/caddy run --config /etc/caddy/Caddyfile
|
||||
|
||||
@@ -36,8 +36,8 @@ BIRDSONGS_DIR="$(readlink -f "$HOME/BirdSongs/Extracted/By_Date")"
|
||||
|
||||
# Ensure directories and set permissions
|
||||
mkdir -p "$INGEST_DIR" || {
|
||||
log_red "Failed to create directory: $INGEST_DIR"
|
||||
exit 1
|
||||
log_red "Failed to create directory: $INGEST_DIR"
|
||||
exit 1
|
||||
}
|
||||
chown -R pi:pi "$INGEST_DIR" || log_yellow "Could not change ownership for $INGEST_DIR"
|
||||
chmod -R 755 "$INGEST_DIR" || log_yellow "Could not set permissions for $INGEST_DIR"
|
||||
@@ -61,71 +61,71 @@ DISK_USAGE_THRESHOLD=95
|
||||
same_file_counter=0
|
||||
SAME_FILE_THRESHOLD=2
|
||||
if [[ -f "$ANALYZING_NOW_FILE" ]]; then
|
||||
analyzing_now=$(<"$ANALYZING_NOW_FILE")
|
||||
analyzing_now=$(< "$ANALYZING_NOW_FILE")
|
||||
else
|
||||
analyzing_now=""
|
||||
analyzing_now=""
|
||||
fi
|
||||
|
||||
########################################
|
||||
# Notification Functions
|
||||
########################################
|
||||
apprisealert() {
|
||||
local issue_message="$1"
|
||||
local current_time
|
||||
current_time=$(date +%s)
|
||||
local issue_message="$1"
|
||||
local current_time
|
||||
current_time=$(date +%s)
|
||||
|
||||
# Calculate time_diff in minutes since last notification
|
||||
local time_diff=$(((current_time - last_notification_time) / 60))
|
||||
# Calculate time_diff in minutes since last notification
|
||||
local time_diff=$(((current_time - last_notification_time) / 60))
|
||||
|
||||
# Throttle notifications
|
||||
if ((time_diff < NOTIFICATION_INTERVAL_IN_MINUTES)); then
|
||||
log_yellow "Notification suppressed (last sent ${time_diff} minutes ago)."
|
||||
return
|
||||
fi
|
||||
# Throttle notifications
|
||||
if ((time_diff < NOTIFICATION_INTERVAL_IN_MINUTES)); then
|
||||
log_yellow "Notification suppressed (last sent ${time_diff} minutes ago)."
|
||||
return
|
||||
fi
|
||||
|
||||
local stopped_service="<br><b>Stopped services:</b> "
|
||||
for service in "${SERVICES[@]}"; do
|
||||
if [[ "$(systemctl is-active "$service")" != "active" ]]; then
|
||||
stopped_service+="$service; "
|
||||
fi
|
||||
done
|
||||
local stopped_service="<br><b>Stopped services:</b> "
|
||||
for service in "${SERVICES[@]}"; do
|
||||
if [[ "$(systemctl is-active "$service")" != "active" ]]; then
|
||||
stopped_service+="$service; "
|
||||
fi
|
||||
done
|
||||
|
||||
local notification="<b>Issue:</b> $issue_message"
|
||||
notification+="$stopped_service"
|
||||
notification+="<br><b>System:</b> ${SITE_NAME:-$(hostname)}"
|
||||
notification+="<br>Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')"
|
||||
notification+="<br>----Last log lines----"
|
||||
notification+="<br> $(timeout 15 cat /proc/1/fd/1 | head -n 5)"
|
||||
notification+="<br>----------------------"
|
||||
[[ -n "$BIRDNETPI_URL" ]] && notification+="<br><a href=\"$BIRDNETPI_URL\">Access your BirdNET-Pi</a>"
|
||||
local notification="<b>Issue:</b> $issue_message"
|
||||
notification+="$stopped_service"
|
||||
notification+="<br><b>System:</b> ${SITE_NAME:-$(hostname)}"
|
||||
notification+="<br>Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')"
|
||||
notification+="<br>----Last log lines----"
|
||||
notification+="<br> $(timeout 15 cat /proc/1/fd/1 | head -n 5)"
|
||||
notification+="<br>----------------------"
|
||||
[[ -n "$BIRDNETPI_URL" ]] && notification+="<br><a href=\"$BIRDNETPI_URL\">Access your BirdNET-Pi</a>"
|
||||
|
||||
local TITLE="BirdNET-Analyzer Alert"
|
||||
if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then
|
||||
"$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \
|
||||
--input-format=html --config="$HOME/BirdNET-Pi/apprise.txt"
|
||||
last_notification_time=$current_time
|
||||
issue_reported=1
|
||||
else
|
||||
log_red "Apprise not configured or missing!"
|
||||
fi
|
||||
local TITLE="BirdNET-Analyzer Alert"
|
||||
if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then
|
||||
"$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \
|
||||
--input-format=html --config="$HOME/BirdNET-Pi/apprise.txt"
|
||||
last_notification_time=$current_time
|
||||
issue_reported=1
|
||||
else
|
||||
log_red "Apprise not configured or missing!"
|
||||
fi
|
||||
}
|
||||
|
||||
apprisealert_recovery() {
|
||||
# Only send a recovery message if we had previously reported an issue
|
||||
if ((issue_reported == 1)); then
|
||||
log_green "$(date) INFO: System is back to normal. Sending recovery notification."
|
||||
# Only send a recovery message if we had previously reported an issue
|
||||
if ((issue_reported == 1)); then
|
||||
log_green "$(date) INFO: System is back to normal. Sending recovery notification."
|
||||
|
||||
local TITLE="BirdNET-Pi System Recovered"
|
||||
local notification="<b>All monitored services are back to normal.</b><br>"
|
||||
notification+="<b>System:</b> ${SITE_NAME:-$(hostname)}<br>"
|
||||
notification+="Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')"
|
||||
local TITLE="BirdNET-Pi System Recovered"
|
||||
local notification="<b>All monitored services are back to normal.</b><br>"
|
||||
notification+="<b>System:</b> ${SITE_NAME:-$(hostname)}<br>"
|
||||
notification+="Available disk space: $(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $4}')"
|
||||
|
||||
if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then
|
||||
"$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \
|
||||
--input-format=html --config="$HOME/BirdNET-Pi/apprise.txt"
|
||||
fi
|
||||
issue_reported=0
|
||||
fi
|
||||
if [[ -f "$HOME/BirdNET-Pi/birdnet/bin/apprise" && -s "$HOME/BirdNET-Pi/apprise.txt" ]]; then
|
||||
"$HOME/BirdNET-Pi/birdnet/bin/apprise" -vv -t "$TITLE" -b "$notification" \
|
||||
--input-format=html --config="$HOME/BirdNET-Pi/apprise.txt"
|
||||
fi
|
||||
issue_reported=0
|
||||
fi
|
||||
}
|
||||
|
||||
########################################
|
||||
@@ -133,115 +133,115 @@ apprisealert_recovery() {
|
||||
########################################
|
||||
|
||||
check_disk_space() {
|
||||
local current_usage
|
||||
current_usage=$(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $5}' | sed 's/%//')
|
||||
local current_usage
|
||||
current_usage=$(df -h "$BIRDSONGS_DIR" | awk 'NR==2 {print $5}' | sed 's/%//')
|
||||
|
||||
if ((current_usage >= DISK_USAGE_THRESHOLD)); then
|
||||
log_red "$(date) INFO: Disk usage is at ${current_usage}% (CRITICAL!)"
|
||||
apprisealert "Disk usage critical: ${current_usage}%"
|
||||
return 1
|
||||
else
|
||||
log_green "$(date) INFO: Disk usage is within acceptable limits (${current_usage}%)."
|
||||
return 0
|
||||
fi
|
||||
if ((current_usage >= DISK_USAGE_THRESHOLD)); then
|
||||
log_red "$(date) INFO: Disk usage is at ${current_usage}% (CRITICAL!)"
|
||||
apprisealert "Disk usage critical: ${current_usage}%"
|
||||
return 1
|
||||
else
|
||||
log_green "$(date) INFO: Disk usage is within acceptable limits (${current_usage}%)."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
check_analyzing_now() {
|
||||
local current_file
|
||||
current_file=$(cat "$ANALYZING_NOW_FILE" 2>/dev/null)
|
||||
if [[ "$current_file" == "$analyzing_now" ]]; then
|
||||
((same_file_counter++))
|
||||
else
|
||||
same_file_counter=0
|
||||
analyzing_now="$current_file"
|
||||
fi
|
||||
local current_file
|
||||
current_file=$(cat "$ANALYZING_NOW_FILE" 2> /dev/null)
|
||||
if [[ "$current_file" == "$analyzing_now" ]]; then
|
||||
((same_file_counter++))
|
||||
else
|
||||
same_file_counter=0
|
||||
analyzing_now="$current_file"
|
||||
fi
|
||||
|
||||
if ((same_file_counter >= SAME_FILE_THRESHOLD)); then
|
||||
log_red "$(date) INFO: 'analyzing_now' file unchanged for $SAME_FILE_THRESHOLD iterations."
|
||||
apprisealert "No change in analyzing_now for ${SAME_FILE_THRESHOLD} iterations"
|
||||
"$HOME/BirdNET-Pi/scripts/restart_services.sh"
|
||||
same_file_counter=0
|
||||
return 1
|
||||
else
|
||||
# Only log if it changed this iteration
|
||||
if ((same_file_counter == 0)); then
|
||||
log_green "$(date) INFO: 'analyzing_now' file has been updated."
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
if ((same_file_counter >= SAME_FILE_THRESHOLD)); then
|
||||
log_red "$(date) INFO: 'analyzing_now' file unchanged for $SAME_FILE_THRESHOLD iterations."
|
||||
apprisealert "No change in analyzing_now for ${SAME_FILE_THRESHOLD} iterations"
|
||||
"$HOME/BirdNET-Pi/scripts/restart_services.sh"
|
||||
same_file_counter=0
|
||||
return 1
|
||||
else
|
||||
# Only log if it changed this iteration
|
||||
if ((same_file_counter == 0)); then
|
||||
log_green "$(date) INFO: 'analyzing_now' file has been updated."
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
check_queue() {
|
||||
local wav_count
|
||||
wav_count=$(find -L "$INGEST_DIR" -maxdepth 1 -name '*.wav' | wc -l)
|
||||
local wav_count
|
||||
wav_count=$(find -L "$INGEST_DIR" -maxdepth 1 -name '*.wav' | wc -l)
|
||||
|
||||
log_green "$(date) INFO: Queue is at a manageable level (${wav_count} wav files)."
|
||||
log_green "$(date) INFO: Queue is at a manageable level (${wav_count} wav files)."
|
||||
|
||||
if ((wav_count > 50)); then
|
||||
log_red "$(date) INFO: Queue >50. Stopping recorder + restarting analyzer."
|
||||
apprisealert "Queue exceeded 50: stopping recorder, restarting analyzer."
|
||||
sudo systemctl stop birdnet_recording
|
||||
sudo systemctl restart birdnet_analysis
|
||||
return 1
|
||||
elif ((wav_count > 30)); then
|
||||
log_red "$(date) INFO: Queue >30. Restarting analyzer."
|
||||
apprisealert "Queue exceeded 30: restarting analyzer."
|
||||
sudo systemctl restart birdnet_analysis
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
if ((wav_count > 50)); then
|
||||
log_red "$(date) INFO: Queue >50. Stopping recorder + restarting analyzer."
|
||||
apprisealert "Queue exceeded 50: stopping recorder, restarting analyzer."
|
||||
sudo systemctl stop birdnet_recording
|
||||
sudo systemctl restart birdnet_analysis
|
||||
return 1
|
||||
elif ((wav_count > 30)); then
|
||||
log_red "$(date) INFO: Queue >30. Restarting analyzer."
|
||||
apprisealert "Queue exceeded 30: restarting analyzer."
|
||||
sudo systemctl restart birdnet_analysis
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
check_services() {
|
||||
local any_inactive=0
|
||||
local any_inactive=0
|
||||
|
||||
for service in "${SERVICES[@]}"; do
|
||||
if [[ "$(systemctl is-active "$service")" != "active" ]]; then
|
||||
SERVICE_INACTIVE_COUNT["$service"]=$((SERVICE_INACTIVE_COUNT["$service"] + 1))
|
||||
for service in "${SERVICES[@]}"; do
|
||||
if [[ "$(systemctl is-active "$service")" != "active" ]]; then
|
||||
SERVICE_INACTIVE_COUNT["$service"]=$((SERVICE_INACTIVE_COUNT["$service"] + 1))
|
||||
|
||||
if ((SERVICE_INACTIVE_COUNT["$service"] == 1)); then
|
||||
# First time inactive => Try to start
|
||||
log_yellow "$(date) INFO: Service '$service' is inactive. Attempting to start..."
|
||||
systemctl start "$service"
|
||||
any_inactive=1
|
||||
elif ((SERVICE_INACTIVE_COUNT["$service"] == 2)); then
|
||||
# Second consecutive time => Send an alert
|
||||
log_red "$(date) INFO: Service '$service' is still inactive after restart attempt."
|
||||
apprisealert "Service '$service' remains inactive after restart attempt."
|
||||
any_inactive=1
|
||||
else
|
||||
# Beyond second check => keep logging or do advanced actions
|
||||
log_red "$(date) INFO: Service '$service' inactive for ${SERVICE_INACTIVE_COUNT["$service"]} checks in a row."
|
||||
any_inactive=1
|
||||
fi
|
||||
else
|
||||
# Service is active => reset counter
|
||||
if ((SERVICE_INACTIVE_COUNT["$service"] > 0)); then
|
||||
log_green "$(date) INFO: Service '$service' is back to active. Resetting counter."
|
||||
fi
|
||||
SERVICE_INACTIVE_COUNT["$service"]=0
|
||||
fi
|
||||
done
|
||||
if ((SERVICE_INACTIVE_COUNT["$service"] == 1)); then
|
||||
# First time inactive => Try to start
|
||||
log_yellow "$(date) INFO: Service '$service' is inactive. Attempting to start..."
|
||||
systemctl start "$service"
|
||||
any_inactive=1
|
||||
elif ((SERVICE_INACTIVE_COUNT["$service"] == 2)); then
|
||||
# Second consecutive time => Send an alert
|
||||
log_red "$(date) INFO: Service '$service' is still inactive after restart attempt."
|
||||
apprisealert "Service '$service' remains inactive after restart attempt."
|
||||
any_inactive=1
|
||||
else
|
||||
# Beyond second check => keep logging or do advanced actions
|
||||
log_red "$(date) INFO: Service '$service' inactive for ${SERVICE_INACTIVE_COUNT["$service"]} checks in a row."
|
||||
any_inactive=1
|
||||
fi
|
||||
else
|
||||
# Service is active => reset counter
|
||||
if ((SERVICE_INACTIVE_COUNT["$service"] > 0)); then
|
||||
log_green "$(date) INFO: Service '$service' is back to active. Resetting counter."
|
||||
fi
|
||||
SERVICE_INACTIVE_COUNT["$service"]=0
|
||||
fi
|
||||
done
|
||||
|
||||
if ((any_inactive == 0)); then
|
||||
log_green "$(date) INFO: All services are active"
|
||||
return 0
|
||||
else
|
||||
log_red "$(date) INFO: One or more services are inactive"
|
||||
return 1
|
||||
fi
|
||||
if ((any_inactive == 0)); then
|
||||
log_green "$(date) INFO: All services are active"
|
||||
return 0
|
||||
else
|
||||
log_red "$(date) INFO: One or more services are inactive"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_for_empty_stream() {
|
||||
local log_tail
|
||||
log_tail=$(timeout 15 cat /proc/1/fd/1 | tail -n 5)
|
||||
local log_tail
|
||||
log_tail=$(timeout 15 cat /proc/1/fd/1 | tail -n 5)
|
||||
|
||||
if echo "$log_tail" | grep -q "Haliastur indus"; then
|
||||
log_red "$(date) INFO: Potential empty stream detected (frequent 'Haliastur indus')."
|
||||
apprisealert "Potential empty stream detected — frequent 'Haliastur indus' in log"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
if echo "$log_tail" | grep -q "Haliastur indus"; then
|
||||
log_red "$(date) INFO: Potential empty stream detected (frequent 'Haliastur indus')."
|
||||
apprisealert "Potential empty stream detected — frequent 'Haliastur indus' in log"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
########################################
|
||||
@@ -251,32 +251,32 @@ TZ_VALUE="$(timedatectl show -p Timezone --value)"
|
||||
export TZ="$TZ_VALUE"
|
||||
|
||||
while true; do
|
||||
sleep 61
|
||||
log_blue "----------------------------------------"
|
||||
log_blue "$(date) INFO: Starting monitoring check"
|
||||
any_issue=0
|
||||
sleep 61
|
||||
log_blue "----------------------------------------"
|
||||
log_blue "$(date) INFO: Starting monitoring check"
|
||||
any_issue=0
|
||||
|
||||
# 1) Disk usage
|
||||
check_disk_space || any_issue=1
|
||||
# 1) Disk usage
|
||||
check_disk_space || any_issue=1
|
||||
|
||||
# 2) 'analyzing_now' file
|
||||
check_analyzing_now || any_issue=1
|
||||
# 2) 'analyzing_now' file
|
||||
check_analyzing_now || any_issue=1
|
||||
|
||||
# 3) Queue check
|
||||
check_queue || any_issue=1
|
||||
# 3) Queue check
|
||||
check_queue || any_issue=1
|
||||
|
||||
# 4) Services check
|
||||
check_services || any_issue=1
|
||||
# 4) Services check
|
||||
check_services || any_issue=1
|
||||
|
||||
# 5) Check for potential empty stream
|
||||
check_for_empty_stream || any_issue=1
|
||||
# 5) Check for potential empty stream
|
||||
check_for_empty_stream || any_issue=1
|
||||
|
||||
# Final summary
|
||||
if ((any_issue == 0)); then
|
||||
log_green "$(date) INFO: All systems are functioning normally"
|
||||
apprisealert_recovery
|
||||
else
|
||||
log_red "$(date) INFO: Issues detected. System status is not fully operational."
|
||||
fi
|
||||
log_blue "----------------------------------------"
|
||||
# Final summary
|
||||
if ((any_issue == 0)); then
|
||||
log_green "$(date) INFO: All systems are functioning normally"
|
||||
apprisealert_recovery
|
||||
else
|
||||
log_red "$(date) INFO: Issues detected. System status is not fully operational."
|
||||
fi
|
||||
log_blue "----------------------------------------"
|
||||
done
|
||||
|
||||
@@ -6,46 +6,46 @@ MAX_SIZE=$((50 * 1024 * 1024))
|
||||
|
||||
# Function to check if a file is a valid WAV
|
||||
is_valid_wav() {
|
||||
local file="$1"
|
||||
# Check if the file contains a valid WAV header
|
||||
file "$file" | grep -qE 'WAVE audio'
|
||||
local file="$1"
|
||||
# Check if the file contains a valid WAV header
|
||||
file "$file" | grep -qE 'WAVE audio'
|
||||
}
|
||||
|
||||
if [ -d "$HOME"/BirdSongs/StreamData ]; then
|
||||
bashio::log.fatal "Container stopping, saving temporary files."
|
||||
bashio::log.fatal "Container stopping, saving temporary files."
|
||||
|
||||
# Stop the services in parallel
|
||||
if systemctl is-active --quiet birdnet_analysis; then
|
||||
bashio::log.info "Stopping birdnet_analysis service."
|
||||
systemctl stop birdnet_analysis &
|
||||
fi
|
||||
# Stop the services in parallel
|
||||
if systemctl is-active --quiet birdnet_analysis; then
|
||||
bashio::log.info "Stopping birdnet_analysis service."
|
||||
systemctl stop birdnet_analysis &
|
||||
fi
|
||||
|
||||
if systemctl is-active --quiet birdnet_recording; then
|
||||
bashio::log.info "Stopping birdnet_recording service."
|
||||
systemctl stop birdnet_recording &
|
||||
fi
|
||||
if systemctl is-active --quiet birdnet_recording; then
|
||||
bashio::log.info "Stopping birdnet_recording service."
|
||||
systemctl stop birdnet_recording &
|
||||
fi
|
||||
|
||||
# Wait for both services to stop
|
||||
wait
|
||||
# Wait for both services to stop
|
||||
wait
|
||||
|
||||
# Create the destination directory
|
||||
mkdir -p /config/TemporaryFiles
|
||||
# Create the destination directory
|
||||
mkdir -p /config/TemporaryFiles
|
||||
|
||||
# Move only valid WAV files under 50MB
|
||||
shopt -s nullglob # Prevent errors if no files match
|
||||
for file in "$HOME"/BirdSongs/StreamData/*.wav; do
|
||||
if [ -f "$file" ] && [ "$(stat --format="%s" "$file")" -lt "$MAX_SIZE" ] && is_valid_wav "$file"; then
|
||||
if mv -v "$file" /config/TemporaryFiles/; then
|
||||
bashio::log.info "Moved valid WAV file: $(basename "$file")"
|
||||
else
|
||||
bashio::log.error "Failed to move: $(basename "$file")"
|
||||
fi
|
||||
else
|
||||
bashio::log.warning "Skipping invalid or large file: $(basename "$file")"
|
||||
fi
|
||||
done
|
||||
# Move only valid WAV files under 50MB
|
||||
shopt -s nullglob # Prevent errors if no files match
|
||||
for file in "$HOME"/BirdSongs/StreamData/*.wav; do
|
||||
if [ -f "$file" ] && [ "$(stat --format="%s" "$file")" -lt "$MAX_SIZE" ] && is_valid_wav "$file"; then
|
||||
if mv -v "$file" /config/TemporaryFiles/; then
|
||||
bashio::log.info "Moved valid WAV file: $(basename "$file")"
|
||||
else
|
||||
bashio::log.error "Failed to move: $(basename "$file")"
|
||||
fi
|
||||
else
|
||||
bashio::log.warning "Skipping invalid or large file: $(basename "$file")"
|
||||
fi
|
||||
done
|
||||
|
||||
bashio::log.info "... files safe, allowing container to stop."
|
||||
bashio::log.info "... files safe, allowing container to stop."
|
||||
else
|
||||
bashio::log.info "No StreamData directory to process."
|
||||
bashio::log.info "No StreamData directory to process."
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
###############
|
||||
@@ -23,24 +23,24 @@ bashio::log.info "Ensuring the file structure is correct:"
|
||||
echo "... creating default files"
|
||||
DEFAULT_FILES=("apprise.txt" "exclude_species_list.txt" "IdentifiedSoFar.txt" "disk_check_exclude.txt" "confirmed_species_list.txt" "blacklisted_images.txt" "whitelist_species_list.txt")
|
||||
for file in "${DEFAULT_FILES[@]}"; do
|
||||
if [ ! -f "/config/$file" ]; then
|
||||
echo "" >"/config/$file"
|
||||
fi
|
||||
if [ ! -f "/config/$file" ]; then
|
||||
echo "" > "/config/$file"
|
||||
fi
|
||||
done
|
||||
touch /config/include_species_list.txt # Ensure this is always created
|
||||
|
||||
# Set BirdSongs folder location from configuration if specified
|
||||
BIRDSONGS_FOLDER="/config/BirdSongs"
|
||||
if bashio::config.has_value "BIRDSONGS_FOLDER"; then
|
||||
BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")"
|
||||
echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION"
|
||||
mkdir -p "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be created"
|
||||
chown -R pi:pi "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be given permissions for 1000:1000"
|
||||
if [ -d "$BIRDSONGS_FOLDER_OPTION" ] && [ "$(stat -c '%u:%g' "$BIRDSONGS_FOLDER_OPTION")" == "1000:1000" ]; then
|
||||
BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION"
|
||||
else
|
||||
bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs"
|
||||
fi
|
||||
BIRDSONGS_FOLDER_OPTION="$(bashio::config "BIRDSONGS_FOLDER")"
|
||||
echo "... BIRDSONGS_FOLDER set to $BIRDSONGS_FOLDER_OPTION"
|
||||
mkdir -p "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be created"
|
||||
chown -R pi:pi "$BIRDSONGS_FOLDER_OPTION" || bashio::log.fatal "...... folder couldn't be given permissions for 1000:1000"
|
||||
if [ -d "$BIRDSONGS_FOLDER_OPTION" ] && [ "$(stat -c '%u:%g' "$BIRDSONGS_FOLDER_OPTION")" == "1000:1000" ]; then
|
||||
BIRDSONGS_FOLDER="$BIRDSONGS_FOLDER_OPTION"
|
||||
else
|
||||
bashio::log.warning "BIRDSONGS_FOLDER reverted to /config/BirdSongs"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create default folders
|
||||
@@ -49,12 +49,12 @@ mkdir -p "$BIRDSONGS_FOLDER/By_Date" "$BIRDSONGS_FOLDER/Charts"
|
||||
|
||||
# Use tmpfs if installed
|
||||
if df -T /tmp | grep -q "tmpfs"; then
|
||||
echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear"
|
||||
mkdir -p /tmp/StreamData /tmp/Processed
|
||||
[ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData"
|
||||
[ -d "$HOME/BirdSongs/Processed" ] && rm -r "$HOME/BirdSongs/Processed"
|
||||
sudo -u pi ln -fs /tmp/StreamData "$HOME/BirdSongs/StreamData"
|
||||
sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed"
|
||||
echo "... tmpfs detected, using it for StreamData and Processed to reduce disk wear"
|
||||
mkdir -p /tmp/StreamData /tmp/Processed
|
||||
[ -d "$HOME/BirdSongs/StreamData" ] && rm -r "$HOME/BirdSongs/StreamData"
|
||||
[ -d "$HOME/BirdSongs/Processed" ] && rm -r "$HOME/BirdSongs/Processed"
|
||||
sudo -u pi ln -fs /tmp/StreamData "$HOME/BirdSongs/StreamData"
|
||||
sudo -u pi ln -fs /tmp/Processed "$HOME/BirdSongs/Processed"
|
||||
fi
|
||||
|
||||
# Set permissions for created files and folders
|
||||
@@ -67,19 +67,19 @@ cp "$HOME/BirdNET-Pi/birdnet.conf" "$HOME/BirdNET-Pi/birdnet.bak"
|
||||
|
||||
# Create default birdnet.conf if not existing
|
||||
if [ ! -f /config/birdnet.conf ]; then
|
||||
cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/
|
||||
cp -f "$HOME/BirdNET-Pi/birdnet.conf" /config/
|
||||
fi
|
||||
|
||||
# Create default birds.db
|
||||
if [ ! -f /config/birds.db ]; then
|
||||
echo "... creating initial db"
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
echo "... creating initial db"
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
elif [ "$(stat -c%s /config/birds.db)" -lt 10240 ]; then
|
||||
echo "... your db is corrupted, creating new one"
|
||||
rm /config/birds.db
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
echo "... your db is corrupted, creating new one"
|
||||
rm /config/birds.db
|
||||
"$HOME/BirdNET-Pi/scripts/createdb.sh"
|
||||
cp "$HOME/BirdNET-Pi/scripts/birds.db" /config/
|
||||
fi
|
||||
|
||||
# Symlink configuration files
|
||||
@@ -87,12 +87,12 @@ echo "... creating symlinks for configuration files"
|
||||
CONFIG_FILES=("$HOME/BirdNET-Pi/birdnet.conf" "$HOME/BirdNET-Pi/scripts/whitelist_species_list.txt" "$HOME/BirdNET-Pi/blacklisted_images.txt" "$HOME/BirdNET-Pi/scripts/birds.db" "$HOME/BirdNET-Pi/BirdDB.txt" "$HOME/BirdNET-Pi/scripts/disk_check_exclude.txt" "$HOME/BirdNET-Pi/apprise.txt" "$HOME/BirdNET-Pi/exclude_species_list.txt" "$HOME/BirdNET-Pi/include_species_list.txt" "$HOME/BirdNET-Pi/IdentifiedSoFar.txt" "$HOME/BirdNET-Pi/scripts/confirmed_species_list.txt")
|
||||
|
||||
for file in "${CONFIG_FILES[@]}"; do
|
||||
filename="${file##*/}"
|
||||
[ ! -f "/config/$filename" ] && touch "/config/$filename"
|
||||
[ -e "$file" ] && rm "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$HOME/BirdNET-Pi/scripts/$filename"
|
||||
sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename"
|
||||
filename="${file##*/}"
|
||||
[ ! -f "/config/$filename" ] && touch "/config/$filename"
|
||||
[ -e "$file" ] && rm "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$file"
|
||||
sudo -u pi ln -fs "/config/$filename" "$HOME/BirdNET-Pi/scripts/$filename"
|
||||
sudo -u pi ln -fs "/config/$filename" "/etc/birdnet/$filename"
|
||||
done
|
||||
|
||||
# Create thisrun.txt for legacy modes
|
||||
@@ -106,9 +106,9 @@ chown pi:pi /usr/local/bin/*
|
||||
|
||||
# Symlink BirdSongs folders
|
||||
for folder in By_Date Charts; do
|
||||
echo "... creating symlink for $BIRDSONGS_FOLDER/$folder"
|
||||
[ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder"
|
||||
sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder"
|
||||
echo "... creating symlink for $BIRDSONGS_FOLDER/$folder"
|
||||
[ -d "$HOME/BirdSongs/Extracted/${folder:?}" ] && rm -r "$HOME/BirdSongs/Extracted/$folder"
|
||||
sudo -u pi ln -fs "$BIRDSONGS_FOLDER/$folder" "$HOME/BirdSongs/Extracted/$folder"
|
||||
done
|
||||
|
||||
# Set permissions for newly created files and folders
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
######################
|
||||
@@ -19,32 +19,32 @@ fi
|
||||
|
||||
if [ -d /config/TemporaryFiles ]; then
|
||||
|
||||
# Check if there are .wav files in /config/TemporaryFiles
|
||||
if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then
|
||||
bashio::log.warning "Container was stopped while files were still being analyzed."
|
||||
echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData."
|
||||
# Check if there are .wav files in /config/TemporaryFiles
|
||||
if find /config/TemporaryFiles -type f -name "*.wav" | grep -q .; then
|
||||
bashio::log.warning "Container was stopped while files were still being analyzed."
|
||||
echo "... restoring .wav files from /config/TemporaryFiles to $HOME/BirdSongs/StreamData."
|
||||
|
||||
# Create the destination directory if it does not exist
|
||||
mkdir -p "$HOME"/BirdSongs/StreamData
|
||||
# Create the destination directory if it does not exist
|
||||
mkdir -p "$HOME"/BirdSongs/StreamData
|
||||
|
||||
# Count the number of .wav files to be moved
|
||||
file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l)
|
||||
echo "... found $file_count .wav files to restore."
|
||||
# Count the number of .wav files to be moved
|
||||
file_count=$(find /config/TemporaryFiles -type f -name "*.wav" | wc -l)
|
||||
echo "... found $file_count .wav files to restore."
|
||||
|
||||
# Move the .wav files using `mv` to avoid double log entries
|
||||
mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/
|
||||
# Move the .wav files using `mv` to avoid double log entries
|
||||
mv -v /config/TemporaryFiles/*.wav "$HOME"/BirdSongs/StreamData/
|
||||
|
||||
# Update permissions only if files were moved successfully
|
||||
if [ "$file_count" -gt 0 ]; then
|
||||
chown -R pi:pi "$HOME"/BirdSongs/StreamData
|
||||
fi
|
||||
# Update permissions only if files were moved successfully
|
||||
if [ "$file_count" -gt 0 ]; then
|
||||
chown -R pi:pi "$HOME"/BirdSongs/StreamData
|
||||
fi
|
||||
|
||||
echo "... $file_count files restored successfully."
|
||||
else
|
||||
echo "... no .wav files found to restore."
|
||||
fi
|
||||
echo "... $file_count files restored successfully."
|
||||
else
|
||||
echo "... no .wav files found to restore."
|
||||
fi
|
||||
|
||||
# Clean up the source folder if it is empty
|
||||
rm -r /config/TemporaryFiles
|
||||
# Clean up the source folder if it is empty
|
||||
rm -r /config/TemporaryFiles
|
||||
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
######################
|
||||
@@ -25,22 +25,22 @@ configtemplate="$HOME"/BirdNET-Pi/birdnet.bak
|
||||
|
||||
# Ensure both files exist before proceeding
|
||||
if [ ! -f "$configcurrent" ] || [ ! -f "$configtemplate" ]; then
|
||||
bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present."
|
||||
exit 1
|
||||
bashio::log.fatal "Missing required birdnet.conf or birdnet.bak file. Please ensure both are present."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract variable names from config template and read each one
|
||||
grep -o '^[^#=]*=' "$configtemplate" | sed 's/=//' | while read -r var; do
|
||||
# Check if the variable is in configcurrent, if not, append it
|
||||
if ! grep -q "^$var=" "$configcurrent"; then
|
||||
bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added"
|
||||
grep "^$var=" "$configtemplate" >>"$configcurrent"
|
||||
fi
|
||||
# Check for duplicates
|
||||
if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then
|
||||
bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out except for the first one"
|
||||
sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent"
|
||||
fi
|
||||
# Check if the variable is in configcurrent, if not, append it
|
||||
if ! grep -q "^$var=" "$configcurrent"; then
|
||||
bashio::log.warning "...$var was missing from your birdnet.conf file, it was re-added"
|
||||
grep "^$var=" "$configtemplate" >> "$configcurrent"
|
||||
fi
|
||||
# Check for duplicates
|
||||
if [ "$(grep -c "^$var=" "$configcurrent")" -gt 1 ]; then
|
||||
bashio::log.error "Duplicate variable $var found in $configcurrent, all were commented out except for the first one"
|
||||
sed -i "0,/^$var=/!s/^$var=/#$var=/" "$configcurrent"
|
||||
fi
|
||||
done
|
||||
|
||||
##############
|
||||
@@ -48,8 +48,8 @@ done
|
||||
##############
|
||||
|
||||
if [[ "$(bashio::addon.port "80")" == 3000 ]]; then
|
||||
bashio::log.fatal "This is crazy but your port is set to 3000 and streamlit doesn't accept this port! You need to change it from the addon options and restart. Thanks"
|
||||
sleep infinity
|
||||
bashio::log.fatal "This is crazy but your port is set to 3000 and streamlit doesn't accept this port! You need to change it from the addon options and restart. Thanks"
|
||||
sleep infinity
|
||||
fi
|
||||
|
||||
##################
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
############
|
||||
@@ -19,66 +19,66 @@ fi
|
||||
|
||||
# Function to perform common setup steps
|
||||
common_steps() {
|
||||
# Attempt to connect to the MQTT broker
|
||||
TOPIC="birdnet"
|
||||
if mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -t "$TOPIC" -m "test" -u "$MQTT_USER" -P "$MQTT_PASS" -q 1 -d --will-topic "$TOPIC" --will-payload "Disconnected" --will-qos 1 --will-retain >/dev/null 2>&1; then
|
||||
# Adapt script with MQTT settings
|
||||
sed -i "s|%%mqtt_server%%|$MQTT_HOST|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|\"%%mqtt_port%%\"|$MQTT_PORT|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_user%%|$MQTT_USER|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_pass%%|$MQTT_PASS|g" /helpers/birdnet_to_mqtt.py
|
||||
# Attempt to connect to the MQTT broker
|
||||
TOPIC="birdnet"
|
||||
if mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -t "$TOPIC" -m "test" -u "$MQTT_USER" -P "$MQTT_PASS" -q 1 -d --will-topic "$TOPIC" --will-payload "Disconnected" --will-qos 1 --will-retain > /dev/null 2>&1; then
|
||||
# Adapt script with MQTT settings
|
||||
sed -i "s|%%mqtt_server%%|$MQTT_HOST|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|\"%%mqtt_port%%\"|$MQTT_PORT|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_user%%|$MQTT_USER|g" /helpers/birdnet_to_mqtt.py
|
||||
sed -i "s|%%mqtt_pass%%|$MQTT_PASS|g" /helpers/birdnet_to_mqtt.py
|
||||
|
||||
# Copy script to the appropriate directory
|
||||
cp /helpers/birdnet_to_mqtt.py "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chown pi:pi "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chmod +x "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
# Copy script to the appropriate directory
|
||||
cp /helpers/birdnet_to_mqtt.py "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chown pi:pi "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
chmod +x "$HOME"/BirdNET-Pi/scripts/utils/birdnet_to_mqtt.py
|
||||
|
||||
# Add hooks to the main analysis script
|
||||
sed -i "/load_global_model, run_analysis/a from utils.birdnet_to_mqtt import automatic_mqtt_publish" "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
sed -i '/write_to_db(/a\ automatic_mqtt_publish(file, detection, os.path.basename(detection.file_name_extr))' "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
else
|
||||
bashio::log.fatal "MQTT connection failed, it will not be configured"
|
||||
fi
|
||||
# Add hooks to the main analysis script
|
||||
sed -i "/load_global_model, run_analysis/a from utils.birdnet_to_mqtt import automatic_mqtt_publish" "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
sed -i '/write_to_db(/a\ automatic_mqtt_publish(file, detection, os.path.basename(detection.file_name_extr))' "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py
|
||||
else
|
||||
bashio::log.fatal "MQTT connection failed, it will not be configured"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if MQTT service is available and not disabled
|
||||
if [[ -f "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py ]] && bashio::services.available 'mqtt' && ! bashio::config.true 'MQTT_DISABLED'; then
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT addon is active on your system! Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")"
|
||||
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")"
|
||||
bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT addon is active on your system! Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
bashio::log.blue "MQTT user : $(bashio::services "mqtt" "username")"
|
||||
bashio::log.blue "MQTT password : $(bashio::services "mqtt" "password")"
|
||||
bashio::log.blue "MQTT broker : tcp://$(bashio::services "mqtt" "host"):$(bashio::services "mqtt" "port")"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
|
||||
# Apply MQTT settings
|
||||
MQTT_HOST="$(bashio::services "mqtt" "host")"
|
||||
MQTT_PORT="$(bashio::services "mqtt" "port")"
|
||||
MQTT_USER="$(bashio::services "mqtt" "username")"
|
||||
MQTT_PASS="$(bashio::services "mqtt" "password")"
|
||||
# Apply MQTT settings
|
||||
MQTT_HOST="$(bashio::services "mqtt" "host")"
|
||||
MQTT_PORT="$(bashio::services "mqtt" "port")"
|
||||
MQTT_USER="$(bashio::services "mqtt" "username")"
|
||||
MQTT_PASS="$(bashio::services "mqtt" "password")"
|
||||
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
|
||||
# Check if manual MQTT configuration is provided
|
||||
elif [[ -f "$HOME"/BirdNET-Pi/scripts/birdnet_analysis.py ]] && bashio::config.has_value "MQTT_HOST_manual" && bashio::config.has_value "MQTT_PORT_manual"; then
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT is manually configured in the addon options"
|
||||
bashio::log.blue "Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "MQTT is manually configured in the addon options"
|
||||
bashio::log.blue "Birdnet-pi is now automatically configured to send its output to MQTT"
|
||||
bashio::log.green "---"
|
||||
bashio::log.blue "Data will be posted to the topic : 'birdnet'"
|
||||
bashio::log.blue "Json data : {'Date', 'Time', 'ScientificName', 'CommonName', 'Confidence', 'SpeciesCode', 'ClipName', 'url'}"
|
||||
bashio::log.blue "---"
|
||||
|
||||
# Apply manual MQTT settings
|
||||
MQTT_HOST="$(bashio::config "MQTT_HOST_manual")"
|
||||
MQTT_PORT="$(bashio::config "MQTT_PORT_manual")"
|
||||
MQTT_USER="$(bashio::config "MQTT_USER_manual")"
|
||||
MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")"
|
||||
# Apply manual MQTT settings
|
||||
MQTT_HOST="$(bashio::config "MQTT_HOST_manual")"
|
||||
MQTT_PORT="$(bashio::config "MQTT_PORT_manual")"
|
||||
MQTT_USER="$(bashio::config "MQTT_USER_manual")"
|
||||
MQTT_PASS="$(bashio::config "MQTT_PASSWORD_manual")"
|
||||
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
# Perform common setup steps
|
||||
common_steps
|
||||
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
################
|
||||
@@ -22,21 +22,21 @@ bashio::log.info "Adapting webui"
|
||||
# HA specific elements
|
||||
######################
|
||||
|
||||
if bashio::supervisor.ping 2>/dev/null; then
|
||||
# Remove services tab from webui
|
||||
echo "... removing System Controls from webui as should be used from HA"
|
||||
sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
if bashio::supervisor.ping 2> /dev/null; then
|
||||
# Remove services tab from webui
|
||||
echo "... removing System Controls from webui as should be used from HA"
|
||||
sed -i '/>System Controls/d' "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
|
||||
# Remove pulseaudio
|
||||
echo "... disabling pulseaudio as managed by HomeAssistant"
|
||||
grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do
|
||||
sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file"
|
||||
done
|
||||
# Remove pulseaudio
|
||||
echo "... disabling pulseaudio as managed by HomeAssistant"
|
||||
grep -srl "pulseaudio --start" "$HOME/BirdNET-Pi/scripts" | while read -r file; do
|
||||
sed -i "s|! pulseaudio --check|pulseaudio --check|g" "$file"
|
||||
done
|
||||
|
||||
# Check if port 80 is correctly configured
|
||||
if [ -n "$(bashio::addon.port "80")" ] && [ "$(bashio::addon.port "80")" != 80 ]; then
|
||||
bashio::log.fatal "The port 80 is enabled, but should still be 80 if you want automatic SSL certificates generation to work."
|
||||
fi
|
||||
# Check if port 80 is correctly configured
|
||||
if [ -n "$(bashio::addon.port "80")" ] && [ "$(bashio::addon.port "80")" != 80 ]; then
|
||||
bashio::log.fatal "The port 80 is enabled, but should still be 80 if you want automatic SSL certificates generation to work."
|
||||
fi
|
||||
fi
|
||||
|
||||
# General elements
|
||||
@@ -45,25 +45,25 @@ fi
|
||||
# Remove Ram drive option from webui
|
||||
echo "... removing Ram drive from webui as it is handled from HA"
|
||||
if grep -q "Ram drive" "$HOME/BirdNET-Pi/scripts/service_controls.php"; then
|
||||
sed -i '/Ram drive/{n;s/center"/center" style="display: none;"/;}' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
sed -i '/Ram drive/d' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
sed -i '/Ram drive/{n;s/center"/center" style="display: none;"/;}' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
sed -i '/Ram drive/d' "$HOME/BirdNET-Pi/scripts/service_controls.php"
|
||||
fi
|
||||
|
||||
# Allow symlinks
|
||||
echo "... ensuring symlinks work"
|
||||
for files in "$HOME"/BirdNET-Pi/scripts/*.sh; do
|
||||
sed -i "s|find |find -L |g" "$files"
|
||||
sed -i "s|find -L -L |find -L |g" "$files"
|
||||
sed -i "s|find |find -L |g" "$files"
|
||||
sed -i "s|find -L -L |find -L |g" "$files"
|
||||
done
|
||||
|
||||
# Correct services to start as user pi
|
||||
echo "... updating services to start as user pi"
|
||||
if ! grep -q "/usr/bin/sudo" "$HOME/BirdNET-Pi/templates/birdnet_analysis.service"; then
|
||||
while IFS= read -r file; do
|
||||
if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then
|
||||
sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file"
|
||||
fi
|
||||
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print)
|
||||
while IFS= read -r file; do
|
||||
if [[ "$(basename "$file")" != "birdnet_log.service" ]]; then
|
||||
sed -i "s|ExecStart=|ExecStart=/usr/bin/sudo -u pi |g" "$file"
|
||||
fi
|
||||
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*net*.service" -print)
|
||||
fi
|
||||
|
||||
# Allow pulseaudio system
|
||||
@@ -73,16 +73,16 @@ sed -i 's#pulseaudio --start#pulseaudio --start 2>/dev/null && pulseaudio --chec
|
||||
# Send services log to container logs
|
||||
echo "... redirecting services logs to container logs"
|
||||
while IFS= read -r file; do
|
||||
sed -i "/StandardError/d" "$file"
|
||||
sed -i "/StandardOutput/d" "$file"
|
||||
sed -i "/\[Service/a StandardError=append:/proc/1/fd/1" "$file"
|
||||
sed -i "/\[Service/a StandardOutput=append:/proc/1/fd/1" "$file"
|
||||
sed -i "/StandardError/d" "$file"
|
||||
sed -i "/StandardOutput/d" "$file"
|
||||
sed -i "/\[Service/a StandardError=append:/proc/1/fd/1" "$file"
|
||||
sed -i "/\[Service/a StandardOutput=append:/proc/1/fd/1" "$file"
|
||||
done < <(find "$HOME/BirdNET-Pi/templates/" -name "*.service" -print)
|
||||
|
||||
# Preencode API key
|
||||
if [[ -f "$HOME/BirdNET-Pi/scripts/common.php" ]] && ! grep -q "221160312" "$HOME/BirdNET-Pi/scripts/common.php"; then
|
||||
sed -i "/return \$_SESSION\['my_config'\];/i\ \ \ \ if (isset(\$_SESSION\['my_config'\]) \&\& empty(\$_SESSION\['my_config'\]\['FLICKR_API_KEY'\])) {\n\ \ \ \ \ \ \ \ \$_SESSION\['my_config'\]\['FLICKR_API_KEY'\] = \"221160312e1c22\";\n\ \ \ \ }" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
sed -i "s|e1c22|e1c22ec60ecf336951b0e77|g" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
sed -i "/return \$_SESSION\['my_config'\];/i\ \ \ \ if (isset(\$_SESSION\['my_config'\]) \&\& empty(\$_SESSION\['my_config'\]\['FLICKR_API_KEY'\])) {\n\ \ \ \ \ \ \ \ \$_SESSION\['my_config'\]\['FLICKR_API_KEY'\] = \"221160312e1c22\";\n\ \ \ \ }" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
sed -i "s|e1c22|e1c22ec60ecf336951b0e77|g" "$HOME"/BirdNET-Pi/scripts/common.php
|
||||
fi
|
||||
|
||||
# Correct log services to show /proc/1/fd/1
|
||||
@@ -92,8 +92,8 @@ sed -i "s|birdnet_log.sh|cat /proc/1/fd/1|g" "$HOME/BirdNET-Pi/templates/birdnet
|
||||
|
||||
# Correct backup script
|
||||
if [[ -f "$HOME/BirdNET-Pi/scripts/backup_data.sh" ]]; then
|
||||
echo "... correct backup script"
|
||||
sed -i "/PHP_SERVICE=/c PHP_SERVICE=\$(systemctl list-unit-files -t service --no-pager | grep 'php' | grep 'fpm' | awk '{print \$1}')" "$HOME/BirdNET-Pi/scripts/backup_data.sh"
|
||||
echo "... correct backup script"
|
||||
sed -i "/PHP_SERVICE=/c PHP_SERVICE=\$(systemctl list-unit-files -t service --no-pager | grep 'php' | grep 'fpm' | awk '{print \$1}')" "$HOME/BirdNET-Pi/scripts/backup_data.sh"
|
||||
fi
|
||||
|
||||
# Caddyfile modifications
|
||||
@@ -101,27 +101,27 @@ echo "... modifying Caddyfile configurations"
|
||||
caddy fmt --overwrite /etc/caddy/Caddyfile
|
||||
#Change port to leave 80 free for certificate requests
|
||||
if ! grep -q "http://:8081" /etc/caddy/Caddyfile; then
|
||||
sed -i "s|http://|http://:8081|g" /etc/caddy/Caddyfile
|
||||
sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f /etc/caddy/Caddyfile.original ]; then
|
||||
rm /etc/caddy/Caddyfile.original
|
||||
fi
|
||||
sed -i "s|http://|http://:8081|g" /etc/caddy/Caddyfile
|
||||
sed -i "s|http://|http://:8081|g" "$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f /etc/caddy/Caddyfile.original ]; then
|
||||
rm /etc/caddy/Caddyfile.original
|
||||
fi
|
||||
fi
|
||||
|
||||
# Correct webui paths
|
||||
echo "... correcting webui paths"
|
||||
if ! grep -q "/stats/" "$HOME/BirdNET-Pi/homepage/views.php"; then
|
||||
sed -i "s|/stats|/stats/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
sed -i "s|/stats|/stats/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
sed -i "s|/log|/log/|g" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
fi
|
||||
|
||||
# Correct systemctl path
|
||||
if [ -f /helpers/systemctl ] && [ -f /helpers/journalctl ]; then
|
||||
echo "... updating systemctl and journalctl"
|
||||
cp -rf /helpers/systemctl /bin/systemctl
|
||||
cp -rf /helpers/journalctl /bin/journalctl
|
||||
chown pi:pi /bin/systemctl /bin/journalctl
|
||||
chmod a+x /bin/systemctl /bin/journalctl
|
||||
echo "... updating systemctl and journalctl"
|
||||
cp -rf /helpers/systemctl /bin/systemctl
|
||||
cp -rf /helpers/journalctl /bin/journalctl
|
||||
chown pi:pi /bin/systemctl /bin/journalctl
|
||||
chmod a+x /bin/systemctl /bin/journalctl
|
||||
fi
|
||||
|
||||
# Allow reverse proxy for streamlit
|
||||
@@ -130,34 +130,34 @@ sed -i "s|plotly_streamlit.py --browser.gatherUsageStats|plotly_streamlit.py --s
|
||||
|
||||
# Clean saved mp3 files
|
||||
if [[ -f "$HOME/BirdNET-Pi/scripts/utils/reporting.py" ]]; then
|
||||
echo ".. add highpass and lowpass to sox extracts"
|
||||
sed -i "s|f'={stop}']|f'={stop}', 'highpass', '250']|g" "$HOME/BirdNET-Pi/scripts/utils/reporting.py"
|
||||
echo ".. add highpass and lowpass to sox extracts"
|
||||
sed -i "s|f'={stop}']|f'={stop}', 'highpass', '250']|g" "$HOME/BirdNET-Pi/scripts/utils/reporting.py"
|
||||
fi
|
||||
|
||||
# Correct timedatectl path
|
||||
echo "... updating timedatectl path"
|
||||
if [[ -f /helpers/timedatectl ]]; then
|
||||
mv /helpers/timedatectl /usr/bin/timedatectl
|
||||
chown pi:pi /usr/bin/timedatectl
|
||||
chmod a+x /usr/bin/timedatectl
|
||||
mv /helpers/timedatectl /usr/bin/timedatectl
|
||||
chown pi:pi /usr/bin/timedatectl
|
||||
chmod a+x /usr/bin/timedatectl
|
||||
fi
|
||||
|
||||
# Set RECS_DIR
|
||||
echo "... setting RECS_DIR to /tmp"
|
||||
grep -rl "RECS_DIR" "$HOME" --exclude="*.php" | while read -r file; do
|
||||
sed -i "s|conf\['RECS_DIR'\]|'/tmp'|g" "$file"
|
||||
sed -i "s|\$RECS_DIR|/tmp|g" "$file"
|
||||
sed -i "s|\${RECS_DIR}|/tmp|g" "$file"
|
||||
sed -i "/^RECS_DIR=/c RECS_DIR=/tmp" "$file"
|
||||
sed -i "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file"
|
||||
sed -i "s|conf\['RECS_DIR'\]|'/tmp'|g" "$file"
|
||||
sed -i "s|\$RECS_DIR|/tmp|g" "$file"
|
||||
sed -i "s|\${RECS_DIR}|/tmp|g" "$file"
|
||||
sed -i "/^RECS_DIR=/c RECS_DIR=/tmp" "$file"
|
||||
sed -i "/^\$RECS_DIR=/c \$RECS_DIR=/tmp" "$file"
|
||||
done
|
||||
mkdir -p /tmp
|
||||
|
||||
# Correct language labels according to birdnet.conf
|
||||
echo "... adapting labels according to birdnet.conf"
|
||||
if export "$(grep "^DATABASE_LANG" /config/birdnet.conf)"; then
|
||||
bashio::log.info "Setting language to ${DATABASE_LANG:-en}"
|
||||
"$HOME/BirdNET-Pi/scripts/install_language_label_nm.sh" -l "${DATABASE_LANG:-}" &>/dev/null || bashio::log.warning "Failed to update language labels"
|
||||
bashio::log.info "Setting language to ${DATABASE_LANG:-en}"
|
||||
"$HOME/BirdNET-Pi/scripts/install_language_label_nm.sh" -l "${DATABASE_LANG:-}" &> /dev/null || bashio::log.warning "Failed to update language labels"
|
||||
else
|
||||
bashio::log.warning "DATABASE_LANG not found in configuration. Using default labels."
|
||||
bashio::log.warning "DATABASE_LANG not found in configuration. Using default labels."
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
#################
|
||||
@@ -24,9 +24,9 @@ ingress_entry=$(bashio::addon.ingress_entry)
|
||||
|
||||
# Quits if ingress is not active
|
||||
if [[ "$ingress_entry" != "/api"* ]]; then
|
||||
bashio::log.info "Ingress entry is not set, exiting configuration."
|
||||
sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh
|
||||
exit 0
|
||||
bashio::log.info "Ingress entry is not set, exiting configuration."
|
||||
sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh
|
||||
exit 0
|
||||
fi
|
||||
|
||||
bashio::log.info "Adapting for ingress"
|
||||
@@ -35,26 +35,26 @@ echo "... setting up nginx"
|
||||
# Check if the NGINX configuration file exists
|
||||
nginx_conf="/etc/nginx/servers/ingress.conf"
|
||||
if [ -f "$nginx_conf" ]; then
|
||||
sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf"
|
||||
sed -i "s/%%interface%%/${ingress_interface}/g" "$nginx_conf"
|
||||
sed -i "s|%%ingress_entry%%|${ingress_entry}|g" "$nginx_conf"
|
||||
sed -i "s/%%port%%/${ingress_port}/g" "$nginx_conf"
|
||||
sed -i "s/%%interface%%/${ingress_interface}/g" "$nginx_conf"
|
||||
sed -i "s|%%ingress_entry%%|${ingress_entry}|g" "$nginx_conf"
|
||||
else
|
||||
bashio::log.error "NGINX configuration file not found: $nginx_conf"
|
||||
exit 1
|
||||
bashio::log.error "NGINX configuration file not found: $nginx_conf"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Disable log
|
||||
sed -i "/View Log/d" "$HOME/BirdNET-Pi/homepage/views.php"
|
||||
|
||||
echo "... ensuring restricted area access"
|
||||
echo "${ingress_entry}" >/ingress_url
|
||||
echo "${ingress_entry}" > /ingress_url
|
||||
|
||||
# Modify PHP file safely
|
||||
php_file="$HOME/BirdNET-Pi/scripts/common.php"
|
||||
if [ -f "$php_file" ]; then
|
||||
sed -i "/function is_authenticated/a if (strpos(\$_SERVER['HTTP_REFERER'], '/api/hassio_ingress') !== false && strpos(\$_SERVER['HTTP_REFERER'], trim(file_get_contents('/ingress_url'))) !== false) { \$ret = true; return \$ret; }" "$php_file"
|
||||
sed -i "/function is_authenticated/a if (strpos(\$_SERVER['HTTP_REFERER'], '/api/hassio_ingress') !== false && strpos(\$_SERVER['HTTP_REFERER'], trim(file_get_contents('/ingress_url'))) !== false) { \$ret = true; return \$ret; }" "$php_file"
|
||||
else
|
||||
bashio::log.warning "PHP file not found: $php_file"
|
||||
bashio::log.warning "PHP file not found: $php_file"
|
||||
fi
|
||||
|
||||
echo "... adapting Caddyfile for ingress"
|
||||
@@ -66,8 +66,8 @@ chmod +x /helpers/caddy_ingress.sh
|
||||
# Update the Caddyfile if update script exists
|
||||
caddy_update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f "$caddy_update_script" ]; then
|
||||
sed -i "/sudo caddy fmt --overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script"
|
||||
sed -i "/sudo caddy fmt --overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script"
|
||||
else
|
||||
bashio::log.error "Caddy update script not found: $caddy_update_script"
|
||||
exit 1
|
||||
bashio::log.error "Caddy update script not found: $caddy_update_script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
###############
|
||||
@@ -18,32 +18,32 @@ fi
|
||||
###############
|
||||
|
||||
if bashio::config.true 'ssl'; then
|
||||
bashio::log.info "SSL is enabled using addon options, setting up NGINX and Caddy."
|
||||
bashio::log.info "SSL is enabled using addon options, setting up NGINX and Caddy."
|
||||
|
||||
# Check required SSL configurations
|
||||
bashio::config.require.ssl
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
# Check required SSL configurations
|
||||
bashio::config.require.ssl
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
|
||||
# Ensure Caddyfile exists before modifying
|
||||
caddyfile="/etc/caddy/Caddyfile"
|
||||
if [ -f "$caddyfile" ]; then
|
||||
sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile"
|
||||
sed -i "s|http://:8081|https://:8081|g" "$caddyfile"
|
||||
else
|
||||
bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration."
|
||||
exit 1
|
||||
fi
|
||||
# Ensure Caddyfile exists before modifying
|
||||
caddyfile="/etc/caddy/Caddyfile"
|
||||
if [ -f "$caddyfile" ]; then
|
||||
sed -i "2a\ tls /ssl/${certfile} /ssl/${keyfile}" "$caddyfile"
|
||||
sed -i "s|http://:8081|https://:8081|g" "$caddyfile"
|
||||
else
|
||||
bashio::log.error "Caddyfile not found at $caddyfile, skipping SSL configuration."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure update_caddyfile.sh exists before modifying
|
||||
update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f "$update_script" ]; then
|
||||
sed -i "s|http://:8081|https://:8081|g" "$update_script"
|
||||
if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then
|
||||
sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"
|
||||
fi
|
||||
else
|
||||
bashio::log.error "Update script not found: $update_script, skipping SSL setup for update."
|
||||
exit 1
|
||||
fi
|
||||
# Ensure update_caddyfile.sh exists before modifying
|
||||
update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh"
|
||||
if [ -f "$update_script" ]; then
|
||||
sed -i "s|http://:8081|https://:8081|g" "$update_script"
|
||||
if ! grep -q "tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"; then
|
||||
sed -i "/https:/a\ tls /ssl/${certfile} /ssl/${keyfile}" "$update_script"
|
||||
fi
|
||||
else
|
||||
bashio::log.error "Update script not found: $update_script, skipping SSL setup for update."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -7,10 +7,10 @@ set -e
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
######################
|
||||
@@ -19,19 +19,19 @@ fi
|
||||
|
||||
# Check if the CPU supports AVX2
|
||||
if [[ "$(uname -m)" = "x86_64" ]]; then
|
||||
if lscpu | grep -q "Flags"; then
|
||||
if ! lscpu | grep -q "avx2"; then
|
||||
bashio::log.warning "NON SUPPORTED CPU DETECTED"
|
||||
bashio::log.warning "Your cpu doesn't support avx2, the analyzer service will likely won't work"
|
||||
bashio::log.warning "Trying to install tensorflow instead of tflite_runtime instead. This might take some time (up to 5 minutes)."
|
||||
bashio::log.warning "You could try also Birdnet-Go which should supports your cpu"
|
||||
source /home/pi/BirdNET-Pi/birdnet/bin/activate
|
||||
mkdir -p /home/pi/.cache/pip || true &>/dev/null
|
||||
chmod 777 /home/pi/.cache/pip || true &>/dev/null
|
||||
pip3 uninstall -y tflite_runtime
|
||||
pip install --upgrade packaging==23.2
|
||||
pip3 install --upgrade --force-reinstall "https://github.com/snowzach/tensorflow-multiarch/releases/download/v2.16.1/tensorflow-2.16.1-cp311-cp311-linux_x86_64.whl"
|
||||
deactivate
|
||||
fi
|
||||
fi
|
||||
if lscpu | grep -q "Flags"; then
|
||||
if ! lscpu | grep -q "avx2"; then
|
||||
bashio::log.warning "NON SUPPORTED CPU DETECTED"
|
||||
bashio::log.warning "Your cpu doesn't support avx2, the analyzer service will likely won't work"
|
||||
bashio::log.warning "Trying to install tensorflow instead of tflite_runtime instead. This might take some time (up to 5 minutes)."
|
||||
bashio::log.warning "You could try also Birdnet-Go which should supports your cpu"
|
||||
source /home/pi/BirdNET-Pi/birdnet/bin/activate
|
||||
mkdir -p /home/pi/.cache/pip || true &> /dev/null
|
||||
chmod 777 /home/pi/.cache/pip || true &> /dev/null
|
||||
pip3 uninstall -y tflite_runtime
|
||||
pip install --upgrade packaging==23.2
|
||||
pip3 install --upgrade --force-reinstall "https://github.com/snowzach/tensorflow-multiarch/releases/download/v2.16.1/tensorflow-2.16.1-cp311-cp311-linux_x86_64.whl"
|
||||
deactivate
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -8,10 +8,10 @@ set -eu
|
||||
##################
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == /etc/cont-init.d/* ]]; then
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
mkdir -p /etc/scripts-init
|
||||
sed -i "s|/etc/cont-init.d|/etc/scripts-init|g" /ha_entrypoint.sh
|
||||
sed -i "/ rm/d" /ha_entrypoint.sh
|
||||
cp "${BASH_SOURCE[0]}" /etc/scripts-init/
|
||||
fi
|
||||
|
||||
##############
|
||||
@@ -21,71 +21,71 @@ fi
|
||||
# Set password
|
||||
bashio::log.info "Setting password for the user pi"
|
||||
if bashio::config.has_value "pi_password"; then
|
||||
echo "pi:$(bashio::config "pi_password")" | chpasswd
|
||||
echo "pi:$(bashio::config "pi_password")" | chpasswd
|
||||
fi
|
||||
bashio::log.info "Password set successfully for user pi."
|
||||
|
||||
# Use timezone defined in add-on options if available
|
||||
bashio::log.info "Setting timezone :"
|
||||
if bashio::config.has_value 'TZ'; then
|
||||
TZ_VALUE="$(bashio::config 'TZ')"
|
||||
if timedatectl set-timezone "$TZ_VALUE"; then
|
||||
echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)."
|
||||
else
|
||||
bashio::log.warning "Couldn't set timezone to $TZ_VALUE. Refer to the list of valid timezones: https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html"
|
||||
timedatectl set-ntp true &>/dev/null
|
||||
fi
|
||||
TZ_VALUE="$(bashio::config 'TZ')"
|
||||
if timedatectl set-timezone "$TZ_VALUE"; then
|
||||
echo "... timezone set to $TZ_VALUE as defined in add-on options (BirdNET config ignored)."
|
||||
else
|
||||
bashio::log.warning "Couldn't set timezone to $TZ_VALUE. Refer to the list of valid timezones: https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html"
|
||||
timedatectl set-ntp true &> /dev/null
|
||||
fi
|
||||
# Use BirdNET-defined timezone if no add-on option is provided
|
||||
elif [ -f /data/timezone ]; then
|
||||
BIRDN_CONFIG_TZ="$(cat /data/timezone)"
|
||||
timedatectl set-ntp false &>/dev/null
|
||||
if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then
|
||||
echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config."
|
||||
else
|
||||
bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone."
|
||||
timedatectl set-ntp true &>/dev/null
|
||||
fi
|
||||
BIRDN_CONFIG_TZ="$(cat /data/timezone)"
|
||||
timedatectl set-ntp false &> /dev/null
|
||||
if timedatectl set-timezone "$BIRDN_CONFIG_TZ"; then
|
||||
echo "... set to $BIRDN_CONFIG_TZ as defined in BirdNET config."
|
||||
else
|
||||
bashio::log.warning "Couldn't set timezone to $BIRDN_CONFIG_TZ. Reverting to automatic timezone."
|
||||
timedatectl set-ntp true &> /dev/null
|
||||
fi
|
||||
# Fallback to automatic timezone if no manual settings are found
|
||||
else
|
||||
if timedatectl set-ntp true &>/dev/null; then
|
||||
bashio::log.info "... automatic timezone enabled."
|
||||
else
|
||||
bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options."
|
||||
fi
|
||||
if timedatectl set-ntp true &> /dev/null; then
|
||||
bashio::log.info "... automatic timezone enabled."
|
||||
else
|
||||
bashio::log.fatal "Couldn't set automatic timezone! Please set a manual one from the options."
|
||||
fi
|
||||
fi || true
|
||||
|
||||
# Use ALSA CARD defined in add-on options if available
|
||||
if [ -n "${ALSA_CARD:-}" ]; then
|
||||
bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD"
|
||||
for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file"
|
||||
fi
|
||||
done
|
||||
bashio::log.warning "ALSA_CARD is defined, the birdnet.conf is adapt to use device $ALSA_CARD"
|
||||
for file in "$HOME"/BirdNET-Pi/birdnet.conf /config/birdnet.conf; do
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/^REC_CARD/c\REC_CARD=$ALSA_CARD" "$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Fix timezone as per installer
|
||||
CURRENT_TIMEZONE="$(timedatectl show --value --property=Timezone)"
|
||||
[ -f /etc/timezone ] && echo "$CURRENT_TIMEZONE" | sudo tee /etc/timezone >/dev/null
|
||||
[ -f /etc/timezone ] && echo "$CURRENT_TIMEZONE" | sudo tee /etc/timezone > /dev/null
|
||||
|
||||
bashio::log.info "Starting system services"
|
||||
|
||||
bashio::log.info "Starting cron service"
|
||||
systemctl start cron >/dev/null
|
||||
systemctl start cron > /dev/null
|
||||
|
||||
bashio::log.info "Starting dbus service"
|
||||
service dbus start >/dev/null
|
||||
service dbus start > /dev/null
|
||||
|
||||
bashio::log.info "Starting BirdNET-Pi services"
|
||||
chmod +x "$HOME/BirdNET-Pi/scripts/restart_services.sh" >/dev/null
|
||||
"$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
|
||||
|
||||
# Start livestream services if enabled in configuration
|
||||
if bashio::config.true "LIVESTREAM_BOOT_ENABLED"; then
|
||||
echo "... starting livestream services"
|
||||
systemctl enable icecast2 >/dev/null
|
||||
systemctl start icecast2.service >/dev/null
|
||||
systemctl enable --now livestream.service >/dev/null
|
||||
echo "... starting livestream services"
|
||||
systemctl enable icecast2 > /dev/null
|
||||
systemctl start icecast2.service > /dev/null
|
||||
systemctl enable --now livestream.service > /dev/null
|
||||
fi
|
||||
|
||||
# Start
|
||||
|
||||
@@ -7,7 +7,7 @@ set +u
|
||||
source /etc/birdnet/birdnet.conf
|
||||
|
||||
# Create ingress configuration for Caddyfile
|
||||
cat <<EOF >>/etc/caddy/Caddyfile
|
||||
cat << EOF >> /etc/caddy/Caddyfile
|
||||
:8082 {
|
||||
root * ${EXTRACTED}
|
||||
file_server browse
|
||||
|
||||
@@ -7,9 +7,9 @@ set -e
|
||||
####################
|
||||
|
||||
if [ -d /homeassistant/addons_config/calibre ]; then
|
||||
echo "Moving database to new location /config"
|
||||
cp -rf /homeassistant/addons_config/calibre/* /config/
|
||||
rm -r /homeassistant/addons_config/calibre
|
||||
echo "Moving database to new location /config"
|
||||
cp -rf /homeassistant/addons_config/calibre/* /config/
|
||||
rm -r /homeassistant/addons_config/calibre
|
||||
fi
|
||||
|
||||
# Legacy path
|
||||
|
||||
@@ -11,23 +11,23 @@ PGID=$(bashio::config "PGID")
|
||||
LOCATION=$(bashio::config 'data_location')
|
||||
|
||||
if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then
|
||||
# Default location
|
||||
LOCATION="/config"
|
||||
# Default location
|
||||
LOCATION="/config"
|
||||
else
|
||||
bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually"
|
||||
bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually"
|
||||
|
||||
# Check if config is located in an acceptable location
|
||||
LOCATIONOK=""
|
||||
for location in "/share" "/config" "/data" "/mnt"; do
|
||||
if [[ "$LOCATION" == "$location"* ]]; then
|
||||
LOCATIONOK=true
|
||||
fi
|
||||
done
|
||||
# Check if config is located in an acceptable location
|
||||
LOCATIONOK=""
|
||||
for location in "/share" "/config" "/data" "/mnt"; do
|
||||
if [[ "$LOCATION" == "$location"* ]]; then
|
||||
LOCATIONOK=true
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$LOCATIONOK" ]; then
|
||||
LOCATION="/config"
|
||||
bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION"
|
||||
fi
|
||||
if [ -z "$LOCATIONOK" ]; then
|
||||
LOCATION="/config"
|
||||
bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
@@ -36,29 +36,29 @@ bashio::log.info "Setting data location to $LOCATION"
|
||||
|
||||
# Correct home locations
|
||||
for file in /etc/s6-overlay/s6-rc.d/*/run; do
|
||||
if [ "$(sed -n '1{/bash/p};q' "$file")" ]; then
|
||||
sed -i "1a export HOME=$LOCATION" "$file"
|
||||
sed -i "1a export FM_HOME=$LOCATION" "$file"
|
||||
fi
|
||||
if [ "$(sed -n '1{/bash/p};q' "$file")" ]; then
|
||||
sed -i "1a export HOME=$LOCATION" "$file"
|
||||
sed -i "1a export FM_HOME=$LOCATION" "$file"
|
||||
fi
|
||||
done
|
||||
|
||||
# Correct home location
|
||||
for folders in /defaults /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d; do
|
||||
if [ -d "$folders" ]; then
|
||||
sed -i "s|/config|$LOCATION|g" $(find "$folders" -type f) &>/dev/null || true
|
||||
fi
|
||||
if [ -d "$folders" ]; then
|
||||
sed -i "s|/config|$LOCATION|g" $(find "$folders" -type f) &> /dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
# Change user home
|
||||
usermod --home "$LOCATION" abc
|
||||
|
||||
# Add environment variables
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" >/var/run/s6/container_environment/HOME; fi
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" >/var/run/s6/container_environment/FM_HOME; fi
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/HOME; fi
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/FM_HOME; fi
|
||||
{
|
||||
printf "%s\n" "HOME=\"$LOCATION\""
|
||||
printf "%s\n" "FM_HOME=\"$LOCATION\""
|
||||
} >>~/.bashrc
|
||||
printf "%s\n" "HOME=\"$LOCATION\""
|
||||
printf "%s\n" "FM_HOME=\"$LOCATION\""
|
||||
} >> ~/.bashrc
|
||||
|
||||
# Create folder
|
||||
echo "Creating $LOCATION"
|
||||
|
||||
@@ -5,50 +5,50 @@ set -e
|
||||
|
||||
# Install specific apps
|
||||
if bashio::config.has_value 'additional_apps'; then
|
||||
bashio::log.info "Installing additional apps :"
|
||||
# hadolint ignore=SC2005
|
||||
NEWAPPS=$(bashio::config 'additional_apps')
|
||||
for packagestoinstall in ${NEWAPPS//,/ }; do
|
||||
bashio::log.green "... $packagestoinstall"
|
||||
if command -v "apk" &>/dev/null; then
|
||||
apk add --no-cache "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
|
||||
elif command -v "apt" &>/dev/null; then
|
||||
apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
|
||||
elif command -v "pacman" &>/dev/null; then
|
||||
pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
|
||||
fi
|
||||
done
|
||||
bashio::log.info "Installing additional apps :"
|
||||
# hadolint ignore=SC2005
|
||||
NEWAPPS=$(bashio::config 'additional_apps')
|
||||
for packagestoinstall in ${NEWAPPS//,/ }; do
|
||||
bashio::log.green "... $packagestoinstall"
|
||||
if command -v "apk" &> /dev/null; then
|
||||
apk add --no-cache "$packagestoinstall" &> /dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
|
||||
elif command -v "apt" &> /dev/null; then
|
||||
apt-get install -yqq --no-install-recommends "$packagestoinstall" &> /dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
|
||||
elif command -v "pacman" &> /dev/null; then
|
||||
pacman --noconfirm -S "$packagestoinstall" &> /dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Set TZ
|
||||
if bashio::config.has_value 'TZ'; then
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" >/etc/timezone
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" > /etc/timezone
|
||||
fi || (bashio::log.fatal "Error : $TIMEZONE not found. Here is a list of valid timezones : https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html")
|
||||
|
||||
# Set cli args
|
||||
if bashio::config.has_value 'CLI_ARGS'; then
|
||||
bashio::log.info "Setting password to the value defined in options"
|
||||
CLI_ARGS=$(bashio::config 'CLI_ARGS')
|
||||
bashio::log.info "Setting arguments to $CLI_ARGS"
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CLI_ARGS" >/var/run/s6/container_environment/CLI_ARGS; fi
|
||||
printf "%s\n" "CLI_ARGS=\"$CLI_ARGS\"" >>~/.bashrc
|
||||
bashio::log.info "Setting password to the value defined in options"
|
||||
CLI_ARGS=$(bashio::config 'CLI_ARGS')
|
||||
bashio::log.info "Setting arguments to $CLI_ARGS"
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CLI_ARGS" > /var/run/s6/container_environment/CLI_ARGS; fi
|
||||
printf "%s\n" "CLI_ARGS=\"$CLI_ARGS\"" >> ~/.bashrc
|
||||
fi || true
|
||||
|
||||
# Set keyboard
|
||||
if bashio::config.has_value 'KEYBOARD'; then
|
||||
KEYBOARD=$(bashio::config 'KEYBOARD')
|
||||
bashio::log.info "Setting keyboard to $KEYBOARD"
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" >/var/run/s6/container_environment/KEYBOARD; fi
|
||||
printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >>~/.bashrc
|
||||
KEYBOARD=$(bashio::config 'KEYBOARD')
|
||||
bashio::log.info "Setting keyboard to $KEYBOARD"
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" > /var/run/s6/container_environment/KEYBOARD; fi
|
||||
printf "%s\n" "KEYBOARD=\"$KEYBOARD\"" >> ~/.bashrc
|
||||
fi || true
|
||||
|
||||
# Set password
|
||||
if bashio::config.has_value 'PASSWORD'; then
|
||||
bashio::log.info "Setting password to the value defined in options"
|
||||
PASSWORD=$(bashio::config 'PASSWORD')
|
||||
passwd -d abc
|
||||
echo -e "$PASSWORD\n$PASSWORD" | passwd abc
|
||||
bashio::log.info "Setting password to the value defined in options"
|
||||
PASSWORD=$(bashio::config 'PASSWORD')
|
||||
passwd -d abc
|
||||
echo -e "$PASSWORD\n$PASSWORD" | passwd abc
|
||||
fi || true
|
||||
|
||||
@@ -9,7 +9,7 @@ SUBFOLDER="$(bashio::addon.ingress_entry)"
|
||||
# Copy template
|
||||
cp /defaults/default.conf "${NGINX_CONFIG}"
|
||||
# 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}"
|
||||
|
||||
# Remove ipv6
|
||||
|
||||
@@ -7,9 +7,9 @@ set -e
|
||||
####################
|
||||
|
||||
if [ -d /homeassistant/addons_config/calibre-web ] && [ ! -L /homeassistant/addons_config/calibre-web ]; then
|
||||
if [ "$(ls -A /homeassistant/addons_config/calibre-web)" ]; then
|
||||
echo "Moving database to new location /config"
|
||||
cp -rf /homeassistant/addons_config/calibre-web/* "$LOCATION"/
|
||||
fi
|
||||
rm -r /homeassistant/addons_config/calibre-web
|
||||
if [ "$(ls -A /homeassistant/addons_config/calibre-web)" ]; then
|
||||
echo "Moving database to new location /config"
|
||||
cp -rf /homeassistant/addons_config/calibre-web/* "$LOCATION"/
|
||||
fi
|
||||
rm -r /homeassistant/addons_config/calibre-web
|
||||
fi
|
||||
|
||||
@@ -10,23 +10,23 @@ PGID=$(bashio::config "PGID")
|
||||
LOCATION=$(bashio::config 'data_location')
|
||||
|
||||
if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then
|
||||
# Default location
|
||||
LOCATION="/config"
|
||||
# Default location
|
||||
LOCATION="/config"
|
||||
else
|
||||
bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually"
|
||||
bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually"
|
||||
|
||||
# Check if config is located in an acceptable location
|
||||
LOCATIONOK=""
|
||||
for location in "/share" "/config" "/data" "/mnt"; do
|
||||
if [[ "$LOCATION" == "$location"* ]]; then
|
||||
LOCATIONOK=true
|
||||
fi
|
||||
done
|
||||
# Check if config is located in an acceptable location
|
||||
LOCATIONOK=""
|
||||
for location in "/share" "/config" "/data" "/mnt"; do
|
||||
if [[ "$LOCATION" == "$location"* ]]; then
|
||||
LOCATIONOK=true
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$LOCATIONOK" ]; then
|
||||
LOCATION=/config
|
||||
bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION"
|
||||
fi
|
||||
if [ -z "$LOCATIONOK" ]; then
|
||||
LOCATION=/config
|
||||
bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
@@ -37,10 +37,10 @@ sed -i "1a export FM_HOME=$LOCATION" /etc/services.d/*/run
|
||||
sed -i "s|/config|$LOCATION|g" /defaults/*
|
||||
sed -i "s|/config|$LOCATION|g" /etc/cont-init.d/*
|
||||
sed -i "s|/config|$LOCATION|g" /etc/services.d/*/run
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" >/var/run/s6/container_environment/HOME; fi
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" >/var/run/s6/container_environment/FM_HOME; fi
|
||||
printf "%s\n" "HOME=\"$LOCATION\"" >>~/.bashrc
|
||||
printf "%s\n" "FM_HOME=\"$LOCATION\"" >>~/.bashrc
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/HOME; fi
|
||||
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/FM_HOME; fi
|
||||
printf "%s\n" "HOME=\"$LOCATION\"" >> ~/.bashrc
|
||||
printf "%s\n" "FM_HOME=\"$LOCATION\"" >> ~/.bashrc
|
||||
|
||||
usermod --home "$LOCATION" abc
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -d /config ]; then
|
||||
echo "Creating /config"
|
||||
mkdir -p /config
|
||||
echo "Creating /config"
|
||||
mkdir -p /config
|
||||
fi
|
||||
|
||||
chown -R "$PUID:$PGID" /config
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -f /etc/cont-init.d/00-smb_mounts.sh ]; then
|
||||
sed -i "s|cifs -o \"|cifs -o \"nobrl,|g" /etc/cont-init.d/00-smb_mounts.sh
|
||||
sed -i "s|cifs -o \"|cifs -o \"nobrl,|g" /etc/cont-init.d/00-smb_mounts.sh
|
||||
fi
|
||||
|
||||
@@ -42,7 +42,7 @@ declare ingress_port
|
||||
|
||||
ingress_user='admin'
|
||||
if bashio::config.has_value 'ingress_user'; then
|
||||
ingress_user=$(bashio::config 'ingress_user')
|
||||
ingress_user=$(bashio::config 'ingress_user')
|
||||
fi
|
||||
|
||||
ingress_port=$(bashio::addon.ingress_port)
|
||||
|
||||
@@ -5,19 +5,19 @@ set -e
|
||||
|
||||
# Set TZ
|
||||
if bashio::config.has_value 'TZ'; then
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime && echo "$TIMEZONE" >/etc/timezone
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime && echo "$TIMEZONE" > /etc/timezone
|
||||
fi
|
||||
|
||||
bashio::log.info "Install libnss3"
|
||||
apt-get update && apt-get install libnss3 &>/dev/null
|
||||
apt-get update && apt-get install libnss3 &> /dev/null
|
||||
|
||||
# Set Ingress login
|
||||
if [ ! -f /config/app.db ]; then
|
||||
bashio::log.warning "First boot : disabling Ingress until addon restart"
|
||||
bashio::log.warning "First boot : disabling Ingress until addon restart"
|
||||
else
|
||||
sqlite3 /config/app.db 'update settings set config_reverse_proxy_login_header_name="X-WebAuth-User",config_allow_reverse_proxy_header_login=1'
|
||||
sqlite3 /config/app.db 'update settings set config_reverse_proxy_login_header_name="X-WebAuth-User",config_allow_reverse_proxy_header_login=1'
|
||||
fi
|
||||
|
||||
bashio::log.info "Default username:password is admin:admin123"
|
||||
|
||||
0
calibre_web/rootfs/etc/services.d/nginx/run
Normal file → Executable file
0
calibre_web/rootfs/etc/services.d/nginx/run
Normal file → Executable file
@@ -7,9 +7,9 @@ set -e
|
||||
####################
|
||||
|
||||
if [ -f /homeassistant/addons_config/cloudcommander ]; then
|
||||
echo "Moving database to new location /config"
|
||||
cp -rnf /homeassistant/addons_config/cloudcommander/* /config/ || true
|
||||
rm -r /homeassistant/addons_config/cloudcommander
|
||||
echo "Moving database to new location /config"
|
||||
cp -rnf /homeassistant/addons_config/cloudcommander/* /config/ || true
|
||||
rm -r /homeassistant/addons_config/cloudcommander
|
||||
fi
|
||||
|
||||
######################
|
||||
@@ -22,12 +22,12 @@ find /homeassistant/addons_config -maxdepth 1 -type l -delete
|
||||
|
||||
# Remove erroneous folders
|
||||
if [ -d /homeassistant ]; then
|
||||
if [ -d /config/addons_config ]; then
|
||||
rm -r /config/addons_config
|
||||
fi
|
||||
if [ -d /config/addons_autoscripts ]; then
|
||||
rm -r /config/addons_autoscripts
|
||||
fi
|
||||
if [ -d /config/addons_config ]; then
|
||||
rm -r /config/addons_config
|
||||
fi
|
||||
if [ -d /config/addons_autoscripts ]; then
|
||||
rm -r /config/addons_autoscripts
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create symlinks
|
||||
@@ -50,8 +50,8 @@ export CLOUDCMD_PREFIX
|
||||
|
||||
declare ADDON_PROTOCOL=http
|
||||
if bashio::config.true 'ssl'; then
|
||||
ADDON_PROTOCOL=https
|
||||
bashio::config.require.ssl
|
||||
ADDON_PROTOCOL=https
|
||||
bashio::config.require.ssl
|
||||
fi
|
||||
|
||||
# port=$(bashio::addon.port 80)
|
||||
@@ -68,15 +68,15 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
|
||||
###############
|
||||
|
||||
if bashio::config.has_value 'CUSTOM_OPTIONS'; then
|
||||
CUSTOMOPTIONS=" $(bashio::config 'CUSTOM_OPTIONS')"
|
||||
CUSTOMOPTIONS=" $(bashio::config 'CUSTOM_OPTIONS')"
|
||||
else
|
||||
CUSTOMOPTIONS=""
|
||||
CUSTOMOPTIONS=""
|
||||
fi
|
||||
|
||||
if bashio::config.has_value 'DROPBOX_TOKEN'; then
|
||||
DROPBOX_TOKEN="--dropbox --dropbox-token $(bashio::config 'DROPBOX_TOKEN')"
|
||||
DROPBOX_TOKEN="--dropbox --dropbox-token $(bashio::config 'DROPBOX_TOKEN')"
|
||||
else
|
||||
DROPBOX_TOKEN=""
|
||||
DROPBOX_TOKEN=""
|
||||
fi
|
||||
|
||||
bashio::log.info "Starting..."
|
||||
|
||||
@@ -19,39 +19,39 @@ urls+=("$(bashio::jq "$result" '.external_url' | cut -d'/' -f3 | cut -d':' -f1)"
|
||||
|
||||
# Get supported interfaces
|
||||
for interface in $(bashio::network.interfaces); do
|
||||
urls+=("$(bashio::network.ipv6_address "${interface}" | cut -d'/' -f1)")
|
||||
urls+=("$(bashio::network.ipv4_address "${interface}" | cut -d'/' -f1)")
|
||||
urls+=("$(bashio::network.ipv6_address "${interface}" | cut -d'/' -f1)")
|
||||
urls+=("$(bashio::network.ipv4_address "${interface}" | cut -d'/' -f1)")
|
||||
done
|
||||
|
||||
if bashio::config.has_value 'csrf_allowed'; then
|
||||
bashio::log.info "Setup manually defined ALLOWED_CSRF domains"
|
||||
bashio::log.info "Setup manually defined ALLOWED_CSRF domains"
|
||||
|
||||
while read -r line; do
|
||||
urls+=("$line")
|
||||
done <<<"$(bashio::config 'csrf_allowed')"
|
||||
while read -r line; do
|
||||
urls+=("$line")
|
||||
done <<< "$(bashio::config 'csrf_allowed')"
|
||||
fi
|
||||
|
||||
# Add internal and external URL as it
|
||||
if [[ "$(bashio::jq "$result" '.external_url')" != "null" ]]; then
|
||||
CSRF=$(bashio::jq "$result" '.external_url')
|
||||
CSRF=$(bashio::jq "$result" '.external_url')
|
||||
fi
|
||||
if [[ "$(bashio::jq "$result" '.internal_url')" != "null" ]]; then
|
||||
CSRF=$(bashio::jq "$result" '.internal_url'),${CSRF}
|
||||
CSRF=$(bashio::jq "$result" '.internal_url'),${CSRF}
|
||||
fi
|
||||
|
||||
# Loop through URls to add them in the CSRF string
|
||||
for url in "${urls[@]}"; do
|
||||
if bashio::var.has_value "${url}"; then
|
||||
if [[ "${url}" != "null" ]] && [[ "${url}" != "null.local" ]]; then
|
||||
CSRF="https://${url}:${port},http://${url}:${port},https://${url},http://${url}",${CSRF}
|
||||
if bashio::var.has_value "$(bashio::addon.port 9810)"; then
|
||||
CSRF="https://${url}:${addon_port},http://${url}:${addon_port}",${CSRF}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if bashio::var.has_value "${url}"; then
|
||||
if [[ "${url}" != "null" ]] && [[ "${url}" != "null.local" ]]; then
|
||||
CSRF="https://${url}:${port},http://${url}:${port},https://${url},http://${url}",${CSRF}
|
||||
if bashio::var.has_value "$(bashio::addon.port 9810)"; then
|
||||
CSRF="https://${url}:${addon_port},http://${url}:${addon_port}",${CSRF}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
CSRF=${CSRF::-1}
|
||||
|
||||
# Save CSFR
|
||||
echo -n "${CSRF}" >/var/run/s6/container_environment/PAPERLESS_CSRF_TRUSTED_ORIGINS
|
||||
echo -n "${CSRF}" > /var/run/s6/container_environment/PAPERLESS_CSRF_TRUSTED_ORIGINS
|
||||
bashio::log.blue "PAPERLESS_CSRF_TRUSTED_ORIGINS is set to ${CSRF}"
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
############
|
||||
|
||||
if bashio::config.has_value 'TZ'; then
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" >/etc/timezone
|
||||
else
|
||||
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
|
||||
fi
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" > /etc/timezone
|
||||
else
|
||||
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
|
||||
fi
|
||||
fi
|
||||
|
||||
#################
|
||||
@@ -32,7 +32,7 @@ export FB_BASEURL
|
||||
declare ADDON_PROTOCOL=http
|
||||
# Generate Ingress configuration
|
||||
if bashio::config.true 'ssl'; then
|
||||
ADDON_PROTOCOL=https
|
||||
ADDON_PROTOCOL=https
|
||||
fi
|
||||
|
||||
#port=$(bashio::addon.port 80)
|
||||
@@ -46,10 +46,10 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
|
||||
|
||||
# Correct baseurl
|
||||
for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/root_path/d" "$file"
|
||||
sed -i "1a root_path = \"${FB_BASEURL}\"" "$file"
|
||||
fi
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/root_path/d" "$file"
|
||||
sed -i "1a root_path = \"${FB_BASEURL}\"" "$file"
|
||||
fi
|
||||
done
|
||||
|
||||
##############
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
############
|
||||
|
||||
if bashio::config.has_value 'TZ'; then
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" >/etc/timezone
|
||||
else
|
||||
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
|
||||
fi
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" > /etc/timezone
|
||||
else
|
||||
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
|
||||
fi
|
||||
fi
|
||||
|
||||
#################
|
||||
@@ -22,37 +22,37 @@ fi
|
||||
|
||||
INGRESS="false"
|
||||
if [[ "$INGRESS" == "true" ]]; then
|
||||
#declare port
|
||||
#declare certfile
|
||||
declare ingress_interface
|
||||
declare ingress_port
|
||||
#declare keyfile
|
||||
#declare port
|
||||
#declare certfile
|
||||
declare ingress_interface
|
||||
declare ingress_port
|
||||
#declare keyfile
|
||||
|
||||
FB_BASEURL="$(bashio::addon.ingress_entry)"
|
||||
export FB_BASEURL
|
||||
FB_BASEURL="$(bashio::addon.ingress_entry)"
|
||||
export FB_BASEURL
|
||||
|
||||
declare ADDON_PROTOCOL=http
|
||||
# Generate Ingress configuration
|
||||
if bashio::config.true 'ssl'; then
|
||||
ADDON_PROTOCOL=https
|
||||
fi
|
||||
declare ADDON_PROTOCOL=http
|
||||
# Generate Ingress configuration
|
||||
if bashio::config.true 'ssl'; then
|
||||
ADDON_PROTOCOL=https
|
||||
fi
|
||||
|
||||
#port=$(bashio::addon.port 80)
|
||||
ingress_port=$(bashio::addon.ingress_port)
|
||||
ingress_interface=$(bashio::addon.ip_address)
|
||||
sed -i "s|%%protocol%%|${ADDON_PROTOCOL}|g" /etc/nginx/servers/ingress.conf
|
||||
sed -i "s|%%port%%|${ingress_port}|g" /etc/nginx/servers/ingress.conf
|
||||
sed -i "s|%%interface%%|${ingress_interface}|g" /etc/nginx/servers/ingress.conf
|
||||
sed -i "s|%%subpath%%|${FB_BASEURL}/|g" /etc/nginx/servers/ingress.conf
|
||||
mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
|
||||
#port=$(bashio::addon.port 80)
|
||||
ingress_port=$(bashio::addon.ingress_port)
|
||||
ingress_interface=$(bashio::addon.ip_address)
|
||||
sed -i "s|%%protocol%%|${ADDON_PROTOCOL}|g" /etc/nginx/servers/ingress.conf
|
||||
sed -i "s|%%port%%|${ingress_port}|g" /etc/nginx/servers/ingress.conf
|
||||
sed -i "s|%%interface%%|${ingress_interface}|g" /etc/nginx/servers/ingress.conf
|
||||
sed -i "s|%%subpath%%|${FB_BASEURL}/|g" /etc/nginx/servers/ingress.conf
|
||||
mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
|
||||
|
||||
# Correct baseurl
|
||||
for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/root_path/d" "$file"
|
||||
sed -i "1a root_path = \"${FB_BASEURL}\"" "$file"
|
||||
fi
|
||||
done
|
||||
# Correct baseurl
|
||||
for file in /config/hypercorn.toml $(find /usr -name hypercorn.toml.default); do
|
||||
if [ -f "$file" ]; then
|
||||
sed -i "/root_path/d" "$file"
|
||||
sed -i "1a root_path = \"${FB_BASEURL}\"" "$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
###########
|
||||
|
||||
@@ -5,52 +5,52 @@ set -e
|
||||
data_location="${data_location:-/share/emby}"
|
||||
config_location="/config/emby"
|
||||
log() {
|
||||
bashio::log.info "$1"
|
||||
bashio::log.info "$1"
|
||||
}
|
||||
|
||||
log "Updating folder structure and permission : data stored in $data_location"
|
||||
|
||||
declare -A directories=(
|
||||
["/emby"]=""
|
||||
["/share/storage/tv"]=""
|
||||
["/share/storage/movies"]=""
|
||||
["$data_location"]=""
|
||||
["$config_location"]=""
|
||||
["/emby"]=""
|
||||
["/share/storage/tv"]=""
|
||||
["/share/storage/movies"]=""
|
||||
["$data_location"]=""
|
||||
["$config_location"]=""
|
||||
)
|
||||
|
||||
for dir in "${!directories[@]}"; do
|
||||
log "Creating directory: $dir"
|
||||
mkdir -p "$dir"
|
||||
chown -R "$PUID:$PGID" "$dir"
|
||||
log "Creating directory: $dir"
|
||||
mkdir -p "$dir"
|
||||
chown -R "$PUID:$PGID" "$dir"
|
||||
done
|
||||
|
||||
if [ -d /homeassistant/emby ]; then
|
||||
log "Migrate previous config location"
|
||||
cp -rf /homeassistant/emby/* "$config_location"/
|
||||
mv /homeassistant/emby /homeassistant/emby_migrated
|
||||
chown -R "$PUID:$PGID" "$config_location"
|
||||
log "Migrate previous config location"
|
||||
cp -rf /homeassistant/emby/* "$config_location"/
|
||||
mv /homeassistant/emby /homeassistant/emby_migrated
|
||||
chown -R "$PUID:$PGID" "$config_location"
|
||||
fi
|
||||
|
||||
if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then
|
||||
cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/
|
||||
mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh
|
||||
cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/
|
||||
mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh
|
||||
fi
|
||||
|
||||
declare -A links=(
|
||||
["/emby/cache"]="$data_location/cache"
|
||||
["/emby/config"]="$config_location"
|
||||
["/emby/data"]="$data_location/data"
|
||||
["/emby/logs"]="$data_location/logs"
|
||||
["/emby/metadata"]="$data_location/metadata"
|
||||
["/emby/plugins"]="$data_location/plugins"
|
||||
["/emby/root"]="$data_location/root"
|
||||
["/emby/cache"]="$data_location/cache"
|
||||
["/emby/config"]="$config_location"
|
||||
["/emby/data"]="$data_location/data"
|
||||
["/emby/logs"]="$data_location/logs"
|
||||
["/emby/metadata"]="$data_location/metadata"
|
||||
["/emby/plugins"]="$data_location/plugins"
|
||||
["/emby/root"]="$data_location/root"
|
||||
)
|
||||
|
||||
for link in "${!links[@]}"; do
|
||||
if [ ! -d "$link" ]; then
|
||||
log "Creating link for $link"
|
||||
mkdir -p "${links[$link]}"
|
||||
chown -R "$PUID:$PGID" "${links[$link]}"
|
||||
ln -s "${links[$link]}" "$link"
|
||||
fi
|
||||
if [ ! -d "$link" ]; then
|
||||
log "Creating link for $link"
|
||||
mkdir -p "${links[$link]}"
|
||||
chown -R "$PUID:$PGID" "${links[$link]}"
|
||||
ln -s "${links[$link]}" "$link"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -7,7 +7,7 @@ set -e
|
||||
###############
|
||||
|
||||
if bashio::config.true 'silent'; then
|
||||
APPEND=' >/dev/null'
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run
|
||||
bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
|
||||
APPEND=' >/dev/null'
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run
|
||||
bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
|
||||
fi
|
||||
|
||||
0
emby/rootfs/etc/services.d/nginx/run
Normal file → Executable file
0
emby/rootfs/etc/services.d/nginx/run
Normal file → Executable file
@@ -5,52 +5,52 @@ set -e
|
||||
data_location="${data_location:-/share/emby}"
|
||||
config_location="/config/emby"
|
||||
log() {
|
||||
bashio::log.info "$1"
|
||||
bashio::log.info "$1"
|
||||
}
|
||||
|
||||
log "Updating folder structure and permission : data stored in $data_location"
|
||||
|
||||
declare -A directories=(
|
||||
["/emby"]=""
|
||||
["/share/storage/tv"]=""
|
||||
["/share/storage/movies"]=""
|
||||
["$data_location"]=""
|
||||
["$config_location"]=""
|
||||
["/emby"]=""
|
||||
["/share/storage/tv"]=""
|
||||
["/share/storage/movies"]=""
|
||||
["$data_location"]=""
|
||||
["$config_location"]=""
|
||||
)
|
||||
|
||||
for dir in "${!directories[@]}"; do
|
||||
log "Creating directory: $dir"
|
||||
mkdir -p "$dir"
|
||||
chown -R "$PUID:$PGID" "$dir"
|
||||
log "Creating directory: $dir"
|
||||
mkdir -p "$dir"
|
||||
chown -R "$PUID:$PGID" "$dir"
|
||||
done
|
||||
|
||||
if [ -d /homeassistant/emby ]; then
|
||||
log "Migrate previous config location"
|
||||
cp -rf /homeassistant/emby/* "$config_location"/
|
||||
mv /homeassistant/emby /homeassistant/emby_migrated
|
||||
chown -R "$PUID:$PGID" "$config_location"
|
||||
log "Migrate previous config location"
|
||||
cp -rf /homeassistant/emby/* "$config_location"/
|
||||
mv /homeassistant/emby /homeassistant/emby_migrated
|
||||
chown -R "$PUID:$PGID" "$config_location"
|
||||
fi
|
||||
|
||||
if [ -f /homeassistant/addons_autoscripts/emby-nas.sh ]; then
|
||||
cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/
|
||||
mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh
|
||||
cp -rf /homeassistant/addons_autoscripts/emby-nas.sh "$config_location"/
|
||||
mv /homeassistant/addons_autoscripts/emby-nas.sh /homeassistant/addons_autoscripts/emby-nas_migrated.sh
|
||||
fi
|
||||
|
||||
declare -A links=(
|
||||
["/emby/cache"]="$data_location/cache"
|
||||
["/emby/config"]="$config_location"
|
||||
["/emby/data"]="$data_location/data"
|
||||
["/emby/logs"]="$data_location/logs"
|
||||
["/emby/metadata"]="$data_location/metadata"
|
||||
["/emby/plugins"]="$data_location/plugins"
|
||||
["/emby/root"]="$data_location/root"
|
||||
["/emby/cache"]="$data_location/cache"
|
||||
["/emby/config"]="$config_location"
|
||||
["/emby/data"]="$data_location/data"
|
||||
["/emby/logs"]="$data_location/logs"
|
||||
["/emby/metadata"]="$data_location/metadata"
|
||||
["/emby/plugins"]="$data_location/plugins"
|
||||
["/emby/root"]="$data_location/root"
|
||||
)
|
||||
|
||||
for link in "${!links[@]}"; do
|
||||
if [ ! -d "$link" ]; then
|
||||
log "Creating link for $link"
|
||||
mkdir -p "${links[$link]}"
|
||||
chown -R "$PUID:$PGID" "${links[$link]}"
|
||||
ln -s "${links[$link]}" "$link"
|
||||
fi
|
||||
if [ ! -d "$link" ]; then
|
||||
log "Creating link for $link"
|
||||
mkdir -p "${links[$link]}"
|
||||
chown -R "$PUID:$PGID" "${links[$link]}"
|
||||
ln -s "${links[$link]}" "$link"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -7,7 +7,7 @@ set -e
|
||||
###############
|
||||
|
||||
if bashio::config.true 'silent'; then
|
||||
APPEND=' >/dev/null'
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run
|
||||
bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
|
||||
APPEND=' >/dev/null'
|
||||
sed -i '$s|$|'"$APPEND"'|' /etc/s6-overlay/s6-rc.d/svc-emby/run
|
||||
bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
|
||||
fi
|
||||
|
||||
0
emby_beta/rootfs/etc/services.d/nginx/run
Normal file → Executable file
0
emby_beta/rootfs/etc/services.d/nginx/run
Normal file → Executable file
@@ -8,21 +8,21 @@ set -e
|
||||
#####################
|
||||
|
||||
if bashio::config.true 'mqtt_autodiscover'; then
|
||||
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
|
||||
# Check if available
|
||||
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
|
||||
# Get variables
|
||||
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..."
|
||||
export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'"
|
||||
export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'"
|
||||
export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'"
|
||||
export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'"
|
||||
export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'"
|
||||
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
|
||||
# Check if available
|
||||
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
|
||||
# Get variables
|
||||
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..."
|
||||
export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'"
|
||||
export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'"
|
||||
export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'"
|
||||
export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'"
|
||||
export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'"
|
||||
|
||||
# Export variables
|
||||
for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do
|
||||
sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2>/dev/null || true
|
||||
# Log
|
||||
bashio::log.blue "$variables"
|
||||
done
|
||||
# Export variables
|
||||
for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do
|
||||
sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2> /dev/null || true
|
||||
# Log
|
||||
bashio::log.blue "$variables"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -10,7 +10,7 @@ set -e
|
||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
# Check CONFIGSOURCE ends with config.yaml
|
||||
if [ "$(basename "$CONFIGSOURCE")" != "config.yaml" ]; then
|
||||
bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")"
|
||||
bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")"
|
||||
fi
|
||||
DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db"
|
||||
|
||||
@@ -22,8 +22,8 @@ chmod 777 -R "$(dirname "${DATABASESOURCE}")"
|
||||
|
||||
# Check absence of config file
|
||||
if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then
|
||||
bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
|
||||
mv /data/config.yaml "$CONFIGSOURCE".bak
|
||||
bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
|
||||
mv /data/config.yaml "$CONFIGSOURCE".bak
|
||||
fi
|
||||
|
||||
#########################################################
|
||||
@@ -31,24 +31,24 @@ fi
|
||||
#########################################################
|
||||
|
||||
if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then
|
||||
mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/
|
||||
rm -r /config/addons_config/enedisgateway2mqtt_dev
|
||||
mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/
|
||||
rm -r /config/addons_config/enedisgateway2mqtt_dev
|
||||
fi
|
||||
|
||||
# If migration was performed, save file in config folder
|
||||
if [ -f /data/enedisgateway.db.migrate ]; then
|
||||
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
|
||||
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
|
||||
fi
|
||||
|
||||
# If migration was performed, save file in config folder
|
||||
if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then
|
||||
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
|
||||
fi
|
||||
|
||||
# If migration was not performed, enable migration
|
||||
if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then
|
||||
mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data
|
||||
mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data
|
||||
fi
|
||||
|
||||
############
|
||||
@@ -57,15 +57,15 @@ fi
|
||||
|
||||
# Check if database is here or create symlink
|
||||
if [ -f "$DATABASESOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
|
||||
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
|
||||
# Create symlink if not existing yet
|
||||
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
|
||||
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
|
||||
else
|
||||
# Create symlink for addon to create database
|
||||
mkdir -p "$(dirname "$DATABASESOURCE")"
|
||||
touch "${DATABASESOURCE}"
|
||||
ln -sf "$DATABASESOURCE" /data
|
||||
rm "$DATABASESOURCE"
|
||||
# Create symlink for addon to create database
|
||||
mkdir -p "$(dirname "$DATABASESOURCE")"
|
||||
touch "${DATABASESOURCE}"
|
||||
ln -sf "$DATABASESOURCE" /data
|
||||
rm "$DATABASESOURCE"
|
||||
fi
|
||||
|
||||
##########
|
||||
@@ -74,28 +74,28 @@ fi
|
||||
|
||||
# Check if config file is there, or create one from template
|
||||
if [ -f "$CONFIGSOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
# shellcheck disable=SC2015
|
||||
[ -f /data/config.yaml ] && rm /data/config.yaml || true
|
||||
ln -sf "$CONFIGSOURCE" /data || true
|
||||
bashio::log.info "Using config file found in $CONFIGSOURCE"
|
||||
# Create symlink if not existing yet
|
||||
# shellcheck disable=SC2015
|
||||
[ -f /data/config.yaml ] && rm /data/config.yaml || true
|
||||
ln -sf "$CONFIGSOURCE" /data || true
|
||||
bashio::log.info "Using config file found in $CONFIGSOURCE"
|
||||
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$?
|
||||
if [ "$EXIT_CODE" = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
cat ERROR
|
||||
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com"
|
||||
fi
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed "$CONFIGSOURCE" &> ERROR || EXIT_CODE=$?
|
||||
if [ "$EXIT_CODE" = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
cat ERROR
|
||||
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com"
|
||||
fi
|
||||
else
|
||||
# Create symlink for addon to create config
|
||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/
|
||||
ln -sf "$CONFIGSOURCE" /data
|
||||
rm "$CONFIGSOURCE"
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
# Create symlink for addon to create config
|
||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/
|
||||
ln -sf "$CONFIGSOURCE" /data
|
||||
rm "$CONFIGSOURCE"
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
fi
|
||||
|
||||
##############
|
||||
|
||||
@@ -8,21 +8,21 @@ set -e
|
||||
#####################
|
||||
|
||||
if bashio::config.true 'mqtt_autodiscover'; then
|
||||
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
|
||||
# Check if available
|
||||
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
|
||||
# Get variables
|
||||
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..."
|
||||
export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'"
|
||||
export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'"
|
||||
export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'"
|
||||
export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'"
|
||||
export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'"
|
||||
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
|
||||
# Check if available
|
||||
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
|
||||
# Get variables
|
||||
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..."
|
||||
export MQTT_HOST=$(bashio::services mqtt "host") || bashio::log.error "can't fetch bashio::services mqtt 'host'"
|
||||
export MQTT_PORT=$(bashio::services mqtt "port") || bashio::log.error "can't fetch bashio::services mqtt 'port'"
|
||||
export MQTT_SSL=$(bashio::services mqtt "ssl") || bashio::log.error "can't fetch bashio::services mqtt 'ssl'"
|
||||
export MQTT_USERNAME=$(bashio::services mqtt "username") || bashio::log.error "can't fetch bashio::services mqtt 'username'"
|
||||
export MQTT_PASSWORD=$(bashio::services mqtt "password") || bashio::log.error "can't fetch bashio::services mqtt 'password'"
|
||||
|
||||
# Export variables
|
||||
for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do
|
||||
sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2>/dev/null || true
|
||||
# Log
|
||||
bashio::log.blue "$variables"
|
||||
done
|
||||
# Export variables
|
||||
for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do
|
||||
sed -i "1a export $variables" /etc/cont-init.d/*/*run* 2> /dev/null || true
|
||||
# Log
|
||||
bashio::log.blue "$variables"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -10,7 +10,7 @@ set -e
|
||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
# Check CONFIGSOURCE ends with config.yaml
|
||||
if [ "$(basename "$CONFIGSOURCE")" != "config.yaml" ]; then
|
||||
bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")"
|
||||
bashio::log.error "Watchout: your CONFIG_LOCATION should end by config.yaml, and instead it is $(basename "$CONFIGSOURCE")"
|
||||
fi
|
||||
DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/cache.db"
|
||||
|
||||
@@ -22,8 +22,8 @@ chmod 777 -R "$(dirname "${DATABASESOURCE}")"
|
||||
|
||||
# Check absence of config file
|
||||
if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then
|
||||
bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
|
||||
mv /data/config.yaml "$CONFIGSOURCE".bak
|
||||
bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
|
||||
mv /data/config.yaml "$CONFIGSOURCE".bak
|
||||
fi
|
||||
|
||||
#########################################################
|
||||
@@ -31,24 +31,24 @@ fi
|
||||
#########################################################
|
||||
|
||||
if [ -f /config/addons_config/enedisgateway2mqtt_dev/config.yaml ]; then
|
||||
mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/
|
||||
rm -r /config/addons_config/enedisgateway2mqtt_dev
|
||||
mv /config/addons_config/enedisgateway2mqtt_dev/* "$(dirname "${CONFIGSOURCE}")"/
|
||||
rm -r /config/addons_config/enedisgateway2mqtt_dev
|
||||
fi
|
||||
|
||||
# If migration was performed, save file in config folder
|
||||
if [ -f /data/enedisgateway.db.migrate ]; then
|
||||
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
|
||||
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
|
||||
fi
|
||||
|
||||
# If migration was performed, save file in config folder
|
||||
if [ -f /data/cache.db ] && [ ! -f "$DATABASESOURCE" ]; then
|
||||
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
|
||||
fi
|
||||
|
||||
# If migration was not performed, enable migration
|
||||
if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then
|
||||
mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data
|
||||
mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data
|
||||
fi
|
||||
|
||||
############
|
||||
@@ -57,15 +57,15 @@ fi
|
||||
|
||||
# Check if database is here or create symlink
|
||||
if [ -f "$DATABASESOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
|
||||
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
|
||||
# Create symlink if not existing yet
|
||||
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
|
||||
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
|
||||
else
|
||||
# Create symlink for addon to create database
|
||||
mkdir -p "$(dirname "$DATABASESOURCE")"
|
||||
touch "${DATABASESOURCE}"
|
||||
ln -sf "$DATABASESOURCE" /data
|
||||
rm "$DATABASESOURCE"
|
||||
# Create symlink for addon to create database
|
||||
mkdir -p "$(dirname "$DATABASESOURCE")"
|
||||
touch "${DATABASESOURCE}"
|
||||
ln -sf "$DATABASESOURCE" /data
|
||||
rm "$DATABASESOURCE"
|
||||
fi
|
||||
|
||||
##########
|
||||
@@ -74,28 +74,28 @@ fi
|
||||
|
||||
# Check if config file is there, or create one from template
|
||||
if [ -f "$CONFIGSOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
# shellcheck disable=SC2015
|
||||
[ -f /data/config.yaml ] && rm /data/config.yaml || true
|
||||
ln -sf "$CONFIGSOURCE" /data || true
|
||||
bashio::log.info "Using config file found in $CONFIGSOURCE"
|
||||
# Create symlink if not existing yet
|
||||
# shellcheck disable=SC2015
|
||||
[ -f /data/config.yaml ] && rm /data/config.yaml || true
|
||||
ln -sf "$CONFIGSOURCE" /data || true
|
||||
bashio::log.info "Using config file found in $CONFIGSOURCE"
|
||||
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$?
|
||||
if [ "$EXIT_CODE" = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
cat ERROR
|
||||
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com"
|
||||
fi
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed "$CONFIGSOURCE" &> ERROR || EXIT_CODE=$?
|
||||
if [ "$EXIT_CODE" = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
cat ERROR
|
||||
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com"
|
||||
fi
|
||||
else
|
||||
# Create symlink for addon to create config
|
||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/
|
||||
ln -sf "$CONFIGSOURCE" /data
|
||||
rm "$CONFIGSOURCE"
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
# Create symlink for addon to create config
|
||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"/
|
||||
ln -sf "$CONFIGSOURCE" /data
|
||||
rm "$CONFIGSOURCE"
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
fi
|
||||
|
||||
##############
|
||||
|
||||
@@ -104,11 +104,6 @@
|
||||
"DAC_READ_SEARCH"
|
||||
],
|
||||
"schema": {
|
||||
"cifsdomain": "str?",
|
||||
"cifspassword": "str?",
|
||||
"cifsusername": "str?",
|
||||
"localdisks": "str?",
|
||||
"networkdisks": "str?",
|
||||
"DB_DATABASE_NAME": "str?",
|
||||
"DB_HOSTNAME": "str?",
|
||||
"DB_PASSWORD": "str",
|
||||
@@ -120,7 +115,12 @@
|
||||
"MINIO_ROOT_PASSWORD": "str",
|
||||
"MINIO_ROOT_USER": "str",
|
||||
"TZ": "str?",
|
||||
"USE_EXTERNAL_DB": "bool?"
|
||||
"USE_EXTERNAL_DB": "bool?",
|
||||
"cifsdomain": "str?",
|
||||
"cifspassword": "str?",
|
||||
"cifsusername": "str?",
|
||||
"localdisks": "str?",
|
||||
"networkdisks": "str?"
|
||||
},
|
||||
"slug": "ente",
|
||||
"udev": true,
|
||||
|
||||
240
ente/rootfs/etc/cont-init.d/99-run.sh
Executable file → Normal file
240
ente/rootfs/etc/cont-init.d/99-run.sh
Executable file → Normal file
@@ -36,34 +36,34 @@ DB_PORT_EXT="$(bashio::config 'DB_PORT' || echo '')"
|
||||
|
||||
USE_EXTERNAL_DB=false
|
||||
if bashio::config.true 'USE_EXTERNAL_DB'; then
|
||||
USE_EXTERNAL_DB=true
|
||||
bashio::log.warning "USE_EXTERNAL_DB enabled: will connect to external Postgres."
|
||||
USE_EXTERNAL_DB=true
|
||||
bashio::log.warning "USE_EXTERNAL_DB enabled: will connect to external Postgres."
|
||||
else
|
||||
bashio::log.info "Using internal Postgres."
|
||||
bashio::log.info "Using internal Postgres."
|
||||
fi
|
||||
|
||||
DISABLE_WEB_UI=false
|
||||
if bashio::config.true 'DISABLE_WEB_UI'; then
|
||||
DISABLE_WEB_UI=true
|
||||
DISABLE_WEB_UI=true
|
||||
fi
|
||||
|
||||
# Active DB connection target (may be overridden below)
|
||||
if $USE_EXTERNAL_DB; then
|
||||
DB_HOST="$DB_HOST_EXT"
|
||||
DB_PORT="$DB_PORT_EXT"
|
||||
DB_HOST="$DB_HOST_EXT"
|
||||
DB_PORT="$DB_PORT_EXT"
|
||||
else
|
||||
DB_HOST="$DB_HOST_INTERNAL"
|
||||
DB_PORT="$DB_PORT_INTERNAL"
|
||||
DB_HOST="$DB_HOST_INTERNAL"
|
||||
DB_PORT="$DB_PORT_INTERNAL"
|
||||
fi
|
||||
|
||||
############################################
|
||||
# Ensure persistent dirs
|
||||
############################################
|
||||
mkdir -p /config/ente/custom-logs \
|
||||
/config/data \
|
||||
/config/minio-data \
|
||||
"$PGDATA" \
|
||||
/config/scripts/compose
|
||||
/config/data \
|
||||
/config/minio-data \
|
||||
"$PGDATA" \
|
||||
/config/scripts/compose
|
||||
|
||||
############################################
|
||||
# Locate binaries
|
||||
@@ -75,18 +75,18 @@ MC_BIN="/usr/local/bin/mc"
|
||||
|
||||
MUSEUM_BIN="$(command -v museum || true)"
|
||||
[ -z "$MUSEUM_BIN" ] && [ -x /app/museum ] && MUSEUM_BIN=/app/museum
|
||||
[ -z "$MUSEUM_BIN" ] && [ -x /museum ] && MUSEUM_BIN=/museum
|
||||
[ -z "$MUSEUM_BIN" ] && MUSEUM_BIN=museum # fallback in PATH
|
||||
[ -z "$MUSEUM_BIN" ] && [ -x /museum ] && MUSEUM_BIN=/museum
|
||||
[ -z "$MUSEUM_BIN" ] && MUSEUM_BIN=museum # fallback in PATH
|
||||
|
||||
############################################
|
||||
# Config generation
|
||||
############################################
|
||||
create_config() {
|
||||
bashio::log.info "Generating new museum config at $CFG"
|
||||
_rand_b64() { head -c "$1" /dev/urandom | base64 | tr -d '\n'; }
|
||||
_rand_b64url() { head -c "$1" /dev/urandom | base64 | tr '+/' '-_' | tr -d '\n'; }
|
||||
bashio::log.info "Generating new museum config at $CFG"
|
||||
_rand_b64() { head -c "$1" /dev/urandom | base64 | tr -d '\n'; }
|
||||
_rand_b64url() { head -c "$1" /dev/urandom | base64 | tr '+/' '-_' | tr -d '\n'; }
|
||||
|
||||
cat >"$CFG" <<EOF
|
||||
cat > "$CFG" << EOF
|
||||
key:
|
||||
encryption: $(_rand_b64 32)
|
||||
hash: $(_rand_b64 64)
|
||||
@@ -116,146 +116,148 @@ EOF
|
||||
# Postgres
|
||||
############################################
|
||||
start_postgres() {
|
||||
if $USE_EXTERNAL_DB; then
|
||||
bashio::log.info "External DB in use; not starting internal Postgres."
|
||||
return 0
|
||||
fi
|
||||
if $USE_EXTERNAL_DB; then
|
||||
bashio::log.info "External DB in use; not starting internal Postgres."
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p /run/postgresql
|
||||
chown postgres:postgres /run/postgresql
|
||||
chmod 775 /run/postgresql
|
||||
mkdir -p /run/postgresql
|
||||
chown postgres:postgres /run/postgresql
|
||||
chmod 775 /run/postgresql
|
||||
|
||||
chown -R postgres:postgres "$PGDATA"
|
||||
chmod 0700 "$PGDATA"
|
||||
chown -R postgres:postgres "$PGDATA"
|
||||
chmod 0700 "$PGDATA"
|
||||
|
||||
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
|
||||
bashio::log.info "Initializing Postgres data directory..."
|
||||
su - postgres -c "$INITDB -D $PGDATA"
|
||||
fi
|
||||
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
|
||||
bashio::log.info "Initializing Postgres data directory..."
|
||||
su - postgres -c "$INITDB -D $PGDATA"
|
||||
fi
|
||||
|
||||
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'" &
|
||||
PG_PID=$!
|
||||
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'" &
|
||||
PG_PID=$!
|
||||
}
|
||||
|
||||
wait_postgres_ready() {
|
||||
local host port
|
||||
if $USE_EXTERNAL_DB; then
|
||||
host="$DB_HOST_EXT"; port="$DB_PORT_EXT"
|
||||
bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..."
|
||||
else
|
||||
host="$DB_HOST_INTERNAL"; port="$DB_PORT_INTERNAL"
|
||||
bashio::log.info "Waiting for internal Postgres..."
|
||||
fi
|
||||
until pg_isready -q -h "$host" -p "$port"; do sleep 1; done
|
||||
bashio::log.info "Postgres reachable."
|
||||
local host port
|
||||
if $USE_EXTERNAL_DB; then
|
||||
host="$DB_HOST_EXT"
|
||||
port="$DB_PORT_EXT"
|
||||
bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..."
|
||||
else
|
||||
host="$DB_HOST_INTERNAL"
|
||||
port="$DB_PORT_INTERNAL"
|
||||
bashio::log.info "Waiting for internal Postgres..."
|
||||
fi
|
||||
until pg_isready -q -h "$host" -p "$port"; do sleep 1; done
|
||||
bashio::log.info "Postgres reachable."
|
||||
}
|
||||
|
||||
bootstrap_internal_db() {
|
||||
if $USE_EXTERNAL_DB; then
|
||||
return 0
|
||||
fi
|
||||
if $USE_EXTERNAL_DB; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
bashio::log.info "Ensuring role & database exist..."
|
||||
local esc_pass="${DB_PASS//\'/\'\'}"
|
||||
bashio::log.info "Ensuring role & database exist..."
|
||||
local esc_pass="${DB_PASS//\'/\'\'}"
|
||||
|
||||
# role
|
||||
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
|
||||
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}';"
|
||||
else
|
||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||
-c "ALTER ROLE \"${DB_USER}\" PASSWORD '${esc_pass}';"
|
||||
fi
|
||||
# role
|
||||
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
|
||||
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}';"
|
||||
else
|
||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||
-c "ALTER ROLE \"${DB_USER}\" PASSWORD '${esc_pass}';"
|
||||
fi
|
||||
|
||||
# db
|
||||
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
|
||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||
-c "CREATE DATABASE \"${DB_NAME}\" OWNER \"${DB_USER}\";"
|
||||
else
|
||||
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}\";"
|
||||
fi
|
||||
# db
|
||||
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
|
||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||
-c "CREATE DATABASE \"${DB_NAME}\" OWNER \"${DB_USER}\";"
|
||||
else
|
||||
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}\";"
|
||||
fi
|
||||
}
|
||||
|
||||
############################################
|
||||
# MinIO
|
||||
############################################
|
||||
start_minio() {
|
||||
bashio::log.info "Starting MinIO (:3200)..."
|
||||
mkdir -p /config/minio-data
|
||||
"$MINIO_BIN" server /config/minio-data --address ":3200" &
|
||||
MINIO_PID=$!
|
||||
bashio::log.info "Starting MinIO (:3200)..."
|
||||
mkdir -p /config/minio-data
|
||||
"$MINIO_BIN" server /config/minio-data --address ":3200" &
|
||||
MINIO_PID=$!
|
||||
}
|
||||
|
||||
wait_minio_ready_and_bucket() {
|
||||
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
|
||||
sleep 1
|
||||
done
|
||||
bashio::log.info "Ensuring buckets..."
|
||||
"$MC_BIN" mb -p "h0/${S3_BUCKET}" || true
|
||||
bashio::log.info "MinIO buckets ready."
|
||||
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
|
||||
sleep 1
|
||||
done
|
||||
bashio::log.info "Ensuring buckets..."
|
||||
"$MC_BIN" mb -p "h0/${S3_BUCKET}" || true
|
||||
bashio::log.info "MinIO buckets ready."
|
||||
}
|
||||
|
||||
############################################
|
||||
# Web (static nginx bundle)
|
||||
############################################
|
||||
start_web() {
|
||||
if $DISABLE_WEB_UI; then
|
||||
bashio::log.info "Web UI disabled."
|
||||
return 0
|
||||
fi
|
||||
if $DISABLE_WEB_UI; then
|
||||
bashio::log.info "Web UI disabled."
|
||||
return 0
|
||||
fi
|
||||
|
||||
ENTE_API_ORIGIN=http://localhost:8080
|
||||
ENTE_ALBUMS_ORIGIN=http://localhost:3002
|
||||
export ENTE_API_ORIGIN ENTE_ALBUMS_ORIGIN
|
||||
ENTE_API_ORIGIN=http://localhost:8080
|
||||
ENTE_ALBUMS_ORIGIN=http://localhost:3002
|
||||
export ENTE_API_ORIGIN ENTE_ALBUMS_ORIGIN
|
||||
|
||||
# Running ente-web-prepare
|
||||
echo "[ente-web-prepare] Substituting origins…"
|
||||
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"
|
||||
# Running ente-web-prepare
|
||||
echo "[ente-web-prepare] Substituting origins…"
|
||||
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"
|
||||
|
||||
mkdir -p /run/nginx /var/log/nginx
|
||||
mkdir -p /run/nginx /var/log/nginx
|
||||
|
||||
# Set nginx
|
||||
mv /etc/nginx/http.d/web.bak /etc/nginx/http.d/web.conf
|
||||
# Set nginx
|
||||
mv /etc/nginx/http.d/web.bak /etc/nginx/http.d/web.conf
|
||||
|
||||
bashio::log.info "Starting Ente web (nginx, ports 3000‑3004)..."
|
||||
exec nginx -g 'daemon off;' &
|
||||
WEB_PID=$!
|
||||
bashio::log.info "Starting Ente web (nginx, ports 3000‑3004)..."
|
||||
exec nginx -g 'daemon off;' &
|
||||
WEB_PID=$!
|
||||
}
|
||||
|
||||
############################################
|
||||
# Museum (API)
|
||||
############################################
|
||||
start_museum_foreground() {
|
||||
if [ ! -f "$CFG" ]; then
|
||||
bashio::log.error "$CFG missing; cannot start museum."
|
||||
return 1
|
||||
fi
|
||||
if [ ! -x "$MUSEUM_BIN" ] && ! command -v "$MUSEUM_BIN" >/dev/null 2>&1; then
|
||||
bashio::log.error "Museum binary not found; cannot launch Ente API."
|
||||
return 1
|
||||
fi
|
||||
if [ ! -f "$CFG" ]; then
|
||||
bashio::log.error "$CFG missing; cannot start museum."
|
||||
return 1
|
||||
fi
|
||||
if [ ! -x "$MUSEUM_BIN" ] && ! command -v "$MUSEUM_BIN" > /dev/null 2>&1; then
|
||||
bashio::log.error "Museum binary not found; cannot launch Ente API."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Force env overrides (museum merges env > yaml)
|
||||
if $USE_EXTERNAL_DB; then
|
||||
export ENTE_DB_HOST="$DB_HOST_EXT"
|
||||
export ENTE_DB_PORT="$DB_PORT_EXT"
|
||||
else
|
||||
export ENTE_DB_HOST="$DB_HOST_INTERNAL"
|
||||
export ENTE_DB_PORT="$DB_PORT_INTERNAL"
|
||||
fi
|
||||
export ENTE_DB_USER="$DB_USER"
|
||||
export ENTE_DB_PASSWORD="$DB_PASS"
|
||||
export ENTE_DB_NAME="$DB_NAME"
|
||||
export ENTE_DB_SSLMODE=disable
|
||||
# Force env overrides (museum merges env > yaml)
|
||||
if $USE_EXTERNAL_DB; then
|
||||
export ENTE_DB_HOST="$DB_HOST_EXT"
|
||||
export ENTE_DB_PORT="$DB_PORT_EXT"
|
||||
else
|
||||
export ENTE_DB_HOST="$DB_HOST_INTERNAL"
|
||||
export ENTE_DB_PORT="$DB_PORT_INTERNAL"
|
||||
fi
|
||||
export ENTE_DB_USER="$DB_USER"
|
||||
export ENTE_DB_PASSWORD="$DB_PASS"
|
||||
export ENTE_DB_NAME="$DB_NAME"
|
||||
export ENTE_DB_SSLMODE=disable
|
||||
|
||||
bashio::log.info "Starting museum (foreground)..."
|
||||
exec "$MUSEUM_BIN" --config "$CFG"
|
||||
bashio::log.info "Starting museum (foreground)..."
|
||||
exec "$MUSEUM_BIN" --config "$CFG"
|
||||
}
|
||||
|
||||
############################################
|
||||
@@ -264,9 +266,9 @@ start_museum_foreground() {
|
||||
bashio::log.info "=== Ente startup sequence ==="
|
||||
|
||||
if [ ! -f "$CFG" ]; then
|
||||
create_config
|
||||
create_config
|
||||
else
|
||||
bashio::log.info "Using existing $CFG."
|
||||
bashio::log.info "Using existing $CFG."
|
||||
fi
|
||||
|
||||
start_postgres
|
||||
|
||||
@@ -8,14 +8,14 @@ set -e
|
||||
|
||||
HOME="/config/addons_config/epicgamesfree"
|
||||
if [ ! -f "$HOME"/config.json ]; then
|
||||
# Copy default config.json
|
||||
cp /templates/config.json "$HOME"/config.json
|
||||
chmod 777 "$HOME"/config.json
|
||||
bashio::log.warning "A default config.json file was copied in $HOME. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on"
|
||||
sleep 5
|
||||
bashio::exit.nok
|
||||
# Copy default config.json
|
||||
cp /templates/config.json "$HOME"/config.json
|
||||
chmod 777 "$HOME"/config.json
|
||||
bashio::log.warning "A default config.json file was copied in $HOME. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on"
|
||||
sleep 5
|
||||
bashio::exit.nok
|
||||
else
|
||||
bashio::log.warning "The config.json file found in $HOME will be used. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on"
|
||||
bashio::log.warning "The config.json file found in $HOME will be used. Please customize according to https://github.com/claabs/epicgames-freegames-node#json-configuration and restart the add-on"
|
||||
fi
|
||||
|
||||
# Permissions
|
||||
|
||||
@@ -7,9 +7,9 @@ set -e
|
||||
####################
|
||||
|
||||
if [ -f /homeassistant/addons_config/filebrowser/filebrowser.dB ]; then
|
||||
echo "Moving database to new location /config"
|
||||
cp -rnf /homeassistant/addons_config/filebrowser/* /config/
|
||||
rm -r /homeassistant/addons_config/filebrowser
|
||||
echo "Moving database to new location /config"
|
||||
cp -rnf /homeassistant/addons_config/filebrowser/* /config/
|
||||
rm -r /homeassistant/addons_config/filebrowser
|
||||
fi
|
||||
|
||||
######################
|
||||
@@ -19,24 +19,24 @@ fi
|
||||
# Clean symlinks
|
||||
find /config -maxdepth 1 -type l -delete
|
||||
if [ -d /homeassistant/addons_config ]; then
|
||||
find /homeassistant/addons_config -maxdepth 1 -type l -delete
|
||||
find /homeassistant/addons_config -maxdepth 1 -type l -delete
|
||||
fi
|
||||
|
||||
# Remove erroneous folders
|
||||
if [ -d /homeassistant ]; then
|
||||
if [ -d /config/addons_config ]; then
|
||||
rm -r /config/addons_config
|
||||
fi
|
||||
if [ -d /config/addons_autoscripts ]; then
|
||||
rm -r /config/addons_autoscripts
|
||||
fi
|
||||
if [ -d /config/addons_config ]; then
|
||||
rm -r /config/addons_config
|
||||
fi
|
||||
if [ -d /config/addons_autoscripts ]; then
|
||||
rm -r /config/addons_autoscripts
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create symlinks with legacy folders
|
||||
if [ -d /homeassistant/addons_config ]; then
|
||||
ln -s /homeassistant/addons_config /config
|
||||
find /addon_configs/ -maxdepth 1 -mindepth 1 -type d -not -name "*filebrowser*" -exec ln -s {} /config/addons_config/ \;
|
||||
ln -s /homeassistant/addons_config /config
|
||||
find /addon_configs/ -maxdepth 1 -mindepth 1 -type d -not -name "*filebrowser*" -exec ln -s {} /config/addons_config/ \;
|
||||
fi
|
||||
if [ -d /homeassistant/addons_autoscripts ]; then
|
||||
ln -s /homeassistant/addons_autoscripts /config
|
||||
ln -s /homeassistant/addons_autoscripts /config
|
||||
fi
|
||||
|
||||
@@ -7,14 +7,14 @@ set -e
|
||||
############
|
||||
|
||||
if bashio::config.has_value 'TZ'; then
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" >/etc/timezone
|
||||
else
|
||||
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
|
||||
fi
|
||||
TIMEZONE=$(bashio::config 'TZ')
|
||||
bashio::log.info "Setting timezone to $TIMEZONE"
|
||||
if [ -f /usr/share/zoneinfo/"$TIMEZONE" ]; then
|
||||
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
|
||||
echo "$TIMEZONE" > /etc/timezone
|
||||
else
|
||||
bashio::log.fatal "$TIMEZONE not found, are you sure it is a valid timezone?"
|
||||
fi
|
||||
fi
|
||||
|
||||
###################
|
||||
@@ -23,13 +23,13 @@ fi
|
||||
|
||||
bashio::config.require.ssl
|
||||
if bashio::config.true 'ssl'; then
|
||||
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths"
|
||||
#set variables
|
||||
CERTFILE="-t /ssl/$(bashio::config 'certfile')"
|
||||
KEYFILE="-k /ssl/$(bashio::config 'keyfile')"
|
||||
bashio::log.info "ssl enabled. If webui don't work, disable ssl or check your certificate paths"
|
||||
#set variables
|
||||
CERTFILE="-t /ssl/$(bashio::config 'certfile')"
|
||||
KEYFILE="-k /ssl/$(bashio::config 'keyfile')"
|
||||
else
|
||||
CERTFILE=""
|
||||
KEYFILE=""
|
||||
CERTFILE=""
|
||||
KEYFILE=""
|
||||
fi
|
||||
|
||||
#################
|
||||
@@ -48,7 +48,7 @@ export FB_BASEURL
|
||||
declare ADDON_PROTOCOL=http
|
||||
# Generate Ingress configuration
|
||||
if bashio::config.true 'ssl'; then
|
||||
ADDON_PROTOCOL=https
|
||||
ADDON_PROTOCOL=https
|
||||
fi
|
||||
|
||||
#port=$(bashio::addon.port 80)
|
||||
@@ -67,41 +67,41 @@ mkdir -p /var/log/nginx && touch /var/log/nginx/error.log
|
||||
NOAUTH=""
|
||||
|
||||
if bashio::config.true 'NoAuth'; then
|
||||
if ! bashio::fs.file_exists "/data/noauth"; then
|
||||
rm /data/auth &>/dev/null || true
|
||||
rm /config/filebrowser.dB &>/dev/null || true
|
||||
touch /data/noauth
|
||||
NOAUTH="--noauth"
|
||||
bashio::log.warning "Auth method change, database reset"
|
||||
fi
|
||||
bashio::log.info "NoAuth option selected"
|
||||
if ! bashio::fs.file_exists "/data/noauth"; then
|
||||
rm /data/auth &> /dev/null || true
|
||||
rm /config/filebrowser.dB &> /dev/null || true
|
||||
touch /data/noauth
|
||||
NOAUTH="--noauth"
|
||||
bashio::log.warning "Auth method change, database reset"
|
||||
fi
|
||||
bashio::log.info "NoAuth option selected"
|
||||
else
|
||||
if ! bashio::fs.file_exists "/data/auth"; then
|
||||
rm /data/noauth &>/dev/null || true
|
||||
rm /config/filebrowser.dB &>/dev/null || true
|
||||
touch /data/auth
|
||||
bashio::log.warning "Auth method change, database reset"
|
||||
fi
|
||||
bashio::log.info "Default username/password : admin/admin"
|
||||
if ! bashio::fs.file_exists "/data/auth"; then
|
||||
rm /data/noauth &> /dev/null || true
|
||||
rm /config/filebrowser.dB &> /dev/null || true
|
||||
touch /data/auth
|
||||
bashio::log.warning "Auth method change, database reset"
|
||||
fi
|
||||
bashio::log.info "Default username/password : admin/admin"
|
||||
fi
|
||||
|
||||
# Set base folder
|
||||
if bashio::config.has_value 'base_folder'; then
|
||||
BASE_FOLDER=$(bashio::config 'base_folder')
|
||||
BASE_FOLDER=$(bashio::config 'base_folder')
|
||||
else
|
||||
BASE_FOLDER=/
|
||||
BASE_FOLDER=/
|
||||
fi
|
||||
|
||||
# Disable thumbnails
|
||||
if bashio::config.true 'disable_thumbnails'; then
|
||||
DISABLE_THUMBNAILS="--disable-thumbnails"
|
||||
DISABLE_THUMBNAILS="--disable-thumbnails"
|
||||
else
|
||||
DISABLE_THUMBNAILS=""
|
||||
DISABLE_THUMBNAILS=""
|
||||
fi
|
||||
|
||||
# Remove configuration file
|
||||
if [ -f /.filebrowser.json ]; then
|
||||
rm /.filebrowser.json
|
||||
rm /.filebrowser.json
|
||||
fi
|
||||
|
||||
bashio::log.info "Starting..."
|
||||
|
||||
@@ -12,8 +12,8 @@ APP_KEY="$(bashio::config 'APP_KEY')"
|
||||
|
||||
# If not base64
|
||||
if [[ ! "$APP_KEY" == *"base64"* ]]; then
|
||||
# Check APP_KEY format
|
||||
if [ ! "${#APP_KEY}" = 32 ]; then bashio::exit.nok "Your APP_KEY has ${#APP_KEY} instead of 32 characters"; fi
|
||||
# Check APP_KEY format
|
||||
if [ ! "${#APP_KEY}" = 32 ]; then bashio::exit.nok "Your APP_KEY has ${#APP_KEY} instead of 32 characters"; fi
|
||||
fi
|
||||
|
||||
# Backup APP_KEY file
|
||||
@@ -27,7 +27,7 @@ CURRENT=$(sed -e '/^[<blank><tab>]*$/d' /config/addons_config/fireflyiii/APP_KEY
|
||||
|
||||
# Save if new
|
||||
if [ "$CURRENT" != "$APP_KEY" ]; then
|
||||
echo "$APP_KEY" >>/config/addons_config/fireflyiii/APP_KEY_BACKUP.txt
|
||||
echo "$APP_KEY" >> /config/addons_config/fireflyiii/APP_KEY_BACKUP.txt
|
||||
fi
|
||||
|
||||
# Update permissions
|
||||
@@ -43,83 +43,83 @@ chmod -R 775 /config/addons_config/fireflyiii
|
||||
bashio::log.info "Defining database"
|
||||
case $(bashio::config 'DB_CONNECTION') in
|
||||
|
||||
# Use sqlite
|
||||
sqlite_internal)
|
||||
bashio::log.info "Using built in sqlite"
|
||||
# Use sqlite
|
||||
sqlite_internal)
|
||||
bashio::log.info "Using built in sqlite"
|
||||
|
||||
# Set variable
|
||||
export DB_CONNECTION=sqlite
|
||||
export DB_DATABASE=/config/addons_config/fireflyiii/database/database.sqlite
|
||||
# Set variable
|
||||
export DB_CONNECTION=sqlite
|
||||
export DB_DATABASE=/config/addons_config/fireflyiii/database/database.sqlite
|
||||
|
||||
# Creating folders
|
||||
mkdir -p /config/addons_config/fireflyiii/database
|
||||
chown -R www-data:www-data /config/addons_config/fireflyiii/database
|
||||
# Creating folders
|
||||
mkdir -p /config/addons_config/fireflyiii/database
|
||||
chown -R www-data:www-data /config/addons_config/fireflyiii/database
|
||||
|
||||
# Creating database
|
||||
if [ ! -f /config/addons_config/fireflyiii/database/database.sqlite ]; then
|
||||
# Create database
|
||||
touch /config/addons_config/fireflyiii/database/database.sqlite
|
||||
# Install database
|
||||
echo "updating database"
|
||||
php artisan migrate:refresh --seed --quiet
|
||||
php artisan firefly-iii:upgrade-database --quiet
|
||||
php artisan passport:install --quiet
|
||||
fi
|
||||
# Creating database
|
||||
if [ ! -f /config/addons_config/fireflyiii/database/database.sqlite ]; then
|
||||
# Create database
|
||||
touch /config/addons_config/fireflyiii/database/database.sqlite
|
||||
# Install database
|
||||
echo "updating database"
|
||||
php artisan migrate:refresh --seed --quiet
|
||||
php artisan firefly-iii:upgrade-database --quiet
|
||||
php artisan passport:install --quiet
|
||||
fi
|
||||
|
||||
# Creating symlink
|
||||
rm -r /var/www/html/storage/database
|
||||
ln -s /config/addons_config/fireflyiii/database /var/www/html/storage
|
||||
# Creating symlink
|
||||
rm -r /var/www/html/storage/database
|
||||
ln -s /config/addons_config/fireflyiii/database /var/www/html/storage
|
||||
|
||||
# Updating permissions
|
||||
chmod 775 /config/addons_config/fireflyiii/database/database.sqlite
|
||||
chown -R www-data:www-data /config/addons_config/fireflyiii
|
||||
chown -R www-data:www-data /var/www/html/storage
|
||||
;;
|
||||
# Updating permissions
|
||||
chmod 775 /config/addons_config/fireflyiii/database/database.sqlite
|
||||
chown -R www-data:www-data /config/addons_config/fireflyiii
|
||||
chown -R www-data:www-data /var/www/html/storage
|
||||
;;
|
||||
|
||||
# Use MariaDB
|
||||
mariadb_addon)
|
||||
bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..."
|
||||
if ! bashio::services.available 'mysql'; then
|
||||
bashio::log.fatal \
|
||||
"Local database access should be provided by the MariaDB addon"
|
||||
bashio::exit.nok \
|
||||
"Please ensure it is installed and started"
|
||||
fi
|
||||
# Use MariaDB
|
||||
mariadb_addon)
|
||||
bashio::log.info "Using MariaDB addon. Requirements : running MariaDB addon. Detecting values..."
|
||||
if ! bashio::services.available 'mysql'; then
|
||||
bashio::log.fatal \
|
||||
"Local database access should be provided by the MariaDB addon"
|
||||
bashio::exit.nok \
|
||||
"Please ensure it is installed and started"
|
||||
fi
|
||||
|
||||
# Use values
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=$(bashio::services "mysql" "host")
|
||||
DB_PORT=$(bashio::services "mysql" "port")
|
||||
DB_DATABASE=firefly
|
||||
DB_USERNAME=$(bashio::services "mysql" "username")
|
||||
DB_PASSWORD=$(bashio::services "mysql" "password")
|
||||
export DB_CONNECTION
|
||||
export DB_HOST && bashio::log.blue "DB_HOST=$DB_HOST"
|
||||
export DB_PORT && bashio::log.blue "DB_PORT=$DB_PORT"
|
||||
export DB_DATABASE && bashio::log.blue "DB_DATABASE=$DB_DATABASE"
|
||||
export DB_USERNAME && bashio::log.blue "DB_USERNAME=$DB_USERNAME"
|
||||
export DB_PASSWORD && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD"
|
||||
# Use values
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=$(bashio::services "mysql" "host")
|
||||
DB_PORT=$(bashio::services "mysql" "port")
|
||||
DB_DATABASE=firefly
|
||||
DB_USERNAME=$(bashio::services "mysql" "username")
|
||||
DB_PASSWORD=$(bashio::services "mysql" "password")
|
||||
export DB_CONNECTION
|
||||
export DB_HOST && bashio::log.blue "DB_HOST=$DB_HOST"
|
||||
export DB_PORT && bashio::log.blue "DB_PORT=$DB_PORT"
|
||||
export DB_DATABASE && bashio::log.blue "DB_DATABASE=$DB_DATABASE"
|
||||
export DB_USERNAME && bashio::log.blue "DB_USERNAME=$DB_USERNAME"
|
||||
export DB_PASSWORD && bashio::log.blue "DB_PASSWORD=$DB_PASSWORD"
|
||||
|
||||
bashio::log.warning "Firefly-iii is using the Maria DB addon"
|
||||
bashio::log.warning "Please ensure this is included in your backups"
|
||||
bashio::log.warning "Uninstalling the MariaDB addon will remove any data"
|
||||
bashio::log.warning "Firefly-iii is using the Maria DB addon"
|
||||
bashio::log.warning "Please ensure this is included in your backups"
|
||||
bashio::log.warning "Uninstalling the MariaDB addon will remove any data"
|
||||
|
||||
bashio::log.info "Creating database for Firefly-iii if required"
|
||||
mysql \
|
||||
-u "${DB_USERNAME}" -p"${DB_PASSWORD}" \
|
||||
-h "${DB_HOST}" -P "${DB_PORT}" \
|
||||
-e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;"
|
||||
;;
|
||||
bashio::log.info "Creating database for Firefly-iii if required"
|
||||
mysql \
|
||||
-u "${DB_USERNAME}" -p"${DB_PASSWORD}" \
|
||||
-h "${DB_HOST}" -P "${DB_PORT}" \
|
||||
-e "CREATE DATABASE IF NOT EXISTS \`firefly\` ;"
|
||||
;;
|
||||
|
||||
# Use remote
|
||||
*)
|
||||
bashio::log.info "Using remote database. Requirement : filling all addon options fields, and making sure the database already exists"
|
||||
for conditions in "DB_HOST" "DB_PORT" "DB_DATABASE" "DB_USERNAME" "DB_PASSWORD"; do
|
||||
if ! bashio::config.has_value "$conditions"; then
|
||||
bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
# Use remote
|
||||
*)
|
||||
bashio::log.info "Using remote database. Requirement : filling all addon options fields, and making sure the database already exists"
|
||||
for conditions in "DB_HOST" "DB_PORT" "DB_DATABASE" "DB_USERNAME" "DB_PASSWORD"; do
|
||||
if ! bashio::config.has_value "$conditions"; then
|
||||
bashio::exit.nok "Remote database has been specified but $conditions is not defined in addon options"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
@@ -131,13 +131,13 @@ bashio::log.info "Defining upload folder"
|
||||
|
||||
# Creating folder
|
||||
if [ ! -d /config/addons_config/fireflyiii/upload ]; then
|
||||
mkdir -p /config/addons_config/fireflyiii/upload
|
||||
chown -R www-data:www-data /config/addons_config/fireflyiii/upload
|
||||
mkdir -p /config/addons_config/fireflyiii/upload
|
||||
chown -R www-data:www-data /config/addons_config/fireflyiii/upload
|
||||
fi
|
||||
|
||||
# Creating symlink
|
||||
if [ -d /var/www/html/storage/ha_upload ]; then
|
||||
rm -r /var/www/html/storage/ha_upload
|
||||
rm -r /var/www/html/storage/ha_upload
|
||||
fi
|
||||
ln -s /config/addons_config/fireflyiii/upload /var/www/html/storage/ha_upload
|
||||
|
||||
@@ -149,8 +149,8 @@ chmod -R 775 /config/addons_config/fireflyiii
|
||||
# Test
|
||||
f=/config/addons_config/fireflyiii
|
||||
while [[ $f != / ]]; do
|
||||
chmod 777 "$f"
|
||||
f=$(dirname "$f")
|
||||
chmod 777 "$f"
|
||||
f=$(dirname "$f")
|
||||
done
|
||||
|
||||
################
|
||||
@@ -158,21 +158,21 @@ done
|
||||
################
|
||||
|
||||
if bashio::config.has_value 'Updates'; then
|
||||
# Align update with options
|
||||
echo ""
|
||||
FREQUENCY=$(bashio::config 'Updates')
|
||||
bashio::log.info "$FREQUENCY updates"
|
||||
echo ""
|
||||
# Align update with options
|
||||
echo ""
|
||||
FREQUENCY=$(bashio::config 'Updates')
|
||||
bashio::log.info "$FREQUENCY updates"
|
||||
echo ""
|
||||
|
||||
# Sets cron // do not delete this message
|
||||
cp /templates/cronupdate /etc/cron."${FREQUENCY}"/
|
||||
chmod 777 /etc/cron."${FREQUENCY}"/cronupdate
|
||||
# Sets cron // do not delete this message
|
||||
cp /templates/cronupdate /etc/cron."${FREQUENCY}"/
|
||||
chmod 777 /etc/cron."${FREQUENCY}"/cronupdate
|
||||
|
||||
# Sets cron to run with www-data user
|
||||
# sed -i 's|root|www-data|g' /etc/crontab
|
||||
# Sets cron to run with www-data user
|
||||
# sed -i 's|root|www-data|g' /etc/crontab
|
||||
|
||||
# Starts cron
|
||||
service cron start
|
||||
# Starts cron
|
||||
service cron start
|
||||
fi
|
||||
|
||||
##############
|
||||
@@ -182,8 +182,8 @@ fi
|
||||
bashio::log.info "Please wait while the app is loading !"
|
||||
|
||||
if bashio::config.true 'silent'; then
|
||||
bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug"
|
||||
sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh >/dev/null'
|
||||
bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug"
|
||||
sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh >/dev/null'
|
||||
else
|
||||
sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh'
|
||||
sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh'
|
||||
fi
|
||||
|
||||
@@ -5,17 +5,17 @@ set -e
|
||||
slug=fireflyiii_data_importer
|
||||
|
||||
if [[ "$(bashio::config "CONFIG_LOCATION")" == *"/addons_config/fireflyiii_data_importer"* ]]; then
|
||||
bashio::log.warning "Reset CONFIG_LOCATION to /config"
|
||||
bashio::addon.option "CONFIG_LOCATION" "/config"
|
||||
bashio::addon.restart
|
||||
bashio::log.warning "Reset CONFIG_LOCATION to /config"
|
||||
bashio::addon.option "CONFIG_LOCATION" "/config"
|
||||
bashio::addon.restart
|
||||
fi
|
||||
|
||||
CONFIGSOURCE="$(bashio::config "CONFIG_LOCATION")"
|
||||
|
||||
if [ -d "/homeassistant/addons_config/$slug" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then
|
||||
echo "Migrating /homeassistant/addons_config/$slug"
|
||||
mv /homeassistant/addons_config/"$slug"/* "$CONFIGSOURCE"/
|
||||
touch /homeassistant/addons_config/$slug/migrated
|
||||
echo "Migrating /homeassistant/addons_config/$slug"
|
||||
mv /homeassistant/addons_config/"$slug"/* "$CONFIGSOURCE"/
|
||||
touch /homeassistant/addons_config/$slug/migrated
|
||||
fi
|
||||
|
||||
# Create directory
|
||||
|
||||
@@ -9,9 +9,9 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
#################
|
||||
|
||||
if [ "$(ls -A "$CONFIGSOURCE/configurations")" ]; then
|
||||
bashio::log.info "Configurations were found in $CONFIGSOURCE/configurations, they will be loaded."
|
||||
JSON_CONFIGURATION_DIR="$CONFIGSOURCE/configurations"
|
||||
export JSON_CONFIGURATION_DIR
|
||||
bashio::log.info "Configurations were found in $CONFIGSOURCE/configurations, they will be loaded."
|
||||
JSON_CONFIGURATION_DIR="$CONFIGSOURCE/configurations"
|
||||
export JSON_CONFIGURATION_DIR
|
||||
fi
|
||||
|
||||
# Allow config dir
|
||||
@@ -31,36 +31,36 @@ export CAN_POST_AUTOIMPORT="$(bashio::config "CAN_POST_AUTOIMPORT")"
|
||||
|
||||
if bashio::config.has_value 'Updates'; then
|
||||
|
||||
# Align update with options
|
||||
echo ""
|
||||
FREQUENCY=$(bashio::config 'Updates')
|
||||
bashio::log.info "$FREQUENCY updates"
|
||||
echo ""
|
||||
# Align update with options
|
||||
echo ""
|
||||
FREQUENCY=$(bashio::config 'Updates')
|
||||
bashio::log.info "$FREQUENCY updates"
|
||||
echo ""
|
||||
|
||||
# Sets cron // do not delete this message
|
||||
cp /templates/cronupdate /etc/cron."${FREQUENCY}"/
|
||||
chmod 777 /etc/cron."${FREQUENCY}"/cronupdate
|
||||
# Sets cron // do not delete this message
|
||||
cp /templates/cronupdate /etc/cron."${FREQUENCY}"/
|
||||
chmod 777 /etc/cron."${FREQUENCY}"/cronupdate
|
||||
|
||||
# Sets cron to run with www-data user
|
||||
# sed -i 's|root|www-data|g' /etc/crontab
|
||||
# Sets cron to run with www-data user
|
||||
# sed -i 's|root|www-data|g' /etc/crontab
|
||||
|
||||
# Starts cron
|
||||
service cron start
|
||||
# Starts cron
|
||||
service cron start
|
||||
|
||||
# Export variables
|
||||
IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
|
||||
export IMPORT_DIR_WHITELIST
|
||||
# Export variables
|
||||
IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
|
||||
export IMPORT_DIR_WHITELIST
|
||||
|
||||
bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE}/import_files will be imported $FREQUENCY."
|
||||
bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE}/import_files will be imported $FREQUENCY."
|
||||
|
||||
if [ ! "$(ls -A "${CONFIGSOURCE}"/import_files)" ]; then
|
||||
bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}/import_files. There will therefore be be no automatic updates."
|
||||
true
|
||||
fi
|
||||
if [ ! "$(ls -A "${CONFIGSOURCE}"/import_files)" ]; then
|
||||
bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}/import_files. There will therefore be be no automatic updates."
|
||||
true
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
bashio::log.info "Automatic updates not set in addon config. If you add configuration files in ${CONFIGSOURCE}/import_files, they won't be automatically updated."
|
||||
bashio::log.info "Automatic updates not set in addon config. If you add configuration files in ${CONFIGSOURCE}/import_files, they won't be automatically updated."
|
||||
|
||||
fi
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ mkdir -p "$CONFIGSOURCE"
|
||||
|
||||
# If no file, provide example
|
||||
if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /data/configurations ]; then
|
||||
cp -r /data/configurations/* "$CONFIGSOURCE"/ || true
|
||||
rm -r /data/configurations
|
||||
cp -r /data/configurations/* "$CONFIGSOURCE"/ || true
|
||||
rm -r /data/configurations
|
||||
fi
|
||||
|
||||
if [ ! "$(ls -A "${CONFIGSOURCE}")" ] && [ -f /app/configurations ]; then
|
||||
cp -r /app/configurations/* "$CONFIGSOURCE"/ || true
|
||||
rm -r /app/configurations
|
||||
cp -r /app/configurations/* "$CONFIGSOURCE"/ || true
|
||||
rm -r /app/configurations
|
||||
fi
|
||||
|
||||
ln -sf "$CONFIGSOURCE" /data/configurations
|
||||
|
||||
@@ -9,9 +9,9 @@ CONFIGSOURCE="/config/addons_config/fireflyiii_fints_importer"
|
||||
#################
|
||||
|
||||
if [ "$(ls -A "$CONFIGSOURCE")" ]; then
|
||||
bashio::log.info "Configurations were found in $CONFIGSOURCE, they will be loaded."
|
||||
bashio::log.info "Configurations were found in $CONFIGSOURCE, they will be loaded."
|
||||
else
|
||||
bashio::log.warning "No configurations in $CONFIGSOURCE, you'll need to input the infos manually."
|
||||
bashio::log.warning "No configurations in $CONFIGSOURCE, you'll need to input the infos manually."
|
||||
fi
|
||||
|
||||
################
|
||||
@@ -20,43 +20,43 @@ fi
|
||||
|
||||
if bashio::config.has_value 'Updates'; then
|
||||
|
||||
if [ "$(ls -A "${CONFIGSOURCE}")" ]; then
|
||||
if [ "$(ls -A "${CONFIGSOURCE}")" ]; then
|
||||
|
||||
# Align update with options
|
||||
echo ""
|
||||
FREQUENCY=$(bashio::config 'Updates')
|
||||
bashio::log.info "$FREQUENCY updates"
|
||||
echo ""
|
||||
# Align update with options
|
||||
echo ""
|
||||
FREQUENCY=$(bashio::config 'Updates')
|
||||
bashio::log.info "$FREQUENCY updates"
|
||||
echo ""
|
||||
|
||||
for i in $(seq 4 2 12); do
|
||||
hour=" $i"
|
||||
freqDir="/etc/periodic/daily$i"
|
||||
echo "0 ${hour:(-4)} * * * run-parts \"$freqDir\"" >>/etc/crontabs/root
|
||||
mkdir "$freqDir"
|
||||
done
|
||||
for i in $(seq 4 2 12); do
|
||||
hour=" $i"
|
||||
freqDir="/etc/periodic/daily$i"
|
||||
echo "0 ${hour:(-4)} * * * run-parts \"$freqDir\"" >> /etc/crontabs/root
|
||||
mkdir "$freqDir"
|
||||
done
|
||||
|
||||
# Sets cron // do not delete this message
|
||||
freqDir="/etc/periodic/${FREQUENCY}"
|
||||
cp /templates/cronupdate "$freqDir/"
|
||||
chmod 777 "$freqDir/cronupdate"
|
||||
# Sets cron // do not delete this message
|
||||
freqDir="/etc/periodic/${FREQUENCY}"
|
||||
cp /templates/cronupdate "$freqDir/"
|
||||
chmod 777 "$freqDir/cronupdate"
|
||||
|
||||
# Sets cron to run with www-data user
|
||||
# sed -i 's|root|www-data|g' /etc/crontab
|
||||
# Sets cron to run with www-data user
|
||||
# sed -i 's|root|www-data|g' /etc/crontab
|
||||
|
||||
# Starts cron
|
||||
echo "Timezone $TZ"
|
||||
export TZ
|
||||
crond -l 2 -f >/dev/stdout 2>/dev/stderr &
|
||||
# Starts cron
|
||||
echo "Timezone $TZ"
|
||||
export TZ
|
||||
crond -l 2 -f > /dev/stdout 2> /dev/stderr &
|
||||
|
||||
# Export variables
|
||||
IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
|
||||
export IMPORT_DIR_WHITELIST
|
||||
# Export variables
|
||||
IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
|
||||
export IMPORT_DIR_WHITELIST
|
||||
|
||||
bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE} will be imported $FREQUENCY."
|
||||
bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE} will be imported $FREQUENCY."
|
||||
|
||||
else
|
||||
bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}. There will therefore be be no automatic updates."
|
||||
fi
|
||||
else
|
||||
bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}. There will therefore be be no automatic updates."
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
@@ -67,8 +67,8 @@ fi
|
||||
bashio::log.info "Please wait while the app is loading !"
|
||||
|
||||
if bashio::config.true 'silent'; then
|
||||
bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug"
|
||||
php -S 0.0.0.0:8080 /app/index.php >/dev/null
|
||||
bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug"
|
||||
php -S 0.0.0.0:8080 /app/index.php > /dev/null
|
||||
else
|
||||
php -S 0.0.0.0:8080 /app/index.php
|
||||
php -S 0.0.0.0:8080 /app/index.php
|
||||
fi
|
||||
|
||||
@@ -5,15 +5,15 @@ set -e
|
||||
slug=flexget
|
||||
|
||||
if [ -d /config/$slug ]; then
|
||||
echo "Moving to new location /config/addons_config/$slug"
|
||||
mkdir -p /config/addons_config/$slug
|
||||
chmod 777 /config/addons_config/$slug
|
||||
mv /config/$slug/* /config/addons_config/$slug/
|
||||
rm -r /config/$slug
|
||||
echo "Moving to new location /config/addons_config/$slug"
|
||||
mkdir -p /config/addons_config/$slug
|
||||
chmod 777 /config/addons_config/$slug
|
||||
mv /config/$slug/* /config/addons_config/$slug/
|
||||
rm -r /config/$slug
|
||||
fi
|
||||
|
||||
if [ ! -d /config/addons_config/$slug ]; then
|
||||
echo "Creating /config/addons_config/$slug"
|
||||
mkdir -p /config/addons_config/$slug
|
||||
chmod 777 /config/addons_config/$slug
|
||||
echo "Creating /config/addons_config/$slug"
|
||||
mkdir -p /config/addons_config/$slug
|
||||
chmod 777 /config/addons_config/$slug
|
||||
fi
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
# Migrate files for new config location
|
||||
slug="free_games_claimer"
|
||||
if [ -f "/homeassistant/addons_config/$slug/config.yaml" ] && [ ! -f "/homeassistant/addons_config/$slug/migrated" ]; then
|
||||
bashio::log.warning "Migrating config.yaml"
|
||||
mv "/homeassistant/addons_config/$slug"/* /config/ || true
|
||||
echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" >"/homeassistant/addons_config/$slug/migrated"
|
||||
bashio::log.warning "Migrating config.yaml"
|
||||
mv "/homeassistant/addons_config/$slug"/* /config/ || true
|
||||
echo "Migrated to internal config folder accessible at /addon_configs/xxx-$slug" > "/homeassistant/addons_config/$slug/migrated"
|
||||
fi
|
||||
|
||||
if [ -f "/homeassistant/addons_autoscripts/$slug.sh" ]; then
|
||||
bashio::log.warning "Migrating autoscript"
|
||||
mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true
|
||||
bashio::log.warning "Migrating autoscript"
|
||||
mv /homeassistant/addons_autoscripts/$slug.sh /config/ || true
|
||||
fi
|
||||
|
||||
@@ -11,20 +11,20 @@ CONFIG_HOME="$(dirname "$CONFIG_HOME")"
|
||||
|
||||
# Use new config file
|
||||
if [ ! -f "$CONFIG_HOME/config.env" ]; then
|
||||
# Copy default config.env
|
||||
cp /templates/config.env "$CONFIG_HOME/"
|
||||
chmod 755 "$CONFIG_HOME/config.env"
|
||||
bashio::log.warning "A default config.env file was copied to $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on"
|
||||
# Copy default config.env
|
||||
cp /templates/config.env "$CONFIG_HOME/"
|
||||
chmod 755 "$CONFIG_HOME/config.env"
|
||||
bashio::log.warning "A default config.env file was copied to $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on"
|
||||
else
|
||||
bashio::log.info "Using existing config.env file in $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on"
|
||||
bashio::log.info "Using existing config.env file in $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on"
|
||||
fi
|
||||
|
||||
# Remove erroneous folder named config.env (bug fix for looping issue)
|
||||
if [ -d "$CONFIG_HOME/config.env" ]; then
|
||||
bashio::log.warning "Found directory named config.env, deleting it..."
|
||||
rm -rf "$CONFIG_HOME/config.env" # Fix: Ensures directory removal even if it exists
|
||||
cp /templates/config.env "$CONFIG_HOME/config.env" # Recreate as a valid file
|
||||
chmod 755 "$CONFIG_HOME/config.env"
|
||||
bashio::log.warning "Found directory named config.env, deleting it..."
|
||||
rm -rf "$CONFIG_HOME/config.env" # Fix: Ensures directory removal even if it exists
|
||||
cp /templates/config.env "$CONFIG_HOME/config.env" # Recreate as a valid file
|
||||
chmod 755 "$CONFIG_HOME/config.env"
|
||||
fi
|
||||
|
||||
# Copy new file
|
||||
@@ -61,23 +61,23 @@ cd /data || true
|
||||
# Fetch commands
|
||||
CMD_ARGUMENTS="$(bashio::config "CMD_ARGUMENTS")"
|
||||
IFS=';'
|
||||
read -ar strarr <<<"$CMD_ARGUMENTS"
|
||||
read -ar strarr <<< "$CMD_ARGUMENTS"
|
||||
|
||||
# Sanitizes commands
|
||||
trim() {
|
||||
local var="$*"
|
||||
var="${var#"${var%%[![:space:]]*}"}"
|
||||
var="${var%"${var##*[![:space:]]}"}"
|
||||
printf '%s' "$var"
|
||||
local var="$*"
|
||||
var="${var#"${var%%[![:space:]]*}"}"
|
||||
var="${var%"${var##*[![:space:]]}"}"
|
||||
printf '%s' "$var"
|
||||
}
|
||||
|
||||
# Add docker-entrypoint command
|
||||
for val in "${strarr[@]}"; do
|
||||
val="$(trim "$val")"
|
||||
echo " "
|
||||
bashio::log.info "Starting the app with arguments \"$val\""
|
||||
echo " "
|
||||
echo "$val" | xargs docker-entrypoint.sh || true
|
||||
val="$(trim "$val")"
|
||||
echo " "
|
||||
bashio::log.info "Starting the app with arguments \"$val\""
|
||||
echo " "
|
||||
echo "$val" | xargs docker-entrypoint.sh || true
|
||||
done
|
||||
|
||||
bashio::log.info "All actions concluded. Stopping in 10 seconds."
|
||||
|
||||
@@ -7,26 +7,26 @@ set -e
|
||||
#####################
|
||||
|
||||
if bashio::config.true 'mqtt_autodiscover'; then
|
||||
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
|
||||
# Check if available
|
||||
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
|
||||
# Get variables
|
||||
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..."
|
||||
MQTT_HOST=$(bashio::services mqtt "host")
|
||||
export MQTT_HOST
|
||||
MQTT_PORT=$(bashio::services mqtt "port")
|
||||
export MQTT_PORT
|
||||
MQTT_SSL=$(bashio::services mqtt "ssl")
|
||||
export MQTT_SSL
|
||||
MQTT_USERNAME=$(bashio::services mqtt "username")
|
||||
export MQTT_USERNAME
|
||||
MQTT_PASSWORD=$(bashio::services mqtt "password")
|
||||
export MQTT_PASSWORD
|
||||
bashio::log.info "mqtt_autodiscover is defined in options, attempting autodiscovery..."
|
||||
# Check if available
|
||||
if ! bashio::services.available "mqtt"; then bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"; fi
|
||||
# Get variables
|
||||
bashio::log.info "... MQTT service found, fetching server detail (you can enter those manually in your config file) ..."
|
||||
MQTT_HOST=$(bashio::services mqtt "host")
|
||||
export MQTT_HOST
|
||||
MQTT_PORT=$(bashio::services mqtt "port")
|
||||
export MQTT_PORT
|
||||
MQTT_SSL=$(bashio::services mqtt "ssl")
|
||||
export MQTT_SSL
|
||||
MQTT_USERNAME=$(bashio::services mqtt "username")
|
||||
export MQTT_USERNAME
|
||||
MQTT_PASSWORD=$(bashio::services mqtt "password")
|
||||
export MQTT_PASSWORD
|
||||
|
||||
# Export variables
|
||||
for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do
|
||||
sed -i "1a export $variables" /etc/services.d/*/*run* 2>/dev/null || true
|
||||
# Log
|
||||
bashio::log.blue "$variables"
|
||||
done
|
||||
# Export variables
|
||||
for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do
|
||||
sed -i "1a export $variables" /etc/services.d/*/*run* 2> /dev/null || true
|
||||
# Log
|
||||
bashio::log.blue "$variables"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -4,64 +4,64 @@ set -e
|
||||
|
||||
for file in /data/gitea/conf/app.ini /etc/templates/app.ini; do
|
||||
|
||||
if [ ! -f "$file" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ ! -f "$file" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
##############
|
||||
# SSL CONFIG #
|
||||
##############
|
||||
##############
|
||||
# SSL CONFIG #
|
||||
##############
|
||||
|
||||
# Clean values
|
||||
sed -i "/PROTOCOL/d" "$file"
|
||||
sed -i "/CERT_FILE/d" "$file"
|
||||
sed -i "/KEY_FILE/d" "$file"
|
||||
# Clean values
|
||||
sed -i "/PROTOCOL/d" "$file"
|
||||
sed -i "/CERT_FILE/d" "$file"
|
||||
sed -i "/KEY_FILE/d" "$file"
|
||||
|
||||
# Add ssl
|
||||
bashio::config.require.ssl
|
||||
if bashio::config.true 'ssl'; then
|
||||
PROTOCOL=https
|
||||
bashio::log.info "ssl is enabled"
|
||||
sed -i "/server/a PROTOCOL=https" "$file"
|
||||
sed -i "/server/a CERT_FILE=/ssl/$(bashio::config 'certfile')" "$file"
|
||||
sed -i "/server/a KEY_FILE=/ssl/$(bashio::config 'keyfile')" "$file"
|
||||
chmod 744 /ssl/*
|
||||
else
|
||||
PROTOCOL=http
|
||||
sed -i "/server/a PROTOCOL=http" "$file"
|
||||
fi
|
||||
# Add ssl
|
||||
bashio::config.require.ssl
|
||||
if bashio::config.true 'ssl'; then
|
||||
PROTOCOL=https
|
||||
bashio::log.info "ssl is enabled"
|
||||
sed -i "/server/a PROTOCOL=https" "$file"
|
||||
sed -i "/server/a CERT_FILE=/ssl/$(bashio::config 'certfile')" "$file"
|
||||
sed -i "/server/a KEY_FILE=/ssl/$(bashio::config 'keyfile')" "$file"
|
||||
chmod 744 /ssl/*
|
||||
else
|
||||
PROTOCOL=http
|
||||
sed -i "/server/a PROTOCOL=http" "$file"
|
||||
fi
|
||||
|
||||
##################
|
||||
# ADAPT ROOT_URL #
|
||||
##################
|
||||
##################
|
||||
# ADAPT ROOT_URL #
|
||||
##################
|
||||
|
||||
if bashio::config.has_value 'ROOT_URL'; then
|
||||
bashio::log.blue "ROOT_URL set, using value : $(bashio::config 'ROOT_URL')"
|
||||
else
|
||||
ROOT_URL="$PROTOCOL://$(bashio::config 'DOMAIN'):$(bashio::addon.port 3000)"
|
||||
bashio::log.blue "ROOT_URL not set, using extrapolated value : $ROOT_URL"
|
||||
sed -i "/server/a ROOT_URL=$ROOT_URL" "$file"
|
||||
fi
|
||||
if bashio::config.has_value 'ROOT_URL'; then
|
||||
bashio::log.blue "ROOT_URL set, using value : $(bashio::config 'ROOT_URL')"
|
||||
else
|
||||
ROOT_URL="$PROTOCOL://$(bashio::config 'DOMAIN'):$(bashio::addon.port 3000)"
|
||||
bashio::log.blue "ROOT_URL not set, using extrapolated value : $ROOT_URL"
|
||||
sed -i "/server/a ROOT_URL=$ROOT_URL" "$file"
|
||||
fi
|
||||
|
||||
####################
|
||||
# ADAPT PARAMETERS #
|
||||
####################
|
||||
####################
|
||||
# ADAPT PARAMETERS #
|
||||
####################
|
||||
|
||||
for param in APP_NAME DOMAIN ROOT_URL; do
|
||||
# Remove parameter
|
||||
sed -i "/$param/d" "$file"
|
||||
for param in APP_NAME DOMAIN ROOT_URL; do
|
||||
# Remove parameter
|
||||
sed -i "/$param/d" "$file"
|
||||
|
||||
# Define parameter
|
||||
if bashio::config.has_value "$param"; then
|
||||
echo "parameter set : $param=$(bashio::config "$param")"
|
||||
sed -i "/server/a $param = \"$(bashio::config "$param")\"" "$file"
|
||||
# Define parameter
|
||||
if bashio::config.has_value "$param"; then
|
||||
echo "parameter set : $param=$(bashio::config "$param")"
|
||||
sed -i "/server/a $param = \"$(bashio::config "$param")\"" "$file"
|
||||
|
||||
# Allow at setup
|
||||
sed -i "1a $param=\"$(bashio::config "$param")\"" /etc/s6/gitea/setup
|
||||
# Allow at setup
|
||||
sed -i "1a $param=\"$(bashio::config "$param")\"" /etc/s6/gitea/setup
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
||||
done
|
||||
|
||||
done
|
||||
|
||||
|
||||
@@ -16,18 +16,18 @@ sed -i "s|%%interface%%|$(bashio::addon.ip_address)|g" /etc/nginx/servers/ssl.co
|
||||
|
||||
# Ssl values
|
||||
if bashio::config.true 'ssl'; then
|
||||
echo "Defining ssl configuration"
|
||||
bashio::config.require.ssl
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
echo "Defining ssl configuration"
|
||||
bashio::config.require.ssl
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
|
||||
#Check if files exist
|
||||
echo "... checking if referenced certificates exist"
|
||||
[ ! -f /ssl/"$certfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$certfile not found" && bashio::exit.nok
|
||||
[ ! -f /ssl/"$keyfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$keyfile not found" && bashio::exit.nok
|
||||
#Check if files exist
|
||||
echo "... checking if referenced certificates exist"
|
||||
[ ! -f /ssl/"$certfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$certfile not found" && bashio::exit.nok
|
||||
[ ! -f /ssl/"$keyfile" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$keyfile not found" && bashio::exit.nok
|
||||
|
||||
sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf
|
||||
sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf
|
||||
sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf
|
||||
bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port "$port")"
|
||||
sed -i "s|default_server|ssl|g" /etc/nginx/servers/ssl.conf
|
||||
sed -i "/proxy_params.conf/a ssl_certificate /ssl/$certfile;" /etc/nginx/servers/ssl.conf
|
||||
sed -i "/proxy_params.conf/a ssl_certificate_key /ssl/$keyfile;" /etc/nginx/servers/ssl.conf
|
||||
bashio::log.info "Ssl enabled, please use https for connection. UI is at https://YOURIP:$(bashio::addon.port "$port")"
|
||||
fi
|
||||
|
||||
@@ -6,21 +6,21 @@ set -e
|
||||
# Set structure #
|
||||
#################
|
||||
for folders in config users indexdir secret media cache thumbnail_cache persist; do
|
||||
mkdir -p /config/"$folders"
|
||||
if [ -d /app/"$folders" ] && [ "$(ls -A /app/"$folders")" ]; then
|
||||
cp -rn /app/"$folders"/* /config/"$folders"
|
||||
fi
|
||||
rm -rf /app/"$folders"
|
||||
ln -sf /config/"$folders" /app/"$folders"
|
||||
mkdir -p /config/"$folders"
|
||||
if [ -d /app/"$folders" ] && [ "$(ls -A /app/"$folders")" ]; then
|
||||
cp -rn /app/"$folders"/* /config/"$folders"
|
||||
fi
|
||||
rm -rf /app/"$folders"
|
||||
ln -sf /config/"$folders" /app/"$folders"
|
||||
done
|
||||
|
||||
# Persist database and plugins
|
||||
mkdir -p /config/gramps
|
||||
if [ -d /root/.gramps ]; then
|
||||
if [ "$(ls -A /root/.gramps)" ]; then
|
||||
cp -rf /root/.gramps/* /config/gramps
|
||||
fi
|
||||
rm -rf /root/.gramps
|
||||
if [ "$(ls -A /root/.gramps)" ]; then
|
||||
cp -rf /root/.gramps/* /config/gramps
|
||||
fi
|
||||
rm -rf /root/.gramps
|
||||
fi
|
||||
ln -sf /config/gramps /root/.gramps
|
||||
|
||||
@@ -29,22 +29,22 @@ ln -sf /config/gramps /root/.gramps
|
||||
#####################
|
||||
# Check if the secret key is defined in addon options
|
||||
if bashio::config.has_value "GRAMPSWEB_SECRET_KEY"; then
|
||||
bashio::log.warning "Using the secret key defined in the addon options."
|
||||
GRAMPSWEB_SECRET_KEY="$(bashio::config "GRAMPSWEB_SECRET_KEY")"
|
||||
export GRAMPSWEB_SECRET_KEY
|
||||
bashio::log.warning "Using the secret key defined in the addon options."
|
||||
GRAMPSWEB_SECRET_KEY="$(bashio::config "GRAMPSWEB_SECRET_KEY")"
|
||||
export GRAMPSWEB_SECRET_KEY
|
||||
else
|
||||
# Check if the secret file exists; if not, create a new one
|
||||
if [ ! -s /config/secret/secret ]; then
|
||||
bashio::log.warning "No secret key found in /config/secret/secret, generating a new one."
|
||||
mkdir -p /config/secret
|
||||
python3 -c "import secrets; print(secrets.token_urlsafe(32))" | tr -d "\n" >/config/secret/secret
|
||||
bashio::log.warning "New secret key generated and stored in /config/secret/secret"
|
||||
fi
|
||||
bashio::log.warning "Using existing secret key from /config/secret/secret."
|
||||
bashio::log.warning "Secret key saved to addon options."
|
||||
GRAMPSWEB_SECRET_KEY="$(cat /config/secret/secret)"
|
||||
export GRAMPSWEB_SECRET_KEY
|
||||
bashio::addon.option "GRAMPSWEB_SECRET_KEY" "$GRAMPSWEB_SECRET_KEY"
|
||||
# Check if the secret file exists; if not, create a new one
|
||||
if [ ! -s /config/secret/secret ]; then
|
||||
bashio::log.warning "No secret key found in /config/secret/secret, generating a new one."
|
||||
mkdir -p /config/secret
|
||||
python3 -c "import secrets; print(secrets.token_urlsafe(32))" | tr -d "\n" > /config/secret/secret
|
||||
bashio::log.warning "New secret key generated and stored in /config/secret/secret"
|
||||
fi
|
||||
bashio::log.warning "Using existing secret key from /config/secret/secret."
|
||||
bashio::log.warning "Secret key saved to addon options."
|
||||
GRAMPSWEB_SECRET_KEY="$(cat /config/secret/secret)"
|
||||
export GRAMPSWEB_SECRET_KEY
|
||||
bashio::addon.option "GRAMPSWEB_SECRET_KEY" "$GRAMPSWEB_SECRET_KEY"
|
||||
fi
|
||||
|
||||
##################
|
||||
|
||||
@@ -5,9 +5,9 @@ set -e
|
||||
echo "Updating folders..."
|
||||
|
||||
for FOLDERS in "/share/grav" "/app/grav-admin/backup"; do
|
||||
echo "... $FOLDERS"
|
||||
mkdir -p $FOLDERS
|
||||
chown -R "$PUID:$PGID" $FOLDERS
|
||||
echo "... $FOLDERS"
|
||||
mkdir -p $FOLDERS
|
||||
chown -R "$PUID:$PGID" $FOLDERS
|
||||
done
|
||||
|
||||
bashio::log.warning "If error of missing folder when loading addon, just restart"
|
||||
|
||||
@@ -68,8 +68,8 @@
|
||||
"/dev/nvme2"
|
||||
],
|
||||
"environment": {
|
||||
"PGDATA": "/config/postgres",
|
||||
"GUACAMOLE_HOME": "/config"
|
||||
"GUACAMOLE_HOME": "/config",
|
||||
"PGDATA": "/config/postgres"
|
||||
},
|
||||
"image": "ghcr.io/alexbelgium/guacamole-{arch}",
|
||||
"ingress": true,
|
||||
|
||||
@@ -9,6 +9,6 @@ set -e
|
||||
slug=guacamole
|
||||
|
||||
if [ -d /homeassistant/addons_config/"$slug" ] && [ ! -d /config/postgres ]; then
|
||||
echo "Moving database to new location /config"
|
||||
cp -rf /homeassistant/addons_config/"$slug"/* /config/
|
||||
echo "Moving database to new location /config"
|
||||
cp -rf /homeassistant/addons_config/"$slug"/* /config/
|
||||
fi
|
||||
|
||||
@@ -13,19 +13,19 @@ declare keyfile
|
||||
|
||||
port=$(bashio::addon.port 80)
|
||||
if bashio::var.has_value "${port}"; then
|
||||
bashio::config.require.ssl
|
||||
bashio::config.require.ssl
|
||||
|
||||
if bashio::config.true 'ssl'; then
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
if bashio::config.true 'ssl'; then
|
||||
certfile=$(bashio::config 'certfile')
|
||||
keyfile=$(bashio::config 'keyfile')
|
||||
|
||||
mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf
|
||||
sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf
|
||||
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf
|
||||
mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf
|
||||
sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf
|
||||
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf
|
||||
|
||||
else
|
||||
mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf
|
||||
fi
|
||||
else
|
||||
mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
ingress_port=$(bashio::addon.ingress_port)
|
||||
|
||||
0
guacamole/rootfs/etc/services.d/nginx/run
Normal file → Executable file
0
guacamole/rootfs/etc/services.d/nginx/run
Normal file → Executable file
@@ -5,17 +5,17 @@ PREVIOUS_FOLDER="immich"
|
||||
|
||||
# Move main folder
|
||||
if [ -f /homeassistant/addons_config/"$PREVIOUS_FOLDER"/config.yaml ]; then
|
||||
bashio::log.warning "----------------------------------------"
|
||||
bashio::log.warning "Migrating configuration to the new addon"
|
||||
bashio::log.warning "----------------------------------------"
|
||||
cp -rnp /homeassistant/addons_config/"$PREVIOUS_FOLDER"/ /config/
|
||||
mv /homeassistant/addons_config/"$PREVIOUS_FOLDER" "$PREVIOUS_FOLDER"_migrated
|
||||
if [ -d /config/addons_config ]; then rm -r /config/addons_config; fi
|
||||
echo "Files moved to /addon_configs/$HOSTNAME"
|
||||
bashio::log.warning "----------------------------------------"
|
||||
bashio::log.warning "Migrating configuration to the new addon"
|
||||
bashio::log.warning "----------------------------------------"
|
||||
cp -rnp /homeassistant/addons_config/"$PREVIOUS_FOLDER"/ /config/
|
||||
mv /homeassistant/addons_config/"$PREVIOUS_FOLDER" "$PREVIOUS_FOLDER"_migrated
|
||||
if [ -d /config/addons_config ]; then rm -r /config/addons_config; fi
|
||||
echo "Files moved to /addon_configs/$HOSTNAME"
|
||||
fi
|
||||
|
||||
# Move autoscript
|
||||
if [ -f /homeassistant/addons_autoscrips/immich.sh ]; then
|
||||
cp -rnf /homeassistant/addons_autoscrips/"$PREVIOUS_FOLDER".sh /config/ &>/dev/null || true
|
||||
bashio::log.yellow "... moved $PREVIOUS_FOLDER.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME"
|
||||
cp -rnf /homeassistant/addons_autoscrips/"$PREVIOUS_FOLDER".sh /config/ &> /dev/null || true
|
||||
bashio::log.yellow "... moved $PREVIOUS_FOLDER.sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME"
|
||||
fi
|
||||
|
||||
@@ -7,14 +7,14 @@ set -e
|
||||
######################
|
||||
|
||||
if bashio::config.has_value "PUID"; then
|
||||
PUID="$(bashio::config 'PUID')"
|
||||
PUID="$(bashio::config 'PUID')"
|
||||
else
|
||||
PUID=0
|
||||
PUID=0
|
||||
fi
|
||||
if bashio::config.has_value "PGID"; then
|
||||
PGID="$(bashio::config 'PGID')"
|
||||
PGID="$(bashio::config 'PGID')"
|
||||
else
|
||||
PGID=0
|
||||
PGID=0
|
||||
fi
|
||||
|
||||
##########################
|
||||
@@ -23,7 +23,7 @@ fi
|
||||
|
||||
# Clean typesense
|
||||
if [ -d /data/typesense ]; then
|
||||
rm -r /data/typesense
|
||||
rm -r /data/typesense
|
||||
fi
|
||||
|
||||
#################
|
||||
@@ -34,9 +34,9 @@ bashio::log.info "Setting data location"
|
||||
DATA_LOCATION="$(bashio::config 'data_location')"
|
||||
export IMMICH_MEDIA_LOCATION="$DATA_LOCATION"
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
printf "%s" "$DATA_LOCATION" >/var/run/s6/container_environment/IMMICH_MEDIA_LOCATION
|
||||
printf "%s" "$DATA_LOCATION" > /var/run/s6/container_environment/IMMICH_MEDIA_LOCATION
|
||||
fi
|
||||
printf "%s\n" "IMMICH_MEDIA_LOCATION=\"$DATA_LOCATION\"" >>~/.bashrc
|
||||
printf "%s\n" "IMMICH_MEDIA_LOCATION=\"$DATA_LOCATION\"" >> ~/.bashrc
|
||||
|
||||
echo "... check $DATA_LOCATION folder exists"
|
||||
mkdir -p "$DATA_LOCATION"
|
||||
@@ -63,32 +63,32 @@ chmod 777 /data
|
||||
####################
|
||||
|
||||
if bashio::config.has_value "library_location"; then
|
||||
LIBRARY_LOCATION="$(bashio::config 'library_location')"
|
||||
bashio::log.info "Setting library location to $LIBRARY_LOCATION. This will not move any of your files, you'll need to do this manually"
|
||||
mkdir -p "$LIBRARY_LOCATION"
|
||||
chown -R "$PUID":"$PGID" "$LIBRARY_LOCATION"
|
||||
LIBRARY_LOCATION="$(bashio::config 'library_location')"
|
||||
bashio::log.info "Setting library location to $LIBRARY_LOCATION. This will not move any of your files, you'll need to do this manually"
|
||||
mkdir -p "$LIBRARY_LOCATION"
|
||||
chown -R "$PUID":"$PGID" "$LIBRARY_LOCATION"
|
||||
|
||||
# Check if the existing library is a directory and not a symlink and has contents
|
||||
if [ -d "$DATA_LOCATION/library" ] && [ ! -L "$DATA_LOCATION/library" ] && [ "$(ls -A "$DATA_LOCATION/library")" ]; then
|
||||
bashio::log.yellow "-------------------------------"
|
||||
bashio::log.warning "Library folder in $DATA_LOCATION/library already exists, is a real folder, and is not empty. Moving to $DATA_LOCATION/library_old"
|
||||
bashio::log.yellow "-------------------------------"
|
||||
mv "$DATA_LOCATION/library" "$DATA_LOCATION/library_old"
|
||||
sleep 5
|
||||
fi
|
||||
# Check if the existing library is a directory and not a symlink and has contents
|
||||
if [ -d "$DATA_LOCATION/library" ] && [ ! -L "$DATA_LOCATION/library" ] && [ "$(ls -A "$DATA_LOCATION/library")" ]; then
|
||||
bashio::log.yellow "-------------------------------"
|
||||
bashio::log.warning "Library folder in $DATA_LOCATION/library already exists, is a real folder, and is not empty. Moving to $DATA_LOCATION/library_old"
|
||||
bashio::log.yellow "-------------------------------"
|
||||
mv "$DATA_LOCATION/library" "$DATA_LOCATION/library_old"
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
# Create symbolic link only if it doesn't already exist or is incorrect
|
||||
if [ ! -L "$DATA_LOCATION/library" ] || [ "$(readlink -f "$DATA_LOCATION/library")" != "$LIBRARY_LOCATION" ]; then
|
||||
ln -sf "$LIBRARY_LOCATION" "$DATA_LOCATION/library"
|
||||
fi
|
||||
# Create symbolic link only if it doesn't already exist or is incorrect
|
||||
if [ ! -L "$DATA_LOCATION/library" ] || [ "$(readlink -f "$DATA_LOCATION/library")" != "$LIBRARY_LOCATION" ]; then
|
||||
ln -sf "$LIBRARY_LOCATION" "$DATA_LOCATION/library"
|
||||
fi
|
||||
fi
|
||||
|
||||
##################
|
||||
# REDIS LOCATION #
|
||||
##################
|
||||
|
||||
echo "sed -i \"s=/config/redis=/data/redis=g\" /etc/s6*/s6*/*/run" >>/docker-mods
|
||||
echo "sed -i \"s=/config/log/redis=/data/log=g\" /etc/s6*/s6*/*/run" >>/docker-mods
|
||||
echo "sed -i \"s=/config/redis=/data/redis=g\" /etc/s6*/s6*/*/run" >> /docker-mods
|
||||
echo "sed -i \"s=/config/log/redis=/data/log=g\" /etc/s6*/s6*/*/run" >> /docker-mods
|
||||
mkdir -p /data/redis
|
||||
mkdir -p /data/log
|
||||
chmod 777 /data/redis
|
||||
|
||||
@@ -5,134 +5,134 @@ set -e
|
||||
|
||||
# Function to export options from JSON to env variables
|
||||
export_options() {
|
||||
local json_source="/data/options.json"
|
||||
bashio::log.info "Exporting addon options from ${json_source}"
|
||||
local json_source="/data/options.json"
|
||||
bashio::log.info "Exporting addon options from ${json_source}"
|
||||
|
||||
# WARNING: Exporting all keys can cause trouble if your config contains unsafe or untrusted keys!
|
||||
mapfile -t keys < <(jq -r 'keys[]' "${json_source}")
|
||||
for key in "${keys[@]}"; do
|
||||
local value
|
||||
value=$(jq -r ".${key}" "${json_source}")
|
||||
if bashio::config.false "verbose" || [[ "$key" == *"PASS"* ]]; then
|
||||
bashio::log.blue "${key}=******"
|
||||
else
|
||||
bashio::log.blue "${key}='${value}'"
|
||||
fi
|
||||
export "${key}=${value}"
|
||||
done
|
||||
# WARNING: Exporting all keys can cause trouble if your config contains unsafe or untrusted keys!
|
||||
mapfile -t keys < <(jq -r 'keys[]' "${json_source}")
|
||||
for key in "${keys[@]}"; do
|
||||
local value
|
||||
value=$(jq -r ".${key}" "${json_source}")
|
||||
if bashio::config.false "verbose" || [[ "$key" == *"PASS"* ]]; then
|
||||
bashio::log.blue "${key}=******"
|
||||
else
|
||||
bashio::log.blue "${key}='${value}'"
|
||||
fi
|
||||
export "${key}=${value}"
|
||||
done
|
||||
}
|
||||
|
||||
# Function to check and adjust DB_HOSTNAME if necessary
|
||||
check_db_hostname() {
|
||||
if [[ "${DB_HOSTNAME}" == "homeassistant.local" ]]; then
|
||||
local host_ip
|
||||
host_ip=$(bashio::network.ipv4_address)
|
||||
host_ip=${host_ip%/*}
|
||||
export DB_HOSTNAME="$host_ip"
|
||||
bashio::log.warning "DB_HOSTNAME was set to homeassistant.local. Using detected IP: $DB_HOSTNAME"
|
||||
fi
|
||||
if [[ "${DB_HOSTNAME}" == "homeassistant.local" ]]; then
|
||||
local host_ip
|
||||
host_ip=$(bashio::network.ipv4_address)
|
||||
host_ip=${host_ip%/*}
|
||||
export DB_HOSTNAME="$host_ip"
|
||||
bashio::log.warning "DB_HOSTNAME was set to homeassistant.local. Using detected IP: $DB_HOSTNAME"
|
||||
fi
|
||||
|
||||
if ! ping -c 1 -W 3 "$DB_HOSTNAME" >/dev/null 2>&1; then
|
||||
bashio::log.warning "------------------------------------"
|
||||
bashio::log.warning "DB_HOSTNAME ($DB_HOSTNAME) is not reachable."
|
||||
bashio::log.warning "Please set it to the IP address of your database."
|
||||
bashio::log.warning "The addon will stop until this is fixed."
|
||||
bashio::log.warning "------------------------------------"
|
||||
sleep 30
|
||||
bashio::addon.stop
|
||||
else
|
||||
echo "$DB_HOSTNAME is reachable."
|
||||
fi
|
||||
if ! ping -c 1 -W 3 "$DB_HOSTNAME" > /dev/null 2>&1; then
|
||||
bashio::log.warning "------------------------------------"
|
||||
bashio::log.warning "DB_HOSTNAME ($DB_HOSTNAME) is not reachable."
|
||||
bashio::log.warning "Please set it to the IP address of your database."
|
||||
bashio::log.warning "The addon will stop until this is fixed."
|
||||
bashio::log.warning "------------------------------------"
|
||||
sleep 30
|
||||
bashio::addon.stop
|
||||
else
|
||||
echo "$DB_HOSTNAME is reachable."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to migrate internal database to external storage if needed
|
||||
migrate_database() {
|
||||
if [ -f /share/postgresql_immich.tar.gz ]; then
|
||||
bashio::log.warning "Previous database export found at /share/postgresql_immich.tar.gz"
|
||||
elif [ -d /data/postgresql ]; then
|
||||
bashio::log.warning "Internal Postgres database detected. Migrating to /share/postgresql_immich.tar.gz"
|
||||
tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql
|
||||
rm -rf /data/postgresql
|
||||
fi
|
||||
if [ -f /share/postgresql_immich.tar.gz ]; then
|
||||
bashio::log.warning "Previous database export found at /share/postgresql_immich.tar.gz"
|
||||
elif [ -d /data/postgresql ]; then
|
||||
bashio::log.warning "Internal Postgres database detected. Migrating to /share/postgresql_immich.tar.gz"
|
||||
tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql
|
||||
rm -rf /data/postgresql
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to validate required configuration values
|
||||
validate_config() {
|
||||
local missing=false
|
||||
for var in DB_USERNAME DB_HOSTNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT JWT_SECRET; do
|
||||
if ! bashio::config.has_value "${var}"; then
|
||||
bashio::log.error "Missing required configuration: ${var}"
|
||||
missing=true
|
||||
fi
|
||||
done
|
||||
if [ "$missing" = true ]; then
|
||||
bashio::exit.nok "Please ensure all required options are set."
|
||||
fi
|
||||
local missing=false
|
||||
for var in DB_USERNAME DB_HOSTNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT JWT_SECRET; do
|
||||
if ! bashio::config.has_value "${var}"; then
|
||||
bashio::log.error "Missing required configuration: ${var}"
|
||||
missing=true
|
||||
fi
|
||||
done
|
||||
if [ "$missing" = true ]; then
|
||||
bashio::exit.nok "Please ensure all required options are set."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to export DB variables to s6 environment if applicable
|
||||
export_db_env() {
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
for var in DB_USERNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT DB_HOSTNAME JWT_SECRET; do
|
||||
if [ -n "${!var:-}" ]; then
|
||||
printf "%s" "${!var}" >"/var/run/s6/container_environment/${var}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
for var in DB_USERNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT DB_HOSTNAME JWT_SECRET; do
|
||||
if [ -n "${!var:-}" ]; then
|
||||
printf "%s" "${!var}" > "/var/run/s6/container_environment/${var}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up the root user with a secure password
|
||||
setup_root_user() {
|
||||
# Generate DB_ROOT_PASSWORD if not set (12-character alphanumeric).
|
||||
if bashio::config.has_value "DB_ROOT_PASSWORD"; then
|
||||
export DB_ROOT_PASSWORD="$(bashio::config 'DB_ROOT_PASSWORD')"
|
||||
else
|
||||
bashio::log.warning "DB_ROOT_PASSWORD not set. Generating a random 12-character alphanumeric password and storing it in the addon options."
|
||||
export DB_ROOT_PASSWORD="$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c12)"
|
||||
bashio::addon.option "DB_ROOT_PASSWORD" "${DB_ROOT_PASSWORD}"
|
||||
# Generate DB_ROOT_PASSWORD if not set (12-character alphanumeric).
|
||||
if bashio::config.has_value "DB_ROOT_PASSWORD"; then
|
||||
export DB_ROOT_PASSWORD="$(bashio::config 'DB_ROOT_PASSWORD')"
|
||||
else
|
||||
bashio::log.warning "DB_ROOT_PASSWORD not set. Generating a random 12-character alphanumeric password and storing it in the addon options."
|
||||
export DB_ROOT_PASSWORD="$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c12)"
|
||||
bashio::addon.option "DB_ROOT_PASSWORD" "${DB_ROOT_PASSWORD}"
|
||||
|
||||
# Store generated password in the s6 environment if available
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
printf "%s" "${DB_ROOT_PASSWORD}" >"/var/run/s6/container_environment/DB_ROOT_PASSWORD"
|
||||
fi
|
||||
fi
|
||||
# Store generated password in the s6 environment if available
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
printf "%s" "${DB_ROOT_PASSWORD}" > "/var/run/s6/container_environment/DB_ROOT_PASSWORD"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to connect as root using the default insecure password.
|
||||
if psql "postgres://root:securepassword@${DB_HOSTNAME}:${DB_PORT}/postgres" -c '\q' 2>/dev/null; then
|
||||
bashio::log.info "Detected root user with default password. Updating to new DB_ROOT_PASSWORD..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
# Try to connect as root using the default insecure password.
|
||||
if psql "postgres://root:securepassword@${DB_HOSTNAME}:${DB_PORT}/postgres" -c '\q' 2> /dev/null; then
|
||||
bashio::log.info "Detected root user with default password. Updating to new DB_ROOT_PASSWORD..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
|
||||
ALTER ROLE root WITH PASSWORD '${DB_ROOT_PASSWORD}';
|
||||
EOF
|
||||
else
|
||||
# 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
|
||||
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
|
||||
else
|
||||
# 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
|
||||
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
|
||||
CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD '${DB_ROOT_PASSWORD}';
|
||||
EOF
|
||||
else
|
||||
bashio::log.info "Root user exists with a non-default password. No migration needed."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
bashio::log.info "Root user exists with a non-default password. No migration needed."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up the 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
|
||||
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
|
||||
bashio::log.info "Database does not exist. Creating it now..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
# Create the database if it does not exist
|
||||
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
|
||||
bashio::log.info "Database does not exist. Creating it now..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
|
||||
CREATE DATABASE ${DB_DATABASE_NAME};
|
||||
EOF
|
||||
else
|
||||
bashio::log.info "Database ${DB_DATABASE_NAME} already exists. Ensuring it is configured correctly."
|
||||
fi
|
||||
else
|
||||
bashio::log.info "Database ${DB_DATABASE_NAME} already exists. Ensuring it is configured correctly."
|
||||
fi
|
||||
|
||||
# Ensure the user exists and update its password
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
# Ensure the user exists and update its password
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
|
||||
DO \$\$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${DB_USERNAME}') THEN
|
||||
@@ -144,38 +144,38 @@ END
|
||||
\$\$;
|
||||
EOF
|
||||
|
||||
# Ensure the user has full privileges on the database
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
# Ensure the user has full privileges on the database
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
|
||||
GRANT ALL PRIVILEGES ON DATABASE ${DB_DATABASE_NAME} TO ${DB_USERNAME};
|
||||
EOF
|
||||
|
||||
bashio::log.info "Database setup completed successfully."
|
||||
bashio::log.info "Database setup completed successfully."
|
||||
}
|
||||
|
||||
# Function to check if vectors extension is enabled
|
||||
check_vector_extension() {
|
||||
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';")
|
||||
if [[ "$RESULT" == "vectors" ]]; then
|
||||
echo "✅ 'vectors' extension is enabled."
|
||||
return 0
|
||||
else
|
||||
bashio::log.warning "❌ 'vectors' extension is NOT enabled."
|
||||
return 1
|
||||
fi
|
||||
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';")
|
||||
if [[ "$RESULT" == "vectors" ]]; then
|
||||
echo "✅ 'vectors' extension is enabled."
|
||||
return 0
|
||||
else
|
||||
bashio::log.warning "❌ 'vectors' extension is NOT enabled."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check if vchord extension is enabled
|
||||
check_vchord_extension() {
|
||||
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';")
|
||||
if [[ "$RESULT" == "vchord" ]]; then
|
||||
echo "✅ 'vchord' extension is enabled."
|
||||
return 0
|
||||
else
|
||||
bashio::log.warning "❌ 'vchord' extension is NOT enabled."
|
||||
return 1
|
||||
fi
|
||||
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';")
|
||||
if [[ "$RESULT" == "vchord" ]]; then
|
||||
echo "✅ 'vchord' extension is enabled."
|
||||
return 0
|
||||
else
|
||||
bashio::log.warning "❌ 'vchord' extension is NOT enabled."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#########################
|
||||
|
||||
@@ -4,7 +4,7 @@ bashio::log.info "Starting Immich Frame"
|
||||
|
||||
mkdir -p /config/Config
|
||||
if [ -f /app/Config ]; then
|
||||
rm -r /app/Config
|
||||
rm -r /app/Config
|
||||
fi
|
||||
ln -sf /app/Config /config/Config
|
||||
|
||||
|
||||
@@ -4,24 +4,24 @@ bashio::log.info "Starting Immich Power Tools"
|
||||
|
||||
# Ensure DB_HOST has no proto in front
|
||||
extract_ip_or_domain() {
|
||||
local url="$1"
|
||||
if [[ ! "$url" =~ ^https?:// ]]; then
|
||||
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|'
|
||||
fi
|
||||
local url="$1"
|
||||
if [[ ! "$url" =~ ^https?:// ]]; then
|
||||
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|'
|
||||
fi
|
||||
}
|
||||
DB_HOST="$(extract_ip_or_domain "$DB_HOST")"
|
||||
export DB_HOST
|
||||
|
||||
# Function to ensure URL has http:// or https:// prefix
|
||||
ensure_http_prefix() {
|
||||
local url="$1"
|
||||
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"
|
||||
echo "http://$url"
|
||||
else
|
||||
echo "$url"
|
||||
fi
|
||||
local url="$1"
|
||||
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"
|
||||
echo "http://$url"
|
||||
else
|
||||
echo "$url"
|
||||
fi
|
||||
}
|
||||
|
||||
# Ensure IMMICH_URL and EXTERNAL_IMMICH_URL have http:// or https:// prefix
|
||||
|
||||
@@ -5,7 +5,7 @@ set -e
|
||||
#################
|
||||
# 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
|
||||
/usr/sbin/inadyn --check-config
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -d /share/downloads ]; then
|
||||
echo "Creating /share/downloads"
|
||||
mkdir -p /share/downloads
|
||||
chown -R "$PUID:$PGID" /share/downloads
|
||||
echo "Creating /share/downloads"
|
||||
mkdir -p /share/downloads
|
||||
chown -R "$PUID:$PGID" /share/downloads
|
||||
fi
|
||||
|
||||
if [ -d /config/Jackett ] && [ ! -d /config/addons_config/Jackett ]; then
|
||||
echo "Moving to new location /config/addons_config/Jackett"
|
||||
mkdir -p /config/addons_config/Jackett
|
||||
chown -R "$PUID:$PGID" /config/addons_config/Jackett
|
||||
mv /config/Jackett/* /config/addons_config/Jackett/
|
||||
rm -r /config/Jackett
|
||||
rm -r /config/jackett
|
||||
echo "Moving to new location /config/addons_config/Jackett"
|
||||
mkdir -p /config/addons_config/Jackett
|
||||
chown -R "$PUID:$PGID" /config/addons_config/Jackett
|
||||
mv /config/Jackett/* /config/addons_config/Jackett/
|
||||
rm -r /config/Jackett
|
||||
rm -r /config/jackett
|
||||
fi
|
||||
|
||||
if [ ! -d /config/addons_config/Jackett ]; then
|
||||
echo "Creating /config/addons_config/Jackett"
|
||||
mkdir -p /config/addons_config/Jackett
|
||||
chown -R "$PUID:$PGID" /config/addons_config/Jackett
|
||||
echo "Creating /config/addons_config/Jackett"
|
||||
mkdir -p /config/addons_config/Jackett
|
||||
chown -R "$PUID:$PGID" /config/addons_config/Jackett
|
||||
fi
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user