-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathinstall.sh
executable file
·300 lines (262 loc) · 9.98 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
set -u
# enable command completion
set -o history -o histexpand
python="python3"
abort() {
printf "%s\n" "$1"
exit 1
}
getc() {
local save_state
save_state=$(/bin/stty -g)
/bin/stty raw -echo
IFS= read -r -n 1 -d '' "$@"
/bin/stty "$save_state"
}
exit_on_error() {
exit_code=$1
last_command=${@:2}
if [ $exit_code -ne 0 ]; then
>&2 echo "\"${last_command}\" command failed with exit code ${exit_code}."
exit $exit_code
fi
}
wait_for_user() {
local c
echo
echo "Press RETURN to continue or any other key to abort"
getc c
# we test for \r and \n because some stuff does \r instead
if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then
exit 1
fi
}
shell_join() {
local arg
printf "%s" "$1"
shift
for arg in "$@"; do
printf " "
printf "%s" "${arg// /\ }"
done
}
# string formatters
if [[ -t 1 ]]; then
tty_escape() { printf "\033[%sm" "$1"; }
else
tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;$1"; }
tty_underline="$(tty_escape "4;39")"
tty_blue="$(tty_mkbold 34)"
tty_red="$(tty_mkbold 31)"
tty_bold="$(tty_mkbold 39)"
tty_reset="$(tty_escape 0)"
ohai() {
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
}
# Things can fail later if `pwd` doesn't exist.
# Also sudo prints a warning message for no good reason
cd "/usr" || exit 1
linux_install_pre() {
sudo apt-get update
sudo apt-get install --no-install-recommends --no-install-suggests -y apt-utils curl git cmake build-essential
exit_on_error $?
}
linux_install_python() {
which $python
if [[ $? != 0 ]] ; then
ohai "Installing python"
sudo apt-get install --no-install-recommends --no-install-suggests -y $python
else
ohai "Updating python"
sudo apt-get install --only-upgrade $python
fi
exit_on_error $?
ohai "Installing python tools"
sudo apt-get install --no-install-recommends --no-install-suggests -y $python-pip $python-dev
exit_on_error $?
}
linux_update_pip() {
PYTHONPATH=$(which $python)
ohai "You are using python@ $PYTHONPATH$"
ohai "Installing python tools"
$python -m pip install --upgrade pip
}
linux_install_bittensor() {
ohai "Cloning bittensor@master into ~/.bittensor/bittensor"
mkdir -p ~/.bittensor/bittensor
git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard ; git clean -xdf)
ohai "Installing bittensor"
$python -m pip install -e ~/.bittensor/bittensor/
$python -m pip install -U bittensor-cli
exit_on_error $?
}
linux_increase_ulimit(){
ohai "Increasing ulimit to 1,000,000"
prlimit --pid=$PPID --nofile=1000000
}
mac_install_xcode() {
which -s xcode-select
if [[ $? != 0 ]] ; then
ohai "Installing xcode:"
xcode-select --install
exit_on_error $?
fi
}
mac_install_brew() {
which -s brew
if [[ $? != 0 ]] ; then
ohai "Installing brew:"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
ohai "Updating brew:"
brew update --verbose
fi
exit_on_error $?
}
mac_install_cmake() {
which -s cmake
if [[ $? != 0 ]] ; then
ohai "Installing cmake:"
brew install cmake
else
ohai "Updating cmake:"
brew upgrade cmake
fi
}
mac_install_python() {
which -s python3
ohai "Installing python3"
brew list python@3 &>/dev/null || brew install python@3;
ohai "Updating python3"
brew upgrade python@3
exit_on_error $?
}
mac_update_pip() {
PYTHONPATH=$(which $python)
ohai "You are using python@ $PYTHONPATH$"
ohai "Installing python tools"
$python -m pip install --upgrade pip
}
mac_install_bittensor() {
ohai "Cloning bittensor into ~/.bittensor/bittensor"
git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard; git clean -xdf)
ohai "Installing bittensor"
$python -m pip install -e ~/.bittensor/bittensor/
$python -m pip install -U bittensor-cli
exit_on_error $?
deactivate
}
# Do install.
OS="$(uname)"
if [[ "$OS" == "Linux" ]]; then
which -s apt-get
if [[ $? == 0 ]] ; then
abort "This linux based install requires apt-get. To run with other distros (centos, arch, etc), you will need to manually install the requirements"
fi
echo """
██████╗░██╗████████╗████████╗███████╗███╗░░██╗░██████╗░█████╗░██████╗░
██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗░██║██╔════╝██╔══██╗██╔══██╗
██████╦╝██║░░░██║░░░░░░██║░░░█████╗░░██╔██╗██║╚█████╗░██║░░██║██████╔╝
██╔══██╗██║░░░██║░░░░░░██║░░░██╔══╝░░██║╚████║░╚═══██╗██║░░██║██╔══██╗
██████╦╝██║░░░██║░░░░░░██║░░░███████╗██║░╚███║██████╔╝╚█████╔╝██║░░██║
╚═════╝░╚═╝░░░╚═╝░░░░░░╚═╝░░░╚══════╝╚═╝░░╚══╝╚═════╝░░╚════╝░╚═╝░░╚═╝
- Mining a new element.
"""
ohai "This script will install:"
echo "git"
echo "curl"
echo "cmake"
echo "build-essential"
echo "python3"
echo "python3-pip"
echo "bittensor"
wait_for_user
linux_install_pre
linux_install_python
linux_update_pip
linux_install_bittensor
ohai "Would you like to increase the ulimit? This will allow your miner to run for a longer time"
wait_for_user
linux_increase_ulimit
echo ""
echo ""
echo "######################################################################"
echo "## ##"
echo "## BITTENSOR SETUP ##"
echo "## ##"
echo "######################################################################"
echo ""
echo ""
elif [[ "$OS" == "Darwin" ]]; then
echo """
██████╗░██╗████████╗████████╗███████╗███╗░░██╗░██████╗░█████╗░██████╗░
██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗░██║██╔════╝██╔══██╗██╔══██╗
██████╦╝██║░░░██║░░░░░░██║░░░█████╗░░██╔██╗██║╚█████╗░██║░░██║██████╔╝
██╔══██╗██║░░░██║░░░░░░██║░░░██╔══╝░░██║╚████║░╚═══██╗██║░░██║██╔══██╗
██████╦╝██║░░░██║░░░░░░██║░░░███████╗██║░╚███║██████╔╝╚█████╔╝██║░░██║
╚═════╝░╚═╝░░░╚═╝░░░░░░╚═╝░░░╚══════╝╚═╝░░╚══╝╚═════╝░░╚════╝░╚═╝░░╚═╝
- Mining a new element.
"""
ohai "This script will install:"
echo "xcode"
echo "homebrew"
echo "git"
echo "cmake"
echo "python3"
echo "python3-pip"
echo "bittensor"
wait_for_user
mac_install_brew
mac_install_cmake
mac_install_python
mac_update_pip
mac_install_bittensor
echo ""
echo ""
echo "######################################################################"
echo "## ##"
echo "## BITTENSOR SETUP ##"
echo "## ##"
echo "######################################################################"
else
abort "Bittensor is only supported on macOS and Linux"
fi
# Use the shell's audible bell.
if [[ -t 1 ]]; then
printf "\a"
fi
echo ""
echo ""
ohai "Welcome. Installation successful"
echo ""
echo "- 1. Create a wallet "
echo " $ btcli w new_coldkey # (for holding funds)"
echo " $ btcli w new_hotkey # (for running miners)"
echo ""
echo "- 2. Run a miner on the prompting network. "
echo " $ python3 ~/.bittensor/bittensor/neurons/text/prompting/miners/gpt4all/neuron.py"
echo ""
ohai "Extras:"
echo ""
echo "- Check your tao balance: "
echo " $ btcli w overview"
echo ""
echo "- Stake to your miners:"
echo " $ btcli stake add"
echo " $ btcli stake remove"
echo ""
echo "- Create/list/register wallets"
echo " $ btcli w new_coldkey"
echo " $ btcli w new_hotkey"
echo " $ btcli w list"
echo " $ btcli s register"
echo ""
echo "- Use the Python API"
echo " $ python3"echo " >> import bittensor"
echo ""
echo "- Join the discussion: "
echo " ${tty_underline}https://discord.gg/3rUr6EcvbB${tty_reset}"
echo ""