forked from openvcash/vcash-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-linux.sh
executable file
·206 lines (186 loc) · 6.26 KB
/
build-linux.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
#!/bin/bash
# Deps infos
OPENSSL_VER=1.0.2k
OPENSSL_URL=https://www.openssl.org/source/openssl-1.0.2k.tar.gz
OPENSSL_SHA=6b3977c61f2aedf0f96367dcfb5c6e578cf37e7b8d913b4ecb6643c3cb88d8c0
DB_VER=6.1.29.NC
DB_URL=https://download.oracle.com/berkeley-db/db-6.1.29.NC.tar.gz
DB_SHA=e3404de2e111e95751107d30454f569be9ec97325d5ea302c95a058f345dfe0e
BOOST_VER=1_53_0
BOOST_URL=https://sourceforge.net/projects/boost/files/boost/1.53.0/boost_1_53_0.tar.gz
BOOST_SHA=7c4d1515e0310e7f810cbbc19adb9b2d425f443cc7a00b4599742ee1bdfd4c39
# Check root or user
if (( EUID == 0 )); then
echo -e "\n- - - - - - - - - \n"
echo "You are too root for this ! Recheck README.md file." 1>&2
echo -e "\n- - - - - - - - - \n"
exit
fi
# Check thread number. Keep n-1 thread(s) if nproc >= 2
nproc=$(nproc)
if [ $nproc -eq 1 ]
then
((job=nproc))
elif [ $nproc -gt 1 ]
then
((job=nproc-1))
fi
echo "Will use $job thread(s)"
# Vcash home dir
echo "Creating ~/vcash/ dir"
mkdir -p ~/vcash/
VCASH_ROOT=$HOME/vcash/
# Remove build.log file
rm -f $VCASH_ROOT/build.log
# Backup dir
mkdir -p $VCASH_ROOT/backup/
# Check src dir & backup deps
ALL_DEPS=0
if [[ -d "$VCASH_ROOT/src" ]]; then
if [[ -d "$VCASH_ROOT/src/deps/boost" && "$VCASH_ROOT/src/deps/db" && "$VCASH_ROOT/src/deps/openssl" ]]; then
mv -f $VCASH_ROOT/src/deps/ $VCASH_ROOT/backup/
echo "Deps backed up." | tee -a $VCASH_ROOT/build.log
ALL_DEPS=1
elif [[ -d "$VCASH_ROOT/backup/deps/boost" && "$VCASH_ROOT/backup/deps/db" && "$VCASH_ROOT/backup/deps/openssl" ]]; then
echo "Deps already backed up." | tee -a $VCASH_ROOT/build.log
ALL_DEPS=1
fi
else
if [[ -d "$VCASH_ROOT/backup/deps/boost" && "$VCASH_ROOT/backup/deps/db" && "$VCASH_ROOT/backup/deps/openssl" ]]; then
echo "Deps already backed up." | tee -a $VCASH_ROOT/build.log
ALL_DEPS=1
fi
fi
# Remove src dir
echo "Clean before clone" | tee -a $VCASH_ROOT/build.log
rm -Rf $VCASH_ROOT/src/
# Check existing vcash binary
echo "Check existing binary" | tee -a $VCASH_ROOT/build.log
if [[ -f "$VCASH_ROOT/vcashd" ]]; then
BACKUP_VCASHD="vcashd-$(date +%s)"
echo "Existing vcashd binary ! Let's backup." | tee -a $VCASH_ROOT/build.log
mkdir -p $VCASH_ROOT/backup/
mv $VCASH_ROOT/vcashd $VCASH_ROOT/backup/$BACKUP_VCASHD
rm -f vcashd
fi
# Github
echo "Git clone vcash in src dir" | tee -a $VCASH_ROOT/build.log
cd $VCASH_ROOT/
git clone https://github.com/vcash-project/vcash.git src
# OpenSSL
function build_openssl {
echo "OpenSSL Install" | tee -a $VCASH_ROOT/build.log
cd $VCASH_ROOT
rm -Rf $VCASH_ROOT/src/deps/openssl/
wget $OPENSSL_URL
echo "$OPENSSL_SHA openssl-$OPENSSL_VER.tar.gz" | sha256sum -c
tar -xzf openssl-$OPENSSL_VER.tar.gz
cd openssl-$OPENSSL_VER
mkdir -p $VCASH_ROOT/src/deps/openssl/
./config threads no-comp --prefix=$VCASH_ROOT/src/deps/openssl/
make -j$job depend && make -j$job && make install && touch $VCASH_ROOT/src/deps/openssl/current_openssl_$OPENSSL_VER
# Clean
cd $VCASH_ROOT
echo "Clean after OpenSSL install" | tee -a $VCASH_ROOT/build.log
rm -Rf openssl-$OPENSSL_VER/
rm openssl-$OPENSSL_VER.tar.gz
}
# DB
function build_db {
cd $VCASH_ROOT
rm -Rf $VCASH_ROOT/src/deps/db/
wget --no-check-certificate $DB_URL
echo "$DB_SHA db-$DB_VER.tar.gz" | sha256sum -c
tar -xzf db-*.tar.gz
echo "Compile & install Berkeley DB in deps folder" | tee -a $VCASH_ROOT/build.log
cd db-$DB_VER/build_unix/
mkdir -p $VCASH_ROOT/src/deps/db/
../dist/configure --enable-cxx --disable-shared --prefix=$VCASH_ROOT/src/deps/db/
make -j$job && make install && touch $VCASH_ROOT/src/deps/db/current_db_$DB_VER
# Clean
cd $VCASH_ROOT
echo "Clean after Berkeley DB install" | tee -a $VCASH_ROOT/build.log
rm -Rf db-$DB_VER/
rm db-$DB_VER.tar.gz
}
# Boost
function build_boost {
cd $VCASH_ROOT
rm -Rf $VCASH_ROOT/src/deps/boost/
wget $BOOST_URL
echo "$BOOST_SHA boost_$BOOST_VER.tar.gz" | sha256sum -c
echo "Extract boost" | tee -a $VCASH_ROOT/build.log
tar -xzf boost_$BOOST_VER.tar.gz
echo "mv boost to deps folder & rename" | tee -a $VCASH_ROOT/build.log
mv boost_$BOOST_VER src/deps/boost
cd $VCASH_ROOT/src/deps/boost/
echo "Build boost system" | tee -a $VCASH_ROOT/build.log
./bootstrap.sh
./bjam -j$job link=static toolset=gcc cxxflags=-std=gnu++0x --with-system release &
touch $VCASH_ROOT/src/deps/boost/current_boost_$BOOST_VER
# Clean
cd $VCASH_ROOT
echo "Clean after Boost install" | tee -a $VCASH_ROOT/build.log
rm boost_$BOOST_VER.tar.gz
}
if [[ $ALL_DEPS == 1 ]]; then
mv $VCASH_ROOT/backup/deps/boost/ $VCASH_ROOT/src/deps/
# Temp
if ! [[ -f "$VCASH_ROOT/src/deps/boost/current_boost_$BOOST_VER" ]]; then
touch $VCASH_ROOT/src/deps/boost/current_boost_$BOOST_VER
fi
mv $VCASH_ROOT/backup/deps/db/ $VCASH_ROOT/src/deps/
mv $VCASH_ROOT/backup/deps/openssl/ $VCASH_ROOT/src/deps/
rm -Rf $VCASH_ROOT/backup/deps/
echo "Deps restored." | tee -a $VCASH_ROOT/build.log
else
build_openssl
build_db
build_boost
fi
# Deps upgrade ?
if ! [[ -f "$VCASH_ROOT/src/deps/openssl/current_openssl_$OPENSSL_VER" ]]; then
build_openssl
fi
if ! [[ -f "$VCASH_ROOT/src/deps/db/current_db_$DB_VER" ]]; then
build_db
fi
if ! [[ -f "$VCASH_ROOT/src/deps/boost/current_boost_$BOOST_VER" ]]; then
build_boost
fi
# Vcash daemon
echo "vcashd bjam build" | tee -a $VCASH_ROOT/build.log
cd $VCASH_ROOT/src/coin/test/
../../deps/boost/bjam -j$job toolset=gcc cxxflags=-std=gnu++0x release | tee -a $VCASH_ROOT/build.log
cd $VCASH_ROOT/src/coin/test/bin/gcc-*/release/link-static/
STACK_OUT=$(pwd)
if [[ -f "$STACK_OUT/stack" ]]; then
echo "vcashd built !" | tee -a $VCASH_ROOT/build.log
strip $STACK_OUT/stack
cp $STACK_OUT/stack $VCASH_ROOT/vcashd
# Check if vcashd is running
RESTART=0
pgrep -l vcashd && RESTART=1
else
cd $VCASH_ROOT/src/coin/test/
echo "vcashd building error..."
exit
fi
# Start or restart
cd $VCASH_ROOT
if [[ $RESTART == 1 ]]; then
echo -e "\n- - - - - - - - - \n"
echo " ! Previous Vcash daemon is still running !"
echo -e "\n- - - - - - - - - \n"
echo " Please kill the process & start the fresh vcashd with:"
echo " cd ~/vcash/ && screen -d -S vcashd -m ./vcashd"
echo -e "\n- - - - - - - - - \n"
else
screen -d -S vcashd -m ./vcashd
echo -e "\n- - - - - - - - - \n"
echo " Vcash daemon launched in a screen session. To switch:"
echo -e "\n- - - - - - - - - \n"
echo " screen -x vcashd"
echo " Ctrl-a Ctrl-d to detach without kill the daemon"
echo -e "\n- - - - - - - - - \n"
fi