diff options
author | felics | 2018-07-18 10:42:27 +0200 |
---|---|---|
committer | felics | 2018-07-18 10:42:27 +0200 |
commit | b33d639e5906b5f1723545044940986124f53862 (patch) | |
tree | dfe1236d0e0b3d2469664392f40b6d8506bc7aa5 | |
parent | 5c69f01cac0f73edf89c0811d83c7d37c172f88a (diff) | |
download | aur-b33d639e5906b5f1723545044940986124f53862.tar.gz |
Added an option to install only packages which are newer in the AUR than locally.
-rw-r--r-- | .SRCINFO | 8 | ||||
-rw-r--r-- | PKGBUILD | 8 | ||||
-rwxr-xr-x | idos-packages-update.sh | 221 |
3 files changed, 215 insertions, 22 deletions
@@ -1,15 +1,17 @@ pkgbase = idos-package-updater-script pkgdesc = Bash script which automates the process of updating installed IDOS timetable browser related packages by reinstalling and thus fetching the newest version. - pkgver = 20160719.2 - pkgrel = 4 + pkgver = 20180718.1 + pkgrel = 1 epoch = 0 arch = any groups = idos-timetable license = custom + depends = python3 + depends = python-texttable depends = yaourt source = idos-packages-update.sh source = copying.txt - sha256sums = 400e0e1161d6908b44e48abcaf62fc94ebe8ae9b4d92bcf98c8c402b10a84c69 + sha256sums = 743145a14c800d46c278cc4b81b79be1ce7518fc5bf5f563bc1a4ea0a99e41a0 sha256sums = c3cbff25307e905545788f5c74cc137d79706c60549092f2a37919b93cf55ee3 pkgname = idos-package-updater-script @@ -5,8 +5,8 @@ _pkgname=idos-package-updater-script pkgname="${_pkgname}" epoch=0 -pkgver=20160719.2 -pkgrel=4 +pkgver=20180718.1 +pkgrel=1 pkgdesc="Bash script which automates the process of updating installed IDOS timetable browser related packages by reinstalling and thus fetching the newest version." arch=('any') license=('custom') @@ -16,6 +16,8 @@ groups=( ) depends=( + "python3" + "python-texttable" "yaourt" ) @@ -36,7 +38,7 @@ source=( ) sha256sums=( - "400e0e1161d6908b44e48abcaf62fc94ebe8ae9b4d92bcf98c8c402b10a84c69" + "743145a14c800d46c278cc4b81b79be1ce7518fc5bf5f563bc1a4ea0a99e41a0" "c3cbff25307e905545788f5c74cc137d79706c60549092f2a37919b93cf55ee3" ) diff --git a/idos-packages-update.sh b/idos-packages-update.sh index f524841ede6c..b24c9b002ec0 100755 --- a/idos-packages-update.sh +++ b/idos-packages-update.sh @@ -2,7 +2,7 @@ ## # -# Version: 2016-07-06 +# Version: 2018-07-18 # ## @@ -15,12 +15,17 @@ # the last submit to the AUR. Newer versions may be there, and so this script simply installs the latest version. The locally # installed package will have the correct version number. # +# However, there is a command line options which makes the script just install packages where newer versions are available in the AUR: +# --needed, -s, or --sloppy. +# ## ## # # This script depends on: # * bash +# * python3 +# * python-texttable # * yaourt # * basic utilities: grep, sort, uniq. # (Instead of grep, comm also can be used, by swapping the comment in front of the respective lines). @@ -38,17 +43,136 @@ idos_pkgs_strings=( 'ttf-timetable' ) + +msg() +{ + if [ $# -ge 1 ]; then + echo "$@" + else + cat + fi +} + +stdout_prefix() +{ + prefix="$1" + while read line; do + echo "${prefix}${line}" + done +} + +verbose() { + if "${_verbose}"; then + msg "$@" + fi +} + +debug() { + if "${_debug}"; then + errmsg " [debug] $@" + fi +} + +errmsg() { + msg "$@" > /dev/stderr +} + +exiterror() { + if [ $# -ge 2 ]; then + _exitcode="$2" + else + _exitcode=1 + fi + if [ $# -ge 1 ]; then + _msg="$1" + else + _msg="$0: Unspecified Error. Aborting." + fi + errmsg "${_msg}" + exit "${_exitcode}" +} + +printusage() { + echo "Usage:" + echo " $0 [arguments ...]" + echo "" + echo "Arguments (all optional):" + echo " -h | --help Print this message and exit." + echo " -s | --sloppy | --needed" + echo " Just install if the version info in the AUR is newer than" + echo " the locally installed version." + echo " Default is to re-installed every locally installed idos-" + echo " packages since version numbers in the AUR may be outdated." + echo " -d | --debug Print some detailed information as we go on." + echo " (Does _not_ imply -v.)" + echo " -v | --verbose Print verbose summary." +} + + +### Variables that can be changed by command line options: +_sloppy=false +_debug=false +_verbose=false + +### Parse command line options: +while [ $# -ge 1 ]; do + case "$1" in + "-h"|"--help"|"help") + shift + printusage + exit 0 + ;; + "-s"|"--sloppy"|"--needed") + _sloppy=true + shift + ;; + "-d"|"--debug") + _debug=true + shift + ;; + "-v"|"--verbose") + _verbose=true + shift + ;; + *) + _unknownarg="$1" + shift + errmsg "$0: Error: Unrecognised argument '${_unknownarg}'." + errmsg "" + errmsg "$(printusage)" + errmsg "" + exiterror "Aborting." 1 + ;; + esac +done + +debug "This is a debug message, testing the debug logic." + + get_installed_pkgs_version() { # From all the packages given as arguments, returns their version number, line by line. If a package is not installed, return empty string, and: # * If it is the only package given at the command line, finish with an exitcode >0. # * If it is amongst other packages, silently ignore. if [ $# -eq 1 ]; then - yaourt -Q "$1" | awk '{print $2}' + debug "Querying version for installed package '$1' ..." + _raw="$(yaourt -Q "$1")" exitcode_query="$?" + if [ "${exitcode_query}" -eq 0 ]; then + echo "${_raw}" | awk '{print $2}' + else + echo '' + fi else - while [ $# -gt 1 ]; do - yaourt -Q "$1" 2>/dev/null | awk '{print $2}' + while [ $# -ge 1 ]; do + debug "Querying version for installed package '$1' ..." + _raw="$(yaourt -Q "$1" 2>/dev/null)" + _exitcode="$?" + if [ "${_exitcode}" -eq 0 ]; then + echo "${_raw}" | awk '{print $2}' + else + echo '' + fi shift done exitcode_query=0 @@ -57,43 +181,108 @@ get_installed_pkgs_version() { return "${exitcode_query}" } -### Those variables will hold, line by line, the packages available for install and the one installed: +get_aur_pkgs_version() { + # From all the packages given as arguments, returns their version number, line by line, as in the AUR. If a package is not available in the repositories, return empty string, and: + # * If it is the only package given at the command line, finish with an exitcode >0. + # * If it is amongst other packages, silently ignore. + + if [ $# -eq 1 ]; then + debug "Querying version for package 'aur/$1' ..." + _raw="$(yaourt -Si "aur/$1")" + exitcode_query="$?" + if [ "${exitcode_query}" -eq 0 ]; then + echo "${_raw}" | sed -n -r 's|^Version[[:space:]]*\:[[:space:]]*||p' + else + echo '' + fi + shift + else + while [ $# -ge 1 ]; do + debug "Querying version for package 'aur/$1' ..." + _raw="$(yaourt -Si "aur/$1" 2>/dev/null)" + _exitcode="$?" + if [ "${_exitcode}" -eq 0 ]; then + echo "${_raw}" | sed -n -r 's|^Version[[:space:]]*\:[[:space:]]*||p' + else + echo '' + fi + shift + done + exitcode_query=0 + fi + + return "${exitcode_query}" +} + +### Those variables will hold, line by line, the packages available for installation and the ones installed: avail='' installed='' for pkg_string in "${idos_pkgs_strings[@]}"; do ### Get packages available for installation. The "echo ''" is there to get a newline added if new content is following. + debug "Searching for installable packages matching the search string '${pkg_string}' ..." avail+="$(echo ''; yaourt -S -q -s "${pkg_string}")" ### Get packages which are installed. The "echo ''" is there to get a newline added if new content is following. - installed+="$(echo ''; yaourt -Q -q -s "${pkg_string}"; echo "")" + debug "Searching for installed packages matching the search string '${pkg_string}' ..." + installed+="$(echo ''; yaourt -Q -q -s "${pkg_string}"; echo '')" done +### Set union of available and installed packages: +installed_or_available="${avail} +${installed}" ### Sort and unify and remove blank lines: avail="$(echo "${avail}" | sort | uniq | grep -E .)" installed="$(echo "${installed}" | sort | uniq | grep -E .)" +installed_or_available="$(echo "${installed_or_available}" | sort | uniq | grep -E .)" ### Get version numbers of installed packages before upgrade: old_vers="$(echo "${installed}" | while read pkg; do get_installed_pkgs_version "${pkg}"; done)" +# old_vers="$(get_installed_pkgs_version ${installed})" + +### Get AUR version numbers of installed packages: +aur_vers="$(echo "${installed}" | while read pkg; do get_aur_pkgs_version "${pkg}" 2>/dev/null || echo ''; done)" +# aur_vers="$(get_aur_pkgs_version ${installed})" ### Get packages which are installed and available for installation at the same time: #installed_and_available="$(comm -1 -2 <(echo "${installed}" | sort) <(echo "${avail}" | sort))" # comm would do the job, on sorted files. grep also works on unsorted files. installed_and_available="$(echo "${avail}" | grep -F -x "${installed}" | sort | uniq)" +### Reformat to python-lists: +py_old_vers="$(echo '['; echo "${old_vers}" | while read line; do echo "'${line}',"; done; echo ']')" +py_aur_vers="$(echo '['; echo "${aur_vers}" | while read line; do echo "'${line}',"; done; echo ']')" +py_installed="$(echo '['; echo "${installed}" | while read line; do echo "'${line}',"; done; echo ']')" + ### Print some information: -_reinstall_marker="(x)" -echo "Installed IDOS-related packages with version. Packages marked with '${_reinstall_marker}'" -echo "can and will be reinstalled." -echo "" -_pkgnr=0 -echo "${installed}" | while read pkg; do - _pkgnr="$(( ${_pkgnr} + 1 ))" - if echo "${avail}" | grep -q -F -x "${pkg}"; then echo -n " ${_reinstall_marker} "; else echo -n " "; fi - echo -n "${pkg} "; echo "${old_vers}" | sed -n "${_pkgnr}"p -done +echo "Installed IDOS-related packages, with version information." echo "" +cat << EOPY | python3 +import texttable + +inst=${py_old_vers} +aur=${py_aur_vers} +pkg=${py_installed} + +tbl=texttable.Texttable(0) +tbl.header(['AUR ver.','Installed ver.','Package']) +tbl.add_rows([list(x) for x in zip(*[aur,inst,pkg])],header=False) + +print(tbl.draw()) +EOPY + + +# echo " Installed version AUR version package " +# _pkgnr=0 +# echo "${installed}" | while read pkg; do +# _pkgnr="$(( ${_pkgnr} + 1 ))" +# if echo "${avail}" | grep -q -F -x "${pkg}"; then echo -n " (x) "; else echo -n " "; fi +# echo -n "${pkg} "; echo "${old_vers}" | sed -n "${_pkgnr}"p +# done +# echo "" + +exit 11 ### Reinstall installed and available packages: yaourt -S --noconfirm ${installed_and_available} |