-
Notifications
You must be signed in to change notification settings - Fork 17
/
install.sh
executable file
·205 lines (178 loc) · 6.84 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
# Script that downloads the sgr client, adds a default engine and (optionally)
# registers the user on Splitgraph Cloud.
#
# Works on Linux/OSX:
#
# bash -c "$(curl -sL https://github.com/splitgraph/sgr/releases/latest/download/install.sh)"
#
# For other installation methods, including Windows/pip/docker-compose, see
# https://www.splitgraph.com/docs/installation/.
set -eo pipefail
SGR_VERSION=${SGR_VERSION-0.3.12}
INSTALL_DIR=${INSTALL_DIR-$HOME/.splitgraph}
# Set IGNORE_SGR_EXISTS to keep going if sgr already exists.
# Set SKIP_BINARY=1 to skip downloading sgr
# Set SKIP_ENGINE=1 to skip setting up the engine.
BINARY=
ENGINE_PORT=${ENGINE_PORT-6432}
CLOUD_SKIPPED=
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
bold=$(tput bold)
blue=$(tput setaf 4)
bblue=$(tput bold)${blue}
end=$(tput sgr0)
cyan=$(tput setaf 6)
red=$(tput setaf 1)
green=$(tput setaf 2)
fi
_die() {
echo "${red}Fatal:${end} $@"
exit 1
}
_check_sgr_exists() {
set +e
current_sgr=$(sgr --version 2>/dev/null)
ret=$?
set -e
if [ $ret == 0 ]; then
if [ -n "$IGNORE_SGR_EXISTS" ]; then
echo "$current_sgr already exists on this machine. Continuing anyway."
else
_die "$current_sgr already exists on this machine. You can upgrade it with sgr upgrade or rerun this with IGNORE_SGR_EXISTS=1 to ignore this message"
fi
fi
}
_get_binary_name() {
os=$(uname)
architecture=$(uname -m)
if [ "$architecture" != x86_64 ]; then
_die "Single binary method method only supported on x64 architectures. Please see https://www.splitgraph.com/docs/installation/ for other installation methods."
fi
if [ "$os" == Linux ]; then
BINARY="sgr-linux-x86_64"
elif [ "$os" == Darwin ]; then
if [ -n "$FORCE_ONEFILE" ] ; then
echo "Forcing --onefile installation on OS X because \$FORCE_ONEFILE is set."
BINARY="sgr-osx-x86_64"
else
# OS X has bad single-file executable support (pyinstaller --onefile), so we default to --onedir variant
echo "Installing optimized package for OS X (built with pyinstaller --onedir instead of --onefile)"
echo "To force install single-file executable (not recommended), set FORCE_ONEFILE=1"
BINARY="sgr-osx-x86_64.tgz"
fi
else
_die "This installation method only supported on Linux/OSX. Please see https://www.splitgraph.com/docs/installation/ for other installation methods."
fi
}
_install_binary () {
if [ -n "$SKIP_BINARY" ]; then
echo "Skipping sgr installation as \$SKIP_BINARY is set."
return
fi
_check_sgr_exists
URL="https://github.com/splitgraph/sgr/releases/download/v${SGR_VERSION}"/$BINARY
# on OS X, splitgraph.spec is called with --onedir to output .tgz of exe and shlibs
if [ "$BINARY" == "sgr-osx-x86_64.tgz" ] ; then
echo "Installing the compressed sgr binary and deps from $URL into $INSTALL_DIR"
echo "Installing sgr binary and deps into $INSTALL_DIR/pkg"
if [ -d "$INSTALL_DIR/pkg/sgr" ] ; then
echo "Removing existing $INSTALL_DIR/pkg/sgr"
rm -rf "$INSTALL_DIR/pkg/sgr"
fi
mkdir -p "$INSTALL_DIR/pkg/sgr"
curl -fsL "$URL" > "$INSTALL_DIR/pkg/sgr/sgr.tgz"
echo "Extract sgr binary and deps into $INSTALL_DIR/pkg/sgr (necessary on MacOS)"
(cd "$INSTALL_DIR"/pkg/sgr && tar xfz sgr.tgz && rm sgr.tgz)
echo "Main sgr binary is at $INSTALL_DIR/pkg/sgr/sgr"
echo "Link $INSTALL_DIR/sgr -> $INSTALL_DIR/pkg/sgr/sgr"
ln -fs "$INSTALL_DIR"/pkg/sgr/sgr "$INSTALL_DIR"/sgr
else
echo "Installing the sgr binary from $URL into $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
curl -fsL "$URL" > "$INSTALL_DIR/sgr"
chmod +x "$INSTALL_DIR/sgr"
fi
"$INSTALL_DIR/sgr" --version && echo "sgr binary installed." && echo && return 0
_die "Installation apparently failed. got non-zero exit code from: $INSTALL_DIR/sgr --version"
}
_setup_engine() {
if [ -n "$SKIP_ENGINE" ]; then
echo "Skipping engine setup as \$SKIP_ENGINE is set."
return
fi
if ! docker info > /dev/null 2>&1; then
_die "Docker doesn't appear to be running on this machine. Adding Splitgraph to existing PostgreSQL installations is currently unsupported."
fi
echo "Setting up a Splitgraph engine."
echo "The engine will be set up with default credentials:"
echo "${blue}"
echo "username: sgr"
echo "password: password"
echo "port: ${ENGINE_PORT}"
echo "${end}"
echo "These credentials are just for this local Postgres installation"
echo "and can be changed after install."
echo
"$INSTALL_DIR/sgr" engine add --password password --port "${ENGINE_PORT}" || (
_die "Error setting up the engine. If an engine already exists, you can skip this step by setting \$SKIP_ENGINE=1. In case of a port conflict, you can restart the installer with ENGINE_PORT set to some other port."
)
"$INSTALL_DIR/sgr" engine version
"$INSTALL_DIR/sgr" status
echo "Engine successfully set up."
echo
}
_register_cloud() {
echo
echo "You can now register on data.splitgraph.com (the registry)."
echo "This lets you push/pull datasets and use public data to build"
echo "your own datasets using Splitfiles."
echo
echo "If you do not wish to register now, you can do it later via"
echo "${green}sgr cloud register${end} or log in through ${green}sgr cloud login${end} / GitHub OAuth."
echo
read -p "Would you like to register now [y/N]? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$INSTALL_DIR/sgr" cloud register
else
CLOUD_SKIPPED=1
fi
}
_welcome() {
echo
echo "${green}${bold}Installation complete!${end}"
echo
echo "sgr $SGR_VERSION has been installed to ${blue}$INSTALL_DIR/sgr${end}."
echo "Your configuration file is located at ${blue}$INSTALL_DIR/.sgconfig${end}."
echo "Make sure to add sgr to your \$PATH, for example by doing:"
echo
echo " ${blue}sudo ln -s $INSTALL_DIR/sgr /usr/local/bin/sgr${end}"
echo
echo
echo "Next steps: "
echo
echo " Check out the example projects"
echo " ${bblue}https://github.com/splitgraph/sgr/tree/v$SGR_VERSION/examples${end}"
echo
echo " Try out the quickstart guide"
echo " ${bblue}https://www.splitgraph.com/docs/getting-started/five_minute_demo${end}"
echo
echo " Clone a dataset"
echo " ${bblue}sgr clone splitgraph/domestic_us_flights${end}"
echo
echo " Or inspect it without cloning it"
echo " ${bblue}sgr table -r data.splitgraph.com splitgraph/domestic_us_flights:latest flights${end}"
echo
echo " Build your own dataset using a Splitfile"
echo " ${bblue}curl -sSL https://raw.githubusercontent.com/splitgraph/splitgraph/v$SGR_VERSION/examples/us-election/qoz_vote_fraction.splitfile \\"
echo " | sgr build - -o qoz_vote_fraction${end}"
echo
echo "Feedback is always welcome via GitHub issues (${bblue}https://github.com/splitgraph/sgr/issues${end})"
echo "or email (${bblue}[email protected]${end})!"
}
_get_binary_name
_install_binary
_setup_engine
_register_cloud
_welcome