1
1
#! /bin/bash
2
2
3
+ HOME_DIR=/home/kingofthenorth/
4
+ KOTN_DIR=/kingofthenorth/
5
+
3
6
function extract_file() {
4
7
local extraction_dir=" ./"
5
8
if [ -n " $2 " ]; then
@@ -17,48 +20,48 @@ function extract_file() {
17
20
}
18
21
19
22
function bootstrap_node() {
20
- local download_dir=/kingofthenorth /bootstrap-seed/
21
- local extraction_dir=/kingofthenorth /raven-dir/
22
- local transmission_dir=~ /.config/transmission-daemon/
23
+ local download_dir=$KOTN_DIR /bootstrap-seed/
24
+ local extraction_dir=$KOTN_DIR /raven-dir/
25
+ local transmission_dir=$HOME_DIR /.config/transmission-daemon/
23
26
local bootstrap_done=" bootstrap.done"
24
27
while [ ! " $( transmission-remote localhost -n transmission:transmission -l | grep " rvn-bootstrap*.tar.gz" | awk ' {print $5}' ) " = " Done" ];
25
28
do
26
- echo -e " $( date) - Waiting for bootstrap file to finish downloading..." > ~ /bootstrap-status.log
27
- echo -e " $( transmission-remote localhost -n transmission:transmission -l | grep " rvn-bootstrap*.tar.gz" ) " >> ~ /bootstrap-status.log
29
+ echo -e " $( date) - Waiting for bootstrap file to finish downloading..." > $HOME_DIR /bootstrap-status.log
30
+ echo -e " $( transmission-remote localhost -n transmission:transmission -l | grep " rvn-bootstrap*.tar.gz" ) " >> $HOME_DIR /bootstrap-status.log
28
31
sleep 60
29
32
done
30
33
31
34
local bootstrap_file=$( find ${download_dir} -type f -name " rvn-bootstrap*tar.gz" )
32
35
if [ -z " ${bootstrap_file} " ]; then
33
- echo -e " $( date) - ERROR: Failed to find the downloaded bootstrap file!" > ~ /bootstrap-status.log
36
+ echo -e " $( date) - ERROR: Failed to find the downloaded bootstrap file!" > $HOME_DIR /bootstrap-status.log
34
37
return 1
35
38
fi
36
39
37
- echo -e " $( date) - Verifying the bootstrap file integrity..." > ~ /bootstrap-status.log
40
+ echo -e " $( date) - Verifying the bootstrap file integrity..." > $HOME_DIR /bootstrap-status.log
38
41
cp ${transmission_dir} /seeding/rvn-bootstrap.md5 ${download_dir}
39
42
pushd $download_dir & > /dev/null
40
43
if ! md5sum -c rvn-bootstrap.md5 --status --ignore-missing; then
41
- echo -e " $( date) - ERROR: Failed to verify the MD5 checksum of the downloaded bootstrap file!" > ~ /bootstrap-status.log
44
+ echo -e " $( date) - ERROR: Failed to verify the MD5 checksum of the downloaded bootstrap file!" > $HOME_DIR /bootstrap-status.log
42
45
popd & > /dev/null
43
46
return 1
44
47
fi
45
48
popd & > /dev/null
46
49
47
50
if [ -f " ${download_dir} /${bootstrap_done} " ]; then
48
- echo -e " $( date) - Extraction skipped since file already exists..." > ~ /bootstrap-status.log
51
+ echo -e " $( date) - Extraction skipped since file already exists..." > $HOME_DIR /bootstrap-status.log
49
52
return 0
50
53
fi
51
54
52
- echo -e " $( date) - Extracting the bootstrap file database..." > ~ /bootstrap-status.log
53
- extract_file $bootstrap_file $extraction_dir || { echo -e " Failed to extract the bootstrap database..." > ~ /bootstrap-status.log && return 1; }
55
+ echo -e " $( date) - Extracting the bootstrap file database..." > $HOME_DIR /bootstrap-status.log
56
+ extract_file $bootstrap_file $extraction_dir || { echo -e " Failed to extract the bootstrap database..." > $HOME_DIR /bootstrap-status.log && return 1; }
54
57
55
- echo -e " $( date) - Extraction of the bootstrap file completed succesfully!" > ~ /bootstrap-status.log
56
- touch $bootstrap_done $ download_dir
58
+ echo -e " $( date) - Extraction of the bootstrap file completed succesfully!" > $HOME_DIR /bootstrap-status.log
59
+ touch $download_dir / $bootstrap_done
57
60
return 0
58
61
}
59
62
60
63
function setup_nodejs(){
61
- local app_dir=/home/kingofthenorth /nodejs-app/
64
+ local app_dir=$HOME_DIR /nodejs-app/
62
65
cd ${app_dir}
63
66
npm i
64
67
return 0
@@ -85,73 +88,75 @@ function install_rvn() {
85
88
ln -sf /opt/raven/bin/ravend /usr/local/bin/ravend
86
89
ln -sf /opt/raven/bin/raven-cli /usr/local/bin/raven-cli
87
90
88
- local raven_dir=/home/kingofthenorth /.raven/
91
+ local raven_dir=$HOME_DIR /.raven/
89
92
mkdir -p ${raven_dir}
90
93
chown -R kingofthenorth:kingofthenorth ${raven_dir}
91
94
92
95
rm -rf /tmp/*
93
96
}
94
97
95
98
function node_status() {
96
- local home_dir=" /home/kingofthenorth"
97
- local bootstrap_file=" ${home_dir} /bootstrap-status.log"
99
+ local bootstrap_file=" ${HOME_DIR} /bootstrap-status.log"
98
100
if [ -f $bootstrap_file ]; then
99
101
cat $bootstrap_file
100
102
fi
101
103
local ravend_pid=$( ps aux | grep ravend | grep -v grep)
102
104
if [ -n " ${ravend_pid} " ]; then
103
- local status_file=" node_status.log"
105
+ local status_file=" ${HOME_DIR} / node_status.log"
104
106
local curr_t=$( date +%s)
105
107
local status_file_t=$( date -r ${status_file} +%s)
106
108
local diff_t=$[$curr_t - $status_file_t ]
107
109
if [ $diff_t -gt 60 ]; then
108
110
raven_status > $status_file
109
- else
110
- cat $status_file
111
111
fi
112
+ cat $status_file
112
113
fi
113
114
return 0
114
115
}
115
116
116
117
function check_env_vars() {
117
118
if [ " ${UPNP} " = " true" ]; then
118
119
echo " Enabling UPNP on services..."
119
- sed -i -e ' /upnp=/ s/=.*/=1/' /home/kingofthenorth /.raven/raven.conf
120
- sed -i -e ' /\"port-forwarding-enabled\":/ s/:.*/: true,/' /home/kingofthenorth /.config/transmission-daemon/settings.json
120
+ sed -i -e ' /upnp=/ s/=.*/=1/' ${HOME_DIR} /.raven/raven.conf
121
+ sed -i -e ' /\"port-forwarding-enabled\":/ s/:.*/: true,/' ${HOME_DIR} /.config/transmission-daemon/settings.json
121
122
fi
122
123
if [ -n " ${RAVEN_PORT} " ]; then
123
124
echo " Setting up custom RVN Core port ${RAVEN_PORT} ..."
124
- sed -i -e " /port=/ s/=.*/=${RAVEN_PORT} /" /home/kingofthenorth /.raven/raven.conf
125
+ sed -i -e " /port=/ s/=.*/=${RAVEN_PORT} /" ${HOME_DIR} /.raven/raven.conf
125
126
fi
126
127
if [ -n " ${TRANSMISSION_PORT} " ]; then
127
128
echo " Setting up custom Transmission port ${TRANSMISSION_PORT} ..."
128
- sed -i -e " /\" peer-port\" :/ s/:.*/: ${TRANSMISSION_PORT} ,/" /home/kingofthenorth /.config/transmission-daemon/settings.json
129
+ sed -i -e " /\" peer-port\" :/ s/:.*/: ${TRANSMISSION_PORT} ,/" ${HOME_DIR} /.config/transmission-daemon/settings.json
129
130
fi
130
131
if [ -n " ${FRONTEND_PORT} " ]; then
131
132
echo " Setting up custom Frontend port ${FRONTEND_PORT} ..."
132
- sed -i -e " /const PORT = / s/=.*/= ${FRONTEND_PORT} /" /home/kingofthenorth /nodejs-app/index.js
133
+ sed -i -e " /const PORT = / s/=.*/= ${FRONTEND_PORT} /" ${HOME_DIR} /nodejs-app/index.js
133
134
fi
134
135
}
135
136
136
137
function init() {
137
138
# Check for environment variables
138
139
check_env_vars
139
140
# Start node front-end
140
- local app_dir=/home/kingofthenorth /nodejs-app/
141
+ local app_dir=${HOME_DIR} /nodejs-app/
141
142
setup_nodejs || return 1
142
143
pushd $app_dir
143
144
node index.js &
144
145
popd
146
+ # Create status file
147
+ touch $HOME_DIR /node_status.log
145
148
# Setup transmission for bootstrap file
146
149
transmission-daemon && sleep 30
147
150
# Start bootstraping the node
148
151
bootstrap_node || { sleep 600 && return 2; }
149
152
# Start ravencoin daemon
150
- local ravend_done=" ravend-reindex.done"
153
+ local ravend_done=" ${KOTN_DIR} /raven-dir/ ravend-reindex.done"
151
154
if [ -f " ${ravend_done} " ]; then
155
+ echo -e " ${ravend_done} file found. Running ravend..."
152
156
ravend || return 3
153
157
else
154
158
touch $ravend_done
159
+ echo -e " ${ravend_done} file NOT found. Running ravend and reindexing chain..."
155
160
ravend -reindex || return 4
156
161
fi
157
162
}
0 commit comments