Commit Diff
Diff:
/dev/null
2ca2e1e39206ec748fcdeec2ccfb3fd58de5861d
Commit:
2ca2e1e39206ec748fcdeec2ccfb3fd58de5861d
Tree:
37c5ecb46f837b4c693163a237685468189cf2f9
Author:
Omar Polo <op@xglobe.in>
Date:
Sat Feb 29 10:06:53 2020 UTC
Message:
initial commit
commit - /dev/null
commit + 2ca2e1e39206ec748fcdeec2ccfb3fd58de5861d
blob - /dev/null
blob + 423965512d13cddb5bb9eb5e86a8fa7d5b6a0325 (mode 644)
--- /dev/null
+++ .gitignore
@@ -0,0 +1,2 @@
+cache
+db
blob - /dev/null
blob + c56647c07d0592aae8199681ca38f993f75a7953 (mode 644)
--- /dev/null
+++ Makefile
@@ -0,0 +1,29 @@
+.PHONY: help add
+
+FTP = 'curl -s'
+
+URI = http://dl-cdn.alpinelinux.org/alpine/
+REPO = edge
+ARCH = x86_64
+FULL_URL= ${URI}/${REPO}/main/${ARCH}/
+
+db: # create the db
+ touch db
+
+help: # print the usage
+ @echo " DEPCHECK -- a tool to look for outdated packages"
+ @echo ""
+ @echo "The following targets are available:"
+ @grep '^[a-z]' Makefile | sort | \
+ awk -F':.*? # ' '{print " - " $$1 ": " $$2}'
+# double quotes because make replace $1 without bothering about escaping
+
+add: # add a package to the db
+ @if [ -z "$PKG" ]; then echo "Missing PKG name"; exit 1; fi
+
+cache: # create a local cache
+ @echo -n "Updating the cache..."
+ @${FTP} ${FULL_URL} | \
+ awk '/^<a href=".*?.apk"/' | \
+ sed -e 's/^<a href=".*">//' -e 's,</a>.*,,' > cache
+ @echo " done!"
blob - /dev/null
blob + c54bc6e1591f5c64cfed1ea12a68124f6744e340 (mode 644)
--- /dev/null
+++ check.awk
@@ -0,0 +1,28 @@
+# Copyright (c) 2020 Omar Polo
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+{
+ pkg = $1
+ ver = $2
+ cmd = sprintf("egrep '^%s-[0-9]' \"%s\"", pkg, cache)
+
+ cmd | getline
+ sub(sprintf("%s-", pkg), "", $0)
+ cachever = $0
+ close(cmd)
+
+ if (ver != cachever) {
+ printf("%s %s -> %s\n", pkg, ver, cachever)
+ }
+}
blob - /dev/null
blob + fe40dce7154e075cf8b5a702c0a8abf262b4d050 (mode 755)
--- /dev/null
+++ depcheck
@@ -0,0 +1,221 @@
+#!/bin/sh
+#
+# Copyright (c) 2020 Omar Polo
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+## configuration variables:
+
+FTP=$FTP
+URI=${URI:-http://dl-cdn.alpinelinux.org/alpine}
+BRANCH=${BRANCH:-edge}
+REPOS=${REPOS:-main community}
+ARCH=${ARCH:-x86_64}
+
+SILENT=off
+CACHE=${DEPCHECKCACHE:-./cache}
+DB=${DEPCHECKDB:-db}
+
+## utility functions
+
+# print $1 on standard error
+err() { printf "%s" "$1" >&2; }
+errln() { printf "%s\n" "$1" >&2; }
+
+help() {
+ case "$1" in
+ help)
+ echo "USAGE: $0 help <action>"
+ echo ""
+ echo "display usage for the given action"
+ ;;
+ add)
+ echo "USAGE: $0 add <package> [version]"
+ echo ""
+ echo "Add package to the database with the given version. If version is empty, the one present in the cache is used." | fmt
+ ;;
+ remove)
+ echo "USAGE: $0 remove <package>"
+ echo ""
+ echo "Remove package from the database"
+ ;;
+ update-cache)
+ echo "USAGE: $0 update-cache"
+ echo ""
+ echo "Re-creates package cache"
+ ;;
+ check|check-updates)
+ echo "USAGE: $0 check|check-updates"
+ echo ""
+ echo "Confront the installed packages against the cache to find if something can be updated" | fmt
+ ;;
+ lookup)
+ echo "USAGE: $0 lookup <package>"
+ echo ""
+ echo "Search the cache for the package given"
+ ;;
+ cron)
+ echo "USAGE: $0 cron"
+ echo ""
+ echo "Update the cache and then check for updates with logging disabled" | fmt
+ ;;
+ *)
+ echo "depcheck - look for outdated packages"
+ echo ""
+ echo "USAGE: $0 [-s] [-c cache] [-d db] <action> [args ...]"
+ echo " add : add a package to the db"
+ echo " check : alias for check-updates"
+ echo " check-updates : check updates for packages in db"
+ echo " cron : update cache and check updates"
+ echo " help : this help message"
+ echo " lookup : search the cache"
+ echo " remove : remove a package from the db"
+ echo " update : alias for update-cache"
+ echo " update-cache : update the cache"
+ echo ""
+ echo "See also: $0 help <action>"
+ ;;
+ esac
+}
+
+# lookup package in cache, creating it if necessary
+lookup() {
+ package=${1:?missing package name}
+
+ if [ ! -f $CACHE ]; then
+ update-cache
+ fi
+ # TODO: check also if cache is ``too old'' (~7 days?)
+
+ pkg=`egrep '^'$package'-[0-9]' $CACHE`
+ if [ -z "$pkg" ] ; then
+ errln "package $package not found"
+ exit 1
+ fi
+
+ printf "%s\n" "$pkg" | sed "s/^$package-//"
+}
+
+# add a package to the db
+add() {
+ package=${1:?missing package name}
+ version=$2
+
+ if [ -z "$2" ]; then
+ if ! version=`lookup $package`; then
+ exit 1
+ fi
+ fi
+
+ if grep "^$package:" "$DB" 2>&1 >/dev/null; then
+ errln "warn: package $package already added, changing version to $version"
+
+ remove "$package"
+ fi
+
+ echo "$package:$version" | tee -a db
+}
+
+# remove a program
+remove() {
+ package=${1:?missing package name}
+
+ # TODO: do all version of sed accept -i'' ?
+ sed -i'' "/^$package:/d" "$DB"
+}
+
+# update local cache
+update-cache() {
+ rm -f $CACHE
+ [ "$SILENT" = "off" ] && err "Updating cache... "
+ for repo in $REPOS; do
+ [ "$SILENT" = "off" ] && err $repo" "
+ $FTP $URI/$BRANCH/$repo/$ARCH/ | \
+ sed -e '/^<a href=".*\.apk"/!d' \
+ -e 's/^<a href="//' \
+ -e 's,\.apk.*,,' \
+ >> $CACHE
+ if [ $? -ne 0 ]; then
+ errln "failed to fetch packages in repo $repo"
+ exit 1
+ fi
+ done
+ [ "$SILENT" = "off" ] && errln "done!"
+}
+
+check-updates() {
+ if [ ! -f "$CACHE" ]; then
+ update-cache
+ fi
+
+ awk -F: -f check.awk -v cache="$CACHE" "$DB"
+}
+
+cron() {
+ SILENT=on
+ update-cache || exit 1
+ check-updates
+}
+
+checkprog() {
+ prg=${1:?missing program name}
+ which "$1" >/dev/null 2>&1
+}
+
+## main
+
+if [ ! -f "$DB" ]; then touch "$DB"; fi
+
+# if fmt(1) is not available, fall back to cat(1).
+if ! checkprog fmt; then
+ alias fmt=cat
+fi
+
+# check for a downloader
+if [ -z "$FTP" ]; then
+ case `uname` in
+ OpenBSD) FTP="ftp -V -o-" ;;
+ FreeBSD) FTP="fetch -o-" ;;
+ *)
+ if checkprog curl; then
+ FTP="curl -s"
+ else
+ err 'Cannot find a program to download HTTP pages. Please install curl or provide an appropriate program in $FTP' | fmt
+ exit 1
+ fi
+ esac
+fi
+
+args=`getopt sc:d: $*`
+set -- $args
+while [ $# -ne 0 ]; do
+ case "$1" in
+ -s) SILENT=on; shift ;;
+ -c) CACHE=$1; shift ;;
+ -d) DB=$1; shift ;;
+ --) shift; break ;;
+ esac
+done
+
+action=$1
+
+case $action in
+ help) help $2 ;;
+ add) add $2 $3 ;;
+ remove) remove $2 ;;
+ update|update-cache) update-cache ;;
+ check|check-updates) check-updates ;;
+ lookup) lookup $2 ;;
+ cron) cron ;;
+ *) help; exit 1 ;;
+esac
blob - /dev/null
blob + 3c680b5abe0f8869b4fac800aea81d3a5d426a03 (mode 644)
--- /dev/null
+++ depcheck.1
@@ -0,0 +1,114 @@
+.\" Copyright (c) 2020 Omar Polo#
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.Dd Feb 23, 2020
+.Dt DEPCHECK 1
+.Os
+.Sh NAME
+.Nm depcheck
+.Nd look for outdated packages
+.Sh SYNOPSIS
+.Nm
+.Op Fl s
+.Op Fl c Ar cache
+.Op Fl d Ar db
+action
+.Op Ar args...
+.Sh DESCRIPTION
+The
+.Nm
+utility tracks packages version from alpine linux repositories to
+check when an update is available.
+.Pp
+The arguments are as follows:
+.Bl -tag -width Ds
+.It Fl s
+Doesn't print status information, be silent.
+.It Fl c Ar cache
+Set the cache file
+.It Fl d Ar db
+Set the db file
+.El
+.Pp
+The action are as follows:
+.Bl -tag -width Ds
+.It add Ar package Op version
+Track
+.Ar package
+using the given version, or the one in the cache if not given.
+.It check
+Alias for check-updates.
+.It check-updates
+Confront the list of tracked packages against the cache and print the
+packages that needs to be updated
+.It cron
+Set verbose to off, updates the cache and then check for updates. It's
+an an alias for
+.Bd -literal -offset indent
+depcheck -s update-cache
+depcheck check-updates
+.Ed
+.It help Op topic
+Print help information about
+.Op topic
+.Ns . Otherwise, print general information about the program.
+.It lookup Ar package
+Looks up package version in cache
+.It remove Ar package
+Don't track
+.Ar package
+anymore.
+.It update
+Alias for update-cache.
+.It update-cache
+Discard the current cache and downloads the latest list of packages.
+.El
+.Pp
+All commands that deals with cache will try to create one if not found.
+.Sh ENVIRONMENT
+The following environment variables are respected
+.Bl -tag -width DEPCHECKCACHE
+.It Ev FTP
+A program (eventually with the proper flags) that downloads the given
+page via HTTP and print it to standard output. By default uses
+.Xr ftp 1 No on OpenBSD, Xr fetch 1 No on FreeBSD and Xr curl 1
+on other sistem if available.
+.It Ev URI
+The base address of an alpine linux mirror. By default is
+http://dl-cdn.alpinelinux.org/alpine. Note that it does not ends with
+a slash '/'.
+.It Ev BRANCH
+The branch of packages to consider, "edge" by default.
+.It Ev REPOS
+A space-delimited list of repository to cache. By default is "main
+community".
+.It Ev ARCH
+The architecture to consider, x86_64 by default.
+.It Ev DEPCHECKCACHE
+The path to the cache file. It is "cache" by default.
+.It Ev DEPCHECKDB
+The path to the database. It is "db" by default.
+.El
+.Sh FILES
+.Bl -tag -width Ds
+.It cache
+The cache file contains line in the form of package-version as found
+on the mirror
+.It db
+The database file contains a series of package:version lines.
+.El
+.Sh EXAMPLES
+.Nm
+is crontab-friendly:
+.Bd -literal -offset indent
+depcheck cron
+.Ed
Omar Polo