From a10316df9cd9a72b98e64dc9cb35939eea7583d5 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 30 Jan 2025 09:40:36 +0100 Subject: [PATCH] Create ha_entrypoint.sh --- .../rootfs/ha_entrypoint.sh | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh diff --git a/zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh b/zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh new file mode 100644 index 000000000..01a520bfe --- /dev/null +++ b/zzz_archived_paperless_ngx/rootfs/ha_entrypoint.sh @@ -0,0 +1,59 @@ +#!/command/with-contenv bashio +# shellcheck shell=bash +echo "Starting..." + +#################### +# Starting scripts # +#################### + +for SCRIPTS in /etc/cont-init.d/*; do + [ -e "$SCRIPTS" ] || continue + echo "$SCRIPTS: executing" + + # Check if run as root + if test "$(id -u)" == 0 && test "$(id -u)" == 0; then + chown "$(id -u)":"$(id -g)" "$SCRIPTS" + chmod a+x "$SCRIPTS" + else + bashio::log.warning "Script executed with user $(id -u):$(id -g), things can break and chown won't work" + # Disable chown and chmod in scripts + sed -i "s/^chown /true # chown /g" "$SCRIPTS" + sed -i "s/ chown / true # chown /g" "$SCRIPTS" + sed -i "s/^chmod /true # chmod /g" "$SCRIPTS" + sed -i "s/ chmod / true # chmod /g" "$SCRIPTS" + fi + + # Get current shebang, if not available use another + currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")" + if [ ! -f "${currentshebang%% *}" ]; then + for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done + sed -i "s|$currentshebang|$shebang|g" "$SCRIPTS" + fi + + # Use source to share env variables when requested + if [ "${ha_entry_source:-null}" = true ] && command -v "source" &>/dev/null; then + # Exit cannot be used with source + sed -i "s/(.*\s|^)exit ([0-9]+)/\1 return \2 || exit \2/g" "$SCRIPTS" + sed -i "s/bashio::exit.nok/return 1/g" "$SCRIPTS" + sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS" + # shellcheck source=/dev/null + source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" + else + # Support for posix only shell + /."$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?" + fi + + # Cleanup + rm "$SCRIPTS" +done + +###################### +# Starting container # +###################### + +echo " " +echo -e "\033[0;32mStarting the upstream container\033[0m" +echo " " + +# Launch lsio mods +if [ -f /docker-mods ]; then exec /docker-mods; fi