From d5a21b1d57ddaeb9912bb6cf9199e53cd45b0406 Mon Sep 17 00:00:00 2001 From: casjay Date: Tue, 16 Sep 2025 09:10:39 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Committing=20everything?= =?UTF-8?q?=20that=20changed=20=F0=9F=97=83=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rootfs/usr/local/etc/docker/functions/entrypoint.sh --- .../local/etc/docker/functions/entrypoint.sh | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index 42869b8..70743be 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -39,35 +39,35 @@ __printf_space() { } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __rm() { [ -n "$1" ] && [ -e "$1" ] && rm -Rf "${1:?}"; } -__grep_test() { grep -sh "$1" "$2" | grep -qwF "${3:-$1}" || return 1; } +__grep_test() { grep -ash "$1" "$2" | grep -aqwF "${3:-$1}" || return 1; } __netstat() { [ -f "$(type -P netstat)" ] && netstat "$@" || return 10; } __cd() { { [ -d "$1" ] || mkdir -p "$1"; } && builtin cd "$1" || return 1; } -__is_in_file() { [ -e "$2" ] && grep -Rsq "$1" "$2" && return 0 || return 1; } +__is_in_file() { [ -e "$2" ] && grep -Rsaq "$1" "$2" && return 0 || return 1; } __curl() { curl -q -sfI --max-time 3 -k -o /dev/null "$@" &>/dev/null || return 10; } -__find() { find "$1" -mindepth 1 -type ${2:-f,d} 2>/dev/null | grep '^' || return 10; } +__find() { find "$1" -mindepth 1 -type ${2:-f,d} 2>/dev/null | grep -a '^' || return 10; } __pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -o "$1$" &>/dev/null || return 10; } __file_exists_with_content() { [ -n "$1" ] && [ -f "$1" ] && [ -s "$1" ] && return 0 || return 2; } __sed() { sed -i 's|'$1'|'$2'|g' "$3" &>/dev/null || sed -i "s|$1|$2|g" "$3" &>/dev/null || return 1; } -__pgrep() { __pcheck "${1:-SERVICE_NAME}" || __ps "${1:-$SERVICE_NAME}" | grep -qv ' grep' || return 10; } -__ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | sed 's|:||g' | grep -Fw " ${1:-$SERVICE_NAME}$" || return 10; } +__pgrep() { __pcheck "${1:-SERVICE_NAME}" || __ps "${1:-$SERVICE_NAME}" | grep -aqv ' grep' || return 10; } +__ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | sed 's|:||g' | grep -aFw " ${1:-$SERVICE_NAME}$" || return 10; } __is_dir_empty() { if [ -n "$1" ]; then [ "$(ls -A "$1" 2>/dev/null | wc -l)" -eq 0 ] && return 0 || return 1; else return 1; fi; } -__get_ip6() { ip a 2>/dev/null | grep -w 'inet6' | awk '{print $2}' | grep -vE '^::1|^fe' | sed 's|/.*||g' | head -n1 | grep '^' || echo ''; } -__get_ip4() { ip a 2>/dev/null | grep -w 'inet' | awk '{print $2}' | grep -vE '^127.0.0' | sed 's|/.*||g' | head -n1 | grep '^' || echo '127.0.0.1'; } -__find_file_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '^' || false; } -__find_directory_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '^' || false; } +__get_ip6() { ip a 2>/dev/null | grep -aw 'inet6' | awk '{print $2}' | grep -avE '^::1|^fe' | sed 's|/.*||g' | head -n1 | grep -a '^' || echo ''; } +__get_ip4() { ip a 2>/dev/null | grep -aw 'inet' | awk '{print $2}' | grep -avE '^127.0.0' | sed 's|/.*||g' | head -n1 | grep -a '^' || echo '127.0.0.1'; } +__find_file_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -av '^$' | grep -a '^' || false; } +__find_directory_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -av '^$' | grep -a '^' || false; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__pid_exists() { ps -ax --no-header | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep '[0-9]' | sort -uV | grep "^$1$" && return 0 || return 1; } -__is_running() { ps -eo args --no-header | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -vE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep -q "${2:-^}" && return 0 || return 1; } -__get_pid() { ps -ax --no-header | sed 's/^[[:space:]]*//g;s|;||g;s|:||g' | awk '{print $1,$5}' | sed 's|:||g' | grep "$1$" | grep -v 'grep' | awk -F' ' '{print $1}' | grep '[0-9]' | sort -uV | head -n1 | grep '^' && return 0 || return 1; } +__pid_exists() { ps -ax --no-header | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep -a '[0-9]' | sort -uV | grep -a "^$1$" && return 0 || return 1; } +__is_running() { ps -eo args --no-header | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -avE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep -aq "${2:-^}" && return 0 || return 1; } +__get_pid() { ps -ax --no-header | sed 's/^[[:space:]]*//g;s|;||g;s|:||g' | awk '{print $1,$5}' | sed 's|:||g' | grep "$1$" | grep -av 'grep' | awk -F' ' '{print $1}' | grep -a '[0-9]' | sort -uV | head -n1 | grep -a '^' && return 0 || return 1; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '^' || return 3; } +__format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -av '^$' | tr '\n' ' ' | __clean_variables | grep -a '^' || return 3; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __clean_variables() { local var="$*" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters var="$(printf '%s\n' "$var" | sed 's/\( \)*/␁/g;s|^ ||g')" - printf '%s' "$var" | grep -v '^$' + printf '%s' "$var" | grep -av '^$' } # Auto-detect services from init.d scripts @@ -179,21 +179,21 @@ __trim() { var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters var="$(echo "$var" | __remove_extra_spaces | sed "s| |; |g;s|;$| |g" | __remove_extra_spaces)" - printf '%s' "$var" | sed 's|;||g' | grep -v '^$' + printf '%s' "$var" | sed 's|;||g' | grep -av '^$' } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __banner() { printf '# - - - %-60s - - - #\n' "$*"; } -__find_php_bin() { find -L '/usr'/*bin -maxdepth 4 -name 'php-fpm*' 2>/dev/null | head -n1 | grep '^' || echo ''; } -__find_php_ini() { find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1 | sed 's|/php.ini||g' | grep '^' || echo ''; } +__find_php_bin() { find -L '/usr'/*bin -maxdepth 4 -name 'php-fpm*' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } +__find_php_ini() { find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1 | sed 's|/php.ini||g' | grep -a '^' || echo ''; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__find_nginx_conf() { find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1 | grep '^' || echo ''; } -__find_caddy_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1 | grep '^' || echo ''; } -__find_lighttpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1 | grep '^' || echo ''; } -__find_cherokee_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1 | grep '^' || echo ''; } -__find_httpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'httpd.conf' -o -iname 'apache2.conf' 2>/dev/null | head -n1 | grep '^' || echo ''; } +__find_nginx_conf() { find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } +__find_caddy_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } +__find_lighttpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } +__find_cherokee_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } +__find_httpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'httpd.conf' -o -iname 'apache2.conf' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__find_mysql_conf() { find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1 | grep '^' || echo ''; } -__find_pgsql_conf() { find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1 | grep '^' || echo ''; } +__find_mysql_conf() { find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } +__find_pgsql_conf() { find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1 | grep -a '^' || echo ''; } __find_couchdb_conf() { return; } __find_mongodb_conf() { return; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -582,7 +582,7 @@ __file_copy() { __generate_random_uids() { local set_random_uid="$(seq 3000 5000 | sort -R | head -n 1)" while :; do - if grep -shq "x:.*:$set_random_uid:" "/etc/group" && ! grep -shq "x:$set_random_uid:.*:" "/etc/passwd"; then + if grep -ashq "x:.*:$set_random_uid:" "/etc/group" && ! grep -ashq "x:$set_random_uid:.*:" "/etc/passwd"; then set_random_uid=$((set_random_uid + 1)) else echo "$set_random_uid" @@ -630,7 +630,7 @@ __fix_permissions() { change_group="${2:-${SERVICE_GROUP:-$change_user}}" [ -n "$RUNAS_USER" ] && [ "$RUNAS_USER" != "root" ] && change_user="$RUNAS_USER" && change_group="$change_user" if [ -n "$change_user" ]; then - if grep -shq "^$change_user:" "/etc/passwd"; then + if grep -ashq "^$change_user:" "/etc/passwd"; then for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do if [ -n "$permissions" ] && [ -e "$permissions" ]; then (chown -Rf $change_user "$permissions" && echo "changed ownership on $permissions to user:$change_user") 2>/dev/stderr | tee -p -a "/data/logs/init.txt" @@ -639,7 +639,7 @@ __fix_permissions() { fi fi if [ -n "$change_group" ]; then - if grep -shq "^$change_group:" "/etc/group"; then + if grep -ashq "^$change_group:" "/etc/group"; then for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do if [ -n "$permissions" ] && [ -e "$permissions" ]; then (chgrp -Rf $change_group "$permissions" && echo "changed group ownership on $permissions to group $change_group") 2>/dev/stderr | tee -p -a "/data/logs/init.txt" @@ -649,12 +649,12 @@ __fix_permissions() { fi } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__get_gid() { grep "^$1:" /etc/group | awk -F ':' '{print $3}' || false; } -__get_uid() { grep "^$1:" /etc/passwd | awk -F ':' '{print $3}' || false; } -__check_for_uid() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; } -__check_for_guid() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; } -__check_for_user() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; } -__check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; } +__get_gid() { grep -a "^$1:" /etc/group | awk -F ':' '{print $3}' || false; } +__get_uid() { grep -a "^$1:" /etc/passwd | awk -F ':' '{print $3}' || false; } +__check_for_uid() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -aq "^$1$" || false; } +__check_for_guid() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -aq "^$1$" || false; } +__check_for_user() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -aq "^$1$" || false; } +__check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -aq "^$1$" || false; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # check if process is already running __proc_check() { @@ -678,9 +678,9 @@ __set_user_group_id() { local random_id="$(__generate_random_uids)" set_uid="$(__get_uid "$set_user" || echo "$set_uid")" set_gid="$(__get_gid "$set_user" || echo "$set_gid")" - grep -shq "^$create_user:" "/etc/passwd" "/etc/group" || return 0 + grep -ashq "^$create_user:" "/etc/passwd" "/etc/group" || return 0 [ -n "$set_user" ] && [ "$set_user" != "root" ] || return - if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then + if grep -ashq "^$set_user:" "/etc/passwd" "/etc/group"; then if __check_for_guid "$set_gid"; then groupmod -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null && chown -Rf ":$set_gid" fi @@ -701,7 +701,7 @@ __create_service_user() { local create_gid="${5:-${SERVICE_GID:-$USER_GID}}" 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 + grep -ashq "^$create_user:" "/etc/passwd" && grep -ashq "^$create_group:" "/etc/group" && return [ "$create_user" = "root" ] && [ "$create_group" = "root" ] && return 0 if [ "$RUNAS_USER" != "root" ] && [ "$RUNAS_USER" != "" ]; then create_user="$RUNAS_USER" @@ -729,8 +729,8 @@ __create_service_user() { 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 fi - grep -shq "$create_group" "/etc/group" || exitStatus=$((exitCode + 1)) - grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitCode + 1)) + grep -ashq "$create_group" "/etc/group" || exitStatus=$((exitCode + 1)) + grep -ashq "$create_user" "/etc/passwd" || exitStatus=$((exitCode + 1)) if [ $exitStatus -eq 0 ]; then export WORK_DIR="${create_home_dir:-}" if [ -n "$WORK_DIR" ]; then @@ -739,7 +739,7 @@ __create_service_user() { fi if [ -d "/etc/sudoers.d" ] && [ ! -f "/etc/sudoers.d/$create_user" ]; then echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers.d/$create_user" - elif [ -f "/etc/sudoers" ] && grep -qs "$create_user" "/etc/sudoers"; then + elif [ -f "/etc/sudoers" ] && grep -aqs "$create_user" "/etc/sudoers"; then echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers" fi export SERVICE_UID="$create_uid" @@ -783,7 +783,7 @@ __exec_command() { local cmdExec="${arg:-}" local pre_exec="--login -c" local shell="$(type -P bash 2>/dev/null || type -P dash 2>/dev/null || type -P ash 2>/dev/null || type -P sh 2>/dev/null)" - bin="$(echo "${arg[*]}" | tr ' ' '\n' | grep -v '^$' | head -n1 | sed 's| ||g' || echo 'bash')" + bin="$(echo "${arg[*]}" | tr ' ' '\n' | grep -av '^$' | head -n1 | sed 's| ||g' || echo 'bash')" prog="$(type -P "$bin" 2>/dev/null || echo "$bin")" if type -t $bin >/dev/null 2>&1; then echo "${exec_message:-Executing command: $cmdExec}" @@ -811,7 +811,7 @@ __setup_mta() { local local_hostname="${FULL_DOMAIN_NAME:-}" local account_user="${SERVER_ADMIN//@*/}" local account_domain="${EMAIL_DOMAIN//*@/}" - echo "$EMAIL_RELAY" | grep '[0-9][0-9]' || relay_port="465" + echo "$EMAIL_RELAY" | grep -a '[0-9][0-9]' || relay_port="465" # sSMTP relay setup and postfix setup would continue here... # Simplified for length return $exitCode @@ -896,8 +896,8 @@ __initialize_system_etc() { local file=() local directories="" if [ -n "$conf_dir" ] && [ -e "$conf_dir" ]; then - files="$(find "$conf_dir"/* -not -path '*/env/*' -type f 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -v '^$' | grep '^' || false)" - directories="$(find "$conf_dir"/* -not -path '*/env/*' -type d 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -v '^$' | grep '^' || false)" + files="$(find "$conf_dir"/* -not -path '*/env/*' -type f 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -av '^$' | grep -a '^' || false)" + directories="$(find "$conf_dir"/* -not -path '*/env/*' -type d 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -av '^$' | grep -a '^' || false)" echo "Copying config files to system: $conf_dir > /etc/${conf_dir//\/config\//}" if [ -n "$directories" ]; then for d in $directories; do @@ -1017,7 +1017,7 @@ __initialize_www_root() { __is_htdocs_mounted() { WWW_ROOT_DIR="${WWW_ROOT_DIR:-/data/htdocs}" [ -n "$ENV_WWW_ROOT_DIR" ] && WWW_ROOT_DIR="$ENV_WWW_ROOT_DIR" - [ -n "$IMPORT_FROM_GIT" ] && echo "$IMPORT_FROM_GIT" | grep -qE 'https://|http://|git://|ssh://' || unset IMPORT_FROM_GIT + [ -n "$IMPORT_FROM_GIT" ] && echo "$IMPORT_FROM_GIT" | grep -aqE 'https://|http://|git://|ssh://' || unset IMPORT_FROM_GIT if [ -n "$IMPORT_FROM_GIT" ] && [ "$(command -v "git" 2>/dev/null)" ]; then if __is_dir_empty "$WWW_ROOT_DIR"; then echo "Importing project from $IMPORT_FROM_GIT to $WWW_ROOT_DIR"