diff options
author | Samantha McVey | 2016-08-27 20:51:14 -0700 |
---|---|---|
committer | Samantha McVey | 2016-08-27 20:51:14 -0700 |
commit | 9325089455f5fcd69d754f4695f3dc4c031904db (patch) | |
tree | e79336d1f2a7a6e8541d59a1d86d1ad01021428e | |
parent | 693ec0cef1a0f445e64b2d453a816821b57017df (diff) | |
download | aur-9325089455f5fcd69d754f4695f3dc4c031904db.tar.gz |
update to 0.1.1
-rw-r--r-- | .SRCINFO | 5 | ||||
-rw-r--r-- | PKGBUILD | 31 | ||||
-rw-r--r-- | pacman-ps-post.hook | 2 | ||||
-rwxr-xr-x | pacman-ps-posthook.sh | 13 | ||||
-rw-r--r-- | pacman-ps.install | 13 | ||||
-rwxr-xr-x | pacman-ps.sh | 89 | ||||
-rwxr-xr-x | ps-lsof.sh | 15 |
7 files changed, 110 insertions, 58 deletions
@@ -1,6 +1,6 @@ pkgbase = pacman-ps 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 - pkgver = 0.1 + pkgver = 0.1.1 pkgrel = 1 url = https://gitlab.com/samcv/ps-lsof arch = any @@ -10,10 +10,13 @@ pkgbase = pacman-ps depends = bash depends = coreutils depends = findutils + options = !strip source = pacman-ps.sh source = pacman-ps-post.hook source = ps-lsof.sh source = pacman-ps-posthook.sh + source = license.txt + md5sums = SKIP md5sums = SKIP md5sums = SKIP md5sums = SKIP @@ -3,34 +3,45 @@ # license for more details. pkgname=('pacman-ps') -pkgver=0.1 +pkgver=0.1.1 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" +options=('!strip') source=("pacman-ps.sh" "pacman-ps-post.hook" "ps-lsof.sh" - "pacman-ps-posthook.sh") + "pacman-ps-posthook.sh" + "license.txt") md5sums=('SKIP' 'SKIP' 'SKIP' + 'SKIP' 'SKIP') package() { - mkdir -p ${pkgdir}/etc/pacman.d/hooks - cp ${srcdir}/pacman-ps-post.hook ${pkgdir}/etc/pacman.d/hooks + LICENSE_DIR="/usr/share/licenses" + BIN_DIR="/usr/bin" + HOOK_DIR="/etc/pacman.d/hooks" + + mkdir -p ${pkgdir}${HOOK_DIR} + cp ${srcdir}/pacman-ps-post.hook ${pkgdir}${HOOK_DIR} mkdir -p ${pkgdir}/usr/bin - cp ${srcdir}/pacman-ps.sh ${pkgdir}/usr/bin/pacman-ps - chmod +x ${pkgdir}/usr/bin/pacman-ps + cp ${srcdir}/pacman-ps.sh ${pkgdir}${BIN_DIR}/pacman-ps + chmod +x ${pkgdir}${BIN_DIR}/pacman-ps + + cp ${srcdir}/ps-lsof.sh ${pkgdir}${BIN_DIR}/ps-lsof + chmod +x ${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 - cp ${srcdir}/ps-lsof.sh ${pkgdir}/usr/bin/ps-lsof - chmod +x ${pkgdir}/usr/bin/ps-lsof + mkdir -p ${pkgdir}${LICENSE_DIR}/pacman-ps + cp ${srcdir}/license.txt ${pkgdir}${LICENSE_DIR}/${pkgname} - cp ${srcdir}/pacman-ps-posthook.sh ${pkgdir}/usr/bin/pacman-ps-posthook - chmod +x ${pkgdir}/usr/bin/pacman-ps-posthook install=pacman-ps.install } diff --git a/pacman-ps-post.hook b/pacman-ps-post.hook index 4e1d113538e1..bde2903df1de 100644 --- a/pacman-ps-post.hook +++ b/pacman-ps-post.hook @@ -1,4 +1,4 @@ -# Hook to update /var/cache/pacman-ps/files package and file list +# Hook to update /var/cache/pacman-ps/files.db (package and file list) [Trigger] Operation = Upgrade Operation = Install diff --git a/pacman-ps-posthook.sh b/pacman-ps-posthook.sh index 4ac6c9e52c5f..82b356f524f2 100755 --- a/pacman-ps-posthook.sh +++ b/pacman-ps-posthook.sh @@ -4,12 +4,9 @@ # # This script is meant to be executed by the pacman-ps-post.hook and it receives # a list of package names seperated by a newline from stdin. It then will add -# the file listing to the CACHEDIR/files -CACHEDIR="/var/cache/pacman-ps" -xargs -I '{}' pacman -Ql '{}' >> ${CACHEDIR}/files.db +# 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- wait -mkdir -p /tmp/pacman-ps -sort -k 2,2 ${CACHEDIR}/files.db | uniq > /tmp/pacman-ps/files-temp.db -rm ${CACHEDIR}/files.db -mv /tmp/pacman-ps/files-temp.db ${CACHEDIR}/files.db -rm -rf /tmp/pacman-ps +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 32e40e1946eb..0a684a428e5c 100644 --- a/pacman-ps.install +++ b/pacman-ps.install @@ -1,11 +1,10 @@ post_install() { - CACHEDIR="/var/cache/pacman-ps" - mkdir -p ${CACHEDIR}/ - pacman -Ql >> ${CACHEDIR}/files.db - sort -k 2,2 ${CACHEDIR}/files.db | uniq > ${CACHEDIR}/files-temp.db - rm ${CACHEDIR}/files.db - mv ${CACHEDIR}/files-temp.db ${CACHEDIR}/files.db - printf "Created initial database at %s/files" "${CACHEDIR}" + 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 + printf "Created initial database at %s/files.db\n" "${DB_DIR}" } post_remove() { if [ -d /var/cache/pacman-ps ]; then diff --git a/pacman-ps.sh b/pacman-ps.sh index 681580ab3ac3..bead513089fd 100755 --- a/pacman-ps.sh +++ b/pacman-ps.sh @@ -1,52 +1,83 @@ -#!/bin/sh +#!/bin/env bash # Copyright (C) 2016 Samantha McVey <samantham@posteo.net> -# This file and project are licensed under the GPLv2 or greater at your choosing +# This file and project are licensed under the GPLv2 or greater at your choosing. +# For more information view the license included or visit: +# https://www.gnu.org/licenses/gpl-2.0.html # # This script processes the output from ps-lsof which is a two column list, where -# the 1st and 2nd columns must be delimited by a space. The first column of the +# the 1st and 2nd columns must be delimited by spaces. The first column of the # input is the process name. The second column is the file. It then compares -# the filename with the file at $PACKAGELIST which is a two column file delimited +# the filename with the file at $DB_FILE which is a two column file delimited # by spaces, the first column is the name of the package and the second is the # filename which belongs to the package. +cleanuptemp() { + if [ "${DB_TEMP_FILE}" = "1" ]; then + rm "${LIST}" + fi +} -PACKAGELIST="/var/cache/pacman-ps/files.db" -TEMPLIST="/tmp/pacman-ps/files.db" -TEMPDIR="/tmp/pacman-ps" +DB_FILE="/var/cache/pacman-ps/files.db" +# Get the resolved filename of the currently running script RUN=$(readlink -f "$0") +# Get the directory name that file is in 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="${RUNDIR}/ps-lsof" + PS_LSOF_CMD="${RUNDIR}/ps-lsof -q" +# Otherwise, if we find a ps-lsof.sh file, use that to call ps-lsof elif [ -f "${RUNDIR}/ps-lsof.sh" ]; then - PS_LSOF="${RUNDIR}/ps-lsof.sh" + PS_LSOF_CMD="${RUNDIR}/ps-lsof.sh -q" 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 -if [ -f "${PACKAGELIST}" ]; then - # echo "Using ${PACKAGELIST} for the package and file list" - LIST=${PACKAGELIST} -else - echo "Could not find ${PACKAGELIST}" - echo "Asking pacman for file listing using pacman -Ql" - mkdir -p ${TEMPDIR} - pacman -Ql > ${TEMPLIST} - LIST=${TEMPLIST} +# -s option will only print out packages and files but not processes + + +# 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) +# If ps-lsof doesn't output anything, our work here is done +if [ "${PS_LSOF_OUTPUT}" = "" ]; then + exit 0 fi -#PACMANCHK="${RUNDIR}/ps-lsof.sh | cut -d ' ' -f 2-99 | xargs -I '{}' grep '{}' ${LIST} | sort | column -t" -if [ "${1}" = "-s" ]; then - $PS_LSOF | cut -d ' ' -f 2-99 | xargs -I '{}' grep '{}' ${LIST} | sort | uniq | (echo "PROCESS FILENAME"; cat) | column -t +# If we find the database file at $DB_FILE then use that +if [ -f "${DB_FILE}" ]; then + LIST=${DB_FILE} else - mkdir -p ${TEMPDIR} - $PS_LSOF | sort -k 2 > "${TEMPDIR}/process.txt" - cut -d ' ' -f 2-99 < ${TEMPDIR}/process.txt | xargs -I '{}' grep '{}' ${LIST} | sort | uniq | column -t | sort -k 2 > "${TEMPDIR}/package.txt" - join -j 2 "${TEMPDIR}/process.txt" "${TEMPDIR}/package.txt" | column -t | sort -k 2 | uniq > "${TEMPDIR}/all.txt" - echo "FILE PROCESS PACKAGE" > ${TEMPDIR}/head.txt - cat ${TEMPDIR}/head.txt ${TEMPDIR}/all.txt | column -t + # If we can't find it, print out that we are falling back to asking pacman + # Unless we invoke -q (quiet) + if [ ! "${1}" = "-q" ]; then + echo "Could not find ${DB_FILE}" + echo "Asking pacman for file listing using pacman -Ql" + fi + # Get a temp filename + LIST=$(mktemp) + trap "cleanuptemp" + pacman -Ql | sort -u -k 2,2 > "${LIST}" + DB_TEMP_FILE="1" +fi +if [ "${1}" = "-s" ]; then + $PS_LSOF_CMD | cut -d ' ' -f 2-99 | xargs -I '{}' grep '{}' "${LIST}" | sort -u | (echo "PROCESS FILENAME"; cat) | column -t + exit 0 +#elif [ "${1}" = "-h" ]; then +# printf "-q (quiet) -s (show only packages and files) -h (shows this help)\n" +# exit 0 +fi + +OUTPUT=$(join -j 2 <(printf "%s" "${PS_LSOF_OUTPUT}") <(cut -d ' ' -f 2-99 <(printf "%s" "${PS_LSOF_OUTPUT}") | xargs -P 8 -I '{}' grep '{}' "${LIST}" | sort -u -k 2,2) ) +# If there's no output just cleanup a temp file if there is one and exit +if [ "$OUTPUT" = "" ]; then + cleanuptemp + exit 0 fi -if [ -d ${TEMPDIR} ]; then - rm -rf ${TEMPDIR} +if [ "${1}" = "-q" ]; then + printf "%s\n" "$OUTPUT" | column -t +else + printf "FILENAME PROCESS PACKAGE\n%s\n" "$OUTPUT" | column -t fi +cleanuptemp +exit 0 diff --git a/ps-lsof.sh b/ps-lsof.sh index 77fd76124191..88098d3f7c2f 100755 --- a/ps-lsof.sh +++ b/ps-lsof.sh @@ -26,5 +26,16 @@ expressions+=("| grep \" DEL \" ") expressions+=("| grep -vE \" /dev| /run| /drm | /SYSV.*$| /memfd| /\[aio\]\" ") # Replace first 7 occurances of spaces with tabs expressions+=("| sed -e 's/ */\t/' -e 's/ */\t/' -e 's/ */\t/' -e 's/ */\t/' -e 's/ */\t/' -e 's/ */\t/' -e 's/ */\t/' ") -expressions+=("| cut -f 1,8 | sort | uniq | (echo "PROCESS FILENAME";cat) | column -t") -eval "${expressions[@]}" +expressions+=("| cut -f 1,8 | sort -u") +OUTPUT=$(eval "${expressions[@]}") + +# If there's no output, don't print anything +if [ "$OUTPUT" = "" ]; then + exit 0 +elif [ "${1}" = "-q" ]; then + printf "%s\n" "$OUTPUT" | column -t + exit 0 +else + printf "PROCESS FILENAME\n%s\n" "$OUTPUT" | column -t + exit 0 +fi |