Compare commits

..

No commits in common. "0e7540eba56cc705216d7f7dcaf72d13ba2c4ba3" and "8241343c35d120611b231608576bdc3af11d303f" have entirely different histories.

5 changed files with 13 additions and 65 deletions

View file

@ -1,16 +1,15 @@
## ever wanted to:
- play minecraft but the server was too expensive to host for just a
little play session?
- play minecraft but the server was too expensive to host
for just a little play session?
- have a minecraft world you wanted to play with your friends as a
one off thing?
## introducing: auto-mc-redux!
this is a modified version of the
[script](https://git.skeh.site/ida/auto-mc) i maintain for
automatically installing minecraft (on `apt` based distrobutions)
and intigrating it with systemd. this aims to create a virtual
machine, create the appropriate firewall rules, and install
minecraft with a world that's kept in an s3 bucket, until you give
it the command to un-deploy it, where it'll back up the world to the
s3 bucket or your local computer, and then unprovision the server!
this is a modified version of the [script](https://git.skeh.site/ida/auto-mc) i maintain for automatically
installing minecraft (on `apt` based distrobutions) and intigrating it
with systemd. this aims to create a virtual machine, create the
appropriate firewall rules, and install minecraft with a world that's
kept in an s3 bucket, until you give it the command to un-deploy it,
where it'll back up the world to the s3 bucket, and then unprovision the
server!

View file

@ -42,7 +42,7 @@ cat <<- 'EOF' > /etc/systemd/system/mc-server.service
EOF
chown root:root /etc/systemd/system/mc-server.service
mkdir -p /root/.local/bin/
echo 'PATH="/root/.local/bin:$PATH"' > /root/.bashrc
echo "PATH=/root/.local/bin/:$PATH" >> /root/.bashrc #FIXME: needs to me made impodent
cat <<- 'EOF' > /root/.local/bin/mc-backup
#!/usr/bin/env bash
@ -50,27 +50,16 @@ cat <<- 'EOF' > /root/.local/bin/mc-backup
tar -c -f - /srv/minecraft/server/ | zstd
EOF
touch /root/.hushlogin
chown root:root /root/.local/bin/mc-backup
chmod 755 /root/.local/bin/mc-backup
if [ -e /server.tar.zstd ]; then
echo 'unpacking server backup...'
tar -C / --zstd --overwrite -x /server.tar.zstd
fi
# find the latest release of the requested version and download it
echo "downloading minecraft $VERSION..."
RELEASE=`curl -s https://api.papermc.io/v2/projects/paper/versions/$VERSION/ | jq -r .builds[-1]`
curl https://api.papermc.io/v2/projects/paper/versions/$VERSION/builds/$RELEASE/downloads/paper-$VERSION-$RELEASE.jar -o /srv/minecraft/server/paperclip.jar
mkdir /home/mc/.ssh
cp /root/.ssh/authorized_keys /home/mc/.ssh/authorized_keys
chown -R mc:mc {/srv/minecraft/,/home/mc/.ssh/authorized_keys}
su mc -c \
'echo "screen -r" >> /home/mc/.bashrc
echo "exit" >> /home/mc/.bashrc
echo "eula=true" > /srv/minecraft/server/eula.txt'
chown -R mc:mc /srv/minecraft/
su mc -c 'echo "eula=true" > /srv/minecraft/server/eula.txt'
# what they say on the tin
echo "loading units..."

View file

@ -21,19 +21,12 @@ fi
versionprompt
echo -n "Waiting for machine to respond"
# tests if ssh is up, waiting one second between attempts
until nc $ipv4_address 22 <<<'' 2> /dev/null | grep -q 'SSH'; do
until nc $ipv4_address 22 <<<'' | grep -q 'SSH'; do
echo -n '.'
sleep 1
done
echo
data_dir get
if [ -f "$data_dir/server.tar.zstd" ]; then
echo "Uploading server backup..."
scp "$data_dir/server.tar.zstd" root@$ipv4_address:/server.tar.zstd
fi
echo "Now installing!"
ssh root@$ipv4_address < <(cat <(echo VERSION=$version) ./automate.sh)

View file

@ -1,31 +1,6 @@
# required for the complex pipes
shopt -s lastpipe
data_dir() {
local command="$1"; shift
case $command in
get)
if [ -d "${XDG_DATA_HOME}/auto-mc-redux" ]; then
data_dir="${XDG_DATA_HOME}/auto-mc-redux"
elif [ -d "$HOME/.local/share/auto-mc-redux" ]; then
data_dir="${HOME}/.local/share/auto-mc-redux"
else
data_dir create
fi
;;
create)
if [ -z ${XDG_DATA_HOME+x} ]; then
mkdir -p "${HOME}/.local/share/auto-mc-redux"
data_dir="${HOME}/.local/share/auto-mc-redux"
else
mkdir -p "${XDG_DATA_HOME}/auto-mc-redux"
data_dir="${XDG_DATA_HOME}/auto-mc-redux"
fi
;;
esac
}
config() {
local command="$1"; shift

View file

@ -1,8 +0,0 @@
#!/usr/bin/env bash
install_dir="$(dirname "$(readlink -f "$0")")" # find the install directory
source "$install_dir/functions.sh"
data_dir get
machine show ipv4 | jq -r .ip_address | read ipv4_address
ssh root@$ipv4_address <<<mc-backup > "$data_dir/server.tar.zstd"
machine destroy