-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
executable file
·128 lines (110 loc) · 3.62 KB
/
install.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
#!/bin/bash
set -e
REPO_OWNER=gosh-sh
REPO=gosh
if [[ -z "${TAG}" ]]; then
echo ""
echo "Downloading latest release of git-remote-gosh"
echo ""
TAG=latest
else
echo ""
echo "Downloading git-remote-gosh tag: $TAG"
echo ""
TAG="tags/$TAG"
fi
# TODO: get it from one source with binary
# Check OS and architecture
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if [[ $(uname -m) == "x86_64" ]]; then
TAR="git-remote-gosh-linux-amd64.tar.gz"
else
TAR="git-remote-gosh-linux-arm64.tar.gz"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
if [[ $(uname -m) == "x86_64" ]]; then
TAR="git-remote-gosh-darwin-amd64.tar.gz"
else
TAR="git-remote-gosh-darwin-arm64.tar.gz"
fi
else
echo "Only \"MacOS\" and \"Linux\" are supported - not \"$OSTYPE\""
exit 1
fi
OLD_TAR="${TAR%.*}"
[ -d $TAR ] && rm $TAR
[ -d $OLD_TAR ] && rm $OLD_TAR
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/${REPO_OWNER}/${REPO}"
GH_TAGS="$GH_REPO/releases/$TAG"
# create dir and dummy config
mkdir -p "$HOME"/.gosh
if [ ! -f "$HOME"/.gosh/config.json ]; then
tee "$HOME"/.gosh/config.json <<EOF
{
"primary-network": "mainnet",
"networks": {
"mainnet": {
"user-wallet": null,
"endpoints": [
"https://bhs01.network.gosh.sh",
"https://eri01.network.gosh.sh",
"https://gra01.network.gosh.sh"
]
}
}
}
EOF
fi
# Read asset tags.
response=$(curl -s "$GH_TAGS")
# Get ID of the asset based on given name.
eval $(echo "$response" | grep -C3 "name.:.\+$TAR" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || {
OLD=TRUE
eval $(echo "$response" | grep -C3 "name.:.\+$OLD_TAR" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || {
echo "Error: Failed to get asset id, response: $response" | awk 'length($0)<100' >&2
exit 1
}
}
wget --content-disposition --no-cookie -q --header "Accept: application/octet-stream" "$GH_REPO/releases/assets/$id" --show-progress
# unpack
if [[ -z "${OLD}" ]]; then
tar -xvzf $TAR
rm -f $TAR
else
tar -xf $OLD_TAR
rm -f $OLD_TAR
fi
DEFAULT_PATH=$HOME/.gosh/
BINARY_PATH="${BINARY_PATH:-$DEFAULT_PATH}"
mv git-remote-gosh $BINARY_PATH
mv git-remote-gosh_v* $BINARY_PATH
mv dispatcher.ini $HOME/.gosh/
echo ""
echo "Binaries were installed to $BINARY_PATH"
echo ""
# check that binary path is added to bashrc
ALREADY_ADDED=$(cat "$HOME"/.bashrc | grep "export PATH=\$PATH:\$HOME/.gosh" | wc -l)
if [ $ALREADY_ADDED -lt 1 ]; then
echo "export PATH=\$PATH:\$HOME/.gosh" >>"$HOME"/.bashrc
export PATH=$PATH:\$HOME/.gosh
fi
NUMBER_OF_BINARIES=$(whereis -b git-remote-gosh | sed 's/git-remote-gosh://' | sed 's/ /\n/g' | grep git | wc -l)
if [ $NUMBER_OF_BINARIES -gt 1 ]; then
echo "There is more than one version of git-remote-gosh installed in your system. Remove extra versions except for '"$BINARY_PATH"git-remote-gosh'!"
echo "Currently installed binaries:"
whereis -b git-remote-gosh | sed 's/git-remote-gosh: //' | sed 's/ /\n/'
fi
if [ $NUMBER_OF_BINARIES -eq 0 ]; then
echo "Restart the terminal to use git-remote-gosh or if you use non-standard shell (not bash), please manually add 'export PATH=\$PATH:\$HOME/.gosh' to your .bashrc analog"
fi
if [ $NUMBER_OF_BINARIES -eq 1 ]; then
IS_PATH_RIGHT=$(whereis -b git-remote-gosh | sed 's/git-remote-gosh://' | grep $BINARY_PATH | wc -l)
if [ ! $IS_PATH_RIGHT -eq 1 ]; then
echo "You have an old version of git-remote-gosh installed on your system. Please remove it. Path:"
whereis -b git-remote-gosh | sed 's/git-remote-gosh: //'
echo "Seems like you use non-standard shell, please manually add 'export PATH=\$PATH:\$HOME/.gosh' to your .bashrc analog"
fi
fi