foodoord/foodoor-update-keydb

84 lines
2.5 KiB
Plaintext
Raw Normal View History

2016-03-31 14:00:53 +00:00
#!/bin/bash
2014-10-29 18:33:36 +00:00
set -e
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
dest=/var/run/foodoor-keys
temp_outfile="$dest.tmp"
2014-10-29 18:33:36 +00:00
if [ ! -e "${dest}/.git/config" ]
then
#echo "Repo does not exist, trying to clone..."
2021-11-07 17:21:12 +00:00
( cd /var/run && git clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "${dest}" )
2014-10-29 18:33:36 +00:00
else
#echo "Repo exists, updating..."
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
2014-10-29 18:33:36 +00:00
fi
rm -f ${temp_outfile}
find "${dest}/keys" -name '*.pub' | sort | \
while read keyfile
do
ssh-keygen -l -f ${keyfile} &> /dev/null
if [ $? -eq 0 ]; then
valid=false
keyinfo=$(ssh-keygen -l -f ${keyfile}) # The whole key information
crypto=$(echo "${keyinfo}" | cut -d" " -f4) # Looks like "(RSA)" or "(ED25519)"
key_length=$(echo "${keyinfo}" | cut -d" " -f1)
if [ "${crypto}" == "(RSA)" ]; then
2020-05-24 18:27:22 +00:00
if [ ${key_length} -lt 4096 ]; then
echo "Key size of key ${keyfile} not equal to 4096. Not adding it to key database." >&2
continue
else
valid=true
fi
2020-05-24 18:27:22 +00:00
elif [ "${crypto}" == "(ED25519)" ]; then
valid=true
fi
if [ "$valid" = true ]; then
2021-11-07 17:37:10 +00:00
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(cat ${keyfile})" >> ${temp_outfile}
fi
fi
done
for appendix in open close door
do
action="$appendix"
2021-11-07 17:31:48 +00:00
if [ "$action" = "door" ]
then
action=""
fi
export action
outfile="${dest}/authorized_keys.${appendix}"
2021-11-07 17:31:48 +00:00
cat ${temp_outfile} |envsubst > ${outfile}
2021-11-07 18:45:39 +00:00
# Oben
if [ "$(hostname)" = "foodoor" ]; then
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
fi
2020-05-24 18:27:22 +00:00
# Unten
2021-11-07 18:45:39 +00:00
if [ "$(hostname)" = "kellertuer" ]; then
if [ "${action}" = "open" ]; then
owner="unlock"
elif [ "${action}" = "close" ]; then
owner="lock"
fi
install -d -o ${owner} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
install -b -S .last -o ${owner} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
if [ "${appendix}" = "door" ]; then
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
fi
fi
2020-05-24 18:27:22 +00:00
2014-10-29 18:33:36 +00:00
done