--- templates/generic-build-script	2003-12-05 10:50:37.275959700 +0100
+++ generic.sh	2004-01-20 17:01:45.439514500 +0100
@@ -26,15 +26,25 @@
 export FULLPKG=${PKG}-${VER}-${REL}
 
 # determine correct decompression option and tarball filename
-if [ -e ${PKG}-${VER}.tar.gz ] ; then
-  export opt_decomp=z
-  export src_orig_pkg_ext=gz
-elif [ -e ${PKG}-${VER}.tar.bz2 ] ; then
+export BASEPKG=${PKG}-${VER}
+if [ -e ${BASEPKG}.tar.bz2 ] ; then
   export opt_decomp=j
-  export src_orig_pkg_ext=bz2
+  export src_orig_pkg_name=${BASEPKG}.tar.bz2
+elif [ -e ${BASEPKG}.tar.gz ] ; then
+  export opt_decomp=z
+  export src_orig_pkg_name=${BASEPKG}.tar.gz
+elif [ -e ${BASEPKG}.tgz ] ; then
+  export opt_decomp=z
+  export src_orig_pkg_name=${BASEPKG}.tgz
+elif [ -e ${BASEPKG}.tar ] ; then
+  export opt_decomp=
+  export src_orig_pkg_name=${BASEPKG}.tar
+else
+  echo Cannot find original package.
+  exit 1
 fi
 
-export src_orig_pkg_name=${PKG}-${VER}.tar.${src_orig_pkg_ext}
+# determine correct names for generated files
 export src_pkg_name=${FULLPKG}-src.tar.bz2
 export src_patch_name=${FULLPKG}.patch
 export bin_pkg_name=${FULLPKG}.tar.bz2
@@ -48,10 +58,6 @@
 export instdir=${srcdir}/.inst
 export srcinstdir=${srcdir}/.sinst
 export checkfile=${topdir}/${FULLPKG}.check
-# run on
-host=i686-pc-cygwin
-# if this package creates binaries, they run on
-target=i686-pc-cygwin
 prefix=/usr
 sysconfdir=/etc
 MY_CFLAGS="-O2"
@@ -80,8 +86,7 @@
   --libdir=${prefix}/lib --includedir=${prefix}/include \
   --mandir=${prefix}/share/man --infodir=${prefix}/share/info \
   --libexecdir='${sbindir}' --localstatedir=/var \
-  --datadir='${prefix}/share'
-)
+  --datadir='${prefix}/share' )
 }
 build() {
   (cd ${objdir} && \
@@ -103,8 +108,7 @@
       rm -f ${instdir}${f} ; \
     fi ;\
   done &&\
-  for d in ${prefix}/share/doc/${PKG}-${VER} ${prefix}/share/doc/Cygwin \
-           ${sysconfdir}/postinstall ; do
+  for d in ${prefix}/share/doc/${PKG}-${VER} ${prefix}/share/doc/Cygwin ; do
     if [ ! -d ${instdir}${d} ] ; then
       mkdir -p ${instdir}${d} ;\
     fi ;\
@@ -131,14 +135,16 @@
     fi ;\
   fi ;\
   if [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \
+    if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
+      mkdir -p ${instdir}${sysconfdir}/postinstall ; \
+    fi && \
   /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
       ${instdir}${sysconfdir}/postinstall/${PKG}.sh
   fi )
 }
 strip() {
   (cd ${instdir} && \
-  find . -name "*.dll" | xargs strip > /dev/null 2>&1
-  find . -name "*.exe" | xargs strip > /dev/null 2>&1
+  find . -name "*.dll" -or -name "*.exe" | xargs strip > /dev/null 2>&1
   true )
 }
 list() {
@@ -163,14 +169,53 @@
 }
 spkg() {
   (mkpatch && \
+  if [ "${SIG}" ]; then name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile; fi && \
   cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \
+  if [ -e ${src_orig_pkg}.sig ]; then cp ${src_orig_pkg}.sig ${srcinstdir}/; fi && \
   cp $0 ${srcinstdir}/`basename $0` && \
+  name=$0 text="SCRIPT" sigfile && \
+  if [ "${SIG}" ]; then cp $0.sig ${srcinstdir}/; fi && \
   cd ${srcinstdir} && \
   tar cvjf ${src_pkg} * )
 }
 finish() {
   rm -rf ${srcdir} 
 }
+sigfile() {
+  if [ \( "${SIG}" \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \
+    if [ -x /usr/bin/gpg ]; then \
+      echo "$text signature need to be updated"; \
+      rm -f $name.sig; \
+      /usr/bin/gpg --detach-sign $name; \
+    else \
+      echo "You need the gnupg package installed in order to make signatures."; \
+    fi; \
+  fi;
+}
+checksig() {
+  if [ -x /usr/bin/gpg ]; then \
+    if [ -e $0.sig ]; then \
+      echo "SCRIPT signature follows:"; \
+      /usr/bin/gpg --verify $0.sig $0; \
+    else \
+      echo "SCRIPT signature missing."; \
+    fi; \
+    if [ -e ${src_orig_pkg}.sig ]; then \
+      echo "ORIGINAL PACKAGE signature follows:"; \
+      /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \
+    else \
+      echo "ORIGINAL PACKAGE signature missing."; \
+    fi; \
+    if [ -e ${src_patch}.sig ]; then \
+      echo "PATCH signature follows:"; \
+      /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
+    else \
+      echo "PATCH signature missing."; \
+    fi; \
+  else
+    echo "You need the gnupg package installed in order to check signatures."; \
+  fi;
+}
 case $1 in
   prep)	prep ; STATUS=$? ;;
   mkdirs)	mkdirs; STATUS=$? ;;
@@ -187,6 +232,7 @@
   src-package)	spkg ; STATUS=$? ;;
   spkg)	spkg ; STATUS=$? ;;
   finish) finish ; STATUS=$? ;;
+  checksig)	checksig ; STATUS=$? ;;
   all) prep && conf && build && install && \
      strip && pkg && spkg && finish ; \
 	  STATUS=$? ;;

