-
Notifications
You must be signed in to change notification settings - Fork 20
/
install-chc.sh
executable file
·149 lines (130 loc) · 5.55 KB
/
install-chc.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
#!/bin/sh
#Version 0.16.4
#Info: Installs Chaincoind daemon, Masternode based on privkey, and a simple web monitor.
#Chaincoin Version 0.9.3 or above
#Tested OS: Ubuntu 17.04, 16.04, and 14.04
#TODO: make script less "ubuntu" or add other linux flavors
#TODO: remove dependency on sudo user account to run script (i.e. run as root and specifiy chaincoin user so chaincoin user does not require sudo privileges)
#TODO: add specific dependencies depending on build option (i.e. gui requires QT4)
noflags() {
echo "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄"
echo "Usage: install-chc"
echo "Example: install-chc"
echo "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄"
exit 1
}
message() {
echo "╒════════════════════════════════════════════════════════════════════════════════>>"
echo "| $1"
echo "╘════════════════════════════════════════════<<<"
}
error() {
message "An error occured, you must fix it to continue!"
exit 1
}
prepdependencies() { #TODO: add error detection
message "Installing dependencies..."
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
sudo apt-get install automake libdb++-dev build-essential libtool autotools-dev autoconf pkg-config libssl-dev libboost-all-dev libminiupnpc-dev git software-properties-common g++ bsdmainutils libevent-dev -y
sudo add-apt-repository ppa:bitcoin/bitcoin -y
sudo apt-get update
sudo apt-get install libdb4.8-dev libdb4.8++-dev -y
}
createswap() { #TODO: add error detection
message "Creating 2GB temporary swap file...this may take a few minutes..."
sudo dd if=/dev/zero of=/swapfile bs=1M count=2000
sudo mkswap /swapfile
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile
#make swap permanent
sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab
}
clonerepo() { #TODO: add error detection
message "Cloning from github repository..."
cd ~/
git clone https://github.com/chaincoin/chaincoin
}
compile() {
cd chaincoin #TODO: squash relative path
message "Preparing to build..."
./autogen.sh
if [ $? -ne 0 ]; then error; fi
message "Configuring build options..."
./configure $1 --disable-tests
if [ $? -ne 0 ]; then error; fi
message "Building ChainCoin...this may take a few minutes..."
make
if [ $? -ne 0 ]; then error; fi
message "Installing ChainCoin..."
sudo make install
if [ $? -ne 0 ]; then error; fi
}
createconf() {
#TODO: Can check for flag and skip this
#TODO: Random generate the user and password
message "Creating chaincoin.conf..."
MNPRIVKEY="6FBUPijSGWWDrhbVPDBEoRuJ67WjLDpTEiY1h4wAvexVZH3HnV6"
CONFDIR=~/.chaincoincore
CONFILE=$CONFDIR/chaincoin.conf
if [ ! -d "$CONFDIR" ]; then mkdir $CONFDIR; fi
if [ $? -ne 0 ]; then error; fi
mnip=$(curl -s https://api.ipify.org)
rpcuser=$(date +%s | sha256sum | base64 | head -c 10 ; echo)
rpcpass=$(date +%s | sha256sum | base64 | head -c 32 ; echo)
printf "%s\n" "rpcuser=$rpcuser" "rpcpassword=$rpcpass" "rpcallowip=127.0.0.1" "listen=1" "server=1" "daemon=1" "maxconnections=256" "masternode=1" "masternodeprivkey=$MNPRIVKEY" > $CONFILE
chaincoind
message "Wait 10 seconds for daemon to load..."
sleep 20s
MNPRIVKEY=$(chaincoin-cli masternode genkey)
chaincoin-cli stop
message "wait 10 seconds for deamon to stop..."
sleep 10s
sudo rm $CONFILE
message "Updating chaincoin.conf..."
printf "%s\n" "rpcuser=$rpcuser" "rpcpassword=$rpcpass" "rpcallowip=127.0.0.1" "listen=1" "server=1" "daemon=1" "maxconnections=256" "masternode=1" "masternodeprivkey=$MNPRIVKEY" > $CONFILE
}
createhttp() {
cd ~/
mkdir web
cd web
wget https://raw.githubusercontent.com/chaoabunga/chc-scripts/master/index.html
wget https://raw.githubusercontent.com/chaoabunga/chc-scripts/master/stats.txt
(crontab -l 2>/dev/null; echo "* * * * * echo MN Count: > ~/web/stats.txt; /usr/local/bin/chaincoind masternode count >> ~/web/stats.txt; /usr/local/bin/chaincoind getinfo >> ~/web/stats.txt") | crontab -
mnip=$(curl -s https://api.ipify.org)
sudo python3 -m http.server 8000 --bind $mnip 2>/dev/null &
echo "Web Server Started! You can now access your stats page at http://$mnip:8000"
}
sentinel() {
message "Installing Sentinel..."
cd ~/
sudo apt-get update
sudo apt-get -y install python-virtualenv
git clone https://github.com/chaincoin/sentinel.git && cd sentinel
virtualenv ./venv && ./venv/bin/pip install -r requirements.txt
git pull
rm -rf venv && virtualenv ./venv && ./venv/bin/pip install -r requirements.txt
message "Creating sentinel.conf..."
printf "%s\n" "rpcuser=$rpcuser" "rpcpassword=$rpcpass" "rpcport=11995" "rpchost=127.0.0.1" "network=mainnet" "db_name=database/sentinel.db" "db_driver=sqlite" > sentinel.conf
message "Updating Crontab..."
(crontab -l 2>/dev/null; echo "* * * * * cd /root/sentinel && ./venv/bin/python bin/sentinel.py >/dev/null 2>&1") | crontab -
}
success() {
chaincoind
message "SUCCESS! Your chaincoind has started. Masternode.conf setting below..."
message "MN $mnip:11994 $MNPRIVKEY TXHASH INDEX"
exit 0
}
install() {
prepdependencies
createswap
clonerepo
compile $1
createconf
sentinel
success
}
#main
#default to --without-gui
install --without-gui