Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

Привет, посмотри bash скрипт, пожалуйста

  1. User

    Привет, посмотри bash скрипт, пожалуйста

  2. Assistant

    К сожалению, в вашем сообщении отсутствует ссылка на bash скрипт, который вы хотите показать. Пожалуйста, пришлите скрипт, и я с радостью его посмотрю.

  3. User

    #!/bin/bash set -Eeo pipefail

    shellcheck disable=2154

    trap 's=?;echo"?; echo "0: Error on line "LINENO":LINENO": BASH_COMMAND"; exit $s' ERR

    reArgsMaybe="^[^:[:space:]]+:.*" # Smallest indication of attempt to use argument reArgSkip='^([[:blank:]]*#.*|[[:blank:]]*)' # comment or empty line

    Paths

    userConfPath="/etc/sftp/users.conf" userConfPathLegacy="/etc/sftp-users.conf" userConfFinalPath="/var/run/sftp/users.conf"

    function log() { echo "[0]0] *" >&2 }

    Allow running other programs, e.g. bash

    if [[ -z "1"∣∣"1" || "1" =~ $reArgsMaybe ]]; then startSshd=true else startSshd=false fi

    Backward compatibility with legacy config path

    if [ ! -f "userConfPath" ] && [ -f "userConfPathLegacy" ]; then mkdir -p "(dirname(dirname userConfPath)" ln -s "userConfPathLegacy""userConfPathLegacy" "userConfPath" fi

    Create users only on first run

    if [ ! -f "userConfFinalPath"];thenmkdir−p"userConfFinalPath" ]; then mkdir -p "(dirname $userConfFinalPath)"

    if [ -f "$userConfPath" ]; then
        # Append mounted config to final config
        grep -v -E "$reArgSkip" <"$userConfPath" >"$userConfFinalPath"
    fi
    
    if $startSshd; then
        # Append users from arguments to final config
        for user in "$@"; do
            echo "$user" >>"$userConfFinalPath"
        done
    fi
    
    if [ -n "$SFTP_USERS" ]; then
        # Append users from environment variable to final config
        IFS=" " read -r -a usersFromEnv <<<"$SFTP_USERS"
        for user in "${usersFromEnv[@]}"; do
            echo "$user" >>"$userConfFinalPath"
        done
    fi
    
    # Check that we have users in config
    if [ -f "$userConfFinalPath" ] && [ "$(wc -l <"$userConfFinalPath")" -gt 0 ]; then
        # Import users from final conf file
        while IFS= read -r user || [[ -n "$user" ]]; do
            create-sftp-user "$user"
            uname=$(echo "$user" | cut -f 1 -d ":")
            mkdir -p /home/"$uname"/dev
            chmod 755 /home/"$uname"/dev
            /etc/init.d/rsyslog start
            ln -f /home/sftp.log.socket /home/"$uname"/dev/log
            touch /var/log/sftp.log
        done <"$userConfFinalPath"
    elif $startSshd; then
        log "FATAL: No users provided!"
        exit 3
    fi
    
    # Generate unique ssh keys for this container, if needed
    if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
        ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
    fi
    if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
        ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ''
    fi
    
    # Restrict access from other users
    chmod 600 /etc/ssh/ssh_host_ed25519_key || true
    chmod 600 /etc/ssh/ssh_host_rsa_key || true
    

    fi

    Source custom scripts, if any

    if [ -d /etc/sftp.d ]; then for f in /etc/sftp.d/*; do if [ -x "f"];thenlog"Runningf" ]; then log "Running f ..." felselog"Couldnotrunf else log "Could not run f, because it's missing execute permission (+x)." fi done unset f fi

    exec /usr/bin/supervisord

  4. Assistant

    Этот скрипт отвечает за создание пользователей SFTP и генерацию ключей для SSH доступа. Здесь также разрешается запуск других программ и существует обратная совместимость для старых путей конфигурации. Настройки пользователей берутся из файла users.conf, а также передаются через переменную окружения SFTP_USERS. В случае отсутствия пользователей производится запись в лог и выход. Кроме того, скрипт запускает супервизор для определения действий, которые должны быть запущены в контейнере SFTP.