diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index 27bb46f..1a8ff08 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -21,7 +21,8 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # 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:-}" +[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || true +{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail # - - - - - - - - - - - - - - - - - - - - - - - - - __remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g'; } # - - - - - - - - - - - - - - - - - - - - - - - - - @@ -633,7 +634,9 @@ __create_service_user() { local random_id="$(__generate_random_uids)" local create_home_dir="${create_home_dir:-/home/$create_user}" grep -shq "^$create_user:" "/etc/passwd" && grep -shq "^$create_group:" "/etc/group" && return - [ "$create_user" = "root" ] && [ "$create_group" = "root" ] && return 0 + if [ "$create_user" = "root" ] && [ "$create_group" = "root" ]; then + return 0 + fi if [ "$RUNAS_USER" != "root" ] && [ "$RUNAS_USER" != "" ]; then create_user="$RUNAS_USER" create_group="$RUNAS_USER" @@ -652,17 +655,17 @@ __create_service_user() { break fi done - if ! __check_for_group "$create_group"; then + if [ -n "$create_group" ] && ! __check_for_group "$create_group"; then echo "creating system group $create_group" - groupadd --force --system -g $create_gid $create_group 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null + groupadd --force --system -g $create_gid $create_group 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null + grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1)) fi - if ! __check_for_user "$create_user"; then + if [ -n "$create_user" ] && ! __check_for_user "$create_user"; then echo "creating system user $create_user" - useradd --system -u $create_uid -g $create_group -c "Account for $create_user" -d "$create_home_dir" -s /bin/false $create_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null + useradd --system --uid $create_uid --gid $create_group --comment "Account for $create_user" --home-dir "$create_home_dir" --shell /bin/false $create_user 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null + grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitStatus + 1)) fi - grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1)) - grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitCode + 1)) - if [ $exitStatus -eq 0 ]; then + if [ $exitStatus -eq 0 ] && [ -n "$create_group" ] && [ -n "$create_user" ]; then export WORK_DIR="${create_home_dir:-}" if [ -n "$WORK_DIR" ]; then [ -d "$WORK_DIR" ] || mkdir -p "$WORK_DIR" @@ -673,6 +676,7 @@ __create_service_user() { elif [ -f "/etc/sudoers" ] && ! grep -qs "$create_user" "/etc/sudoers"; then echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers" fi + exitStatus=0 export SERVICE_UID="$create_uid" export SERVICE_GID="$create_gid" export SERVICE_USER="$create_user" diff --git a/rootfs/usr/local/etc/docker/init.d/01-tor-bridge.sh b/rootfs/usr/local/etc/docker/init.d/01-tor-bridge.sh index 664143d..3e5fbec 100755 --- a/rootfs/usr/local/etc/docker/init.d/01-tor-bridge.sh +++ b/rootfs/usr/local/etc/docker/init.d/01-tor-bridge.sh @@ -194,7 +194,7 @@ 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)" +RANDOM_NICK="$(head -n50 '/dev/random' | tr -dc 'a-zA-Z' | tr -d '[:space:]\042\047\134' | fold -w "18" | sed 's| ||g' | head -n 1)" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Custom commands to run before copying to /config __run_precopy() { diff --git a/rootfs/usr/local/etc/docker/init.d/02-tor-relay.sh b/rootfs/usr/local/etc/docker/init.d/02-tor-relay.sh index 2a31f00..0b680d8 100755 --- a/rootfs/usr/local/etc/docker/init.d/02-tor-relay.sh +++ b/rootfs/usr/local/etc/docker/init.d/02-tor-relay.sh @@ -194,7 +194,7 @@ 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)" +RANDOM_NICK="$(head -n50 '/dev/random' | tr -dc 'a-zA-Z' | tr -d '[:space:]\042\047\134' | fold -w "18" | sed 's| ||g' | head -n 1)" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Custom commands to run before copying to /config __run_precopy() {