modpack.sh - automatic pk3 creation for mods - tZork - 10-20-2011
Finding myself spending far to much time keeping track on what files i needed to add to pk3's and send to clients when running non vanilla servers, i decided to create a script to do it for me. Consider this WIP and use at your own risk! Comments, suggestions and improvements are welcome.
This assumes that you:
Save this as xonotic/data/xonotic-data.pk3dir/modpack.sh, and run it by typing "./modpack.sh" in the same dir. For options, use -?
i would like to point out, again, that this is "use at your own risk". i take no responsibility even if this eats your pets, puts your children in high orbit and send nude pictures of steve ballmer to your boss
Code: #!/bin/sh
branch_name=`git name-rev --name-only HEAD | sed 's/\//_/g'`
mod_date=`date +%Y-%m-%d`
pk3_file="$branch_name-$mod_date.pk3"
blacklist=(defaultXonotic.cfg shaderlist.txt *.exe *.dll)
whitelist=(*.iqm *.md3 *.dpm *.mdl *.obj *.ase *.map *.bsp *.mapinfo *.rtlights *.waypoints *.waypoints.cache *.jpg *.tga *.png *.dds *.shader *.txt *.wav *.ogg *.cfg)
use_whitelist=0
add_progs=0
ref_branch="origin/master"
do_overwite=0
function usage
{
echo "-h or --help: Show this text"
echo "-f or --file: Specify .pk3 filname"
echo "-w or --whitelist: Also check each filename against whitelist (slow)"
echo "-r or --ref-branch: Set relative branch (default: origin/master)"
echo "-o or --overwrite: Continiue (and delete) even in pk3 file allready exists"
echo "-p or --with-progs: Also include menu, client and server .dat in pk3"
}
while [ "$1" != "" ]; do
case $1 in
-r | --ref-branch ) shift
ref_branch=$1
;;
-f | --file ) shift
pk3_file=$1
;;
-o | --overwrite ) do_overwite=1
;;
-p | --with-progs ) add_progs=1
;;
-w | --whitelist ) use_whitelist=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
if [ $add_progs -ne 0 ]
then
echo "-p specified, checking progs..."
progs_fail=0
if [ ! -f "progs.dat" ]
then
echo " - [EE] progs.dat missing!"
progs_fail=1
fi
if [ ! -f "menu.dat" ]
then
echo " - [EE] menu.dat missing!"
progs_fail=1
fi
if [ ! -f "csprogs.dat" ]
then
echo " - [EE] csprogs.dat missing!"
progs_fail=1
fi
if [ $progs_fail -ne 0 ]
then
echo " - [EE] One or more progs are missing, aborting."
exit 1
fi
fi
if [ -f "$pk3_file" ]
then
if [ $do_overwite -ne 0 ]
then
echo "$pk3_file allraedy exsists, deleting"
rm "$pk3_file"
else
echo "$pk3_file allraedy exsists, aborting"
exit 1
fi
fi
mod_files=`git diff --name-only $ref_branch`
echo "Creating MOD pk3 for $branch_name in $pk3_file"
echo "Checking and adding files"
for mod_file in $mod_files
do
mod_file_name=`basename $mod_file`
file_ok=1
if [ $use_whitelist -ne 0 ]
then
for good_file in "${whitelist[@]}"
do
if [ `echo "$mod_file_name" | grep -E "$good_file"` ]
then
file_ok=1
fi
done
fi
for bad_file in "${blacklist[@]}"
do
if [ `echo "$mod_file_name" | grep -E "$bad_file"` ]
then
file_ok=-1
fi
done
if [ $file_ok -eq 1 ]
then
echo " - [OK] $mod_file_name > $pk3_file"
junk=`zip -9 "$pk3_file" "$mod_file"`
else
if [ $file_ok -eq -1 ]
then
echo " - [WW] $mod_file_name BLACKLISTED, not adding to package"
else
echo " - [WW] $mod_file_name not whitelisted, not adding to package"
fi
fi
done
echo ""
if [ $add_progs -ne 0 ]
then
echo "-p specified, refusing to add .serverpackage"
echo " - Adding csprogs.dat, menu.dat & progs.dat"
junk=`zip -9 progs.dat`
junk=`zip -9 menu.dat`
junk=`zip -9 csprogs.dat`
else
echo "Creating and adding .serverpackage"
echo "$branch_name-$mod_date" > "$branch_name-$mod_date.serverpackage"
junk=`zip -9 "$pk3_file" "$branch_name-$mod_date.serverpackage"`
rm "$branch_name-$mod_date.serverpackage"
fi
echo ""
echo ""
echo "Your package is ready, the filename is: `pwd`/$pk3_file"
|