go-check-updates

command module
v0.0.0-...-9af655b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 25 Imported by: 0

README

Go Report Card

Introduction

A program to check for updates and make the list of updates available through a JSON file or a simple API. By default it will check for updates every 12 hours, if run in daemon mode then it will refresh every 12 hours, otherwise it simply does nothing when run before 12 hours has passed since the previous update.

The default cache file may change, the first choice is /tmp/go-check-updates.json. If the file exists but it isn't writable, it will fallback to $HOME/.cache/go-check-updates/cache.json instead.

It can be disabled completely with --no-cache.

The refresh interval can be changed with the --cache.interval option, disable with --no-refresh. Disabled without daemon mode will refresh every time it is run, with daemon mode there is no auto-refresh.

It is also possible to monitor the package manager logs, this functionality can be enabled with -w or --watch.enable. Enabled by default when using setup.sh to generate systemd units.

See go-check-updates -h for up to date information on the parameters.

This can then be read by other scripts, for example my own go-motd.

Supported package managers

Manager Name Old Ver New Ver Repo Logs
pacman Y Y Y N* Y
dnf/yum Y N Y Y Y

* Repo is set to "pacman"

NOTE: pacman only tested on Arch Linux, dnf/yum only tested on Fedora

Supported AUR helpers

Manager Name Old Ver New Ver Repo Logs
yay Y Y Y N* N/A
pikaur Y Y Y N* N/A
paru Y Y Y N* N/A

* Repo to "aur"

NOTE: Only tested on Arch Linux

Installation

Arch Linux
git clone https://github.com/cosandr/go-check-updates.git
cd go-check-updates/PKGBUILD
makepkg -si

Enable and start go-check-updates.socket, the pacman hook triggers after every update/remove.

Generic

Use setup.sh, read the help it prints out setup.sh -h

Usage

Assuming it is listening on localhost:8100. See API section for more details.

# Update now, returns after update has completed
$ curl 'http://localhost:8100/api?refresh'
{}
# Refresh internal cache by reading package manager log file
# Best used in post-install hooks as it is quite fast
$ curl 'http://localhost:8100/api?refresh&log_file'
{}
# Update now, return file location immediately
$ curl 'http://localhost:8100/api?refresh&filepath&immediate'
{"filePath":"/tmp/go-check-updates.json","queued":true}
# Get current list of updates
$ curl 'http://localhost:8100/api?updates'
{"data":{"checked":"2020-06-02T13:28:16+02:00","updates":[]}}
# Get current updates, update if file is older than 1 hour and return immediately
# Status code will be 202 and the "queued" key will be present and true if an update was queued
# If no update is needed, status code is 200 and there is no queued key present
$ curl 'http://localhost:8100/api?refresh&updates&immediate&every=1h'
{"data":{"checked":"2020-09-11T14:47:21+02:00","updates":[{"pkg":"snapper","oldVer":"0.8.12-1","newVer":"0.8.13-1","repo":"pacman"}]},"queued":true}
# Can run directly as well (-every can be passed as argument)
$ go-check-updates

Example output

Note this is what the API returns in the data key, the websocket returns exactly this data directly.

{
  "checked": "2020-06-01T23:10:23+02:00",
  "updates": [
    {
      "pkg": "archiso",
      "oldVer": "43-2",
      "newVer": "44-2",
      "repo": "pacman"
    },
    {
      "pkg": "ca-certificates-mozilla",
      "oldVer": "3.52.1-2",
      "newVer": "3.53-1",
      "repo": "pacman"
    },
    {
      "pkg": "imagemagick",
      "oldVer": "7.0.10.15-1",
      "newVer": "7.0.10.16-2",
      "repo": "pacman"
    }
  ]
}

API

Run with --daemon argument to start a web server, listen address and port can be adjusted with --web.listen-address.

Alternatively, systemd socket activation can be used with the --systemd argument, socket and service units can be created with the setup.sh script.

/api endpoint

One of these parameters must be present:

  • filepath returns path to the cache file in use
  • updates returns currently cached updates
  • refresh refreshes cached update list, the other commands run after this one. The following parameters can be combined with this one
    • every value parsed as time duration, it will only refresh if the file is older than this duration
    • immediate won't wait for the request to finish before returning, returned data (if requested) is likely out of date
    • log_file refresh using package manager log file

Status codes:

  • 200 request was successful
  • 400 bad argument(s)
  • 202 update queued
  • 500 something went wrong server side, Error is included in response with more details

Websocket

Requires web server (daemon or systemd mode). Connect to /ws endpoint to receive data (same as the JSON file) when updates are refreshed.

Example usage in my Polybar setup.

Discord notifications

Edit /etc/sysconfig/go-check-updates and add NOTIFY_ENABLE=1 and WEBHOOK_URL="<url>". By default notifications are only sent every hour at most (to prevent spam when upgrading packages), this can be adjusted with the NOTIFY_INTERVAL env variable.

Enabling delta notifications NOTIFY_DELTA or --notify.delta will only send updates which were not present in the last notification, this is particularly useful when a large number of updates are pending.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
types module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL