-
Notifications
You must be signed in to change notification settings - Fork 58
/
install-pool.sh
executable file
·144 lines (126 loc) · 9.62 KB
/
install-pool.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
#!/bin/bash
#### COLOR SETTINGS ####
black=$(tput setaf 0 && tput bold)
red=$(tput setaf 1 && tput bold)
green=$(tput setaf 2 && tput bold)
yellow=$(tput setaf 3 && tput bold)
blue=$(tput setaf 4 && tput bold)
magenta=$(tput setaf 5 && tput bold)
cyan=$(tput setaf 6 && tput bold)
white=$(tput setaf 7 && tput bold)
blackbg=$(tput setab 0 && tput bold)
redbg=$(tput setab 1 && tput bold)
greenbg=$(tput setab 2 && tput bold)
yellowbg=$(tput setab 3 && tput bold)
bluebg=$(tput setab 4 && tput dim)
magentabg=$(tput setab 5 && tput bold)
cyanbg=$(tput setab 6 && tput bold)
whitebg=$(tput setab 7 && tput bold)
stand=$(tput sgr0)
### System dialog VARS
showinfo="$green[info]$stand"
showerror="$red[error]$stand"
showexecute="$yellow[running]$stand"
showok="$magenta[OK]$stand"
showdone="$blue[DONE]$stand"
showinput="$cyan[input]$stand"
showwarning="$red[warning]$stand"
showremove="$green[removing]$stand"
shownone="$magenta[none]$stand"
redhashtag="$redbg$white#$stand"
abortte="$cyan[abort to Exit]$stand"
showport="$yellow[PORT]$stand"
##
### GENERAL VARS
getgit=$(if cat /etc/*release | grep -q -o -m 1 Ubuntu; then echo "$(apt-cache policy git | grep Installed | grep none | awk '{print$2}' | sed s'/[\(\)]//g')"; elif cat /etc/*release | grep -q -o -m 1 Debian; then echo "$(apt-cache policy git | grep Installed | grep none | awk '{print$2} | sed s'/[\(\)]//g'')"; elif cat /etc/*release | grep -q -o -m 1 centos; then echo "$(if yum list git | grep -q -o "Available Packages"; then echo "none"; else echo "Installed"; fi)"; fi)
###
#### Dependencies START
function deps(){
if [[ "$getgit" == "(none)" ]]; then
echo "$showinfo We need to install Git"
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y git; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y git; elif cat /etc/*release | grep -q -o -m 1 centos; then yum install -y git; fi
else
if [[ "$getgit" == Installed ]]; then
echo "$showok Git is already installed!"
else
if [[ "$getgit" == * ]]; then
echo "$showok Git is already installed!"
fi
fi
fi
}
#### Dependencies check END
deps # call deps function
if [[ $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt update -y; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get update -y; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum update -y; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt upgrade -y; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get upgrade -y; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum upgrade -y; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y linuxbrew-wrapper; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y linuxbrew-wrapper; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y build-essential; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y build-essential; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum group install -y "Development Tools"; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y clang; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y clang; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum install -y clang; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then if [[ -d $HOME/.nvm ]]; then echo "$showok NVM is already installed!"; elif [[ ! -d $HOME/.nvm ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash && export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && source ~/.profile && nvm install 16 && nvm use 16 && nvm alias default 16; fi \
elif cat /etc/*release | grep -q -o -m 1 Debian; then if [[ -d $HOME/.nvm ]]; then echo "$showok NVM is already installed!"; elif [[ ! -d $HOME/.nvm ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash && export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && source ~/.profile && nvm install 16 && nvm use 16 && nvm alias default 16; fi \
elif cat /etc/*release | grep -q -o -m 1 centos; then if [[ -d $HOME/.nvm ]]; then echo "$showok NVM is already installed!"; elif [[ ! -d $HOME/.nvm ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash && export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && source ~/.bash_profile && nvm install 16 && nvm use 16 && nvm alias default 16; fi fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then npm install -g node-gyp; elif cat /etc/*release | grep -q -o -m 1 Debian; then npm install -g node-gyp; elif cat /etc/*release | grep -q -o -m 1 centos; then npm install -g node-gyp; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then npm install pm2 -g --unsafe-perm; elif cat /etc/*release | grep -q -o -m 1 Debian; then npm install pm2 -g --unsafe-perm; elif cat /etc/*release | grep -q -o -m 1 centos; then npm install pm2 -g --unsafe-perm ; fi
echo "$showexecute Running npm install..." && npm install
echo "$showexecute Runing npm run build_browser..." && npm run build_browser && echo "$showexecute Runing npm run build_browser_user_interface..." && npm run build_browser_user_interface
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then if [[ $(node --version) ]]; then echo "$showok NVM sourced ok..."; else echo "$showinfo ${red}MANDATORY$stand: execute ${yellow}source ~/.profile$stand"; fi elif cat /etc/*release | grep -q -o -m 1 Debian; then if [[ $(node --version) ]]; then echo "$showok NVM sourced ok..."; else echo "$showinfo ${red}MANDATORY$stand: execute ${yellow}source ~/.profile$stand"; fi elif cat /etc/*release | grep -q -o -m 1 centos; then if [[ $(node --version) ]]; then echo "$showok NVM sourced ok..."; else echo "$showinfo ${red}MANDATORY$stand: execute ${yellow}source ~/.bash_profile$stand"; fi fi
echo "$showinfo Current dir is $yellow$(pwd)$stand"
if [[ $(ls -d vue-Frontend) == vue-Frontend ]]; then
echo "$showinfo vue-Frontend is already present."
function vue_upd() {
read -r -e -p "$showinput Do you want to update vue-Frontend? (y or n): " yn_update
if [[ "$yn_update" == [nN] ]]; then
echo -e "$showinfo OK..."
elif [[ "$yn_update" == [yY] ]]; then
if cd vue-Frontend; then echo "$showexecute Changing dir to ${yellow}vue-Frontend$stand"; else echo "$showerror Couldn't cd to vue-Frontend folder!"; fi
echo "$showexecute Updating vue-Frontend..." && git pull origin MiningPools && npm install
echo "$showexecute Going back to Node-WebDollar folder..." && if cd ..; then echo "$showexecute Changing dir to ${yellow}$(pwd)$stand"; else echo "$showerror Couldn't cd back!"; fi
elif [[ "$yn_update" == * ]]; then
echo -e "$showerror Possible options are: yY or nN."
vue_upd
fi
}
vue_upd
else
if [[ ! $(ls -d vue-Frontend) == vue-Frontend ]]; then
echo "$showerror vue-Frontend not found inside Node-WebDollar!"
echo "$showinfo Cloning vue-Frontend from WebDollar repository..."
git clone https://github.com/WebDollar/vue-Frontend.git
if cd vue-Frontend; then echo "$showexecute Changing dir to ${yellow}vue-Frontend$stand"; else echo "$showerror Couldn't cd to vue-Frontend folder!"; fi
npm install
if cd ..; then echo "$showexecute Changing dir to ${yellow}$(pwd)$stand"; else echo "$showerror Couldn't cd back!"; fi
if [[ $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
echo "$showinfo We're inside a Node-WebDollar folder!"
if [[ $(ls certificates/private.key) || $(ls certificates/certificate.crt) || $(ls certificates/ca_bundle.crt) ]]; then
echo "$showexecute Copying SSL certificates to vue-Frontend..."
echo "$showexecute Copying ${yellow}private.key$stand" && cp certificates/private.key "vue-Frontend/certificates/."
echo "$showexecute Copying ${yellow}certificate.crt$stand" && cp certificates/certificate.crt "vue-Frontend/certificates/."
echo "$showexecute Copying ${yellow}ca_bundle.crt$stand"&& cp certificates/ca_bundle.crt "vue-Frontend/certificates/."
else
echo "$showerror SSL certificates not found!"
function letsenc() {
read -r -e -p "$showinput Do you want to run ${yellow}start-node-letsencrypt.sh$stand? (y or n): " yn_letsenc
if [[ $yn_letsenc == [nN] ]]; then
echo -e "$showinfo OK..."
elif [[ $yn_letsenc == [yY] ]]; then
echo "$showexecute ${yellow}start-node-letsencrypt.sh$stand"
bash start-node-letsencrypt.sh
echo "$showexecute Copying SSL certificates to vue-Frontend..."
echo "$showexecute Copying ${yellow}private.key$stand" && cp certificates/private.key "vue-Frontend/certificates/."
echo "$showexecute Copying ${yellow}certificate.crt$stand" && cp certificates/certificate.crt "vue-Frontend/certificates/."
echo "$showexecute Copying ${yellow}ca_bundle.crt$stand"&& cp certificates/ca_bundle.crt "vue-Frontend/certificates/."
elif [[ $yn_letsenc == * ]]; then
echo -e "$showerror Possible options are: yY or nN."
letsenc
fi
}
letsenc
fi
fi
fi
fi
else
echo "$showerror You are not inside the Node-WebDollar folder."
echo "$showinfo To install your POOL, use this script inside the Node-WebDollar folder."
fi