cd $TMP
tar xzvf $SRC_DIR/pinepgp-$PINEPGP.tar.gz
cd pinepgp-$PINEPGP
-chown -R root.root .
+
+# Make sure ownerships and permissions are sane:
+chown -R root:root .
+find . -perm 664 -exec chmod 644 {} \;
+find . -perm 600 -exec chmod 644 {} \;
+find . -perm 444 -exec chmod 644 {} \;
+find . -perm 400 -exec chmod 644 {} \;
+find . -perm 440 -exec chmod 644 {} \;
+find . -perm 777 -exec chmod 755 {} \;
+find . -perm 775 -exec chmod 755 {} \;
+find . -perm 511 -exec chmod 755 {} \;
+find . -perm 711 -exec chmod 755 {} \;
+find . -perm 555 -exec chmod 755 {} \;
+
+# Patch from Gentoo
+if [ -f "$CWD/pinepgp-0.18.0-makefile-sed-fix.patch.gz" ]; then
+ zcat $CWD/pinepgp-0.18.0-makefile-sed-fix.patch.gz | patch -p1 --verbose || exit $ERROR_PATCH
+fi
+
./configure --prefix=/usr || exit $ERROR_CONF
make || exit $ERROR_MAKE
make install DESTDIR=$PKG1 || exit $ERROR_INSTALL