-
Notifications
You must be signed in to change notification settings - Fork 7
/
hcloud.sh
250 lines (193 loc) · 11.6 KB
/
hcloud.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
#!/bin/bash
#
# Title: PGBlitz (Reference Title File)
# Author(s): Admin9705 - Deiteq
# URL: https://pgblitz.com - http://github.pgblitz.com
# GNU: General Public License v3.0
################################################################################
test=$(hcloud server list)
if [ "$test" == "" ]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⛔️ WARNING! - You Must Input an API Token from Hetzner First!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚡ Reference: http://hcloud.pgblitz.com
* Activate a Hetzner Cloud Account and Create a Project
* Click Access (left hand side) and then click API Tokens
* Create a Token and Save It (and paste below here)
* Not Ready? Just type something & Press [ENTER]
EOF
hcloud context create plexguide
test=$(hcloud server list)
if [ "$test" == "" ]; then
hcloud context delete plexguide
exit
fi
fi
# Start Process
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🌎 PG - Hetzner's Cloud Generator
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚡ Reference: http://hcloud.pgblitz.com
[1] Deploy a New Server
[2] Destory a Server
[A] List Server Info
[B] Display Inital Server Passwords
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[Z] Exit
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
read -p 'Type a Number | Press [ENTER]: ' typed </dev/tty
if [ "$typed" == "1" ]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ PG - Create a Server Name
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
read -p 'Type a Server Name | Press [ENTER]: ' name </dev/tty
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ PG - Hetzner's Cloud OS Selector
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[1] Ubuntu 18.04 (PGBlitz Works)
[2] Ubuntu 16.04 (PGBlitz Works)
[3] Debian 9
[4] Centos 7
[5] Fendora 28
[6] Fendora 27
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[Z] Exit
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
read -p 'Type a Number | Press [ENTER]: ' typed </dev/tty
if [ "$typed" == "1" ]; then
os="ubuntu-18.04"
elif [ "$typed" == "2" ]; then
os="ubuntu-16.04"
elif [ "$typed" == "3" ]; then
os="debian-9"
elif [ "$typed" == "4" ]; then
os="centos-7"
elif [ "$typed" == "5" ]; then
os="fendora-28"
elif [ "$typed" == "6" ]; then
os="fendora-27"
elif [ "$typed" == "Z" ] || [ "$typed" == "z" ]; then
exit
fi
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🚀 PG - Deploying Your Server!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
hcloud server create --name $name --type cx11 --image $os >/opt/appdata/plexguide/server.info
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ PG - New Server Information - [$name]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
cat /opt/appdata/plexguide/server.info
# Creates Log
touch /opt/appdata/plexguide/server.store
cat /opt/appdata/plexguide/server.info >>/opt/appdata/plexguide/server.store
echo "Server Name: $name" >>/opt/appdata/plexguide/server.store
echo "" >>/opt/appdata/plexguide/server.store
# Variable Info
serverip=$(cat /opt/appdata/plexguide/server.info | tail -n +3 | head -n 1 | cut -d " " -f2-)
initialpw=$(cat /opt/appdata/plexguide/server.info | tail -n +4 | cut -d " " -f3-)
tee <<-EOF
⚠️ To Reach Your Server >>> Exit PG >>> TYPE: pg-$name ⚠️
✅️ [IMPORTANT NOTE]
Wait for one minute for the server to boot! Typing pg-$name will
display your initial password! Also can manually by typing:
Command: ssh root@$serverip
FIRST TIME LOGIN - Initial Password: $initialpw
EOF
read -p 'Press [ENTER] to Exit ' fill </dev/tty
# Creates Command pg-whatevername 2
echo "" >>/bin/pg-$name
echo "echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" >/bin/pg-$name
echo "echo '↘️ Server - $name | Initial Password $initialpw'" >>/bin/pg-$name
echo "echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" >>/bin/pg-$name
echo "echo '✅️ Donate @ donate.pgblitz.com - Helps Costs & Mrs. Admin - #1 Enemy!'" >>/bin/pg-$name
echo "echo ''" >>/bin/pg-$name
echo "ssh root@$serverip" >>/bin/pg-$name
chmod 777 /bin/pg-$name
chown 1000:1000 /bin/pg-$name
bash /opt/hcloud/hcloud.sh
exit
elif [ "$typed" == "A" ] || [ "$typed" == "a" ]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ PG - Hetzner Server Cloud List
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Server Name
━━━━━━━━━━━
EOF
hcloud server list | tail -n +2 | cut -d " " -f2- | cut -d " " -f2- | cut -d " " -f2-
echo
read -p 'Press [ENTER] to Continue! ' typed </dev/tty
bash /opt/hcloud/hcloud.sh
exit
elif [ "$typed" == "2" ]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ PG - Destory a Hetzner Cloud Server!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Server Name
━━━━━━━━━━━
EOF
hcloud server list | tail -n +2 | cut -d " " -f2- | cut -d " " -f2- | cut -d " " -f2-
echo
echo "[Z] Exit"
read -p 'Type a Server to Destroy | Press [ENTER]: ' destroy </dev/tty
if [[ "$destroy" == "exit" || "$destroy" == "Exit" || "$destroy" == "EXIT" || "$destroy" == "z" || "$destroy" == "Z" ]]; then
bash /opt/hcloud/hcloud.sh
exit
else
check=$(hcloud server list | tail -n +2 | cut -d " " -f2- | cut -d " " -f2- | cut -d " " -f2-)
next=$(echo $check | grep -c "\<$destroy\>")
if [ "$next" == "0" ]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⛔️ PG - Server: $destroy - Does Not Exist!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
read -p 'Press [ENTER] to Continue! ' typed </dev/tty
bash /opt/hcloud/hcloud.sh
exit
fi
echo
hcloud server delete $destroy
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ PG - Server: $destroy - Destroyed!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
read -p 'Press [ENTER] to Continue! ' typed </dev/tty
rm -rf /bin/pg-$destroy
bash /opt/hcloud/hcloud.sh
exit
fi
elif [ "$typed" == "B" ] || [ "$typed" == "b" ]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↘️ PG - Inital Server Passwords
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ Useful if NEVER logged in! List created by this Server (new > old)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
touch /opt/appdata/plexguide/server.store
tac -r /opt/appdata/plexguide/server.store
echo "" &
echo ""
read -p 'Press [ENTER] to Continue! ' corn </dev/tty
bash /opt/hcloud/hcloud.sh
exit
elif [ "$typed" == "Z" ] || [ "$typed" == "z" ]; then
exit
else
bash /opt/hcloud/hcloud.sh
exit
fi