• # debbuild

    Posté par . En réponse au journal construire un paquet debian -- KISS way (ou presque). Évalué à 10.

    En cadeau bonux, un script de construction de paquet debian, très inspiré des SlackBuilds :

    #!/bin/sh
    # Debian package creation script
    # Last release: https://github.com/valr/cbatticon/releases
    NAME="cbatticon"
    #VERSION="1.6.7"
    PKG="/tmp/build/$NAME"
    DOC="Changelog COPYING README"
    SRC="https://github.com/valr/cbatticon.git"
    #SRC="https://github.com/valr/cbatticon/archive/$VERSION.tar.gz"
    REVISION=${REVISION:-1}
    SECTION="x11"
    PRIORITY="optional"
    ARCH="amd64"
    DEPENDS=""
    MAINTAINER="masao"
    DESCRIPTION="A lightweight and fast battery icon that sits in your system tray"
    HOMEPAGE="https://github.com/valr/cbatticon"
    CONFFILES=""
    CWD=$(pwd)
    set -e
    umask 022
    if [ "$(id -u)" = "0" ]; then
     echo "Don't run this script as root !"
     exit 1
    fi
    ## GIT
    # Check if there is update
    if [ -d "$NAME" ]; then
     cd $NAME
     if [ $REVISION -eq 1 ]; then
     git fetch origin
     if [ -z "$(git log HEAD..origin/master --oneline)" ]; then
     echo "Already up to date"
     exit 0
     fi
     fi
    else
     git clone $SRC
     cd $NAME
    fi
    # Get last version
    git pull
    version=$(git log --date=short | grep '^Date' | head -1 | sed -r 's/.*([0-9]{4}-[0-9]{2}-[0-9]{2})/1円/' | tr -d '-')
    ## RELEASE
    #[ -e "$NAME-$VERSION" ] || wget $SRC -O $NAME-$VERSION.tar.gz
    #tar xvf $NAME-$VERSION.tar.gz
    #cd $NAME-$VERSION
    #version=$VERSION
    [ -d $PKG ] || mkdir -p $PKG
    make
    make install DESTDIR=$PKG
    # Install documentation
    mkdir -p $PKG/usr/share/doc/$NAME-$version
    cp -a $DOC $PKG/usr/share/doc/$NAME-$version
    # Compress man pages
    if [ -d $PKG/usr/share/man ]; then
     find $PKG/usr/share/man -type f -name "*.?" -exec gzip -9 {} \;
     for manpage in $(find $PKG/usr/share/man -type l -name "*.?") ; do
     ln -s $(readlink $manpage).gz $manpage.gz
     rm -f $manpage
     done
    fi
    # Copy systemd unit, if any
    if [ -r $CWD/${NAME}.service ]; then
     mkdir -p $PKG/lib/systemd/system
     cp $CWD/${NAME}.service $PKG/lib/systemd/system
    fi
    # Strip binaries, libraries and archives
    find $PKG -type f | xargs file | grep "ELF \(32\|64\)-bit LSB" | cut -d: -f1 | \
     xargs strip --strip-unneeded 2> /dev/null || echo "No binaries and/or shared objects to strip"
    find $PKG -type f | xargs file | grep "current ar archive" | cut -f 1 -d : | \
     xargs strip -g 2> /dev/null || echo "No archives to strip"
    # Prepare package
    mkdir $PKG/DEBIAN
    cat >$PKG/DEBIAN/control <<EOF
    Package: $NAME
    Version: $version-$REVISION
    Section: $SECTION
    Priority: $PRIORITY
    Architecture: $ARCH
    Depends: $DEPENDS
    Maintainer: $MAINTAINER
    Description: $DESCRIPTION
    Homepage: $HOMEPAGE
    EOF
    if [ -n "$CONFFILES" ]; then
     for conffile in $CONFFILES ; do
     echo $conffile >>$PKG/DEBIAN/conffiles
     done
    fi
    for script in postrm prerm preinst postinst ; do
     if [ -r $CWD/$script ]; then
     cp $CWD/$script $PKG/DEBIAN/
     chmod 755 $PKG/DEBIAN/$script
     fi
    done
    # Build package
    fakeroot dpkg-deb --build $PKG $CWD/$NAME-$version-${REVISION}.deb
    rm -rf $PKG