made a multi threaded version of ht2crack2search since the file lookups should benefi...
[RRG-proxmark3.git] / tools / mkversion.sh
blobd8209438deaa72a98077cc18abac48e0e613efa9
1 #!/usr/bin/env sh
3 if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "" ]; then
4 echo "To report a short string about the current version:"
5 echo " $0 --short"
6 echo "To regenerate version_pm3.c if needed:"
7 echo " $0 [--force] [--undecided] path/to/version_pm3.c"
8 exit 0
9 fi
11 # Output a version_pm3.c file that includes information about the current build
12 # From mkversion.pl
13 # pure sh POSIX as now even on Windows we use WSL or ProxSpace with sh available
15 # Clear environment locale so that git will not use localized strings
16 export LC_ALL="C"
17 export LANG="C"
19 SHORT=false
20 if [ "$1" = "--short" ]; then
21 SHORT=true
22 shift
24 FORCE=false
25 if [ "$1" = "--force" ]; then
26 FORCE=true
27 shift
29 UNDECIDED=false
30 if [ "$1" = "--undecided" ]; then
31 UNDECIDED=true
32 shift
34 VERSIONSRC="$1"
36 if ! $SHORT && [ "$VERSIONSRC" = "" ]; then
37 echo "Error: $0 is missing its destination filename"
38 exit 1
41 if $SHORT && [ "$VERSIONSRC" != "" ]; then
42 echo "Error: can't output a short string and generate file at the same time"
43 exit 1
46 # if you are making your own fork, change this line to reflect your fork-name
47 fullgitinfo="Iceman"
48 # GIT status 0 = dirty, 1 = clean , 2 = undecided
49 clean=2
51 # Do we have access to git command?
52 commandGIT=$(env git)
54 if [ "$commandGIT" != "" ]; then
56 # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case
57 gitversion=$(git describe --dirty --always)
58 gitbranch=$(git rev-parse --abbrev-ref HEAD)
59 if $UNDECIDED; then
60 if [ "$gitversion" != "${gitversion%-dirty}" ]; then
61 clean=0
62 else
63 clean=1
66 if [ "$gitbranch" != "" ] && [ "$gitversion" != "" ]; then
67 fullgitinfo="${fullgitinfo}/${gitbranch}/${gitversion}"
68 ctime="$(date '+%Y-%m-%d %H:%M:%S')"
69 else
70 fullgitinfo="${fullgitinfo}/master/release (git)"
72 else
73 fullgitinfo="${fullgitinfo}/master/release (no_git)"
74 dl_time=$(stat --printf="%y" ../README.md)
75 # POSIX way...
76 ctime=${dl_time%.*}
78 if $SHORT; then
79 echo "$fullgitinfo"
80 exit 0
83 # Crop so it fits within 50 characters C string, so max 49 chars
84 # POSIX way
85 fullgitinfoextra="${fullgitinfo#??????????????????????????????????????????????}"
86 if [ "$fullgitinfoextra" != "$fullgitinfo" ]; then
87 fullgitinfo46="${fullgitinfo%"${fullgitinfoextra}"}"
88 fullgitinfo="${fullgitinfo46}..."
90 sha=$(
91 pm3path=$(dirname -- "$0")/..
92 cd "$pm3path" || return
93 # did we find the src?
94 [ -f armsrc/appmain.c ] || return
95 if [ "${OSTYPE#darwin}" != "$OSTYPE" ]; then
96 # macOS
97 ls armsrc/*.[ch] common_arm/*.[ch]|grep -E -v "(disabled|version_pm3|fpga_version_info)"|sort|xargs shasum -a 256 -t|shasum -a 256|cut -c -9
98 else
99 ls armsrc/*.[ch] common_arm/*.[ch]|grep -E -v "(disabled|version_pm3|fpga_version_info)"|sort|xargs sha256sum -t|sha256sum|cut -c -9
102 if [ "$sha" = "" ]; then
103 sha="no sha256"
106 REDO=true
107 if ! $FORCE && [ -f "$VERSIONSRC" ]; then
108 # version src file exists, check if it needs to be updated
109 # file parser quite fragile, be careful if you edit VERSIONSRC template below...
110 oldclean=$(sed '13s/.*\([0-9]\+\).*/\1/;13!d' "$VERSIONSRC")
111 oldfullgitinfo=$(sed '14s/.*"\([^"]*\)".*/\1/;14!d' "$VERSIONSRC")
112 oldsha=$(sed '16s/.*"\([^"]*\)".*/\1/;16!d' "$VERSIONSRC")
113 if [ "$oldclean" = "$clean" ] && [ "$oldfullgitinfo" = "$fullgitinfo" ] && [ "$oldsha" = "$sha" ]; then
114 REDO=false
117 if $REDO; then
118 # use a tmp file to avoid concurrent call to mkversion to parse a half-written file.
119 cat > "${VERSIONSRC}.tmp" <<EOF
120 #include "common.h"
121 /* Generated file, do not edit */
122 #ifndef ON_DEVICE
123 #define SECTVERSINFO
124 #else
125 #define SECTVERSINFO __attribute__((section(".version_information")))
126 #endif
128 const struct version_information_t SECTVERSINFO g_version_information = {
129 VERSION_INFORMATION_MAGIC,
132 $clean,
133 "$fullgitinfo",
134 "$ctime",
135 "$sha"
138 mv "${VERSIONSRC}.tmp" "${VERSIONSRC}"