This page permanently redirects to gemini://m0yng.uk/2020/08/aptChecker---Keeping-too-many-things-updated/.

aptChecker - Keeping too many things updated - M0YNG.uk

Created 2020-08-26

Modified 2021-02-10

=> Tagged

It's an obvious problem to me that I have too many computers, and keeping on top of which have been updated recently is... not simple.

I've finally got around to making a semi solution, using a bash script and some PHP! Is there a better way? Almost certainly! Would it work easily and quickly on even a raspberry pi v1 and zero without stopping them doing the thing I want them to do? Maybe not.

Update

=> I've added some new bits (remote server checks), detailed in part two

=> Pager showing that radiopi-10 has 18 updates available [IMG]

The Bits

The page is simple, and looks like this (I could probably format the date time, but meh.)

=> Screenshot white text on black in a table showing update counts for different systems [IMG]

The code

aptChecker.sh

#!/bin/bash

hostname=$(hostname)
datetime=$(date --iso-8601=seconds)

apt update

updatecount=$(apt list --upgradeable | wc -l)

# correct for always getting at least one, even if there are none
updatecount=$((updatecount - 1))

echo $updatecount

curl -X POST -F "hostname=$hostname" -F "datetime=$datetime" -F "updatecount=$updatecount" http://myserver/aptCounter.php

aptCounter.php

 (string) $_POST['hostname'],
        "datetime" => (string) $_POST['datetime'],
        "updatecount" => (int) $_POST['updatecount'],
    ];

    $hostname = $newEntry->hostname;

    $aptCounterData[$newEntry->hostname] = $newEntry;

    file_put_contents("aptCounter.json", json_encode($aptCounterData));
    if ($newEntry->updatecount > 0) {
        echo $newEntry->updatecount;
        $url = 'http://www.hampager.de:8080/calls';
        $data = array('text' => "M0YNG: $newEntry->hostname has $newEntry->updatecount updates available.", 'callSignNames' => ['m0yng'], 'transmitterGroupNames' => ['UK-ALL'], 'emergency' => 'false');
        $auth = base64_encode('m0yng:mypassword');

        $options = array(
            'http' => array(
                'header' => "Content-type: application/json\r\nAuthorization: Basic $auth",
                'method' => 'POST',
                'content' => json_encode($data),
            ),
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);

        var_dump($result);

    }

    echo "Done.";
    exit();
} else if ($_SERVER['QUERY_STRING'] == 'format=json') {
    header('Content-Type: application/json');

    echo json_encode($aptCounterData);
} else {
    usort($aptCounterData, function ($a, $b) {return $a['updatecount'] < $b['updatecount'];});
    ?>




  
  
  aptChecker Counts
  


aptChecker Counts

0) { } $host['goodbad'] = ($host['updatecount'] > 0 ? 'bad' : 'good'); echo ""; } ?>
HostnameDateTimeUpdate Count
${host['hostname']}${host['datetime']}${host['updatecount']}

-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-

๐Ÿ–ค Black Lives Matter

๐Ÿ’™๐Ÿค๐Ÿ’œ Trans Rights are Human Rights

โค๏ธ๐Ÿงก๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ Love is Love

Copyright ยฉ 2024 Christopher M0YNG - It is forbidden to use any part of this site for crypto/NFT/AI related projects.

=> Code snippets are licenced under the Hippocratic License 3.0 (or later.)

Page generated 2024-12-13 by Complex 19

Proxy Information
Original URL
gemini://m0yng.uk/2020/08/aptChecker---Keeping-too-many-things-updated
Status Code
Success (20)
Meta
text/gemini;lang=en
Capsule Response Time
338.694777 milliseconds
Gemini-to-HTML Time
0.731629 milliseconds

This content has been proxied by September (3851b).