Skip to content

Instantly share code, notes, and snippets.

@sli
Created December 3, 2010 04:21
Show Gist options
  • Save sli/726577 to your computer and use it in GitHub Desktop.
Save sli/726577 to your computer and use it in GitHub Desktop.
Minecraft server crontab
#!/bin/sh
# Set this to the directory where everything will be moved.
FINAL_DIR=/var/www/mc
# Requirements:
# * pigmap, found here: https://github.com/equalpants/pigmap
# * mcmap, found here: https://github.com/Zahl/mcmap
# * rsync
# * pngcrush
#
# After compiling pigmap, you'll want to run these commands to generate the first map *before*
# running this script. Replace $FINAL_DIR with the directory you set above. I suggest shutting
# down the server to copy the world folder. You may start the server back up when running pigmap.
#
# cp -r ./world ./world-backup/world
# ./pigmap -B 6 -T 1 -Z 10 -i ./world -o $FINAL_DIR/map -g ./pigmap-data -h 3
#
# The following are required by default, but can be removed from
# the script if you want. They are marked in the code with (OPTIONAL):
# * Python with PIL
# * Imagemagick
#############################
## No more editing needed! ##
#############################
day_map() {
local t=`echo $1 | sed -e 's/^./\u&/'`
echo -n " * $t...\t\t\t\t"
./mcmap -colors rcolors.txt -skylight -$1 -png -file map-world-$1.png ./world-tmp > cron.log 2>&1
convert -trim map-world-$1.png map-world-$1.png > cron.log 2>&1
convert -thumbnail 150x150 map-world-$1.png map-world-$1-thumb.png > cron.log 2>&1
pngcrush map-world-$1.png map-world-$1.crush > cron.log 2>&1
mv map-world-$1.crush $FINAL_DIR/map-world-$1.png > cron.log 2>&1
echo "[ \033[36mDone\033[37m ]"
}
night_map() {
local t=`echo $1 | sed -e 's/^./\u&/'`
echo -n " * $t...\t\t\t\t"
./mcmap -colors rcolors.txt -skylight -night -$1 -png -file map-night-$1.png ./world-tmp > cron.log 2>&1
convert -trim map-night-$1.png map-night-$1.png > cron.log 2>&1
convert -thumbnail 150x150 map-night-$1.png map-night-$1-thumb.png > cron.log 2>&1
pngcrush map-night-$1.png map-night-$1.crush > cron.log 2>&1
mv map-night-$1.crush $FINAL_DIR/map-night-$1.png > cron.log 2>&1
echo "[ \033[36mDone\033[37m ]"
}
cave_map() {
local t=`echo $1 | sed -e 's/^./\u&/'`
echo -n " * $t...\t\t\t\t"
./mcmap -colors rcolors.txt -skylight -cave -$1 -png -file map-cave-$1.png ./world-tmp > cron.log 2>&1
convert -trim map-cave-$1.png map-cave-$1.png > cron.log 2>&1
convert -thumbnail 150x150 map-cave-$1.png map-cave-$1-thumb.png > cron.log 2>&1
pngcrush map-cave-$1.png map-cave-$1.crush > cron.log 2>&1
mv map-cave-$1.crush $FINAL_DIR/map-cave-$1.png > cron.log 2>&1
echo "[ \033[36mDone\033[37m ]"
}
nether_map() {
local t=`echo $1 | sed -e 's/^./\u&/'`
echo -n " * $t...\t\t\t\t"
./mcmap -colors rcolors.txt -skylight -$1 -png -file map-nether-$1.png ./nether-tmp > cron.log 2>&1
convert -trim map-nether-$1.png map-nether-$1.png > cron.log 2>&1
convert -thumbnail 150x150 map-nether-$1.png map-nether-$1-thumb.png > cron.log 2>&1
pngcrush map-nether-$1.png map-nether-$1.crush > cron.log 2>&1
mv map-nether-$1.crush $FINAL_DIR/map-nether-$1.png > cron.log 2>&1
echo "[ \033[36mDone\033[37m ]"
}
start=$(date +%s)
if [ -f cron.log ]; then
rm -f cron.log
fi
if [ -d nether-tmp/ ]; then
rm -rf ./nether-tmp/
fi
echo "Creating world backup..."
echo -n " * World...\t\t\t\t"
rsync -r -t -v ./world ./world-backup/world > change
tail -n +3 ./change > ./pigmap-data/changes
rm change
cp -r ./world ./world-tmp
echo "[ \033[36mDone\033[37m ]"
echo -n " * Nether...\t\t\t\t"
mkdir ./nether-tmp
cp -r ./nether/DIM-1/* ./nether-tmp
cp ./nether/* ./nether-tmp > cron.log 2>&1
echo "[ \033[36mDone\033[37m ]"
# generate archives of world backup
echo "Creating world archives..."
echo -n " * Gzipped...\t\t\t\t"
tar -czf $FINAL_DIR/world.tar.gz ./world-tmp
echo "[ \033[36mDone\033[37m ]"
echo -n " * Bzipped...\t\t\t\t"
tar -cjf $FINAL_DIR/world.tar.bz2 ./world-tmp
echo "[ \033[36mDone\033[37m ]"
echo -n " * Zipped...\t\t\t\t"
zip -q9r $FINAL_DIR/world.zip ./world-tmp
echo "[ \033[36mDone\033[37m ]"
# overworld
echo "Creating day maps..."
#day_map north
#day_map south
day_map east
#day_map west
# overworld, night
echo "Creating night maps..."
#night_map north
#night_map south
night_map east
#night_map west
# caves
echo "Creating cave maps..."
#cave_map north
#cave_map south
cave_map east
#cave_map west
# nether
echo "Creating nether maps..."
#nether_map north
#nether_map south
nether_map east
#nether_map west
# rebuild google map cache
echo -n "Updating interactive map...\t\t"
./pigmap -i ./world-tmp -o $FINAL_DIR/map -g ./pigmap-data -r ./pigmap-data/changes -h 3 -x -m ./pigmap-data/templates/ > cron.log 2>&1
mv $FINAL_DIR/map/pigmap-default.html $FINAL_DIR/map/index.htm
echo "[ \033[36mDone\033[37m ]"
# run pngcrush on everything
mappngs=`find $FINAL_DIR/map -name "*.png"`
echo -n "Crushing PNGs...\t\t\t"
for p in $mappngs
do
new=`echo $p | sed -e 's/png/crush/'`
pngcrush $p $new > cron.log 2>&1
mv $new $p
done
echo "[ \033[36mDone\033[37m ]"
# create timestamp
./timestamp.py $FINAL_DIR/time.png
rm -rf ./world-tmp
rm -rf ./nether-tmp
end=$(date +%s)
diff=$((($end-$start)/60))
echo "All done! Script took $diff minutes."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment