-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.sh
executable file
·51 lines (40 loc) · 1.24 KB
/
create.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
#!/usr/bin/env bash
set -eu -o pipefail
SSH_KEY_PATH="/home/$USER/.ssh/id_ed25519_adhoc-mc"
while getopts u:p:s:w:o:c: flag
do
case "${flag}" in
u) username=${OPTARG};;
p) pass=${OPTARG};;
s) storage=${OPTARG};;
w) whitelist=${OPTARG};;
o) ops=${OPTARG};;
c) user_cred=${OPTARG};;
esac
done
# Check if variables are set
: ${username:?Missing -u}
: ${pass:?Missing -p}
: ${storage:?Missing -s}
: ${whitelist:?Missing -w}
: ${ops:?Missing -o}
: ${user_cred:?Missing -c}
if [ ! -f "$SSH_KEY_PATH" ]; then
echo "Creating ad-hoc minecraft SSH key ..."
ssh-keygen -t ed25519 -f "$SSH_KEY_PATH" -N "" -C "adhoc-mc"
fi
terraform apply -auto-approve
IP="$(terraform output -raw minecraft_server_ip)"
PW_HASH="$(openssl passwd -6 $user_cred)"
echo -e "#!/usr/bin/env bash\nssh minecraft@$IP -i $SSH_KEY_PATH" > ./ssh.sh
chmod +x ./ssh.sh
echo -e "\nWaiting for server to boot (20 sec) ..."
sleep 20
ansible-playbook -i "$IP," \
--private-key ~/.ssh/id_ed25519_adhoc-mc \
-u root \
--extra-vars "ext_storage=$storage user=$username pass=$pass whitelist=$whitelist ops=$ops pw_hash=$PW_HASH" \
ansible/create-minecraft.yml
echo "Server is ready!"
echo "ssh into the server by running ./ssh.sh"
echo -e "\nMinecraft Server IP: $IP"