mirror of
https://github.com/casjaysdevdocker/tor
synced 2025-10-14 02:02:18 -04:00
🦈🏠🐜❗ Initial Commit ❗🐜🦈🏠
All checks were successful
release-tag / release-image (push) Successful in 6m56s
All checks were successful
release-tag / release-image (push) Successful in 6m56s
This commit is contained in:
40
rootfs/root/docker/setup/00-init.sh
Executable file
40
rootfs/root/docker/setup/00-init.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061127-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 00-init.sh
|
||||
# @@Description : script to run init
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
if [ -d "/usr/local/share/template-files/data" ]; then rm -Rf "/usr/local/share/template-files/data"/*; fi
|
||||
if [ -d "/usr/local/share/template-files/config" ]; then rm -Rf "/usr/local/share/template-files/config"/*; fi
|
||||
if [ -d "/usr/local/share/template-files/defaults" ]; then rm -Rf "/usr/local/share/template-files/defaults"/*; fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
38
rootfs/root/docker/setup/01-system.sh
Executable file
38
rootfs/root/docker/setup/01-system.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061127-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 01-system.sh
|
||||
# @@Description : script to run system
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
38
rootfs/root/docker/setup/02-packages.sh
Executable file
38
rootfs/root/docker/setup/02-packages.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061127-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 02-packages.sh
|
||||
# @@Description : script to run packages
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
89
rootfs/root/docker/setup/03-files.sh
Executable file
89
rootfs/root/docker/setup/03-files.sh
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202408270903-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 03-files.sh
|
||||
# @@Description : script to run files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
rm -Rf /etc/unbound/*
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
if [ -d "/tmp/bin" ]; then
|
||||
mkdir -p "/usr/local/bin"
|
||||
for bin in "/tmp/bin"/*; do
|
||||
name="$(basename -- "$bin")"
|
||||
echo "Installing $name to /usr/local/bin/$name"
|
||||
copy "$bin" "/usr/local/bin/$name"
|
||||
chmod -f +x "/usr/local/bin/$name"
|
||||
done
|
||||
fi
|
||||
unset bin
|
||||
if [ -d "/tmp/var" ]; then
|
||||
for var in "/tmp/var"/*; do
|
||||
name="$(basename -- "$var")"
|
||||
echo "Installing $var to /var/$name"
|
||||
if [ -d "$var" ]; then
|
||||
mkdir -p "/var/$name"
|
||||
copy "$var/." "/var/$name/"
|
||||
else
|
||||
copy "$var" "/var/$name"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
unset var
|
||||
if [ -d "/tmp/etc" ]; then
|
||||
for config in "/tmp/etc"/*; do
|
||||
name="$(basename -- "$config")"
|
||||
echo "Installing $config to /etc/$name"
|
||||
if [ -d "$config" ]; then
|
||||
mkdir -p "/etc/$name"
|
||||
copy "$config/." "/etc/$name/"
|
||||
mkdir -p "/usr/local/share/template-files/config/$name"
|
||||
copy "$config/." "/usr/local/share/template-files/config/$name/"
|
||||
else
|
||||
copy "$config" "/etc/$name"
|
||||
copy "$config" "/usr/local/share/template-files/config/$name"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
unset config
|
||||
if [ -d "/tmp/data" ]; then
|
||||
for data in "/tmp/data"/*; do
|
||||
name="$(basename -- "$data")"
|
||||
echo "Installing $data to /usr/local/share/template-files/data"
|
||||
if [ -d "$data" ]; then
|
||||
mkdir -p "/usr/local/share/template-files/data/$name"
|
||||
copy "$data/." "/usr/local/share/template-files/data/$name/"
|
||||
else
|
||||
copy "$data" "/usr/local/share/template-files/data/$name"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
unset data
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
38
rootfs/root/docker/setup/04-users.sh
Executable file
38
rootfs/root/docker/setup/04-users.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061127-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 04-users.sh
|
||||
# @@Description : script to run users
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
47
rootfs/root/docker/setup/05-custom.sh
Executable file
47
rootfs/root/docker/setup/05-custom.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061127-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 05-custom.sh
|
||||
# @@Description : script to run custom
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
tor_bin="$(type -P tor)"
|
||||
tor_dir=$(dirname "$tor_bin")
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
for tor_service in bridge relay server; do cp -Rf "$tor_bin" "$tor_dir/tor-$tor_service"; done
|
||||
[ -f "/etc/privoxy/trust.new" ] && mv -f /etc/privoxy/trust.new /etc/privoxy/trust
|
||||
[ -f "/etc/privoxy/user.action.new" ] && mv -f /etc/privoxy/user.action.new /etc/privoxy/user.action
|
||||
[ -f "/etc/privoxy/user.filter.new" ] && mv -f /etc/privoxy/user.filter.new /etc/privoxy/user.filter
|
||||
[ -f "/etc/privoxy/default.action.new" ] && mv -f /etc/privoxy/default.action.new /etc/privoxy/default.action
|
||||
[ -f "/etc/privoxy/default.filter.new" ] && mv -f /etc/privoxy/default.filter.new /etc/privoxy/default.filter
|
||||
[ -f "/etc/privoxy/match-all.action.new" ] && mv -f /etc/privoxy/match-all.action.new /etc/privoxy/match-all.action
|
||||
[ -f "/etc/privoxy/regression-tests.action.new" ] && mv -f /etc/privoxy/regression-tests.action.new /etc/privoxy/regression-tests.action
|
||||
rm -Rf /etc/privoxy/*.new /etc/tor/*.sample
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
38
rootfs/root/docker/setup/06-post.sh
Executable file
38
rootfs/root/docker/setup/06-post.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061127-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 06-post.sh
|
||||
# @@Description : script to run post
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
39
rootfs/root/docker/setup/07-cleanup.sh
Executable file
39
rootfs/root/docker/setup/07-cleanup.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061127-git
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 07-cleanup.sh
|
||||
# @@Description : script to run cleanup
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
if [ -d "/tmp" ]; then rm -Rf "/tmp"/*; fi
|
||||
if [ -d "$HOME/.cache" ]; then rm -Rf "$HOME/.cache"; fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
79
rootfs/tmp/etc/nginx/mime.types
Normal file
79
rootfs/tmp/etc/nginx/mime.types
Normal file
@@ -0,0 +1,79 @@
|
||||
types {
|
||||
text/html html htm shtml;
|
||||
text/css css;
|
||||
text/xml xml;
|
||||
image/gif gif;
|
||||
image/jpeg jpeg jpg;
|
||||
application/x-javascript js;
|
||||
application/atom+xml atom;
|
||||
application/rss+xml rss;
|
||||
|
||||
text/mathml mml;
|
||||
text/plain txt;
|
||||
text/vnd.sun.j2me.app-descriptor jad;
|
||||
text/vnd.wap.wml wml;
|
||||
text/x-component htc;
|
||||
|
||||
image/png png;
|
||||
image/tiff tif tiff;
|
||||
image/vnd.wap.wbmp wbmp;
|
||||
image/x-icon ico;
|
||||
image/x-jng jng;
|
||||
image/x-ms-bmp bmp;
|
||||
image/svg+xml svg svgz;
|
||||
image/webp webp;
|
||||
|
||||
application/java-archive jar war ear;
|
||||
application/mac-binhex40 hqx;
|
||||
application/msword doc;
|
||||
application/pdf pdf;
|
||||
application/postscript ps eps ai;
|
||||
application/rtf rtf;
|
||||
application/vnd.ms-excel xls;
|
||||
application/vnd.ms-powerpoint ppt;
|
||||
application/vnd.wap.wmlc wmlc;
|
||||
application/vnd.google-earth.kml+xml kml;
|
||||
application/vnd.google-earth.kmz kmz;
|
||||
application/x-7z-compressed 7z;
|
||||
application/x-cocoa cco;
|
||||
application/x-java-archive-diff jardiff;
|
||||
application/x-java-jnlp-file jnlp;
|
||||
application/x-makeself run;
|
||||
application/x-perl pl pm;
|
||||
application/x-pilot prc pdb;
|
||||
application/x-rar-compressed rar;
|
||||
application/x-redhat-package-manager rpm;
|
||||
application/x-sea sea;
|
||||
application/x-shockwave-flash swf;
|
||||
application/x-stuffit sit;
|
||||
application/x-tcl tcl tk;
|
||||
application/x-x509-ca-cert der pem crt;
|
||||
application/x-xpinstall xpi;
|
||||
application/xhtml+xml xhtml;
|
||||
application/zip zip;
|
||||
|
||||
application/octet-stream bin exe dll;
|
||||
application/octet-stream deb;
|
||||
application/octet-stream dmg;
|
||||
application/octet-stream eot;
|
||||
application/octet-stream iso img;
|
||||
application/octet-stream msi msp msm;
|
||||
|
||||
audio/midi mid midi kar;
|
||||
audio/mpeg mp3;
|
||||
audio/ogg ogg;
|
||||
audio/x-m4a m4a;
|
||||
audio/x-realaudio ra;
|
||||
|
||||
video/3gpp 3gpp 3gp;
|
||||
video/mp4 mp4;
|
||||
video/mpeg mpeg mpg;
|
||||
video/quicktime mov;
|
||||
video/webm webm;
|
||||
video/x-flv flv;
|
||||
video/x-m4v m4v;
|
||||
video/x-mng mng;
|
||||
video/x-ms-asf asx asf;
|
||||
video/x-ms-wmv wmv;
|
||||
video/x-msvideo avi;
|
||||
}
|
126
rootfs/tmp/etc/nginx/nginx.conf
Normal file
126
rootfs/tmp/etc/nginx/nginx.conf
Normal file
@@ -0,0 +1,126 @@
|
||||
# Default nginx configuration
|
||||
user REPLACE_SERVICE_USER;
|
||||
worker_processes auto;
|
||||
daemon off;
|
||||
pid /run/nginx.pid;
|
||||
error_log /data/logs/nginx/nginx.log warn;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type "text/html";
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
gzip on;
|
||||
disable_symlinks off;
|
||||
server_names_hash_bucket_size 128;
|
||||
access_log /data/logs/nginx/access.REPLACE_SERVER_NAME.log;
|
||||
map $http_upgrade $connection_upgrade { default upgrade; '' close; }
|
||||
root REPLACE_SERVER_WWW_DIR;
|
||||
|
||||
server {
|
||||
listen REPLACE_SERVER_PORT default_server;
|
||||
server_name REPLACE_SERVER_NAME;
|
||||
root REPLACE_SERVER_WWW_DIR;
|
||||
index index.php index.html index.cgi index.pl index.aspx index.txt index.json index.unknown.php index.default.php;
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' *; frame-src 'self' *; object-src 'self'" always;
|
||||
proxy_intercept_errors off;
|
||||
client_max_body_size 0;
|
||||
send_timeout 3600;
|
||||
|
||||
location ^~ /favicon.ico {
|
||||
alias REPLACE_SERVER_WWW_DIR/favicon.ico;
|
||||
allow all;
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location ^~ /robots.txt {
|
||||
default_type "text/plain";
|
||||
alias REPLACE_SERVER_WWW_DIR/robots.txt;
|
||||
allow all;
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location ^~ /.well-known {
|
||||
default_type "text/plain";
|
||||
alias REPLACE_SERVER_WWW_DIR/.well-known;
|
||||
allow all;
|
||||
log_not_found on;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location ^~ /.well-known/security.txt {
|
||||
default_type "text/plain";
|
||||
alias REPLACE_SERVER_WWW_DIR/security.txt;
|
||||
allow all;
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location ^~ /health {
|
||||
default_type "text/plain";
|
||||
allow all;
|
||||
access_log off;
|
||||
return 200 'ok';
|
||||
}
|
||||
|
||||
location ^~ /health/txt {
|
||||
default_type "text/plain";
|
||||
allow all;
|
||||
access_log off;
|
||||
return 200 'ok';
|
||||
}
|
||||
|
||||
location ^~ /health/json {
|
||||
default_type "application/json";
|
||||
allow all;
|
||||
access_log off;
|
||||
return 200 '{"status":"OK"}';
|
||||
}
|
||||
|
||||
location ^~ /health/status {
|
||||
stub_status;
|
||||
}
|
||||
|
||||
location ~ [^/]\.php(/|$) {
|
||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||
if (!-f $document_root$fastcgi_script_name) {
|
||||
return 404;
|
||||
}
|
||||
fastcgi_param HTTP_PROXY "";
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param QUERY_STRING $query_string;
|
||||
fastcgi_param REQUEST_METHOD $request_method;
|
||||
fastcgi_param CONTENT_TYPE $content_type;
|
||||
fastcgi_param CONTENT_LENGTH $content_length;
|
||||
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param REQUEST_URI $request_uri;
|
||||
fastcgi_param DOCUMENT_URI $document_uri;
|
||||
fastcgi_param DOCUMENT_ROOT $document_root;
|
||||
fastcgi_param SERVER_PROTOCOL $server_protocol;
|
||||
fastcgi_param REQUEST_SCHEME $scheme;
|
||||
fastcgi_param HTTPS $https if_not_empty;
|
||||
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
|
||||
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
|
||||
fastcgi_param REMOTE_ADDR $remote_addr;
|
||||
fastcgi_param REMOTE_PORT $remote_port;
|
||||
fastcgi_param SERVER_ADDR $server_addr;
|
||||
fastcgi_param SERVER_PORT $server_port;
|
||||
fastcgi_param SERVER_NAME $server_name;
|
||||
fastcgi_param REDIRECT_STATUS 200;
|
||||
}
|
||||
}
|
||||
include /etc/nginx/vhosts.d/*.conf;
|
||||
}
|
71
rootfs/tmp/etc/nginx/vhosts.d/template
Normal file
71
rootfs/tmp/etc/nginx/vhosts.d/template
Normal file
@@ -0,0 +1,71 @@
|
||||
#DO NOT CHANGE THIS FILE
|
||||
#Use as template and copy to /etc/nginx/vhosts.d/servername.conf
|
||||
|
||||
#Reverse Proxy
|
||||
#See /etc/nginx/conf.d/default.conf for proxy servers
|
||||
server {
|
||||
server_name REPLACE_ONION_SITE;
|
||||
listen REPLACE_ONION_PORT;
|
||||
keepalive_timeout 75 75;
|
||||
access_log /data/logs/nginx/access.REPLACE_ONION_SITE.log;
|
||||
error_log /data/logs/nginx/error.REPLACE_ONION_SITE.log info;
|
||||
client_max_body_size 0;
|
||||
send_timeout 3600;
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' *; frame-src 'self' *; object-src 'self'" always;
|
||||
root REPLACE_ONION_WWW_DIR;
|
||||
index index.php index.html index.cgi index.pl index.aspx index.txt index.json index.unknown.php index.default.php;
|
||||
|
||||
location / {
|
||||
root REPLACE_ONION_WWW_DIR;
|
||||
}
|
||||
location ^~ /favicon.ico {
|
||||
alias REPLACE_SERVER_WWW_DIR/favicon.ico;
|
||||
allow all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
location ^~ /robots.txt {
|
||||
default_type "text/plain";
|
||||
alias REPLACE_SERVER_WWW_DIR/robots.txt;
|
||||
allow all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
location ^~ /.well-known {
|
||||
default_type "text/plain";
|
||||
alias REPLACE_SERVER_WWW_DIR/.well-known;
|
||||
allow all;
|
||||
access_log off;
|
||||
log_not_found on;
|
||||
}
|
||||
location ^~ /.well-known/security.txt {
|
||||
default_type "text/plain";
|
||||
alias REPLACE_SERVER_WWW_DIR/security.txt;
|
||||
allow all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
location ^~ /health {
|
||||
default_type "text/plain";
|
||||
allow all;
|
||||
access_log off;
|
||||
return 200 'ok';
|
||||
}
|
||||
location ^~ /health/txt {
|
||||
default_type "text/plain";
|
||||
allow all;
|
||||
access_log off;
|
||||
return 200 'ok';
|
||||
}
|
||||
location ^~ /health/json {
|
||||
default_type "application/json";
|
||||
allow all;
|
||||
access_log off;
|
||||
return 200 '{"status":"OK"}';
|
||||
}
|
||||
}
|
5
rootfs/tmp/etc/privoxy/config
Normal file
5
rootfs/tmp/etc/privoxy/config
Normal file
@@ -0,0 +1,5 @@
|
||||
forward-socks5t / 127.0.0.1:9050 .
|
||||
listen-address 0.0.0.0:8118
|
||||
max-client-connections 9999999
|
||||
listen-backlog 8192
|
||||
trust-x-forwarded-for 1
|
0
rootfs/tmp/etc/tor/torrc
Normal file
0
rootfs/tmp/etc/tor/torrc
Normal file
22
rootfs/tmp/etc/unbound/unbound.conf
Normal file
22
rootfs/tmp/etc/unbound/unbound.conf
Normal file
@@ -0,0 +1,22 @@
|
||||
server:
|
||||
directory: "/etc/unbound"
|
||||
do-udp: yes
|
||||
do-tcp: yes
|
||||
interface: 0.0.0.0
|
||||
interface: ::0
|
||||
interface-automatic: yes
|
||||
interface-automatic-ports: "53 9053"
|
||||
access-control: 0.0.0.0/0 allow
|
||||
access-control: ::/0 allow
|
||||
domain-insecure: "onion"
|
||||
private-domain: "onion"
|
||||
do-not-query-localhost: no
|
||||
local-zone: "onion." nodefault
|
||||
|
||||
forward-zone:
|
||||
name: "onion"
|
||||
forward-addr: 127.0.0.1@8053
|
||||
forward-zone:
|
||||
name: "."
|
||||
forward-addr: 148.135.52.175
|
||||
forward-addr: 1.1.1.1
|
572
rootfs/usr/local/bin/entrypoint.sh
Executable file
572
rootfs/usr/local/bin/entrypoint.sh
Executable file
@@ -0,0 +1,572 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061041-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
# @@ReadME : entrypoint.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Monday, Jan 06, 2025 10:41 EST
|
||||
# @@File : entrypoint.sh
|
||||
# @@Description : Entrypoint file for tor
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/docker-entrypoint
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
SCRIPT_FILE="$0"
|
||||
CONTAINER_NAME="tor"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# remove whitespaces from beginning argument
|
||||
while :; do [ "$1" = " " ] && shift 1 || break; done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$1" = "$SCRIPT_FILE" ] && shift 1
|
||||
[ "$1" = "$SCRIPT_NAME" ] && shift 1
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
|
||||
. "/usr/local/etc/docker/functions/entrypoint.sh"
|
||||
else
|
||||
echo "Can not load functions from /usr/local/etc/docker/functions/entrypoint.sh"
|
||||
exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
case "$1" in
|
||||
# Help message
|
||||
-h | --help)
|
||||
shift 1
|
||||
echo 'Docker container for '$CONTAINER_NAME''
|
||||
echo "Usage: $CONTAINER_NAME [cron exec start init shell certbot ssl procs ports healthcheck backup command]"
|
||||
echo ""
|
||||
exit 0
|
||||
;;
|
||||
-*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create the default env files
|
||||
__create_env_file "/config/env/default.sh" "/root/env.sh" &>/dev/null
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables from files
|
||||
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
unset set_env
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
SERVICE_USER="root" # execute command as another user
|
||||
SERVICE_GROUP="root" # Set the service group
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Primary server port- will be added to server ports
|
||||
WEB_SERVER_PORT="$PORT" # port : 80,443
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Secondary ports
|
||||
SERVER_PORTS="" # specifiy other ports
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Healthcheck variables
|
||||
HEALTH_ENABLED="yes" # enable healthcheck [yes/no]
|
||||
SERVICES_LIST="tini,tor-bridge,tor-relay,tor-server,unbound,privoxy,zz-nginx"
|
||||
HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test]
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Update path var
|
||||
export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_ROOT_DIR DATABASE_DIR
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show message
|
||||
__run_message() {
|
||||
|
||||
return
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
################## END OF CONFIGURATION #####################
|
||||
# Lets get containers ip address
|
||||
IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$IP4_ADDRESS}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Startup variables
|
||||
export INIT_DATE="${INIT_DATE:-$(date)}"
|
||||
export CONTAINER_INIT="${CONTAINER_INIT:-no}"
|
||||
export START_SERVICES="${START_SERVICES:-no}"
|
||||
export ENTRYPOINT_MESSAGE="${ENTRYPOINT_MESSAGE:-yes}"
|
||||
export ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}"
|
||||
export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-no}"
|
||||
export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-no}"
|
||||
export CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# System
|
||||
export LANG="${LANG:-C.UTF-8}"
|
||||
export LC_ALL="${LANG:-C.UTF-8}"
|
||||
export TZ="${TZ:-${TIMEZONE:-America/New_York}}"
|
||||
export HOSTNAME="$(hostname -s)"
|
||||
export DOMAINNAME="$(hostname -d)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default directories
|
||||
export SSL_DIR="${SSL_DIR:-/config/ssl}"
|
||||
export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}"
|
||||
export SSL_KEY="${SSL_KEY:-/config/ssl/localhost.pem}"
|
||||
export SSL_CERT="${SSL_CERT:-/config/ssl/localhost.crt}"
|
||||
export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}"
|
||||
export DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}"
|
||||
export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}"
|
||||
export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Backup settings
|
||||
export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}"
|
||||
export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}"
|
||||
export BACKUP_DIR="${BACKUP_DIR:-/data/backups}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional
|
||||
export PHP_INI_DIR="${PHP_INI_DIR:-$(__find_php_ini)}"
|
||||
export PHP_BIN_DIR="${PHP_BIN_DIR:-$(__find_php_bin)}"
|
||||
export HTTPD_CONFIG_FILE="${HTTPD_CONFIG_FILE:-$(__find_httpd_conf)}"
|
||||
export NGINX_CONFIG_FILE="${NGINX_CONFIG_FILE:-$(__find_nginx_conf)}"
|
||||
export MYSQL_CONFIG_FILE="${MYSQL_CONFIG_FILE:-$(__find_mysql_conf)}"
|
||||
export PGSQL_CONFIG_FILE="${PGSQL_CONFIG_FILE:-$(__find_pgsql_conf)}"
|
||||
export MONGODB_CONFIG_FILE="${MONGODB_CONFIG_FILE:-$(__find_mongodb_conf)}"
|
||||
export ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-$ENTRYPOINT_PID_FILE}"
|
||||
export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}"
|
||||
export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}"
|
||||
export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then
|
||||
www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")"
|
||||
rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/*
|
||||
mkdir -p "$WWW_ROOT_DIR" "$www_temp_dir"
|
||||
git clone -q "$CONTAINER_WEB_SERVER_WWW_REPO" "$www_temp_dir" 2>/dev/null
|
||||
rm -Rf "$www_temp_dir/.git" "$www_temp_dir"/.git*
|
||||
rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete >/dev/null 2>&1
|
||||
rm -Rf "$www_temp_dir"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# variables based on env/files
|
||||
[ -f "/config/enable/ssl" ] && SSL_ENABLED="yes"
|
||||
[ -f "/config/enable/ssh" ] && SSH_ENABLED="yes"
|
||||
[ "$WEB_SERVER_PORT" = "443" ] && SSL_ENABLED="yes"
|
||||
[ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ] && SSL_ENABLED="yes"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# export variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# is already Initialized
|
||||
[ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="yes" || DATA_DIR_INITIALIZED="no"
|
||||
[ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="yes" || CONFIG_DIR_INITIALIZED="no"
|
||||
{ [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="yes"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# clean ENV_PORTS variables
|
||||
ENV_PORTS="${ENV_PORTS//,/ }" #
|
||||
ENV_PORTS="${ENV_PORTS//\/*/}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# clean SERVER_PORTS variables
|
||||
SERVER_PORTS="${SERVER_PORTS//,/ }" #
|
||||
SERVER_PORTS="${SERVER_PORTS//\/*/}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# clean WEB_SERVER_PORTS variables
|
||||
WEB_SERVER_PORTS="${WEB_SERVER_PORT//\/*/}" #
|
||||
WEB_SERVER_PORTS="${WEB_SERVER_PORTS//\/*/}" #
|
||||
WEB_SERVER_PORTS="${WEB_SERVER_PORT//,/ } ${ENV_WEB_SERVER_PORTS//,/ }" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# rewrite and merge variables
|
||||
ENV_PORTS="$(__format_variables "$ENV_PORTS" || false)"
|
||||
WEB_SERVER_PORTS="$(__format_variables "$WEB_SERVER_PORTS" || false)"
|
||||
ENV_PORTS="$(__format_variables "$SERVER_PORTS" "$WEB_SERVER_PORTS" "$ENV_PORTS" "$SERVER_PORTS" || false)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Remove the commas from env
|
||||
HEALTH_ENDPOINTS="${HEALTH_ENDPOINTS//,/ }"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create required directories
|
||||
mkdir -p "/run"
|
||||
mkdir -p "/tmp"
|
||||
mkdir -p "/root"
|
||||
mkdir -p "/var/run"
|
||||
mkdir -p "/var/tmp"
|
||||
mkdir -p "/run/cron"
|
||||
mkdir -p "/data/logs"
|
||||
mkdir -p "/run/init.d"
|
||||
mkdir -p "/config/enable"
|
||||
mkdir -p "/config/secure"
|
||||
mkdir -p "/usr/local/etc/docker/exec"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create required files
|
||||
touch "/data/logs/start.log"
|
||||
touch "/data/logs/entrypoint.log"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# fix permissions
|
||||
chmod -f 777 "/run"
|
||||
chmod -f 777 "/tmp"
|
||||
chmod -f 700 "/root"
|
||||
chmod -f 777 "/var/run"
|
||||
chmod -f 777 "/var/tmp"
|
||||
chmod -f 777 "/run/cron"
|
||||
chmod -f 777 "/data/logs"
|
||||
chmod -f 777 "/run/init.d"
|
||||
chmod -f 777 "/config/enable"
|
||||
chmod -f 777 "/config/secure"
|
||||
chmod -f 777 "/data/logs/entrypoint.log"
|
||||
chmod -f 777 "/usr/local/etc/docker/exec"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# lets ensure everyone can write to std*
|
||||
[ -f "/dev/stdin" ] && chmod -f 777 "/dev/stdin"
|
||||
[ -f "/dev/stderr" ] && chmod -f 777 "/dev/stderr"
|
||||
[ -f "/dev/stdout" ] && chmod -f 777 "/dev/stdout"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
cat <<EOF | tee /etc/profile.d/locales.shadow /etc/profile.d/locales.sh >/dev/null
|
||||
export LANG="\${LANG:-C.UTF-8}"
|
||||
export LC_ALL="\${LANG:-C.UTF-8}"
|
||||
export TZ="\${TZ:-\${TIMEZONE:-America/New_York}}"
|
||||
EOF
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create the backup dir
|
||||
[ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -f "$ENTRYPOINT_PID_FILE" ]; then
|
||||
START_SERVICES="no"
|
||||
touch "$ENTRYPOINT_PID_FILE"
|
||||
else
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
fi
|
||||
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
|
||||
ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
|
||||
# Show start message
|
||||
if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then
|
||||
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for tor"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set reusable variables
|
||||
{ { [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" && touch "/etc/hosts"
|
||||
{ { [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" && touch "/etc/timezone"
|
||||
{ { [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" && touch "/etc/resolv.conf"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set timezone
|
||||
[ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone"
|
||||
[ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# if ipv6 add it to /etc/hosts
|
||||
if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then
|
||||
echo "# known hostname mappings" >"/etc/hosts"
|
||||
if [ -n "$(ip a 2>/dev/null | grep 'inet6.*::' || ifconfig 2>/dev/null | grep 'inet6.*::')" ]; then
|
||||
__printf_space "40" "::1" "localhost" >>"/etc/hosts"
|
||||
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts"
|
||||
else
|
||||
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts"
|
||||
fi
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# add .home domain
|
||||
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then
|
||||
__grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts"
|
||||
__grep_test " ${HOSTNAME%%.*}.home" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.home" >>"/etc/hosts"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# add domainname
|
||||
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "home" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then
|
||||
__grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set containers hostname
|
||||
[ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set containers hostname with domain
|
||||
# [ -n "$DOMAINNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME.$DOMAINNAME" >"/etc/hostname"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -f "/etc/hostname" ]; then
|
||||
[ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")"
|
||||
export HOSTNAME
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import hosts file into container
|
||||
[ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import resolv.conf file into container
|
||||
[ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then
|
||||
[ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Delete any .gitkeep files
|
||||
[ -d "/data" ] && rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep
|
||||
[ -d "/config" ] && rm -Rf "/config/.gitkeep" "/config"/*/*.gitkeep
|
||||
[ -f "/usr/local/bin/.gitkeep" ] && rm -Rf "/usr/local/bin/.gitkeep"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup bin directory - /config/bin > /usr/local/bin
|
||||
__initialize_custom_bin_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy default system configs - /usr/local/share/template-files/defaults > /config/
|
||||
__initialize_default_templates
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy custom config files - /usr/local/share/template-files/config > /config/
|
||||
__initialize_config_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy custom data files - /usr/local/share/template-files/data > /data/
|
||||
__initialize_data_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__initialize_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
|
||||
ENTRYPOINT_FIRST_RUN="no"
|
||||
fi
|
||||
if [ -d "/config" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Check if this is a new container
|
||||
if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then
|
||||
DATA_DIR_INITIALIZED="yes"
|
||||
fi
|
||||
if [ -d "/data" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then
|
||||
CONFIG_DIR_INITIALIZED="yes"
|
||||
fi
|
||||
if [ -d "/config" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
|
||||
# setup the smtp server
|
||||
__setup_mta
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# if no pid assume container restart - clean stale files on restart
|
||||
if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then
|
||||
START_SERVICES="yes"
|
||||
# Clean stale pid files from previous container runs
|
||||
rm -f /run/__start_init_scripts.pid /run/init.d/*.pid /run/*.pid
|
||||
elif [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
START_SERVICES="yes"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "Container ip address is:" "$CONTAINER_IP4_ADDRESS"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show configured listing processes
|
||||
if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then
|
||||
show_port=""
|
||||
for port in $ENV_PORTS; do [ -n "$port" ] && show_port+="$(printf '%s ' "${port// /}") "; done
|
||||
__printf_space "40" "The following ports are open:" "$show_port"
|
||||
unset port show_port
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute init script
|
||||
if [ -f "/tmp/init" ]; then sh "/tmp/init"; fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create user if needed
|
||||
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Modify user if needed
|
||||
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show message
|
||||
__run_message
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Just start services
|
||||
START_SERVICES="${START_SERVICES:-SYSTEM_INIT}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Start all services if no pidfile
|
||||
if [ "$START_SERVICES" = "yes" ] && [ "$1" != "backup" ] && [ "$1" != "healthcheck" ] && [ "$1" != "cron" ] && [ "$1" != "logs" ] && [ "$1" != "cron" ]; then
|
||||
[ "$1" = "start" ] && shift 1
|
||||
[ "$1" = "all" ] && shift 1
|
||||
[ "$1" = "init" ] && export CONTAINER_INIT="yes"
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
rm -Rf "/run"/*/*pid
|
||||
__start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
START_SERVICES="no"
|
||||
CONTAINER_INIT="${CONTAINER_INIT:-no}"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Begin options
|
||||
case "$1" in
|
||||
init)
|
||||
shift 1
|
||||
echo "Container has been Initialized"
|
||||
exit 0
|
||||
;;
|
||||
logs)
|
||||
shift 1
|
||||
case "$1" in
|
||||
follow)
|
||||
tail -Fq /data/logs/*/*
|
||||
;;
|
||||
clean)
|
||||
log_files="$(find "/data/logs" -type f)"
|
||||
for log in "${log_files[@]}"; do
|
||||
echo "clearing $log"
|
||||
printf '' >$log
|
||||
done
|
||||
;;
|
||||
*)
|
||||
echo "Usage: logs [follow,clean]"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
cron)
|
||||
shift 1
|
||||
__cron "$@" &
|
||||
echo "cron script is running with pid: $!"
|
||||
exit
|
||||
;;
|
||||
# backup data and config dirs
|
||||
backup)
|
||||
shift 1
|
||||
__backup $BACKUP_MAX_DAYS $1
|
||||
exit $?
|
||||
;;
|
||||
# Docker healthcheck
|
||||
healthcheck)
|
||||
healthStatus=0
|
||||
services="${SERVICES_LIST:-$@}"
|
||||
healthEnabled="${HEALTH_ENABLED:-}"
|
||||
healthPorts="${WEB_SERVER_PORTS:-}"
|
||||
healthEndPoints="${HEALTH_ENDPOINTS:-}"
|
||||
healthMessage="Everything seems to be running"
|
||||
services="${services//,/ }"
|
||||
[ "$healthEnabled" = "yes" ] || exit 0
|
||||
{ [ "$1" = "init" ] || [ "$1" = "test" ]; } && exit 0
|
||||
for proc in $services; do
|
||||
if [ -n "$proc" ]; then
|
||||
if ! __pgrep "$proc"; then
|
||||
echo "$proc is not running" >&2
|
||||
healthStatus=$((healthStatus + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
for port in $ports; do
|
||||
if [ -n "$(type -P netstat)" ] && [ -n "$port" ]; then
|
||||
if ! netstat -taupln | grep -q ":$port "; then
|
||||
echo "$port isn't open" >&2
|
||||
healthStatus=$((healthStatus + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
for endpoint in $healthEndPoints; do
|
||||
if [ -n "$endpoint" ]; then
|
||||
if ! __curl "$endpoint"; then
|
||||
echo "Can not connect to $endpoint" >&2
|
||||
healthStatus=$((healthStatus + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
[ "$healthStatus" -eq 0 ] || healthMessage="Errors reported see: docker logs --follow $CONTAINER_NAME"
|
||||
[ -n "$healthMessage" ] && echo "$healthMessage"
|
||||
exit $healthStatus
|
||||
;;
|
||||
# show open ports
|
||||
ports)
|
||||
shift 1
|
||||
ports="$(__netstat -taupln | awk -F ' ' '{print $4}' | awk -F ':' '{print $2}' | sort --unique --version-sort | grep -v '^$' | grep '^' || echo '')"
|
||||
[ -n "$ports" ] && printf '%s\n%s\n' "The following are servers:" "$ports" | tr '\n' ' '
|
||||
exit $?
|
||||
;;
|
||||
# show running processes
|
||||
procs)
|
||||
shift 1
|
||||
ps="$(__ps axco command | grep -vE 'COMMAND|grep|ps' | sort -u || grep '^' || echo '')"
|
||||
[ -n "$ps" ] && printf '%s\n%s\n' "Found the following processes" "$ps" | tr '\n' ' '
|
||||
exit $?
|
||||
;;
|
||||
# setup ssl
|
||||
ssl)
|
||||
shift 1
|
||||
__create_ssl_cert
|
||||
exit $?
|
||||
;;
|
||||
# manage ssl certificate
|
||||
certbot)
|
||||
shift 1
|
||||
CERT_BOT_ENABLED="yes"
|
||||
if [ "$1" = "create" ]; then
|
||||
shift 1
|
||||
__certbot "create"
|
||||
elif [ "$1" = "renew" ]; then
|
||||
shift 1
|
||||
__certbot "renew certonly --force-renew"
|
||||
else
|
||||
__exec_command "certbot" "$@"
|
||||
fi
|
||||
exit $?
|
||||
;;
|
||||
# Launch shell
|
||||
*/bin/sh | */bin/bash | bash | sh | shell)
|
||||
shift 1
|
||||
__exec_command "${@:-/bin/bash -l}"
|
||||
exit $?
|
||||
;;
|
||||
# execute commands
|
||||
exec)
|
||||
shift 1
|
||||
__exec_command "${@:-echo "No commands given"}"
|
||||
exit $?
|
||||
;;
|
||||
# show/start init scripts
|
||||
start)
|
||||
shift 1
|
||||
export PATH="/usr/local/etc/docker/init.d:$PATH"
|
||||
if [ $# -eq 0 ]; then
|
||||
scripts="$(ls -A "/usr/local/etc/docker/init.d")"
|
||||
[ -n "$scripts" ] && echo "$scripts" || echo "No scripts found in: /usr/local/etc/docker/init.d"
|
||||
exit
|
||||
elif [ "$1" = "all" ]; then
|
||||
shift $#
|
||||
if [ "$START_SERVICES" = "yes" ]; then
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
__start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
__no_exit
|
||||
elif [ -f "/usr/local/etc/docker/init.d/$1" ]; then
|
||||
eval "/usr/local/etc/docker/init.d/$1" &
|
||||
__no_exit
|
||||
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
# Execute primary command
|
||||
*)
|
||||
if [ $# -eq 0 ]; then
|
||||
if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
[ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
fi
|
||||
__no_exit
|
||||
else
|
||||
__exec_command "$@"
|
||||
fi
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# end of entrypoint
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
# ex: ts=2 sw=2 et filetype=sh
|
142
rootfs/usr/local/bin/pkmgr
Executable file
142
rootfs/usr/local/bin/pkmgr
Executable file
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck shell=sh
|
||||
# shellcheck disable=SC2016
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
USER_UID="$(id -u)"
|
||||
USER_GID="$(id -g)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -x "$(command -v apt 2>/dev/null)" ]; then
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
pkmgr_cmd="apt"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd clean"
|
||||
pkmgr_mkcache_cmd="$pkmgr_cmd update"
|
||||
pkmgr_update_cmd="$pkmgr_cmd upgrade -yy"
|
||||
pkmgr_install_cmd="$pkmgr_cmd install -yy $PKMGR_OPTS"
|
||||
pkmgr_install_post="$pkmgr_cmd --fix-broken install"
|
||||
elif [ -x "$(command -v apt-get 2>/dev/null)" ]; then
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
pkmgr_cmd="apt-get"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd clean"
|
||||
pkmgr_mkcache_cmd="$pkmgr_cmd update"
|
||||
pkmgr_update_cmd="$pkmgr_cmd upgrade -yy"
|
||||
pkmgr_install_cmd="$pkmgr_cmd install -yy $PKMGR_OPTS"
|
||||
pkmgr_install_post="$pkmgr_cmd --fix-broken install"
|
||||
elif [ -x "$(command -v dnf 2>/dev/null)" ]; then
|
||||
pkmgr_cmd="dnf"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd clean all"
|
||||
pkmgr_mkcache_cmd="$pkmgr_cmd makecache"
|
||||
pkmgr_update_cmd="$pkmgr_cmd update -y --skip-broken $PKMGR_OPTS"
|
||||
pkmgr_install_cmd="$pkmgr_cmd install -y --skip-broken $PKMGR_OPTS"
|
||||
elif [ -x "$(command -v yum 2>/dev/null)" ]; then
|
||||
pkmgr_cmd="yum"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd clean all"
|
||||
pkmgr_mkcache_cmd="$pkmgr_cmd makecache"
|
||||
pkmgr_update_cmd="$pkmgr_cmd update -y --skip-broken $PKMGR_OPTS"
|
||||
pkmgr_install_cmd="$pkmgr_cmd install -y --skip-broken $PKMGR_OPTS"
|
||||
elif [ -n "$(command -v pacman 2>/dev/null)" ]; then
|
||||
pkmgr_cmd="pacman"
|
||||
pkmgr_mkcache_cmd="true"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd -Scc --noconfirm"
|
||||
pkmgr_update_cmd="$pkmgr_cmd -Syyu --noconfirm $PKMGR_OPTS"
|
||||
pkmgr_install_cmd="$pkmgr_cmd -Syy --noconfirm $PKMGR_OPTS"
|
||||
elif [ -x "$(command -v apk 2>/dev/null)" ]; then
|
||||
pkmgr_cmd="apk"
|
||||
pkmgr_mkcache_cmd="true"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd cache clean"
|
||||
pkmgr_update_cmd="$pkmgr_cmd -U upgrade --no-cache $PKMGR_OPTS"
|
||||
pkmgr_install_cmd="$pkmgr_cmd add --no-cache $PKMGR_OPTS"
|
||||
elif [ -x "$(command -v zypper 2>/dev/null)" ]; then
|
||||
pkmgr_cmd="zypper"
|
||||
pkmgr_mkcache_cmd="true"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd clean --all"
|
||||
pkmgr_update_cmd="$pkmgr_cmd update -y $PKMGR_OPTS"
|
||||
pkmgr_install_cmd="$pkmgr_cmd install -y $PKMGR_OPTS"
|
||||
else
|
||||
pkmgr_cmd="true"
|
||||
pkmgr_mkcache_cmd="$pkmgr_cmd"
|
||||
pkmgr_clean_cmd="$pkmgr_cmd"
|
||||
pkmgr_update_cmd="$pkmgr_cmd"
|
||||
pkmgr_install_cmd="$pkmgr_cmd"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -f "/config/pkmgr/settings.conf" ]; then
|
||||
. "/config/pkmgr/settings.conf"
|
||||
elif [ -f "/etc/pkmgr/settings.conf" ]; then
|
||||
. "/etc/pkmgr/settings.conf"
|
||||
else
|
||||
mkdir -p "/config/pkmgr"
|
||||
cat <<EEOF >"/config/pkmgr/settings.conf"
|
||||
pkmgr_cmd="$pkmgr_cmd"
|
||||
pkmgr_clean_cmd="$pkmgr_clean_cmd"
|
||||
pkmgr_update_cmd="$pkmgr_update_cmd"
|
||||
pkmgr_install_cmd="$pkmgr_install_cmd"
|
||||
pkmgr_mkcache_cmd="$pkmgr_mkcache_cmd"
|
||||
EEOF
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ -n "$pkmgr_cmd" ] || { echo "Can not determine the package manager" && exit 1; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
case "$1" in
|
||||
pip)
|
||||
shift 1
|
||||
pip_bin="$(command -v python3 2>/dev/null || command -v python2 2>/dev/null || command -v python 2>/dev/null || echo "")"
|
||||
py_version="$($pip_bin --version | sed 's|[pP]ython ||g' | awk -F '.' '{print $1$2}' | grep '[0-9]' || echo "0")"
|
||||
[ "$py_version" -gt "310" ] && pip_opts="--break-system-packages " || pip_opts=""
|
||||
case "$1" in
|
||||
install)
|
||||
shift 1
|
||||
pkg_list="$*"
|
||||
for pkg in $pkg_list; do
|
||||
$pip_bin -m pip $pip_opts "$pkg"
|
||||
done
|
||||
;;
|
||||
*)
|
||||
for pkg in "$@"; do
|
||||
$pip_bin -m pip "$pkg"
|
||||
done
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
;;
|
||||
install)
|
||||
shift 1
|
||||
[ -n "$1" ] || exit 0
|
||||
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_install_cmd="sudo $pkmgr_install_cmd"
|
||||
if [ -f "$1" ]; then
|
||||
install_list="$(cat "$1")"
|
||||
else
|
||||
install_list="$*"
|
||||
fi
|
||||
for pkg in $install_list;do
|
||||
echo "installing packages command: $pkmgr_install_cmd $pkg"
|
||||
$pkmgr_install_cmd $pkg
|
||||
if [ -n "$pkmgr_install_post" ]; then eval $pkmgr_install_post; fi
|
||||
done
|
||||
exit
|
||||
;;
|
||||
update | upgrade)
|
||||
shift $#
|
||||
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_update_cmd="sudo $pkmgr_install_cmd"
|
||||
echo "Updating packages command: $pkmgr_update_cmd"
|
||||
$pkmgr_mkcache_cmd
|
||||
$pkmgr_update_cmd
|
||||
exit $?
|
||||
;;
|
||||
clean)
|
||||
shift $#
|
||||
[ -n "$1" ] || exit 0
|
||||
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_clean_cmd="sudo $pkmgr_clean_cmd"
|
||||
echo "Cleaning package cache: $pkmgr_clean_cmd"
|
||||
$pkmgr_clean_cmd
|
||||
exit $?
|
||||
;;
|
||||
*)
|
||||
[ -n "$1" ] || exit 0
|
||||
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_cmd="sudo $pkmgr_cmd"
|
||||
echo "executing packages command: $pkmgr_cmd $*"
|
||||
$pkmgr_cmd "$@"
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# end
|
751
rootfs/usr/local/etc/docker/init.d/01-tor-bridge.sh
Executable file
751
rootfs/usr/local/etc/docker/init.d/01-tor-bridge.sh
Executable file
@@ -0,0 +1,751 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501060902-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
# @@ReadME : tor.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Monday, Jan 06, 2025 09:02 EST
|
||||
# @@File : tor.sh
|
||||
# @@Description :
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/start-service
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Exit if service is disabled
|
||||
if [ "$TOR_BRIDGE_ENABLED" != "yes" ]; then exit 0; fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run trap command on exit
|
||||
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="tor-bridge"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
|
||||
. "/usr/local/etc/docker/functions/entrypoint.sh"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables
|
||||
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Script to execute
|
||||
START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Reset environment before executing service
|
||||
RESET_ENV="yes"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set webroot
|
||||
WWW_ROOT_DIR="/usr/local/share/httpd/default"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default predefined variables
|
||||
DATA_DIR="/data/tor/bridge" # set data directory
|
||||
CONF_DIR="/config/tor/bridge" # set config directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the containers etc directory
|
||||
ETC_DIR="/etc/tor/bridge"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the var dir
|
||||
VAR_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TMP_DIR="/tmp/tor/bridge" # set the temp dir
|
||||
RUN_DIR="/run/tor/bridge" # set scripts pid dir
|
||||
LOG_DIR="/data/logs/tor" # set log directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the working dir
|
||||
WORK_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# port which service is listening on
|
||||
SERVICE_PORT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
#SERVICE_USER="tor" # execute command as another user
|
||||
#SERVICE_GROUP="tor" # Set the service group
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set password length
|
||||
RANDOM_PASS_USER=""
|
||||
RANDOM_PASS_ROOT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute command variables - keep single quotes variables will be expanded later
|
||||
EXEC_CMD_BIN='tor-bridge' # command to execute
|
||||
EXEC_CMD_ARGS='-f $CONF_DIR/bridge.conf' # command arguments
|
||||
EXEC_PRE_SCRIPT='' # execute script before
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a web server
|
||||
IS_WEB_SERVER="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a database server
|
||||
IS_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Does this service use a database server
|
||||
USES_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set defualt type - [custom,sqlite,redis,postgres,mariadb,mysql,couchdb,mongodb,supabase]
|
||||
DATABASE_SERVICE_TYPE="sqlite"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show message before execute
|
||||
PRE_EXEC_MESSAGE=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the wait time to execute __post_execute function - minutes
|
||||
POST_EXECUTE_WAIT_TIME="1"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Update path var
|
||||
PATH="$PATH:."
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Lets get containers ip address
|
||||
IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Where to save passwords to
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info password/random]
|
||||
root_user_name="${TOR_ROOT_USER_NAME:-}" # root user name
|
||||
root_user_pass="${TOR_ROOT_PASS_WORD:-}" # root user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Normal user info [password/random]
|
||||
user_name="${TOR_USER_NAME:-}" # normal user name
|
||||
user_pass="${TOR_USER_PASS_WORD:-}" # normal user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Load variables from config
|
||||
[ -f "/config/env/tor.script.sh" ] && . "/config/env/tor.script.sh" # Generated by my dockermgr script
|
||||
[ -f "/config/env/tor.sh" ] && . "/config/env/tor.sh" # Overwrite the variabes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional predefined variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Specifiy custom directories to be created
|
||||
ADD_APPLICATION_FILES=""
|
||||
ADD_APPLICATION_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
APPLICATION_FILES=""
|
||||
APPLICATION_DIRS="$ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional config dirs - will be Copied to /etc/$name
|
||||
ADDITIONAL_CONFIG_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\"
|
||||
CMD_ENV=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Overwrite based on file/directory
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Per Application Variables or imports
|
||||
TOR_DNS_ENABLED="${TOR_DNS_ENABLED:-yes}"
|
||||
TOR_RELAY_ENABLED="${TOR_RELAY_ENABLED:-yes}"
|
||||
TOR_BRIDGE_ENABLED="${TOR_BRIDGE_ENABLED:-yes}"
|
||||
TOR_HIDDEN_ENABLED="${TOR_HIDDEN_ENABLED:-yes}"
|
||||
RANDOM_NICK="$(head -n50 '/dev/random' | tr -dc 'a-zA-Z' | tr -d '[:space:]\042\047\134' | fold -w "32" | sed 's| ||g' | head -n 1)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom commands to run before copying to /config
|
||||
__run_precopy() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom prerun functions - IE setup WWW_ROOT_DIR
|
||||
__execute_prerun() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Run any pre-execution checks
|
||||
__run_pre_execute_checks() {
|
||||
# Set variables
|
||||
local exitStatus=0
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME" # message to show at start
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME" # message to show at completion
|
||||
__banner "$pre_execute_checks_MessageST"
|
||||
# Put command to execute in parentheses
|
||||
{
|
||||
true
|
||||
}
|
||||
exitStatus=$?
|
||||
__banner "$pre_execute_checks_MessageEnd: Status $exitStatus"
|
||||
|
||||
# show exit message
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
# exit function
|
||||
return $exitStatus
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# delete files
|
||||
__rm "$CONF_DIR/bridge.conf"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# custom commands
|
||||
chmod 600 $RUN_DIR
|
||||
chown -Rf ${SERVICE_USER:-$RUNAS_USER}:${SERVICE_GROUP:-$RUNAS_USER} $RUN_DIR
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# replace variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions
|
||||
mkdir -p "$CONF_DIR/conf.d"
|
||||
cat <<EOF >>"$CONF_DIR/bridge.conf"
|
||||
##### Bridge
|
||||
RunAsDaemon 0
|
||||
HardwareAccel 1
|
||||
AddressDisableIPv6 0
|
||||
|
||||
#### control settings
|
||||
ControlSocketsGroupWritable 1
|
||||
CookieAuthentication 1
|
||||
CookieAuthFileGroupReadable 1
|
||||
HashedControlPassword 16:C30604D1D90F341360A14D9A1048C1DF4A3CA2411444E52EE5B954C01F
|
||||
|
||||
##### directiories and files
|
||||
DataDirectory $DATA_DIR
|
||||
ControlSocket $RUN_DIR/bridge.sock
|
||||
CookieAuthFile $RUN_DIR/bridge.authcookie
|
||||
|
||||
##### socks option
|
||||
SOCKSPort 0
|
||||
SafeSocks ${TOR_SOCKS_SAFE:-0}
|
||||
SocksTimeout ${TOR_SOCKS_TIMEOUT:-10}
|
||||
|
||||
##### logging
|
||||
LogMessageDomains 1
|
||||
Log notice file $LOG_DIR/bridge.log
|
||||
#Log debug file $LOG_DIR/bridge.debug
|
||||
|
||||
##### Bridge Settings
|
||||
BridgeRelay 1
|
||||
ServerTransportPlugin obfs4 exec /usr/bin/lyrebird
|
||||
ServerTransportListenAddr obfs4 0.0.0.0:${TOR_BRIDGE_PT_PORT:-57003}
|
||||
|
||||
ORPort ${TOR_BRIDGE_OR_PORT:-57004}
|
||||
DirPort ${TOR_BRIDGE_DIR_PORT:-57005}
|
||||
Nickname ${TOR_BRIDGE_NICK_NAME:-$RANDOM_NICK}
|
||||
ContactInfo ${TOR_BRIDGE_ADMIN:-tor-admin@$HOSTNAME}
|
||||
AccountingMax ${TOR_BRIDGE_ACCOUNT_MAX:-250 GBytes}
|
||||
RelayBandwidthRate ${TOR_BRIDGE_BANDWIDTH_RATE:-96 KB}
|
||||
RelayBandwidthBurst ${TOR_BRIDGE_BANDWIDTH_BURST:-192 KB}
|
||||
AccountingStart month 1 00:00
|
||||
PublishServerDescriptor 1
|
||||
|
||||
# Block ports
|
||||
ExitPolicy reject *:25
|
||||
ExitPolicy reject *:465
|
||||
ExitPolicy reject *:587
|
||||
ExitPolicy reject *:135-139
|
||||
ExitPolicy accept *:*
|
||||
|
||||
%include $CONF_DIR/conf.d/*.conf
|
||||
|
||||
EOF
|
||||
[ -f "$CONF_DIR/conf.d/default.conf" ] || touch "$CONF_DIR/conf.d/default.conf"
|
||||
if [ "$TOR_DEBUG" = "yes" ]; then
|
||||
sed -i 's|#Log debug|Log debug|g' "$CONF_DIR/bridge.conf"
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute if directories is empty
|
||||
# __is_dir_empty "$CONF_DIR" && true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions to run after copying to /config
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# unset unneeded variables
|
||||
unset sysname
|
||||
# Lets wait a few seconds before continuing
|
||||
sleep 5
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run after executing
|
||||
__post_execute() {
|
||||
local pid="" # init pid var
|
||||
local retVal=0 # set default exit code
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing
|
||||
local waitTime=$((ctime * 60)) # convert minutes to seconds
|
||||
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
|
||||
# wait
|
||||
sleep $waitTime
|
||||
# execute commands after waiting
|
||||
(
|
||||
# show message
|
||||
__banner "$postMessageST"
|
||||
# commands to execute
|
||||
sleep 5
|
||||
# show exit message
|
||||
__banner "$postMessageEnd: Status $retVal"
|
||||
) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
pid=$!
|
||||
ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && retVal=0 || retVal=10
|
||||
# allow custom functions
|
||||
if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi
|
||||
# exit function
|
||||
return $retVal
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__pre_message() {
|
||||
local exitCode=0
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to setup ssl support
|
||||
__update_ssl_conf() {
|
||||
local exitCode=0
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi
|
||||
# set exitCode
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env() {
|
||||
local exitCode=0
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
|
||||
cat <<EOF | tee -p "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info [password/random]
|
||||
#ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$TOR_ROOT_USER_NAME}" # root user name
|
||||
#ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$TOR_ROOT_PASS_WORD}" # root user password
|
||||
#root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" #
|
||||
#root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#Normal user info [password/random]
|
||||
#ENV_USER_NAME="${ENV_USER_NAME:-$TOR_USER_NAME}" #
|
||||
#ENV_USER_PASS="${ENV_USER_PASS:-$TOR_USER_PASS_WORD}" #
|
||||
#user_name="${ENV_USER_NAME:-$user_name}" # normal user name
|
||||
#user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password
|
||||
|
||||
EOF
|
||||
fi
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__execute_prerun_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_pre_execute_checks_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_conf_files_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__post_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_message_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_ssl_conf_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
fi
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1))
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1))
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local runExitCode=0
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
|
||||
local path="$(eval echo "$PATH")" # expand variables
|
||||
local message="$(eval echo "")" # expand variables
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
|
||||
#
|
||||
if [ -z "$cmd" ]; then
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
echo "$name is not a valid executable"
|
||||
return 2
|
||||
fi
|
||||
# check and exit if already running
|
||||
if __proc_check "$name" || __proc_check "$cmd"; then
|
||||
echo "$name is already running" >&2
|
||||
return 0
|
||||
else
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show message if env exists
|
||||
if [ -n "$cmd" ]; then
|
||||
[ -n "$SERVICE_USER" ] && echo "Setting up $cmd to run as $SERVICE_USER" || SERVICE_USER="root"
|
||||
[ -n "$SERVICE_PORT" ] && echo "$name will be running on port $SERVICE_PORT" || SERVICE_PORT=""
|
||||
fi
|
||||
if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then
|
||||
export cmd_exec="$pre $cmd $args"
|
||||
message="Starting service: $name $args through $pre"
|
||||
else
|
||||
export cmd_exec="$cmd $args"
|
||||
message="Starting service: $name $args"
|
||||
fi
|
||||
[ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "/data/logs/init.txt"
|
||||
echo "$message" | tee -a -p "/data/logs/init.txt"
|
||||
su_cmd touch "$SERVICE_PID_FILE"
|
||||
if [ "$RESET_ENV" = "yes" ]; then
|
||||
env_command="$(echo "env -i HOME=\"$home\" LC_CTYPE=\"$lc_type\" PATH=\"$path\" HOSTNAME=\"$sysname\" USER=\"${SERVICE_USER:-$RUNAS_USER}\" $extra_env")"
|
||||
execute_command="$(__trim "$su_exec $env_command $cmd_exec")"
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2 >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT"
|
||||
[ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT"
|
||||
runExitCode=$?
|
||||
fi
|
||||
return $runExitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# username and password actions
|
||||
__run_secure_function() {
|
||||
local filesperms
|
||||
if [ -n "$user_name" ] || [ -n "$user_pass" ]; then
|
||||
for filesperms in "${USER_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
|
||||
for filesperms in "${ROOT_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
unset filesperms
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow ENV_ variable - Import env file
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SERVICE_EXIT_CODE=0 # default exit code
|
||||
# application specific
|
||||
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
|
||||
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check
|
||||
__check_service "$1" && SERVICE_IS_RUNNING=yes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ensure needed directories exists
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create auth directories
|
||||
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
|
||||
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
|
||||
[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER"
|
||||
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}"
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Database env
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
RESET_ENV="no"
|
||||
DATABASE_CREATE="${ENV_DATABASE_CREATE:-$DATABASE_CREATE}"
|
||||
DATABASE_USER_NORMAL="${ENV_DATABASE_USER:-${DATABASE_USER_NORMAL:-$user_name}}"
|
||||
DATABASE_PASS_NORMAL="${ENV_DATABASE_PASSWORD:-${DATABASE_PASS_NORMAL:-$user_pass}}"
|
||||
DATABASE_USER_ROOT="${ENV_DATABASE_ROOT_USER:-${DATABASE_USER_ROOT:-$root_user_name}}"
|
||||
DATABASE_PASS_ROOT="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_PASS_ROOT:-$root_user_pass}}"
|
||||
if [ -n "$DATABASE_PASS_NORMAL" ] && [ ! -f "${USER_FILE_PREFIX}/db_pass_user" ]; then
|
||||
echo "$DATABASE_PASS_NORMAL" >"${USER_FILE_PREFIX}/db_pass_user"
|
||||
fi
|
||||
if [ -n "$DATABASE_PASS_ROOT" ] && [ ! -f "${ROOT_FILE_PREFIX}/db_pass_root" ]; then
|
||||
echo "$DATABASE_PASS_ROOT" >"${ROOT_FILE_PREFIX}/db_pass_root"
|
||||
fi
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# [DATABASE_DIR_[SQLITE,REDIS,POSTGRES,MARIADB,COUCHDB,MONGODB,SUPABASE]]
|
||||
if [ "$DATABASE_SERVICE_TYPE" = "custom" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_CUSTOM:-/usr/local/share/httpd/admin/databases}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_CUSTOM:-/admin/dbadmin}"
|
||||
elif [ "$SERVICE_NAME" = "redis" ] || [ "$DATABASE_SERVICE_TYPE" = "redis" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_REDIS:-/usr/local/share/httpd/admin/redis}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_REDIS:-/admin/redis}"
|
||||
elif [ "$SERVICE_NAME" = "postgres" ] || [ "$DATABASE_SERVICE_TYPE" = "postgres" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_POSTGRES:-/usr/local/share/httpd/admin/postgres}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_POSTGRES:-/admin/postgres}"
|
||||
elif [ "$SERVICE_NAME" = "mariadb" ] || [ "$DATABASE_SERVICE_TYPE" = "mariadb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MARIADB:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MARIADB:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "mysql" ] || [ "$DATABASE_SERVICE_TYPE" = "mysql" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MYSQL:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MYSQL:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "couchdb" ] || [ "$DATABASE_SERVICE_TYPE" = "couchdb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_COUCHDB:-/usr/local/share/httpd/admin/couchdb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_COUCHDB:-/admin/couchdb}"
|
||||
elif [ "$SERVICE_NAME" = "mongodb" ] || [ "$DATABASE_SERVICE_TYPE" = "mongodb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MONGODB:-/usr/local/share/httpd/admin/mongodb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MONGODB:-/admin/mongodb}"
|
||||
elif [ "$SERVICE_NAME" = "supabase" ] || [ "$DATABASE_SERVICE_TYPE" = "supabase" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SUPABASE:-/usr/local/share/httpd/admin/supabase}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SUPBASE:-/admin/supabase}"
|
||||
elif [ "$SERVICE_NAME" = "sqlite" ] || [ "$DATABASE_SERVICE_TYPE" = "sqlite" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SQLITE:-/usr/local/share/httpd/admin/sqlite}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SQLITE:-/admin/sqlite}"
|
||||
[ -d "$DATABASE_DIR" ] || mkdir -p "$DATABASE_DIR"
|
||||
chmod 777 "$DATABASE_DIR"
|
||||
fi
|
||||
[ -n "$DATABASE_ADMIN_WWW_ROOT" ] && { [ ! -d "$DATABASE_ADMIN_WWW_ROOT" ] || mkdir -p "${DATABASE_ADMIN_WWW_ROOT}"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow variables via imports - Overwrite existing
|
||||
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set password to random if variable is random
|
||||
[ "$user_pass" = "random" ] && user_pass="$(__random_password ${RANDOM_PASS_USER:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password ${RANDOM_PASS_ROOT:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow setting initial users and passwords via environment and save to file
|
||||
[ -n "$user_name" ] && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$user_pass" ] && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
[ -n "$root_user_name" ] && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$root_user_pass" ] && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create needed dirs
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow per init script usernames and passwords
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/db_pass_user" && DATABASE_PASS_NORMAL="$(<"${USER_FILE_PREFIX}/db_pass_user")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/db_pass_root" && DATABASE_PASS_ROOT="$(<"${ROOT_FILE_PREFIX}/db_pass_root")"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set hostname for script
|
||||
sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup /config directories
|
||||
__init_config_etc
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# pre-run function
|
||||
__execute_prerun
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create user if needed
|
||||
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Modify user if needed
|
||||
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create base directories
|
||||
__setup_directories
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set switch user command
|
||||
__switch_to_user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize the home/working dir
|
||||
__init_working_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show init message
|
||||
__pre_message
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_db_users
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions in ${USER_FILE_PREFIX} and ${ROOT_FILE_PREFIX}
|
||||
__run_secure_function
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy /config to /etc
|
||||
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
|
||||
__initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Replace variables
|
||||
__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_database
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions
|
||||
__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log"
|
||||
errorCode=$?
|
||||
if [ -n "$EXEC_CMD_BIN" ]; then
|
||||
if [ "$errorCode" -eq 0 ]; then
|
||||
SERVICE_EXIT_CODE=0
|
||||
SERVICE_IS_RUNNING="yes"
|
||||
else
|
||||
SERVICE_EXIT_CODE=$errorCode
|
||||
SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}"
|
||||
[ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE"
|
||||
fi
|
||||
SERVICE_EXIT_CODE=0
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# start the post execute function in background
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
753
rootfs/usr/local/etc/docker/init.d/02-tor-relay.sh
Executable file
753
rootfs/usr/local/etc/docker/init.d/02-tor-relay.sh
Executable file
@@ -0,0 +1,753 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501060902-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
# @@ReadME : tor.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Monday, Jan 06, 2025 09:02 EST
|
||||
# @@File : tor.sh
|
||||
# @@Description :
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/start-service
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Exit if service is disabled
|
||||
if [ "$TOR_RELAY_ENABLED" != "yes" ]; then exit 0; fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run trap command on exit
|
||||
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="tor-relay"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
|
||||
. "/usr/local/etc/docker/functions/entrypoint.sh"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables
|
||||
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Script to execute
|
||||
START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Reset environment before executing service
|
||||
RESET_ENV="yes"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set webroot
|
||||
WWW_ROOT_DIR="/usr/local/share/httpd/default"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default predefined variables
|
||||
DATA_DIR="/data/tor/relay" # set data directory
|
||||
CONF_DIR="/config/tor/relay" # set config directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the containers etc directory
|
||||
ETC_DIR="/etc/tor/relay"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the var dir
|
||||
VAR_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TMP_DIR="/tmp/tor" # set the temp dir
|
||||
RUN_DIR="/run/tor/relay" # set scripts pid dir
|
||||
LOG_DIR="/data/logs/tor" # set log directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the working dir
|
||||
WORK_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# port which service is listening on
|
||||
SERVICE_PORT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
#SERVICE_USER="tor" # execute command as another user
|
||||
#SERVICE_GROUP="tor" # Set the service group
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set password length
|
||||
RANDOM_PASS_USER=""
|
||||
RANDOM_PASS_ROOT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute command variables - keep single quotes variables will be expanded later
|
||||
EXEC_CMD_BIN='tor-relay' # command to execute
|
||||
EXEC_CMD_ARGS='-f $CONF_DIR/relay.conf' # command arguments
|
||||
EXEC_PRE_SCRIPT='' # execute script before
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a web server
|
||||
IS_WEB_SERVER="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a database server
|
||||
IS_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Does this service use a database server
|
||||
USES_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set defualt type - [custom,sqlite,redis,postgres,mariadb,mysql,couchdb,mongodb,supabase]
|
||||
DATABASE_SERVICE_TYPE="sqlite"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show message before execute
|
||||
PRE_EXEC_MESSAGE=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the wait time to execute __post_execute function - minutes
|
||||
POST_EXECUTE_WAIT_TIME="1"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Update path var
|
||||
PATH="$PATH:."
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Lets get containers ip address
|
||||
IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Where to save passwords to
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info password/random]
|
||||
root_user_name="${TOR_ROOT_USER_NAME:-}" # root user name
|
||||
root_user_pass="${TOR_ROOT_PASS_WORD:-}" # root user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Normal user info [password/random]
|
||||
user_name="${TOR_USER_NAME:-}" # normal user name
|
||||
user_pass="${TOR_USER_PASS_WORD:-}" # normal user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Load variables from config
|
||||
[ -f "/config/env/tor.script.sh" ] && . "/config/env/tor.script.sh" # Generated by my dockermgr script
|
||||
[ -f "/config/env/tor.sh" ] && . "/config/env/tor.sh" # Overwrite the variabes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional predefined variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Specifiy custom directories to be created
|
||||
ADD_APPLICATION_FILES=""
|
||||
ADD_APPLICATION_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
APPLICATION_FILES=""
|
||||
APPLICATION_DIRS="$ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional config dirs - will be Copied to /etc/$name
|
||||
ADDITIONAL_CONFIG_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\"
|
||||
CMD_ENV=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Overwrite based on file/directory
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Per Application Variables or imports
|
||||
TOR_DNS_ENABLED="${TOR_DNS_ENABLED:-yes}"
|
||||
TOR_RELAY_ENABLED="${TOR_RELAY_ENABLED:-yes}"
|
||||
TOR_BRIDGE_ENABLED="${TOR_BRIDGE_ENABLED:-yes}"
|
||||
TOR_HIDDEN_ENABLED="${TOR_HIDDEN_ENABLED:-yes}"
|
||||
RANDOM_NICK="$(head -n50 '/dev/random' | tr -dc 'a-zA-Z' | tr -d '[:space:]\042\047\134' | fold -w "32" | sed 's| ||g' | head -n 1)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom commands to run before copying to /config
|
||||
__run_precopy() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom prerun functions - IE setup WWW_ROOT_DIR
|
||||
__execute_prerun() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Run any pre-execution checks
|
||||
__run_pre_execute_checks() {
|
||||
# Set variables
|
||||
local exitStatus=0
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME" # message to show at start
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME" # message to show at completion
|
||||
__banner "$pre_execute_checks_MessageST"
|
||||
# Put command to execute in parentheses
|
||||
{
|
||||
true
|
||||
}
|
||||
exitStatus=$?
|
||||
__banner "$pre_execute_checks_MessageEnd: Status $exitStatus"
|
||||
|
||||
# show exit message
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
# exit function
|
||||
return $exitStatus
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# delete files
|
||||
#__rm ""
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# custom commands
|
||||
chmod 600 $RUN_DIR
|
||||
chown -Rf ${SERVICE_USER:-$RUNAS_USER}:${SERVICE_GROUP:-$RUNAS_USER} $RUN_DIR
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# replace variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions
|
||||
mkdir -p "$CONF_DIR/conf.d"
|
||||
cat <<EOF >"$CONF_DIR/relay.conf"
|
||||
##### Relay
|
||||
RunAsDaemon 0
|
||||
HardwareAccel 1
|
||||
AddressDisableIPv6 0
|
||||
|
||||
#### control settings
|
||||
ControlSocketsGroupWritable 1
|
||||
CookieAuthentication 1
|
||||
CookieAuthFileGroupReadable 1
|
||||
HashedControlPassword 16:C30604D1D90F341360A14D9A1048C1DF4A3CA2411444E52EE5B954C01F
|
||||
|
||||
##### directiories and files
|
||||
DataDirectory $DATA_DIR
|
||||
ControlSocket $RUN_DIR/relay.sock
|
||||
CookieAuthFile $RUN_DIR/relay.authcookie
|
||||
|
||||
##### socks option
|
||||
SOCKSPort 0
|
||||
SafeSocks ${TOR_SOCKS_SAFE:-0}
|
||||
SocksTimeout ${TOR_SOCKS_TIMEOUT:-10}
|
||||
|
||||
##### logging
|
||||
LogMessageDomains 1
|
||||
Log notice file $LOG_DIR/relay.log
|
||||
#Log debug file $LOG_DIR/relay.debug
|
||||
|
||||
##### Relay Settings
|
||||
ServerTransportPlugin obfs4 exec /usr/bin/lyrebird
|
||||
ServerTransportListenAddr obfs4 0.0.0.0:${TOR_RELAY_PORT:-57000}
|
||||
ORPort ${TOR_RELAY_OR_PORT:-57001}
|
||||
DirPort ${TOR_RELAY_DIR_PORT:-57002}
|
||||
|
||||
ExitRelay 1
|
||||
PublishServerDescriptor 1
|
||||
Nickname ${TOR_RELAY_NICK_NAME:-$RANDOM_NICK}
|
||||
ContactInfo ${TOR_RELAY_ADMIN:-tor-admin@$HOSTNAME}
|
||||
AccountingMax ${TOR_RELAY_ACCOUNT_MAX:-250 GBytes}
|
||||
RelayBandwidthRate ${TOR_RELAY_BANDWIDTH_RATE:-96 KB}
|
||||
RelayBandwidthBurst ${TOR_RELAY_BANDWIDTH_BURST:-192 KB}
|
||||
AccountingStart month 1 00:00
|
||||
DirPortFrontPage /usr/share/tor/html/exit.html
|
||||
|
||||
# Block ports
|
||||
ExitPolicy reject *:25
|
||||
ExitPolicy reject *:465
|
||||
ExitPolicy reject *:587
|
||||
ExitPolicy reject *:135-139
|
||||
ExitPolicy accept *:*
|
||||
|
||||
%include $CONF_DIR/conf.d/*.conf
|
||||
|
||||
EOF
|
||||
[ -f "$CONF_DIR/conf.d/default.conf" ] || touch "$CONF_DIR/conf.d/default.conf"
|
||||
if [ "$TOR_DEBUG" = "yes" ]; then
|
||||
sed -i 's|#Log debug|Log debug|g' "$CONF_DIR/relay.conf"
|
||||
fi
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute if directories is empty
|
||||
# __is_dir_empty "$CONF_DIR" && true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions to run after copying to /config
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# unset unneeded variables
|
||||
unset sysname
|
||||
# Lets wait a few seconds before continuing
|
||||
sleep 5
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run after executing
|
||||
__post_execute() {
|
||||
local pid="" # init pid var
|
||||
local retVal=0 # set default exit code
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing
|
||||
local waitTime=$((ctime * 60)) # convert minutes to seconds
|
||||
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
|
||||
# wait
|
||||
sleep $waitTime
|
||||
# execute commands after waiting
|
||||
(
|
||||
# show message
|
||||
__banner "$postMessageST"
|
||||
# commands to execute
|
||||
sleep 5
|
||||
# show exit message
|
||||
__banner "$postMessageEnd: Status $retVal"
|
||||
) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
pid=$!
|
||||
ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && retVal=0 || retVal=10
|
||||
# allow custom functions
|
||||
if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi
|
||||
# exit function
|
||||
return $retVal
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__pre_message() {
|
||||
local exitCode=0
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to setup ssl support
|
||||
__update_ssl_conf() {
|
||||
local exitCode=0
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi
|
||||
# set exitCode
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env() {
|
||||
local exitCode=0
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
|
||||
cat <<EOF | tee -p "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info [password/random]
|
||||
#ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$TOR_ROOT_USER_NAME}" # root user name
|
||||
#ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$TOR_ROOT_PASS_WORD}" # root user password
|
||||
#root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" #
|
||||
#root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#Normal user info [password/random]
|
||||
#ENV_USER_NAME="${ENV_USER_NAME:-$TOR_USER_NAME}" #
|
||||
#ENV_USER_PASS="${ENV_USER_PASS:-$TOR_USER_PASS_WORD}" #
|
||||
#user_name="${ENV_USER_NAME:-$user_name}" # normal user name
|
||||
#user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password
|
||||
|
||||
EOF
|
||||
fi
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__execute_prerun_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_pre_execute_checks_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_conf_files_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__post_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_message_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_ssl_conf_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
fi
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1))
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1))
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local runExitCode=0
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
|
||||
local path="$(eval echo "$PATH")" # expand variables
|
||||
local message="$(eval echo "")" # expand variables
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
|
||||
#
|
||||
if [ -z "$cmd" ]; then
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
echo "$name is not a valid executable"
|
||||
return 2
|
||||
fi
|
||||
# check and exit if already running
|
||||
if __proc_check "$name" || __proc_check "$cmd"; then
|
||||
echo "$name is already running" >&2
|
||||
return 0
|
||||
else
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show message if env exists
|
||||
if [ -n "$cmd" ]; then
|
||||
[ -n "$SERVICE_USER" ] && echo "Setting up $cmd to run as $SERVICE_USER" || SERVICE_USER="root"
|
||||
[ -n "$SERVICE_PORT" ] && echo "$name will be running on port $SERVICE_PORT" || SERVICE_PORT=""
|
||||
fi
|
||||
if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then
|
||||
export cmd_exec="$pre $cmd $args"
|
||||
message="Starting service: $name $args through $pre"
|
||||
else
|
||||
export cmd_exec="$cmd $args"
|
||||
message="Starting service: $name $args"
|
||||
fi
|
||||
[ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "/data/logs/init.txt"
|
||||
echo "$message" | tee -a -p "/data/logs/init.txt"
|
||||
su_cmd touch "$SERVICE_PID_FILE"
|
||||
if [ "$RESET_ENV" = "yes" ]; then
|
||||
env_command="$(echo "env -i HOME=\"$home\" LC_CTYPE=\"$lc_type\" PATH=\"$path\" HOSTNAME=\"$sysname\" USER=\"${SERVICE_USER:-$RUNAS_USER}\" $extra_env")"
|
||||
execute_command="$(__trim "$su_exec $env_command $cmd_exec")"
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2 >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT"
|
||||
[ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT"
|
||||
runExitCode=$?
|
||||
fi
|
||||
return $runExitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# username and password actions
|
||||
__run_secure_function() {
|
||||
local filesperms
|
||||
if [ -n "$user_name" ] || [ -n "$user_pass" ]; then
|
||||
for filesperms in "${USER_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
|
||||
for filesperms in "${ROOT_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
unset filesperms
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow ENV_ variable - Import env file
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SERVICE_EXIT_CODE=0 # default exit code
|
||||
# application specific
|
||||
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
|
||||
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check
|
||||
__check_service "$1" && SERVICE_IS_RUNNING=yes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ensure needed directories exists
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create auth directories
|
||||
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
|
||||
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
|
||||
[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER"
|
||||
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}"
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Database env
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
RESET_ENV="no"
|
||||
DATABASE_CREATE="${ENV_DATABASE_CREATE:-$DATABASE_CREATE}"
|
||||
DATABASE_USER_NORMAL="${ENV_DATABASE_USER:-${DATABASE_USER_NORMAL:-$user_name}}"
|
||||
DATABASE_PASS_NORMAL="${ENV_DATABASE_PASSWORD:-${DATABASE_PASS_NORMAL:-$user_pass}}"
|
||||
DATABASE_USER_ROOT="${ENV_DATABASE_ROOT_USER:-${DATABASE_USER_ROOT:-$root_user_name}}"
|
||||
DATABASE_PASS_ROOT="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_PASS_ROOT:-$root_user_pass}}"
|
||||
if [ -n "$DATABASE_PASS_NORMAL" ] && [ ! -f "${USER_FILE_PREFIX}/db_pass_user" ]; then
|
||||
echo "$DATABASE_PASS_NORMAL" >"${USER_FILE_PREFIX}/db_pass_user"
|
||||
fi
|
||||
if [ -n "$DATABASE_PASS_ROOT" ] && [ ! -f "${ROOT_FILE_PREFIX}/db_pass_root" ]; then
|
||||
echo "$DATABASE_PASS_ROOT" >"${ROOT_FILE_PREFIX}/db_pass_root"
|
||||
fi
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# [DATABASE_DIR_[SQLITE,REDIS,POSTGRES,MARIADB,COUCHDB,MONGODB,SUPABASE]]
|
||||
if [ "$DATABASE_SERVICE_TYPE" = "custom" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_CUSTOM:-/usr/local/share/httpd/admin/databases}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_CUSTOM:-/admin/dbadmin}"
|
||||
elif [ "$SERVICE_NAME" = "redis" ] || [ "$DATABASE_SERVICE_TYPE" = "redis" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_REDIS:-/usr/local/share/httpd/admin/redis}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_REDIS:-/admin/redis}"
|
||||
elif [ "$SERVICE_NAME" = "postgres" ] || [ "$DATABASE_SERVICE_TYPE" = "postgres" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_POSTGRES:-/usr/local/share/httpd/admin/postgres}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_POSTGRES:-/admin/postgres}"
|
||||
elif [ "$SERVICE_NAME" = "mariadb" ] || [ "$DATABASE_SERVICE_TYPE" = "mariadb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MARIADB:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MARIADB:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "mysql" ] || [ "$DATABASE_SERVICE_TYPE" = "mysql" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MYSQL:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MYSQL:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "couchdb" ] || [ "$DATABASE_SERVICE_TYPE" = "couchdb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_COUCHDB:-/usr/local/share/httpd/admin/couchdb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_COUCHDB:-/admin/couchdb}"
|
||||
elif [ "$SERVICE_NAME" = "mongodb" ] || [ "$DATABASE_SERVICE_TYPE" = "mongodb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MONGODB:-/usr/local/share/httpd/admin/mongodb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MONGODB:-/admin/mongodb}"
|
||||
elif [ "$SERVICE_NAME" = "supabase" ] || [ "$DATABASE_SERVICE_TYPE" = "supabase" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SUPABASE:-/usr/local/share/httpd/admin/supabase}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SUPBASE:-/admin/supabase}"
|
||||
elif [ "$SERVICE_NAME" = "sqlite" ] || [ "$DATABASE_SERVICE_TYPE" = "sqlite" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SQLITE:-/usr/local/share/httpd/admin/sqlite}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SQLITE:-/admin/sqlite}"
|
||||
[ -d "$DATABASE_DIR" ] || mkdir -p "$DATABASE_DIR"
|
||||
chmod 777 "$DATABASE_DIR"
|
||||
fi
|
||||
[ -n "$DATABASE_ADMIN_WWW_ROOT" ] && { [ ! -d "$DATABASE_ADMIN_WWW_ROOT" ] || mkdir -p "${DATABASE_ADMIN_WWW_ROOT}"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow variables via imports - Overwrite existing
|
||||
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set password to random if variable is random
|
||||
[ "$user_pass" = "random" ] && user_pass="$(__random_password ${RANDOM_PASS_USER:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password ${RANDOM_PASS_ROOT:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow setting initial users and passwords via environment and save to file
|
||||
[ -n "$user_name" ] && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$user_pass" ] && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
[ -n "$root_user_name" ] && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$root_user_pass" ] && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create needed dirs
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow per init script usernames and passwords
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/db_pass_user" && DATABASE_PASS_NORMAL="$(<"${USER_FILE_PREFIX}/db_pass_user")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/db_pass_root" && DATABASE_PASS_ROOT="$(<"${ROOT_FILE_PREFIX}/db_pass_root")"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set hostname for script
|
||||
sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup /config directories
|
||||
__init_config_etc
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# pre-run function
|
||||
__execute_prerun
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create user if needed
|
||||
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Modify user if needed
|
||||
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create base directories
|
||||
__setup_directories
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set switch user command
|
||||
__switch_to_user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize the home/working dir
|
||||
__init_working_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show init message
|
||||
__pre_message
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_db_users
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions in ${USER_FILE_PREFIX} and ${ROOT_FILE_PREFIX}
|
||||
__run_secure_function
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy /config to /etc
|
||||
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
|
||||
__initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Replace variables
|
||||
__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_database
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions
|
||||
__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log"
|
||||
errorCode=$?
|
||||
if [ -n "$EXEC_CMD_BIN" ]; then
|
||||
if [ "$errorCode" -eq 0 ]; then
|
||||
SERVICE_EXIT_CODE=0
|
||||
SERVICE_IS_RUNNING="yes"
|
||||
else
|
||||
SERVICE_EXIT_CODE=$errorCode
|
||||
SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}"
|
||||
[ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE"
|
||||
fi
|
||||
SERVICE_EXIT_CODE=0
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# start the post execute function in background
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
806
rootfs/usr/local/etc/docker/init.d/03-tor-server.sh
Executable file
806
rootfs/usr/local/etc/docker/init.d/03-tor-server.sh
Executable file
@@ -0,0 +1,806 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501060902-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
# @@ReadME : tor.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Monday, Jan 06, 2025 09:02 EST
|
||||
# @@File : tor.sh
|
||||
# @@Description :
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/start-service
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run trap command on exit
|
||||
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="tor-server"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
|
||||
. "/usr/local/etc/docker/functions/entrypoint.sh"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables
|
||||
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Script to execute
|
||||
START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Reset environment before executing service
|
||||
RESET_ENV="yes"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set webroot
|
||||
WWW_ROOT_DIR="/usr/local/share/httpd/default"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default predefined variables
|
||||
DATA_DIR="/data/tor/server" # set data directory
|
||||
CONF_DIR="/config/tor/server" # set config directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the containers etc directory
|
||||
ETC_DIR="/etc/tor/server"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the var dir
|
||||
VAR_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TMP_DIR="/tmp/tor/server" # set the temp dir
|
||||
RUN_DIR="/run/tor/server" # set scripts pid dir
|
||||
LOG_DIR="/data/logs/tor" # set log directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the working dir
|
||||
WORK_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# port which service is listening on
|
||||
SERVICE_PORT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
#SERVICE_USER="tor" # execute command as another user
|
||||
#SERVICE_GROUP="tor" # Set the service group
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set password length
|
||||
RANDOM_PASS_USER=""
|
||||
RANDOM_PASS_ROOT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute command variables - keep single quotes variables will be expanded later
|
||||
EXEC_CMD_BIN='tor-server' # command to execute
|
||||
EXEC_CMD_ARGS='-f $CONF_DIR/server.conf' # command arguments
|
||||
EXEC_PRE_SCRIPT='' # execute script before
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a web server
|
||||
IS_WEB_SERVER="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a database server
|
||||
IS_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Does this service use a database server
|
||||
USES_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set defualt type - [custom,sqlite,redis,postgres,mariadb,mysql,couchdb,mongodb,supabase]
|
||||
DATABASE_SERVICE_TYPE="sqlite"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show message before execute
|
||||
PRE_EXEC_MESSAGE=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the wait time to execute __post_execute function - minutes
|
||||
POST_EXECUTE_WAIT_TIME="5"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Update path var
|
||||
PATH="$PATH:."
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Lets get containers ip address
|
||||
IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Where to save passwords to
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info password/random]
|
||||
root_user_name="${TOR_ROOT_USER_NAME:-}" # root user name
|
||||
root_user_pass="${TOR_ROOT_PASS_WORD:-}" # root user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Normal user info [password/random]
|
||||
user_name="${TOR_USER_NAME:-}" # normal user name
|
||||
user_pass="${TOR_USER_PASS_WORD:-}" # normal user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Load variables from config
|
||||
[ -f "/config/env/tor.script.sh" ] && . "/config/env/tor.script.sh" # Generated by my dockermgr script
|
||||
[ -f "/config/env/tor.sh" ] && . "/config/env/tor.sh" # Overwrite the variabes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional predefined variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional variables
|
||||
TOR_HIDDEN_SERVERS="${TOR_HIDDEN_SERVERS//,/ }"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Specifiy custom directories to be created
|
||||
ADD_APPLICATION_FILES=""
|
||||
ADD_APPLICATION_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
APPLICATION_FILES=""
|
||||
APPLICATION_DIRS="$ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional config dirs - will be Copied to /etc/$name
|
||||
ADDITIONAL_CONFIG_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\"
|
||||
CMD_ENV=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Overwrite based on file/directory
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Per Application Variables or imports
|
||||
TOR_DNS_ENABLED="${TOR_DNS_ENABLED:-yes}"
|
||||
TOR_RELAY_ENABLED="${TOR_RELAY_ENABLED:-yes}"
|
||||
TOR_BRIDGE_ENABLED="${TOR_BRIDGE_ENABLED:-yes}"
|
||||
TOR_HIDDEN_ENABLED="${TOR_HIDDEN_ENABLED:-yes}"
|
||||
RANDOM_NICK="$(head -n50 '/dev/random' | tr -dc 'a-zA-Z' | tr -d '[:space:]\042\047\134' | fold -w "32" | sed 's| ||g' | head -n 1)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom commands to run before copying to /config
|
||||
__run_precopy() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom prerun functions - IE setup WWW_ROOT_DIR
|
||||
__execute_prerun() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
touch "/tmp/init_tor_services"
|
||||
# allow custom functions
|
||||
if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Run any pre-execution checks
|
||||
__run_pre_execute_checks() {
|
||||
# Set variables
|
||||
local exitStatus=0
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME" # message to show at start
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME" # message to show at completion
|
||||
__banner "$pre_execute_checks_MessageST"
|
||||
# Put command to execute in parentheses
|
||||
{
|
||||
true
|
||||
}
|
||||
exitStatus=$?
|
||||
__banner "$pre_execute_checks_MessageEnd: Status $exitStatus"
|
||||
|
||||
# show exit message
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
# exit function
|
||||
return $exitStatus
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# delete files
|
||||
__rm "$CONF_DIR/server.conf"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# custom commands
|
||||
chmod 600 $RUN_DIR
|
||||
chown -Rf ${SERVICE_USER:-$RUNAS_USER}:${SERVICE_GROUP:-$RUNAS_USER} $RUN_DIR
|
||||
mkdir -p "/run/tor/sites" && chmod 777 "/run/tor/sites"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# replace variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
cat <<EOF >>"$CONF_DIR/server.conf"
|
||||
##### Server
|
||||
RunAsDaemon 0
|
||||
HardwareAccel 1
|
||||
AddressDisableIPv6 0
|
||||
#VirtualAddrNetwork 10.0.0.0/12
|
||||
|
||||
#### control settings
|
||||
ControlPort 127.0.0.1:9051
|
||||
ControlSocketsGroupWritable 1
|
||||
CookieAuthentication 1
|
||||
CookieAuthFileGroupReadable 1
|
||||
HashedControlPassword 16:C30604D1D90F341360A14D9A1048C1DF4A3CA2411444E52EE5B954C01F
|
||||
|
||||
##### bandwidth and accounting (monitoring only)
|
||||
Nickname ${TOR_SERVER_NICK_NAME:-$RANDOM_NICK}
|
||||
ContactInfo ${TOR_SERVER_ADMIN:-tor-admin@$HOSTNAME}
|
||||
AccountingMax ${TOR_SERVER_ACCOUNT_MAX:-250 GBytes}
|
||||
AccountingStart month 1 00:00
|
||||
|
||||
##### directiories and files
|
||||
DataDirectory $DATA_DIR
|
||||
ControlSocket $RUN_DIR/server.sock
|
||||
CookieAuthFile $RUN_DIR/server.authcookie
|
||||
|
||||
##### socks option
|
||||
SOCKSPort 0.0.0.0:9050
|
||||
SafeSocks ${TOR_SOCKS_SAFE:-0}
|
||||
SocksTimeout ${TOR_SOCKS_TIMEOUT:-10}
|
||||
|
||||
##### logging
|
||||
LogMessageDomains 1
|
||||
Log notice file $LOG_DIR/server.log
|
||||
|
||||
##### port mappings
|
||||
TransPort 0.0.0.0:9040
|
||||
HTTPTunnelPort 0.0.0.0:9080
|
||||
|
||||
##### hidden services
|
||||
HiddenServiceDir ${TOR_HIDDEN_SERVICE_DIR:-$DATA_DIR/hidden_service}
|
||||
HiddenServicePort ${TOR_HIDDEN_SERVICE_PORT:-80 127.0.0.1:80}
|
||||
|
||||
##### security
|
||||
SafeLogging 1
|
||||
UseEntryGuards 1
|
||||
NumEntryGuards 3
|
||||
DisableAllSwap 1
|
||||
|
||||
##### exit relay
|
||||
ExcludeNodes {ru},{cn},{ir},{kp},{sy}
|
||||
|
||||
EOF
|
||||
# define actions
|
||||
if [ "$TOR_DNS_ENABLED" = "yes" ]; then
|
||||
SHOW_HIDDEN_HOSTNAMES=yes
|
||||
mkdir -p "$CONF_DIR/conf.d"
|
||||
cat <<EOF >>"$CONF_DIR/server.conf"
|
||||
#### dns forwarder
|
||||
Log notice file $LOG_DIR/dns.log
|
||||
DNSPort 0.0.0.0:8053
|
||||
DNSListenAddress 0.0.0.0,[::]
|
||||
AutomapHostsOnResolve 1
|
||||
AutomapHostsSuffixes .exit,.onion
|
||||
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ "$TOR_HIDDEN_ENABLED" = "yes" ]; then
|
||||
mkdir -p "$CONF_DIR/hidden.d"
|
||||
mkdir -p "$DATA_DIR/services"
|
||||
chmod 700 "$DATA_DIR/services"
|
||||
cat <<EOF >>"$CONF_DIR/server.conf"
|
||||
#### hidden services
|
||||
HiddenServiceDir $DATA_DIR/services/default
|
||||
HiddenServicePort 80 127.0.0.1:80
|
||||
%include $CONF_DIR/hidden.d/*.conf
|
||||
|
||||
EOF
|
||||
fi
|
||||
|
||||
cat <<EOF >>"$CONF_DIR/server.conf"
|
||||
##### include configurations
|
||||
%include $CONF_DIR/conf.d/*.conf
|
||||
|
||||
EOF
|
||||
if [ "$TOR_DEBUG" = "yes" ]; then
|
||||
sed -i 's|#Log debug|Log debug|g' "$CONF_DIR/server.conf"
|
||||
fi
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute if directories is empty
|
||||
# __is_dir_empty "$CONF_DIR" && true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions to run after copying to /config
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# unset unneeded variables
|
||||
unset sysname
|
||||
# Lets wait a few seconds before continuing
|
||||
sleep 5
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run after executing
|
||||
__post_execute() {
|
||||
local pid="" # init pid var
|
||||
local retVal=0 # set default exit code
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing
|
||||
local waitTime=$((ctime * 60)) # convert minutes to seconds
|
||||
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
|
||||
# wait
|
||||
sleep $waitTime
|
||||
# execute commands after waiting
|
||||
(
|
||||
# commands to execute
|
||||
while :; do
|
||||
if pgrep unbound >/dev/null 2>&1; then
|
||||
break
|
||||
else
|
||||
sleep 10
|
||||
fi
|
||||
done
|
||||
# show message
|
||||
__banner "$postMessageST"
|
||||
if [ -d "/data/htdocs/www" ]; then
|
||||
WWW_ROOT_DIR="/data/htdocs/www"
|
||||
fi
|
||||
if [ -d "$DATA_DIR/services" ]; then
|
||||
echo "Begin current hidden services"htdocs
|
||||
[ -f "$WWW_ROOT_DIR/hostnames.html" ] && rm -f "$WWW_ROOT_DIR/hostnames.html"
|
||||
for host in "$DATA_DIR/services"/*/hostname; do
|
||||
d="$(dirname -- $host)"
|
||||
name="$(basename "$d")"
|
||||
url="$(<"$host")"
|
||||
site="$(echo "$url" | sed 's|\.onion$||g')"
|
||||
echo "$name: $url"
|
||||
touch "/run/tor/sites/$site"
|
||||
echo '<a href="http://'$url'">'$name'</a><br />' >>"$WWW_ROOT_DIR/hostnames.html"
|
||||
if [ "$name" = "default" ]; then echo "$site" >"$WWW_ROOT_DIR/default_host.txt"; fi
|
||||
done
|
||||
echo "End current hidden services"
|
||||
fi
|
||||
[ -f "/tmp/init_tor_services" ] && rm -Rf "/tmp/init_tor_services"
|
||||
(while :; do sleep 10 && __pgrep $EXEC_CMD_BIN >/dev/null || eval $EXEC_CMD_BIN $EXEC_CMD_ARGS >/dev/null; done &)
|
||||
# show exit message
|
||||
__banner "$postMessageEnd: Status $retVal"
|
||||
) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
pid=$!
|
||||
ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && retVal=0 || retVal=10
|
||||
# allow custom functions
|
||||
if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi
|
||||
# exit function
|
||||
return $retVal
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__pre_message() {
|
||||
local exitCode=0
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to setup ssl support
|
||||
__update_ssl_conf() {
|
||||
local exitCode=0
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi
|
||||
# set exitCode
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env() {
|
||||
local exitCode=0
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
|
||||
cat <<EOF | tee -p "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info [password/random]
|
||||
#ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$TOR_ROOT_USER_NAME}" # root user name
|
||||
#ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$TOR_ROOT_PASS_WORD}" # root user password
|
||||
#root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" #
|
||||
#root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#Normal user info [password/random]
|
||||
#ENV_USER_NAME="${ENV_USER_NAME:-$TOR_USER_NAME}" #
|
||||
#ENV_USER_PASS="${ENV_USER_PASS:-$TOR_USER_PASS_WORD}" #
|
||||
#user_name="${ENV_USER_NAME:-$user_name}" # normal user name
|
||||
#user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password
|
||||
|
||||
EOF
|
||||
fi
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__execute_prerun_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_pre_execute_checks_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_conf_files_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__post_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_message_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_ssl_conf_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
fi
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1))
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1))
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local runExitCode=0
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
|
||||
local path="$(eval echo "$PATH")" # expand variables
|
||||
local message="$(eval echo "")" # expand variables
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
|
||||
#
|
||||
if [ -z "$cmd" ]; then
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
echo "$name is not a valid executable"
|
||||
return 2
|
||||
fi
|
||||
# check and exit if already running
|
||||
if __proc_check "$name" || __proc_check "$cmd"; then
|
||||
echo "$name is already running" >&2
|
||||
return 0
|
||||
else
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show message if env exists
|
||||
if [ -n "$cmd" ]; then
|
||||
[ -n "$SERVICE_USER" ] && echo "Setting up $cmd to run as $SERVICE_USER" || SERVICE_USER="root"
|
||||
[ -n "$SERVICE_PORT" ] && echo "$name will be running on port $SERVICE_PORT" || SERVICE_PORT=""
|
||||
fi
|
||||
if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then
|
||||
export cmd_exec="$pre $cmd $args"
|
||||
message="Starting service: $name $args through $pre"
|
||||
else
|
||||
export cmd_exec="$cmd $args"
|
||||
message="Starting service: $name $args"
|
||||
fi
|
||||
[ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "/data/logs/init.txt"
|
||||
echo "$message" | tee -a -p "/data/logs/init.txt"
|
||||
su_cmd touch "$SERVICE_PID_FILE"
|
||||
if [ "$RESET_ENV" = "yes" ]; then
|
||||
env_command="$(echo "env -i HOME=\"$home\" LC_CTYPE=\"$lc_type\" PATH=\"$path\" HOSTNAME=\"$sysname\" USER=\"${SERVICE_USER:-$RUNAS_USER}\" $extra_env")"
|
||||
execute_command="$(__trim "$su_exec $env_command $cmd_exec")"
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2 >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT"
|
||||
[ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT"
|
||||
runExitCode=$?
|
||||
fi
|
||||
return $runExitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# username and password actions
|
||||
__run_secure_function() {
|
||||
local filesperms
|
||||
if [ -n "$user_name" ] || [ -n "$user_pass" ]; then
|
||||
for filesperms in "${USER_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
|
||||
for filesperms in "${ROOT_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
unset filesperms
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow ENV_ variable - Import env file
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SERVICE_EXIT_CODE=0 # default exit code
|
||||
# application specific
|
||||
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
|
||||
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check
|
||||
__check_service "$1" && SERVICE_IS_RUNNING=yes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ensure needed directories exists
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create auth directories
|
||||
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
|
||||
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
|
||||
[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER"
|
||||
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}"
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Database env
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
RESET_ENV="no"
|
||||
DATABASE_CREATE="${ENV_DATABASE_CREATE:-$DATABASE_CREATE}"
|
||||
DATABASE_USER_NORMAL="${ENV_DATABASE_USER:-${DATABASE_USER_NORMAL:-$user_name}}"
|
||||
DATABASE_PASS_NORMAL="${ENV_DATABASE_PASSWORD:-${DATABASE_PASS_NORMAL:-$user_pass}}"
|
||||
DATABASE_USER_ROOT="${ENV_DATABASE_ROOT_USER:-${DATABASE_USER_ROOT:-$root_user_name}}"
|
||||
DATABASE_PASS_ROOT="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_PASS_ROOT:-$root_user_pass}}"
|
||||
if [ -n "$DATABASE_PASS_NORMAL" ] && [ ! -f "${USER_FILE_PREFIX}/db_pass_user" ]; then
|
||||
echo "$DATABASE_PASS_NORMAL" >"${USER_FILE_PREFIX}/db_pass_user"
|
||||
fi
|
||||
if [ -n "$DATABASE_PASS_ROOT" ] && [ ! -f "${ROOT_FILE_PREFIX}/db_pass_root" ]; then
|
||||
echo "$DATABASE_PASS_ROOT" >"${ROOT_FILE_PREFIX}/db_pass_root"
|
||||
fi
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# [DATABASE_DIR_[SQLITE,REDIS,POSTGRES,MARIADB,COUCHDB,MONGODB,SUPABASE]]
|
||||
if [ "$DATABASE_SERVICE_TYPE" = "custom" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_CUSTOM:-/usr/local/share/httpd/admin/databases}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_CUSTOM:-/admin/dbadmin}"
|
||||
elif [ "$SERVICE_NAME" = "redis" ] || [ "$DATABASE_SERVICE_TYPE" = "redis" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_REDIS:-/usr/local/share/httpd/admin/redis}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_REDIS:-/admin/redis}"
|
||||
elif [ "$SERVICE_NAME" = "postgres" ] || [ "$DATABASE_SERVICE_TYPE" = "postgres" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_POSTGRES:-/usr/local/share/httpd/admin/postgres}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_POSTGRES:-/admin/postgres}"
|
||||
elif [ "$SERVICE_NAME" = "mariadb" ] || [ "$DATABASE_SERVICE_TYPE" = "mariadb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MARIADB:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MARIADB:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "mysql" ] || [ "$DATABASE_SERVICE_TYPE" = "mysql" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MYSQL:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MYSQL:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "couchdb" ] || [ "$DATABASE_SERVICE_TYPE" = "couchdb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_COUCHDB:-/usr/local/share/httpd/admin/couchdb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_COUCHDB:-/admin/couchdb}"
|
||||
elif [ "$SERVICE_NAME" = "mongodb" ] || [ "$DATABASE_SERVICE_TYPE" = "mongodb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MONGODB:-/usr/local/share/httpd/admin/mongodb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MONGODB:-/admin/mongodb}"
|
||||
elif [ "$SERVICE_NAME" = "supabase" ] || [ "$DATABASE_SERVICE_TYPE" = "supabase" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SUPABASE:-/usr/local/share/httpd/admin/supabase}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SUPBASE:-/admin/supabase}"
|
||||
elif [ "$SERVICE_NAME" = "sqlite" ] || [ "$DATABASE_SERVICE_TYPE" = "sqlite" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SQLITE:-/usr/local/share/httpd/admin/sqlite}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SQLITE:-/admin/sqlite}"
|
||||
[ -d "$DATABASE_DIR" ] || mkdir -p "$DATABASE_DIR"
|
||||
chmod 777 "$DATABASE_DIR"
|
||||
fi
|
||||
[ -n "$DATABASE_ADMIN_WWW_ROOT" ] && { [ ! -d "$DATABASE_ADMIN_WWW_ROOT" ] || mkdir -p "${DATABASE_ADMIN_WWW_ROOT}"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow variables via imports - Overwrite existing
|
||||
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set password to random if variable is random
|
||||
[ "$user_pass" = "random" ] && user_pass="$(__random_password ${RANDOM_PASS_USER:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password ${RANDOM_PASS_ROOT:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow setting initial users and passwords via environment and save to file
|
||||
[ -n "$user_name" ] && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$user_pass" ] && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
[ -n "$root_user_name" ] && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$root_user_pass" ] && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create needed dirs
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow per init script usernames and passwords
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/db_pass_user" && DATABASE_PASS_NORMAL="$(<"${USER_FILE_PREFIX}/db_pass_user")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/db_pass_root" && DATABASE_PASS_ROOT="$(<"${ROOT_FILE_PREFIX}/db_pass_root")"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set hostname for script
|
||||
sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup /config directories
|
||||
__init_config_etc
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# pre-run function
|
||||
__execute_prerun
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create user if needed
|
||||
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Modify user if needed
|
||||
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create base directories
|
||||
__setup_directories
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set switch user command
|
||||
__switch_to_user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize the home/working dir
|
||||
__init_working_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show init message
|
||||
__pre_message
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_db_users
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions in ${USER_FILE_PREFIX} and ${ROOT_FILE_PREFIX}
|
||||
__run_secure_function
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy /config to /etc
|
||||
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
|
||||
__initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Replace variables
|
||||
__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_database
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions
|
||||
__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log"
|
||||
errorCode=$?
|
||||
if [ -n "$EXEC_CMD_BIN" ]; then
|
||||
if [ "$errorCode" -eq 0 ]; then
|
||||
SERVICE_EXIT_CODE=0
|
||||
SERVICE_IS_RUNNING="yes"
|
||||
else
|
||||
SERVICE_EXIT_CODE=$errorCode
|
||||
SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}"
|
||||
[ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE"
|
||||
fi
|
||||
SERVICE_EXIT_CODE=0
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# start the post execute function in background
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
690
rootfs/usr/local/etc/docker/init.d/09-unbound.sh
Executable file
690
rootfs/usr/local/etc/docker/init.d/09-unbound.sh
Executable file
@@ -0,0 +1,690 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501082150-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
# @@ReadME : 09-unbound.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Wednesday, Jan 08, 2025 21:50 EST
|
||||
# @@File : 09-unbound.sh
|
||||
# @@Description :
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/start-service
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run trap command on exit
|
||||
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="unbound"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
|
||||
. "/usr/local/etc/docker/functions/entrypoint.sh"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables
|
||||
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Script to execute
|
||||
START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Reset environment before executing service
|
||||
RESET_ENV="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set webroot
|
||||
WWW_ROOT_DIR="/usr/local/share/httpd/default"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default predefined variables
|
||||
DATA_DIR="/data/unbound" # set data directory
|
||||
CONF_DIR="/config/unbound" # set config directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the containers etc directory
|
||||
ETC_DIR="/etc/unbound"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the var dir
|
||||
VAR_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TMP_DIR="/tmp/unbound" # set the temp dir
|
||||
RUN_DIR="/run/unbound" # set scripts pid dir
|
||||
LOG_DIR="/data/logs/unbound" # set log directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the working dir
|
||||
WORK_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# port which service is listening on
|
||||
SERVICE_PORT="9053"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
#SERVICE_USER="unbound" # execute command as another user
|
||||
#SERVICE_GROUP="unbound" # Set the service group
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set password length
|
||||
RANDOM_PASS_USER=""
|
||||
RANDOM_PASS_ROOT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute command variables - keep single quotes variables will be expanded later
|
||||
EXEC_CMD_BIN='unbound' # command to execute
|
||||
EXEC_CMD_ARGS='-d -c $CONF_DIR/unbound.conf ' # command arguments
|
||||
EXEC_PRE_SCRIPT='unbound-checkconfig -f $CONF_DIR/unbound.conf' # execute script before
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a web server
|
||||
IS_WEB_SERVER="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a database server
|
||||
IS_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Does this service use a database server
|
||||
USES_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set defualt type - [custom,sqlite,redis,postgres,mariadb,mysql,couchdb,mongodb,supabase]
|
||||
DATABASE_SERVICE_TYPE="sqlite"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show message before execute
|
||||
PRE_EXEC_MESSAGE=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the wait time to execute __post_execute function - minutes
|
||||
POST_EXECUTE_WAIT_TIME="1"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Update path var
|
||||
PATH="$PATH:."
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Lets get containers ip address
|
||||
IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Where to save passwords to
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info password/random]
|
||||
root_user_name="${UNBOUND_ROOT_USER_NAME:-}" # root user name
|
||||
root_user_pass="${UNBOUND_ROOT_PASS_WORD:-}" # root user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Normal user info [password/random]
|
||||
user_name="${UNBOUND_USER_NAME:-}" # normal user name
|
||||
user_pass="${UNBOUND_USER_PASS_WORD:-}" # normal user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Load variables from config
|
||||
[ -f "/config/env/unbound.script.sh" ] && . "/config/env/unbound.script.sh" # Generated by my dockermgr script
|
||||
[ -f "/config/env/unbound.sh" ] && . "/config/env/unbound.sh" # Overwrite the variabes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional predefined variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Specifiy custom directories to be created
|
||||
ADD_APPLICATION_FILES=""
|
||||
ADD_APPLICATION_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
APPLICATION_FILES="$LOG_DIR/$SERVICE_NAME.log"
|
||||
APPLICATION_DIRS="$ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional config dirs - will be Copied to /etc/$name
|
||||
ADDITIONAL_CONFIG_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\"
|
||||
CMD_ENV=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Overwrite based on file/directory
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Per Application Variables or imports
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom commands to run before copying to /config
|
||||
__run_precopy() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom prerun functions - IE setup WWW_ROOT_DIR
|
||||
__execute_prerun() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Run any pre-execution checks
|
||||
__run_pre_execute_checks() {
|
||||
# Set variables
|
||||
local exitStatus=0
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME" # message to show at start
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME" # message to show at completion
|
||||
__banner "$pre_execute_checks_MessageST"
|
||||
# Put command to execute in parentheses
|
||||
{
|
||||
true
|
||||
}
|
||||
exitStatus=$?
|
||||
__banner "$pre_execute_checks_MessageEnd: Status $exitStatus"
|
||||
|
||||
# show exit message
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
# exit function
|
||||
return $exitStatus
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# delete files
|
||||
#__rm ""
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# custom commands
|
||||
echo 'nameserver 127.0.0.1' >"/etc/resolv.conf"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# replace variables
|
||||
# __replace "" "" "$CONF_DIR/unbound.conf"
|
||||
# replace variables recursively
|
||||
# __find_replace "" "" "$CONF_DIR"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute if directories is empty
|
||||
# __is_dir_empty "$CONF_DIR" && true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions to run after copying to /config
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# unset unneeded variables
|
||||
unset sysname
|
||||
# Lets wait a few seconds before continuing
|
||||
sleep 5
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run after executing
|
||||
__post_execute() {
|
||||
local pid="" # init pid var
|
||||
local retVal=0 # set default exit code
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing
|
||||
local waitTime=$((ctime * 60)) # convert minutes to seconds
|
||||
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
|
||||
# wait
|
||||
sleep $waitTime
|
||||
# execute commands after waiting
|
||||
(
|
||||
# show message
|
||||
__banner "$postMessageST"
|
||||
# commands to execute
|
||||
sleep 5
|
||||
# show exit message
|
||||
__banner "$postMessageEnd: Status $retVal"
|
||||
) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
pid=$!
|
||||
ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && retVal=0 || retVal=10
|
||||
# allow custom functions
|
||||
if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi
|
||||
# exit function
|
||||
return $retVal
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__pre_message() {
|
||||
local exitCode=0
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to setup ssl support
|
||||
__update_ssl_conf() {
|
||||
local exitCode=0
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi
|
||||
# set exitCode
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env() {
|
||||
local exitCode=0
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
|
||||
cat <<EOF | tee -p "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info [password/random]
|
||||
#ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$UNBOUND_ROOT_USER_NAME}" # root user name
|
||||
#ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$UNBOUND_ROOT_PASS_WORD}" # root user password
|
||||
#root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" #
|
||||
#root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#Normal user info [password/random]
|
||||
#ENV_USER_NAME="${ENV_USER_NAME:-$UNBOUND_USER_NAME}" #
|
||||
#ENV_USER_PASS="${ENV_USER_PASS:-$UNBOUND_USER_PASS_WORD}" #
|
||||
#user_name="${ENV_USER_NAME:-$user_name}" # normal user name
|
||||
#user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password
|
||||
|
||||
EOF
|
||||
fi
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__execute_prerun_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_pre_execute_checks_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_conf_files_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__post_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_message_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_ssl_conf_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
fi
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1))
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1))
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local runExitCode=0
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
|
||||
local path="$(eval echo "$PATH")" # expand variables
|
||||
local message="$(eval echo "")" # expand variables
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
|
||||
#
|
||||
if [ -z "$cmd" ]; then
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
echo "$name is not a valid executable"
|
||||
return 2
|
||||
fi
|
||||
# check and exit if already running
|
||||
if __proc_check "$name" || __proc_check "$cmd"; then
|
||||
echo "$name is already running" >&2
|
||||
return 0
|
||||
else
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show message if env exists
|
||||
if [ -n "$cmd" ]; then
|
||||
[ -n "$SERVICE_USER" ] && echo "Setting up $cmd to run as $SERVICE_USER" || SERVICE_USER="root"
|
||||
[ -n "$SERVICE_PORT" ] && echo "$name will be running on port $SERVICE_PORT" || SERVICE_PORT=""
|
||||
fi
|
||||
if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then
|
||||
export cmd_exec="$pre $cmd $args"
|
||||
message="Starting service: $name $args through $pre"
|
||||
else
|
||||
export cmd_exec="$cmd $args"
|
||||
message="Starting service: $name $args"
|
||||
fi
|
||||
[ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "/data/logs/init.txt"
|
||||
echo "$message" | tee -a -p "/data/logs/init.txt"
|
||||
su_cmd touch "$SERVICE_PID_FILE"
|
||||
if [ "$RESET_ENV" = "yes" ]; then
|
||||
env_command="$(echo "env -i HOME=\"$home\" LC_CTYPE=\"$lc_type\" PATH=\"$path\" HOSTNAME=\"$sysname\" USER=\"${SERVICE_USER:-$RUNAS_USER}\" $extra_env")"
|
||||
execute_command="$(__trim "$su_exec $env_command $cmd_exec")"
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2 >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT"
|
||||
[ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT"
|
||||
runExitCode=$?
|
||||
fi
|
||||
return $runExitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# username and password actions
|
||||
__run_secure_function() {
|
||||
local filesperms
|
||||
if [ -n "$user_name" ] || [ -n "$user_pass" ]; then
|
||||
for filesperms in "${USER_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
|
||||
for filesperms in "${ROOT_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
unset filesperms
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow ENV_ variable - Import env file
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SERVICE_EXIT_CODE=0 # default exit code
|
||||
# application specific
|
||||
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
|
||||
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check
|
||||
__check_service "$1" && SERVICE_IS_RUNNING=yes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ensure needed directories exists
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create auth directories
|
||||
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
|
||||
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
|
||||
[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER"
|
||||
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}"
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Database env
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
RESET_ENV="no"
|
||||
DATABASE_CREATE="${ENV_DATABASE_CREATE:-$DATABASE_CREATE}"
|
||||
DATABASE_USER_NORMAL="${ENV_DATABASE_USER:-${DATABASE_USER_NORMAL:-$user_name}}"
|
||||
DATABASE_PASS_NORMAL="${ENV_DATABASE_PASSWORD:-${DATABASE_PASS_NORMAL:-$user_pass}}"
|
||||
DATABASE_USER_ROOT="${ENV_DATABASE_ROOT_USER:-${DATABASE_USER_ROOT:-$root_user_name}}"
|
||||
DATABASE_PASS_ROOT="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_PASS_ROOT:-$root_user_pass}}"
|
||||
if [ -n "$DATABASE_PASS_NORMAL" ] && [ ! -f "${USER_FILE_PREFIX}/db_pass_user" ]; then
|
||||
echo "$DATABASE_PASS_NORMAL" >"${USER_FILE_PREFIX}/db_pass_user"
|
||||
fi
|
||||
if [ -n "$DATABASE_PASS_ROOT" ] && [ ! -f "${ROOT_FILE_PREFIX}/db_pass_root" ]; then
|
||||
echo "$DATABASE_PASS_ROOT" >"${ROOT_FILE_PREFIX}/db_pass_root"
|
||||
fi
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# [DATABASE_DIR_[SQLITE,REDIS,POSTGRES,MARIADB,COUCHDB,MONGODB,SUPABASE]]
|
||||
if [ "$DATABASE_SERVICE_TYPE" = "custom" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_CUSTOM:-/usr/local/share/httpd/admin/databases}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_CUSTOM:-/admin/dbadmin}"
|
||||
elif [ "$SERVICE_NAME" = "redis" ] || [ "$DATABASE_SERVICE_TYPE" = "redis" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_REDIS:-/usr/local/share/httpd/admin/redis}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_REDIS:-/admin/redis}"
|
||||
elif [ "$SERVICE_NAME" = "postgres" ] || [ "$DATABASE_SERVICE_TYPE" = "postgres" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_POSTGRES:-/usr/local/share/httpd/admin/postgres}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_POSTGRES:-/admin/postgres}"
|
||||
elif [ "$SERVICE_NAME" = "mariadb" ] || [ "$DATABASE_SERVICE_TYPE" = "mariadb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MARIADB:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MARIADB:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "mysql" ] || [ "$DATABASE_SERVICE_TYPE" = "mysql" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MYSQL:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MYSQL:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "couchdb" ] || [ "$DATABASE_SERVICE_TYPE" = "couchdb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_COUCHDB:-/usr/local/share/httpd/admin/couchdb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_COUCHDB:-/admin/couchdb}"
|
||||
elif [ "$SERVICE_NAME" = "mongodb" ] || [ "$DATABASE_SERVICE_TYPE" = "mongodb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MONGODB:-/usr/local/share/httpd/admin/mongodb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MONGODB:-/admin/mongodb}"
|
||||
elif [ "$SERVICE_NAME" = "supabase" ] || [ "$DATABASE_SERVICE_TYPE" = "supabase" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SUPABASE:-/usr/local/share/httpd/admin/supabase}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SUPBASE:-/admin/supabase}"
|
||||
elif [ "$SERVICE_NAME" = "sqlite" ] || [ "$DATABASE_SERVICE_TYPE" = "sqlite" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SQLITE:-/usr/local/share/httpd/admin/sqlite}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SQLITE:-/admin/sqlite}"
|
||||
[ -d "$DATABASE_DIR" ] || mkdir -p "$DATABASE_DIR"
|
||||
chmod 777 "$DATABASE_DIR"
|
||||
fi
|
||||
[ -n "$DATABASE_ADMIN_WWW_ROOT" ] && { [ ! -d "$DATABASE_ADMIN_WWW_ROOT" ] || mkdir -p "${DATABASE_ADMIN_WWW_ROOT}"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow variables via imports - Overwrite existing
|
||||
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set password to random if variable is random
|
||||
[ "$user_pass" = "random" ] && user_pass="$(__random_password ${RANDOM_PASS_USER:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password ${RANDOM_PASS_ROOT:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow setting initial users and passwords via environment and save to file
|
||||
[ -n "$user_name" ] && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$user_pass" ] && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
[ -n "$root_user_name" ] && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$root_user_pass" ] && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create needed dirs
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow per init script usernames and passwords
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/db_pass_user" && DATABASE_PASS_NORMAL="$(<"${USER_FILE_PREFIX}/db_pass_user")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/db_pass_root" && DATABASE_PASS_ROOT="$(<"${ROOT_FILE_PREFIX}/db_pass_root")"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set hostname for script
|
||||
sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup /config directories
|
||||
__init_config_etc
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# pre-run function
|
||||
__execute_prerun
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create user if needed
|
||||
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Modify user if needed
|
||||
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create base directories
|
||||
__setup_directories
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set switch user command
|
||||
__switch_to_user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize the home/working dir
|
||||
__init_working_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show init message
|
||||
__pre_message
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_db_users
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions in ${USER_FILE_PREFIX} and ${ROOT_FILE_PREFIX}
|
||||
__run_secure_function
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy /config to /etc
|
||||
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
|
||||
__initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Replace variables
|
||||
__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_database
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions
|
||||
__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log"
|
||||
errorCode=$?
|
||||
if [ -n "$EXEC_CMD_BIN" ]; then
|
||||
if [ "$errorCode" -eq 0 ]; then
|
||||
SERVICE_EXIT_CODE=0
|
||||
SERVICE_IS_RUNNING="yes"
|
||||
else
|
||||
SERVICE_EXIT_CODE=$errorCode
|
||||
SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}"
|
||||
[ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE"
|
||||
fi
|
||||
SERVICE_EXIT_CODE=0
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# start the post execute function in background
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
690
rootfs/usr/local/etc/docker/init.d/98-privoxy.sh
Executable file
690
rootfs/usr/local/etc/docker/init.d/98-privoxy.sh
Executable file
@@ -0,0 +1,690 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501061124-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
# @@ReadME : privoxy.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Monday, Jan 06, 2025 11:24 EST
|
||||
# @@File : privoxy.sh
|
||||
# @@Description :
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/start-service
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run trap command on exit
|
||||
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="privoxy"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
|
||||
. "/usr/local/etc/docker/functions/entrypoint.sh"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables
|
||||
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Script to execute
|
||||
START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Reset environment before executing service
|
||||
RESET_ENV="yes"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set webroot
|
||||
WWW_ROOT_DIR="/usr/local/share/httpd/default"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default predefined variables
|
||||
DATA_DIR="/data/privoxy" # set data directory
|
||||
CONF_DIR="/config/privoxy" # set config directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the containers etc directory
|
||||
ETC_DIR="/etc/privoxy"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the var dir
|
||||
VAR_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TMP_DIR="/tmp/privoxy" # set the temp dir
|
||||
RUN_DIR="/run/privoxy" # set scripts pid dir
|
||||
LOG_DIR="/data/logs/privoxy" # set log directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the working dir
|
||||
WORK_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# port which service is listening on
|
||||
SERVICE_PORT="8118"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
#SERVICE_USER="privoxy" # execute command as another user
|
||||
#SERVICE_GROUP="privoxy" # Set the service group
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set password length
|
||||
RANDOM_PASS_USER=""
|
||||
RANDOM_PASS_ROOT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute command variables - keep single quotes variables will be expanded later
|
||||
EXEC_CMD_BIN='privoxy' # command to execute
|
||||
EXEC_CMD_ARGS='--no-daemon $CONF_DIR/config' # command arguments
|
||||
EXEC_PRE_SCRIPT='' # execute script before
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a web server
|
||||
IS_WEB_SERVER="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a database server
|
||||
IS_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Does this service use a database server
|
||||
USES_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set defualt type - [custom,sqlite,redis,postgres,mariadb,mysql,couchdb,mongodb,supabase]
|
||||
DATABASE_SERVICE_TYPE="sqlite"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show message before execute
|
||||
PRE_EXEC_MESSAGE=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the wait time to execute __post_execute function - minutes
|
||||
POST_EXECUTE_WAIT_TIME="1"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Update path var
|
||||
PATH="$PATH:."
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Lets get containers ip address
|
||||
IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Where to save passwords to
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info password/random]
|
||||
root_user_name="${PRIVOXY_ROOT_USER_NAME:-}" # root user name
|
||||
root_user_pass="${PRIVOXY_ROOT_PASS_WORD:-}" # root user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Normal user info [password/random]
|
||||
user_name="${PRIVOXY_USER_NAME:-}" # normal user name
|
||||
user_pass="${PRIVOXY_USER_PASS_WORD:-}" # normal user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Load variables from config
|
||||
[ -f "/config/env/privoxy.script.sh" ] && . "/config/env/privoxy.script.sh" # Generated by my dockermgr script
|
||||
[ -f "/config/env/privoxy.sh" ] && . "/config/env/privoxy.sh" # Overwrite the variabes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional predefined variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Specifiy custom directories to be created
|
||||
ADD_APPLICATION_FILES=""
|
||||
ADD_APPLICATION_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
APPLICATION_FILES="$LOG_DIR/$SERVICE_NAME.log"
|
||||
APPLICATION_DIRS="$ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional config dirs - will be Copied to /etc/$name
|
||||
ADDITIONAL_CONFIG_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\"
|
||||
CMD_ENV=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Overwrite based on file/directory
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Per Application Variables or imports
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom commands to run before copying to /config
|
||||
__run_precopy() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom prerun functions - IE setup WWW_ROOT_DIR
|
||||
__execute_prerun() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Run any pre-execution checks
|
||||
__run_pre_execute_checks() {
|
||||
# Set variables
|
||||
local exitStatus=0
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME" # message to show at start
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME" # message to show at completion
|
||||
__banner "$pre_execute_checks_MessageST"
|
||||
# Put command to execute in parentheses
|
||||
{
|
||||
true
|
||||
}
|
||||
exitStatus=$?
|
||||
__banner "$pre_execute_checks_MessageEnd: Status $exitStatus"
|
||||
|
||||
# show exit message
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
# exit function
|
||||
return $exitStatus
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# delete files
|
||||
#__rm ""
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# custom commands
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# replace variables
|
||||
# __replace "" "" "$CONF_DIR/privoxy.conf"
|
||||
# replace variables recursively
|
||||
# __find_replace "" "" "$CONF_DIR"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute if directories is empty
|
||||
# __is_dir_empty "$CONF_DIR" && true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions to run after copying to /config
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# unset unneeded variables
|
||||
unset sysname
|
||||
# Lets wait a few seconds before continuing
|
||||
sleep 5
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run after executing
|
||||
__post_execute() {
|
||||
local pid="" # init pid var
|
||||
local retVal=0 # set default exit code
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing
|
||||
local waitTime=$((ctime * 60)) # convert minutes to seconds
|
||||
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
|
||||
# wait
|
||||
sleep $waitTime
|
||||
# execute commands after waiting
|
||||
(
|
||||
# show message
|
||||
__banner "$postMessageST"
|
||||
# commands to execute
|
||||
sleep 5
|
||||
# show exit message
|
||||
__banner "$postMessageEnd: Status $retVal"
|
||||
) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
pid=$!
|
||||
ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && retVal=0 || retVal=10
|
||||
# allow custom functions
|
||||
if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi
|
||||
# exit function
|
||||
return $retVal
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__pre_message() {
|
||||
local exitCode=0
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to setup ssl support
|
||||
__update_ssl_conf() {
|
||||
local exitCode=0
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi
|
||||
# set exitCode
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env() {
|
||||
local exitCode=0
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
|
||||
cat <<EOF | tee -p "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info [password/random]
|
||||
#ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$PRIVOXY_ROOT_USER_NAME}" # root user name
|
||||
#ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$PRIVOXY_ROOT_PASS_WORD}" # root user password
|
||||
#root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" #
|
||||
#root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#Normal user info [password/random]
|
||||
#ENV_USER_NAME="${ENV_USER_NAME:-$PRIVOXY_USER_NAME}" #
|
||||
#ENV_USER_PASS="${ENV_USER_PASS:-$PRIVOXY_USER_PASS_WORD}" #
|
||||
#user_name="${ENV_USER_NAME:-$user_name}" # normal user name
|
||||
#user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password
|
||||
|
||||
EOF
|
||||
fi
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__execute_prerun_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_pre_execute_checks_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_conf_files_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__post_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_message_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_ssl_conf_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
fi
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1))
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1))
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local runExitCode=0
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
|
||||
local path="$(eval echo "$PATH")" # expand variables
|
||||
local message="$(eval echo "")" # expand variables
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
|
||||
#
|
||||
if [ -z "$cmd" ]; then
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
echo "$name is not a valid executable"
|
||||
return 2
|
||||
fi
|
||||
# check and exit if already running
|
||||
if __proc_check "$name" || __proc_check "$cmd"; then
|
||||
echo "$name is already running" >&2
|
||||
return 0
|
||||
else
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show message if env exists
|
||||
if [ -n "$cmd" ]; then
|
||||
[ -n "$SERVICE_USER" ] && echo "Setting up $cmd to run as $SERVICE_USER" || SERVICE_USER="root"
|
||||
[ -n "$SERVICE_PORT" ] && echo "$name will be running on port $SERVICE_PORT" || SERVICE_PORT=""
|
||||
fi
|
||||
if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then
|
||||
export cmd_exec="$pre $cmd $args"
|
||||
message="Starting service: $name $args through $pre"
|
||||
else
|
||||
export cmd_exec="$cmd $args"
|
||||
message="Starting service: $name $args"
|
||||
fi
|
||||
[ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "/data/logs/init.txt"
|
||||
echo "$message" | tee -a -p "/data/logs/init.txt"
|
||||
su_cmd touch "$SERVICE_PID_FILE"
|
||||
if [ "$RESET_ENV" = "yes" ]; then
|
||||
env_command="$(echo "env -i HOME=\"$home\" LC_CTYPE=\"$lc_type\" PATH=\"$path\" HOSTNAME=\"$sysname\" USER=\"${SERVICE_USER:-$RUNAS_USER}\" $extra_env")"
|
||||
execute_command="$(__trim "$su_exec $env_command $cmd_exec")"
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2 >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT"
|
||||
[ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT"
|
||||
runExitCode=$?
|
||||
fi
|
||||
return $runExitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# username and password actions
|
||||
__run_secure_function() {
|
||||
local filesperms
|
||||
if [ -n "$user_name" ] || [ -n "$user_pass" ]; then
|
||||
for filesperms in "${USER_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
|
||||
for filesperms in "${ROOT_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
unset filesperms
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow ENV_ variable - Import env file
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SERVICE_EXIT_CODE=0 # default exit code
|
||||
# application specific
|
||||
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
|
||||
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check
|
||||
__check_service "$1" && SERVICE_IS_RUNNING=yes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ensure needed directories exists
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create auth directories
|
||||
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
|
||||
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
|
||||
[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER"
|
||||
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}"
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Database env
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
RESET_ENV="no"
|
||||
DATABASE_CREATE="${ENV_DATABASE_CREATE:-$DATABASE_CREATE}"
|
||||
DATABASE_USER_NORMAL="${ENV_DATABASE_USER:-${DATABASE_USER_NORMAL:-$user_name}}"
|
||||
DATABASE_PASS_NORMAL="${ENV_DATABASE_PASSWORD:-${DATABASE_PASS_NORMAL:-$user_pass}}"
|
||||
DATABASE_USER_ROOT="${ENV_DATABASE_ROOT_USER:-${DATABASE_USER_ROOT:-$root_user_name}}"
|
||||
DATABASE_PASS_ROOT="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_PASS_ROOT:-$root_user_pass}}"
|
||||
if [ -n "$DATABASE_PASS_NORMAL" ] && [ ! -f "${USER_FILE_PREFIX}/db_pass_user" ]; then
|
||||
echo "$DATABASE_PASS_NORMAL" >"${USER_FILE_PREFIX}/db_pass_user"
|
||||
fi
|
||||
if [ -n "$DATABASE_PASS_ROOT" ] && [ ! -f "${ROOT_FILE_PREFIX}/db_pass_root" ]; then
|
||||
echo "$DATABASE_PASS_ROOT" >"${ROOT_FILE_PREFIX}/db_pass_root"
|
||||
fi
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# [DATABASE_DIR_[SQLITE,REDIS,POSTGRES,MARIADB,COUCHDB,MONGODB,SUPABASE]]
|
||||
if [ "$DATABASE_SERVICE_TYPE" = "custom" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_CUSTOM:-/usr/local/share/httpd/admin/databases}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_CUSTOM:-/admin/dbadmin}"
|
||||
elif [ "$SERVICE_NAME" = "redis" ] || [ "$DATABASE_SERVICE_TYPE" = "redis" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_REDIS:-/usr/local/share/httpd/admin/redis}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_REDIS:-/admin/redis}"
|
||||
elif [ "$SERVICE_NAME" = "postgres" ] || [ "$DATABASE_SERVICE_TYPE" = "postgres" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_POSTGRES:-/usr/local/share/httpd/admin/postgres}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_POSTGRES:-/admin/postgres}"
|
||||
elif [ "$SERVICE_NAME" = "mariadb" ] || [ "$DATABASE_SERVICE_TYPE" = "mariadb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MARIADB:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MARIADB:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "mysql" ] || [ "$DATABASE_SERVICE_TYPE" = "mysql" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MYSQL:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MYSQL:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "couchdb" ] || [ "$DATABASE_SERVICE_TYPE" = "couchdb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_COUCHDB:-/usr/local/share/httpd/admin/couchdb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_COUCHDB:-/admin/couchdb}"
|
||||
elif [ "$SERVICE_NAME" = "mongodb" ] || [ "$DATABASE_SERVICE_TYPE" = "mongodb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MONGODB:-/usr/local/share/httpd/admin/mongodb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MONGODB:-/admin/mongodb}"
|
||||
elif [ "$SERVICE_NAME" = "supabase" ] || [ "$DATABASE_SERVICE_TYPE" = "supabase" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SUPABASE:-/usr/local/share/httpd/admin/supabase}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SUPBASE:-/admin/supabase}"
|
||||
elif [ "$SERVICE_NAME" = "sqlite" ] || [ "$DATABASE_SERVICE_TYPE" = "sqlite" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SQLITE:-/usr/local/share/httpd/admin/sqlite}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SQLITE:-/admin/sqlite}"
|
||||
[ -d "$DATABASE_DIR" ] || mkdir -p "$DATABASE_DIR"
|
||||
chmod 777 "$DATABASE_DIR"
|
||||
fi
|
||||
[ -n "$DATABASE_ADMIN_WWW_ROOT" ] && { [ ! -d "$DATABASE_ADMIN_WWW_ROOT" ] || mkdir -p "${DATABASE_ADMIN_WWW_ROOT}"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow variables via imports - Overwrite existing
|
||||
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set password to random if variable is random
|
||||
[ "$user_pass" = "random" ] && user_pass="$(__random_password ${RANDOM_PASS_USER:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password ${RANDOM_PASS_ROOT:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow setting initial users and passwords via environment and save to file
|
||||
[ -n "$user_name" ] && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$user_pass" ] && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
[ -n "$root_user_name" ] && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$root_user_pass" ] && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create needed dirs
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow per init script usernames and passwords
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/db_pass_user" && DATABASE_PASS_NORMAL="$(<"${USER_FILE_PREFIX}/db_pass_user")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/db_pass_root" && DATABASE_PASS_ROOT="$(<"${ROOT_FILE_PREFIX}/db_pass_root")"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set hostname for script
|
||||
sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup /config directories
|
||||
__init_config_etc
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# pre-run function
|
||||
__execute_prerun
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create user if needed
|
||||
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Modify user if needed
|
||||
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create base directories
|
||||
__setup_directories
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set switch user command
|
||||
__switch_to_user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize the home/working dir
|
||||
__init_working_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show init message
|
||||
__pre_message
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_db_users
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions in ${USER_FILE_PREFIX} and ${ROOT_FILE_PREFIX}
|
||||
__run_secure_function
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy /config to /etc
|
||||
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
|
||||
__initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Replace variables
|
||||
__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_database
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions
|
||||
__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log"
|
||||
errorCode=$?
|
||||
if [ -n "$EXEC_CMD_BIN" ]; then
|
||||
if [ "$errorCode" -eq 0 ]; then
|
||||
SERVICE_EXIT_CODE=0
|
||||
SERVICE_IS_RUNNING="yes"
|
||||
else
|
||||
SERVICE_EXIT_CODE=$errorCode
|
||||
SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}"
|
||||
[ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE"
|
||||
fi
|
||||
SERVICE_EXIT_CODE=0
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# start the post execute function in background
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
745
rootfs/usr/local/etc/docker/init.d/zz-nginx.sh
Executable file
745
rootfs/usr/local/etc/docker/init.d/zz-nginx.sh
Executable file
@@ -0,0 +1,745 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202501291320-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
# @@ReadME : zz-nginx.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Wednesday, Jan 29, 2025 13:20 EST
|
||||
# @@File : zz-nginx.sh
|
||||
# @@Description :
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/start-service
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run trap command on exit
|
||||
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="nginx"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
|
||||
. "/usr/local/etc/docker/functions/entrypoint.sh"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables
|
||||
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
__onion_site_dir_is_empty() { [ "$(ls -A "/data/htdocs/onions/${1:-$onion_site}" 2>/dev/null | wc -l)" -eq 0 ] || return 1; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Script to execute
|
||||
START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Reset environment before executing service
|
||||
RESET_ENV="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set webroot
|
||||
WWW_ROOT_DIR="/data/htdocs/www"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default predefined variables
|
||||
DATA_DIR="/data/nginx" # set data directory
|
||||
CONF_DIR="/config/nginx" # set config directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the containers etc directory
|
||||
ETC_DIR="/etc/nginx"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the var dir
|
||||
VAR_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TMP_DIR="/tmp/nginx" # set the temp dir
|
||||
RUN_DIR="/run/nginx" # set scripts pid dir
|
||||
LOG_DIR="/data/logs/nginx" # set log directory
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the working dir
|
||||
WORK_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# port which service is listening on
|
||||
SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
#SERVICE_USER="nginx" # execute command as another user
|
||||
#SERVICE_GROUP="nginx" # Set the service group
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set password length
|
||||
RANDOM_PASS_USER=""
|
||||
RANDOM_PASS_ROOT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute command variables - keep single quotes variables will be expanded later
|
||||
EXEC_CMD_BIN='nginx' # command to execute
|
||||
EXEC_CMD_ARGS='-c $ETC_DIR/nginx.conf' # command arguments
|
||||
EXEC_PRE_SCRIPT='' # execute script before
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a web server
|
||||
IS_WEB_SERVER="yes"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a database server
|
||||
IS_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Does this service use a database server
|
||||
USES_DATABASE_SERVICE="no"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set defualt type - [custom,sqlite,redis,postgres,mariadb,mysql,couchdb,mongodb,supabase]
|
||||
DATABASE_SERVICE_TYPE="sqlite"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show message before execute
|
||||
PRE_EXEC_MESSAGE=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the wait time to execute __post_execute function - minutes
|
||||
POST_EXECUTE_WAIT_TIME="1"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Update path var
|
||||
PATH="$PATH:."
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Lets get containers ip address
|
||||
IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Where to save passwords to
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info password/random]
|
||||
root_user_name="${NGINX_ROOT_USER_NAME:-}" # root user name
|
||||
root_user_pass="${NGINX_ROOT_PASS_WORD:-}" # root user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Normal user info [password/random]
|
||||
user_name="${NGINX_USER_NAME:-}" # normal user name
|
||||
user_pass="${NGINX_USER_PASS_WORD:-}" # normal user password
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Load variables from config
|
||||
[ -f "/config/env/nginx.script.sh" ] && . "/config/env/nginx.script.sh" # Generated by my dockermgr script
|
||||
[ -f "/config/env/nginx.sh" ] && . "/config/env/nginx.sh" # Overwrite the variabes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional predefined variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional variables
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Specifiy custom directories to be created
|
||||
ADD_APPLICATION_FILES=""
|
||||
ADD_APPLICATION_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
APPLICATION_FILES="$LOG_DIR/$SERVICE_NAME.log"
|
||||
APPLICATION_DIRS="$ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional config dirs - will be Copied to /etc/$name
|
||||
ADDITIONAL_CONFIG_DIRS=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\"
|
||||
CMD_ENV=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Overwrite based on file/directory
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Per Application Variables or imports
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom commands to run before copying to /config
|
||||
__run_precopy() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
# Define actions/commands
|
||||
if [ ! -d "$WWW_ROOT_DIR" ] || __is_dir_empty "$WWW_ROOT_DIR"; then
|
||||
mkdir -p "$WWW_ROOT_DIR"
|
||||
if [ -d "/usr/share/httpd/default" ]; then
|
||||
cp -Rf "/usr/share/httpd/default/." "$WWW_ROOT_DIR/"
|
||||
[ -f "$WWW_ROOT_DIR/hidden_service.html" ] && rm -Rf "$WWW_ROOT_DIR/hidden_service.html"
|
||||
else
|
||||
echo "Welcome" >"$WWW_ROOT_DIR/index.php"
|
||||
fi
|
||||
fi
|
||||
if [ -d "$WWW_ROOT_DIR/.git" ]; then
|
||||
rm -Rf "$WWW_ROOT_DIR/.git"
|
||||
fi
|
||||
[ -d "$WWW_ROOT_DIR/.well-known" ] || mkdir -p "$WWW_ROOT_DIR/.well-known"
|
||||
# allow custom functions
|
||||
if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom prerun functions - IE setup WWW_ROOT_DIR
|
||||
__execute_prerun() {
|
||||
# Define environment
|
||||
local hostname=${HOSTNAME}
|
||||
local php_ver="${PHP_VERSION:-84}"
|
||||
local php_fpm_bin="$(type -P php-fpm || type -P php-fpm$$php_ver || false)"
|
||||
# Define actions/commands
|
||||
if [ -n "$php_fpm_bin" ]; then
|
||||
$php_fpm_bin --nodaemonize --fpm-config "/etc/php$php_ver/php-fpm.conf" &
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Run any pre-execution checks
|
||||
__run_pre_execute_checks() {
|
||||
# Set variables
|
||||
local exitStatus=0
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME" # message to show at start
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME" # message to show at completion
|
||||
__banner "$pre_execute_checks_MessageST"
|
||||
# Put command to execute in parentheses
|
||||
{
|
||||
true
|
||||
}
|
||||
exitStatus=$?
|
||||
__banner "$pre_execute_checks_MessageEnd: Status $exitStatus"
|
||||
|
||||
# show exit message
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
# exit function
|
||||
return $exitStatus
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
local default_host="$DEFAULT_ONION_SITE"
|
||||
if [ -f "$WWW_ROOT_DIR/default_host.txt" ]; then
|
||||
default_host="${default_host:-$(<"$WWW_ROOT_DIR/default_host.txt")}"
|
||||
rm -Rf "$WWW_ROOT_DIR/default_host.txt"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# delete files
|
||||
#__rm ""
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# custom commands
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# replace variables
|
||||
# __replace "" "" "$CONF_DIR/nginx.conf"
|
||||
# replace variables recursively
|
||||
# __find_replace "" "" "$CONF_DIR"
|
||||
if [ -n "$default_host" ] && [ -f "$WWW_ROOT_DIR/index.html" ]; then
|
||||
sed -i 's|REPLACE_DEFAULT_TOR_ADDRESS|'$default_host'|g' "$WWW_ROOT_DIR/index.html"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions
|
||||
while :; do
|
||||
echo "waiting for tor to start"
|
||||
[ -f "/tmp/init_tor_services" ] && sleep 30 || break
|
||||
done
|
||||
echo "The tor server seems to have started "
|
||||
for site in "/run/tor/sites"/*; do
|
||||
onion_site="$(basename -- $site)"
|
||||
__onion_site_dir_is_empty "$onion_site" && NEW_SITE="yes"
|
||||
[ -d "/data/htdocs/onions/$onion_site" ] || mkdir -p "/data/htdocs/onions/$onion_site"
|
||||
if [ "$default_host" = "$onion_site" ]; then
|
||||
if __onion_site_dir_is_empty "$onion_site"; then
|
||||
cp -Rfa "$WWW_ROOT_DIR/." "/data/htdocs/onions/$onion_site/"
|
||||
fi
|
||||
else
|
||||
if [ "$NEW_SITE" = "yes" ]; then
|
||||
if [ -f "/usr/share/httpd/default/hidden_service.html" ]; then
|
||||
cp -Rf "/usr/share/httpd/default/hidden_service.html" "/data/htdocs/onions/$onion_site/index.html"
|
||||
else
|
||||
echo '<html><body><br /><center>HTML Document Root: /data/htdocs/onions/'$onion_site'</center><br /></body></html>' >"/data/htdocs/onions/$onion_site/index.html"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ ! -f "/config/nginx/vhosts.d/$onion_site.onion.conf" ]; then
|
||||
cp -Rf "/config/nginx/vhosts.d/template" "/config/nginx/vhosts.d/$onion_site.onion.conf"
|
||||
sed -i 's|REPLACE_ONION_PORT|'$SERVICE_PORT'|g' "/config/nginx/vhosts.d/$onion_site.onion.conf"
|
||||
sed -i 's|REPLACE_ONION_SITE|'$onion_site.onion'|g' "/config/nginx/vhosts.d/$onion_site.onion.conf"
|
||||
sed -i 's|REPLACE_ONION_WWW_DIR|/data/htdocs/onions/'$onion_site'|g' "/config/nginx/vhosts.d/$onion_site.onion.conf"
|
||||
sed -i 's|REPLACE_ONION_WWW_DIR|/data/htdocs/onions/'$onion_site'|g' "/data/htdocs/onions/$onion_site/index.html"
|
||||
sed -i 's|REPLACE_DEFAULT_TOR_ADDRESS|'$onion_site'|g' "/data/htdocs/onions/$onion_site/index.html"
|
||||
fi
|
||||
unset NEW_SITE
|
||||
echo "Created $onion_site.onion in /data/htdocs/onions/$onion_site"
|
||||
done
|
||||
# allow custom functions
|
||||
if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute if directories is empty
|
||||
# __is_dir_empty "$CONF_DIR" && true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# define actions to run after copying to /config
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# unset unneeded variables
|
||||
unset sysname
|
||||
# Lets wait a few seconds before continuing
|
||||
sleep 5
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run after executing
|
||||
__post_execute() {
|
||||
local pid="" # init pid var
|
||||
local retVal=0 # set default exit code
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing
|
||||
local waitTime=$((ctime * 60)) # convert minutes to seconds
|
||||
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
|
||||
# wait
|
||||
sleep $waitTime
|
||||
# execute commands after waiting
|
||||
(
|
||||
# show message
|
||||
__banner "$postMessageST"
|
||||
# commands to execute
|
||||
sleep 5
|
||||
# show exit message
|
||||
__banner "$postMessageEnd: Status $retVal"
|
||||
) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
pid=$!
|
||||
ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && retVal=0 || retVal=10
|
||||
# allow custom functions
|
||||
if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi
|
||||
# exit function
|
||||
return $retVal
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__pre_message() {
|
||||
local exitCode=0
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi
|
||||
# exit function
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to setup ssl support
|
||||
__update_ssl_conf() {
|
||||
local exitCode=0
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi
|
||||
# set exitCode
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env() {
|
||||
local exitCode=0
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
|
||||
cat <<EOF | tee -p "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info [password/random]
|
||||
#ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$NGINX_ROOT_USER_NAME}" # root user name
|
||||
#ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$NGINX_ROOT_PASS_WORD}" # root user password
|
||||
#root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" #
|
||||
#root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#Normal user info [password/random]
|
||||
#ENV_USER_NAME="${ENV_USER_NAME:-$NGINX_USER_NAME}" #
|
||||
#ENV_USER_PASS="${ENV_USER_PASS:-$NGINX_USER_PASS_WORD}" #
|
||||
#user_name="${ENV_USER_NAME:-$user_name}" # normal user name
|
||||
#user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password
|
||||
|
||||
EOF
|
||||
fi
|
||||
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__execute_prerun_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_pre_execute_checks_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_conf_files_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__post_execute_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pre_message_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_ssl_conf_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
fi
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1))
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1))
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local runExitCode=0
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
|
||||
local path="$(eval echo "$PATH")" # expand variables
|
||||
local message="$(eval echo "")" # expand variables
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
|
||||
#
|
||||
if [ -z "$cmd" ]; then
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
echo "$name is not a valid executable"
|
||||
return 2
|
||||
fi
|
||||
# check and exit if already running
|
||||
if __proc_check "$name" || __proc_check "$cmd"; then
|
||||
echo "$name is already running" >&2
|
||||
return 0
|
||||
else
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show message if env exists
|
||||
if [ -n "$cmd" ]; then
|
||||
[ -n "$SERVICE_USER" ] && echo "Setting up $cmd to run as $SERVICE_USER" || SERVICE_USER="root"
|
||||
[ -n "$SERVICE_PORT" ] && echo "$name will be running on port $SERVICE_PORT" || SERVICE_PORT=""
|
||||
fi
|
||||
if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then
|
||||
export cmd_exec="$pre $cmd $args"
|
||||
message="Starting service: $name $args through $pre"
|
||||
else
|
||||
export cmd_exec="$cmd $args"
|
||||
message="Starting service: $name $args"
|
||||
fi
|
||||
[ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "/data/logs/init.txt"
|
||||
echo "$message" | tee -a -p "/data/logs/init.txt"
|
||||
su_cmd touch "$SERVICE_PID_FILE"
|
||||
if [ "$RESET_ENV" = "yes" ]; then
|
||||
env_command="$(echo "env -i HOME=\"$home\" LC_CTYPE=\"$lc_type\" PATH=\"$path\" HOSTNAME=\"$sysname\" USER=\"${SERVICE_USER:-$RUNAS_USER}\" $extra_env")"
|
||||
execute_command="$(__trim "$su_exec $env_command $cmd_exec")"
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
else
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
retVal=10
|
||||
cmd="$cmd"
|
||||
SERVICE_NAME="$SERVICE_NAME"
|
||||
SERVICE_PID_FILE="$SERVICE_PID_FILE"
|
||||
$execute_command 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
|
||||
execPid=\$!
|
||||
sleep 2
|
||||
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
|
||||
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
|
||||
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $execute_command" >&2 >&2
|
||||
exit \$retVal
|
||||
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT"
|
||||
[ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT"
|
||||
runExitCode=$?
|
||||
fi
|
||||
return $runExitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# username and password actions
|
||||
__run_secure_function() {
|
||||
local filesperms
|
||||
if [ -n "$user_name" ] || [ -n "$user_pass" ]; then
|
||||
for filesperms in "${USER_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
|
||||
for filesperms in "${ROOT_FILE_PREFIX}"/*; do
|
||||
if [ -e "$filesperms" ]; then
|
||||
chmod -Rf 600 "$filesperms"
|
||||
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null
|
||||
fi
|
||||
done 2>/dev/null | tee -p -a "/data/logs/init.txt"
|
||||
fi
|
||||
unset filesperms
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow ENV_ variable - Import env file
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SERVICE_EXIT_CODE=0 # default exit code
|
||||
# application specific
|
||||
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
|
||||
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check
|
||||
__check_service "$1" && SERVICE_IS_RUNNING=yes
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ensure needed directories exists
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create auth directories
|
||||
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
|
||||
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
|
||||
[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER"
|
||||
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}"
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted
|
||||
[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Database env
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
RESET_ENV="no"
|
||||
DATABASE_CREATE="${ENV_DATABASE_CREATE:-$DATABASE_CREATE}"
|
||||
DATABASE_USER_NORMAL="${ENV_DATABASE_USER:-${DATABASE_USER_NORMAL:-$user_name}}"
|
||||
DATABASE_PASS_NORMAL="${ENV_DATABASE_PASSWORD:-${DATABASE_PASS_NORMAL:-$user_pass}}"
|
||||
DATABASE_USER_ROOT="${ENV_DATABASE_ROOT_USER:-${DATABASE_USER_ROOT:-$root_user_name}}"
|
||||
DATABASE_PASS_ROOT="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_PASS_ROOT:-$root_user_pass}}"
|
||||
if [ -n "$DATABASE_PASS_NORMAL" ] && [ ! -f "${USER_FILE_PREFIX}/db_pass_user" ]; then
|
||||
echo "$DATABASE_PASS_NORMAL" >"${USER_FILE_PREFIX}/db_pass_user"
|
||||
fi
|
||||
if [ -n "$DATABASE_PASS_ROOT" ] && [ ! -f "${ROOT_FILE_PREFIX}/db_pass_root" ]; then
|
||||
echo "$DATABASE_PASS_ROOT" >"${ROOT_FILE_PREFIX}/db_pass_root"
|
||||
fi
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# [DATABASE_DIR_[SQLITE,REDIS,POSTGRES,MARIADB,COUCHDB,MONGODB,SUPABASE]]
|
||||
if [ "$DATABASE_SERVICE_TYPE" = "custom" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_CUSTOM:-/usr/local/share/httpd/admin/databases}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_CUSTOM:-/admin/dbadmin}"
|
||||
elif [ "$SERVICE_NAME" = "redis" ] || [ "$DATABASE_SERVICE_TYPE" = "redis" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_REDIS:-/usr/local/share/httpd/admin/redis}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_REDIS:-/admin/redis}"
|
||||
elif [ "$SERVICE_NAME" = "postgres" ] || [ "$DATABASE_SERVICE_TYPE" = "postgres" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_POSTGRES:-/usr/local/share/httpd/admin/postgres}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_POSTGRES:-/admin/postgres}"
|
||||
elif [ "$SERVICE_NAME" = "mariadb" ] || [ "$DATABASE_SERVICE_TYPE" = "mariadb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MARIADB:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MARIADB:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "mysql" ] || [ "$DATABASE_SERVICE_TYPE" = "mysql" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MYSQL:-/usr/local/share/httpd/admin/mysql}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MYSQL:-/admin/mysql}"
|
||||
elif [ "$SERVICE_NAME" = "couchdb" ] || [ "$DATABASE_SERVICE_TYPE" = "couchdb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_COUCHDB:-/usr/local/share/httpd/admin/couchdb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_COUCHDB:-/admin/couchdb}"
|
||||
elif [ "$SERVICE_NAME" = "mongodb" ] || [ "$DATABASE_SERVICE_TYPE" = "mongodb" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MONGODB:-/usr/local/share/httpd/admin/mongodb}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MONGODB:-/admin/mongodb}"
|
||||
elif [ "$SERVICE_NAME" = "supabase" ] || [ "$DATABASE_SERVICE_TYPE" = "supabase" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SUPABASE:-/usr/local/share/httpd/admin/supabase}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SUPBASE:-/admin/supabase}"
|
||||
elif [ "$SERVICE_NAME" = "sqlite" ] || [ "$DATABASE_SERVICE_TYPE" = "sqlite" ]; then
|
||||
DATABASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_BASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME"
|
||||
DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SQLITE:-/usr/local/share/httpd/admin/sqlite}"
|
||||
[ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SQLITE:-/admin/sqlite}"
|
||||
[ -d "$DATABASE_DIR" ] || mkdir -p "$DATABASE_DIR"
|
||||
chmod 777 "$DATABASE_DIR"
|
||||
fi
|
||||
[ -n "$DATABASE_ADMIN_WWW_ROOT" ] && { [ ! -d "$DATABASE_ADMIN_WWW_ROOT" ] || mkdir -p "${DATABASE_ADMIN_WWW_ROOT}"; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow variables via imports - Overwrite existing
|
||||
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set password to random if variable is random
|
||||
[ "$user_pass" = "random" ] && user_pass="$(__random_password ${RANDOM_PASS_USER:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password ${RANDOM_PASS_ROOT:-16})"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow setting initial users and passwords via environment and save to file
|
||||
[ -n "$user_name" ] && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$user_pass" ] && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
[ -n "$root_user_name" ] && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name"
|
||||
[ -n "$root_user_pass" ] && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create needed dirs
|
||||
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
|
||||
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Allow per init script usernames and passwords
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")"
|
||||
__file_exists_with_content "${USER_FILE_PREFIX}/db_pass_user" && DATABASE_PASS_NORMAL="$(<"${USER_FILE_PREFIX}/db_pass_user")"
|
||||
__file_exists_with_content "${ROOT_FILE_PREFIX}/db_pass_root" && DATABASE_PASS_ROOT="$(<"${ROOT_FILE_PREFIX}/db_pass_root")"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set hostname for script
|
||||
sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_service_env
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup /config directories
|
||||
__init_config_etc
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# pre-run function
|
||||
__execute_prerun
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# create user if needed
|
||||
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Modify user if needed
|
||||
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create base directories
|
||||
__setup_directories
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set switch user command
|
||||
__switch_to_user
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize the home/working dir
|
||||
__init_working_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# show init message
|
||||
__pre_message
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_db_users
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions in ${USER_FILE_PREFIX} and ${ROOT_FILE_PREFIX}
|
||||
__run_secure_function
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_precopy
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy /config to /etc
|
||||
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
|
||||
__initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Replace variables
|
||||
__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__initialize_database
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set permissions
|
||||
__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#
|
||||
__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log"
|
||||
errorCode=$?
|
||||
if [ -n "$EXEC_CMD_BIN" ]; then
|
||||
if [ "$errorCode" -eq 0 ]; then
|
||||
SERVICE_EXIT_CODE=0
|
||||
SERVICE_IS_RUNNING="yes"
|
||||
else
|
||||
SERVICE_EXIT_CODE=$errorCode
|
||||
SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}"
|
||||
[ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE"
|
||||
fi
|
||||
SERVICE_EXIT_CODE=0
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# start the post execute function in background
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
22
rootfs/usr/share/httpd/default/hidden_service.html
Normal file
22
rootfs/usr/share/httpd/default/hidden_service.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="color-scheme" content="dark" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||
/>
|
||||
<title>Welcome!</title>
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<br /><br /><br />
|
||||
<h1>
|
||||
Welcome to your hidden onion site!<br />
|
||||
This document is located in: REPLACE_ONION_WWW_DIR
|
||||
</h1>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
116
rootfs/usr/share/httpd/default/index.css
Normal file
116
rootfs/usr/share/httpd/default/index.css
Normal file
@@ -0,0 +1,116 @@
|
||||
TD,
|
||||
TH,
|
||||
BODY {
|
||||
font-family: Verdana, Helvetica, sans-serif;
|
||||
font-size: 1.1rem;
|
||||
font-weight: normal;
|
||||
font-variant: normal;
|
||||
text-transform: none;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
text-wrap: balance;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
background-image: url('/index.png');
|
||||
}
|
||||
|
||||
TH {
|
||||
background-color: #333;
|
||||
color: #ffffff;
|
||||
border-top: 1px solid #678ca0;
|
||||
vertical-align: middle;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
TD {
|
||||
background-color: 333;
|
||||
border-top: 1px solid #678ca0;
|
||||
}
|
||||
|
||||
.box {
|
||||
border: 1px solid #678ca0;
|
||||
padding: 0px;
|
||||
width: 100%;
|
||||
background-color: #333;
|
||||
margin-bottom: 10px;
|
||||
width: 600px;
|
||||
}
|
||||
|
||||
H5,
|
||||
H3 {
|
||||
padding: 3px;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 0px;
|
||||
background-color: #333;
|
||||
color: white;
|
||||
font-family: Verdana, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
H3 {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
H5 {
|
||||
font-size: 10px;
|
||||
text-align: right;
|
||||
background-color: #333;
|
||||
color: #678ca0;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
margin: 0px;
|
||||
width: 100%;
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
.leftspacer {
|
||||
margin: 0px;
|
||||
padding: 5px;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
.serviceup {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.servicedown {
|
||||
color: red;
|
||||
}
|
||||
|
||||
A {
|
||||
text-decoration: none;
|
||||
color: #5d83a9;
|
||||
}
|
||||
|
||||
P.main {
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
text-align: center;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #c39;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #f00;
|
||||
}
|
||||
|
||||
a:active {
|
||||
color: #c0f;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background-color: #f5f5f5;
|
||||
}
|
30
rootfs/usr/share/httpd/default/index.html
Normal file
30
rootfs/usr/share/httpd/default/index.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" type="text/css" href="/index.css" />
|
||||
<title>Welcome</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<center>
|
||||
<h2>
|
||||
<br /><br /><br />
|
||||
<br />
|
||||
Tor DNS is running on port 9053 and Tor Socks on 9050<br />
|
||||
Server address is: REPLACE_DEFAULT_TOR_ADDRESS <br />
|
||||
<br />
|
||||
Other usefull onion sites<br />
|
||||
<a href="http://duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion/">DuckDuckGo Search</a><br />
|
||||
<a href="http://paavlaytlfsqyvkg3yqj7hflfg5jw2jdg2fgkza5ruf6lplwseeqtvyd.onion/">Tor Hidden Wiki</a><br />
|
||||
<a href="http://protonmailrmez3lotccipshtkleegetolb73fuirgj7r4o4vfu7ozyd.onion">Protonmail</a><br />
|
||||
<a href="http://2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.onion/">Tor Project</a><br />
|
||||
<a href="http://sdolvtfhatvsysc6l34d65ymdwxcujausv7k5jk4cy5ttzhjoi6fzvyd.onion">Secure Drop</a><br />
|
||||
<a href="./list.html">A very long list of other onion sites</a><br />
|
||||
<br /><br /><br /><br />
|
||||
</h2>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
1654
rootfs/usr/share/httpd/default/list.html
Normal file
1654
rootfs/usr/share/httpd/default/list.html
Normal file
File diff suppressed because it is too large
Load Diff
337
rootfs/usr/share/tor/html/exit.html
Normal file
337
rootfs/usr/share/tor/html/exit.html
Normal file
@@ -0,0 +1,337 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<title>This is a Tor Exit Router</title>
|
||||
|
||||
<!--
|
||||
|
||||
This notice is intended to be placed on a virtual host for a domain that
|
||||
your Tor exit node IP reverse resolves to so that people who may be about
|
||||
to file an abuse complaint would check it first before bothering you or
|
||||
your ISP. Ex:
|
||||
http://tor-exit.yourdomain.org or http://tor-readme.yourdomain.org.
|
||||
|
||||
This type of setup has proven very effective at reducing abuse complaints
|
||||
for exit node operators.
|
||||
|
||||
There are a few places in this document that you may want to customize.
|
||||
They are marked with FIXME.
|
||||
|
||||
-->
|
||||
</head>
|
||||
<body>
|
||||
<p style="text-align: center; font-size: xx-large; font-weight: bold">
|
||||
This is a Tor Exit Router
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Most likely you are accessing this website because you had some issue with
|
||||
the traffic coming from this IP. This router is part of the
|
||||
<a href="https://www.torproject.org/">Tor Anonymity Network</a>, which is
|
||||
dedicated to
|
||||
<a href="https://www.torproject.org/about/overview">providing privacy</a>
|
||||
to people who need it most: average computer users. This router IP should
|
||||
be generating no other traffic, unless it has been compromised.
|
||||
</p>
|
||||
|
||||
<p style="text-align: center">
|
||||
<a href="https://www.torproject.org/about/overview">
|
||||
<img
|
||||
src="data:image/png;base64,
|
||||
iVBORw0KGgoAAAANSUhEUgAAAQQAAACQCAMAAADZVuXZAAAABGdBTUEAANbY1E9Y
|
||||
MgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGAUExURej4
|
||||
6Zycm+Hh4XZ2duTk5LS0tfP79OLc3P/r/6iopv///2ZmZgMDAw8PD/b29v39/cTE
|
||||
whUVFS8vL/Ly8by8uvv7+vn5+CUlJcXCm+/v7xsbGuzs7E5OTq2trASbBVpaWszM
|
||||
yaKipDk5ONra2iAhH8/OrX9/fPf35vv77j4+Pvj2zPz82Onp6PPz3t7e3ra2n66s
|
||||
if7+9b+/v+3t7efn529vb9DQ0GNjY4iIiLi9xtfX15aWldTU1Ofmyy6wMZCQjtkG
|
||||
Bufl4ZTcmYiLjujo4dbVwmppZmvLcd3czoaHhaSstsjIyMTL07Pmt9ny2sjty///
|
||||
/EVBPe/x05WcpZGRkVKzV+Pj3vDuw9vasqOfet/extbd5uPivOVXVvr9+dHY35WU
|
||||
hefm1IjJi8zR2e+bm/vg4C5PMvfFxf3w8DlyQP/4+Nvj6/77/IuTnZ7KolF8Vv39
|
||||
/+bi5v/9/HvCgCU7KLm5uMraylZfa3CZdf3//P3//7TQtu3k7ZwICPn9/eLu7gnB
|
||||
e20AAB3ZSURBVHja7F2JQ9rY1hdCOh/33YRAQhBDIAGJbLJYwAUqFhfUulu1taO1
|
||||
+zZdpp193ve9f/0754ZNwG4683yvHjAJycnJvb977pb8chz6x5X8Y+gf5JuXKxCu
|
||||
QPgYCE5KiEBGs980CKGACSBYRA4ZhA/5v0kQPJRQIsijQZql8qhMv0kQqtRLNSoG
|
||||
IPtZ3huZ/CZBoH5SclN11BX1gU9Eole9w1UX+a2CIN/cvwny4/6PN9maLW+ep4d4
|
||||
908wsG+bBbu4BYvvLjEI/iJRNU3LZBZuOrP7rn2X62Yms0XkgWcfb9Rnw+HwLC7C
|
||||
jc1rg6+hfrclawto0rWPcnNhYUHbWvD09kn/XECwFopwHDf29xdgq6/ngn37CwzP
|
||||
hYXW2nPBIIjlLXeJs1a4pclIKBn1BUa9At0vZPpP3WiEw3sPN1o/r/3ZmA3vbW70
|
||||
K8rlLQ4sWmAyFEr6mEkv2Vd71PzZrZlyWVJ0t6NScZhuXpHk93JP/jxBv1g2JIXX
|
||||
Taalg5a4JV80CNKWOblUKiEG2y0QjC1nT2J+b4Rn62qfufW9cPjhcc9OTSIlsFha
|
||||
igCszOQIgLAs9mFFSgAWV2ppeQV3QevRUrOJKpQRx01GIskoaI14qVEoei4WBFkq
|
||||
nEQikUlMsA0CXGa44Dp1mYez4fr/nWFRrYdnT9eLjLQ1GZkEiYT29p76ApBwQRgA
|
||||
gkRAZ4mhb19XqCUWegpZrSaUphL6KQNB8jv9F+0JiZMQoBBCP7DT4qW5hKsbgvDe
|
||||
xkeNboTD3QpavBBBkwBrvfE0wLInbPWBEJQKTAsujblDLasPBLE8lm8qQc1CWwJV
|
||||
Cln/RXtCYiW5HdreDjEMWKlRPbHf8fjw3qfNXpsNb3ZAMAohNPg06Vtfj0C6R4SB
|
||||
ICiJ7RATLGIEX+DGHvSDULO1oMoEsM5AEY1lL9wT0itRqAgIAfM2SDB1256wgIW8
|
||||
93mGxb02DAhCEuRtfX1zY3O97kVcC4e9IGhKArVYg4AXBq3SIBBWmNK2jRTgCX6a
|
||||
fXfRnpC2fAwAXzMpVKD5tBMONcK/z4Y3Pts084bGQ2wY02Av6gMQNoY2AARhIAhB
|
||||
KRH1Rdvgo9ZS+oHYB8IJJC+KWuCmUEaU5tIXXx3SXACTAfWNuSRtgQANf/jOFxkP
|
||||
4vjhAzSM6SiY8z19GtrY+O3FU8SAJgaDYGOPXo4XLo33gzBuNXVYc4VO5R77C0Cw
|
||||
RgPsEiN2XQDRx5zgBzAq+lLzdRxEBaU0phlRXV9/ITCbwkAQmmrtC58FAmqNtDD4
|
||||
CzwB2gRrZGSUQWBfg+JlXA0cGM5e+0LzOJIM7wEIIyPMYL0OfkDR6CAQ0lDJ8cre
|
||||
Fvjczg25HwSWuK7k/RXVIWV5mX1MSROE4ZTzj6++xLVflHTAa0vbpJA+/KUXhHg6
|
||||
wLLW0bJSN3o9oTp+FzRsnGw4aW784scJqRVMRxcEAMK48xzX+J942id0MLCNpu/s
|
||||
rfdXh9aFm9dd2ekHIZUXOqaYopL6C9qEu1hnGcqtxNxJuc5xDS2e8qG9Vsk1PeFl
|
||||
uGssgSAMpwNCN/SU5lPf91WHHUloS7OI/gIQUgcH36PcYcI2D1I/ngeEpsk7TZPM
|
||||
ZuqOCH3H7EY3CKAUH8477p6crJzczQ/H7xwcHPZ5wsHBnTvDw3lbycwN3/n+4ODC
|
||||
q4ORy+cd+eE8yDCTu458XsqcY4oSVMBkPgcpH0aTYBcs5iRxExrNh93VYTiHx+PD
|
||||
TcnlhnPxXhBiCuyOd5SGwbDkumAQ/K41Xnc8WF5cNIxFWCzu53leqZ5nsirHJN59
|
||||
iCYXbZMLJs8bLhX6jtnwqfzp7mW4bBzEiP+i6LqixHpnkUVJdytVOC7F45JhVHNu
|
||||
ni9rFzyLJKLmqubu5ttA35WcRU0+D9R+OeMs37170jFZdbk00UMam6TeGXp4ZFes
|
||||
nMsjBPH1eDyfm3G6ir33E4gItnK5eEvyejXr1NSLvr3mf6cWlUQhkYC/QgHWEiBw
|
||||
PqQ9fjE7hsZsSRSWVX/L4my9cxsus18eHxtLJMaYLH9X1Po7Zo9YXF4ea0p6bCw+
|
||||
UxTPeWNpAAg3dVZc8XhrCRUwN36uiyy2/KpplFX4VqbaFcIjLaoJURxjXybqsNKH
|
||||
gaokEqDAVGy9Yz540SCoZUX647jwQ8H/g7+AC/8PJKcsn+caIq/s+9GS/7i1Cip8
|
||||
q4I1HnbUFn+HS6KrFPxqQS0oCt/bFoGXKgUVTKjHqqqiX23xynf+CwZBlqZ5RR1j
|
||||
ONsfNcfz1fNcJujmpw9F8F40iiKO6zzfavE2Wq2CDE2cMTYOFQL+ZFDjQbReQGd4
|
||||
PgdHZVAbAzU5AambUS8cBF3Xc+nx9Dh+QdJuXXdXz1PtNLCgL47bglk8dLtXc+1m
|
||||
v1Ufgrrpdg8bceweFrHNM0H6QKiabjOPKobdMjpAqSxe+N1mR61SqdUqJzWQE7as
|
||||
6K7zgBBUKjVmDFYnTcMOpe3o4ePWjVa3A2S3An+4cFRMReqt7mqWNysVplbZhQ9u
|
||||
5mIX7Qmqy1BgYDCtoPBsqUjV4HlAEGOS0hKet+1K2XbpzQ61qnvVMNbgUzYMo1w2
|
||||
JKkcc/WWsV+bwcNdsmbMaBfdJnhELVMsFjOZTDHDlvgjeK6rwDihyMwwi0VmU+sM
|
||||
AFpDZ48qBmU5CH9MgrAlqp7+3rZ5EA7jB76i/6J7B7wQfD3wZX8ee8c5xWMb8dgG
|
||||
PZ5um3sb5N8sl+CB7OzmJQFhW6CKbnZ2U+qzqzMlxOsR2rvZchKmryNdNhxmtF11
|
||||
ff/BIFCn5vYKJCCQaAVyKkcILS7B/uTkJBHICEnSIBFGYcPOPXUSjsacpVFCdKrX
|
||||
3BZRqENNUtNHv5zRsXdZQNCitGa6a5Ye8Eo1pOdEIx676CkRVMGxQkIB96RJ9IiO
|
||||
nRbNOkOEun1MY8R0R8FjvBkv/PgKVsulAYGSMnXr1pJS9gb5CHi1gx2doT5BQRDc
|
||||
ZIVWFBeJSQGDgTCDILjZmSUAIUj1edn3dSA0LgsIJqWxIlUoNUZ84Pky1PrsNtSG
|
||||
DJFKAb9ABKpnKM2QIqUaA4EE6IqEjUiEJnf5JFkSRuUoOs6XU90a65eud/D+7Ulo
|
||||
1K+6SFJ/6Lk8IHg/0cUFBu302d1mkDvH/Gp243KAYBkVYhGjpApkhVQwR3wJK7+0
|
||||
QpYssqKYRHFQaB+IanAe7D1MDZRKFZkatAxNg2NELJe+Ng3dd1v/rb2DGVIE12iV
|
||||
eiejRFirQRFnoeQVqkeyPhFaTL8gQasn0Qx1ey3Ivy80yY06RzI0S3VoSd0+FQ5+
|
||||
ZRr2wpelizRNIRYhmpeGoDeETlJYgmERv0ImvaMwCEgWwe8Ni1AYRgWUEtaNbCg6
|
||||
Img4kIgESSwEjvC1IGzOqvbcqCXv2lt+z4Ablv3iuZC7zXSEzggijApgTFimSxHi
|
||||
otuQJ2WFCCvgByQk0ijkN7SdDZEADyD4RqjkrcGhAICgkSzlaejsMYIoiyKb/Yls
|
||||
i90/7Dr8poGZW+g/b4uovXNpdX+A/a1zTfXbIFhJEiFWNBYiZpCRmZO4lHXCBxQp
|
||||
SkrqUiRCuKhTq3i4KjQCAYePWD5eKUHWLUiozw0nn4nBuJbJaAuZhQx+2V+m+1GB
|
||||
Gma3S7Y8pCBrONNGomNQfE/I+0Jv9sQHP5AtFYyBEnw1DdU853ok0KkOXyhfMlHy
|
||||
Z4lYNQxJUpo3VySj+l7svoWK/BfZOFYiv5aQnBfa9vmQOSgkE8c93EGPtkwik0uc
|
||||
VVqyaZYjAqWjBU2+ABD+UlGrW2aJs1i6Q01mZGGsm3sozzLuoLIEGJQiSOFjDEUh
|
||||
mihke0AoLm9FUKs0GYm0KIYjhfGLAcHim3tC2Ujbr5Py/PSnbayHwx9t31Vjq9Li
|
||||
hyI7D7k4+2Onihim07KUcNtsx+iLFz/ZvLmAlugHoQBT26W2GnK36MWAINEIX6Uc
|
||||
8VGZCu5i1BJIhS5Be6m7ynSFeKMh7C8rpESz2aWoANVBwt205cx7JDy7sRc+/iMc
|
||||
Xr9W72F3iVKhxuihkSard0QQlNMgXAvPhqWEI4R8x1C00fgpwKhb3uWx2AAQbCIj
|
||||
qD21jdFrC/KFtAnbEuQfxj4zIWck5i1HqpEYrUXlpRjMpXE+7SEwZnAmVZxA+4K1
|
||||
aUoCLtq6Zz4bPg5vbOxthGc3r4WHwsenuU2ikbA6DEVWxFQf737Yf4wMLyl9EgK1
|
||||
7aivvg46o8jDWOwHYTHhCyEtMhmo16NQFZCzM7ZzMSAsSdRdIYYVBRBmKJmswuho
|
||||
PiqWYJv6KY6ZHSbN+nTLdBMefIEqNc9I+05pfSNM1vfW12fr9fpGYwAIye0k46Ai
|
||||
Ow9BcJ8CgTxEEMasZDIZ3Wu82dxcf7jHCEnx9CAQQO3p3oc3mxuohjS3sQvxhBr1
|
||||
KQ4cJAjKPI04EQQ6CqNCapZXKM4PRj0kMuIlPoGbhg4SR1QC3nFivrCBbUKY/B4O
|
||||
16+Fw7NDjeNwHwjRpM1QDNi0QMEc//FU7hrh8J9jFraHjfr6hrr5Z4Nx3OLp3jbB
|
||||
tZgORKPRp3uN9Q0PMkORrtLH+bx8vYNopJF7yOiXNj2P0vx4D/flYRhZpKDx9reH
|
||||
mxvKh98YHyc+PsATRsDYT3t7HzY33nzYY6Sd8f8IELgmjxFZ26zszIPelwcaStqy
|
||||
tQLr64EmOW0xFev3BG+bFPm0yVvqozu+83xE3jWfJPSCAG0bm9p//k2eSHNdO3X5
|
||||
uR/O8ITR0dPUyNzBqx4QgtAwjjAe40/1+ghlat47qXu9nhBPe9EWWHvYJkXuHHZ7
|
||||
gidrmtPTq9MVaXqad+s8f7/6SHr0aFpf5cvGmoR7p/ndVbUfhPrmtQb5sLlO6jiQ
|
||||
V5Y02c1leTY9LinEsaLAPo9L4edJJSiVVgh1EK5CXJM+nHG/fHxEHj8jTx4fvRwI
|
||||
QoqzCYreNoMtfqMXBFnaOfEylLxPnzaJaSM7A0EYYXrepz95myy31CnOp8hz3Pz8
|
||||
69XXq6u7q6s6vzoNIkm8vgpbPOzc3X3N/fprZ+DeAuF49uFefe9DIzw0O7RORJgZ
|
||||
a6OS7qvC8NgbY5Posq9KV6I4oTbozChPyyHemqaGgC8GiXPPjp7978u5J3NngGAJ
|
||||
p4mR9MaTXlIggHBXaPIYW1qBndT9h71tQgqVuric4DCnQPDIqxYHuZ9eW3vkuH/v
|
||||
3r1Xznuv7r969epeFn7wj9bWpldXX3OlDuWtBcLvs43NjT1oo0k9XCciLVEtSWoj
|
||||
2yXsCpJ4B1XiiMuSSEgJKRxxV6DXDIVgpJDUGAhk7ujo+Rw5yxNOTvMTKU0f/Njn
|
||||
Cam80MNj3N45+OdpQrXHFU/1sh1p4LQnyGuO0vz8CnzmYT1fq813pGbBkRVrxbJ2
|
||||
Xf7+NoGBsDlbDzcaJEaTNAO1npZgpBiK4E0DKtLRAI6tKQwdRygZodYolQI+qkI3
|
||||
+fyIHB0BEHNneUIqlU6l06kuOfhnPwhMDfXSHe0fYRzVxaj2ZOKppgpTZavUwSkQ
|
||||
VFdZ+qhAuyAZsaDnq3sHB8W7DN3yyUcNfqfuqN0d7shJrWIqvZ2aeN+s1KwurXyt
|
||||
4nAoQRxHdd2PDiqOSm24W0DNbXQ3zx5VDmrwaQluaRp+g/aCPdLuont9OQgiCZa/
|
||||
7BTk5q3l+Nx+FuS7fScvlWPZPtqdP+iMGW6FV3I4287lcooxE4sVxaHwqTeq1Eys
|
||||
Kin8cA4UUTcnGTMzzuBF3E8Ad8bVs2cDVEL2yiD8qaASS1+Agiq7lIWFmw8ePMDF
|
||||
gqSJAzgFHlXM5BaXD/FzuLy8bGiiqoJauB4e6gYLjC3OwPFD9l1c/JetdoZUI58N
|
||||
whx59vL9c+jmXpKXzxFvzeMRg34RHzwqREagQ5I1DY1gEB1PDIpagMjg0VqQBOVP
|
||||
3dtSh3O6eReJwnnH3Txs5HLD/cn27y9K7hsdWTQWlx/g7ArG5d3VZrGsLN648T18
|
||||
mBxKi8sfSUE5QgR8zOyFho56PgrC/6pzR3NzR48fzz2fO3pG/NSiQepz00nsIoPQ
|
||||
TBIPHYFZBEzj8Tk9hSl3gPdFHSEOmkyf8XEM3sWme/lXC8pib4L8RanvzLhkjyvf
|
||||
7HXNy6t9aobyMU9QRG434Ao5aTDr+7gnAAhPnhw9noN6MfeEkEkvdpEW9SUBBPak
|
||||
lUTKJcM5SQNUIjUFXCAQEUYtxUs/fWtONBT+QSIhqgkRliJsLPO80cfXrSq8qqoJ
|
||||
f6GAK/hsSYpSttVm20NZTZmOb/kTCdBR/QnU3ZJ4Xj7TD5TQUqTi8KluJ4V29uMg
|
||||
iOAAT46Ons09hnEPkaI61UrEFcCHD0KQgbA0WeKzkZDOBUmWcqPFQC2iR6CDlGHK
|
||||
6fkECLzOHzYpfAvwt8jzfNnTr8Xr44zn+ByZfmPIUGxj1a4QLtg7LA4hi/H5GKpd
|
||||
Gwa1szitfkqzppCM+ETTsEao+6MgfEeePH/58smT5+9exp7B+N+Ixd45CXGio8c8
|
||||
WVJGbl/R73cRA73RWY6RLJkpk4wkymUS+wQIVSiDCrYIbpR8vlJxVLK958iGCQd3
|
||||
dnZuHOwwycFvs2X64WxrxKi7TVNhChsHBzs3mJr7fMTev2MW6c8YNneP8QKn2XY/
|
||||
KVCM8W6zR/jOexbh1t1mQzfNU4oOk6/Klx4Ejxq0iXsZmxjIGHx9TZknmJ2pzpyW
|
||||
bIfHyOZ1iFUx1q+m+S89CC3OXvdyIFZiW5qbXf3/tZYr+LFJVG0Ne62qFx1E4tLK
|
||||
X/jU9j8HhC9+MfW/EoSNKxDIqQnENwvCVZtwBUJ3F/lNgzA0ewUC2WxcgUDq9SsQ
|
||||
SP3hFQjkX1/UJjwnzx//F4JwHP58AN7PPSYqgDD3+BKBIAY1kHFcaMFx9ihgPPil
|
||||
L3TOHn6e3tzc8/b2JQJBHRj/uS8shSfDsNLGM5qG3wWErHOH9pdZe74tD5AOH/B5
|
||||
LyRPLgkI8uLWCmdZVmlyMrLdjKiV7I/HKFa3JF5ncRZrK/jY0KHL77tuvrDJgz9T
|
||||
eE/GZySp9eaq5BTJD+9bd+GO5nqMPnl8SUDQ4qRU4jiuhGEuk3ZAtxGS7QtFaKCa
|
||||
xS2xQJCM36X7u+IxMlcQY4ll1CqVJm0aGBKgYsetF9qffFUC/xYQpC0MoYg0xqdP
|
||||
f7Kz5+0HIYjxGJdKNlTRwOioV1g5FYoQJ9NqVZ0BJQ6sMconRusTjILB3OrZ8wFX
|
||||
fzb3SWj+JhAizRiK9foLO9LigKCUQWmrFY+xyVQVLHFBPD2HClYTixHkfEYiL96+
|
||||
tUOdCnzCYJ4wN/Dyzx7PXQYQMB6jTWNcr7+w+WtCoQ8ETQI1DDa5nWzGpBRKY6dA
|
||||
qM/ONqqJP0N2hMu39Q/NAJd3myAMlqO5T3WVf48nJJClmXzx22+bmw9/22M0k0Eg
|
||||
sHiMdjhGRvGiS6cIir8j5fP+2PA2WAOdt/U3gs2BOkmU/e/mnr0cePXHcyCXAgTo
|
||||
E5J2PMbN9cbZIETbkRZHMXsAQjct7Q8E4d6YEgWg9hpv1pHziUH9qDVmqFDeP5wx
|
||||
eAIQnn0+CJ5PyDvPV71ArzUDLb798GZjY/1Ng5FtBocibIVjbEaCXOohKO6Fw9Vx
|
||||
BRmRjcb65tDQev0t0nasdPkPLO+zGsCXR3OfB4InaL5WeH668maNnzZ1nS8/qj4y
|
||||
Hj2CrbVyeQ0JYKv87u7XBO7Q4uloM8jl5nqIUjso5eIAEAIBXzsSJJKRSqmeUISN
|
||||
sJHKYczMFy/evtn85cWLn9DWStp4Mtep+R55zSivVWOPsrEZfFATe/XqO6fTmYWt
|
||||
bPZeNluNzTxak6oDmCrqo9Kv3Ovd3Qry3pD8Nz29Zk5L06vIe9tF3tvr+Xlu6Wui
|
||||
nIEn+EYZkdFbr4eapLN0f4zWeDpgh1rsxGPsBYH8+SY1HLDJnL/V39h40pNU+air
|
||||
8VN5rvR69/VuydzddczXKq+xAOH7+nWFZxw+E/LC/Sr3c5ZEifu1yXvT1+7fv3fv
|
||||
1b1X+uY9EPhhPgJXgHPnS9WvCF+iDSd8yD2EzL198RNtxWPsbxPSAZuh2GbnWYNC
|
||||
EcabMTPfNj40OXz5nftHnQbBI69y3C6SF9ce7WJGXkFWfrnXzMobdOpVJDL2Ufgw
|
||||
do+jBENbC8ar3AojvdVqnE1+W5nnkPcGK8t0ql9VHXxeoRPn82wQfALjMdKW4kmf
|
||||
J4jVnTgLSdmKyWjHIix3hdL2BHmL2zUBhbW13UeP7qPE7BX8mmYgrO5y3M1+EPyZ
|
||||
KpLb1hjBbY19mmS3bpn5mtfOMFov7REhfae/TUiFGAG8FXHSOzI8IDLnk3iLytnG
|
||||
Kp46NU4QszizYMKegLMPzzaakW1ws6oNoPD55TblTWuy3ewVUuC0JhPuq2K4aHEk
|
||||
HB4cfH8nHo8Px+98f4A/B4FgExM7kuoH4dHB99tNujwKtDQB3/epcne6WGwcV7FY
|
||||
dOECtlwgbGX/tDeC6oAu0uO3n/eqamvdJa1dX/X4Vxs+SKXsb5PImTo4SA0AIY6h
|
||||
Fu/Y4d4ALvglxQcFpYxjrMYcI4KxM1KnPYH4VVFuvYDZeg+zvaO1T/3EYAkagwud
|
||||
Ss9MrzoOHzy4gTQUWNwYr7hXpb7WRXSV1/hrhcIPhcRxoaBuZaclo9obblLMKnk3
|
||||
EkNZTDtc3HXnc8POM0tH5+x32TPzXzhipNokBTiRR+An6rlf7PcHi1kjXztZbEal
|
||||
zLvLTlemj1ziUWVt5m5H8k5NlvspnzOG5EiMjeG9lCFYisq0YWTPZqpElBkKXk7K
|
||||
S2dnZCAIAjKYhckSH1F925P03P8Myy/KMXWLbLWEVMVB9Et1IWvcOFw+vHHjxvLy
|
||||
jcP4zP6Adz7BVlFy381hhcD4pTmlKH8s3FRkxQoQ6vOWqY/OfDEIk9Sn0SWN+gTx
|
||||
vBgUWWTWpmCMVqjI/dxHv5R7wPJ/eDizzHiaTxRFHeAvP/KFBIuaiVKIu+SPddsR
|
||||
KUaNChFik0Swvqg6lJI+frsyaoQooVnunP9MhIi61OeJBt9XeLLOxz0FP0Zb9B9j
|
||||
XEai9BMUPaL7zuIvdgA+Ow7fncXD/PLZVTYyWaKioAtl6qbKl4BgSFBOSlXKEIn4
|
||||
eem8tSHoVpSEmFCRxwllpyYSfqUTj7Gjlud5qRmu8Pn40OB4jKoT0vNDoQAoed7D
|
||||
Ej5EGuAwbclKkkZivEeOKeK/dSoNuePt3OHi2tBQjtdzff4V5E3TzG20qM07jKg3
|
||||
ICilkgMYAc2xhIhxLhM4EDpfLMK/A4RgzmE6zHyO9e05+GDYRbOvXJDIqJ8SXprp
|
||||
eyuiCjo5xHLHZsju5NyrunH5QWDDWGV6WlLYC1mM0bnWF2kRJj7O7CmJZYt97zGI
|
||||
MdOBsSgrjoq9cDgqDnPm8oOAw1gMG5HJdFZB8YxAISq2i2yE6setvi5EY1McycAl
|
||||
LiRjrftNnksLArHjOzZvXJHzBUBRm1McFr2yuSVeePDqb1CuQLgC4QqEKxCuQLgC
|
||||
4QqEKxA+AsKV/GPoyhEIuQLhCoRPgcBdJ+RW39vFUxxK5/fEbULcnItMdCLBOyb6
|
||||
jcWmmL2uo82fvWJyE5+TbLBn31+Y4s74j22xibMucX4QINt696/rnEisqQliTnwK
|
||||
hKbsfhyEz054r92PJ/OcIJgcZxKrXOUmRBt0sH79NgcFxk1hTM7bLpcFbmC5YlPc
|
||||
VAx3ViZuTbkmOO62OFHBE9ygzDwBNG5fd+BRNH+bm7ougqFbxDHFldkGAMhxtnHY
|
||||
F4OfoPQzx7na+1p6aA+ud52Dv1ZiUFkHZTQ6EYM/dsWpWMyyOMfXgoDiuDV1/frU
|
||||
LfNnnjNv3W5BrDtIjLvOUkN+npgwXZZrhYA7TEDSIE+3retkql0Q1anrLq6MINwG
|
||||
h/mZHUXzE6Qy8bNJXFPirk54N24w6G3jFXa+wyQOKIef7X0Ondgn2CAAKghuOzGg
|
||||
XHEQNx8rk6qFyeSuszTFABcrdh5PQK/SJ27ddjgsk2+B4IDsg22WmaoJ7m/pJupf
|
||||
53DJCvGWxU25On7JPIGdsMuKmJnXJxwIdAzM2Rtsd4UZdzCEYalPEF3fbe1r6dlt
|
||||
jI4gtBPTUr6ugyvYILA0YZWZOhcIzBOgJlgxO5EdT3DZIIgW1BI3FAuibjEQJnjm
|
||||
M7ft2l8GC9ZE0xN0d+soywOvExdLvb3R8QSXDUKlma/2vp+bel0gtBPTAsFtkgmu
|
||||
4wnWuUHYReyh4b9t4ZecbhPsNuw25GkCgIhZrE24Dl4uWrfgtNvXJ1hV1Fttggtr
|
||||
MTvaAgGrryVC6u0NtrtZ/095QntfS68LhHZiWsq3OM7NibdYm7CCbQIDYcJxNU64
|
||||
GixdgXAFwhUIny3/L8AAEAy9MIp/F7YAAAAASUVORK5CYII="
|
||||
alt="How Tor works"
|
||||
style="border-style: none"
|
||||
/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Tor sees use by
|
||||
<a href="https://www.torproject.org/about/torusers"
|
||||
>many important segments of the population</a
|
||||
>, including whistle blowers, journalists, Chinese dissidents skirting the
|
||||
Great Firewall and oppressive censorship, abuse victims, stalker targets,
|
||||
the US military, and law enforcement, just to name a few. While Tor is not
|
||||
designed for malicious computer users, it is true that they can use the
|
||||
network for malicious ends. In reality however, the actual amount of
|
||||
<a href="https://www.torproject.org/docs/faq-abuse">abuse</a> is quite
|
||||
low. This is largely because criminals and hackers have significantly
|
||||
better access to privacy and anonymity than do the regular users whom they
|
||||
prey upon. Criminals can and do
|
||||
<a
|
||||
href="http://voices.washingtonpost.com/securityfix/2008/08/web_fraud_20_tools.html"
|
||||
>build, sell, and trade</a
|
||||
>
|
||||
far larger and
|
||||
<a
|
||||
href="http://voices.washingtonpost.com/securityfix/2008/08/web_fraud_20_distributing_your.html"
|
||||
>more powerful networks</a
|
||||
>
|
||||
than Tor on a daily basis. Thus, in the mind of this operator, the social
|
||||
need for easily accessible censorship-resistant private, anonymous
|
||||
communication trumps the risk of unskilled bad actors, who are almost
|
||||
always more easily uncovered by traditional police work than by extensive
|
||||
monitoring and surveillance anyway.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
In terms of applicable law, the best way to understand Tor is to consider
|
||||
it a network of routers operating as common carriers, much like the
|
||||
Internet backbone. However, unlike the Internet backbone routers, Tor
|
||||
routers explicitly do not contain identifiable routing information about
|
||||
the source of a packet, and no single Tor node can determine both the
|
||||
origin and destination of a given transmission.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
As such, there is little the operator of this router can do to help you
|
||||
track the connection further. This router maintains no logs of any of the
|
||||
Tor traffic, so there is little that can be done to trace either
|
||||
legitimate or illegitimate traffic (or to filter one from the other).
|
||||
Attempts to seize this router will accomplish nothing.
|
||||
</p>
|
||||
|
||||
<!-- FIXME: US-Only section. Remove if you are a non-US operator -->
|
||||
|
||||
<p>
|
||||
Furthermore, this machine also serves as a carrier of email, which means
|
||||
that its contents are further protected under the ECPA.
|
||||
<a href="https://www.law.cornell.edu/uscode/text/18/2707">18 USC 2707</a>
|
||||
explicitly allows for civil remedies ($1000/account
|
||||
<i><b>plus</b></i> legal fees) in the event of a seizure executed without
|
||||
good faith or probable cause (it should be clear at this point that
|
||||
traffic with an originating IP address of FIXME_DNS_NAME should not
|
||||
constitute probable cause to seize the machine). Similar considerations
|
||||
exist for 1st amendment content on this machine.
|
||||
</p>
|
||||
|
||||
<!-- FIXME: May or may not be US-only. Some non-US tor nodes have in
|
||||
fact reported DMCA harassment... -->
|
||||
|
||||
<p>
|
||||
If you are a representative of a company who feels that this router is
|
||||
being used to violate the DMCA, please be aware that this machine does not
|
||||
host or contain any illegal content. Also be aware that network
|
||||
infrastructure maintainers are not liable for the type of content that
|
||||
passes over their equipment, in accordance with
|
||||
<a href="https://www.law.cornell.edu/uscode/text/17/512"
|
||||
>DMCA "safe harbor" provisions</a
|
||||
>. In other words, you will have just as much luck sending a takedown
|
||||
notice to the Internet backbone providers. Please consult
|
||||
<a href="https://www.torproject.org/eff/tor-dmca-response"
|
||||
>EFF's prepared response</a
|
||||
>
|
||||
for more information on this matter.
|
||||
</p>
|
||||
|
||||
<p>For more information, please consult the following documentation:</p>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
<a href="https://www.torproject.org/about/overview">Tor Overview</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://www.torproject.org/docs/faq-abuse">Tor Abuse FAQ</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://www.torproject.org/eff/tor-legal-faq">Tor Legal FAQ</a>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
That being said, if you still have a complaint about the router, you may
|
||||
email the <a href="mailto:FIXME_YOUR_EMAIL_ADDRESS">maintainer</a>. If
|
||||
complaints are related to a particular service that is being abused, I
|
||||
will consider removing that service from my exit policy, which would
|
||||
prevent my router from allowing that traffic to exit through it. I can
|
||||
only do this on an IP+destination port basis, however. Common P2P ports
|
||||
are already blocked.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You also have the option of blocking this IP address and others on the Tor
|
||||
network if you so desire. The Tor project provides a
|
||||
<a href="https://check.torproject.org/cgi-bin/TorBulkExitList.py"
|
||||
>web service</a
|
||||
>
|
||||
to fetch a list of all IP addresses of Tor exit nodes that allow exiting
|
||||
to a specified IP:port combination, and an official
|
||||
<a href="https://www.torproject.org/tordnsel/dist/">DNSRBL</a> is also
|
||||
available to determine if a given IP address is actually a Tor exit
|
||||
server. Please be considerate when using these options. It would be
|
||||
unfortunate to deny all Tor users access to your site indefinitely simply
|
||||
because of a few bad apples.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user