-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenauthkeys.sh
executable file
·38 lines (32 loc) · 1.04 KB
/
genauthkeys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
generate_auth_keys() {
echo ">> Configuring authorized keys"
SOURCE_AUTH_KEYS='/etc/authorized_keys'
DEST_AUTH_PATH='/home/'${BORG_USER}'/.ssh'
DEST_AUTH_KEYS=${DEST_AUTH_PATH}'/authorized_keys'
if [ ! -e "${DEST_AUTH_PATH}" ]; then
mkdir ${DEST_AUTH_PATH}
chown ${BORG_USER}:${BORG_GROUP} ${DEST_AUTH_PATH}
else
rm ${DEST_AUTH_KEYS}
fi
for f in ${SOURCE_AUTH_KEYS}/*.pub; do
clientName=$(basename $f .pub)
echo 'Adding client '${clientName}
echo '# '${clientName} >> ${DEST_AUTH_KEYS}
if [ ${RESTRICT_TO_PATH} == 'true' ]; then
clientPath='/backups/'${clientName}
echo -n 'command="cd '${clientPath}'; borg serve --restrict-to-path '${clientPath}'" ' >> ${DEST_AUTH_KEYS}
if [ ! -e ${clientPath} ]; then
mkdir ${clientPath}
chown ${BORG_USER}:${BORG_GROUP} ${clientPath}
fi
else
clientPath='/backups/'
echo -n 'command="cd '${clientPath}'; borg serve" ' >> ${DEST_AUTH_KEYS}
fi
cat ${f} >> ${DEST_AUTH_KEYS}
done
chown ${BORG_USER}:${BORG_GROUP} ${DEST_AUTH_KEYS}
}
generate_auth_keys