Created
November 5, 2010 14:36
-
-
Save Lixivial/664229 to your computer and use it in GitHub Desktop.
bash script to parse and bundle maps by gametype.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# map_pack.sh - Jesse M. Pearson (Lixivial) | |
# contact: jesall@gmail.com | |
# | |
# Description: | |
# A simple script meant to break up Nexuiz maps into individual | |
# gametypes. | |
# | |
# Things to note: | |
# 1. The files generated/used are mostly self-contained to the script's execution directory. | |
# Defined as follows: | |
# pack_dir: where to store the generated tars | |
# map_dir: base dir with all the .pk3's -- assumes all in a single list, is not yet recursive | |
# db_files: where to store the list of maps for each gametype. This might become heavily reworked. | |
# If I rewrite this in perl, I might opt for an sqlite option for more efficient/robust querying. | |
# | |
# TODO: | |
# 1. Perhaps rewrite this in perl. | |
# 2. Perhaps add some switches to control flow, such as: | |
# only generate/update db's | |
# only generate/update tars | |
# clean the entire db and rebuild | |
# clean the tars and rebuild | |
declare -a maps | |
# Try to reliably determine the current execution path. | |
exec_dir=`readlink -f $0` | |
file_len=`basename $0` | |
exec_dir=${exec_dir:0:${#exec_dir}-${#file_len}} | |
db_files="$exec_dir/mapdbs/" | |
pack_dir="$exec_dir/packs/" | |
map_dir="$HOME/maps/" | |
maps=$(ls -1 $map_dir | egrep -v "zz(-|_)") | |
# Mayhaps these should just become 1 file, with mapname,type | |
ctf_file="$db_files/ctf.txt" | |
kh_file="$db_files/kh.txt" | |
ons_file="$db_files/ons.txt" | |
dm_file="$db_files/dm.txt" | |
nb_file="$db_files/nb.txt" | |
arena_file="$db_files/arena.txt" | |
rune_file="$db_files/rune.txt" | |
tdm_file="$db_files/tdm.txt" | |
rc_file="$db_files/rc.txt" | |
lms_file="$db_files/lms.txt" | |
dom_file="$db_files/dom.txt" | |
race_file="$db_files/race.txt" | |
ca_file="$db_files/ca.txt" | |
cts_file="$db_files/cts.txt" | |
IFS=' | |
' | |
function checkExistence() | |
{ | |
local __db_file=$1 | |
local __map_file=$2 | |
# Escape regex characters for grep. | |
__map_file=`echo "${__map_file}" | sed 's/\[/\\\[/;s/\]/\\\]/g'` | |
# Grep for the existence of the file. | |
local result=`grep "${__map_file}" $__db_file` | |
if [[ $result != "" ]]; then | |
echo "true" | |
else | |
echo "false" | |
fi | |
} | |
function writeServerFile() | |
{ | |
local __server_types=$1 | |
local __file=$2 | |
for server_type in $__server_types; do | |
a=`echo $server_type | cut -f2 -d " "` | |
case $a in | |
"ctf") | |
if [ $(checkExistence $ctf_file $__file) == "false" ]; then | |
echo $__file >> $ctf_file | |
fi | |
;; | |
"kh") | |
if [ $(checkExistence $kh_file $__file) == "false" ]; then | |
echo $__file >> $kh_file | |
fi | |
;; | |
"ons") | |
if [ $(checkExistence $ons_file $__file) == "false" ]; then | |
echo $__file >> $ons_file | |
fi | |
;; | |
"dm") | |
if [ $(checkExistence $dm_file $__file) == "false" ]; then | |
echo $__file >> $dm_file | |
fi | |
;; | |
"nexball") | |
if [ $(checkExistence $nb_file $__file) == "false" ]; then | |
echo $__file >> $nb_file | |
fi | |
;; | |
"arena") | |
if [ $(checkExistence $arena_file $__file) == "false" ]; then | |
echo $__file >> $arena_file | |
fi | |
;; | |
"rune") | |
if [ $(checkExistence $rune_file $__file) == "false" ]; then | |
echo $__file >> $rune_file | |
fi | |
;; | |
"tdm") | |
if [ $(checkExistence $tdm_file $__file) == "false" ]; then | |
echo $__file >> $tdm_file | |
fi | |
;; | |
"rc") | |
if [ $(checkExistence $rc_file $__file) == "false" ]; then | |
echo $__file >> $rc_file | |
fi | |
;; | |
"lms") | |
if [ $(checkExistence $lms_file $__file) == "false" ]; then | |
echo $__file >> $lms_file | |
fi | |
;; | |
"dom") | |
if [ $(checkExistence $dom_file $__file) == "false" ]; then | |
echo $__file >> $dom_file | |
fi | |
;; | |
"race") | |
if [ $(checkExistence $race_file $__file) == "false" ]; then | |
echo $__file >> $race_file | |
fi | |
;; | |
"ca") | |
if [ $(checkExistence $ca_file $__file) == "false" ]; then | |
echo $__file >> $ca_file | |
fi | |
;; | |
"cts") | |
if [ $(checkExistence $cts_file $__file) == "false" ]; then | |
echo $__file >> $cts_file | |
fi | |
;; | |
*) | |
if [ $(checkExistence $dm_file $__file) == "false" ]; then | |
echo $__file >> $dm_file | |
fi | |
;; | |
esac | |
done | |
} | |
# This'll need a check for the tar's existence, and if it does exist, just update rather than rebuild. | |
function generatePacks() { | |
cd $map_dir | |
if [ -e "$pack_dir/ctf.tar" ]; then | |
tar -u -T $ctf_file -f $pack_dir/ctf.tar | |
else | |
tar -c -T $ctf_file -f $pack_dir/ctf.tar | |
fi | |
if [ -e "$pack_dir/keyhunt.tar" ]; then | |
tar -u -T $kh_file -f $pack_dir/keyhunt.tar | |
else | |
tar -c -T $kh_file -f $pack_dir/keyhunt.tar | |
fi | |
if [ -e "$pack_dir/onslaught.tar" ]; then | |
tar -u -T $ons_file -f $pack_dir/onslaught.tar | |
else | |
tar -c -T $ons_file -f $pack_dir/onslaught.tar | |
fi | |
if [ -e "$pack_dir/dm.tar" ]; then | |
tar -u -T $dm_file -f $pack_dir/dm.tar | |
else | |
tar -c -T $dm_file -f $pack_dir/dm.tar | |
fi | |
if [ -e "$pack_dir/nexball.tar" ]; then | |
tar -u -T $nb_file -f $pack_dir/nexball.tar | |
else | |
tar -c -T $nb_file -f $pack_dir/nexball.tar | |
fi | |
if [ -e "$pack_dir/arena.tar" ]; then | |
tar -u -T $arena_file -f $pack_dir/arena.tar | |
else | |
tar -c -T $arena_file -f $pack_dir/arena.tar | |
fi | |
if [ -e "$pack_dir/rune.tar" ]; then | |
tar -u -T $rune_file -f $pack_dir/rune.tar | |
else | |
tar -c -T $rune_file -f $pack_dir/rune.tar | |
fi | |
if [ -e "$pack_dir/tdm.tar" ]; then | |
tar -u -T $tdm_file -f $pack_dir/tdm.tar | |
else | |
tar -c -T $tdm_file -f $pack_dir/tdm.tar | |
fi | |
if [ -e "$pack_dir/rc.tar" ]; then | |
tar -u -T $rc_file -f $pack_dir/rc.tar | |
else | |
tar -c -T $rc_file -f $pack_dir/rc.tar | |
fi | |
if [ -e "$pack_dir/lms.tar" ]; then | |
tar -u -T $lms_file -f $pack_dir/lms.tar | |
else | |
tar -c -T $lms_file -f $pack_dir/lms.tar | |
fi | |
if [ -e "$pack_dir/domination.tar" ]; then | |
tar -u -T $dom_file -f $pack_dir/domination.tar | |
else | |
tar -c -T $dom_file -f $pack_dir/domination.tar | |
fi | |
if [ -e "$pack_dir/race.tar" ]; then | |
tar -u -T $race_file -f $pack_dir/race.tar | |
else | |
tar -c -T $race_file -f $pack_dir/race.tar | |
fi | |
if [ -e "$pack_dir/ca.tar" ]; then | |
tar -u -T $ca_file -f $pack_dir/ca.tar | |
else | |
tar -c -T $ca_file -f $pack_dir/ca.tar | |
fi | |
if [ -e "$pack_dir/cts.tar" ]; then | |
tar -u -T $ca_file -f $pack_dir/cts.tar | |
else | |
tar -c -T $ca_file -f $pack_dir/cts.tar | |
fi | |
if [ -e "$pack_dir/allmaps.tar" ]; then | |
tar -u -T ${maps} -f $pack_dir/allmaps.tar | |
else | |
tar -c -T ${maps} -f $pack_dir/allmaps.tar | |
fi | |
} | |
function listFiles() { | |
# Get the a list of all packages | |
for package in ${maps}; do | |
mapinfo=`unzip -qql $map_dir/$package 2>/dev/null | grep .mapinfo | grep -v "error" | awk '{ print $4 }'` | |
# a mapinfo exists | |
if [[ "$mapinfo" != "" ]]; then | |
server_types=`unzip -p $map_dir/$package *.mapinfo 2>/dev/null | grep "^type" | grep -v "//"` | |
writeServerFile "${server_types[@]}" $package | |
fi | |
done | |
} | |
listFiles | |
generatePacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# map_pack.sh.debug - Jesse M. Pearson (Lixivial) | |
# contact: jesall@gmail.com | |
# | |
# Description: | |
# A simple script meant to break up Nexuiz maps into individual | |
# gametypes. (Used for debugging purposes to determine what maps fall into a given gametype) | |
# | |
# Things to note: | |
# 1. The files generated/used are mostly self-contained to the script's execution directory. | |
# Defined as follows: | |
# pack_dir: where to store the generated tars | |
# map_dir: base dir with all the .pk3's -- assumes all in a single list, is not yet recursive | |
# db_files: where to store the list of maps for each gametype. This might become heavily reworked. | |
# If I rewrite this in perl, I might opt for an sqlite option for more efficient/robust querying. | |
# | |
# TODO: | |
# 1. Perhaps rewrite this in perl. | |
# 2. Perhaps add some switches to control flow, such as: | |
# only generate/update db's | |
# only generate/update tars | |
# clean the entire db and rebuild | |
# clean the tars and rebuild | |
declare -a maps | |
# Try to reliably determine the current execution path. | |
exec_dir=`readlink -f $0` | |
file_len=`basename $0` | |
exec_dir=${exec_dir:0:${#exec_dir}-${#file_len}} | |
db_files="$exec_dir/mapdbs/" | |
pack_dir="$exec_dir/packs/" | |
map_dir="$HOME/maps/" | |
maps=$(ls -1 $map_dir | egrep -v "zz(-|_)") | |
# Mayhaps these should just become 1 file, with mapname,type | |
ctf_file="$db_files/ctf.txt" | |
kh_file="$db_files/kh.txt" | |
ons_file="$db_files/ons.txt" | |
dm_file="$db_files/dm.txt" | |
nb_file="$db_files/nb.txt" | |
arena_file="$db_files/arena.txt" | |
rune_file="$db_files/rune.txt" | |
tdm_file="$db_files/tdm.txt" | |
rc_file="$db_files/rc.txt" | |
lms_file="$db_files/lms.txt" | |
dom_file="$db_files/dom.txt" | |
race_file="$db_files/race.txt" | |
ca_file="$db_files/ca.txt" | |
cts_file="$db_files/cts.txt" | |
IFS=' | |
' | |
function checkExistence() | |
{ | |
local __db_file=$1 | |
local __map_file=$2 | |
# Escape regex characters for grep. | |
__map_file=`echo "${__map_file}" | sed 's/\[/\\\[/;s/\]/\\\]/g'` | |
# Grep for the existence of the file. | |
local result=`grep "${__map_file}" $__db_file` | |
if [[ $result != "" ]]; then | |
echo "true" | |
else | |
echo "false" | |
fi | |
} | |
function writeServerFile() | |
{ | |
local __server_types=$1 | |
local __file=$2 | |
for server_type in $__server_types; do | |
a=`echo $server_type | cut -f2 -d " "` | |
case $a in | |
"ctf") | |
if [ $(checkExistence $ctf_file $__file) == "false" ]; then | |
echo $__file >> $ctf_file | |
fi | |
;; | |
"kh") | |
if [ $(checkExistence $kh_file $__file) == "false" ]; then | |
echo $__file >> $kh_file | |
fi | |
;; | |
"ons") | |
if [ $(checkExistence $ons_file $__file) == "false" ]; then | |
echo $__file >> $ons_file | |
fi | |
;; | |
"dm") | |
if [ $(checkExistence $dm_file $__file) == "false" ]; then | |
echo $__file >> $dm_file | |
fi | |
;; | |
"nexball") | |
if [ $(checkExistence $nb_file $__file) == "false" ]; then | |
echo $__file >> $nb_file | |
fi | |
;; | |
"arena") | |
if [ $(checkExistence $arena_file $__file) == "false" ]; then | |
echo $__file >> $arena_file | |
fi | |
;; | |
"rune") | |
if [ $(checkExistence $rune_file $__file) == "false" ]; then | |
echo $__file >> $rune_file | |
fi | |
;; | |
"tdm") | |
if [ $(checkExistence $tdm_file $__file) == "false" ]; then | |
echo $__file >> $tdm_file | |
fi | |
;; | |
"rc") | |
if [ $(checkExistence $rc_file $__file) == "false" ]; then | |
echo $__file >> $rc_file | |
fi | |
;; | |
"lms") | |
if [ $(checkExistence $lms_file $__file) == "false" ]; then | |
echo $__file >> $lms_file | |
fi | |
;; | |
"dom") | |
if [ $(checkExistence $dom_file $__file) == "false" ]; then | |
echo $__file >> $dom_file | |
fi | |
;; | |
"race") | |
if [ $(checkExistence $race_file $__file) == "false" ]; then | |
echo $__file >> $race_file | |
fi | |
;; | |
"ca") | |
if [ $(checkExistence $ca_file $__file) == "false" ]; then | |
echo $__file >> $ca_file | |
fi | |
;; | |
"cts") | |
if [ $(checkExistence $cts_file $__file) == "false" ]; then | |
echo $__file >> $cts_file | |
fi | |
;; | |
*) | |
if [ $(checkExistence $dm_file $__file) == "false" ]; then | |
echo $__file >> $dm_file | |
fi | |
;; | |
esac | |
done | |
} | |
# This'll need a check for the tar's existence, and if it does exist, just update rather than rebuild. | |
function generatePacks() { | |
cd $map_dir | |
if [ -e "$pack_dir/ctf.tar" ]; then | |
tar -u -T $ctf_file -f $pack_dir/ctf.tar | |
else | |
tar -c -T $ctf_file -f $pack_dir/ctf.tar | |
fi | |
if [ -e "$pack_dir/keyhunt.tar" ]; then | |
tar -u -T $kh_file -f $pack_dir/keyhunt.tar | |
else | |
tar -c -T $kh_file -f $pack_dir/keyhunt.tar | |
fi | |
if [ -e "$pack_dir/onslaught.tar" ]; then | |
tar -u -T $ons_file -f $pack_dir/onslaught.tar | |
else | |
tar -c -T $ons_file -f $pack_dir/onslaught.tar | |
fi | |
if [ -e "$pack_dir/dm.tar" ]; then | |
tar -u -T $dm_file -f $pack_dir/dm.tar | |
else | |
tar -c -T $dm_file -f $pack_dir/dm.tar | |
fi | |
if [ -e "$pack_dir/nexball.tar" ]; then | |
tar -u -T $nb_file -f $pack_dir/nexball.tar | |
else | |
tar -c -T $nb_file -f $pack_dir/nexball.tar | |
fi | |
if [ -e "$pack_dir/arena.tar" ]; then | |
tar -u -T $arena_file -f $pack_dir/arena.tar | |
else | |
tar -c -T $arena_file -f $pack_dir/arena.tar | |
fi | |
if [ -e "$pack_dir/rune.tar" ]; then | |
tar -u -T $rune_file -f $pack_dir/rune.tar | |
else | |
tar -c -T $rune_file -f $pack_dir/rune.tar | |
fi | |
if [ -e "$pack_dir/tdm.tar" ]; then | |
tar -u -T $tdm_file -f $pack_dir/tdm.tar | |
else | |
tar -c -T $tdm_file -f $pack_dir/tdm.tar | |
fi | |
if [ -e "$pack_dir/rc.tar" ]; then | |
tar -u -T $rc_file -f $pack_dir/rc.tar | |
else | |
tar -c -T $rc_file -f $pack_dir/rc.tar | |
fi | |
if [ -e "$pack_dir/lms.tar" ]; then | |
tar -u -T $lms_file -f $pack_dir/lms.tar | |
else | |
tar -c -T $lms_file -f $pack_dir/lms.tar | |
fi | |
if [ -e "$pack_dir/domination.tar" ]; then | |
tar -u -T $dom_file -f $pack_dir/domination.tar | |
else | |
tar -c -T $dom_file -f $pack_dir/domination.tar | |
fi | |
if [ -e "$pack_dir/race.tar" ]; then | |
tar -u -T $race_file -f $pack_dir/race.tar | |
else | |
tar -c -T $race_file -f $pack_dir/race.tar | |
fi | |
if [ -e "$pack_dir/ca.tar" ]; then | |
tar -u -T $ca_file -f $pack_dir/ca.tar | |
else | |
tar -c -T $ca_file -f $pack_dir/ca.tar | |
fi | |
if [ -e "$pack_dir/cts.tar" ]; then | |
tar -u -T $ca_file -f $pack_dir/cts.tar | |
else | |
tar -c -T $ca_file -f $pack_dir/cts.tar | |
fi | |
if [ -e "$pack_dir/allmaps.tar" ]; then | |
tar -u -T ${maps} -f $pack_dir/allmaps.tar | |
else | |
tar -c -T ${maps} -f $pack_dir/allmaps.tar | |
fi | |
} | |
function listFiles() { | |
# Get the a list of all packages | |
for package in ${maps}; do | |
mapinfo=`unzip -qql $map_dir/$package 2>/dev/null | grep .mapinfo | grep -v "error" | awk '{ print $4 }'` | |
# a mapinfo exists | |
if [[ "$mapinfo" != "" ]]; then | |
server_types=`unzip -p $map_dir/$package *.mapinfo 2>/dev/null | grep "^type" | grep -v "//"` | |
#writeServerFile "${server_types[@]}" $package | |
for server_type in ${server_types[@]}; do | |
a=`echo $server_type | cut -f2 -d " "` | |
case $a in | |
"tdm") | |
# Escape regex characters for grep. | |
__map_file=`echo "$package" | sed 's/\[/\\\[/;s/\]/\\\]/g'` | |
# Grep for the existence of the file. | |
result=`grep "${__map_file}" $tdm_file` | |
echo ${__map_file} | |
if [[ $result != "" ]]; then | |
echo ${__map_file} $result | |
else | |
echo "false" | |
fi | |
esac | |
done | |
fi | |
done | |
} | |
listFiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment