| 1 | #!/bin/bash |
|---|
| 2 | #(C)DatuX 2008 all rights reserved |
|---|
| 3 | |
|---|
| 4 | # Gets a .deb debian package from a packagename out of the svn tree. |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | cd `dirname $0` |
|---|
| 9 | CWD=`pwd` |
|---|
| 10 | PKG=$1 |
|---|
| 11 | TARGET=$2 |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | if ! [ -e "$TARGET" ]; then |
|---|
| 15 | echo "Usage: "; |
|---|
| 16 | echo " $0 packagename /path/to/target/dir" |
|---|
| 17 | echo |
|---|
| 18 | echo "This will convert the syn3 svn-package to a debian package and put it in the target dir." |
|---|
| 19 | echo "Also outputs a .deb.syn3 file which is used by $0 to allow intelligent caching." |
|---|
| 20 | exit 1 |
|---|
| 21 | fi |
|---|
| 22 | |
|---|
| 23 | mkdir -p $TARGET 2>/dev/null |
|---|
| 24 | |
|---|
| 25 | if TAR=`./findfile "$PKG.pkg"`; then |
|---|
| 26 | BASEPATH=`echo $TAR| sed 's/.pkg$//'` || exit 1 |
|---|
| 27 | FULLNAME=`./pkgname $TAR | sed 's/.tgz//'`.deb || exit 1 |
|---|
| 28 | BUILDPATH=`./findbuild $PKG` || exit 1 |
|---|
| 29 | #calc MD5 sum of files that are used to generate the .deb. |
|---|
| 30 | MD5="`cat $BUILDPATH.md5 $BASEPATH.arch $BASEPATH.version $BASEPATH.{preinst,postinst,prerm,postrm} 2>/dev/null| md5sum`" || exit 1 |
|---|
| 31 | else |
|---|
| 32 | TAR=`./findpkg $PKG` || exit 1 |
|---|
| 33 | FULLNAME=`echo $TAR | sed 's@.*/@@' | sed 's/.tgz//' `.deb || exit 1 |
|---|
| 34 | BUILDPATH= |
|---|
| 35 | MD5=`cat $TAR| md5sum ` || exit 1 |
|---|
| 36 | fi |
|---|
| 37 | |
|---|
| 38 | echo "Tar= $TAR"; |
|---|
| 39 | echo "Fullname= $FULLNAME"; |
|---|
| 40 | echo "Buildpath= $BUILDPATH"; |
|---|
| 41 | echo "MD5= $MD5"; |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | #do we need to rebuild the .deb file? |
|---|
| 45 | #check if the md5 we build the .deb against still matches: |
|---|
| 46 | if ! grep -x "$MD5" $TARGET/$FULLNAME.syn3 &>/dev/null; then |
|---|
| 47 | echo -n " (creating) " >&2 |
|---|
| 48 | |
|---|
| 49 | #tempdir and cleanup |
|---|
| 50 | TMP=`mktemp -d` || exit 1 |
|---|
| 51 | trap "rm -r $TMP" 0 |
|---|
| 52 | |
|---|
| 53 | #echo "Installing in $TMP:" |
|---|
| 54 | TGZ=`./findpkg $PKG` || exit 1 |
|---|
| 55 | ROOT=$TMP installpkg $TGZ &>/dev/null || exit 1 |
|---|
| 56 | |
|---|
| 57 | #HACK:we bepalen de runtime dependencys nu nog aan de hand van de build time deps. |
|---|
| 58 | #dit moet nog anders. |
|---|
| 59 | #BUILDSCRIPT=`./findbuild $PKG`.SlackBuild || return 0 |
|---|
| 60 | #DEPS="`cat "$BUILDSCRIPT"|egrep '^#NEED:|^#DEP:'|cut -f2 -d':'`" || exit 1 |
|---|
| 61 | DEPS= |
|---|
| 62 | |
|---|
| 63 | #echo "Adding control file.." |
|---|
| 64 | mkdir $TMP/DEBIAN |
|---|
| 65 | CONTROL=$TMP/DEBIAN/control |
|---|
| 66 | echo "Package: $PKG" > $CONTROL |
|---|
| 67 | |
|---|
| 68 | #hackerdehack |
|---|
| 69 | VER=`cat $BASEPATH.version` |
|---|
| 70 | if ! [ "$VER" ]; then |
|---|
| 71 | VER=0.0 |
|---|
| 72 | fi |
|---|
| 73 | echo "Version: $VER" >> $CONTROL |
|---|
| 74 | echo "Maintainer: root@datux.nl" >> $CONTROL |
|---|
| 75 | echo "Description: Auto generated package by Syn-3 getdeb." >> $CONTROL |
|---|
| 76 | if [ "$DEPS" ]; then |
|---|
| 77 | echo "Depends: `echo $DEPS| sed 's/ /, /g'`" >> $CONTROL |
|---|
| 78 | fi |
|---|
| 79 | |
|---|
| 80 | #copy install scripts |
|---|
| 81 | cp $BASEPATH.{preinst,postinst,prerm,postrm} $TMP/DEBIAN/ 2>/dev/null |
|---|
| 82 | |
|---|
| 83 | #translate architecture to a debian-compatible one. |
|---|
| 84 | #this is either: all or i386 |
|---|
| 85 | DEBARCH=`cat $BASEPATH.arch | sed 's/noarch/all/' | sed 's/i.86/i386/'`; |
|---|
| 86 | if ! [ "$DEBARCH" ]; then |
|---|
| 87 | DEBARCH=i386 |
|---|
| 88 | fi |
|---|
| 89 | echo "Architecture: $DEBARCH" >> $CONTROL |
|---|
| 90 | |
|---|
| 91 | dpkg-deb --nocheck -b $TMP $TARGET/$PKG.deb >/dev/null || exit 1 |
|---|
| 92 | |
|---|
| 93 | #store md5 for the situation we've build against |
|---|
| 94 | echo "$MD5" > $TARGET/$FULLNAME.syn3 |
|---|
| 95 | fi |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | #echo the absolute path to the created or cached deb package |
|---|
| 99 | echo "$TARGET/$FULLNAME" |
|---|
| 100 | exit 0 |
|---|