-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitgreen-cache-server-install.sh
135 lines (114 loc) · 3.41 KB
/
bitgreen-cache-server-install.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
# welcome info
echo
echo
echo "*** Welcome to the Bitgreen Cache Server Installer ***"
echo
echo "This will configure your server to cache the Bitgreen blockchain data in a local Postgresql database and serve the data via public API"
echo
read -n 1 -s -r -p "Press any key to continue"
echo
# root privileges check
if [ "$EUID" -ne 0 ]
then echo "Please run this script with root privileges"
exit
fi
# hardware check !!
# set hostname
echo
echo "Enter your desired hostname: "
read input_name
echo "You entered: ${input_name}!"
hostnamectl set-hostname $input_name
# install Rust
echo "installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup install nightly
rustup default nightly
rustup target add wasm32-unknown-unknown
apt install clang
echo "Rust install and configuration successful"
echo
# install Bitgreen node
echo "cloning Bitgreen Github repository..."
git clone https://github.com/bitgreen/bitgreen-node.git
echo "Bitgreen Github repository successfully cloned"
echo
echo "building Bitgreen node..."
cd bitg-node
cargo build --release
echo "Bitgreen node build successful"
echo
# launch Bitgreen node
echo "launching Bitgreen node"
screen -d -m ./target/release/bitg-node
echo "Bitgreen node launched in detached screen environment"
echo
# install Postgresql
echo "installing Postgresql..."
apt install postgresql
echo "Postgresql install successful"
echo
# generate random secure password (15 characters)
password=$(tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 15);
partA="ALTER USER postgres WITH PASSWORD '"
partB="';"
sqlString=$partA+=$password+=$partB
# echo $sqlString
# set postgres password
sudo -u postgres psql -c $sqlString
# configure Postgres
echo "The Bitgreen installer will now open your environment file. Please input your relevant settings."
read -n 1 -s -r -p "Press any key to continue."
cd cache-engine
cp env.example .env
# edit environment file
cat .env
>.env
echo '# this file was auto-generated by the Bitgreen installer'>.env
echo 'NODE_ENV=production'>>.env
echo '# postgresql config'>>.env
echo 'PGHOST=localhost'>>.env
echo 'PGUSER=psql'>>.env
echo 'PGDATABASE=cache-engine'>>.env
echo "PGPASSWORD="+=$password>>.env
echo 'PGPORT=5432'>>.env
echo '# rpc node provider'>>.env
echo 'RPC_PROVIDER=ws://127.0.0.1:9944'>>.env
echo '# api endpoint port'>>.env
echo 'API_PORT=3000'>>.env
# set all DB tables
npm run migrate up
# clear password from environment variable after use
password="void"
sqlString="void"
# configure Postgres
echo "configuring Postres"
cd cache-engine
npm install
npm run migrate up
echo "Postgres config complete"
echo
# run crawler to download blocks and save to Postgres
screen -d -m npm run node
echo "Block crawler launched in detached screen environment"
echo
# run api server to provide public endpoints
screen -d -m npm run api
echo "API service launched in detached screen environment"
echo
echo "Installation complete. Your Bitgreen node is up and running."
echo "Our bits are greener :)"
:'
while true; do
read -p "Is this server a master or a slave? (if unsure, select master)" ans
case $ans in
[Mm]* ) echo "master"; break;;
[Ss]* ) echo "slave"; exit;;
* ) echo "Please select 'm' for master or 's' for slave.";;
esac
done
'
# nano /etc/apt/sources.list
# deb http://deb.debian.org/debian stretch main
# deb-src http://deb.debian.org/debian stretch main