forked from StreamitCoin/stream-install
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream-update.sh
More file actions
153 lines (137 loc) · 4.46 KB
/
Copy pathstream-update.sh
File metadata and controls
153 lines (137 loc) · 4.46 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
CONFIG_FILE='streamitcoin.conf'
CONFIGFOLDER='/root/.streamitcoin'
COIN_DAEMON='/usr/local/bin/streamitcoind'
COIN_CLI='/usr/local/bin/streamitcoin-cli'
COIN_REPO='https://github.com/StreamitCoin/StreamitCoin/releases/download/v1.0.1.0/streamitcoin-1.0.1-x86_64-linux-gnu.tar.gz'
COIN_NAME='StreamitCoin'
COIN_PORT=63636
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
progressfilt () {
local flag=false c count cr=$'\r' nl=$'\n'
while IFS='' read -d '' -rn 1 c
do
if $flag
then
printf '%c' "$c"
else
if [[ $c != $cr && $c != $nl ]]
then
count=0
else
((count++))
if ((count > 1))
then
flag=true
fi
fi
fi
done
}
function compile_node() {
echo -e "Stop the $COIN_NAME wallet daemon"
if (( $UBUNTU_VERSION == 16 || $UBUNTU_VERSION == 18 )); then
systemctl stop $COIN_NAME.service
else
/etc/init.d/$COIN_NAME stop
fi
sleep 7
echo -e "Remove the old $COIN_NAME wallet from the system"
rm -f /usr/local/bin/streamitcoin* >/dev/null 2>&1
rm -rf $CONFIGFOLDER/blocks/ >/dev/null 2>&1
rm -rf $CONFIGFOLDER/chainstate/ >/dev/null 2>&1
rm $CONFIGFOLDER/banlist.dat >/dev/null 2>&1
rm $CONFIGFOLDER/mnpayments.dat >/dev/null 2>&1
rm $CONFIGFOLDER/fee_estimates.dat >/dev/null 2>&1
rm $CONFIGFOLDER/peers.dat >/dev/null 2>&1
rm $CONFIGFOLDER/budget.dat >/dev/null 2>&1
rm $CONFIGFOLDER/mncache.dat >/dev/null 2>&1
rm $CONFIGFOLDER/debug.log >/dev/null 2>&1
rm $CONFIGFOLDER/db.log >/dev/null 2>&1
rm $CONFIGFOLDER/bootstrap.dat >/dev/null 2>&1
rm $CONFIGFOLDER/bootstrap.dat.old >/dev/null 2>&1
sleep 5
clear
echo -e "Prepare to download a new wallet of $COIN_NAME"
TMP_FOLDER=$(mktemp -d)
cd $TMP_FOLDER
wget --progress=bar:force $COIN_REPO 2>&1 | progressfilt
compile_error
COIN_ZIP=$(echo $COIN_REPO | awk -F'/' '{print $NF}')
COIN_VER=$(echo $COIN_ZIP | awk -F'/' '{print $NF}' | sed -n 's/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/p')
COIN_DIR=$(echo ${COIN_NAME,,}-$COIN_VER)
tar xvzf $COIN_ZIP --strip=2 ${COIN_DIR}/bin/${COIN_NAME,,}d ${COIN_DIR}/bin/${COIN_NAME,,}-cli>/dev/null 2>&1
compile_error
rm -f $COIN_ZIP >/dev/null 2>&1
cp streamitcoin* /usr/local/bin >/dev/null 2>&1
compile_error
strip $COIN_DAEMON $COIN_CLI
cd - >/dev/null 2>&1
rm -rf $TMP_FOLDER >/dev/null 2>&1
clear
echo -e "Start the $COIN_NAME wallet daemon"
if (( $UBUNTU_VERSION == 16 || $UBUNTU_VERSION == 18 )); then
systemctl start $COIN_NAME.service
else
/etc/init.d/$COIN_NAME start
fi
sleep 7
clear
}
function compile_error() {
if [ "$?" -gt "0" ];
then
echo -e "${RED}Failed to compile $COIN_NAME. Please investigate.${NC}"
exit 1
fi
}
function detect_ubuntu() {
if [[ $(lsb_release -d) == *18.04* ]]; then
UBUNTU_VERSION=18
elif [[ $(lsb_release -d) == *16.04* ]]; then
UBUNTU_VERSION=16
elif [[ $(lsb_release -d) == *14.04* ]]; then
UBUNTU_VERSION=14
else
echo -e "${RED}You are not running Ubuntu 14.04, 16.04 or 18.04 Installation is cancelled.${NC}"
exit 1
fi
}
function checks() {
detect_ubuntu
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}$0 must be run as root.${NC}"
exit 1
fi
}
function prepare_system() {
echo -e "Prepare the system to update ${GREEN}$COIN_NAME${NC} master node."
apt-get update >/dev/null 2>&1
apt-get install -y wget curl ufw binutils >/dev/null 2>&1
}
function important_information() {
echo
echo -e "================================================================================"
echo -e "$COIN_NAME Masternode wallet is update and running, listening on port ${RED}$COIN_PORT${NC}."
echo -e "Configuration file is: ${RED}$CONFIGFOLDER/$CONFIG_FILE${NC}"
if (( $UBUNTU_VERSION == 16 || $UBUNTU_VERSION == 18 )); then
echo -e "Start: ${RED}systemctl start $COIN_NAME.service${NC}"
echo -e "Stop: ${RED}systemctl stop $COIN_NAME.service${NC}"
echo -e "Status: ${RED}systemctl status $COIN_NAME.service${NC}"
else
echo -e "Start: ${RED}/etc/init.d/$COIN_NAME start${NC}"
echo -e "Stop: ${RED}/etc/init.d/$COIN_NAME stop${NC}"
echo -e "Status: ${RED}/etc/init.d/$COIN_NAME status${NC}"
fi
echo -e "Check if $COIN_NAME is running by using the following command:\n${RED}ps -ef | grep $COIN_DAEMON | grep -v grep${NC}"
echo -e "Now update your local wallet (Windows/Mac) and run Masternode from local wallet."
echo -e "================================================================================"
}
##### Main #####
clear
checks
prepare_system
compile_node
important_information