change setuser mechanism

rely on the fact the LC_IDENTIFICATION (and other LC_*)
environment variables are forwarded from an ssh client to the
server
This commit is contained in:
2025-04-17 16:19:22 +02:00
parent fefb87dfe6
commit cddf70bcdd

View File

@ -8,25 +8,36 @@ GITEA_URL = 'https://gitea.psi.ch/linse/%s.git'
GET_GITEA_TOKEN = """#!/bin/bash
if [ -z "$GITEA_TOKEN" ]; then
echo "" 1>&2
echo "you try to push without setting GITEA_TOKEN" 1>&2
echo "please use 'setuser <initials>' to identify yourself" 1>&2
echo "" 1>&2
echo quit=1
re='^([0-9a-f]{8:}) ([^ ]*) (.*)?$'
if [[ "$LC_IDENTIFICATION" =~ $re ]]; then
export GITEA_TOKEN=${BASH_REMATCH[1]}
export GIT_AUTHOR_NAME=${BASH_REMATCH[3]}
else
echo "" 1>&2
echo "you try to push without setting GITEA_TOKEN" 1>&2
echo "please use 'setuser <user name>' to identify yourself" 1>&2
echo "" 1>&2
echo quit=1
fi
else
if [ "$1" == "get" ]; then
echo "connecting with gitea token for $GIT_AUTHOR_NAME" 1>&2
fi
echo username=_
echo "username=_"
echo "password=$GITEA_TOKEN"
fi
"""
PRE_COMMIT_HOOK = """#!/bin/bash
re='^([0-9a-f]{8:}) ([^ ]*) (.*)?$'
if [[ "$LC_IDENTIFICATION" =~ $re ]]; then
export GIT_AUTHOR_EMAIL=${BASH_REMATCH[2]}
export GIT_AUTHOR_NAME=${BASH_REMATCH[3]}
fi
if [ "$GIT_AUTHOR_NAME" == "PREVENT_DEFAULT" ]; then
echo ''
echo 'You tried to commit without specified author'
echo "please execute 'setuser <initials>' to identify yourself"
echo 'You try to commit without specified author'
echo "please execute 'setuser <user name>' to identify yourself"
echo 'or add the author with: git commit --author=<your name>'
echo ''
exit 1