Reformat key update script

This commit is contained in:
Hauro 2015-04-05 13:48:07 +02:00
parent 017fa93157
commit c4edb6f7b6
1 changed files with 21 additions and 21 deletions

View File

@ -8,30 +8,30 @@ dest=/var/run/foodoor-keys
if [ ! -e "${dest}/.git/config" ] if [ ! -e "${dest}/.git/config" ]
then then
#echo "Repo does not exist, trying to clone..." #echo "Repo does not exist, trying to clone..."
( cd /var/run && git clone --quiet --single-branch --depth=1 luftschleuse@nordstern.chaospott.de:/home/luftschleuse/foodoor-keys "${dest}" ) ( cd /var/run && git clone --quiet --single-branch --depth=1 luftschleuse@nordstern.chaospott.de:/home/luftschleuse/foodoor-keys "${dest}" )
else else
#echo "Repo exists, updating..." #echo "Repo exists, updating..."
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master ) ( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
fi fi
for action in open close for action in open close
do do
outfile="${dest}/authorized_keys.${action}" outfile="${dest}/authorized_keys.${action}"
rm -f ${outfile} rm -f ${outfile}
find "${dest}/keys" -name '*.pub' | sort | \ find "${dest}/keys" -name '*.pub' | sort | \
while read keyfile while read keyfile
do do
valid_key=$(ssh-keygen -l -f ${keyfile}) valid_key=$(ssh-keygen -l -f ${keyfile})
if [ "$?" -eq "0" ]; then if [ "$?" -eq "0" ]; then
if [ $(echo "${valid_key}" | cut -d" " -f1) -ne "4096" ]; then if [ $(echo "${valid_key}" | cut -d" " -f1) -ne "4096" ]; then
echo "Key size of key ${keyfile} not equal to 4096. Not adding it to key database." >&2 echo "Key size of key ${keyfile} not equal to 4096. Not adding it to key database." >&2
continue continue
fi fi
fi fi
printf "command=\"/usr/sbin/foodoor.sh ${action}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding " >> ${outfile} printf "command=\"/usr/sbin/foodoor.sh ${action}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding " >> ${outfile}
cat "${keyfile}" >> ${outfile} cat "${keyfile}" >> ${outfile}
done done
install -d -o ${action} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh install -d -o ${action} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
install -b -S .last -o ${action} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys install -b -S .last -o ${action} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
done done