Receipt for: tazpkg

source stuff/check_tazpkgupg.sh stuff/it.po stuff/tazpkg-doc-fr.patch
# SliTaz package receipt.

PACKAGE="tazpkg"
VERSION="5.8.2"
CATEGORY="base-system"
SHORT_DESC="SliTaz packages manager"
MAINTAINER="pankso@slitaz.org"
LICENSE="GPL3"
WEB_SITE="http://www.slitaz.org/"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WGET_URL="http://hg.slitaz.org/tazpkg/archive/$VERSION.tar.gz"
TAGS="slitaz package-manager"
HOST_ARCH="i486 arm x86_64"

DEPENDS="busybox gettext-base"
SUGGESTED="tazpanel"
BUILD_DEPENDS="gettext"

# Gettext is part of cross-chroot
case "$ARCH" in
	arm)  BUILD_DEPENDS="" ;;
esac

# What is the latest version available today?
# Latest hg tag (the release marker) -- first <title> is the feed name,
# second is the newest tag.
current_version()
{
	wget -O - http://hg.slitaz.org/$PACKAGE/rss-tags 2>/dev/null | \
	sed '/<title>/!d;s|.*<title>||;s|</title>.*||' | sed -n '2p'
}

# Rules to gen a SliTaz package suitable for TazPkg.
#
# TazPkg is SliTaz packages manager. On an other GNU/Linux install
# can be do with `make install` from the sources directory.
#

# Rules to configure and make the package.
compile_rules()
{
        # Thanks Rantanplan, fix miss translate in tazpkg.fr.html
        patch -p1 < $stuff/tazpkg-doc-fr.patch

	# Upgrade subsystem (free-space, prefetch, upgrade-lock, tazpkg-first,
	# core-pkg ordering) is now upstream in the tazpkg repo (>= 5.8 / rev 986).
	# 5.8.1: glibc-base/gcc-lib-base now upgraded before busybox (rev 988).
	# 5.8.2: install_all_deps resolves LOCAL deps that have no arch suffix
	# (i486 legacy names) and globs $PKGS when packages.info lacks the dep
	# (rev 990/992/993). Before this, a bdep's transitive DEPENDS (e.g.
	# e2fsprogs-dev -> libcomerr-dev) silently dropped to the mirror -> flaky
	# builds ("passait sur tank, plus sur marmite"). 5.8.1 (rev 988) predates
	# the fix, so this bump is required to actually ship it into the chroots.

	# Ensure we don't add .orig / .rej
	rm -rf modules/*.orig modules/*.rej

	# Disable libnotify dependency
	sed -i "s|^all: msgfmt notify$|all: msgfmt|" Makefile
	sed -i "/tazpkg-box tazpkg-notify/s/ tazpkg-notify//" Makefile
	sed -i "s|install -m 0755 build/tazpkg-notify|#install -m 0755 build/tazpkg-notify|" Makefile
	sed -i "s|install -m 0755 tazpkg-notification|#install -m 0755 tazpkg-notification|" Makefile

	# Enable it locale
	sed -i 's/fr ja/fr it ja/' Makefile
	cp $stuff/it.po po

	sed -i 's|\. receipt|. ./receipt|' */*
	make && make DESTDIR=$DESTDIR VERSION=$VERSION install
}

genpkg_rules()
{
	mkdir -p $fs/etc/init.d
	cp -a $stuff/check_tazpkgupg.sh $fs/etc/init.d

	cp -a $install/* $fs
	chown -R root:root $fs

	# Default icon for mimetype (freedesktop standard compliant file
	# manager will diplay a tazpkg icon for SliTaz packages).
	icons="$fs/usr/share/icons/hicolor/32x32/mimetypes"
	mkdir -p $icons
	ln -s ../apps/tazpkg.png $icons/application-x-tazpkg.png
}

post_install()
{
	# Remove lockfile if exist, now tazpkg upgraded
	if [ -f /var/lock/tazpkgup.lock ]; then
		rm /var/lock/tazpkgup.lock
	fi

	# Ensure symlink for locale doc always exist
	if [ -f $1/etc/locale.conf ]; then
		locale=$(cat $1/etc/locale.conf | awk -F'LANG=' '{print $2}' \
		| sed 's/.UTF-8//')
		chroot "$1/" /sbin/tazlocale $locale 
	fi

	# Apply a fix to config file /etc/slitaz/slitaz.conf
	[ -f $1/etc/slitaz/slitaz.conf ] && \
		sed -i 's/LOCAL_STATE/LOCALSTATE/' $1/etc/slitaz/slitaz.conf
	grep -q ^Icon= $1/usr/share/applications/tazpkg-url.desktop ||
	  echo "Icon=tazpkg" >> $1/usr/share/applications/tazpkg-url.desktop

	# Add variables missing from tazpkg.conf (non-destructive merge from reference)
	default="$1/usr/share/tazpkg/tazpkg.conf.default"
	sysconf="$1/etc/slitaz/tazpkg.conf"
	if [ -f "$default" ] && [ -f "$sysconf" ]; then
		while IFS= read -r line; do
			case "$line" in ''|'#'*) continue ;; esac
			var="${line#export }"
			var="${var%%=*}"
			grep -q "^${var}=\|^export ${var}=" "$sysconf" || echo "$line" >> "$sysconf"
		done < "$default"
	fi
}