Compare commits

..

No commits in common. "8241343c35d120611b231608576bdc3af11d303f" and "4577cf384e414d3b342d03017541dfe917e6fb87" have entirely different histories.

3 changed files with 15 additions and 10 deletions

View file

@ -23,7 +23,7 @@ fi
echo "preparing..." # making sure things have the right owners echo "preparing..." # making sure things have the right owners
adduser --disabled-password --gecos "" mc adduser --disabled-password --gecos "" mc
mkdir -p /srv/minecraft/server mkdir -p /srv/minecraft/{server,backups}
cat <<- 'EOF' > /etc/systemd/system/mc-server.service cat <<- 'EOF' > /etc/systemd/system/mc-server.service
[Unit] [Unit]
Description=Minecraft server Description=Minecraft server
@ -46,8 +46,7 @@ echo "PATH=/root/.local/bin/:$PATH" >> /root/.bashrc #FIXME: needs to me made im
cat <<- 'EOF' > /root/.local/bin/mc-backup cat <<- 'EOF' > /root/.local/bin/mc-backup
#!/usr/bin/env bash #!/usr/bin/env bash
systemctl stop mc-server tar -caf /srv/minecraft/backups/server.tar.xz /srv/minecraft/server/
tar -c -f - /srv/minecraft/server/ | zstd
EOF EOF
chown root:root /root/.local/bin/mc-backup chown root:root /root/.local/bin/mc-backup

View file

@ -20,8 +20,8 @@ fi
versionprompt versionprompt
echo -n "Waiting for machine to respond" echo -n "Waiting for machine to respond"
# tests if ssh is up, waiting one second between attempts # send pings every second, waiting for 1 second
until nc $ipv4_address 22 <<<'' | grep -q 'SSH'; do until ping -w 1 -c 1 $ipv4_address >/dev/null 2>&1; do
echo -n '.' echo -n '.'
sleep 1 sleep 1
done done

View file

@ -184,6 +184,7 @@ machine(){
case $command in case $command in
create) create)
# read isn't used in these pipelines because of job control shinanigans
echo 'Creating Droplet...' echo 'Creating Droplet...'
curl -s -X POST \ curl -s -X POST \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
@ -194,7 +195,10 @@ machine(){
"image":"ubuntu-24-10-x64", "image":"ubuntu-24-10-x64",
"ssh_keys":["'$fingerprint'"], "ssh_keys":["'$fingerprint'"],
"tags":["auto-mc"]}' \ "tags":["auto-mc"]}' \
"https://api.digitalocean.com/v2/droplets" > /dev/null "https://api.digitalocean.com/v2/droplets" |\
jq .droplet.id | read droplet
export droplet
echo 'Waiting for droplet to be active...' echo 'Waiting for droplet to be active...'
while sleep 5; do while sleep 5; do
machine show status machine show status
@ -216,21 +220,23 @@ machine(){
curl -s -X GET \ curl -s -X GET \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \ -H "Authorization: Bearer $TOKEN" \
"https://api.digitalocean.com/v2/droplets?tag_name=auto-mc" |\ "https://api.digitalocean.com/v2/droplets/$droplet" |\
jq '.droplets[].networks.v4[] | select(.type == "public")' jq '.droplet.networks.v4[] | select(.type == "public")'
;; ;;
status) status)
curl -s -X GET \ curl -s -X GET \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \ -H "Authorization: Bearer $TOKEN" \
"https://api.digitalocean.com/v2/droplets?tag_name=auto-mc" |\ "https://api.digitalocean.com/v2/droplets/$droplet" |\
jq -r .droplets[].status | read status jq -r .droplet.status | read status
export status export status
;; ;;
esac esac
esac esac
} }
versionprompt() { versionprompt() {
if [ -z ${latest+x} ]; then if [ -z ${latest+x} ]; then
latest=`curl -s https://api.papermc.io/v2/projects/paper/ | jq -r .versions[-1]` latest=`curl -s https://api.papermc.io/v2/projects/paper/ | jq -r .versions[-1]`