2023-09-10 17:52:45 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-09-16 19:23:29 +02:00
|
|
|
set -e
|
|
|
|
|
2023-09-10 17:52:45 +02:00
|
|
|
SSH_DIR="/home/borgwarehouse/.ssh"
|
|
|
|
AUTHORIZED_KEYS_FILE="$SSH_DIR/authorized_keys"
|
|
|
|
REPOS_DIR="/home/borgwarehouse/repos"
|
|
|
|
|
2023-09-17 11:21:22 +02:00
|
|
|
init_ssh_server() {
|
|
|
|
if [ -z "$(ls -A /etc/ssh)" ]; then
|
|
|
|
echo "/etc/ssh is empty, generating SSH host keys..."
|
|
|
|
ssh-keygen -A
|
|
|
|
cp /home/borgwarehouse/sshd_config /home/borgwarehouse/moduli /etc/ssh/
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-09-16 19:23:29 +02:00
|
|
|
create_ssh_directory() {
|
|
|
|
if [ ! -d "$SSH_DIR" ]; then
|
|
|
|
echo "The .ssh directory does not exist, creating..."
|
|
|
|
mkdir -p "$SSH_DIR"
|
|
|
|
chmod 700 "$SSH_DIR"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
create_authorized_keys_file() {
|
|
|
|
if [ ! -f "$AUTHORIZED_KEYS_FILE" ]; then
|
|
|
|
echo "The authorized_keys file does not exist, creating..."
|
|
|
|
touch "$AUTHORIZED_KEYS_FILE"
|
|
|
|
chmod 600 "$AUTHORIZED_KEYS_FILE"
|
|
|
|
fi
|
|
|
|
}
|
2023-09-10 17:52:45 +02:00
|
|
|
|
2023-09-16 19:23:29 +02:00
|
|
|
create_repos_directory() {
|
|
|
|
if [ ! -d "$REPOS_DIR" ]; then
|
|
|
|
echo "The repos directory does not exist, creating..."
|
|
|
|
mkdir -p "$REPOS_DIR"
|
|
|
|
fi
|
|
|
|
}
|
2023-09-10 17:52:45 +02:00
|
|
|
|
2023-09-17 11:21:22 +02:00
|
|
|
init_ssh_server
|
2023-09-16 19:23:29 +02:00
|
|
|
create_ssh_directory
|
|
|
|
create_authorized_keys_file
|
|
|
|
create_repos_directory
|
2023-09-10 17:52:45 +02:00
|
|
|
|
2023-09-16 19:23:29 +02:00
|
|
|
exec "$@"
|