-
Notifications
You must be signed in to change notification settings - Fork 166
/
setup-intersango.sh
289 lines (231 loc) · 7.92 KB
/
setup-intersango.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
# command history to setup Intersango on Amazon Linux AMI
# some command responses are prefixed with “##”
### get the current version of this script by running:
# GET https://raw.github.com/dooglus/intersango/pp/setup-intersango.sh > intersango.sh
# or, if we want to fix the SITE_HOST_NAME at the same time:
# GET https://raw.github.com/dooglus/intersango/pp/setup-intersango.sh | sed "s|^SITE_HOST_NAME=.*|SITE_HOST_NAME='ec2-50-17-107-240.compute-1.amazonaws.com'|" > intersango.sh
########################################################################
# passwords
# bitcoind username
BITCOIN_PW='frank45$lin'
# mysql root password
MYSQL_ROOT_PW='benjamin22%'
# password to connect Intersango database
MYSQL_INTERSANGO_PW='benjamin22%'
# passphrase to encrypt wallet backups
BITCOIN_WALLET_BACKUP_PP="iZ-QTlng ungue5bl3 [email protected] fUr wa1'utbkup"
# duo setup - to register, visit http://www.duosecurity.com/pricing
# then fill in form on right, follow the signup process, verify account,
# and create a new itegration of type 'Web SDK'
DUO_SECRET_STRING='sdfieruhy8yiuhgifhuvhw8gyg92fy3287tjbhpoergio'
DUO_INTEGRATION_KEY='DIB1AA2XQZ52AWNRZK1U'
DUO_SECRET_KEY='WMHwNR52u4suB2UC8cXc4ooPbJpa689F0775YCqU'
DUO_API_HOSTNAME='api-afdc7efd.duosecurity.com'
# other parameters
# bitcoind username
BITCOIN_USER='benjamin33!'
# username to connect Intersango database
MYSQL_INTERSANGO_USER='intersango'
# Intersango database's name
MYSQL_INTERSANGO_DBNAME='intersango'
# Linux username for Intersango user
SYSTEM_INTERSANGO_USER='intersango'
# server URL without http://
SITE_HOST_NAME='ec2-54-247-132-226.eu-west-1.compute.amazonaws.com'
# if we want to download a recent copy of the blockchain, put the URL here (with neither filename nor trailing slash)
# else leave it empty (BLOCKCHAIN_URL='')
BLOCKCHAIN_URL='https://s3.amazonaws.com/ppbtcblockchain'
# BLOCKCHAIN_URL=''
# is this a 32 or 64 bit instance?
OS_BITS=64
########################################################################
# install Apache
echo Installing Apache ...
yum -y install httpd
##Complete!
# enable Apache start on boot
echo Enabling Apache start on boot ...
chkconfig httpd on
# start Apache
echo Starting Apache ...
service httpd start
##Starting httpd: [ OK ]
# install PHP
echo Installing PHP and modules ...
yum -y install php php-mysql php-bcmath
##Complete!
# install git
echo Installing git ...
yum -y install git
##Complete!
# create intersango user
adduser $SYSTEM_INTERSANGO_USER
chmod 701 /home/$SYSTEM_INTERSANGO_USER
passwd --lock $SYSTEM_INTERSANGO_USER
##passwd: Success
# set up .bashrc, .gitconfig, etc.
su - $SYSTEM_INTERSANGO_USER <<EOF
cat >> .bashrc <<EOF2
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias bc='~/bin/bitcoind'
alias df='df -h'
alias i='cd ~/intersango'
alias l='ls -l'
alias la='ls -al'
alias lh='ls -lh'
alias lt='ls -altr | tail -20'
alias pull='pushd ~/intersango; git stash && git pull && git stash apply; popd'
alias sa='. ~/.bashrc'
alias sql='mysql -u $MYSQL_INTERSANGO_USER --password="$MYSQL_INTERSANGO_PW" $MYSQL_INTERSANGO_DBNAME'
EOF2
cat > .gitconfig <<EOF2
[core]
pager = cat
[alias]
co = checkout
br = branch
ci = commit
tree = log --date=local --pretty='format:%h %ad %s' --decorate --graph
[user]
email = [email protected]
name = intersango
EOF2
EOF
# clone Intersango code
su - $SYSTEM_INTERSANGO_USER <<EOF
echo Cloning Intersango code ...
git clone git://github.com/dooglus/intersango.git
cd intersango
git checkout pp
cd backups
touch db.txt
git init
git add -f db.txt
EOF
##Resolving deltas: 100% (2953/2953), done.
# install Mysql
echo Installing Mysql ...
yum -y install mysql-server
##Complete!
# enable Mysql start on boot
echo Enabling Mysql start on boot ...
chkconfig mysqld on
# start Mysql
echo Starting Mysql ...
service mysqld start
##Starting mysqld: [ OK ]
# secure Mysql
echo Securing Mysql ...
/usr/bin/mysql_secure_installation <<COMMANDS
Y
$MYSQL_ROOT_PW
$MYSQL_ROOT_PW
Y
Y
Y
Y
COMMANDS
# set up timezones in MySQL
echo Setting up MySQL timezones ...
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql --password="$MYSQL_ROOT_PW"
## Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
# create Intersango database in Mysql
echo Creating Intersango database ...
mysql -u root mysql --password=$MYSQL_ROOT_PW <<COMMANDS
create database $MYSQL_INTERSANGO_DBNAME;
create user $MYSQL_INTERSANGO_USER identified by '$MYSQL_INTERSANGO_PW';
grant all privileges on $MYSQL_INTERSANGO_DBNAME.* to $MYSQL_INTERSANGO_USER with grant option;
quit
COMMANDS
# set up database schema in Intersango Mysql database
echo Setting up Intersango database schema ...
mysql -u $MYSQL_INTERSANGO_USER --password="$MYSQL_INTERSANGO_PW" $MYSQL_INTERSANGO_DBNAME < ~intersango/intersango/DATABASE
# download and symlink to bitcoin executable
echo Downloading bitcoind executable
su - $SYSTEM_INTERSANGO_USER <<EOF
wget -O- http://voxel.dl.sourceforge.net/project/bitcoin/Bitcoin/bitcoin-0.6.0/bitcoin-0.6.0-linux.tar.gz | tar xfz -
mkdir bin
ln -s ../bitcoin-0.6.0-linux/bin/$OS_BITS/bitcoind bin/bitcoind
EOF
##2012-03-08 21:11:48 (6.43 MB/s) - written to stdout [9903046/9903046]
# configure bitcoind, download blockchain if configured to do so
echo Configuring bitcoind
su - $SYSTEM_INTERSANGO_USER <<EOF
mkdir -p .bitcoin
echo "$BITCOIN_WALLET_BACKUP_PP" > .bitcoin/pp
cat > ~/.bitcoin/bitcoin.conf <<EOF2
rpcuser=$BITCOIN_USER
rpcpassword=$BITCOIN_PW
EOF2
if [ -n "$BLOCKCHAIN_URL" ]
then
for i in blk0001.dat blkindex.dat
do
wget -O .bitcoin/\$i "$BLOCKCHAIN_URL/\$i"
done
fi
EOF
# configure Intersango
echo Configuring Intersango
su - $SYSTEM_INTERSANGO_USER <<EOF
touch intersango/log{,-{problem,error,bad-page}}.txt
chmod o+w intersango/{docs,log{,-{problem,error,bad-page}}.txt,locks}
cat > db.intersango.sh <<EOF2
MYSQL_INTERSANGO_USER='$MYSQL_INTERSANGO_USER'
MYSQL_INTERSANGO_PW='$MYSQL_INTERSANGO_PW'
MYSQL_INTERSANGO_DBNAME='$MYSQL_INTERSANGO_DBNAME'
USER='$SYSTEM_INTERSANGO_USER'
EOF2
cat > db.intersango.inc <<EOF2
<?php
mysql_connect('localhost', '$MYSQL_INTERSANGO_USER', '$MYSQL_INTERSANGO_PW') or die(mysql_error());
mysql_select_db('$MYSQL_INTERSANGO_DBNAME') or die(mysql_error());
function connect_bitcoin() {
disable_errors_if_not_me();
\\\$bitcoin = new jsonRPCClient('http://$BITCOIN_USER:[email protected]:8332/');
enable_errors();
return \\\$bitcoin;
}
?>
EOF2
EOF
# configure apache
rmdir /var/www/html/
ln -s /home/$SYSTEM_INTERSANGO_USER/intersango/htdocs /var/www/html
# configure Intersango
echo Configuring Intersango ...
configure_php_field() {
field=$1
file=$2
value=$3
sed -i -e "s|^define('$field'.*|define('$field', $value);|" /home/$SYSTEM_INTERSANGO_USER/intersango/$file
}
configure_sh_field() {
field=$1
file=$2
value=$3
sed -i -e "s|^$field=.*|$field=$value|" /home/$SYSTEM_INTERSANGO_USER/intersango/$file
}
configure_php_field SITE_URL htdocs/config.php "'https://$SITE_HOST_NAME/'"
configure_php_field AKEY duo_config.php "'$DUO_SECRET_STRING'"
configure_php_field IKEY duo_config.php "'$DUO_INTEGRATION_KEY'"
configure_php_field SKEY duo_config.php "'$DUO_SECRET_KEY'"
configure_php_field HOST duo_config.php "'$DUO_API_HOSTNAME'"
# configure_sh_field USER bin/every-minute "'$SYSTEM_INTERSANGO_USER'"
# set up crontab
echo Installing crontab
su - $SYSTEM_INTERSANGO_USER <<EOF
crontab intersango/crontab.txt
EOF
# restart Apache
echo Restarting Apache ...
service httpd restart
##Starting httpd: [ OK ]
# still to do:
# configure the other configurable stuff - there's lots of WBX-specific stuff there
# edit html where needed - there are WBX references
# put a cron job in place to:
# run scripts that need running
# (re)start bitcoind if it's not running