Someone asked for a tar2rpm script which could convert tar files into rpm files so they could be installled, upgraded and removed by the standard package tools. Not being into rpm I ignored the thread until told him that it would be hard.

And then I had to write a tar2deb script to show how easy it could be:


#!/bin/sh

# $1 - tar.gz fil
# $2 - package name
# $3 - version

CONTROL=$( mktemp -dt )
DATA=$( mktemp -dt )

cat $1 | (cd $DATA ; tar xvzf - )

SIZE=$( du -s $DATA | cut -f1 )

cat > $CONTROL/control <<EOF
Package: $2
Section: unknown
Priority: optional
Architechture: all
Version: $3
Installed-Size: $SIZE
Maintainer: $USER
Description: Deb-package made from $1
 This package is made by tar2deb by $USER at
 $( date ) from $1
EOF

(cd $DATA; find -type f | xargs md5sum ) > $CONTROL/md5sums
(cd $CONTROL; tar cvzf control.tar.gz *)
cp $1 $CONTROL/data.tar.gz
echo 2.0 > $CONTROL/debian-binary

ar -cr $2_$3_all.deb $CONTROL/{debian-binary,control.tar.gz,data.tar.gz}

rm -Rf $CONTROL
rm -Rf $DATA

exit 0;

I not sure I would use it in a production system but I think it is at interesting script. Wouldn't a tar2rpm be as easy to write? No, deb packages can be made with standard unix tools while rpm packages is a cpio archive with a header which isn't quite as easy to manipulate directly.