tarpkg 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. # create/install compressed tar balls
  3. #set -x
  4. if [ "$1" = "build" ];then
  5. if [ ! -d $2 ];then
  6. echo "not a directory"
  7. exit 1
  8. fi
  9. pkgname=$(grep "^Package:" $2/CONTROL/control | sed -e "s/^[^:]*:[[:space:]]*//")
  10. version=$(grep "^Version:" $2/CONTROL/control | sed -e "s/^[^:]*:[[:space:]]*//")
  11. arch=$(grep "^Architecture:" $2/CONTROL/control | sed -e "s/^[^:]*:[[:space:]]*//")
  12. for file in preinst postinst prerm postrm; do
  13. [ ! -f $2/CONTROL/$file ] || ( mkdir -p ${2}/usr/lib/pkg && \
  14. cp $2/CONTROL/$file ${2}/usr/lib/pkg/${pkgname}.$file && \
  15. chmod +x ${2}/usr/lib/pkg/${pkgname}.$file )
  16. done
  17. rm -rf $2/CONTROL
  18. (cd $2 && tar -cf - .|gzip -c > $3/${pkgname}_${version}_${arch}.tar.gz)
  19. elif [ "$1" = "install" ];then
  20. pkg=$(echo $(basename $2)|sed -e "s#_.*##")
  21. if [ -x ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.preinst ]; then
  22. IPKG_INSTROOT="$PKG_INSTROOT" ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.preinst
  23. rm ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.preinst
  24. fi
  25. gzip -d -c $2|tar -xpf - -C ${PKG_INSTROOT}
  26. if [ -x ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.postinst ]; then
  27. IPKG_INSTROOT="$PKG_INSTROOT" ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.postinst
  28. rm ${PKG_INSTROOT}/usr/lib/pkg/${pkg}.postinst
  29. fi
  30. rm -rf ${PKG_INSTROOT}/usr/lib/pkg
  31. else
  32. echo "unknown command"
  33. exit 1
  34. fi