-
Notifications
You must be signed in to change notification settings - Fork 16
/
installUbuntu.sh
executable file
·291 lines (248 loc) · 11.2 KB
/
installUbuntu.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/bash
pwd="$PWD"
#USERNAME="$SUDO_USER" ###if you want to run the application as your user, uncomment this
USERNAME="$USER" ###if you want to run everything as root, uncomment this
USERHOME="$(eval echo ~$USERNAME)"
USERGROUP="$(id -gn $USERNAME)"
echo "USERHOME pre validation $USERHOME"
if [ $USERHOME = "/root" ] ; then
echo "USERHOME IS ROOT"
echo "RUNNING AS $USER"
#deb file can be run thru double click
#in which case the app is installed as root
USER="root"
USERNAME="$USER"
USERHOME="$(eval echo ~$USER)"
USERGROUP="$(id -gn $USERNAME)"
HOME="$USERHOME"
else
echo "USERHOME ISSET $USERHOME"
fi
architecture=$(dpkg --print-architecture)
sudo chown -R "$USERNAME:$USERGROUP" $pwd && \
if [[ ! -s "$USERHOME/.bash_profile" && -s "$USERHOME/.profile" ]] ; then
profile_file="$USERHOME/.profile"
else
profile_file="$USERHOME/.bash_profile"
fi
source $profile_file && \
echo -e "RUNNING USER IS: $USER" && \
echo -e "USERHOME: $USERHOME" && \
echo -e "USERNAME: $USERNAME" && \
##install nvm
source $USERHOME/.bashrc && \
if [[ ! -d "$USERHOME/.nvm" ]] ; then
# Install nvm
if [ $USERNAME = "root" ] ; then
cd $USERHOME && \
git clone https://github.com/nvm-sh/nvm.git $USERHOME/.nvm &&
cd $USERHOME/.nvm && \
git checkout v0.38.0
#curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
else
su - $USERNAME -c "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash"
fi
fi
echo "NVM installation complete" && \
export NVM_DIR="$USERHOME/.nvm" && \
NVM_DIR="$USERHOME/.nvm" && \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && \
echo "INSTALL NVM VERSION $(cat $pwd/.nvmrc)" && \
cd $pwd && nvm install $(cat $pwd/.nvmrc)
echo -e "########## \x1b[92mInstalling HandyHost Dependencies...\x1b[0m ##########" && \
mkdir -p $USERHOME/.HandyHost
if [[ ! -d "$HOME/.handy" ]] ; then
mkdir "$HOME/.handy" && \
openssl genrsa -out "$HOME/.handy/handyhost.key" 4096 && \
openssl rsa -in "$HOME/.handy/handyhost.key" -pubout -out "$HOME/.handy/handyhost.pub" && \
chmod -R 0600 "$HOME/.handy" && \
chmod 0644 "$HOME/.handy/handyhost.pub"
fi
if [[ ! -d "$USERHOME/.HandyHost/keystore" ]] ; then
mkdir "$USERHOME/.HandyHost/keystore" && \
chmod 0700 "$USERHOME/.HandyHost/keystore" && \
openssl genrsa -out "$USERHOME/.HandyHost/keystore/handyhost.key" 4096 && \
openssl rsa -in "$USERHOME/.HandyHost/keystore/handyhost.key" -pubout -out "$USERHOME/.HandyHost/keystore/handyhost.pub" && \
chmod 0644 "$USERHOME/.HandyHost/keystore/handyhost.pub" && \
chmod 0600 "$USERHOME/.HandyHost/keystore/handyhost.key" && \
cp "$HOME/.handy/handyhost.pub" "$USERHOME/.HandyHost/keystore/daemon.pub" && \
chown "$USERNAME:$USERGROUP" "$USERHOME/.HandyHost/keystore/daemon.pub" && \
chmod 0644 "$USERHOME/.HandyHost/keystore/daemon.pub"
fi
cd $pwd
if [ $USERNAME = "root" ] ; then
VER=$(cat $pwd/.nvmrc)
echo "VERSION TARGET: $VER" && \
cd $pwd && nvm install "$VER" && \
source $USERHOME/.bashrc && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && cd $pwd && nvm install "$VER" && nvm use && npm config set user 0 && npm config set unsafe-perm true && npm install --build-from-source --python=/usr/bin/python3
else
su - $USERNAME -c "source $USERHOME/.bashrc && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && cd $pwd && nvm install $(cat $pwd/.nvmrc) && nvm use && npm install --build-from-source --python=/usr/bin/python3"
fi
VER=$(cat $pwd/.nvmrc)
echo "VERSION TARGET: $VER" && \
nvm install "$VER" && \
nvm use && \
npm install -g bower && \
npm install -g forever && \
cd $pwd/client
if [ $USERNAME = "root" ] ; then
cd $pwd && source $USERHOME/.bashrc && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && cd $pwd && nvm install $(cat $pwd/.nvmrc) && nvm use && cd $pwd/client && bower install --allow-root
else
su - $USERNAME -c "cd $pwd && source $USERHOME/.bashrc && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && cd $pwd && nvm install $(cat $pwd/.nvmrc) && nvm use && cd $pwd/client && bower install"
fi
sudo chown -R "$USERNAME:$USERGROUP" $USERHOME/.HandyHost && \
echo -e "########## \x1b[92mInstalling Sia\x1b[0m ##########" && \
cd $USERHOME/.HandyHost && \
if [[ ! -s "/usr/local/go" ]] ; then
echo "Installing Go"
wget "https://golang.org/dl/go1.16.6.linux-${architecture}.tar.gz" && \
sudo rm -rf /usr/local/go && \
sudo tar -C /usr/local -xzf "go1.16.6.linux-${architecture}.tar.gz" && \
sudo rm "go1.16.6.linux-${architecture}.tar.gz"
else
echo "Go already installed"
fi
export PATH=$PATH:/usr/local/go/bin && \
if [[ ! -d "$USERHOME/.HandyHost/siaRepo" ]] ; then
mkdir -p $USERHOME/.HandyHost/siaRepo && \
git clone https://github.com/SiaFoundation/siad $USERHOME/.HandyHost/siaRepo
else
cd $USERHOME/.HandyHost/siaRepo && \
git fetch --all && \
git pull
fi
#export GOPATH="$USERHOME/go"
if [ $USERNAME = "root" ] ; then
export PATH=$PATH:/usr/local/go/bin:${USERHOME}/go/bin
source $profile_file && \
export HOME="$USERHOME" && \
cd $USERHOME/.HandyHost/siaRepo && make dependencies && make
else
su - $USERNAME -c "cd $USERHOME/.HandyHost/siaRepo && make dependencies && make"
fi
if ! grep -q "${USERHOME}/go/bin" "${profile_file}" ; then
echo "###Editing ${profile_file} to add go env variables###"
echo "export PATH=$PATH:/usr/local/go/bin:${USERHOME}/go/bin" >> "${profile_file}"
source $profile_file
fi
# if ! grep -q "export GOPATH" "${profile_file}" ; then
# echo "export GOPATH=$USERHOME/go" >> "${profile_file}"
# source $profile_file
# fi
echo -e "########## \x1b[92mInstalling DVPN\x1b[0m ##########" && \
cd $pwd/dvpnAPI && \
# if ! command -v docker &> /dev/null
# then
# # Install Docker
# curl -fsSL get.docker.com -o ${USERHOME}/get-docker.sh && \
# sudo sh ${USERHOME}/get-docker.sh
# fi
export HOME=$USERHOME
echo "Setting up Docker nosudo" && \
sudo groupadd docker || true && \
sudo gpasswd -a $USERNAME docker || true && \
sudo machinectl shell --uid=$USERNAME .host $(which dockerd-rootless-setuptool.sh) install --force | echo "$(grep 'export DOCKER_HOST')" >> ${profile_file} && \
if ! grep -q 'PATH=/usr/bin' "${profile_file}" ; then
echo "export PATH=/usr/bin:$PATH" >> "${profile_file}"
fi
sudo machinectl shell --uid=$USERNAME .host $(which systemctl) --user enable docker && \
sudo machinectl shell --uid=$USERNAME .host $(which loginctl) enable-linger $USERNAME
source ${USERHOME}/.profile && \
echo "DOCKER HOST: ${DOCKER_HOST}" && \
mkdir -p ${USERHOME}/.HandyHost/sentinelData && \
if [[ ! -d ${USERHOME}/.HandyHost/sentinelData/dvpn-node ]] ; then
echo "installing DVPN"
git clone https://github.com/sentinel-official/dvpn-node.git ${USERHOME}/.HandyHost/sentinelData/dvpn-node && \
cd ${USERHOME}/.HandyHost/sentinelData/dvpn-node && \
commit=$(git rev-list --tags --max-count=1) && \
git checkout $(git describe --tags ${commit}) && \
sudo chown -R "$USERNAME:$USERGROUP" $USERHOME/.HandyHost/sentinelData && \
sudo machinectl shell --uid=$USERNAME --setenv="DOCKER_HOST=${DOCKER_HOST}" .host $(which docker) build --file ${USERHOME}/.HandyHost/sentinelData/dvpn-node/Dockerfile \
--tag sentinel-dvpn-node \
--force-rm \
--no-cache \
--compress ${USERHOME}/.HandyHost/sentinelData/dvpn-node/
else
echo "DVPN already installed, skipping"
fi
echo -e "########## \x1b[92mInstalling Akash\x1b[0m ##########" && \
LATEST_KUBESPRAY=$(jq -r 'map(select(.prerelease != true)) | first | .tag_name' <<< $(curl --silent "https://api.github.com/repos/kubernetes-sigs/kubespray/releases"))
cd $pwd/aktAPI && \
if [[ ! -d ${USERHOME}/.HandyHost/aktData/kubespray ]] ; then
mkdir -p ${USERHOME}/.HandyHost/aktData/kubespray && \
cd ${USERHOME}/.HandyHost/aktData/kubespray && \
git clone https://github.com/kubernetes-sigs/kubespray.git . && \
git checkout "$LATEST_KUBESPRAY" && \
virtualenv --python=python3 venv && \
. venv/bin/activate && \
pip3 install -r requirements.txt
else
echo "kubespray already installed, check for updates" && \
cd ${USERHOME}/.HandyHost/aktData/kubespray && \
git fetch --all && \
LOCAL_KUBESPRAY=$(git describe --tags)
if [[ "$LOCAL_KUBESPRAY" == "$LATEST_KUBESPRAY" ]]; then
echo "Kubespray is up to date"
else
echo "kubespray is out of date, updating" && \
git fetch --all && \
git checkout "$LATEST_KUBESPRAY" && \
virtualenv --python=python3 venv && \
. venv/bin/activate && \
pip3 uninstall -y ansible && \
pip3 install -r requirements.txt
fi
fi
if [[ ! -d ${USERHOME}/.HandyHost/aktData/ubuntu-autoinstall-generator ]] ; then
echo "installing ubuntu-autoinstall-generator"
cd ${USERHOME}/.HandyHost/aktData && \
git clone https://github.com/covertsh/ubuntu-autoinstall-generator.git && \
cd ubuntu-autoinstall-generator && \
chmod +x ubuntu-autoinstall-generator.sh
else
echo "check for ubuntu-autoinstall-generator updates"
cd ${USERHOME}/.HandyHost/aktData/ubuntu-autoinstall-generator && \
git fetch && \
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @ @{u})
if [[ "$LOCAL" == "$REMOTE" ]]; then
echo "ubuntu-autoinstall-generator is up to date"
else
echo "ubuntu-autoinstall-generator is out of date, updating" && \
git pull origin master
chmod +x ubuntu-autoinstall-generator.sh
fi
fi
export AKASH_NET="https://raw.githubusercontent.com/ovrclk/net/master/mainnet"
export AKASH_VERSION=$(/bin/bash "$pwd/aktAPI/getAkashLatestVersion.sh")
export AKASH_CHAIN_ID="$(curl -s "$AKASH_NET/chain-id.txt")"
export AKASH_NODE="$(curl -s "$AKASH_NET/rpc-nodes.txt" | shuf -n 1)"
cd ${USERHOME}/.HandyHost/aktData && \
if [[ ! -d "${USERHOME}/.HandyHost/aktData/akashRepo" ]] ; then
mkdir -p "${USERHOME}/.HandyHost/aktData/akashRepo" && \
cd "${USERHOME}/.HandyHost/aktData/akashRepo" && \
git clone https://github.com/ovrclk/akash.git . && \
git checkout "$AKASH_VERSION"
else
cd "${USERHOME}/.HandyHost/aktData/akashRepo" && \
git fetch --all && \
git checkout "$AKASH_VERSION"
fi
chown -R "$USERNAME:$USERGROUP" "${USERHOME}/.HandyHost/aktData/akashRepo" && \
echo "installing Akash software..." && \
cd ${USERHOME}/.HandyHost/aktData && \
curl https://raw.githubusercontent.com/ovrclk/akash/master/godownloader.sh | sh -s -- "$AKASH_VERSION"
echo -e "########## \x1b[92mDONE INSTALLING!\x1b[0m ##########" && \
cd $pwd && \
nvm use && \
sudo chown -R "$USERNAME:$USERGROUP" $USERHOME/go && \
sudo chown -R "$USERNAME:$USERGROUP" $pwd && \
sudo chown -R "$USERNAME:$USERGROUP" $USERHOME/.HandyHost && \
node rainbow.js && \
echo "HandyHost is installed and ready to run!" && \
echo -e "Run manually with: \x1b[92m sudo ./localdev_bootstrap.sh\x1b[0m" && \
echo -e "Or restart with: \x1b[92m sudo ./localdev_bootstrap.sh restart\x1b[0m" && \
echo -e "\x1b[92mHandyHost will be available on: http://localhost:8008\x1b[0m" && \
echo -e "\x1b[92mHandyHost will aos be available on: https://localhost:58008\x1b[0m (self-signed certificate, generated by you)"