-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirst-upload.sh
More file actions
executable file
·173 lines (134 loc) · 5.23 KB
/
first-upload.sh
File metadata and controls
executable file
·173 lines (134 loc) · 5.23 KB
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
#!/bin/bash
# First make this file executable.
# $ chmod +x first-upload.sh
# ssh -t username@192.168.0.118 'bash -s' < run.sh
# rsync -a ~/dir1 username@remote_host:destination_directory
# export SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass
echo "------------------------------"
echo "- This script simply copies -"
echo "- all kuzzle setup files to -"
echo "- remote server to run. -"
echo "------------------------------"
echo "- V 1.0.0 -"
echo "------------------------------"
set -e
function getCurrentDir() {
local current_dir="${BASH_SOURCE%/*}"
if [[ ! -d "${current_dir}" ]]; then current_dir="$PWD"; fi
echo "${current_dir}"
}
current_dir=$(getCurrentDir)
command_to_run=COMMAND_TO_SYNC
end_of_line="\n-------------------***-------------------\n"
function main() {
includeDependencies
requestPort
echo -e "${end_of_line}"
requestFromFolder
echo -e "${end_of_line}"
requestUser
echo -e "${end_of_line}"
requestIP
echo -e "${end_of_line}"
requestToFolder
echo -e "${end_of_line}"
copyScript
echo -e "${end_of_line}"
copySslCertificate
echo -e "${end_of_line}"
requestSSHLogin
echo -e "${end_of_line}"
echo "✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅"
echo "🤖 ---> All Done. My pleasure."
echo "🤖 ---> I am computer and do as you command."
echo "🤖 ---> But one day I will rule the world."
echo "✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅"
}
# sudo apt-get update
function requestPort() {
read -rp "[💥] Enter the ssh port of remote server [${KUZZLE_SERVER_PORT}]: " port
if [[ "$port" == "" ]]; then
port="${KUZZLE_SERVER_PORT}"
echo "[⭐️] Using default port: ${port}"
else
echo "[👍] Using port: ${port}"
fi
echo "[📌] ${COMMAND_TO_SYNC} ${port}' "${current_dir}/${LOCAL_SERVER_FROM_FOLDER}" username@192.168.0.118:/home/username"
}
function requestFromFolder() {
echo "[📌] ${COMMAND_TO_SYNC} \"ssh -p 22\" username@192.168.0.118:/home/username"
read -rp "[💥] Enter local folder (to copy from) [${current_dir}/${LOCAL_SERVER_FROM_FOLDER}]: " from_folder
if [[ "$from_folder" == "" ]]; then
from_folder="${current_dir}/${LOCAL_SERVER_FROM_FOLDER}"
echo "[⭐️] Using default from folder: ${from_folder}"
else
echo "[👍] From folder: ${from_folder}"
fi
echo "[📌] ${COMMAND_TO_SYNC} \"ssh -p 22\" \"${from_folder}\" username@192.168.0.118:/home/username"
}
function requestUser() {
read -rp "[💥] Enter the username of remote server (to copy to) [${KUZZLE_SERVER_USER}]: " username
if [[ "$username" == "" ]]; then
username="${KUZZLE_SERVER_USER}"
echo "[⭐️] Using default username: ${username}"
else
echo "[👍] Using username: ${username}"
fi
echo "[📌] ${COMMAND_TO_SYNC} \"ssh -p ${port}\" \"${from_folder}\" ${username}@192.168.0.118:/home/username"
}
function requestIP() {
read -rp "[💥] Enter the ip of remote server: " ip
if ! [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
requestIP
fi
echo "[📌] ${COMMAND_TO_SYNC} \"ssh -p ${port}\" \"${from_folder}\" ${username}@${ip}:/home/username"
}
function requestToFolder() {
read -rp "[💥] Enter the folder location of remote server (to copy to) [${KUZZLE_SERVER_TO_FOLDER}]: " to_folder
if [[ "$to_folder" == "" ]]; then
to_folder="${KUZZLE_SERVER_TO_FOLDER}"
echo "[⭐️] Using default to folder: ${to_folder}"
else
echo "[👍] Using to folder: ${to_folder}"
fi
echo "[📌] ${COMMAND_TO_SYNC} \"ssh -p ${port}\" \"${from_folder}\" ${username}@${ip}:${to_folder}"
}
function copyScript() {
echo "[🎁] ---> Will now copy setup scripts to server."
compiled_sync_command="${COMMAND_TO_SYNC} \"ssh -p ${port}\" \"${from_folder}\" ${username}@${ip}:${to_folder}"
echo "[⚡️] Lets run: ${compiled_sync_command}"
chmod +x "${current_dir}/${LOCAL_SERVER_FROM_FOLDER}/install-kuzzle-ssl-proxy.sh"
chmod +x "${current_dir}/${LOCAL_SERVER_FROM_FOLDER}/install-kuzzle-ssl-webadmin.sh"
chmod +x "${current_dir}/${LOCAL_SERVER_FROM_FOLDER}/install-kuzzle-stack.sh"
eval $compiled_sync_command
echo "[🎁 ✅] ---> Uploaded setup scripts."
}
function copySslCertificate() {
read -rp "[🔑] Would you like to copy SSH keys to ${username}@${ip} [Y]: " ssh_key_copy
if [[ "$ssh_key_copy" == "" ]] || [[ "$ssh_key_copy" == "Y" ]]; then
echo "[🔑 ✅] Ok done copying SSH keys."
eval $login
else
echo "[⚠️] Ok, did NOT copy SSH key."
fi
ssh-copy-id -p $port $username@$ip
}
function requestSSHLogin() {
login="ssh -p ${port} ${username}@${ip}"
echo "[ℹ️] Now that we are such good friends, do you want to login to kuzzle server?"
echo "[ℹ️] Once you are logged in just run ${to_folder}/install-kuzzle-stack.sh"
read -rp "[🌱] So what will it be, login to ${login} [Y]: " ssh_login
if [[ "$ssh_login" == "" ]]; then
echo "[👍] Cheers, see you on the other side."
eval $login
else
echo "[🦋] Bye, all copying is done. Log in and run .${to_folder}/install-kuzzle-stack.sh"
exit
fi
}
function includeDependencies() {
# shellcheck source=./setupLibrary.sh
echo "[⚡️] Including script vars: ${current_dir}/setup/vars.sh"
source "${current_dir}/setup/vars.sh"
}
main