-
Notifications
You must be signed in to change notification settings - Fork 0
/
install2.sh
121 lines (106 loc) · 4.55 KB
/
install2.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
#!/usr/bin/env bash
OS="DEFAULT"
ARCH="DEFAULT"
while [[ -n "$1" ]]; do
case "$1" in
-o)
OS="$2"
if [[ "${OS}" != "darwin" && "${OS}" != "linux" ]]; then
echo "The operating system you entered isn't supported, please correct and retry. Supported: darwin, linux. darwin means macOS."
exit 1
fi
shift 2
;;
-a)
ARCH="$2"
if [[ "${ARCH}" != "amd64" && "${ARCH}" != "386" && "${ARCH}" != "arm64" && "${ARCH}" != "arm" ]]; then
echo "The arch you entered isn't supported, please correct and retry. Supported: amd64, 386, arm64, arm"
exit 1
fi
shift 2
;;
*)
echo "Wrong arguments, correct usage: bash install.sh -o OS -a ARCH"
echo "Supported OS: darwin, linux; supported arch: amd64, 386. darwin means macOS."
exit 1
;;
esac
done
if [[ "${ARCH}" = "DEFAULT" ]]; then
echo "Please enter operating system. Supported: darwin, linux. darwin means macOS."
exit 1
fi
if [[ "${OS}" = "DEFAULT" ]]; then
echo "Please enter arch. Supported: amd64, 386, arm64, arm"
exit 1
fi
mkdir -p /tmp/btfs.tmp && cd /tmp/btfs.tmp
n=0
while true; do
m=0
while true; do
curl -fL -o config_${OS}_${ARCH}_downloaded.yaml https://github.com/TRON-US/go-btfs/releases/latest/download/config_${OS}_${ARCH}.yaml && curl -fL -O https://github.com/TRON-US/go-btfs/releases/latest/download/btfs-${OS}-${ARCH}.tar && break
let "m++"
if [[ "${m}" -ge 3 ]]; then echo "Download of installation file failed, confirm your internet connection to GitHub is working and rerun this script."; exit 1; fi
sleep 5
done
MD5_FROM_CONFIG_FILE=$(grep md5 config_${OS}_${ARCH}_downloaded.yaml | awk '{print $2}')
tar -xf btfs-${OS}-${ARCH}.tar
case ${OS} in
darwin)
if ! command -v md5 > /dev/null; then echo "Please install md5 command first, then rerun this script."; exit 1; fi
MD5=$(md5 -r btfs-${OS}-${ARCH} | awk '{print $1}')
;;
linux)
if ! command -v md5sum > /dev/null; then echo "Please install md5sum command first, then rerun this script."; exit 1; fi
MD5=$(md5sum btfs-${OS}-${ARCH} | awk '{print $1}')
;;
esac
if [[ "${MD5}" = "${MD5_FROM_CONFIG_FILE}" ]]; then break; fi
let "n++"
if [[ "${n}" -ge 3 ]]; then echo "Installation file is corrupted, confirm your internet connection to GitHub is working and rerun this script."; exit 1; fi
sleep 5
done
m=0
while true; do
curl -fL -O https://github.com/TRON-US/btfs-distributions/raw/master/fs-repo-migrations/versions && break
let "m++"
if [[ "${m}" -ge 3 ]]; then echo "Download of fs-repo-migrations version file failed, confirm your internet connection to GitHub is working and rerun this script."; exit 1; fi
sleep 5
done
VERSION=$(cat versions | sort -V | tail -n 1)
FILE1="fs-repo-migrations_${VERSION}_${OS}-${ARCH}.tar.gz"
FILE2="fs-repo-migrations_${VERSION}_${OS}-${ARCH}.tar.gz.sha512"
URL1="https://github.com/TRON-US/btfs-distributions/raw/master/fs-repo-migrations/${VERSION}/${FILE1}"
URL2="https://github.com/TRON-US/btfs-distributions/raw/master/fs-repo-migrations/${VERSION}/${FILE2}"
n=0
while true; do
m=0
while true; do
curl -fL -O "${URL1}" && curl -fL -O "${URL2}" && break
let "m++"
if [[ "${m}" -ge 3 ]]; then echo "Download of fs-repo-migrations files failed, confirm your internet connection to GitHub is working and rerun this script."; exit 1; fi
sleep 5
done
if ! command -v shasum > /dev/null; then echo "Please install shasum command first, then rerun this script."; exit 1; fi
SHA512=$(shasum -a 512 "${FILE1}" | awk '{print $1}')
SHA512_FROM_FILE=$(grep "${FILE1}" "${FILE2}" |awk '{print $1}')
if [[ "${SHA512}" = "${SHA512_FROM_FILE}" ]]; then break; fi
let "n++"
if [[ "${n}" -ge 3 ]]; then echo "${FILE1} is corrupted, confirm your internet connection to GitHub is working and rerun this script."; exit 1; fi
sleep 5
done
tar -xzf "${FILE1}"
BTFSPATH=${HOME}/btfs
if [[ -d "${BTFSPATH}" ]]; then
echo "~/btfs already exists, deleting ~/btfs first..."
rm -rf "${BTFSPATH}"
echo "Deleting ~/btfs succeeded!"
fi
mkdir -p ${BTFSPATH}/bin
mv btfs-${OS}-${ARCH} ${BTFSPATH}/bin/btfs
mv config_${OS}_${ARCH}.yaml ${BTFSPATH}/bin/config.yaml
mv fs-repo-migrations/fs-repo-migrations ${BTFSPATH}/bin/
rm -rf /tmp/btfs.tmp
echo "Installation of BTFS succeeded!"
exit 0