summaryrefslogtreecommitdiffstats
path: root/client/engine
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2020-03-04 18:53:15 +0100
committerRamón M. Gómez <ramongomez@us.es>2020-03-04 18:53:15 +0100
commitd230bb755c52c4c2bd7842d855a488db562b8fc7 (patch)
tree9ede63d09e376e7e17d016a803eacfd0614e6a3f /client/engine
parentfd8609ed771527bf00a575ef6e06b714a592d1ad (diff)
#966: Function `ogListSoftware` also lists Flatpak and Snappy applications.
Diffstat (limited to 'client/engine')
-rwxr-xr-xclient/engine/Inventory.lib81
1 files changed, 51 insertions, 30 deletions
diff --git a/client/engine/Inventory.lib b/client/engine/Inventory.lib
index 92b46ef4..820a45c9 100755
--- a/client/engine/Inventory.lib
+++ b/client/engine/Inventory.lib
@@ -224,7 +224,7 @@ lshw | awk 'BEGIN {type="mod";}
function ogListSoftware ()
{
# Variables locales.
-local MNTDIR TYPE DPKGDIR RPMDIR PACMANDIR k
+local APPS HIVE k KEYS KEYS32 MNTDIR PKGDIR PROG VERS TMPFILE TYPE
# Si se solicita, mostrar ayuda.
if [ "$*" == "help" ]; then
@@ -238,14 +238,16 @@ fi
MNTDIR=$(ogMount $1 $2) || return $?
TYPE=$(ogGetOsType $1 $2) || return $?
-# Sistema Operativo en la primera línea de la salida
-ogGetOsVersion $1 $2 | awk -F ':' '{print $2}'
+# Ficheros temporales.
+APPS=$(mktemp /tmp/apps.XXXXX)
+TMPFILE=$(mktemp /tmp/tmp.XXXXX)
+trap "rm -f $APPS $TMPFILE" 1 2 3 9 15
case "$TYPE" in
Linux) # Software de GNU/Linux.
# Procesar paquetes dpkg.
- DPKGDIR="${MNTDIR}/var/lib/dpkg"
- if [ -r $DPKGDIR ]; then
+ PKGDIR="${MNTDIR}/var/lib/dpkg"
+ if [ -r $PKGDIR ]; then
# Proceso de fichero en sistemas de 64 bits.
awk '/Package:/ {if (pack!="") print pack,vers;
sub(/-dev$/,"",$2);
@@ -254,73 +256,87 @@ case "$TYPE" in
vers=$2}
/Status:/ {if ($2!="install") pack=vers=""}
END {if (pack!="") print pack,vers}
- ' $DPKGDIR/status | sort | uniq
+ ' $PKGDIR/status > $APPS
fi
# Procesar paquetes RPM.
- RPMDIR="${MNTDIR}/var/lib/rpm"
- if [ -r $RPMDIR ]; then
+ PKGDIR="${MNTDIR}/var/lib/rpm"
+ if [ -r $PKGDIR ]; then
# Listar si está instalado el paquete "rpm" en el cliente.
if which rpm &>/dev/null; then
- rm -f ${RPMDIR}/__db.*
- rpm --dbpath $RPMDIR -qa --qf "%{NAME} %{VERSION}\n" 2>/dev/null | \
- awk '$1!~/-devel$/ {sub(/-.*$/,"",$2); print $0}' | sort | uniq
- rm -f ${RPMDIR}/__db.*
+ rm -f ${PKGDIR}/__db.*
+ rpm --dbpath $PKGDIR -qa --qf "%{NAME} %{VERSION}\n" 2>/dev/null | \
+ awk '$1!~/-devel$/ {sub(/-.*$/,"",$2); print $0}' > $APPS
+ rm -f ${PKGDIR}/__db.*
else
# Obtener el nombre de cada paquete en la BD de RPM.
python <<<"
import re;
import bsddb;
-db=bsddb.hashopen('$RPMDIR/Name','r');
+db=bsddb.hashopen('$PKGDIR/Name','r');
for k in db.keys():
- print re.sub('-devel$','',k);" | sort | uniq
+ print re.sub('-devel$','',k);" > $APPS
fi
fi
# Procesar paquetes pacman.
- PACMANDIR="${MNTDIR}/var/lib/pacman/local"
- if [ -r $PACMANDIR ]; then
- ls $PACMANDIR | awk -F- '/-/ {print gensub(/-/, " ", NF-2);}'
+ PKGDIR="${MNTDIR}/var/lib/pacman/local"
+ if [ -r $PKGDIR ]; then
+ ls $PKGDIR | awk -F- '/-/ {print gensub(/-/, " ", NF-2);}' > $APPS
fi
+ # Procesar aplicaciones Snappy.
+ PKGDIR="${MNTDIR}/snap"
+ find $PKGDIR/*/current/meta -name snap.yaml -exec \
+ awk '/name:/ {pack=$2}
+ /version:/ {vers=$2}
+ END {if (pack!="") print pack,"(snap)",vers}' {} 2>/dev/null \; >> $APPS
+ # Procesar aplicaciones Flatpak.
+ PKGDIR="${MNTDIR}/var/lib/flatpak"
+ ls -1 $PKGDIR/app/*/current/active/deploy 2> /dev/null | python -c "
+import sys
+for f in sys.stdin:
+ p = open(f.strip()).read().split('\0')
+ try:
+ if(p[0] != 'flathub'):
+ raise ValueError
+ print('{} (flatpak) {}'.format(p[p.index('appdata-name') + 4], p[p.index('appdata-version') + 1]))
+ except ValueError:
+ pass
+" >> $APPS
;;
Windows) # Software de Windows.
# Comprobar tipo de proceso del registro de Windows.
if which hivexregedit &>/dev/null; then
# Nuevo proceso más rápido basado en "hivexregedit".
- local HIVE TMPFILE
HIVE=$(ogGetHivePath $MNTDIR software 2>/dev/null)
if [ -n "$HIVE" ]; then
# Claves de registro para programas instalados.
- TMPFILE=/tmp/tmp$$
- trap "rm -f $TMPFILE" 1 2 3 9 15
hivexregedit --unsafe-printable-strings --export "$HIVE" '\Microsoft\Windows\CurrentVersion\Uninstall' > $TMPFILE 2>/dev/null
hivexregedit --unsafe-printable-strings --export "$HIVE" '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' >> $TMPFILE 2>/dev/null
# Mostrar los valores "DisplayName" y "DisplayVersion" para cada clave.
awk -F\" '$1~/^\[/ {n=""}
$2~/DisplayName/ {n=$4}
$2~/DisplayVersion/ {print n,$4}
- ' $TMPFILE | sort | uniq
- rm -f $TMPFILE
+ ' $TMPFILE > $APPS
fi
else
# Compatibilidad con clientes ogLive antiguos.
- local KEYS KEYS32 PROG VERS
# Claves de registro para programas instalados: formato "{clave}".
KEYS=$(ogListRegistryKeys $MNTDIR software '\Microsoft\Windows\CurrentVersion\Uninstall')
KEYS32=$(ogListRegistryKeys $MNTDIR software '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
# Mostrar los valores "DisplayName" y "DisplayVersion" para cada clave.
- (for k in $KEYS; do
+ for k in $KEYS; do
PROG=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
if [ -n "$PROG" ]; then
VERS=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
echo "$PROG $VERS"
fi
- done
- for k in $KEYS32; do
+ done > $APPS
+ for k in $KEYS32; do
PROG=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
if [ -n "$PROG" ]; then
VERS=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
echo "$PROG $VERS"
fi
- done) | sort | uniq
+ done >> $APPS
fi
;;
MacOS) # Software de Mac OS.
@@ -332,15 +348,20 @@ for k in db.keys():
[ -s "$FILE" ] && VERSION=$(awk -F"[<>]" '/ShortVersionString/ {getline;v=$3}
END {print v}' "$FILE")
echo "$(basename "$k" .app) $VERSION"
- done | sort
+ done > $APPS
;;
BSD) # Software de FreeBSD.
sqlite3 $MNTDIR/var/db/pkg/local.sqlite <<<"SELECT name FROM pkg_search;" 2>/dev/null | \
- sed 's/\(.*\)-\(.*\)/\1 \2/g' | sort
+ sed 's/\(.*\)-\(.*\)/\1 \2/g' > $APPS
;;
- *) ogRaiseError $OG_ERR_PARTITION "$1, $2"
+ *) ogRaiseError $OG_ERR_NOTOS "$1, $2 ${TYPE+($TYPE)}"
return $? ;;
esac
+
+# Mostrar sistema Operativo y aplicaciones.
+ogGetOsVersion $1 $2 | awk -F: '{print $2}'
+sort $APPS | uniq
+rm -f $APPS $TMPFILE
}
#/**