summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamantha McVey2016-12-03 19:24:13 -0800
committerSamantha McVey2016-12-03 19:24:13 -0800
commit54dcbd8740a12ceb9f714640cc6fefff57fc85a8 (patch)
treeb9410cd9226c4146d13a83d76637be09a959939d
parent97a0cd9bdfbb48e65b121609dc8ce94624cdcde8 (diff)
downloadaur-54dcbd8740a12ceb9f714640cc6fefff57fc85a8.tar.gz
Release v2.0 post-install hook now finishes almost instantly
You must run pacman-ps as root or using sudo if you have installed or upgrades any packages. It will do the processing of the database if it hasn't been processed yet on running pacman-ps now.
-rw-r--r--PKGBUILD42
-rwxr-xr-xpacman-ps-posthook.sh7
-rw-r--r--pacman-ps.install31
-rwxr-xr-xpacman-ps.sh23
4 files changed, 68 insertions, 35 deletions
diff --git a/PKGBUILD b/PKGBUILD
index 997f218c56e3..80699b3ae0b1 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -5,13 +5,16 @@
# https://www.gnu.org/licenses/gpl-2.0.html
pkgname=('pacman-ps')
-pkgver=0.1.3
-pkgrel=2
+pkgver=0.2.0
+pkgrel=1
arch=('any')
url='https://gitlab.com/samcv/ps-lsof'
license=('GPLv2')
depends=('lsof' 'procps-ng' 'bash' 'coreutils' 'findutils')
-pkgdesc="Provides a command to identify which running processes have files that have changed on disk. It also provides a pacman hook and pacman-ps to also show which packages own the files that are still open."
+pkgdesc="Provides a command to identify which running processes have files that \
+ have changed on disk. It also provides a pacman hook and pacman-ps to also show \
+ which packages own the files that are still open."
+
options=('!strip')
source=("pacman-ps.sh"
"pacman-ps-post.hook"
@@ -20,13 +23,13 @@ source=("pacman-ps.sh"
"pacman-ps.install"
"license.txt"
"pacman-ps.1")
-sha1sums=('9d48ae474feeed2bf16079f3f6b713af21feffc3'
- '28be8f69c8b349a43d90de416b9d6cd8282b37af'
- '36f5b7b3706e4e82d27a6c7b0588e9e5258e06cc'
- '13403de1fc04e8642e167ddd87b567401b48b099'
- '49f62584fc204f91fa96e72a7ff21b5fa338e472'
- '4cc77b90af91e615a64ae04893fdffa7939db84c'
- 'd32f392fc69fbc264525923e50bd4b0243bae869')
+sha1sums=('SKIP'
+ 'SKIP'
+ 'SKIP'
+ 'SKIP'
+ 'SKIP'
+ 'SKIP'
+ 'SKIP')
package() {
LICENSE_DIR="/usr/share/licenses"
@@ -34,24 +37,17 @@ package() {
HOOK_DIR="/etc/pacman.d/hooks"
MAN_DIR="/usr/share/man/man1"
- mkdir -p ${pkgdir}${HOOK_DIR}
- cp ${srcdir}/pacman-ps-post.hook ${pkgdir}${HOOK_DIR}
+ install -D -m 644 ${srcdir}/pacman-ps-post.hook ${pkgdir}${HOOK_DIR}/pacman-ps-post.hook
- mkdir -p ${pkgdir}/usr/bin
- cp ${srcdir}/pacman-ps.sh ${pkgdir}${BIN_DIR}/pacman-ps
- chmod +x ${pkgdir}${BIN_DIR}/pacman-ps
+ install -D -m 755 ${srcdir}/pacman-ps.sh ${pkgdir}${BIN_DIR}/pacman-ps
- cp ${srcdir}/ps-lsof.sh ${pkgdir}${BIN_DIR}/ps-lsof
- chmod +x ${pkgdir}${BIN_DIR}/ps-lsof
+ install -D -m 755 ${srcdir}/ps-lsof.sh ${pkgdir}${BIN_DIR}/ps-lsof
- cp ${srcdir}/pacman-ps-posthook.sh ${pkgdir}${BIN_DIR}/pacman-ps-posthook
- chmod +x ${pkgdir}${BIN_DIR}/pacman-ps-posthook
+ install -D -m 755 ${srcdir}/pacman-ps-posthook.sh ${pkgdir}${BIN_DIR}/pacman-ps-posthook
- mkdir -p ${pkgdir}${LICENSE_DIR}/pacman-ps
- cp ${srcdir}/license.txt ${pkgdir}${LICENSE_DIR}/${pkgname}
+ install -D -m 644 ${srcdir}/license.txt ${pkgdir}${LICENSE_DIR}/${pkgname}/license.txt
- mkdir -p ${pkgdir}${MAN_DIR}
- cp ${srcdir}/pacman-ps.1 ${pkgdir}${MAN_DIR}
+ install -D -m 644 ${srcdir}/pacman-ps.1 ${pkgdir}${MAN_DIR}/pacman-ps.1
install=pacman-ps.install
}
diff --git a/pacman-ps-posthook.sh b/pacman-ps-posthook.sh
index bcad431c4d72..1d943b33ffc0 100755
--- a/pacman-ps-posthook.sh
+++ b/pacman-ps-posthook.sh
@@ -8,7 +8,8 @@
# a list of package names seperated by a newline from stdin. It then will add
# the file listing to the DB_DIR/files.db
DB_DIR="/var/cache/pacman-ps"
-xargs -I '{}' pacman -Ql '{}' | sort -u -k 2,2 - ${DB_DIR}/files.db > ${DB_DIR}/files.db-
+xargs -I '{}' pacman -Ql '{}' >> "${DB_DIR}/files.db"
+if [ -f "${DB_DIR}/files.db.sorted" ]; then
+ rm "${DB_DIR}/files.db.sorted"
+fi
wait
-rm ${DB_DIR}/files.db
-mv ${DB_DIR}/files.db- ${DB_DIR}/files.db
diff --git a/pacman-ps.install b/pacman-ps.install
index 0a684a428e5c..9b5d17ba48cf 100644
--- a/pacman-ps.install
+++ b/pacman-ps.install
@@ -1,13 +1,30 @@
+# This generated the initial database for pacman-ps
+DB_DIR="/var/cache/pacman-ps"
post_install() {
- DB_DIR="/var/cache/pacman-ps"
- mkdir -p ${DB_DIR}
- pacman -Ql | sort -u -k 2,2 - ${DB_DIR}/files.db > ${DB_DIR}/files-temp.db
- rm ${DB_DIR}/files.db
- mv ${DB_DIR}/files-temp.db ${DB_DIR}/files.db
+ # If the database exists, just update it and keep existing entries
+ if [ -f "${DB_DIR}/files.db" ]; then
+ pacman -Ql | sort -u -k 2,2 - "${DB_DIR}/files.db" > "${DB_DIR}/files-temp.db"
+ # Otherwise create it
+ else
+ mkdir -p "${DB_DIR}"
+ pacman -Ql | sort -u -k 2,2 - > ${DB_DIR}/files-temp.db
+ fi
+ rm "${DB_DIR}/files.db"
+ mv "${DB_DIR}/files-temp.db" "${DB_DIR}/files.db"
printf "Created initial database at %s/files.db\n" "${DB_DIR}"
}
+
+# On package upgrade if the database doesn't exist, create it
+post_upgrade() {
+ if [ ! -f "${DB_DIR}/files.db" ]; then
+ printf "Can't find database at %s/files.db\nGenerating one" "${DB_DIR}"
+ pacman -Ql | sort -u -k 2,2 - > ${DB_DIR}/files-temp.db
+ fi
+}
+
+# This removes the initial database for pacman-ps if it exists
post_remove() {
- if [ -d /var/cache/pacman-ps ]; then
- rm -rf /var/cache/pacman-ps
+ if [ -d "${DB_DIR}" ]; then
+ rm -rf "${DB_DIR}"
fi
}
diff --git a/pacman-ps.sh b/pacman-ps.sh
index 6df72a8bb8ad..41d28d5c73a5 100755
--- a/pacman-ps.sh
+++ b/pacman-ps.sh
@@ -31,7 +31,20 @@ cleanuptemp() {
rm "${LIST}"
fi
}
-
+sortdb() {
+ DB_DIR="/var/cache/pacman-ps"
+ if [ ! -f "${DB_DIR}/files.db.sorted" ]; then
+ if (( "$EUID" != 0 )); then
+ echo "Please run as root or sudo, to process the database."
+ exit 1
+ fi
+ sort -u -k 2,2 "${DB_DIR}/files.db" > "${DB_DIR}/files.db-"
+ rm "${DB_DIR}/files.db"
+ mv "${DB_DIR}/files.db-" "${DB_DIR}/files.db"
+ touch "${DB_DIR}/files.db.sorted"
+ fi
+}
+sortdb
DB_FILE="/var/cache/pacman-ps/files.db"
# Get the resolved filename of the currently running script
RUN=$(readlink -f "$0")
@@ -40,17 +53,23 @@ RUNDIR=$(dirname "${RUN}")
# If a file called ps-lsof is found in the same directory as pacman-ps use that
if [ -f "${RUNDIR}/ps-lsof" ]; then
PS_LSOF_CMD="${RUNDIR}/ps-lsof -q"
+ #printf "using ps-lsof -q\n"
+elif [ -f "${RUNDIR}/ps-lsof.pl" ]; then
+ PS_LSOF_CMD="${RUNDIR}/ps-lsof.pl"
+ #printf "Using ps-lsof.pl\n"
# Otherwise, if we find a ps-lsof.sh file, use that to call ps-lsof
elif [ -f "${RUNDIR}/ps-lsof.sh" ]; then
PS_LSOF_CMD="${RUNDIR}/ps-lsof.sh -q"
+ #printf "Using ps-lsof.sh -q\n"
else
echo "Could not find ps-lsof or ps-lsof.sh"
echo "Make sure it is in the same folder as pacman-ps or pacman-ps.sh"
exit 1
fi
+
# Get the output from ps-lsof and sort it so that 'join' will be happy
-PS_LSOF_OUTPUT=$($PS_LSOF_CMD | sort -k 2,2)
+PS_LSOF_OUTPUT=$(${PS_LSOF_CMD} | sort -k 2,2)
# If ps-lsof doesn't output anything, our work here is done
if [ "${PS_LSOF_OUTPUT}" = "" ]; then
exit 0