Coding-Style; First floor and basement are now the same with the

authentication user
This commit is contained in:
Bandie 2022-04-11 18:47:42 +02:00
parent aadce7fb1a
commit aacb9c9669
Signed by: Bandie
GPG Key ID: F4E0AB327841A877

View File

@ -9,75 +9,52 @@ temp_outfile="$dest.tmp"
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 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "${dest}" ) ( cd /var/run && git clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "${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
rm -f ${temp_outfile} rm -f ${temp_outfile}
find "${dest}/keys" -name '*.pub' | sort | \ find "${dest}/keys" -name '*.pub' | sort | \
while read keyfile while read keyfile
do do
ssh-keygen -l -f ${keyfile} &> /dev/null ssh-keygen -l -f ${keyfile} &> /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
valid=false valid=false
keyinfo=$(ssh-keygen -l -f ${keyfile}) # The whole key information keyinfo=$(ssh-keygen -l -f ${keyfile}) # The whole key information
crypto=$(echo "${keyinfo}" | cut -d" " -f4) # Looks like "(RSA)" or "(ED25519)" crypto=$(echo "${keyinfo}" | cut -d" " -f4) # Looks like "(RSA)" or "(ED25519)"
key_length=$(echo "${keyinfo}" | cut -d" " -f1) key_length=$(echo "${keyinfo}" | cut -d" " -f1)
if [ "${crypto}" == "(RSA)" ]; then if [ "${crypto}" == "(RSA)" ]; then
if [ ${key_length} -lt 4096 ]; then if [ ${key_length} -lt 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
else else
valid=true valid=true
fi fi
elif [ "${crypto}" == "(ED25519)" ]; then elif [ "${crypto}" == "(ED25519)" ]; then
valid=true valid=true
fi fi
if [ "$valid" = true ]; then if [ "$valid" = true ]; then
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(cat ${keyfile})" >> ${temp_outfile} echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(cat ${keyfile})" >> ${temp_outfile}
fi fi
fi fi
done done
for appendix in open close door for appendix in open close door
do do
action="$appendix" action="$appendix"
if [ "$action" = "door" ]
then
action=""
fi
export action export action
outfile="${dest}/authorized_keys.${appendix}" outfile="${dest}/authorized_keys.${appendix}"
cat ${temp_outfile} |envsubst > ${outfile} cat ${temp_outfile} |envsubst > ${outfile}
# Oben # Oben und unten
if [ "$(hostname)" = "foodoor" ]; then install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
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
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
fi
# Unten
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
done done