documentation/audit/dopackagelist

64 lines
1.5 KiB
Bash

#!/bin/bash
# 2023-01-04 Cpm
align_dpkgs()
{
local source_file="$1"
local letter="$2"
# Find the longest position.
local max=0
while read -r line; do
if [[ $line =~ '||/ N' ]]; then
local pos=$(expr index "$line" "$letter")
if (( $pos > $max)); then
max=$pos
fi
fi
done < "$source_file"
# Insert spaces.
local currentpos=0
local middle=""
while read -r line; do
#echo -e "$line\n"
if [[ $line =~ '||/ N' ]]; then
local currentpos=$(expr index "$line" "$letter")
currentpos=$(($currentpos-1))
local diff=$(($max-currentpos-1))
middle=$(printf %${diff}s)
local start=${line:0:currentpos}
local end=${line:currentpos}
echo "${start}${middle}${end}"
elif [[ $line =~ 'ii ' ]]; then
local start=${line:0:currentpos}
local end=${line:currentpos}
echo "${start}${middle}${end}"
fi
done < "$source_file"
}
# ##############################################################################
# Put all dpkg -l output in one file.
dpkg -l --no-pager > tmp
for guest in $(cat machines.txt) ;
do
ssh -t admin666@$guest dpkg -l --no-pager >> tmp
done
# Align the column Version.
align_dpkgs "tmp" "V" > tmp2
# Align the column Architecture.
align_dpkgs "tmp2" "A" > tmp
# Output cleaned lines.
grep "^ii" tmp | sort | uniq
# Clean temprary files.
rm tmp tmp2