docker-borgserver/data/run.sh

60 lines
1.8 KiB
Bash
Raw Normal View History

2017-10-19 17:41:41 +00:00
#!/bin/bash
# Start Script for docker-borgserver
set -e
2020-03-26 17:16:56 +00:00
source env.sh
usermod -o -u "$PUID" borg &>/dev/null
groupmod -o -g "$PGID" borg &>/dev/null
2017-10-19 17:41:41 +00:00
echo "########################################################"
echo -n " * Docker BorgServer powered by "
borg -V
echo "########################################################"
echo " * User id: $(id -u borg)"
echo " * Group id: $(id -g borg)"
2020-03-26 17:16:56 +00:00
if [ -z "${KEY_GIT_URL}" ] ; then
echo "* Pulling keys from ${KEY_GIT_URL}"
fi
echo "########################################################"
# Precheck if BORG_ADMIN is set
if [ "${BORG_APPEND_ONLY}" == "yes" ] && [ -z "${BORG_ADMIN}" ] ; then
echo "WARNING: BORG_APPEND_ONLY is active, but no BORG_ADMIN was specified!"
fi
# Init the ssh keys directory from a remote git repository
2020-03-26 17:16:56 +00:00
update-ssh-keys.sh
# Precheck directories & client ssh-keys
2017-10-19 17:41:41 +00:00
for dir in BORG_DATA_DIR SSH_KEY_DIR ; do
dirpath=$(eval echo '$'${dir})
echo " * Testing Volume ${dir}: ${dirpath}"
if [ ! -d "${dirpath}" ] ; then
echo "ERROR: ${dirpath} is no directory!"
2017-10-19 17:41:41 +00:00
exit 1
fi
if [ "$(find ${SSH_KEY_DIR}/clients ! -regex '.*/\..*' -a -type f | wc -l)" == "0" ] ; then
echo "ERROR: No SSH-Pubkey file found in ${SSH_KEY_DIR}"
2017-10-19 17:41:41 +00:00
exit 1
fi
done
# Create SSH-Host-Keys on persistent storage, if not exist
mkdir -p ${SSH_KEY_DIR}/host 2>/dev/null
echo " * Checking / Preparing SSH Host-Keys..."
for keytype in ed25519 rsa ; do
if [ ! -f "${SSH_KEY_DIR}/host/ssh_host_${keytype}_key" ] ; then
echo " ** Creating SSH Hostkey [${keytype}]..."
ssh-keygen -q -f "${SSH_KEY_DIR}/host/ssh_host_${keytype}_key" -N '' -t ${keytype}
fi
done
2017-10-19 17:41:41 +00:00
# Add every key to borg-users authorized_keys
2020-03-26 17:16:56 +00:00
create-client-dirs.sh
2017-10-19 17:41:41 +00:00
echo "########################################################"
echo " * Init done! Starting SSH-Daemon..."
2017-10-19 17:41:41 +00:00
/usr/sbin/sshd -D -e