-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig-git.sh
More file actions
executable file
·95 lines (76 loc) · 2.55 KB
/
config-git.sh
File metadata and controls
executable file
·95 lines (76 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env sh
# SPDX-FileCopyrightText: NONE
# SPDX-License-Identifier: CC0-1.0
pause_if_needed()
{
# shellcheck disable=SC3028 # Ignore: In POSIX sh, SHLVL is undefined
if test "${NO_PAUSE:-0}" = '0' && test "${no_pause:-0}" = '0' && test "${CI:-false}" = 'false' && test "${TERM_PROGRAM:-unknown}" != 'vscode' && test "${SHLVL:-1}" = '1' && test -t 0 && test -t 1 && test -t 2; then
if test -n "${NO_COLOR-}"; then
printf 1>&2 '\n%s' 'Press any key to exit... ' || :
else
printf 1>&2 '\n\033[1;32m\r%s' 'Press any key to exit... ' || :
fi
# shellcheck disable=SC3045 # Ignore: In POSIX sh, read -s / -n is undefined
IFS='' read 2> /dev/null 1>&2 -r -s -n1 _ || IFS='' read 1>&2 -r _ || :
printf 1>&2 '\n' || :
test -n "${NO_COLOR-}" || printf 1>&2 '\033[0m\r \r' || :
fi
unset no_pause || :
return "${1:-0}"
}
config_var()
{
printf '%s' "Configuring ${1:?}: "
if test -n "${3-}" && test "${3:?}" != 0; then
printf '%s\n' 'Missing'
return 44
fi
if HOME="${USER_HOME:-${HOME:?}}" git config set --local "${1:?}" "${2:?}"; then
printf '%s\n' 'OK'
else
_status="${?}"
printf '%s\n' 'Error'
return "${_status:?}"
fi
}
import_gpg_keys()
{
printf '%s' "Importing ${1:?} public keys: "
if test -n "${3-}" && test "${3:?}" != 0; then
printf '%s\n' 'Missing'
return 44
fi
if HOME="${USER_HOME:-${HOME:?}}" gpg 2> /dev/null --import -- "${2:?}"; then
printf '%s\n' 'OK'
else
_status="${?}"
printf '%s\n' 'Error'
return "${_status:?}"
fi
}
setup_gpg()
{
command 1> /dev/null -v 'gpg' || {
printf '%s\n' 'WARNING: gpg is missing'
return 255
}
# GitHub => https://github.com/web-flow.gpg
test -f "${PWD:?}/.public-keys/github.gpg"
import_gpg_keys 'GitHub' "${PWD:?}/.public-keys/github.gpg" "${?}" || return "${?}"
printf '%s\n' '968479A1AFF927E37D1A566BB5690EEEBB952194:6:' | HOME="${USER_HOME:-${HOME:?}}" gpg --import-ownertrust || return "${?}"
}
STATUS=0
printf '%s\n\n' "Repo dir: ${PWD?}" || STATUS="${?}"
test -f "${PWD:?}/allowed_signers"
config_var gpg.ssh.allowedSignersFile 'allowed_signers' "${?}" || STATUS="${?}"
config_var format.signOff 'true' || STATUS="${?}"
config_var alias.cm 'commit -s' || STATUS="${?}"
printf '\n'
test -d "${PWD:?}/.git-hooks"
config_var core.hooksPath '.git-hooks' "${?}" || STATUS="${?}"
HOME="${USER_HOME:-${HOME:?}}" git lfs install --local || STATUS="${?}"
printf '\n'
setup_gpg || STATUS="${?}"
test "${STATUS:?}" = 0 || printf '%s\n' "Error code: ${STATUS:?}"
pause_if_needed "${STATUS:?}"
exit "${?}"