#! /bin/sh # Copyright (C) 2010 Carsten Hey # Published under the terms of the MIT license # and provided without warranty of any kind. set -u set -e gen_changelog() { local CHANGELOG="${1:?}" shift local DCH="dch --no-conf --no-auto-nmu --noquery \ --force-distribution --distribution unstable \ --changelog $CHANGELOG" if ! [ -f "$CHANGELOG" ] then # create new changelog file $DCH --newversion "0.0.0~$(date '+%Y%m%d')" \ --package "$DIR2DEB_PACKAGENAME" \ --create "Initial release." else # increment version number and add new entry local OLD_VERSION="$( dpkg-parsechangelog -l"$CHANGELOG" \ | awk '/^Version: / { print $2 }' )" local NEW_VERSION="0.0.0~$( date '+%Y%m%d' )" if [ "$OLD_VERSION" = "$NEW_VERSION" ] then # append +1 to old version number NEW_VERSION="$OLD_VERSION+1" elif printf '%s\n' "${OLD_VERSION#$NEW_VERSION}" \ | grep -qE '^\+[0-9]+$' then # increment old version number by 1 NEW_VERSION="${NEW_VERSION}+$(( 1 $( printf '%s\n' "$OLD_VERSION" \ | grep -oE '\+[0-9]+$' ) ))" fi $DCH --newversion "$NEW_VERSION" \ "New release." fi } gen_compat() { local FILENAME="${1:?}" shift if [ -e "$FILENAME" ]; then return 0; fi echo "$DIR2DEB_COMPAT" > "$FILENAME" } gen_control() { local FILENAME="${1:?}" shift if [ -e "$FILENAME" ]; then return 0; fi cat > "$FILENAME" <<- EOH Source: $DIR2DEB_PACKAGENAME Section: misc Priority: optional Maintainer: ${DEBFULLNAME:?} <${DEBEMAIL:?}> Build-Depends: debhelper (>= ${DIR2DEB_COMPAT}) Standards-Version: $DIR2DEB_STANDARDS_VERSION Package: $DIR2DEB_PACKAGENAME Architecture: all Depends: \${misc:Depends} Description: No description yet. No long description yet. EOH } # }}} gen_copyright() { local FILENAME="${1:?}" shift if [ -e "$FILENAME" ]; then return 0; fi cat > "$FILENAME" <<- EOH [ Do not upload with this minimalistic debian/copyright file! ] Please check indivudal files in this package for their copyright and license information. EOH } gen_rules() { local FILENAME="${1:?}" shift if [ -e "$FILENAME" ]; then return 0; fi cat > "$FILENAME" << "EOH" #!/usr/bin/make -f build clean : ; dh $@ binary : binary-arch binary-indep binary-% : install ; dh $@ install : build install-stamp install-stamp: dh_testdir dh_testroot dh_prep dh_installdirs test -d "`pwd`/debian/`dh_listpackages`" find . -mindepth 1 -maxdepth 1 -type d ! -name debian \ -exec cp -a '{}' "`pwd`/debian/`dh_listpackages`" ';' touch $@ EOH chmod a+rx "$FILENAME" } dir="${1:?please specify directory\n}" shift DIR2DEB_COMPAT="7" DIR2DEB_STANDARDS_VERSION="3.8.4" DIR2DEB_PACKAGENAME="$(cd $dir ; basename `pwd`)" : ${DEBFULLNAME:?you need to set $DEBFULLNAME\n} : ${DEBEMAIL:?you need to set $DEBEMAIL} if [ ! -d "$dir/debian" ] \ && [ ! -d "$dir/bin" ] \ && [ ! -d "$dir/boot" ] \ && [ ! -d "$dir/etc" ] \ && [ ! -d "$dir/lib" ] \ && [ ! -d "$dir/sbin" ] \ && [ ! -d "$dir/usr" ] \ && [ ! -d "$dir/var" ] then echo "Can't find package directory in \"$dir\"" >&2 exit 1 fi if [ ! -d "$dir/debian" ]; then mkdir "$dir/debian" fi gen_changelog "$dir/debian/changelog" gen_compat "$dir/debian/compat" gen_control "$dir/debian/control" gen_copyright "$dir/debian/copyright" gen_rules "$dir/debian/rules"