Code: Select all
#!/bin/bash
BASEDIR=/home/ut99/ut-server
REDIRECTDIR=$BASEDIR/redirdownloads
# patterns relative to BASEDIR
PATTERNS[0]=Maps/*.unr
PATTERNS[1]=Music/*.umx
PATTERNS[2]=Sounds/*.uax
PATTERNS[3]=System/*.u
PATTERNS[4]=Textures/*.utx
EXCLUDEFILES="Engine.u IpDrv.u IpServer.u UBrowser.u UMenu.u UTBrowser.u UTMenu.u UTServerAdmin.u UWeb.u UWindow.u"
function ErrorExit {
echo error: $@
exit 1
}
function extract_filename {
# returns the part of the given parameter until (but without)
# the last dot.
# The result is not necessarly the filename itself - it may still
# contain a path. Use "basename" for that...
echo ${1%.*}
}
function extract_file_ext {
# returns the (last) extension of the given parameter
echo ${1##*.}
}
function GetDirToExt {
# 1. param: extension (eg "uax")
# returns the directory given in PATTERNS
local EXT="$1"
# echo ${#PATTERNS[@]}
for ((i=0; i < ${#PATTERNS[@]}; i++)); do
# echo "${PATTERNS[$i]}"
CUREXT=$(extract_file_ext "${PATTERNS[$i]}")
if [ "$CUREXT" = "$EXT" ]; then
echo $(dirname "${PATTERNS[$i]}")
return
fi
done
# for DIR in "${PATTERNS[@]}" ; do
# CUREXT=$(extract_file_ext "$DIR")
# echo $DIR
# done
}
function DoExclude {
for i in $EXCLUDEFILES; do
test "$i" = "$1" && return 0
done
return 1
}
function CheckRedirFiles {
for i in $REDIRECTDIR/*; do
test -f "$i" || continue
if [ -L "$i" ]; then
echo "skipping soft link \"$i\""
continue
fi
REDIR_FILENAME=$(basename "$i")
REDIR_EXT=$(extract_file_ext "$REDIR_FILENAME")
if [ "$REDIR_EXT" != "uz" ]; then
echo "Warning: extension 'uz' expected for file \"$i\", skipping"
continue
fi
# now left out the extension "uz":
REDIR_FILENAME=$(extract_filename "$REDIR_FILENAME")
# now get the extension of the uncompressed file:
EXT=$(extract_file_ext "$REDIR_FILENAME")
if [ -z "$EXT" ]; then
echo "Error: could not extract the uncompressed extension for file \"$i\", skipping"
continue
fi
SRCDIR=$(GetDirToExt "$EXT")
if [ -z "$SRCDIR" ]; then
echo "Error: could determinate the source directory for the extension \"$EXT\" of file \"$i\", skipping"
continue
fi
test -f "$SRCDIR/$REDIR_FILENAME" || echo "file not needed: $i"
done
}
CheckRedirFiles
cd $BASEDIR/System
for DIR in ${PATTERNS[@]}; do
for f in ../$DIR; do
FN=$(basename $f)
if [ -f "$REDIRECTDIR/$FN.uz" ]; then
test "$f" -ot "$REDIRECTDIR/$FN.uz" && continue
fi
DoExclude "$FN" && continue
test -f "$f.uz" && rm -v "$f.uz"
./ucc-bin compress "$f" -nohomedir | grep "Compressed"
test -f "$f.uz" || ErrorExit "compressed file $f.uz does not exist"
# touch "$f.uz" --reference="$f"
mv "$f.uz" "$REDIRECTDIR/"
done
done