Skip to content

Instantly share code, notes, and snippets.

@MurphysChaos
Last active December 11, 2018 17:31
Show Gist options
  • Save MurphysChaos/b1ffaad3d154ec193127174f39c99952 to your computer and use it in GitHub Desktop.
Save MurphysChaos/b1ffaad3d154ec193127174f39c99952 to your computer and use it in GitHub Desktop.
Quick tool for minecraft servers.
#!/usr/bin/env bash
# Copyright (C) 2015-2018 Joel Murphy
# All rights reserved
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
PROP_FILE=server.properties
SHOULD_START=false
generate_seed() {
SEED="$((0x$(echo $(cat /dev/urandom | head -c 8 | od -A n -t x8) | tr -d '[:space:]')))"
}
random_world() {
generate_seed
if [ -f ${PROP_FILE} ]
then
sed -i "~" "s/level-seed=.*/level-seed=${SEED}/g" ${PROP_FILE}
else
touch ${PROP_FILE}
echo "#Minecraft server properties" >> ${PROP_FILE}
echo "#$(date)" >> ${PROP_FILE}
echo "level-seed=${SEED}" >> ${PROP_FILE}
fi
echo -e "$(grep 'level-seed' ./${PROP_FILE} | sed 's/\(.*\)=\(.*\)/\\e[0;32m\1\\e[0m=\\e[1;33m\2\\e[0m/')"
}
make_backup() {
if [[ ! -e "./backups" ]]; then
mkdir ./backups
fi
7z a ./backups/$(date -j "+%Y%m%d_%H%M%S.7z") ./assets ./world
}
MEMUSE=${MCMEMUSE:-'4G'}
#for c in $*
while (( "$#" ))
do
case "$1" in
-*)
DASH1="${1:1}"
case "$DASH1" in
m)
MEMUSE=${2}
shift
;;
*)
echo "Unrecognized switch: ${1}"
;;
esac
;;
start)
SHOULD_START=true
;;
random-world)
random_world
;;
reset-world)
rm -rf world
;;
backup)
make_backup
;;
test)
echo "MEMUSE=${MEMUSE}"
;;
*)
echo "Unknown command: ${1}"
;;
esac
shift
done
if [[ $SHOULD_START == true ]]; then
echo "Starting server.jar with ${MEMUSE}"
java -jar -Xms${MEMUSE} -Xmx${MEMUSE} server.jar nogui
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment