
Untitled
By: a guest on
Oct 14th, 2012 | syntax:
Bash | size: 1.77 KB | hits: 30 | expires: Never
#!/bin/sh
###
#Just a boilerplate shell script preamble that I use
usage()
{
cat <<-USAGE
Create new Debian package version of updated WordPress package
usage: ${0##*/} FILE
positional arguments:
FILE .zip-file of WordPress package
USAGE
exit 1
}
#Enable -h. Mostly a placeholder for potential future switches.
while getopts "h" option; do
case ${option} in
h|\? ) usage;;
esac
done
shift $((${OPTIND}-1))
#If exactly one argument is not given to the script, show usage instructions.
[ ${#} -ne 1 ] && usage
###
set -e
REPOSITORY=/home/whatever
#unzip does not have a -- construct, it seems. This is a workaround.
unzip "$(readlink -f -- "${1}")"
#Instead of forking wc, cut and sed (along with the unicode troubles they all
#inherit), all simple matchings can be done POSIXly consistent and forkless
#with parameter expansion.
#
#Strip everything up to and including last directory separator
FILE=${1##*/}
#Strip everything including and after first dot
PACKAGE=${FILE%%\.*}
#Pick out the remainder of the $FILE string from the above expression,
#excluding the separating dot
ENDING=${FILE#${PACKAGE}\.}
#Strip trailing .zip
VER=${ENDING%\.zip}
DIRNAME="wordpress-${PACKAGE}-${VER}"
mv -- "${PACKAGE}" "${DIRNAME}"
tar czf "wordpress-${PACKAGE}_${VER}.orig.tar.gz" -- "${DIRNAME}"
cd -- "${DIRNAME}"
#No need to reverse ls output and picking the last line - don't reverse and
#just pick the first (head -1 closes the pipe when the first line has been
#read, so it is also infinitesimally faster, yay :-) ).
tar xzf -- "$(ls -t -- "${REPOSITORY}/wordpress-${PACKAGE}"_*.debian.tar.gz | head -1)"
dch -i
dpkg-buildpackage
#Change directory back to where the script was called (and don't bother the
#user with details)
cd - >/dev/null