summaryrefslogtreecommitdiffstats
path: root/core/modules/ssh-auth-keys/data/opt/openslx/scripts/systemd-ssh_auth_keys
blob: d08e78a0d41c7de90000421dd4793b37ebcdf7b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/ash

AUTH_KEYS_DIR="/root/.ssh/authorized_keys.d/"
AUTH_KEYS_FILE="/root/.ssh/authorized_keys"

# do we even have the directory?
[ ! -d "$AUTH_KEYS_DIR" ] && echo "No such directory: $AUTH_KEYS_DIR" && exit 0

mkdir -m 700 $(dirname "$AUTH_KEYS_FILE") 2>/dev/null
TMP=$(mktemp)

[ -s "$AUTH_KEYS_FILE" ] && cat "$AUTH_KEYS_FILE" >> "$TMP"

# ok, lets cat them in the real file
for KEY in "$AUTH_KEYS_DIR"/* ; do
	grep -E '(^#|\bssh-.*\sAAA)' "$KEY" >> "$TMP"
done

sort -u "$TMP" > "$AUTH_KEYS_FILE" || cp -f "$TMP" "$AUTH_KEYS_FILE"

rm -f -- "$TMP"

# all done, all good
exit 0