-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.sh
95 lines (80 loc) · 1.51 KB
/
utils.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
#!/bin/bash
function debug {
set +x
echo "~ ${1} ~"
set -x
}
function info {
set +x
echo
echo "=== ${1} ==="
echo
set -x
}
function warning {
set +x
echo
echo "!!! ${1} !!!"
echo
set -x
}
function git_clone_or_pull {
set +x
DIR=${1}
REPO=${2}
BRANCH=${3}
set -x
if [ ! -d "${DIR}" ]; then
git clone -b "${BRANCH}" "${REPO}" "${DIR}"
fi
(
cd "${DIR}" || return 1
git pull origin "${BRANCH}"
git submodule update --init --recursive
)
}
function download_file {
set +x
DEST=${1}
URL=${2}
set -x
TMP=$(mktemp)
curl -4 -sSL -o "${TMP}" "${URL}"
if [ -f "${DEST}" ]; then
OLD_MD5=$(md5sum "${DEST}" | cut -d ' ' -f 1)
NEW_MD5=$(md5sum "${TMP}" | cut -d ' ' -f 1)
if [ "${OLD_MD5}" != "${NEW_MD5}" ]; then
TMP2=$(mktemp)
mv "${DEST}" "${TMP2}"
fi
fi
mv "${TMP}" "${DEST}"
}
function download_executable {
set +x
DEST=${1}
URL=${2}
set -x
TMP=$(mktemp)
curl -4 -sSL -o "${TMP}" "${URL}"
chmod +x "${TMP}"
if [ -f "${DEST}" ]; then
OLD_MD5=$(md5sum "${DEST}" | cut -d ' ' -f 1)
NEW_MD5=$(md5sum "${TMP}" | cut -d ' ' -f 1)
if [ "${OLD_MD5}" != "${NEW_MD5}" ]; then
TMP2=$(mktemp)
mv "${DEST}" "${TMP2}"
fi
fi
mv "${TMP}" "${DEST}"
}
function create_symlink {
set +x
SOURCE_FILE=${1}
DEST_FILE=${2}
if [ "$(readlink -f "$DEST_FILE")" != "$SOURCE_FILE" ]; then
debug "updating symlink ${DEST_FILE} -> ${SOURCE_FILE}"
ln -f -s "$SOURCE_FILE" "$DEST_FILE"
fi
set -x
}