-
Notifications
You must be signed in to change notification settings - Fork 4
/
getdgraph.sh
executable file
·182 lines (154 loc) · 5.87 KB
/
getdgraph.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
#
# Dgraph Installer Script
#
# Homepage: https://dgraph.io
# Requires: bash, curl, tar or unzip
#
# Hello! This is a script that installs Dgraph
# into your PATH (which may require password authorization).
# Use it like this:
#
# $ curl https://get.dgraph.io | bash
#
# This should work on Mac, Linux, and BSD systems.
set -e
BLACK='\033[30;1m'
RED='\033[91;1m'
GREEN='\033[32;1m'
RESET='\033[0m'
WHITE='\033[97;1m'
print_instruction() {
printf "$WHITE$1$RESET\n"
}
print_step() {
printf "$BLACK$1$RESET\n"
}
print_error() {
printf "$RED$1$RESET\n"
}
print_good() {
printf "$GREEN$1$RESET\n"
}
install_dgraph() {
printf $BLACK
cat << "EOF"
_____ _
| __ \ | |
| | | | __ _ _ __ __ _ _ __ | |__
| | | |/ _` | '__/ _` | '_ \| '_ \
| |__| | (_| | | | (_| | |_) | | | |
|_____/ \__, |_| \__,_| .__/|_| |_|
__/ | | |
|___/ |_|
EOF
printf $RESET
# Check curl is installed
if ! hash curl 2>/dev/null; then
print_error "Could not find curl. Please install curl and try again.";
exit 1;
fi
sudo_cmd=""
if hash sudo 2>/dev/null; then
sudo_cmd="sudo"
fi
install_path="/usr/local/bin"
release_version="$(curl -s https://api.github.com/repos/dgraph-io/dgraph/releases | grep "tag_name" | awk '{print $2}' | tr -dc '[:alnum:].\n\r' | head -n1)"
print_step "Latest release version is $release_version."
platform="$(uname | tr '[:upper:]' '[:lower:]')"
if [ "$platform" = "linux" ]; then
md5cmd=md5sum
else
md5cmd="md5 -r"
fi
checksum_file="dgraph-checksum-$platform-amd64-$release_version".md5
checksum_link="https://github.com/dgraph-io/dgraph/releases/download/"$release_version"/"$checksum_file
print_step "Downloading checksum file."
if curl -L --progress-bar "$checksum_link" -o "/tmp/$checksum_file"; then
print_step "Download complete."
else
print_error "Sorry. Binaries not available for your platform. Please compile manually: https://wiki.dgraph.io/Beginners_Guide"
echo
exit 1;
fi
dgraph=$(grep -m 1 /usr/local/bin/dgraph /tmp/$checksum_file | awk '{print $1;}')
dgraphloader=$(grep -m 1 /usr/local/bin/dgraphloader /tmp/$checksum_file | awk '{print $1;}')
print_step "Comparing checksums for dgraph binaries"
if $md5cmd /usr/local/bin/dgraph &>/dev/null && $md5cmd /usr/local/bin/dgraphloader &>/dev/null; then
dgraphsum=$($md5cmd /usr/local/bin/dgraph | awk '{print $1;}')
dgraphloadersum=$($md5cmd /usr/local/bin/dgraphloader | awk '{print $1;}')
else
dgraphsum=""
dgraphloadersum=""
fi
if [ "$dgraph" == "$dgraphsum" ] && [ "$dgraphloader" == "$dgraphloadersum" ]; then
print_good "You already have Dgraph $release_version installed."
else
tar_file=dgraph-$platform-amd64-$release_version".tar.gz"
dgraph_link="https://github.com/dgraph-io/dgraph/releases/download/"$release_version"/"$tar_file
# Backup existing dgraph binaries in HOME directory
if hash dgraph 2>/dev/null; then
dgraph_path="$(which dgraph)"
dgraph_backup="dgraph_backup_olderversion"
print_step "Backing up older versions in ~/$dgraph_backup (password may be required)."
mkdir -p ~/$dgraph_backup
$sudo_cmd mv $dgraph_path* ~/$dgraph_backup/.
fi
# Download and untar Dgraph binaries
if curl --output /dev/null --silent --head --fail "$dgraph_link"; then
print_step "Downloading $dgraph_link"
curl -L --progress-bar "$dgraph_link" -o "/tmp/$tar_file"
print_good "Download complete."
else
print_error "Sorry. Binaries not available for your platform. Please compile manually: https://wiki.dgraph.io/Beginners_Guide";
echo
exit 1;
fi
print_step "Inflating binaries (password may be required).";
$sudo_cmd tar -C /usr/local/bin -xzf /tmp/$tar_file --strip-components=1;
rm "/tmp/"$tar_file;
# Check installation
if hash dgraph 2>/dev/null; then
print_good "Dgraph binaries $release_version have been installed successfully in /usr/local/bin.";
else
print_error "Installation failed. Please try again.";
exit 1;
fi
fi
icu=$(grep -m 1 /icudt58l.dat /tmp/$checksum_file | awk '{print $1;}')
icufile="icudt58l.dat"
iculoc="/usr/local/share/$icufile"
if $md5cmd $iculoc &>/dev/null; then
icusum=$($md5cmd $iculoc | awk '{print $1;}')
else
icusum=""
fi
if [ "$icu" == "$icusum" ]; then
print_good "You already have ICU v58.2 data file."
else
if [ -f $iculoc ]; then
$sudo_cmd rm $iculoc
fi
print_step "Downloading ICU data file.";
curl -L --progress-bar https://github.com/dgraph-io/dgraph/releases/download/$release_version/$icufile -o /tmp/$icufile;
$sudo_cmd mv /tmp/$icufile /usr/local/share/
print_good "ICU data file for v58.2 has been downloaded and put in /usr/local/share.";
fi
if [ "$ICU_DATA" != "$iculoc" ]; then
print_error "
########################################### IMPORTANT #################################################
# #
# You do not have ICU_DATA environment variable set. #
# To use the indexing features of Dgraph, export the ICU_DATA variable to your ~/.bashrc or ~/.zshrc. #
# #
# echo \"export ICU_DATA=/usr/local/share/icudt58l.dat\" >> ~/.bashrc #
# echo \"export ICU_DATA=/usr/local/share/icudt58l.dat\" >> ~/.zshrc #
# #
#########################################################################################################
"
else
print_good "You already have ICU_DATA environment variable correctly set."
fi
print_instruction "Please visit https://wiki.dgraph.io/Get_Started for further instructions on usage."
}
install_dgraph "$@"