2025.08.20 17:02:19 (laptop1.cmoser.eu)

This commit is contained in:
Christian Moser 2025-08-20 17:02:19 +02:00
parent 4bc0615154
commit de8e04cbf9
Failed to extract signature

236
git.sh
View File

@ -1,130 +1,130 @@
# vim: syn=sh ts=4 sts=4 sw=4 smartindent autoindent expandtab ff=unix # vim: syn=sh ts=4 sts=4 sw=4 smartindent autoindent expandtab ff=unix
git-initialize() { #git-initialize() {
USAGE="git-initialize -u USER -e EMAIL [-b DEFAULT_BRANCH] [-S SSH_KEY] [-s SSH_COMMAND]" # USAGE="git-initialize -u USER -e EMAIL [-b DEFAULT_BRANCH] [-S SSH_KEY] [-s SSH_COMMAND]"
args=$( getopt "b:e:s:S:u:" $* ) # args=$( getopt "b:e:s:S:u:" $* )
if [ $? -ne 0 ]; then # if [ $? -ne 0 ]; then
echo "$USAGE" # echo "$USAGE"
return 2 # return 2
fi # fi
local default_branch=main # local default_branch=main
local user="$USER" # local user="$USER"
local email="" # local email=""
local ssh_key="" # local ssh_key=""
local ssh_command="" # local ssh_command=""
set -- $args # set -- $args
while :; do # while :; do
case "$1" in # case "$1" in
-b) # -b)
local default_branch="$2" # local default_branch="$2"
shift; shift # shift; shift
;; # ;;
-e) # -e)
local email="$2" # local email="$2"
shift; shift # shift; shift
;; # ;;
-S) # -S)
local ssh_key="$2" # local ssh_key="$2"
shift; shift # shift; shift
;; # ;;
-s) # -s)
local ssh_command="$2" # local ssh_command="$2"
shift; shift # shift; shift
;; # ;;
-u) # -u)
local user="$2" # local user="$2"
shift; shift # shift; shift
;; # ;;
--) # --)
shift; break # shift; break
;; # ;;
esac # esac
done # done
if [ -z "$email" ]; then # if [ -z "$email" ]; then
read -p "Email: " __git_email__ # read -p "Email: " __git_email__
local email=$__git_email__ # local email=$__git_email__
unset __git_email__ # unset __git_email__
fi # fi
signingkey=$( gpgsm --list-secret-keys | egrep '(key usage|ID)' | grep -v CertifyID |grep -B 1 digitalSignature | awk '/ID/ {print $2}' ) # signingkey=$( gpgsm --list-secret-keys | egrep '(key usage|ID)' | grep -v CertifyID |grep -B 1 digitalSignature | awk '/ID/ {print $2}' )
git config --global user.name "$user" # git config --global user.name "$user"
git config --global user.email "$email" # git config --global user.email "$email"
git config --global init.defaultBranch "$default_branch" # git config --global init.defaultBranch "$default_branch"
if [ -n "$ssh_command" ]; then # if [ -n "$ssh_command" ]; then
git config --global core.sshCommand "$ssh_command" # git config --global core.sshCommand "$ssh_command"
elif [ -n "$ssh_key" ]; then # elif [ -n "$ssh_key" ]; then
git config --global core.sshCommand "ssh -i \"$ssh_key\"" # git config --global core.sshCommand "ssh -i \"$ssh_key\""
fi # fi
} #}
git-init-smime() { #git-init-smime() {
USAGE="git-init-smime [-cgh] CERT_ID" # USAGE="git-init-smime [-cgh] CERT_ID"
args=$( getopt "cCgh" $* ) # args=$( getopt "cCgh" $* )
if [ $? -ne 0 ]; then # if [ $? -ne 0 ]; then
echo $USAGE # echo $USAGE
return 2 # return 2
fi # fi
set -- $args # set -- $args
#
local sign_commits="" # local sign_commits=""
local global="" # local global=""
#
while :; do # while :; do
case "$1" in # case "$1" in
-C) # -C)
local sign_commits=NO # local sign_commits=NO
shift # shift
;; # ;;
-c) # -c)
local sign_commits=YES # local sign_commits=YES
shift # shift
;; # ;;
-g) # -g)
local global="--global" # local global="--global"
shift # shift
;; # ;;
-h) # -h)
cat << EOF # cat << EOF
git-init-smime HELP #git-init-smime HELP
#
SYNOPSIS #SYNOPSIS
$USAGE # $USAGE
#
OPTIONS #OPTIONS
-C Disable automatic signing of commits. # -C Disable automatic signing of commits.
[DEFAULT: no change] # [DEFAULT: no change]
-c Enable automatic signing of commits. # -c Enable automatic signing of commits.
[DEFAULT: no change] # [DEFAULT: no change]
-g Set global GIT options. # -g Set global GIT options.
-h Print this help message and exit. # -h Print this help message and exit.
EOF #EOF
shift; return # shift; return
;; # ;;
--) # --)
shift; break # shift; break
;; # ;;
esac # esac
done # done
#
if [ -z "$1" ]; then # if [ -z "$1" ]; then
echo "No CERT_ID given! Obtain the ID with \"gpgsm --list-secret-keys\"" >&2 # echo "No CERT_ID given! Obtain the ID with \"gpgsm --list-secret-keys\"" >&2
echo "$USAGE" # echo "$USAGE"
return 2 # return 2
fi # fi
#
git config $global user.signingkey "$1" # git config $global user.signingkey "$1"
git config $global gpg.format x509 # git config $global gpg.format x509
if [ "$sign_commits" = "YES" ]; then # if [ "$sign_commits" = "YES" ]; then
git config $global commit.gpgsign true # git config $global commit.gpgsign true
elif [ "$sign_commits" = "NO" ]; then # elif [ "$sign_commits" = "NO" ]; then
git config $global commit.gpgsign false # git config $global commit.gpgsign false
fi # fi
} #}
git-init-gpg() { git-init-gpg() {
echo TODO echo TODO