Penguin Crumbs

Notes and tips from a Linux user

home about this blog
search:  

Tracking the configuration of several Ubuntu desktops

Being the administrator of several Linux installations can be frustrating: each machine has its own configuration and a variable number of different installed software. And this is particularly annoying in the case of desktop installations, if users can install what they want.

To keep my Ubuntu desktops under control without adding more installed software even further, I created a small script that generates a file in HTML format containing a summary of the installation, including the list of the packages, their repository of origin (this is not trivial at all!) and other information. It should also work on other distros derived from Debian, maybe with minor modifications.

At your option, of course the script can be scheduled at will and the result can be uploaded in a single shared directory.

I'm sharing it with you in this post, hoping it will be helpful or even for purely educational purposes.

#!/bin/bash

readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly TMP_FILE_PKG="$SCRIPT_DIR/packages.tmp"
readonly TMP_FILE_VER="$SCRIPT_DIR/sw_versions.tmp"
readonly OUTPUT_HTML_FILE="$SCRIPT_DIR/CONFIGURATION of $(hostname).html"

function filetowrite() {
    echo "$1" >> "$OUTPUT_HTML_FILE"
}

rm -f "$OUTPUT_HTML_FILE"
filetowrite "<!DOCTYPE html>"
filetowrite "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"
filetowrite "<body style=\"font-family: Verdana,Helvetica,Arial,sans-serif; font-size: 11pt\">"
filetowrite "<h1><font color=\"#cc6600\">Configuration of $(hostname)</font></h1>"
filetowrite "<i>file creation timestamp: $(date +"%Y-%m-%d %H:%M:%S")</i></br>"

filetowrite "<h2>General OS information</h2>"
filetowrite "<pre>"
filetowrite "$(cat /etc/lsb-release)"
filetowrite "</pre>"

filetowrite "<h2>Users</h2>"
filetowrite "<pre>"
filetowrite "$(awk -F: '($3>=1000)&&($1!="nobody")' /etc/passwd)"
filetowrite "</pre>"

filetowrite "<h2>Output of \"ifconfig\"</h2>"
filetowrite "<pre>"
filetowrite "$(ifconfig)"
filetowrite "</pre>"

filetowrite "<h2>Configured repositories</h2>"
filetowrite "<pre>"
filetowrite "$(grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null | sort -u)"
filetowrite "----"
filetowrite "last repo synchronization: $(stat -c %y /var/lib/apt/periodic/update-success-stamp)"
filetowrite "</pre>"

filetowrite "<h2>Installed software from repositories</h2>"
dpkg -l grep ^ii "$TMP_FILE_PKG"
filetowrite "numer of packages: $(cat "$TMP_FILE_PKG" | wc -l)</br>&nbsp;</br>"
filetowrite "<table border=\"1\">"
filetowrite "<tr><td>PACKAGE NAME</td><td>REPOSITORY</td></tr>"
pkg_count=0

while read line_from_pkg_filedo
    nome_pkg=$(echo $line_from_pkg_file | cut -d' ' -f2)
    apt-cache policy $nome_pkg "$TMP_FILE_VER"

    next_line_is_ok=0
    while read text_linedo
        if "$next_line_is_ok" -eq "1" ]; then
            repo=${text_line:4}
            if "$repo" == "/var/lib/dpkg/status" ]; then
                repo="<i>unknown</i>"
            fi
            filetowrite "<tr><td>$nome_pkg</td><td>$repo</td></tr>"
            next_line_is_ok=0
            let pkg_count+=1
        else
            line_beginning=${text_line:0:4}
            if "$line_beginning" == "*** " ]; then
                next_line_is_ok=1
            fi
        fi
    done "$TMP_FILE_VER"
done "$TMP_FILE_PKG"
filetowrite "</table>"

filetowrite "<h2>Installed software from snap</h2>"
filetowrite "<pre>"
filetowrite "$(snap list)"
filetowrite "</pre>"

filetowrite "</body></html>"

rm -f "$TMP_FILE_PKG" "$TMP_FILE_VER"

 
 
Posted on 2019-06-08  
 
⇦  back
 
__________________
 
Copyright © 2019 Marcello Zaniboni