summaryrefslogtreecommitdiff
path: root/scripts/tarpkg
blob: 40ff9412270c17fd4579621c17940584003af33f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash
# create/install compressed tar balls
#set -x

if [ "$1" = "build" ];then
	if [ ! -d $2 ];then
		echo "not a directory"
		exit 1
	fi
	pkgname=$(grep "^Package:" $2/CONTROL/control | sed -e "s/^[^:]*:[[:space:]]*//")
	version=$(grep "^Version:" $2/CONTROL/control | sed -e "s/^[^:]*:[[:space:]]*//")
	arch=$(grep "^Architecture:" $2/CONTROL/control | sed -e "s/^[^:]*:[[:space:]]*//")
	for file in preinst postinst prerm postrm; do
	  [ ! -f $2/CONTROL/$file ] || ( mkdir -p ${2}/usr/lib/pkg && \
		cp $2/CONTROL/$file ${2}/usr/lib/pkg/${pkgname}.$file && \
		chmod +x ${2}/usr/lib/pkg/${pkgname}.$file )
	done
	rm -rf $2/CONTROL 
	(cd $2 && tar -cf - .|xz -c > $3/${pkgname}_${version}_${arch}.tar.xz)
elif [ "$1" = "install" ];then
	pkg=$(echo $(basename $2)|sed -e "s#_.*##")
	if [ -x ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.preinst ]; then
   	  IPKG_INSTROOT="$PKG_INSTROOT" ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.preinst
	  rm ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.preinst
	fi
	xz -d -c $2|tar -xpf - -C ${PKG_INSTROOT}
	if [ -x ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.postinst ]; then
   	  IPKG_INSTROOT="$PKG_INSTROOT" ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.postinst
	  rm ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.postinst
	fi
	rm -rf ${PKG_INSTROOT}/usr/lib/pkg
else
	echo "unknown command"
	exit 1
fi