diff --git a/bin/xbps-src/main.sh b/bin/xbps-src/main.sh
index bcd9a50971e..12976ff0a9a 100755
--- a/bin/xbps-src/main.sh
+++ b/bin/xbps-src/main.sh
@@ -96,16 +96,18 @@ run_file()
set_defvars()
{
- local i=
+ local DDIRS i
: ${XBPS_TEMPLATESDIR:=$XBPS_DISTRIBUTIONDIR/templates}
+ : ${XBPS_TRIGGERSDIR:=$XBPS_DISTRIBUTIONDIR/triggers}
: ${XBPS_HELPERSDIR:=$XBPS_TEMPLATESDIR/helpers}
: ${XBPS_DBDIR:=$XBPS_MASTERDIR/var/db/xbps}
: ${XBPS_META_PATH:=$XBPS_DBDIR/}
: ${XBPS_PKGMETADIR:=$XBPS_DBDIR/metadata}
: ${XBPS_SHUTILSDIR:=$XBPS_DISTRIBUTIONDIR/shutils}
- local DDIRS="XBPS_TEMPLATESDIR XBPS_HELPERSDIR XBPS_SHUTILSDIR"
+ DDIRS="XBPS_TEMPLATESDIR XBPS_TRIGGERSDIR"
+ DDIRS="$DDIRS XBPS_HELPERSDIR XBPS_SHUTILSDIR"
for i in ${DDIRS}; do
eval val="\$$i"
[ ! -d "$val" ] && msg_error "cannot find $i, aborting."
diff --git a/doc/TODO b/doc/TODO
index 9e72cb11f78..bcf8336018a 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -4,8 +4,6 @@ xbps-src:
Something like ${sourceforge} to pick up any specified mirror on the list.
* Add support to run INSTALL/REMOVE scripts, so that the same actions are
performed in source/bin packages. [STOPPED]
- * Use current postinstall_helpers to automatically add triggers, shared
- by src/bin packages. [IN PROGRESS]
Packages:
* fix mpfr hardcoded rpath for gmp.
@@ -19,7 +17,6 @@ xbps-bin:
* Add support to update packages.
* While installing a package, check if version that is going to be
installed is already installed.
- * (Un)register info files automatically. [IN PROGRESS]
xbps-repo:
* Replace binpkg-genindex.sh with a target for xbps-repo to generate the
diff --git a/shutils/binpkg.sh b/shutils/binpkg.sh
index ea4e8b0e472..fc93b45665a 100644
--- a/shutils/binpkg.sh
+++ b/shutils/binpkg.sh
@@ -25,11 +25,9 @@
write_metadata_flist_header()
{
- local file="$1"
+ [ ! -f "$1" ] && return 1
- [ -z "$file" ] && return 1
-
- cat > $file <<_EOF
+ cat > $1 <<_EOF
@@ -43,7 +41,7 @@ _EOF
xbps_write_metadata_pkg()
{
local pkg="$1"
- local subpkg=
+ local subpkg
for subpkg in ${subpackages}; do
if [ "${pkg}" != "${sourcepkg}" ] && \
@@ -56,7 +54,8 @@ xbps_write_metadata_pkg()
if [ ! -f $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template ]; then
msg_error "Cannot find subpackage template!"
fi
- unset run_depends conf_files keep_dirs noarch install_priority
+ unset run_depends conf_files keep_dirs noarch install_priority \
+ triggers
. $XBPS_TEMPLATESDIR/${sourcepkg}/${subpkg}.template
pkgname=${sourcepkg}-${subpkg}
set_tmpl_common_vars
@@ -83,7 +82,7 @@ xbps_write_metadata_pkg()
xbps_write_metadata_pkg_real()
{
local metadir=${DESTDIR}/var/db/xbps/metadata/$pkgname
- local f i j arch prioinst TMPFLIST TMPFPLIST
+ local f i j arch dirat lnkat newlnk prioinst TMPFLIST TMPFPLIST
local fpattern="s|${DESTDIR}||g;s|^\./$||g;/^$/d"
if [ ! -d "${DESTDIR}" ]; then
@@ -106,7 +105,66 @@ xbps_write_metadata_pkg_real()
# Write the files.plist file.
TMPFLIST=$(mktemp -t flist.XXXXXXXXXX) || exit 1
TMPFPLIST=$(mktemp -t fplist.XXXXXXXXXX) || exit 1
+ TMPINFOLIST=$(mktemp -t infolist.XXXXXXXXXX) || exit 1
+ #
+ # Find out if this package contains info files and compress
+ # all them with gzip.
+ #
+ if [ -f "${DESTDIR}/usr/share/info/dir" ]; then
+ if [ -f ${XBPS_MASTERDIR}/usr/share/info/dir ]; then
+ rm -f ${DESTDIR}/usr/share/info/dir
+ fi
+ # Add info-files trigger.
+ triggers="info-files $triggers"
+
+ for f in $(find -L ${DESTDIR}/usr/share/info -type f); do
+ j=$(echo $f|sed -e "$fpattern")
+ [ "$j" = "" ] && continue
+ [ "$j" = "/usr/share/info/dir" ] && continue
+ if $(echo $j|grep -q '.gz'); then
+ continue
+ fi
+ if [ -h ${DESTDIR}/$j ]; then
+ dirat=$(dirname $j)
+ lnkat=$(readlink ${DESTDIR}/$j)
+ newlnk=$(basename $j)
+ rm -f ${DESTDIR}/$j
+ cd ${DESTDIR}/$dirat
+ ln -s ${lnkat}.gz ${newlnk}.gz
+ continue
+ fi
+ echo "=> Compressing info file: $j..."
+ gzip -q9 ${DESTDIR}/$j
+ done
+ fi
+
+ #
+ # Find out if this package contains manual pages and
+ # compress all them with gzip.
+ #
+ if [ -d "${DESTDIR}/usr/share/man" ]; then
+ for f in $(find -L ${DESTDIR}/usr/share/man -type f); do
+ j=$(echo $f|sed -e "$fpattern")
+ [ "$j" = "" ] && continue
+ if $(echo $j|grep -q '.gz'); then
+ continue
+ fi
+ if [ -h ${DESTDIR}/$j ]; then
+ dirat=$(dirname $j)
+ lnkat=$(readlink ${DESTDIR}/$j)
+ newlnk=$(basename $j)
+ rm -f ${DESTDIR}/$j
+ cd ${DESTDIR}/$dirat
+ ln -s ${lnkat}.gz ${newlnk}.gz
+ continue
+ fi
+ echo "=> Compressing manpage: $j..."
+ gzip -q9 ${DESTDIR}/$j
+ done
+ fi
+
+ cd ${DESTDIR}
msg_normal "Writing package metadata for $pkgname-$version..."
write_metadata_flist_header $TMPFPLIST
@@ -115,59 +173,73 @@ xbps_write_metadata_pkg_real()
for f in $(find ${DESTDIR} -type l); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
- printf "$j\n" >> $TMPFLIST
- printf "\n" >> $TMPFPLIST
- printf "file\n" >> $TMPFPLIST
- printf "$j\n" >> $TMPFPLIST
- printf "type\n" >> $TMPFPLIST
- printf "link\n" >> $TMPFPLIST
- printf "\n" >> $TMPFPLIST
+ echo "$j" >> $TMPFLIST
+ echo "" >> $TMPFPLIST
+ echo "file" >> $TMPFPLIST
+ echo "$j" >> $TMPFPLIST
+ echo "type" >> $TMPFPLIST
+ echo "link" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
done
# Pass 2: add regular files.
for f in $(find ${DESTDIR} -type f); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
- printf "$j\n" >> $TMPFLIST
- printf "\n" >> $TMPFPLIST
- printf "file\n" >> $TMPFPLIST
- printf "$j\n" >> $TMPFPLIST
- printf "type\n" >> $TMPFPLIST
- printf "file\n" >> $TMPFPLIST
- printf "sha256\n" >> $TMPFPLIST
- printf "$(xbps-digest $f)\n" >> $TMPFPLIST
+ echo "$j" >> $TMPFLIST
+ echo "" >> $TMPFPLIST
+ echo "file" >> $TMPFPLIST
+ echo "$j" >> $TMPFPLIST
+ echo "type" >> $TMPFPLIST
+ echo "file" >> $TMPFPLIST
+ echo "sha256" >> $TMPFPLIST
+ echo "$(xbps-digest $f)" >> $TMPFPLIST
for i in ${conf_files}; do
if [ "$j" = "$i" ]; then
- printf "conf_file\n" >> $TMPFPLIST
- printf "\n" >> $TMPFPLIST
+ echo "conf_file" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
break
fi
done
- printf "\n" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
done
# Pass 3: add directories.
for f in $(find ${DESTDIR} -type d|sort -ur); do
j=$(echo $f|sed -e "$fpattern")
[ "$j" = "" ] && continue
- printf "$j\n" >> $TMPFLIST
- printf "\n" >> $TMPFPLIST
- printf "file\n" >> $TMPFPLIST
- printf "$j\n" >> $TMPFPLIST
- printf "type\n" >> $TMPFPLIST
- printf "dir\n" >> $TMPFPLIST
+ echo "$j" >> $TMPFLIST
+ echo "" >> $TMPFPLIST
+ echo "file" >> $TMPFPLIST
+ echo "$j" >> $TMPFPLIST
+ echo "type" >> $TMPFPLIST
+ echo "dir" >> $TMPFPLIST
for i in ${keep_dirs}; do
if [ "$j" = "$i" ]; then
- printf "keep\n" >> $TMPFPLIST
- printf "\n" >> $TMPFPLIST
+ echo "keep" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
break
fi
done
- printf "\n" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
done
- printf "\n\n\n" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
+ echo "" >> $TMPFPLIST
sed -i -e /^$/d $TMPFLIST
+ #
+ # Find out if this package contains info files and write
+ # a list will all them in a file.
+ #
+ if [ -d "${DESTDIR}/usr/share/info" ]; then
+ for f in $(find ${DESTDIR}/usr/share/info -type f); do
+ j=$(echo $f|sed -e "$fpattern")
+ [ "$j" = "" ] && continue
+ echo "$j" >> $TMPINFOLIST
+ done
+ fi
+
# Write the props.plist file.
local TMPFPROPS=$(mktemp -t fprops.XXXXXXXXXX) || exit 1
@@ -195,35 +267,36 @@ xbps_write_metadata_pkg_real()
_EOF
# Dependencies
if [ -n "$run_depends" ]; then
- printf "run_depends\n" >> $TMPFPROPS
- printf "\n" >> $TMPFPROPS
+ echo "run_depends" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
for f in ${run_depends}; do
- printf "$f\n" >> $TMPFPROPS
+ echo "$f" >> $TMPFPROPS
done
- printf "\n" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
fi
# Configuration files
if [ -n "$conf_files" ]; then
- printf "conf_files\n" >> $TMPFPROPS
- printf "\n" >> $TMPFPROPS
+ echo "conf_files" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
for f in ${conf_files}; do
- printf "$f\n" >> $TMPFPROPS
+ echo "$f" >> $TMPFPROPS
done
- printf "\n" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
fi
# Keep directories while removing.
if [ -n "$keep_dirs" ]; then
- printf "keep_dirs\n" >> $TMPFPROPS
- printf "\n" >> $TMPFPROPS
+ echo "keep_dirs" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
for f in ${keep_dirs}; do
- printf "$f\n" >> $TMPFPROPS
+ echo "$f" >> $TMPFPROPS
done
- printf "\n" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
fi
# Terminate the property list file.
- printf "\n\n" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
+ echo "" >> $TMPFPROPS
if [ ! -d $metadir ]; then
mkdir -p $metadir >/dev/null 2>&1
@@ -235,28 +308,131 @@ _EOF
fi
# Write metadata files and cleanup.
- cp -f $TMPFLIST $metadir/flist
- cp -f $TMPFPLIST $metadir/files.plist
- cp -f $TMPFPROPS $metadir/props.plist
+ if [ -s $TMPFLIST ]; then
+ mv -f $TMPFLIST $metadir/flist
+ else
+ rm -f $TMPFLIST
+ fi
+ mv -f $TMPFPLIST $metadir/files.plist
+ mv -f $TMPFPROPS $metadir/props.plist
+ if [ -s $TMPINFOLIST ]; then
+ mv -f $TMPINFOLIST $metadir/info-files
+ else
+ rm -f $TMPINFOLIST
+ fi
$XBPS_REGPKGDB_CMD sanitize-plist $metadir/files.plist
$XBPS_REGPKGDB_CMD sanitize-plist $metadir/props.plist
chmod 644 $metadir/*
- rm -f $TMPFLIST $TMPFPLIST $TMPFPROPS
- if [ -f "$XBPS_TEMPLATESDIR/$pkgname/INSTALL" ]; then
- cp -f $XBPS_TEMPLATESDIR/$pkgname/INSTALL ${DESTDIR}
- chmod +x ${DESTDIR}/INSTALL
- fi
- if [ -f "$XBPS_TEMPLATESDIR/$pkgname/REMOVE" ]; then
- cp -f $XBPS_TEMPLATESDIR/$pkgname/REMOVE $metadir
- chmod +x $metadir/REMOVE
+ #
+ # Create the INSTALL/REMOVE scripts if package uses them
+ # or uses any available trigger.
+ #
+ xbps_make_script install
+ xbps_make_script remove
+}
+
+xbps_make_script()
+{
+ local action="$1"
+ local metadir="${DESTDIR}/var/db/xbps/metadata/$pkgname"
+ local tmpf=$(mktemp -t xbps-install.XXXXXXXXXX) || exit 1
+ local triggerdir="./var/db/xbps/triggers"
+ local targets found
+
+ case "$action" in
+ install) ;;
+ remove) ;;
+ *) return 1;;
+ esac
+
+ cd ${DESTDIR}
+ cat >> $tmpf <<_EOF
+#!/bin/sh -e
+#
+# Generic INSTALL/REMOVE script.
+#
+# $1 = cwd
+# $2 = action
+# $3 = pkgname
+# $4 = version
+#
+# Note that paths must be relative to CWD, to avoid calling
+# host commands.
+#
+
+export PATH="./bin:./sbin:./usr/bin:./usr/sbin"
+_EOF
+
+ if [ -n "$triggers" ]; then
+ found=1
+ echo "case \"\$2\" in" >> $tmpf
+ echo "pre)" >> $tmpf
+ for f in ${triggers}; do
+ if [ ! -f $XBPS_TRIGGERSDIR/$f ]; then
+ rm -f $tmpf
+ msg_error "$pkgname: unknown trigger $f, aborting!"
+ fi
+ done
+ for f in ${triggers}; do
+ targets=$($XBPS_TRIGGERSDIR/$f targets)
+ for j in ${targets}; do
+ if ! $(echo $j|grep -q pre-${action}); then
+ continue
+ fi
+ printf "\t$triggerdir/$f run $j $pkgname $version\n" >> $tmpf
+ printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
+ done
+ done
+ printf "\t;;\n" >> $tmpf
+ echo "post)" >> $tmpf
+ for f in ${triggers}; do
+ targets=$($XBPS_TRIGGERSDIR/$f targets)
+ for j in ${targets}; do
+ if ! $(echo $j|grep -q post-${action}); then
+ continue
+ fi
+ printf "\t$triggerdir/$f run $j $pkgname $version\n" >> $tmpf
+ printf "\t[ \$? -ne 0 ] && exit \$?\n" >> $tmpf
+ done
+ done
+ printf "\t;;\n" >> $tmpf
+ echo "esac" >> $tmpf
+ echo >> $tmpf
fi
+
+ case "$action" in
+ install)
+ if [ -f "$XBPS_TEMPLATESDIR/$pkgname/INSTALL" ]; then
+ found=1
+ cat $XBPS_TEMPLATESDIR/$pkgname/INSTALL >> $tmpf
+ fi
+ echo "exit 0" >> $tmpf
+ if [ -z "$found" ]; then
+ rm -f $tmpf
+ return 0
+ fi
+ mv $tmpf ${DESTDIR}/INSTALL && chmod 755 ${DESTDIR}/INSTALL
+ ;;
+ remove)
+ if [ -f "$XBPS_TEMPLATESDIR/$pkgname/REMOVE" ]; then
+ found=1
+ cat $XBPS_TEMPLATESDIR/$pkgname/REMOVE >> $tmpf
+ fi
+ echo "exit 0" >> $tmpf
+ if [ -z "$found" ]; then
+ rm -f $tmpf
+ return 0
+ fi
+ mv $tmpf ${metadir}/REMOVE && chmod 755 ${metadir}/REMOVE
+ ;;
+ esac
}
xbps_make_binpkg()
{
local pkg="$1"
- local subpkg=
+ local subpkg
for subpkg in ${subpackages}; do
if [ "$pkg" = "$pkgname-$subpkg" ]; then
@@ -280,10 +456,7 @@ xbps_make_binpkg()
#
xbps_make_binpkg_real()
{
- local binpkg=
- local pkgdir=
- local arch=
- local use_sudo=
+ local binpkg pkgdir arch use_sudo
if [ ! -d ${DESTDIR} ]; then
echo "$pkgname: unexistent destdir... skipping!"
diff --git a/templates/kernel/INSTALL b/templates/kernel/INSTALL
index fc207010cc2..85dc24060c5 100644
--- a/templates/kernel/INSTALL
+++ b/templates/kernel/INSTALL
@@ -1,12 +1,7 @@
-#!/bin/sh -e
-
-export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
-
-# $1 = chrootdir
-# $2 = action
-# $3 = pkgname
-# $4 = version
-
+#
+# This scripts creates the initramfs for the newly installed
+# kernel package.
+#
case "$2" in
pre)
;;
@@ -39,5 +34,3 @@ post)
${umntsys_cmd}
;;
esac
-
-exit 0
diff --git a/templates/shadow/INSTALL b/templates/shadow/INSTALL
index 888b5a003b6..cac9265b957 100644
--- a/templates/shadow/INSTALL
+++ b/templates/shadow/INSTALL
@@ -1,11 +1,8 @@
-#!/bin/sh -e
-
-export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
-
-# $1 = chrootdir
-# $2 = action
-# $3 = pkgname
-# $4 = version
+#
+# This script creates default /etc/passwd and /etc/group
+# files if they are unexistent.
+#
+# Also shadow passwords are enabled.
create_passwd()
{
@@ -66,6 +63,3 @@ post)
fi
;;
esac
-
-exit 0
-
diff --git a/templates/texinfo/INSTALL b/templates/texinfo/INSTALL
new file mode 100644
index 00000000000..d0f755f2ab1
--- /dev/null
+++ b/templates/texinfo/INSTALL
@@ -0,0 +1,31 @@
+#
+# This script registers all currently installed info files.
+#
+texinfo_files="info.info.gz info-stnd.info.gz texinfo.gz
+ texinfo-1.gz texinfo-2.gz texinfo-3.gz"
+
+case "$2" in
+pre)
+ ;;
+post)
+ for file in $(find ./usr/share/info -type f ! -name dir); do
+ for i in ${texinfo_files}; do
+ if [ "$(basename ${file#.})" = "${i}" ]; then
+ found=1
+ break
+ fi
+ done
+ if [ -n "$found" ]; then
+ unset found
+ continue
+ fi
+ echo -n "Registering info file: ${file#.}... "
+ install-info $file ./usr/share/info/dir 2> /dev/null
+ if [ $? -eq 0 ]; then
+ echo "done."
+ else
+ echo "failed!"
+ fi
+ done
+ ;;
+esac
diff --git a/templates/xbps-base-dirs/template b/templates/xbps-base-dirs/template
index bb828a0cffb..8ea2dd41841 100644
--- a/templates/xbps-base-dirs/template
+++ b/templates/xbps-base-dirs/template
@@ -1,11 +1,12 @@
# Template file for 'xbps-base-dirs'
pkgname=xbps-base-dirs
-version=0.2
+version=0.3
build_style=custom-install
short_desc="xbps base system directories"
maintainer="Juan RP "
long_desc="
- This package installs the base system directories."
+ This package installs the base system directories as well
+ as some required files for xbps."
base_chroot=yes
noarch=yes
@@ -48,4 +49,9 @@ do_install()
cd $DESTDIR && ln -s lib lib64
cd $DESTDIR/usr && ln -s lib lib64
fi
+
+ for f in info-files; do
+ install -D -m 755 ${XBPS_TRIGGERSDIR}/$f \
+ $DESTDIR/var/db/xbps/triggers/$f
+ done
}
diff --git a/triggers/info-files b/triggers/info-files
new file mode 100755
index 00000000000..f6bc1e38f1a
--- /dev/null
+++ b/triggers/info-files
@@ -0,0 +1,54 @@
+#!/bin/sh
+#
+# Registers or unregisters info files for a package.
+#
+# Arguments: $1 = action [run/targets]
+# $2 = target [post-install/pre-remove]
+# $3 = pkgname
+#
+trigger="info-files"
+
+xbps_metadir="./var/db/xbps/metadata"
+finfometa="$xbps_metadir/$3/$trigger"
+installinfo="./usr/bin/install-info"
+infodir="./usr/share/info"
+
+case "$1" in
+targets)
+ echo "post-install pre-remove"
+ ;;
+run)
+ [ ! -x $installinfo ] && exit 0
+
+ if [ ! -r $finfometa ]; then
+ echo "$trigger: can't find info-files in metadata directory!"
+ exit 1
+ fi
+
+ cat $finfometa | while read line; do
+ [ ! -f ./$line ] && continue
+
+ case "$2" in
+ post-install)
+ echo -n "Registering info file: $line... "
+ ;;
+ pre-remove)
+ echo -n "Unregistering info file: $line... "
+ infoargs="--delete"
+ ;;
+ esac
+
+ $installinfo $infoargs ./$line $infodir/dir 2>/dev/null
+ if [ $? -eq 0 ]; then
+ echo "done."
+ else
+ echo "failed!"
+ fi
+ done
+ ;;
+*)
+ exit 1
+ ;;
+esac
+
+exit 0