User:Watchout/Package
From WoWWiki
I wrote this script for my iBook since I'm developing on it. If you want to use it on a linux box you should set the makedmg variable to something else than "yes".
usage: ScriptName AddonFolder [AdditionalFolder ...]
- the script will parse AddonFolder for a .toc file and this one for a Version line and name the archive
AddonFolder.Version.extension. - You can define additional folders (virtually no limit, but there may be a limit from bash itself) that will be included in the archive, thats useful for load-on-demand user interface additions to an addon.
Created and tested on: MacOSX 10.3.7-10.3.9; Bash 2.05b.0; Zip 2.1;
Also tested on Windows XP (SP2/3) with Cygwin installed and using the "Console" or the default cygwin shell
#!/bin/bash
# defaults
makedmg="yes";
makezip="yes";
function Copy()
{
#echo Object: $1;
#echo Target: $2;
if [[ -d "$1" ]]; then
#echo Creating Directory $2/$1;
mkdir "$2/$1";
fi
for name in "$1"/*; do
if [[ -d "$name" ]]; then
Copy "$name" "$2";
fi
done
for name in $1/?*{.lua,.tga,.toc,.xml,.ttf,.txt}; do
if [[ -f "$name" ]]; then
#echo Copying $name to $2/$name;
cp "$name" "$2/$name";
fi
done
}
function dmp()
{
local ok=;
if [[ $1 == "-o" ]]; then
echo -e "\r[\033[1mdone\033[0m";
tput sgr0;
elif [[ $1 == "-f" ]]; then
echo -e "\r[\033[1m\E[31;31mfail\033[0m";
tput sgr0;
else
echo -n "[ ?? ]" $@;
fi
}
if [[ -d "$1" ]]; then
echo Archiving $1;
AF=".Archive";
if [[ -d "$AF" ]]; then
dmp Folder $AF exists... deleting...;
rm -r "$AF";
dmp -o;
fi
# create temporary Archive Folder
dmp Creating Folder $AF....;
mkdir "$AF";
dmp -o
shopt -s nullglob;
shopt -s nocaseglob;
# Copy Files
for dir; do
dmp Copying Files in Folder $dir... ;
Copy "$dir" "$AF";
dmp -o;
done
echo Figuring out the version number...
dv="0";
hit=0;
if [[ -f "$1/$1.toc" ]]; then
line=`grep -E "Version: [[:alnum:]]+" < "$1/$1.toc"`
v=`echo $line | awk '{gsub("\r",""); gsub(".*Version:[ \t]+",""); print $0}'`;
fi
if [[ $v ]]; then
echo Version Number is: $v;
else
echo No Version Number found, using default: $dv
fi
################
# ZIP creation #
if [[ $makezip == "yes" ]]; then
an="$1.$v.zip";
if [[ -f "$an" ]]; then
dmp Deleting old ZIP Archive...
rm "$an";
dmp -o;
fi
dmp Creating ZIP Archive...;
cd "$AF";
zip -rq9 "../$an" "$1";
cd ..
dmp -o;
fi
################
# DMG creation #
if [[ $makedmg == "yes" ]]; then
an="$1.$v.dmg";
dmp Creating DMG Archive...;
hdiutil create -quiet -noscrub -ov -volname "$1" -srcfolder "$AF" -format UDZO -imagekey zlib-level=9 "$an"
dmp -o;
fi
################
# Cleaning up #
dmp Deleting Temporary Files...;
rm -r "$AF";
dmp -o;
fi
