forked from click2install/xumacoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-ucc.sh
More file actions
173 lines (155 loc) · 5.8 KB
/
update-ucc.sh
File metadata and controls
173 lines (155 loc) · 5.8 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
TMP_FOLDER=$(mktemp -d)
BINARY_LINK="https://github.com/UCCNetwork/ucc/releases/download/v2.2.0.0/UCC-2.2.0.0-Linux64bit.zip"
INSTALL_LINK=https://github.com/UCCNetwork/installscript/raw/master/install_ucc_binary.sh
INSTALL_FILE=install_ucc_binary.sh
DAEMON_BINARY="uccd"
CLI_BINARY="ucc-cli"
DAEMON_BINARY_FILE="/usr/local/bin/$DAEMON_BINARY"
CLI_BINARY_FILE="/usr/local/bin/$CLI_BINARY"
DEFAULT_USER="$( pgrep -n $DAEMON_BINARY | xargs -r ps -o uname= -p )"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
function load_installer()
{
wget -q $INSTALL_LINK && bash $INSTALL_FILE
exit 0
}
function checks()
{
if [[ $(lsb_release -d) != *Ubuntu* ]]; then
echo -e "${RED}You are not running Ubuntu. Installation is cancelled.${NC}"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}$0 must be run as root.${NC}"
exit 1
fi
if [ -n "$(pidof $DAEMON_BINARY)" ]; then
echo -e "${GREEN}The uccd daemon is already running. We will update it.${NC}"
else
echo -e "${RED}The uccd daemon is currently not running. We try update it.${NC}"
sleep 2
echo -e "${RED}Searching for the user and data-directory ...${NC}"
sleep 2
DATADIRS=$(find /home -type d -name ".ucc")
DATADIR=$(echo "$DATADIRS" | head -1)
if [ -d $DATADIR ]; then
DEFAULT_USER=$(echo "$DATADIR" | rev | awk -F \/ '{print $2}' | rev)
echo -e "${GREEN}Found the user: $DEFAULT_USER. We continue with the update.${NC}"
echo -e "${GREEN}Found the Data-Dir(s): $DATADIRS.${NC}"
else
echo -e "${RED}UCC seems not to be installed.${NC}"
read -e -p "$(echo -e $YELLOW Should we fetch the install-script and install a new masternode? [Y/N] $NC)" ICHOICE
if [[ ("$ICHOICE" == "n" || "$ICHOICE" == "N") ]]; then
exit 1;
else
load_installer
fi
fi
fi
}
function stop_service()
{
echo -e "${GREEN}Stopping UCC Masternode ... this takes some time ...${NC}"
sleep 2
systemctl stop "$USER_NAME"
}
function start_service()
{
echo -e "${GREEN}Starting UCC Masternode ...${NC}"
sleep 5
systemctl start "$USER_NAME"
}
function update_binary()
{
cd "$TMP_FOLDER"
mkdir ucc_binary && cd ucc_binary
echo -e "${GREEN}Downloading UCC Binary from Github ...${NC}"
wget $BINARY_LINK
sleep 3
unzip UCC*
cd UCC*
echo -e "${GREEN}Replacing the UCC Binary with newer Version ...${NC}"
cp -a $DAEMON_BINARY $DAEMON_BINARY_FILE
cp -a $CLI_BINARY $CLI_BINARY_FILE
chmod 755 $DAEMON_BINARY_FILE
chmod 755 $CLI_BINARY_FILE
}
function ask_user()
{
read -e -p "$(echo -e $YELLOW We found this user running the Masternode. Please change if it is not correct: $NC)" -i $DEFAULT_USER USER_NAME
if [ -z "$(getent passwd $USER_NAME)" ]; then
echo -e "${RED}User does not yet exist. Please enter the correct username.${NC}"
ask_user
fi
}
function cleanup()
{
echo -e "${GREEN}Cleaning up the temporary folders ...${NC}"
rm -rfv "$TMP_FOLDER"
}
function show_output()
{
echo
echo -e "================================================================================================================================"
echo
echo -e "${GREEN}Your UCC master node was updated!${NC}"
echo
echo -e "You can manage your UCC service from your SSH cmdline with the following commands:"
echo -e " - ${GREEN}systemctl start $USER_NAME.service${NC} to start the service."
echo -e " - ${GREEN}systemctl stop $USER_NAME.service${NC} to stop the service."
echo -e " - ${GREEN}systemctl status $USER_NAME.service${NC} to get the status of the service."
echo
echo -e "You can find the masternode status when logged in as $USER_NAME using the command below:"
echo -e " - ${GREEN}${CLI_BINARY} getinfo${NC} to retrieve your nodes status and information"
echo
echo -e " if you are not logged in as $USER_NAME then you can run ${YELLOW}su - $USER_NAME${NC} to switch to that user before"
echo -e " running the ${GREEN}getinfo${NC} command."
echo -e " NOTE: the deamon must be running first before trying this command. See notes above on service commands usage."
echo
echo -e "You can run ${GREEN}htop${NC} if you want to verify the UCC service is running or to monitor your server."
echo
echo -e "================================================================================================================================"
echo
}
clear
echo
echo -e "========================================================================================================="
echo -e "${GREEN}"
echo -e " u u c c"
echo " u u c c"
echo " u u c c"
echo -e " uuuud c c"
echo
echo -e "${NC}"
echo -e "This script will automate the update of your UCC masternode by"
echo -e "performing the following steps:"
echo
echo -e " - Obtain the latest UCC masternode files from the UCC GitHub repository"
echo -e " - Check the current user which runs actually the UCC masternode service"
echo -e " - Stop the UCC masternode service"
echo -e " - update the UCC masternode binaries"
echo -e " - Start the UCC masternode service"
echo
echo -e "The script will output ${YELLOW}questions${NC}, ${GREEN}information${NC} and ${RED}errors${NC}"
echo -e "When finished the script will show a summary of what has been done."
echo
echo -e "Script created by fly"
echo -e " - GitHub: https://github.com/UCCNetwork/installscript/"
echo
echo -e "========================================================================================================="
echo
read -e -p "$(echo -e $YELLOW Do you want to continue? [Y/N] $NC)" CHOICE
if [[ ("$CHOICE" == "n" || "$CHOICE" == "N") ]]; then
exit 1;
fi
checks
ask_user
stop_service
update_binary
start_service
show_output
cleanup