forked from stacks-network/stacks-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_started.sh
More file actions
executable file
·137 lines (103 loc) · 4.02 KB
/
get_started.sh
File metadata and controls
executable file
·137 lines (103 loc) · 4.02 KB
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
#!/bin/sh
BLOCKSTACK_VERSION="0.14.1"
VENV_DIR="$(pwd)/blockstack-$BLOCKSTACK_VERSION"
LOGPATH="/tmp/blockstack_${BLOCKSTACK_VERSION}_get_started.log"
echo "Welcome to Blockstack!"
echo "----------------------"
echo "This script will install Blockstack to a virtual environment at $VENV_DIR."
echo "A log of this script will be stored to $LOGPATH."
echo -n "Proceed? (Y/n) "
read YN
if [ -z "$YN" ] || [ "$YN" = "n" ] || [ "$YN" = "N" ]; then
echo "Exiting..."
exit 0
fi
logecho() {
echo "$(date) $1" >> "$LOGPATH"
echo "$(date) $1"
}
exit_with_error() {
logecho "$1" >&2
# exit the virtualenv as well
type deactivate | grep "shell function" && deactivate
exit 1
}
find_header() {
HEADER_FILE="$1"
logecho "Find header $HEADER_FILE"
for HEADER_DIR in "/usr/include" "/usr/local/include" $2; do
test -f "$HEADER_DIR"/"$HEADER_FILE"
if [ $? -eq 0 ]; then
logecho "Found $HEADER_FILE at $HEADER_DIR/$HEADER_FILE"
return 0
fi
done
return 1
}
find_library() {
LIBRARY_PREFIX="$1"
logecho "Find library $LIBRARY_PREFIX"
for LIBRARY_DIR in "/lib" "/usr/lib" "/usr/local/lib" $2; do
ls "$LIBRARY_DIR"/"$LIBRARY_PREFIX".* >/dev/null 2>&1
if [ $? -eq 0 ]; then
logecho "Found $LIBRARY_PREFIX at $LIBRARY_DIR/$LIBRARY_PREFIX"
return 0
fi
done
return 1
}
exit_missing_sysdep() {
exit_with_error "$1 is required. You can install it with your system package manager."
}
exit_missing_executable() {
INSTALL_WITH="$2"
if [ -z "$INSTALL_WITH" ]; then
INSTALL_WITH="your system package manager"
fi
exit_with_error "Could not find '$1' executable. You can install it with $INSTALL_WITH"
}
logecho "Begin Blockstack installation to $VENV_DIR"
# sanity check
test -d "$VENV_DIR" && exit_with_error "Directory $VENV_DIR already exists. Please remove it and try again."
# do some heuristics
# should have Python 2.7.x
test -x "$(which python2)" || exit_missing_executable "Python"
python2 --version 2>&1 | grep "2.7" >/dev/null || exit_missing_executable "Python2.7"
# should have pip >= 9.0.1
test -x "$(which pip)" || exit_missing_executable "pip"
# need pip >= 9.0.1
pip --version 2>&1 | grep "9.0" >/dev/null || exit_missing_executable "pip" "'pip install --upgrade pip'"
# should have virtualenv
test -x "$(which virtualenv)" || exit_missing_executable "virtualenv" "'pip install virtualenv'"
# need libpython-dev
find_header "python2.7/Python.h" || exit_missing_sysdep "python-dev"
# need libgmp
find_library "libgmp.so" || exit_missing_sysdep "libgmp"
# need libgmp-dev
find_header "gmp.h" || exit_missing_sysdep "libgmp-dev"
# need libssl
find_library "libssl.so" || exit_missing_sysdep "libssl"
# need libcrypto
find_library "libcrypto.so" || exit_missing_sysdep "libcrypto"
# need libssl-dev
find_header "openssl/crypto.h" || exit_missing_sysdep "libssl-dev"
# need libffi
find_library "libffi.so" || exit_missing_sysdep "libffi"
# need libffi-dev.
# can be in /usr/lib/libffi-VERSION/include on some systems
find_header "ffi.h" "/usr/lib/libffi-*/include" || exit_missing_sysdep "libffi-dev"
mkdir "$VENV_DIR" || exit_with_error "Failed to make directory $VENV_DIR"
virtualenv "$VENV_DIR" 2>&1 | tee -a "$LOGPATH"
if [ $? -ne 0 ]; then
exit_with_error "Failed to set up virtualenv. Logfile in $LOGPATH"
fi
source "$VENV_DIR"/bin/activate || exit_with_error "Failed to activate virtualenv. Logfile in $LOGPATH"
pip install blockstack 2>&1 | tee -a "$LOGPATH" || exit_with_error "Failed to install blockstack. Logfile in $LOGPATH"
# test blockstack
test -x "$(which blockstack)" || exit_with_error "Failed to find installed blockstack program. Logfile in $LOGPATH"
blockstack --version 2>/dev/null | grep "$BLOCKSTACK_VERSION" >/dev/null || exit_with_error "Could not find blockstack $BLOCKSTACK_VERSION. Logfile in $LOGPATH."
logecho "Blockstack $BLOCKSTACK_VERSION installed to $VENV_DIR."
echo ""
echo "Success! Activate virtualenv with 'source $VENV_DIR/bin/activate' to run 'blockstack'"
echo ""
exit 0