mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-10-13 11:41:36 +02:00
* Add one-shot app_config linter migration workflow * Add app_config linter compatibility action * Add add-on map compatibility normalizer * Test add-on map compatibility normalizer * Run app_config compatibility preparation on pull request * Validate app_config short and long map forms separately * Export validated workflow updates * Use app_config-compatible linter for PR checks * Use app_config-compatible linter for builds * Remove temporary linter preparation workflow * Add one-shot app_config manifest migration * Migrate legacy addon_config maps to app_config * Preserve upstream legacy aliases without deprecated literals * Test legacy alias compatibility without deprecated literals * Validate completed app_config migration * Count only add-on manifests during migration validation * Remove temporary migration validation workflow * Document legacy alias construction * Remove obsolete local linter compatibility script * Remove obsolete local linter compatibility tests * fix(pr-2937-review): address reviewer findings on app_config migration - Remove the orphaned .github/actions/addon-linter composite action: it references .github/scripts/prepare_addon_lint_config.py, which was never added (the normalization approach was superseded by pinning frenck/action-addon-linter directly in #2936). Confirmed unused - no workflow invokes it. - cleanuparr: HA_DATA_DIR pointed at /app_configs/cleanuparr, a path not mounted inside the container. cleanuparr's map is app_config:rw, which Supervisor mounts at /config, so data was living on the ephemeral container filesystem. Point it at /config instead (pre-existing bug, not introduced by this PR - just carried the wrong path forward). - joplin/README.md: joplin's config.yaml still declares config:rw, not app_config (it was never part of the 86-manifest migration). Revert the doc text that incorrectly started calling it the app_config mapping. - qbittorrent/00-folders.sh: fix a pre-existing copy/paste bug in the migration marker/log for the main-folder migration block - it referenced "openvpn" and a "qBitorrent" typo instead of qBittorrent. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
217 lines
5.2 KiB
Bash
Executable File
217 lines
5.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# shellcheck shell=bash
|
|
set -e
|
|
|
|
##########################################
|
|
# Pick an exec-capable directory #
|
|
##########################################
|
|
|
|
pick_exec_dir() {
|
|
local d
|
|
for d in /dev/shm /run /var/run /mnt /root /; do
|
|
if [ -d "$d" ] && [ -w "$d" ]; then
|
|
local t="${d%/}/.exec_test_$$"
|
|
printf '#!/bin/sh\necho ok\n' >"$t" 2>/dev/null || { rm -f "$t" 2>/dev/null || true; continue; }
|
|
chmod 700 "$t" 2>/dev/null || { rm -f "$t" 2>/dev/null || true; continue; }
|
|
if "$t" >/dev/null 2>&1; then
|
|
rm -f "$t" 2>/dev/null || true
|
|
echo "$d"
|
|
return 0
|
|
fi
|
|
rm -f "$t" 2>/dev/null || true
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
EXEC_DIR="$(pick_exec_dir || true)"
|
|
if [ -z "${EXEC_DIR:-}" ]; then
|
|
echo "ERROR: Could not find an exec-capable writable directory."
|
|
exit 1
|
|
fi
|
|
|
|
######################
|
|
# Select the shebang #
|
|
######################
|
|
|
|
candidate_shebangs=(
|
|
"/command/with-contenv bashio"
|
|
"/usr/bin/with-contenv bashio"
|
|
"/usr/bin/env bashio"
|
|
"/usr/bin/bashio"
|
|
"/usr/bin/bash"
|
|
"/bin/bash"
|
|
"/usr/bin/sh"
|
|
"/bin/sh"
|
|
)
|
|
|
|
SHEBANG_ERRORS=()
|
|
|
|
probe_script_content='
|
|
set -e
|
|
|
|
if ! command -v bashio::addon.version >/dev/null 2>&1; then
|
|
for f in \
|
|
/usr/lib/bashio/bashio.sh \
|
|
/usr/lib/bashio/lib.sh \
|
|
/usr/src/bashio/bashio.sh \
|
|
/usr/local/lib/bashio/bashio.sh
|
|
do
|
|
if [ -f "$f" ]; then
|
|
# shellcheck disable=SC1090
|
|
. "$f"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
set +e
|
|
_bv="$(bashio::addon.version 2>/dev/null)"
|
|
_rc=$?
|
|
set -e
|
|
|
|
if [ "$_rc" -ne 0 ] || [ -z "$_bv" ] || [ "$_bv" = "null" ]; then
|
|
for _sf in /usr/local/lib/bashio-standalone.sh /.bashio-standalone.sh; do
|
|
if [ -f "$_sf" ]; then
|
|
# shellcheck disable=SC1090
|
|
. "$_sf"
|
|
_bv="$(bashio::addon.version 2>/dev/null || true)"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
echo "${_bv:-PROBE_OK}"
|
|
'
|
|
|
|
validate_shebang() {
|
|
local candidate="$1"
|
|
local tmp out rc
|
|
local errfile msg
|
|
|
|
# shellcheck disable=SC2206
|
|
local cmd=( $candidate )
|
|
local exe="${cmd[0]}"
|
|
|
|
if [ ! -x "$exe" ]; then
|
|
SHEBANG_ERRORS+=(" - FAIL (not executable): #!$candidate")
|
|
return 1
|
|
fi
|
|
|
|
tmp="${EXEC_DIR%/}/shebang_test.$$.$RANDOM"
|
|
errfile="${EXEC_DIR%/}/shebang_probe_err.$$"
|
|
{
|
|
printf '#!%s\n' "$candidate"
|
|
printf '%s\n' "$probe_script_content"
|
|
} >"$tmp"
|
|
chmod 700 "$tmp" 2>/dev/null || true
|
|
|
|
set +e
|
|
out="$("$tmp" 2>"$errfile")"
|
|
rc=$?
|
|
set -e
|
|
|
|
rm -f "$tmp" 2>/dev/null || true
|
|
|
|
if [ "$rc" -eq 0 ] && [ -n "${out:-}" ] && [ "$out" != "null" ]; then
|
|
rm -f "$errfile" 2>/dev/null || true
|
|
return 0
|
|
fi
|
|
|
|
msg=$' - FAIL: #!'"$candidate"$'\n'" rc=$rc, stdout='${out:-}'"$'\n'
|
|
if [ -s "$errfile" ]; then
|
|
msg+=$' stderr:\n'
|
|
msg+="$(sed -n '1,8p' "$errfile")"$'\n'
|
|
else
|
|
msg+=$' stderr: <empty>\n'
|
|
fi
|
|
SHEBANG_ERRORS+=("$msg")
|
|
rm -f "$errfile" 2>/dev/null || true
|
|
return 1
|
|
}
|
|
|
|
shebang=""
|
|
for candidate in "${candidate_shebangs[@]}"; do
|
|
if validate_shebang "$candidate"; then
|
|
shebang="$candidate"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$shebang" ]; then
|
|
echo "ERROR: No valid shebang found." >&2
|
|
printf ' - %s\n' "${candidate_shebangs[@]}" >&2
|
|
if [ "${#SHEBANG_ERRORS[@]}" -gt 0 ]; then
|
|
printf '%s\n' "${SHEBANG_ERRORS[@]}" >&2
|
|
fi
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v bashio::addon.version >/dev/null 2>&1; then
|
|
for f in /usr/lib/bashio/bashio.sh /usr/lib/bashio/lib.sh /usr/src/bashio/bashio.sh /usr/local/lib/bashio/bashio.sh /usr/local/lib/bashio-standalone.sh; do
|
|
if [ -f "$f" ]; then
|
|
# shellcheck disable=SC1090
|
|
. "$f"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
##################
|
|
# INITIALIZATION #
|
|
##################
|
|
|
|
# Exit if /config is not mounted or HA not used
|
|
if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then
|
|
echo "..."
|
|
exit 0
|
|
fi
|
|
|
|
# Define slug
|
|
slug="${HOSTNAME/-/_}"
|
|
slug="${slug#*_}"
|
|
|
|
# Check type of config folder
|
|
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
|
|
CONFIGLOCATION="/config"
|
|
CONFIGFILEBROWSER="/app_configs/${HOSTNAME/-/_}/$slug.sh"
|
|
else
|
|
CONFIGLOCATION="/config/addons_autoscripts"
|
|
CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh"
|
|
fi
|
|
|
|
# Default location
|
|
mkdir -p "$CONFIGLOCATION" || true
|
|
CONFIGSOURCE="$CONFIGLOCATION/$slug.sh"
|
|
|
|
bashio::log.notice "This script is used to run custom commands at start of the addon. Instructions here : https://github.com/alexbelgium/hassio-addons/wiki/Running-custom-scripts-in-Addons"
|
|
bashio::log.green "Execute $CONFIGFILEBROWSER if existing"
|
|
|
|
# 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
|
|
fi
|
|
|
|
# Convert scripts to linux
|
|
dos2unix "$CONFIGSOURCE" >/dev/null 2>&1 || true
|
|
chmod +x "$CONFIGSOURCE"
|
|
|
|
if grep -q 'bashio' "$CONFIGSOURCE"; then
|
|
sed -i "1s|^.*|#!$shebang|" "$CONFIGSOURCE"
|
|
else
|
|
sed -i '1s|^.*|#!/bin/bash|' "$CONFIGSOURCE"
|
|
fi
|
|
|
|
# Check if there is actual commands
|
|
while IFS= read -r line; do
|
|
line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
|
|
|
if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then
|
|
bashio::log.green "... script found, executing"
|
|
"$CONFIGSOURCE"
|
|
break
|
|
fi
|
|
done < "$CONFIGSOURCE"
|