This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
forked from nirui/sshwifty
-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_git_source_version.sh
executable file
·184 lines (167 loc) · 4.29 KB
/
make_git_source_version.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env sh
# shellcheck disable=SC3040
# vim: filetype=sh:tabstop=4:tw=76
# shellcheck disable=SC2006,SC2046,SC2065
test _$(printf '%s' "asdf" 2> /dev/null) != "_asdf" > /dev/null &&
printf '%s\n' \
"Error: This shell seems to be csh, which is not supported." &&
exit 1
set +e > /dev/null 2>&1
set +u > /dev/null 2>&1
# shellcheck disable=SC2046
eval export $(locale 2> /dev/null) > /dev/null 2>&1 || true
DUALCASE=1 && export DUALCASE
LC_ALL=C && export LC_ALL
LANGUAGE=C && export LANGUAGE
LANG=C && export LANG
(unset CDPATH > /dev/null 2>&1) > /dev/null 2>&1 &&
unset CDPATH > /dev/null 2>&1
if [ ".${ZSH_VERSION:-}" != "." ] &&
(emulate sh 2> /dev/null) > /dev/null 2>&1; then
emulate sh > /dev/null 2>&1
NULLCMD=: && export NULLCMD
# shellcheck disable=SC2142
alias -g '${1+"$@"}'='"$@"' > /dev/null 2>&1
unalias -a > /dev/null 2>&1 || true > /dev/null 2>&1
unalias -m '*' > /dev/null 2>&1
disable -f -m '*' > /dev/null 2>&1
setopt pipefail > /dev/null 2>&1
POSIXLY_CORRECT=1 && export POSIXLY_CORRECT
POSIX_ME_HARDER=1 && export POSIX_ME_HARDER
elif [ ".${BASH_VERSION:-}" != "." ] &&
(set -o posix 2> /dev/null) > /dev/null 2>&1; then
set -o posix > /dev/null 2>&1
set -o pipefail > /dev/null 2>&1
POSIXLY_CORRECT=1 && export POSIXLY_CORRECT
POSIX_ME_HARDER=1 && export POSIX_ME_HARDER
unalias -a > /dev/null 2>&1 || true > /dev/null 2>&1
fi
for as_var in BASH_ENV ENV MAIL MAILPATH; do
# shellcheck disable=SC1083,SC2015
eval test x\${"${as_var:?}"+set} = xset &&
(
(unset "${as_var:-}") ||
{
printf >&2 '%s\n' \
"Error: clear environment failed."
exit 1
}
) &&
unset "${as_var:-}" || true
done
TZ="UTC" && export TZ > /dev/null 2>&1
set -u > /dev/null 2>&1
set -e > /dev/null 2>&1
get_git_info()
{
if command command true 2> /dev/null 1>&2; then
if command git version 2> /dev/null 1>&2; then
GITTEST=$(git version 2> /dev/null)
# shellcheck disable=SC2236
if [ -n "${GITTEST:-}" ] &&
[ ! -z "${GITTEST:-}" ]; then
BRANCH=$(git branch --show-current 2> /dev/null)
CDDATE=" "$(git show -s --format="%cd" \
--date="format:%Y-%m-%d" 2> /dev/null)
GITVER=$(git describe --long --dirty --tags --always \
2> /dev/null)
if [ ! -n "${BRANCH:-}" ] ||
[ -z "${BRANCH:-}" ]; then
BRANCH="nobranch"
fi
if [ "${BRANCH:-}" = "master" ] ||
[ "${BRANCH:-}" = "main" ] ||
[ "${BRANCH:-}" = "trunk" ] ||
[ "${BRANCH:-}" = "nobranch" ]; then
if [ -n "${GITVER:-}" ] &&
[ ! -z "${GITVER:-}" ]; then
GIT_OUT=$(printf '%s' \
"${GITVER:?}${CDDATE:?}" |
sed -e 's/-0-g.* / /' \
-e 's/-[0-9]\+-g/+-g/')
fi
else
if [ -n "${GITVER:-}" ] &&
[ ! -z "${GITVER:-}" ]; then
GIT_OUT=$(printf '%s' \
"${GITVER:?}-${BRANCH:?}${CDDATE:?}" |
sed -e 's/-0-g.* / /' \
-e 's/-[0-9]\+-g/+-g/')
fi
fi
fi
else
printf >&2 '%s\n' \
"Error: git version failed."
exit 1
fi
else
printf >&2 '%s\n' \
"Error: command true failed."
exit 1
fi
GIT_SOURCE_INFO="${GIT_OUT:-0.0.0} "
GIT_SOURCE_XFRM=$(printf '%s\n' "${GIT_SOURCE_INFO:?}" | \
sed -e 's/VERSION_//' -e 's/_/\./g' 2> /dev/null) ||
{
printf >&2 '%s\n' \
"Error: sed failed."
exit 1
}
# shellcheck disable=SC2236
if [ -n "${GIT_SOURCE_XFRM:-}" ] &&
[ ! -z "${GIT_SOURCE_XFRM:-}" ]; then
printf '%s\n' \
"${GIT_SOURCE_XFRM:?}"
else
printf '%s\n' \
"${GIT_SOURCE_INFO:?}"
fi
}
get_utc_date()
{
# UTC_BLD_DATE=$(TZ=UTC date -u "+%Y-%m-%d" 2> /dev/null) ||
# {
# printf >&2 '%s\n' \
# "Error: date failed."
# exit 1
# }
# # shellcheck disable=SC2236
# if [ -n "${UTC_BLD_DATE:-}" ] &&
# [ ! -z "${UTC_BLD_DATE:-}" ]; then
# UTC_BLD_DATE_INFO="(compiled ${UTC_BLD_DATE:?})"
# else
#
UTC_BLD_DATE_INFO=""
# fi
printf '%s\n' \
"${UTC_BLD_DATE_INFO:-}"
}
BUILD_VER="$(get_git_info)" ||
{
printf >&2 '%s\n' \
"Error: get_git_info() failed."
exit 1
}
BUILD_UTC="$(get_utc_date)" ||
{
printf >&2 '%s\n' \
"Error: get_utc_date() failed."
exit 1
}
# shellcheck disable=SC1003
printf '%s\n' \
"${BUILD_VER:?}${BUILD_UTC:-}" \
> "./version.inc" ||
{
printf >&2 '%s\n' \
"Error: writing version.inc failed."
exit 1
}
# Local Variables:
# mode: sh
# sh-shell: sh
# sh-indentation: 4
# sh-basic-offset: 4
# tab-width: 4
# End: