tbuild_tools_util.sh - electrum - Electrum Bitcoin wallet
HTML git clone https://git.parazyd.org/electrum
DIR Log
DIR Files
DIR Refs
DIR Submodules
---
tbuild_tools_util.sh (4015B)
---
1 #!/usr/bin/env bash
2
3 # Set a fixed umask as this leaks into docker containers
4 umask 0022
5
6 RED='\033[0;31m'
7 BLUE='\033[0;34m'
8 YELLOW='\033[0;33m'
9 NC='\033[0m' # No Color
10 function info {
11 printf "\r💬 ${BLUE}INFO:${NC} ${1}\n"
12 }
13 function fail {
14 printf "\r🗯 ${RED}ERROR:${NC} ${1}\n"
15 exit 1
16 }
17 function warn {
18 printf "\r⚠️ ${YELLOW}WARNING:${NC} ${1}\n"
19 }
20
21
22 # based on https://superuser.com/questions/497940/script-to-verify-a-signature-with-gpg
23 function verify_signature() {
24 local file=$1 keyring=$2 out=
25 if out=$(gpg --no-default-keyring --keyring "$keyring" --status-fd 1 --verify "$file" 2>/dev/null) &&
26 echo "$out" | grep -qs "^\[GNUPG:\] VALIDSIG "; then
27 return 0
28 else
29 echo "$out" >&2
30 exit 1
31 fi
32 }
33
34 function verify_hash() {
35 local file=$1 expected_hash=$2
36 actual_hash=$(sha256sum $file | awk '{print $1}')
37 if [ "$actual_hash" == "$expected_hash" ]; then
38 return 0
39 else
40 echo "$file $actual_hash (unexpected hash)" >&2
41 rm "$file"
42 exit 1
43 fi
44 }
45
46 function download_if_not_exist() {
47 local file_name=$1 url=$2
48 if [ ! -e $file_name ] ; then
49 wget -O $file_name "$url"
50 fi
51 }
52
53 # https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh
54 function retry() {
55 local result=0
56 local count=1
57 while [ $count -le 3 ]; do
58 [ $result -ne 0 ] && {
59 echo -e "\nThe command \"$@\" failed. Retrying, $count of 3.\n" >&2
60 }
61 ! { "$@"; result=$?; }
62 [ $result -eq 0 ] && break
63 count=$(($count + 1))
64 sleep 1
65 done
66
67 [ $count -gt 3 ] && {
68 echo -e "\nThe command \"$@\" failed 3 times.\n" >&2
69 }
70
71 return $result
72 }
73
74 function gcc_with_triplet()
75 {
76 TRIPLET="$1"
77 CMD="$2"
78 shift 2
79 if [ -n "$TRIPLET" ] ; then
80 "$TRIPLET-$CMD" "$@"
81 else
82 "$CMD" "$@"
83 fi
84 }
85
86 function gcc_host()
87 {
88 gcc_with_triplet "$GCC_TRIPLET_HOST" "$@"
89 }
90
91 function gcc_build()
92 {
93 gcc_with_triplet "$GCC_TRIPLET_BUILD" "$@"
94 }
95
96 function host_strip()
97 {
98 if [ "$GCC_STRIP_BINARIES" -ne "0" ] ; then
99 case "$BUILD_TYPE" in
100 linux|wine)
101 gcc_host strip "$@"
102 ;;
103 darwin)
104 # TODO: Strip on macOS?
105 ;;
106 esac
107 fi
108 }
109
110 # on MacOS, there is no realpath by default
111 if ! [ -x "$(command -v realpath)" ]; then
112 function realpath() {
113 [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
114 }
115 fi
116
117
118 export SOURCE_DATE_EPOCH=1530212462
119 export PYTHONHASHSEED=22
120 # Set the build type, overridden by wine build
121 export BUILD_TYPE="${BUILD_TYPE:-$(uname | tr '[:upper:]' '[:lower:]')}"
122 # Add host / build flags if the triplets are set
123 if [ -n "$GCC_TRIPLET_HOST" ] ; then
124 export AUTOCONF_FLAGS="$AUTOCONF_FLAGS --host=$GCC_TRIPLET_HOST"
125 fi
126 if [ -n "$GCC_TRIPLET_BUILD" ] ; then
127 export AUTOCONF_FLAGS="$AUTOCONF_FLAGS --build=$GCC_TRIPLET_BUILD"
128 fi
129
130 export GCC_STRIP_BINARIES="${GCC_STRIP_BINARIES:-0}"
131
132
133 function break_legacy_easy_install() {
134 # We don't want setuptools sneakily installing dependencies, invisible to pip.
135 # This ensures that if setuptools calls distutils which then calls easy_install,
136 # easy_install will not download packages over the network.
137 # see https://pip.pypa.io/en/stable/reference/pip_install/#controlling-setup-requires
138 # see https://github.com/pypa/setuptools/issues/1916#issuecomment-743350566
139 info "Intentionally breaking legacy easy_install."
140 DISTUTILS_CFG="${HOME}/.pydistutils.cfg"
141 DISTUTILS_CFG_BAK="${HOME}/.pydistutils.cfg.orig"
142 # If we are not inside docker, we might be overwriting a config file on the user's system...
143 if [ -e "$DISTUTILS_CFG" ] && [ ! -e "$DISTUTILS_CFG_BAK" ]; then
144 warn "Overwriting python distutils config file at '$DISTUTILS_CFG'. A copy will be saved at '$DISTUTILS_CFG_BAK'."
145 mv "$DISTUTILS_CFG" "$DISTUTILS_CFG_BAK"
146 fi
147 cat <<EOF > "$DISTUTILS_CFG"
148 [easy_install]
149 index_url = ''
150 find_links = ''
151 EOF
152 }
153