Compare commits

..

No commits in common. "154aa0359da26180538329a596eb878b8471d9a6" and "79226a01ca900ad0afac9b39f56508175e674801" have entirely different histories.

2 changed files with 35 additions and 91 deletions

View file

@ -11,6 +11,32 @@ fi
echo "fetching..."
apt install -y screen tar xz-utils curl jq #FIXME: this wont probably work on a system that has not run apt update for the first time
# find the latest version of paper
LATEST=`curl -s https://papermc.io/api/v2/projects/paper/ | jq -r .versions[-1]`
printf "\n\n\n"
function versionprompt {
# ask the user which version of minecraft they would like to install
echo "which version of minecraft would you like to serve?"
echo -n "version [$LATEST]:"
if ! read -t 30 VERSION; then # have a timeout for user input handy for unattented installs
VERSION=$LATEST
echo "timed out, defaulting to $LATEST..."
return 0
fi
if [ -n "$VERSION" ]; then # check if the user wrote anything
echo "probing..."
#validate user input
if ! curl -s https://papermc.io/api/v2/projects/paper/ | jq -r .versions | grep -q \"$VERSION\"; then
echo "we cant find that version! either its not supported or you made an error, trying again..."
versionprompt
fi
else
VERSION=$LATEST
echo "defaulting to $LATEST..."
fi
}
versionprompt
# this has to be seperate from the first run of apt since java versions before 16 is deprecated for minecraft 1.17 and before 17 for 1.18, and java versions before 21 for 1.21
echo "installing java..."
if printf '%s\n' 1.20.6 $VERSION | sort -VC; then # check if $VERSION is above 1.20.6

100
deploy.sh
View file

@ -2,10 +2,6 @@
# required for the complex pipes in the machine function
shopt -s lastpipe
#TODO: add these to config create, probably with a select menu or something
size="s-2vcpu-4gb"
reigon="sfo3"
config() {
local command="$1"; shift
@ -22,7 +18,7 @@ config() {
fi
;;
create)
read -p "Enter your DigialOcean API token: " TOKEN
read -p "enter your DigialOcean API token: " TOKEN
# this parameter expands to nothing if unset, or x if it is.
if [ -z ${XDG_CONFIG_HOME+x} ]; then
mkdir -p "${HOME}/.config/auto-mc-redux"
@ -61,16 +57,6 @@ firewall(){
"name": "auto-mc",
"tags":["auto-mc"],
"inbound_rules": [
{
"protocol": "icmp",
"ports": "0",
"sources": {
"addresses": [
"0.0.0.0/0",
"::/0"
]
}
},
{
"protocol": "tcp",
"ports": "25565",
@ -92,38 +78,6 @@ firewall(){
}
}
]
"outbound_rules": [
{
"protocol": "icmp",
"ports": "0",
"sources": {
"addresses": [
"0.0.0.0/0",
"::/0"
]
}
},
{
"protocol": "tcp",
"ports": "0",
"sources": {
"addresses": [
"0.0.0.0/0",
"::/0"
]
}
},
{
"protocol": "udp",
"ports": "0",
"sources": {
"addresses": [
"0.0.0.0/0",
"::/0"
]
}
}
]
}
json
;;
@ -185,8 +139,8 @@ machine(){
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $TOKEN" \
-d '{"name":"auto-mc",
"size":"'$size'",
"region":"'$reigon'",
"size":"s-2vcpu-4gb",
"region":"sfo2",
"image":"ubuntu-24-10-x64",
"ssh_keys":["'$fingerprint'"],
"tags":["auto-mc"]}' \
@ -230,51 +184,15 @@ machine(){
esac
}
versionprompt() {
# ask the user which version of minecraft they would like to install
echo "Which version of minecraft would you like to serve?"
echo -n "Version [$latest]:"
# have a timeout for user input handy for unattented installs
if ! read -t 30 version; then
version=$latest
echo "Timed out, defaulting to $latest..."
return 0
fi
if [ -n "$version" ]; then # check if the user wrote anything
echo "Probing..."
#validate user input
if ! curl -s https://api.papermc.io/v2/projects/paper/ |\
jq -r .versions | grep -q \"$version\"; then
echo "We cant find that version!"
echo "Either its not supported yet or you made an error, trying again..."
versionprompt
fi
else
version=$latest
echo "Defaulting to $latest..."
fi
}
config get
keys check
machine create
#if ! firewall check; then
# firewall create
#else
# echo "Firewall rule already exists"
#fi
machine show ipv4 | jq .ip_address | read ipv4_address
echo "Machine created at $ipv4_address!"
if ! firewall check; then
firewall create
else
echo "Firewall rule already exists"
fi
latest=`curl -s https://api.papermc.io/v2/projects/paper/ | jq -r .versions[-1]`
versionprompt
echo "Waiting for machine to respond"
# send pings every second, waiting for 1 second
until ping -w 1 -c 1 $ip_address >/dev/null 2>&1; do
echo -n '.'
sleep 1
done
cat <(cat <(echo VERSION=$version) ./automate.sh)
#
#machine destroy