-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathengine_create
260 lines (180 loc) · 10.7 KB
/
engine_create
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
# creates usability space bot engine
# (still under development)
# ─────────────────────────────────
# prepare includes
# ─────────────────────────────────
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
if [ -z "$DONT_REDEPLOY" ] ; then
source "$SCRIPT_DIR/engine_redeploy_scripts"
fi
if [ -z "$DONT_CLS" ] && [ -z "$1" ] ; then
cls
fi
# ─────────────────────────────────
# prepare
# ─────────────────────────────────
# report user
echo "STARTING TO CREATE BOT ENGINE:"
# remember curdir
curdir="$PWD" # not used in this script
# go to root working dir
go "/var/www/www-root/data/nodejs/server"
# make base engine dir
md "usability-space-bot-engine"
# ─────────────────────────────────
# prepare ssh keys
# ─────────────────────────────────
# create .ssh/git-deploy-key
# and fill it with keys
nd ".ssh"
nd "git-deploy-key"
# create ssh-keys files
# ask user
type="10"
while [ "$type" -ne "0" ] && [ "$type" -ne "1" ] && [ "$type" -ne "2" ] && [ "$type" -ne "3" ] && [ "$type" -ne "4" ] && [ "$type" -ne "5" ] && [ "$type" -ne "6" ]; do
echo "Chose how you want to create your keys:"
echo " ● -2 — To begin, run git clone https://UsabilitySpace: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@github.com/UsabilitySpace/bookocean-engine-deploy.git deploy;"
echo " ● -1 — Just run eval \"\$(ssh-agent -s)\";"
echo " ● 0 — Run eval \"\$(ssh-agent -s)\", and after that add existing private keys from /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key;"
echo " ● 1 — Just add existing private keys from /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key;"
echo " ● 2 — Copy existing keys from developer's hosting (you won't need to publish them to the git, so you won't need access to git, but you need to know developer's IP ans SSH login/password;"
echo " ● 3 — Generate new keys (you will need to publish them to the git by yourself, which will need access to git and may take a long time;"
echo " ● 4 — Create ~/.ssh/config as a totally new file;"
echo " ● 5 — Append ~/.ssh/config at the end;"
echo " ● 6 — Clone all from git;"
echo "Enter your choice — from -1 to 6: "
read type
done
if [ "$type" -eq "-2" ] ; then
git clone https://UsabilitySpace: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@github.com/UsabilitySpace/bookocean-engine-deploy.git deploy
elif [ "$type" -eq "-1" ] ; then
echo "Running eval:"
eval "$(ssh-agent -s)"
echo "Ssh-agent has been started in background."
elif [ "$type" -eq "0" ] ; then
echo "Running eval:"
eval "$(ssh-agent -s)"
echo "Ssh-agent has been started in background."
echo "Adding existing keys:"
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-bot
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-config
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-deploy
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-menu
elif [ "$type" -eq "1" ] ; then
echo "Existing public & private keys are going to be used:"
ll
echo "Public keys content is as follows:"
echo " ● github.com-repo-bookocean-engine-bot.pub:"
echo " $(cat github.com-repo-bookocean-engine-bot.pub)"
echo " ● github.com-repo-bookocean-engine-config.pub:"
echo " $(cat github.com-repo-bookocean-engine-config.pub)"
echo " ● github.com-repo-bookocean-engine-deploy.pub:"
echo " $(cat github.com-repo-bookocean-engine-deploy.pub)"
echo " ● github.com-repo-bookocean-engine-menu.pub:"
echo " $(cat github.com-repo-bookocean-engine-menu.pub)"
echo "This ↑ public keys has been already added to git by the developer, you don't need to do something about that."
echo "Adding existing keys:"
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-bot
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-config
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-deploy
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-menu
elif [ "$type" -eq "2" ] ; then
echo "Copying existing keys from developer's hosting..."
scp -r root@192.168.0.104:/var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh
# scp -r ~/Desktop/Startuper/@_@BookOcean.io/DEV/bookocean-bot/bookocean-bot-developer-local/.ssh/git-deploy-key root@194.67.87.198:/var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh
echo "Existing public & private keys has been copied from developer's hosting:"
ll
echo "Public keys content is as follows:"
echo " ● github.com-repo-bookocean-engine-bot.pub:"
echo " $(cat github.com-repo-bookocean-engine-bot.pub)"
echo " ● github.com-repo-bookocean-engine-config.pub:"
echo " $(cat github.com-repo-bookocean-engine-config.pub)"
echo " ● github.com-repo-bookocean-engine-deploy.pub:"
echo " $(cat github.com-repo-bookocean-engine-deploy.pub)"
echo " ● github.com-repo-bookocean-engine-menu.pub:"
echo " $(cat github.com-repo-bookocean-engine-menu.pub)"
echo "This ↑ public keys has been already added to git by the developer, you don't need to do something about that."
elif [ "$type" -eq "3" ] ; then
echo "Generating new keys..."
# generates OpenSSH key 31 host
function generate_key(){
echo "Enter:"
echo "● File in which to save the key : $1"
echo "● Passphrase (EXACTELY THE SAME): a9A387aagf?Q_"
ssh-keygen -t ed25519 -C "kobuch@ya.ru"
}
# ssh-add 1 st time
# user need to enter 4 pairs of data
# which are hinted by generate_key:
generate_key github.com-repo-bookocean-engine-bot
generate_key github.com-repo-bookocean-engine-config
generate_key github.com-repo-bookocean-engine-deploy
generate_key github.com-repo-bookocean-engine-menu
echo "New public & private keys has been generated:"
ll
echo "Public keys content is as follows:"
echo " ● github.com-repo-bookocean-engine-bot.pub:"
echo " $(cat github.com-repo-bookocean-engine-bot.pub)"
echo " ● github.com-repo-bookocean-engine-config.pub:"
echo " $(cat github.com-repo-bookocean-engine-config.pub)"
echo " ● github.com-repo-bookocean-engine-deploy.pub:"
echo " $(cat github.com-repo-bookocean-engine-deploy.pub)"
echo " ● github.com-repo-bookocean-engine-menu.pub:"
echo " $(cat github.com-repo-bookocean-engine-menu.pub)"
echo "This ↑ public keys has NOT been yet added to git, so you need to add them yourself."
myself="0"
while [ "$myself" -ne "1" ] ; do
echo "Has you published the above mentioned public keys to git?"
echo " ● 1 — Yes, I have published the above mentioned public keys to git."
echo "Enter 1 when ready..."
read myself
done
# prepare to ssh-add —
# launch ssh-agent in background
eval "$(ssh-agent -s)"
# ssh add
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-bot
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-config
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-deploy
ssh-add /var/www/www-root/data/nodejs/server/usability-space-bot-engine/.ssh/git-deploy-key/github.com-repo-bookocean-engine-menu
elif [ "$type" -eq "4" ] ; then
echo "Crating ssh config"
cp /var/www/www-root/data/nodejs/server/usability-space-bot-engine/deploy/~_ssh_config ~/.ssh/config
echo "Ssh config has been created"
elif [ "$type" -eq "5" ] ; then
echo "Appinding ssh config"
# save backup for safety
cp ~/.ssh/config ~/.ssh/config-$(date +"%Y-%d-%m-%H-%M-%S")
# append new content to the end of ~/.ssh/config
cat /var/www/www-root/data/nodejs/server/usability-space-bot-engine/deploy/~_ssh_config ~/.ssh/config > ~/.ssh/config
echo "Ssh config has been appended"
else
cd "/var/www/www-root/data/nodejs/server/usability-space-bot-engine"
echo "Starting cloning from git:"
# create folders
# (just for joke, git would create them)
# create dirs
# or report they already exist
md bot
md config
md deploy
md menu
md run
md restart
# clone projects using ssh keys
# Using multiple repositories on one server
git clone git@github.com-repo-bookocean-engine-bot:UsabilitySpace/bookocean-engine-bot.git bot
git clone git@github.com-repo-bookocean-engine-config:UsabilitySpace/bookocean-engine-config.git config
git clone git@github.com-repo-bookocean-engine-deploy:UsabilitySpace/bookocean-engine-deploy.git deploy
git clone git@github.com-repo-bookocean-engine-menu:UsabilitySpace/bookocean-engine-menu.git menu
# show content of /var/www/www-root/data/nodejs/server/usability-space-bot-engine/
ll
# report user
echo "Creation of a new bot engine has finished."
echo "See for absense of errors above to check if the creation process has been successful."
fi
# ─────────────────────────────────
# finish
# ─────────────────────────────────
cd $curdir # OF NO NEED
# must do nothing else ■