setuser: do not use LC_IDENTIFICATION anymore

rather allow GIT* env variables to pass through ssh
This commit is contained in:
2025-04-28 13:31:49 +02:00
committed by l_samenv
parent 16bb53784c
commit b3cd338a1e
4 changed files with 153 additions and 18 deletions

View File

@@ -1,3 +1,11 @@
if [[ -z "$GIT_AUTHOR_EMAIL" || -z "$GIT_AUTHOR_NAME" ]]; then
export GIT_AUTHOR_NAME=PREVENT_DEFAULT
fi
function sigint_handler() {
trap - INT
}
function setuser() {
if [[ $# -eq 0 ]]; then
cat << EOF
@@ -8,27 +16,36 @@ function setuser() {
set author for git commit and get gitea token from linse-c if available
EOF
if [[ ! -z "$LC_IDENTIFICATION" ]]; then
local id=($LC_IDENTIFICATION)
echo "you are already identified as ${id[@]:2:9} <${id[1]}>"
if [[ "$GIT_AUTHOR_NAME" != "PREVENT_DEFAULT" ]]; then
echo "you are already identified as $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
echo " "
fi
return 1
fi
local isuser=$(ssh l_samenv@linse-c "test -d ~$1 && echo OK" 2>/dev/null)
if [[ "$isuser" == "OK" ]]; then
local id=($LC_IDENTIFICATION)
echo " "
if [[ ! -z "$id" ]]; then
echo "you are already identified as: ${id[@]:2:9} <${id[1]}> - you may press ctrl-c to abort"
fi
echo "get token from $1@linse-c"
export LC_IDENTIFICATION=$(ssh $1@linse-c 'echo $LC_IDENTIFICATION' 2>/dev/null)
if [[ -z "$LC_IDENTIFICATION" ]]; then
echo "LC_IDENTIFICATION is not defined in your rc file on $1@linse-c"
if [[ "$GIT_AUTHOR_NAME" != "PREVENT_DEFAULT" && ! -z "$GITEA_TOKEN" ]]; then
echo "you are already identified as $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> - you may press ctrl-c to abort"
echo "get token again from $1@linse-c"
else
local id=($LC_IDENTIFICATION)
echo "you are identified as ${id[@]:2:9} <${id[1]}>"
echo "get token from $1@linse-c"
fi
trap sigint_handler SIGINT
local all=($(ssh $1@linse-c 'echo _ $GITEA_TOKEN $GIT_AUTHOR_EMAIL $GIT_AUTHOR_NAME' 2>/dev/null))
if [[ -z "$all" ]]; then
return 1
fi
local token=${all[1]}
local email=${all[2]}
local name=${all[@]:3:9}
if [[ -z "$token" || -z "$email" || -z "$name" ]]; then
echo "GITEA_TOKEN, GIT_AUTHOR_EMAIL and GIT_AUTHOR_NAME are not defined in your rc file on $1@linse-c"
else
export GITEA_TOKEN=$token
export GIT_AUTHOR_EMAIL=$email
export GIT_AUTHOR_NAME=$name
echo "you are identified as $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
fi
echo " "
else
@@ -36,7 +53,7 @@ EOF
export GIT_AUTHOR_NAME="$1"
export GIT_AUTHOR_EMAIL="$1@$host"
echo " "
echo "$1 is no valid linux user on linse-c -> not gitea token available for git push"
echo "$1 is no valid linux user on linse-c -> no gitea token available for git push"
echo " "
echo "however, you are identified as $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> for git commit"
echo " "