WindowMaker themes -> Debian packages
Hi. Over the weekend, I wrote a script that converts WindowMaker themes to
Debian packages automatically. (the themes have to follow wm.t.o's packaging
policy). I think it would be useful for other Debian users but I don't really
know what to do with it. So, based on looking over Debian's mailing lists,
I'm mentioning it here. (would a different list have been more appropriate?)
The script can do a number of useful things, including converting .tar.gz
theme files to .deb packages, downloading themes from wm.t.o and then
converting them, and installing the packages. I think it may go against
Debian policy in that it drops all the themes into the section
wmaker-themes, but that should be easily fixed..lintian also tells me that
I need a Copyright file, unfortunately that's hard to guess from the package
file. (maybe I could try to extract it from the .lsm...)
Anyway, in the hope that it's useful, here it is.
Daniel Burrows
PS - I just read the Weekly Newsletter and noticed discussion of distributing
WindowMaker, E, etc themes as Debian packages. I suppose that this is somewhat
relevant to that. Personally, I think that I'd rather preview the themes
on the Web page and then install them with the script but...
#!/bin/sh
# Copyright (C) 1999 Daniel Burrows
umask 022
# rwxr-xr-x
trap '
echo "Interrupted! Cleaning up.."
rm -rf /tmp/wmto2deb_$$
exit 0
' EXIT
show_help() {
cat << EOF
wmto2deb -- create Debian packages from wm.themes.org theme archives
Usage: wmto2deb [option] ... <theme.tar.gz> [--description <description> ...]
--email <address>
Specify the address to use as the package maintainer address
--name <address>
Specify the name to use as the package maintainer
--pkgver <version>
Specify the version number to give to the package
--no-infer-descr
If this is given, the script will not attempt to infer a description
for the package from the files in the theme archive
--install
Attempt to install the packages after building them.
--sudo
--su
--nogetperms
Determine how wmto2deb tries to become root to install a package. It
can use sudo, su, or not attempt to gain extra priviliges.
--verbose
Print lots of extra information
--quiet
Don't print much information
--version
Print the version number of this program
--help
Display this information
--license
Display license information
Package options:
These options control settings for individual packages.
--download <theme>
This is treated exactly as if a file were being named, except that
the theme is fetched from wm.themes.org rather than from the local
filesystem. Requires wget.
--description <description>
Specify the description to use for the package.
--pkgname <name>
Specify the name to give the package (in the Debian database)
--pkgfile <filename>
Specify the file to store the package in. ( - for stdout )
EOF
}
show_license() {
cat << EOF
Copyright (C) 1999 Daniel Burrows
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
EOF
}
echo_verbose() {
if [ "$VERBOSITY" = "VERBOSE" ]; then echo $* 1>&2; fi
}
echo_normal() {
if ! [ "$VERBOSITY" = "QUIET" ]; then echo $* 1>&2; fi
}
tee_verbose() {
if [ "$VERBOSITY" = "VERBOSE" ]; then tee $1; else filename=$1; shift; tee $* > $filename ; fi
}
tar_verbose() {
if [ "$VERBOSITY" = "VERBOSE" ]; then tar -v $*; else tar $*; fi
}
dpkg_verbose() {
if [ "$VERBOSITY" = "VERBOSE" ]; then dpkg $*; else dpkg $* > /dev/null; fi
}
fakeroot_verbose() {
if [ "$VERBOSITY" = "VERBOSE" ]; then fakeroot $*; else fakeroot $* > /dev/null; fi
}
wget_verbose() {
case "$VERBOSITY" in
"VERBOSE") wget --verbose $* ;;
"QUIET") wget --quiet $* ;;
"NORMAL") wget -nv $* ;;
* )
echo_normal "Hmm, weirdness in wget_verbose(), assuming normal verbosity" 1>&2
wget -nv $*
;;
esac
}
exit_notrap() {
trap EXIT
exit $*
}
unset ARCHIVES
unset BLURBS
unset PKGNAMES
unset DOWNLOADS
unset PKGFILES
EMAIL=`whoami`@`hostname -f`
NAME=$(grep ^`whoami` /etc/passwd | sed --expression 's/[^:]*:[^:]*:[^:]*:[^:]*:\([^:,]*\).*/\1/')
VERSION=1.0-0
LONG_DESCRIPTION=true
QUIET=false
INSTALL=false
VERBOSITY=NORMAL
if which sudo > /dev/null
then
GETPERMS=sudo
else
if which su > /dev/null
then
GETPERMS=su
else
GETPERMS=
fi
fi
if ! ( [ `id -u` -eq 0 ] || which fakeroot > /dev/null )
then
NEED_POSTINST=true
else
NEED_POSTINST=false
fi
while [ $# -ne 0 ]
do
case "$1" in
"--version" )
echo "wmto2deb version 0.6.2a"
shift
;;
"--license" )
show_license
exit_notrap 0
;;
"--email" )
if [ $# -lt 2 ]
then
echo "Warning! No argument to --email!"
else
EMAIL="$2"
shift 2
fi
;;
"--quiet" )
VERBOSITY=QUIET
shift
;;
"--verbose" )
VERBOSITY=VERBOSE
shift
;;
"--name" )
if [ $# -lt 2 ]
then
echo "Warning! No argument to --name!"
else
NAME="$2"
shift 2
fi
;;
"--pkgver" )
if [ $# -lt 2 ]
then
echo "Warning! No argument to --pkgver!"
else
VERSION="$2"
shift
fi
shift
;;
"--description" )
echo "Warning! Description encountered without an associated theme file!"
shift
;;
"--no-infer-descr" )
LONG_DESCRIPTION=false
shift
;;
"--install" )
INSTALL=true
shift
;;
"--sudo" )
GETPERMS=sudo
shift
;;
"--su" )
GETPERMS=su
shift
;;
"--nogetperms" )
GETPERMS=
shift
;;
"--help" )
show_help
exit_notrap 0
;;
* )
# First, assume this is a package..
if ! ( [ "$1" = "--download" ] || [ "$1" = "-" ] || tar tzf $1 > /dev/null 2>&1 )
then
echo "Hmm, $1 doesn't look like a tarball to me, skipping.."
shift
else
if [ "$1" = "--download" ]
then
DOWNLOADS[${#DOWNLOADS[*]}]=true
shift
else
DOWNLOADS[${#DOWNLOAD[*]}]=false
fi
i=${#ARCHIVES[*]}
ARCHIVES[i]=$1
BLURBS[i]="`basename ${1%.tar.gz}` theme for WindowMaker"
shift
while [ $# -ne 0 ]
do
case "$1" in
"--description" )
if [ "$#" -lt 2 ]
then
echo "Warning! No argument to --description!"
else
BLURBS[i]=$2
shift
fi
shift
;;
"--pkgname" )
if [ "$#" -lt 2 ]
then
echo "Warning! No argument to --pkgname!"
else
PKGNAMES[i]=$2
shift
fi
shift
;;
"--pkgfile" )
if [ "$#" -lt 2 ]
then
echo "Warning! No argument to --pkgfile!"
else
PKGFILES[i]=$2
shift
fi
shift
;;
* )
break
;;
esac
done
fi
;;
esac
done
if [ -z "${ARCHIVES[*]}" ]
then
echo "wmto2deb: no archives specified"
show_help
exit_notrap 1
fi
if [ -z "$EMAIL" ] && [ -z "$NAME" ]
then
echo "wmto2deb: Both name and email are null, can't get maintainer data"
exit_notrap 1
fi
if "$INSTALL" && [ `id -u` -ne 0 ] && [ -z "$GETPERMS" ]
then
echo "wmto2deb: You asked me to install the package, but you aren't root and I"
echo " don't know how to become root."
exit_notrap 1
fi
echo_verbose "Processing archives: ${ARCHIVES[*]}"
echo_verbose
i=0
while [ $i -lt "${#ARCHIVES[*]}" ]
do
echo_verbose "Processing $ARCHIVES"
echo_verbose
FILENAME=${ARCHIVES[i]}
TARFILE=`basename $FILENAME`
THEMENAME=${TARFILE%.tar.gz}
PACKAGENAME=wm-theme-`echo $THEMENAME | sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ `
if [ -z "${PKGNAMES[i]}" ]
then
PKGNAMES[i]=$PACKAGENAME
else
PACKAGENAME=${PKGNAMES[i]}
fi
DESCRIPTION=${BLURBS[i]}
IS_DOWNLOAD=${DOWNLOADS[i]}
PACKAGEFILE=/tmp/$PACKAGENAME.deb
if [ -z "${PKGFILES[i]}" ]
then
PKGFILES[i]=$PACKAGEFILE
else
PACKAGEFILE=${PKGFILES[i]}
fi
i=$(($i+1))
cd /tmp
mkdir wmto2deb_$$ || {
echo "Couldn't create temporary working directory!"
exit_notrap 1
}
cd wmto2deb_$$
echo_normal
echo_normal "Building theme package $PACKAGENAME"
(
echo_verbose
echo_verbose "Creating directory structure.." &&
mkdir $PACKAGENAME &&
cd $PACKAGENAME &&
mkdir usr &&
cd usr &&
mkdir share &&
cd share &&
mkdir WindowMaker &&
cd WindowMaker &&
echo_verbose "Unpacking theme archive.." &&
if ! $IS_DOWNLOAD
then
tar_verbose -xzf $FILENAME
else
wget_verbose -O - 'http://wm.themes.org/theme-download.cgi?name='$FILENAME | tar_verbose -xzf -
fi
) || {
echo "Ack! Something bad happened while unpacking the theme archive! Aborting.."
rm -rf /tmp/wmto2deb_$$
exit_notrap 1
}
echo_verbose
echo_verbose "Creating Debian control info..."
echo_verbose
(
cd $PACKAGENAME
mkdir DEBIAN &&
{ ( cat | tee_verbose DEBIAN/control ) << EOF
Package: $PACKAGENAME
Version: $VERSION
Architecture: all
Depends: wmaker
Maintainer: $( if ! [ -z "$NAME" ]; then echo "$NAME" $( if ! [ -z "$EMAIL" ]; then echo "<$EMAIL>"; fi ); else echo "$EMAIL"; fi )
`
echo "Description: $DESCRIPTION"
DESCFILES=$(find usr/share/WindowMaker/ -maxdepth 1 -type f)
if "$LONG_DESCRIPTION" && ! [ -z "$DSECFILES" ]
then
for i in $DESCFILES
do
echo "Description: "
{
while read THISLINE
do
if [ "${THISLINE##Description*:*}" = "" ]
then
echo " ${THISLINE#Description*:}"
while read THISLINE
do
echo -n " "
echo $THISLINE
done
rm $DESCFILES
exit 0
fi
done
} < $i
done
rm $DESCFILES
fi
`
Section: wmaker-themes
Priority: optional
EOF
} &&
if $NEED_POSTINST
then
echo_verbose "Creating postinst file.." && {
(cat | tee_verbose DEBIAN/postinst) << EOF
#!/bin/sh
for i in `find usr/share/WindowMaker/* | sed 's/$/ \\\\/' `
do
chown root.root /\$i
done
EOF
} && chmod a+x DEBIAN/postinst
else
echo_verbose "Don't need postinst, skipping.."
fi
) || {
echo "Couldn't create control info, bailing out..."
rm -rf /tmp/wmto2deb_$$
exit_notrap 1
}
echo_verbose
echo_verbose "Building package.."
{
if which fakeroot > /dev/null
then
echo_verbose "Found fakeroot, using it."
fakeroot_verbose dpkg --build $PACKAGENAME || { echo "Couldn't build package, bailing out..."; exit_notrap 1; }
else
dpkg_verbose --build $PACKAGENAME || { echo "Couldn't build package, bailing out..."; exit_notrap 1; }
fi
} || {
echo "Couldn't build package, bailing out.."
rm -rf /tmp/wmto2deb_$$
exit_notrap 1
}
echo_verbose
echo_verbose "Moving package to $PKGFILE"
if [ "$PACKAGEFILE" = "-" ]
then
cat /tmp/wmto2deb_$$/$PACKAGENAME.deb
else
mv /tmp/wmto2deb_$$/$PACKAGENAME.deb $PACKAGEFILE
fi
echo_verbose "Cleaning up.."
cd /tmp
rm -rf /tmp/wmto2deb_$$
done
DO_INSTALL="dpkg --install `for i in ${PKGFILES[*]}; do if ! [ "$i" = "-" ]; then echo $i; fi; done`"
if "$INSTALL"
then
if [ "$DO_INSTALL" = "dpkg --install " ]
then
echo_normal "Can't install packages, they're all going to stdout!"
else
if [ "$GETPERMS" = "su" ]
then
su -c "$DO_INSTALL"
else
$GETPERMS $DO_INSTALL
fi
fi
else
echo_normal "Done! Packages are in /tmp/<themename>.deb by default."
fi
trap EXIT
Reply to: