From 6a54f3574667523f2f91fb74f4424094493485e0 Mon Sep 17 00:00:00 2001 From: Aetherinox Date: Tue, 13 May 2025 23:47:17 -0700 Subject: [PATCH] build: update builder files --- root/custom-cont-init.d/plugins | 72 ++++++- .../s6-overlay/s6-rc.d/ci-service-check/up | 2 +- root/etc/s6-overlay/s6-rc.d/init-adduser/run | 102 ++++++++++ .../s6-overlay/s6-rc.d/init-custom-files/run | 76 +++++++- root/etc/services.d/tvapp2/run | 184 +++++++++++++++++- 5 files changed, 420 insertions(+), 16 deletions(-) diff --git a/root/custom-cont-init.d/plugins b/root/custom-cont-init.d/plugins index a4c69f73..2a57a86f 100644 --- a/root/custom-cont-init.d/plugins +++ b/root/custom-cont-init.d/plugins @@ -9,10 +9,80 @@ # @repo.3 https://github.com/aetherinox/docker-base-alpine # # +# # +# define > colors +# +# Use the color table at: +# - https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 +# # + +declare -A c=( + [end]=$'\e[0m' + [white]=$'\e[97m' + [bold]=$'\e[1m' + [dim]=$'\e[2m' + [underline]=$'\e[4m' + [strike]=$'\e[9m' + [blink]=$'\e[5m' + [inverted]=$'\e[7m' + [hidden]=$'\e[8m' + [black]=$'\e[0;30m' + [redl]=$'\e[0;91m' + [redd]=$'\e[0;31m' + [magental]=$'\e[0;95m' + [magentad]=$'\e[0;35mm' + [bluel]=$'\e[0;94m' + [blued]=$'\e[0;34m' + [cyanl]=$'\e[0;96m' + [cyand]=$'\e[0;36m' + [greenl]=$'\e[0;92m' + [greend]=$'\e[0;32m' + [yellowl]=$'\e[0;93m' + [yellowd]=$'\e[0;33m' + [greyl]=$'\e[0;37m' + [greyd]=$'\e[0;90m' + [navy]=$'\e[38;5;62m' + [olive]=$'\e[38;5;144m' + [peach]=$'\e[38;5;210m' +) + +# # +# unicode for emojis +# https://apps.timwhitlock.info/emoji/tables/unicode +# # + +declare -A icon=( + ["symbolic link"]=$'\xF0\x9F\x94\x97' # 🔗 + ["regular file"]=$'\xF0\x9F\x93\x84' # 📄 + ["directory"]=$'\xF0\x9F\x93\x81' # 📁 + ["regular empty file"]=$'\xe2\xad\x95' # ⭕ + ["log"]=$'\xF0\x9F\x93\x9C' # 📜 + ["1"]=$'\xF0\x9F\x93\x9C' # 📜 + ["2"]=$'\xF0\x9F\x93\x9C' # 📜 + ["3"]=$'\xF0\x9F\x93\x9C' # 📜 + ["4"]=$'\xF0\x9F\x93\x9C' # 📜 + ["5"]=$'\xF0\x9F\x93\x9C' # 📜 + ["pem"]=$'\xF0\x9F\x94\x92' # 🔑 + ["pub"]=$'\xF0\x9F\x94\x91' # 🔒 + ["pfx"]=$'\xF0\x9F\x94\x92' # 🔑 + ["p12"]=$'\xF0\x9F\x94\x92' # 🔑 + ["key"]=$'\xF0\x9F\x94\x91' # 🔒 + ["crt"]=$'\xF0\x9F\xAA\xAA ' # 🪪 + ["gz"]=$'\xF0\x9F\x93\xA6' # 📦 + ["zip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["gzip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["deb"]=$'\xF0\x9F\x93\xA6' # 📦 + ["sh"]=$'\xF0\x9F\x97\x94' # 🗔 +) + +# # +# define > general +# # + PLUGINS_PATH="/config/www/plugins" # # # Plugins > Start # # -echo -e " Loader : Checking tvapp2-plugins" +printf '%-29s %-65s\n' " ${c[bluel]}Loader${c[end]}" "${c[end]}Checking tvapp2-plugins${c[end]}" diff --git a/root/etc/s6-overlay/s6-rc.d/ci-service-check/up b/root/etc/s6-overlay/s6-rc.d/ci-service-check/up index b5a14787..37be1277 100644 --- a/root/etc/s6-overlay/s6-rc.d/ci-service-check/up +++ b/root/etc/s6-overlay/s6-rc.d/ci-service-check/up @@ -1 +1 @@ -echo -e " Core : Completed loading container" +echo -e " Completed loading container" diff --git a/root/etc/s6-overlay/s6-rc.d/init-adduser/run b/root/etc/s6-overlay/s6-rc.d/init-adduser/run index b296d117..50c44a9b 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-adduser/run +++ b/root/etc/s6-overlay/s6-rc.d/init-adduser/run @@ -1,23 +1,121 @@ #!/usr/bin/with-contenv bash # shellcheck shell=bash +# # +# defaults +# # + PUID=${PUID:-911} PGID=${PGID:-911} +DIR_BUILD=${DIR_BUILD:-/usr/src/app} +DIR_RUN=${DIR_RUN:-/usr/bin/app} +bHasError=false + +# # +# define > colors +# +# Use the color table at: +# - https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 +# # + +declare -A c=( + [end]=$'\e[0m' + [white]=$'\e[97m' + [bold]=$'\e[1m' + [dim]=$'\e[2m' + [underline]=$'\e[4m' + [strike]=$'\e[9m' + [blink]=$'\e[5m' + [inverted]=$'\e[7m' + [hidden]=$'\e[8m' + [black]=$'\e[0;30m' + [redl]=$'\e[0;91m' + [redd]=$'\e[0;31m' + [magental]=$'\e[0;95m' + [magentad]=$'\e[0;35mm' + [bluel]=$'\e[0;94m' + [blued]=$'\e[0;34m' + [cyanl]=$'\e[0;96m' + [cyand]=$'\e[0;36m' + [greenl]=$'\e[0;92m' + [greend]=$'\e[0;32m' + [yellowl]=$'\e[0;93m' + [yellowd]=$'\e[0;33m' + [greyl]=$'\e[0;37m' + [greyd]=$'\e[0;90m' + [navy]=$'\e[38;5;62m' + [olive]=$'\e[38;5;144m' + [peach]=$'\e[38;5;210m' +) + +# # +# unicode for emojis +# https://apps.timwhitlock.info/emoji/tables/unicode +# # + +declare -A icon=( + ["symbolic link"]=$'\xF0\x9F\x94\x97' # 🔗 + ["regular file"]=$'\xF0\x9F\x93\x84' # 📄 + ["directory"]=$'\xF0\x9F\x93\x81' # 📁 + ["regular empty file"]=$'\xe2\xad\x95' # ⭕ + ["log"]=$'\xF0\x9F\x93\x9C' # 📜 + ["1"]=$'\xF0\x9F\x93\x9C' # 📜 + ["2"]=$'\xF0\x9F\x93\x9C' # 📜 + ["3"]=$'\xF0\x9F\x93\x9C' # 📜 + ["4"]=$'\xF0\x9F\x93\x9C' # 📜 + ["5"]=$'\xF0\x9F\x93\x9C' # 📜 + ["pem"]=$'\xF0\x9F\x94\x92' # 🔑 + ["pub"]=$'\xF0\x9F\x94\x91' # 🔒 + ["pfx"]=$'\xF0\x9F\x94\x92' # 🔑 + ["p12"]=$'\xF0\x9F\x94\x92' # 🔑 + ["key"]=$'\xF0\x9F\x94\x91' # 🔒 + ["crt"]=$'\xF0\x9F\xAA\xAA ' # 🪪 + ["gz"]=$'\xF0\x9F\x93\xA6' # 📦 + ["zip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["gzip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["deb"]=$'\xF0\x9F\x93\xA6' # 📦 + ["sh"]=$'\xF0\x9F\x97\x94' # 🗔 +) + +# # +# get container ips +# # IP_GATEWAY=$(/sbin/ip route|awk '/default/ { print $3 }') IP_CONTAINER=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1') +# # +# usermod +# -o, --non-unique allow using duplicate (non-unique) UID +# -g, --gid GROUP force use GROUP as new primary group +# -G, --groups GROUPS new list of supplementary GROUPS +# -u, --uid UID new UID for the user account +# -U, --unlock unlock the user account +# +# groupmod +# -g, --gid GID change the group ID to GID +# -o, --non-unique allow to use a duplicate (non-unique) GID +# # + if [[ -z ${TVAPP_READ_ONLY_FS} ]] && [[ -z ${TVAPP_NON_ROOT_USER} ]]; then groupmod -o -g "$PGID" dockerx usermod -o -u "$PUID" dockerx fi +# # +# s6 > branding +# # + if { [[ -z ${TVAPP_READ_ONLY_FS} ]] && [[ -z ${TVAPP_NON_ROOT_USER} ]]; } || [[ ! ${TVAPP_FIRST_PARTY} = "true" ]]; then cat /etc/s6-overlay/s6-rc.d/init-adduser/branding else cat /run/branding fi +# # +# branding > non-root user +# # + if [[ -z ${TVAPP_NON_ROOT_USER} ]]; then echo "" echo " User:Group $(id -u dockerx):$(id -g dockerx)" @@ -31,6 +129,10 @@ echo " App Folder $(echo $DIR_RUN)" echo "" echo '──────────────────────────────────────────────────────────────────────────────────────────' +# # +# set permissions +# # + if [[ -z ${TVAPP_READ_ONLY_FS} ]] && [[ -z ${TVAPP_NON_ROOT_USER} ]]; then aetherxown dockerx:dockerx /app aetherxown dockerx:dockerx /config diff --git a/root/etc/s6-overlay/s6-rc.d/init-custom-files/run b/root/etc/s6-overlay/s6-rc.d/init-custom-files/run index 21129925..81265df0 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-custom-files/run +++ b/root/etc/s6-overlay/s6-rc.d/init-custom-files/run @@ -1,22 +1,88 @@ #!/usr/bin/with-contenv bash # shellcheck shell=bash +# # +# define > colors +# +# Use the color table at: +# - https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 +# # + +declare -A c=( + [end]=$'\e[0m' + [white]=$'\e[97m' + [bold]=$'\e[1m' + [dim]=$'\e[2m' + [underline]=$'\e[4m' + [strike]=$'\e[9m' + [blink]=$'\e[5m' + [inverted]=$'\e[7m' + [hidden]=$'\e[8m' + [black]=$'\e[0;30m' + [redl]=$'\e[0;91m' + [redd]=$'\e[0;31m' + [magental]=$'\e[0;95m' + [magentad]=$'\e[0;35mm' + [bluel]=$'\e[0;94m' + [blued]=$'\e[0;34m' + [cyanl]=$'\e[0;96m' + [cyand]=$'\e[0;36m' + [greenl]=$'\e[0;92m' + [greend]=$'\e[0;32m' + [yellowl]=$'\e[0;93m' + [yellowd]=$'\e[0;33m' + [greyl]=$'\e[0;37m' + [greyd]=$'\e[0;90m' + [navy]=$'\e[38;5;62m' + [olive]=$'\e[38;5;144m' + [peach]=$'\e[38;5;210m' +) + +# # +# unicode for emojis +# https://apps.timwhitlock.info/emoji/tables/unicode +# # + +declare -A icon=( + ["symbolic link"]=$'\xF0\x9F\x94\x97' # 🔗 + ["regular file"]=$'\xF0\x9F\x93\x84' # 📄 + ["directory"]=$'\xF0\x9F\x93\x81' # 📁 + ["regular empty file"]=$'\xe2\xad\x95' # ⭕ + ["log"]=$'\xF0\x9F\x93\x9C' # 📜 + ["1"]=$'\xF0\x9F\x93\x9C' # 📜 + ["2"]=$'\xF0\x9F\x93\x9C' # 📜 + ["3"]=$'\xF0\x9F\x93\x9C' # 📜 + ["4"]=$'\xF0\x9F\x93\x9C' # 📜 + ["5"]=$'\xF0\x9F\x93\x9C' # 📜 + ["pem"]=$'\xF0\x9F\x94\x92' # 🔑 + ["pub"]=$'\xF0\x9F\x94\x91' # 🔒 + ["pfx"]=$'\xF0\x9F\x94\x92' # 🔑 + ["p12"]=$'\xF0\x9F\x94\x92' # 🔑 + ["key"]=$'\xF0\x9F\x94\x91' # 🔒 + ["crt"]=$'\xF0\x9F\xAA\xAA ' # 🪪 + ["gz"]=$'\xF0\x9F\x93\xA6' # 📦 + ["zip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["gzip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["deb"]=$'\xF0\x9F\x93\xA6' # 📦 + ["sh"]=$'\xF0\x9F\x97\x94' # 🗔 +) + # Directories SCRIPTS_DIR="/custom-cont-init.d" # Make sure custom init directory exists and has files in it if [[ -e "${SCRIPTS_DIR}" ]] && [[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]]; then - echo -e " Loader : Plugins found, loading them ..." + printf '%-29s %-65s\n' " ${c[bluel]}Loader${c[end]}" "${c[end]}Loading any found plugins${c[end]}" for SCRIPT in "${SCRIPTS_DIR}"/*; do NAME="$(basename "${SCRIPT}")" if [[ -f "${SCRIPT}" ]]; then - echo -e " Loader : Executing ..." + printf '%-29s %-65s\n' " ${c[bluel]}Loader${c[end]}" "${c[end]}Executing${c[end]}" /bin/bash "${SCRIPT}" - echo -e " Loader : ${NAME}: Ran Successfully with code [$?]" + printf '%-29s %-65s\n' " ${c[bluel]}Loader${c[end]}" "${c[end]}Successfully ran with code ${c[bluel]}[$?]${c[end]}" elif [[ ! -f "${SCRIPT}" ]]; then - echo -e " Loader : ${NAME}: Not a valid file" + printf '%-29s %-65s\n' " ${c[bluel]}Loader${c[end]}" "${c[end]}${c[bluel]}${NAME}${c[end]} is not a valid file${c[end]}" fi done else - echo -e " Loader : No Plugins found, skipping..." + printf '%-29s %-65s\n' " ${c[bluel]}Loader${c[end]}" "${c[end]}No plugins found; skipping${c[end]}" fi diff --git a/root/etc/services.d/tvapp2/run b/root/etc/services.d/tvapp2/run index 8c8c5818..b21dd907 100755 --- a/root/etc/services.d/tvapp2/run +++ b/root/etc/services.d/tvapp2/run @@ -1,14 +1,113 @@ -#!/usr/bin/with-contenv sh +#!/usr/bin/with-contenv bash +# shellcheck shell=bash # # -# Store env variables in s6 +# defaults +# # + +PUID=${PUID:-911} +PGID=${PGID:-911} +DIR_BUILD=${DIR_BUILD:-/usr/src/app} +DIR_RUN=${DIR_RUN:-/usr/bin/app} +bHasError=false + +# # +# define > colors +# +# Use the color table at: +# - https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 +# # + +declare -A c=( + [end]=$'\e[0m' + [white]=$'\e[97m' + [bold]=$'\e[1m' + [dim]=$'\e[2m' + [underline]=$'\e[4m' + [strike]=$'\e[9m' + [blink]=$'\e[5m' + [inverted]=$'\e[7m' + [hidden]=$'\e[8m' + [black]=$'\e[0;30m' + [redl]=$'\e[0;91m' + [redd]=$'\e[0;31m' + [magental]=$'\e[0;95m' + [magentad]=$'\e[0;35mm' + [bluel]=$'\e[0;94m' + [blued]=$'\e[0;34m' + [cyanl]=$'\e[0;96m' + [cyand]=$'\e[0;36m' + [greenl]=$'\e[0;92m' + [greend]=$'\e[0;32m' + [yellowl]=$'\e[0;93m' + [yellowd]=$'\e[0;33m' + [greyl]=$'\e[0;37m' + [greyd]=$'\e[0;90m' + [navy]=$'\e[38;5;62m' + [olive]=$'\e[38;5;144m' + [peach]=$'\e[38;5;210m' +) + +# # +# unicode for emojis +# https://apps.timwhitlock.info/emoji/tables/unicode +# # + +declare -A icon=( + ["symbolic link"]=$'\xF0\x9F\x94\x97' # 🔗 + ["regular file"]=$'\xF0\x9F\x93\x84' # 📄 + ["directory"]=$'\xF0\x9F\x93\x81' # 📁 + ["regular empty file"]=$'\xe2\xad\x95' # ⭕ + ["log"]=$'\xF0\x9F\x93\x9C' # 📜 + ["1"]=$'\xF0\x9F\x93\x9C' # 📜 + ["2"]=$'\xF0\x9F\x93\x9C' # 📜 + ["3"]=$'\xF0\x9F\x93\x9C' # 📜 + ["4"]=$'\xF0\x9F\x93\x9C' # 📜 + ["5"]=$'\xF0\x9F\x93\x9C' # 📜 + ["pem"]=$'\xF0\x9F\x94\x92' # 🔑 + ["pub"]=$'\xF0\x9F\x94\x91' # 🔒 + ["pfx"]=$'\xF0\x9F\x94\x92' # 🔑 + ["p12"]=$'\xF0\x9F\x94\x92' # 🔑 + ["key"]=$'\xF0\x9F\x94\x91' # 🔒 + ["crt"]=$'\xF0\x9F\xAA\xAA ' # 🪪 + ["gz"]=$'\xF0\x9F\x93\xA6' # 📦 + ["zip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["gzip"]=$'\xF0\x9F\x93\xA6' # 📦 + ["deb"]=$'\xF0\x9F\x93\xA6' # 📦 + ["sh"]=$'\xF0\x9F\x97\x94' # 🗔 +) + +# # +# define > system +# # + +sys_os_ver="1.0.0" +sys_os_name="Unknown" + +# # +# s6 > store env variables +# # + +printf '%-29s %-65s\n' " ${c[bluel]}STATUS${c[end]}" "${c[end]}Fetching docker container and gateway addresses${c[end]}" + +# # +# get container ips # # ip_gateway=$(/sbin/ip route|awk '/default/ { print $3 }') ip_container=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1') -printf "$ip_gateway" > /var/run/s6/container_environment/IP_GATEWAY -printf "$ip_container" > /var/run/s6/container_environment/IP_CONTAINER +if [ -d "/var/run/s6/container_environment/" ]; then + printf "$ip_gateway" > /var/run/s6/container_environment/IP_GATEWAY + printf "$ip_container" > /var/run/s6/container_environment/IP_CONTAINER +else + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot generate s6-overlay env files; folder ${c[redl]}/var/run/s6/container_environment/${c[end]} does not exist${c[end]}" + bHasError=true +fi + +# # +# s6 > export env vars +# # export IP_GATEWAY=$ip_gateway export IP_GATEWAY=$ip_container @@ -17,8 +116,75 @@ export IP_GATEWAY=$ip_container # install and startup for tvapp2 # # -cp -r ${DIR_BUILD}/* ${DIR_RUN} -rm -rf ${DIR_BUILD}/* -cd ${DIR_RUN} -npm install --omit=dev -npm start +printf '%-29s %-65s\n' " ${c[bluel]}STATUS${c[end]}" "${c[end]}Copying ${c[bluel]}${DIR_BUILD}${c[end]} to ${c[bluel]}${DIR_RUN}${c[end]}" +if [ -z "${DIR_BUILD}" ]; then + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot copy; env var ${c[redl]}\${DIR_BUILD}${c[end]} missing${c[end]}" + bHasError=true +else + if [ -d "${DIR_BUILD}" ]; then + cp -r ${DIR_BUILD}/* ${DIR_RUN} + else + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot copy folder ${c[redl]}${DIR_BUILD}${c[end]} to ${c[redl]}${DIR_RUN}${c[end]}; build folder ${c[redl]}${DIR_BUILD}${c[end]} does not exist${c[end]}" + bHasError=true + fi +fi + +# # +# remove build directory +# # + +printf '%-29s %-65s\n' " ${c[bluel]}STATUS${c[end]}" "${c[end]}Remove ${c[bluel]}${DIR_BUILD}/${c[end]}" +if [ -z "${DIR_BUILD}" ]; then + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot remove; env var ${c[redl]}\${DIR_BUILD}${c[end]} missing${c[end]}" +else + if [ -d "${DIR_BUILD}" ]; then + rm -rf ${DIR_BUILD}/* + else + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot remove; build folder ${c[redl]}${DIR_BUILD}${c[end]} does not exist${c[end]}" + fi +fi + +# # +# cd to BUILD_RUN directory +# # + +printf '%-29s %-65s\n' " ${c[bluel]}STATUS${c[end]}" "${c[end]}Changing to run directory ${c[bluel]}${DIR_RUN}/${c[end]}" +if [ -z "${DIR_RUN}" ]; then + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot cd; env var ${c[redl]}\${DIR_RUN}${c[end]} missing${c[end]}" + bHasError=true +else + if [ -d "${DIR_RUN}" ]; then + cd ${DIR_RUN} + else + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot cd; run folder ${c[redl]}${DIR_RUN}${c[end]} does not exist${c[end]}" + bHasError=true + fi +fi + +# # +# install tvapp2 via npm +# # + +printf '%-29s %-65s\n' " ${c[bluel]}STATUS${c[end]}" "${c[end]}Running command ${c[bluel]}npm install --omit=dev${c[end]}" +if ! [ -x "$(command -v npm)" ]; then + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Cannot install TVApp2 with npm because package ${c[redl]}npm${c[end]} not installed${c[end]}" + bHasError=true +else + npm install --omit=dev + + printf '%-29s %-65s\n' " ${c[bluel]}STATUS${c[end]}" "${c[end]}Running command ${c[bluel]}npm start${c[end]}" + npm start +fi + +# # +# finished run script +# # + +printf '%-29s %-65s\n' " ${c[greenl]}OK${c[end]}" "${c[end]}Finished initializing script${c[end]}" +if [ "$bHasError" = true ] ; then + printf '%-29s %-65s\n' "" "" + printf '%-29s %-65s\n' " ${c[redl]}ERROR${c[end]}" "${c[end]}Fatal errors were detected${c[end]}" + printf '%-29s %-65s\n' " ${c[redl]}${c[end]}" "${c[end]}The run script detected that certain steps failed. This app may not${c[end]}" + printf '%-29s %-65s\n' " ${c[redl]}${c[end]}" "${c[end]}work properly. Try restarting the container.${c[end]}" + printf '%-29s %-65s\n' "" "" +fi