-
Notifications
You must be signed in to change notification settings - Fork 0
/
steembootstrap.sh.template
188 lines (149 loc) · 5.14 KB
/
steembootstrap.sh.template
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
#!/usr/bin/env bash
set -x
PROGNAME=$(basename $0)
# Settings
STEEM_REPO="https://github.com/steemit/steem"
MODE=build_and_install
LOG_FILE=/tmp/steembootstrap.log
# Build Options
BUILD_OPTIONS="-DCMAKE_BUILD_TYPE=Release"
BUILD_THREADS=1
{ # this ensures the entire script is downloaded #
# Setup logging output of each command to log file
BASEDIR=""
function cleanup
{
exec 2>&4 1>&3
[ ! -z $BASEDIR ] && rm -rf $BASEDIR
}
function error_exit
{
echo "${PROGNAME}: ERROR - ${1:-"Unknown Error"}" >&4
exit 1
}
function print_info
{
bold=`tput bold`
reset=`tput sgr0`
echo "${bold}$1${reset}" >&3
}
function print_warn
{
bold=`tput dim`
reset=`tput sgr0`
echo "${bold}WARN: $1${reset}" >&4
}
exec 3>&1 4>&2
exec 1>$LOG_FILE 2>&1
trap cleanup EXIT INT TERM QUIT
# Parsing arguments
if [ ! -z $1 ]; then
[ x"build_only" == x"$1" ] && MODE=build_only
fi
print_info "* Checking System"
# Only works on Ubuntu
os=`cat /etc/lsb-release 2>/dev/null| grep DISTRIB_ID | cut -d'=' -f2 | tr '[:upper:]' '[:lower:]'`
if [[ "x$os" != "xubuntu" ]]; then
error_exit "Unsupported OS"
fi
# Test Physical Memory
phymem=$(free|awk '/^Mem:/{print $2}')
phymem=$((phymem/1000000))
if (( phymem < 4 )); then
error_exit "You have no enough Physical Memory (min: 4Gb)"
elif (( phymem < 16 )); then
print_warn "You have Physical Memory < 16Gb, will build LOW_MEMORY_NODE"
BUILD_OPTIONS="$BUILD_OPTIONS -DLOW_MEMORY_NODE=ON -DCLEAR_VOTES=ON"
fi
# Get number of processors
cpunum=$(getconf _NPROCESSORS_ONLN)
# There are required 3gb per compiling thread
possible_threads=$((phymem/3))
BUILD_THREADS=$((possible_threads<cpunum?possible_threads:cpunum))
BASEDIR=`mktemp -d`
if [ $? -ne 0 ]; then
error_exit "Cannot create tempopary directory"
fi
pushd $BASEDIR >/dev/null
# Unpack contribute files
base64 -d <<CONTRIBEOF | tar xz
##CONTRIBBASE64##
CONTRIBEOF
# Check if required packages are not installed
print_info " - Checking Required Packages"
pkgs_to_install=""
for pkg in git cmake g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev libboost-all-dev libssl-dev libncurses5-dev doxygen libreadline-dev dh-autoreconf build-essential; do
pkg_ok=no
dpkg-query -W --showformat='${Status}\n' $pkg | grep "install ok installed" > /dev/null && pkg_ok=yes
print_info " - - Checking For $pkg: $pkg_ok"
if [ x"no" == x"$pkg_ok" ]; then
pkgs_to_install="$pkgs_to_install $pkg"
fi
done
# If found missed packages - install
if [ x"" != x"$pkgs_to_install" ]; then
print_info ""
print_info " - - Next packages will be installed: $pkgs_to_install."
print_info " - - This operation requires root privileges."
print_info ""
sudo apt-get update || :
sudo apt-get install -y $pkgs_to_install || error_exit "Cannot Install Required Packages"
fi
# Upgrade system (not sure)
# apt-get -y upgrade
##################################
# Building Steem Node
##################################
print_info "* Building Steem"
# Create folder for installing node
DEB_PATH=$BASEDIR/package/steem
STEEM_PATH=$BASEDIR/package/steem/opt/steem
mkdir -p $DEB_PATH
mkdir -p $STEEM_PATH
# Clone Steem
print_info " - Downloading Source Code"
git clone $STEEM_REPO || error_exit "Cannot clone sources"
cd steem
git checkout master
git submodule update --init --recursive
# Build
print_info " - Compiling"
cmake $BUILD_OPTIONS . || error_exit "Cannot configure project"
make -j$BUILD_THREADS || error_exit "Cannot compile project"
# Preparing steemnode package
print_info " - Copying Files For Packaging"
install -m 0755 programs/steemd/steemd $STEEM_PATH/
install -m 0755 programs/cli_wallet/cli_wallet $STEEM_PATH
cd ..
# Copying contrib files to package
mkdir $STEEM_PATH/witness_node_data_dir
cp $BASEDIR/contrib/config.ini $STEEM_PATH/witness_node_data_dir/config.ini
mkdir -p $DEB_PATH/lib/systemd/system
cp $BASEDIR/contrib/steemd.service $DEB_PATH/lib/systemd/system/
cp -r $BASEDIR/contrib/debian $DEB_PATH/DEBIAN
# Fixing package version
STEEM_VERSION=$(cat $BASEDIR/steem/libraries/protocol/include/steemit/protocol/config.hpp | grep -m 1 STEEMIT_BLOCKCHAIN_VERSION | grep -oP '(\d+(, )?){3}' | sed 's/, /./g')
UNIXTIME=$(date +%s)
sed -i "s/##STEEM_VERSION##/$STEEM_VERSION/" $DEB_PATH/DEBIAN/control
sed -i "s/##UNIXTIME##/$UNIXTIME/" $DEB_PATH/DEBIAN/control
# Make deb package
print_info "* Packaging"
fakeroot dpkg-deb --build $DEB_PATH || error_exit "Cannot make DEB"
mv $DEB_PATH/../steem.deb /tmp/steem-$STEEM_VERSION-$UNIXTIME.deb
if [ x"$MODE" == x"build_and_install" ]; then
print_info "* Installing Steem (requires root privileges)"
sudo dpkg -i /tmp/steem-$STEEM_VERSION-$UNIXTIME.deb || error_exit "Cannot install package"
fi
print_info "* DONE"
print_info
print_info
print_info "###############################################################"
print_info "# DEB package path: /tmp/steem-${STEEM_VERSION}-${UNIXTIME}.deb"
print_info "#"
print_info "# To run steemd use: sudo systemctl start steemd"
print_info "# To check steemd use: sudo systemctl status steemd"
print_info "# To stop steemd use: sudo systemctl stop steemd"
print_info "# Steem path: /opt/steem"
print_info "###############################################################"
popd > /dev/null # basedir
} # this ensures the entire script is downloaded #