From 4f8721564f5d29a89a6af04b002f370fdc0fafc4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 19 Jun 2014 20:19:00 -0400 Subject: add alfplayer's libredbdiff script --- src/abslibre-tools/libredbdiff | 141 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 src/abslibre-tools/libredbdiff (limited to 'src/abslibre-tools/libredbdiff') diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff new file mode 100755 index 0000000..67b3245 --- /dev/null +++ b/src/abslibre-tools/libredbdiff @@ -0,0 +1,141 @@ +#!/bin/bash + +name="Libredbdiff" + +baseconfpath="/etc/libredbdiff" +basedbpath="/var/lib/libredbdiff" + +conffile="$baseconfpath/pacman.conf.parabola" +conffilearch="$baseconfpath/pacman.conf.archlinux" + +dbpath="$basedbpath/pacman.parabola" +dbpatharch="$basedbpath/pacman.archlinux" + +mirrorlist="$baseconfpath/mirrorlist.parabola" +mirrorlistarch="$baseconfpath/mirrorlist.archlinux" + +mirror='http://repo.parabolagnulinux.org/$repo/os/$arch' +mirrorarch='http://mirrors.kernel.org/archlinux/$repo/os/$arch' + + +error() { echo -e "Error. $@" > /dev/stderr ; exit 1; } + +if [[ $# == 1 ]] ; then + [[ $1 == -n ]] && UPDATE=0 + [[ $1 == -h ]] && { echo -e "${name}. Show [libre] packages that need to be updated from Arch repositories.\n\nUsage:\nlibredbdiff\t\tInitialize (first run) or update pacman databases\nlibredbdiff -n\t\tPrint results" ; exit 0 ; } +elif [[ $# != 0 ]] ; then + error "Bad arguments. Nothing done." +else + UPDATE=1 +fi + +if (( $UPDATE )) ; then + [[ $EUID != 0 ]] && { error "To initialize $name or update $name pacman databases, the script must be run as root. Nothing done." ; } + + [[ -d "$baseconfpath" && -d "$basedbpath" && -d "$dbpath" && -d "$dbpatharch" && -e "${conffile}" && -e "${conffilearch}" && -e "${mirrorlist}" && -e "${mirrorlist}" ]] || { echo "${name} files are missing. Initializing." ; init=1 ; } + + createdir() { + if [[ ! -e $1 ]] ; then + echo "Creating directory $1" + mkdir "$1" || error "Failed to create directory $1. Exiting." + else + [[ $init ]] && echo "Warning. ${1} already exists. Skipping." + fi + } + createdir "$baseconfpath" + createdir "$basedbpath" + createdir "$dbpath" + createdir "$dbpatharch" + + downloadfile() { + if [[ ! -e $1 ]] ; then + echo "$2" + if wget -q "$3" -O "$1"; then + return 255 + else + error "Failed to download ${1}. Exiting." + fi + else + [[ $init ]] && echo "Warning. ${1} already exists. Skipping." + fi + } + downloadfile "${conffile}" "Downloading Parabola pacman.conf" "https://projects.parabolagnulinux.org/abslibre.git/plain/libre/pacman/pacman.conf.x86_64" + + downloadfile "${conffilearch}" "Downloading Arch pacman.conf" "https://projects.archlinux.org/svntogit/packages.git/plain/pacman/trunk/pacman.conf.x86_64" + if [[ $? == 255 ]] ; then + echo "Setting Arch mirrorlist file in ${conffilearch}" + sed -i "s|/etc/pacman\.d/mirrorlist$|$baseconfpath/mirrorlist.archlinux|" "${conffilearch}" + fi + + setmirror() { + local distro="$1" + local mirror="$2" + local mirrorlist="$3" + [[ $init ]] && [[ $mirror ]] && { + mirrorescaped="${mirror//./\\.}" ; mirrorescaped="${mirrorescaped//\$/\\$}" + echo "Setting ${mirror} as the only enabled ${distro} mirror." && \ + sed -i 's|^#\(Server = '"${mirrorescaped}"'\)$|\1|' "${mirrorlist}" + } + } + + downloadfile "${mirrorlist}" "Downloading Parabola mirrorlist" "https://repo.parabolagnulinux.org/mirrorlist.txt" + if [[ $? == 255 ]] ; then + sed -i 's|^Server|#Server|' "${mirrorlist}" + setmirror "Parabola" "$mirror" "$mirrorlist" + fi + + downloadfile "${mirrorlistarch}" "Downloading Arch mirrorlist" "https://projects.archlinux.org/svntogit/packages.git/plain/pacman-mirrorlist/trunk/mirrorlist" + if [[ $? == 255 ]] ; then + setmirror "Arch" "$mirrorarch" "$mirrorlistarch" + fi + + echo -e "\nSynchronizing $name pacman databases for Parabola" + pacman --config "${conffile}" -b "${dbpath}" -Sy || error "Failed to synchronize pacman database for Parabola. Exiting." + + echo -e "\nSynchronizing $name pacman databases for Arch" + pacman --config "${conffilearch}" -b "${dbpatharch}" -Sy || error "Failed to synchronize pacman database for Arch. Exiting." + + echo + echo "$name pacman databases are updated. $name is ready. Run libredbdiff -n to print results." + exit 0 +else + filenotfound() { + [[ ! -r $1 ]] && { error "Could not read $1. Nothing done.\nIt may be necessary to run libredbdiff without arguments as root to initialize ${name}." ; } + } + filenotfound "${dbpath}" + filenotfound "${dbpatharch}" + filenotfound "${conffile}" + filenotfound "${conffilearch}" + filenotfound "${mirrorlist}" + filenotfound "${mirrorlistarch}" +fi + +unset provides ver verarch +declare -Ax provides ver verarch + +comparepkgs() { + if [[ ${verarch["$pkgname"]} ]] ; then + cmp=$(vercmp ${ver["$pkgname"]} ${verarch["$pkgname"]}) + [[ $cmp -lt 0 ]] && echo "${pkgname} needs update from the Arch package of the same name. Versions: ${ver["$pkgname"]} - ${verarch["$pkgname"]}" + elif [[ ${provides["$pkgname"]} ]] ; then + for provide in ${provides["$pkgname"]} ; do + [[ ${verarch["$provide"]} ]] && { + cmp=$(vercmp "${ver["$pkgname"]}" "${verarch["$provide"]}") + [[ $cmp -lt 0 ]] && echo "${pkgname} may need update from provide candidate ${provide}. Versions: ${ver["$pkgname"]} - ${verarch["$provide"]}" + } + done + else + echo "Could not find candidate to compare ${pkgname}" + fi +} + +while read -a line ; do + verarch["${line[0]}"]="${line[1]}" +done < <(pacman --dbpath "${dbpatharch}" --config "${conffilearch}" -Ss | grep -v '^ ' | awk -F/ '{print $2}') + +expac -b "${dbpath}" -c "${conffile}" -Ss '%r/%n %v %S' | awk -F/ '$1 == "libre" {print $2}' | while read -a line ; do + ver["${line[0]}"]="${line[1]}" + provides[${line[0]}]="${line[@]:2}" + pkgname=${line[0]} + comparepkgs +done -- cgit v1.2.3-2-g168b From 37fbad264b04cdecc015079ca24dc8f09eb77def Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 19 Jun 2014 20:20:11 -0400 Subject: libretools-ize libredbdiff --- src/abslibre-tools/libredbdiff | 280 ++++++++++++++++++++++++----------------- 1 file changed, 164 insertions(+), 116 deletions(-) (limited to 'src/abslibre-tools/libredbdiff') diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff index 67b3245..47e659f 100755 --- a/src/abslibre-tools/libredbdiff +++ b/src/abslibre-tools/libredbdiff @@ -17,125 +17,173 @@ mirrorlistarch="$baseconfpath/mirrorlist.archlinux" mirror='http://repo.parabolagnulinux.org/$repo/os/$arch' mirrorarch='http://mirrors.kernel.org/archlinux/$repo/os/$arch' +. libremessages + +cmd="${0##*/}" + +downloadfile() { + local outfile=$1 + local url=$2 + local mesg=("${@:3}") + if [[ ! -e $outfile ]] ; then + msg "${mesg[@]}" + if wget -q "$url" -O "$outfile"; then + return 255 + else + die "Failed to download %q. Exiting." "$outfile" + fi + elif [[ $init ]]; then + warning "%q already exists. Skipping." "$outfile" + fi +} -error() { echo -e "Error. $@" > /dev/stderr ; exit 1; } - -if [[ $# == 1 ]] ; then - [[ $1 == -n ]] && UPDATE=0 - [[ $1 == -h ]] && { echo -e "${name}. Show [libre] packages that need to be updated from Arch repositories.\n\nUsage:\nlibredbdiff\t\tInitialize (first run) or update pacman databases\nlibredbdiff -n\t\tPrint results" ; exit 0 ; } -elif [[ $# != 0 ]] ; then - error "Bad arguments. Nothing done." -else - UPDATE=1 -fi - -if (( $UPDATE )) ; then - [[ $EUID != 0 ]] && { error "To initialize $name or update $name pacman databases, the script must be run as root. Nothing done." ; } - - [[ -d "$baseconfpath" && -d "$basedbpath" && -d "$dbpath" && -d "$dbpatharch" && -e "${conffile}" && -e "${conffilearch}" && -e "${mirrorlist}" && -e "${mirrorlist}" ]] || { echo "${name} files are missing. Initializing." ; init=1 ; } - - createdir() { - if [[ ! -e $1 ]] ; then - echo "Creating directory $1" - mkdir "$1" || error "Failed to create directory $1. Exiting." - else - [[ $init ]] && echo "Warning. ${1} already exists. Skipping." - fi - } - createdir "$baseconfpath" - createdir "$basedbpath" - createdir "$dbpath" - createdir "$dbpatharch" - - downloadfile() { - if [[ ! -e $1 ]] ; then - echo "$2" - if wget -q "$3" -O "$1"; then - return 255 - else - error "Failed to download ${1}. Exiting." - fi - else - [[ $init ]] && echo "Warning. ${1} already exists. Skipping." - fi - } - downloadfile "${conffile}" "Downloading Parabola pacman.conf" "https://projects.parabolagnulinux.org/abslibre.git/plain/libre/pacman/pacman.conf.x86_64" - - downloadfile "${conffilearch}" "Downloading Arch pacman.conf" "https://projects.archlinux.org/svntogit/packages.git/plain/pacman/trunk/pacman.conf.x86_64" - if [[ $? == 255 ]] ; then - echo "Setting Arch mirrorlist file in ${conffilearch}" - sed -i "s|/etc/pacman\.d/mirrorlist$|$baseconfpath/mirrorlist.archlinux|" "${conffilearch}" - fi - - setmirror() { - local distro="$1" - local mirror="$2" - local mirrorlist="$3" - [[ $init ]] && [[ $mirror ]] && { - mirrorescaped="${mirror//./\\.}" ; mirrorescaped="${mirrorescaped//\$/\\$}" - echo "Setting ${mirror} as the only enabled ${distro} mirror." && \ - sed -i 's|^#\(Server = '"${mirrorescaped}"'\)$|\1|' "${mirrorlist}" - } - } - - downloadfile "${mirrorlist}" "Downloading Parabola mirrorlist" "https://repo.parabolagnulinux.org/mirrorlist.txt" - if [[ $? == 255 ]] ; then - sed -i 's|^Server|#Server|' "${mirrorlist}" - setmirror "Parabola" "$mirror" "$mirrorlist" - fi - - downloadfile "${mirrorlistarch}" "Downloading Arch mirrorlist" "https://projects.archlinux.org/svntogit/packages.git/plain/pacman-mirrorlist/trunk/mirrorlist" - if [[ $? == 255 ]] ; then - setmirror "Arch" "$mirrorarch" "$mirrorlistarch" - fi - - echo -e "\nSynchronizing $name pacman databases for Parabola" - pacman --config "${conffile}" -b "${dbpath}" -Sy || error "Failed to synchronize pacman database for Parabola. Exiting." - - echo -e "\nSynchronizing $name pacman databases for Arch" - pacman --config "${conffilearch}" -b "${dbpatharch}" -Sy || error "Failed to synchronize pacman database for Arch. Exiting." - - echo - echo "$name pacman databases are updated. $name is ready. Run libredbdiff -n to print results." - exit 0 -else - filenotfound() { - [[ ! -r $1 ]] && { error "Could not read $1. Nothing done.\nIt may be necessary to run libredbdiff without arguments as root to initialize ${name}." ; } - } - filenotfound "${dbpath}" - filenotfound "${dbpatharch}" - filenotfound "${conffile}" - filenotfound "${conffilearch}" - filenotfound "${mirrorlist}" - filenotfound "${mirrorlistarch}" -fi - -unset provides ver verarch -declare -Ax provides ver verarch +createdir() { + local dir=$1 + if [[ ! -e $dir ]] ; then + msg "Creating directory %q" "$dir" + mkdir -- "$1" || die "Failed to create directory %q. Exiting." "$dir" + elif [[ $init ]]; then + warning "%q already exists. Skipping." "$dir" + fi +} + +setmirror() { + local distro="$1" + local mirror="$2" + local mirrorlist="$3" + if [[ $init ]] && [[ $mirror ]]; then + mirrorescaped="${mirror//./\\.}" + mirrorescaped="${mirrorescaped//\$/\\$}" + msg "Setting %q as the only enabled %s mirror." "${mirror}" "${distro}" + sed -i 's|^#\(Server = '"${mirrorescaped}"'\)$|\1|' "${mirrorlist}" + fi +} + +filenotfound() { + local file=$1 + if [[ ! -r $1 ]]; then + die "Could not read %q. Nothing done." "$file" + plain "It may be necessary to run %q without arguments as root to initialize %s." "$cmd" "$name" + fi +} comparepkgs() { - if [[ ${verarch["$pkgname"]} ]] ; then - cmp=$(vercmp ${ver["$pkgname"]} ${verarch["$pkgname"]}) - [[ $cmp -lt 0 ]] && echo "${pkgname} needs update from the Arch package of the same name. Versions: ${ver["$pkgname"]} - ${verarch["$pkgname"]}" - elif [[ ${provides["$pkgname"]} ]] ; then - for provide in ${provides["$pkgname"]} ; do - [[ ${verarch["$provide"]} ]] && { - cmp=$(vercmp "${ver["$pkgname"]}" "${verarch["$provide"]}") - [[ $cmp -lt 0 ]] && echo "${pkgname} may need update from provide candidate ${provide}. Versions: ${ver["$pkgname"]} - ${verarch["$provide"]}" - } - done - else - echo "Could not find candidate to compare ${pkgname}" - fi + if [[ ${verarch[$pkgname]} ]] ; then + cmp=$(vercmp "${ver[$pkgname]}" "${verarch[$pkgname]}") + if [[ $cmp -lt 0 ]]; then + msg "%s needs update from the Arch package of the same name. Versions: %s - %s" "${pkgname}" "${ver[$pkgname]}" "${verarch[$pkgname]}" + fi + elif [[ ${provides[$pkgname]} ]]; then + for provide in "${provides[$pkgname]}"; do + if [[ ${verarch["$provide"]} ]]; then + cmp=$(vercmp "${ver[$pkgname]}" "${verarch[$provide]}") + if [[ $cmp -lt 0 ]]; then + msg "%s may need update from provide candidate %s. Versions: %s - %s" "${pkgname}" "${provide}" "${ver[$pkgname]}" "${verarch[$provide]}" + fi + fi + done + else + msg "Could not find candidate to compare %s" "${pkgname}" + fi +} + +usage() { + print "Usage: %q [-n|-h]" "$cmd" + print 'Show [libre] packages that need to be updated from Arch repositories.' + echo + prose "The default mode of operation is to download/update all nescessary + files for comparison, but not compare them. Specify the \`-n\` + flag to not download anything, but to compare already downloaded + files." + echo + print 'Options:' + flag '-n' "Don't update anything, just compare already downloaded files." + flag '-h' 'Show this message' } -while read -a line ; do - verarch["${line[0]}"]="${line[1]}" -done < <(pacman --dbpath "${dbpatharch}" --config "${conffilearch}" -Ss | grep -v '^ ' | awk -F/ '{print $2}') +main() { + local UPDATE=1 + local arg + for arg in "$@"; do + case "$arg" in + -n) UPDATE=0;; + -h) usage; return 0;; + *) + error "Bad arguments. Nothing done." + usage >&2 + return 1 + ;; + esac + done + + if (( $UPDATE )) ; then + if [[ $EUID != 0 ]]; then + die "To initialize $name or update %s pacman databases, the script must be run as root. Nothing done." "$name" + fi + + if ! [[ -d "$baseconfpath" && -d "$basedbpath" && -d "$dbpath" && -d "$dbpatharch" && -e "${conffile}" && -e "${conffilearch}" && -e "${mirrorlist}" && -e "${mirrorlist}" ]]; then + msg "%s files are missing. Initializing." "${name}" + init=1 + fi + + createdir "$baseconfpath" + createdir "$basedbpath" + createdir "$dbpath" + createdir "$dbpatharch" + + downloadfile "${conffile}" "https://projects.parabolagnulinux.org/abslibre.git/plain/libre/pacman/pacman.conf.x86_64" \ + "Downloading Parabola %q" pacman.conf + + downloadfile "${conffilearch}" "https://projects.archlinux.org/svntogit/packages.git/plain/pacman/trunk/pacman.conf.x86_64" \ + "Downloading Arch %q" pacman.conf + if [[ $? == 255 ]] ; then + msg "Setting Arch mirrorlist file in %q" "${conffilearch}" + sed -i "s|/etc/pacman\.d/mirrorlist$|$baseconfpath/mirrorlist.archlinux|" "${conffilearch}" + fi + + downloadfile "${mirrorlist}" "https://repo.parabolagnulinux.org/mirrorlist.txt" \ + "Downloading Parabola %q" mirrorlist + if [[ $? == 255 ]] ; then + sed -i 's|^Server|#Server|' "${mirrorlist}" + setmirror "Parabola" "$mirror" "$mirrorlist" + fi + + downloadfile "${mirrorlistarch}" "https://projects.archlinux.org/svntogit/packages.git/plain/pacman-mirrorlist/trunk/mirrorlist" \ + "Downloading Arch %q" mirrorlist + if [[ $? == 255 ]] ; then + setmirror "Arch" "$mirrorarch" "$mirrorlistarch" + fi + + msg "Synchronizing %s pacman databases for Parabola" "$name" + pacman --config "${conffile}" -b "${dbpath}" -Sy || die "Failed to synchronize pacman database for Parabola. Exiting." + + msg "Synchronizing %s pacman databases for Arch" "$name" + pacman --config "${conffilearch}" -b "${dbpatharch}" -Sy || die "Failed to synchronize pacman database for Arch. Exiting." + + msg "%s pacman databases are updated. %s is ready. Run %q -n to print results." "$name" "$name" "$cmd" + return 0 + else + filenotfound "${dbpath}" + filenotfound "${dbpatharch}" + filenotfound "${conffile}" + filenotfound "${conffilearch}" + filenotfound "${mirrorlist}" + filenotfound "${mirrorlistarch}" + fi + + unset provides ver verarch + declare -gA provides ver verarch + + while read -a line; do + verarch["${line[0]}"]="${line[1]}" + done < <(pacman --dbpath "${dbpatharch}" --config "${conffilearch}" -Ss | grep -v '^ ' | awk -F/ '{print $2}') + + while read -a line; do + ver[${line[0]}]="${line[1]}" + provides[${line[0]}]="${line[@]:2}" + pkgname=${line[0]} + comparepkgs + done < <(expac -b "${dbpath}" -c "${conffile}" -Ss '%r/%n %v %S' | awk -F/ '$1 == "libre" {print $2}') +} -expac -b "${dbpath}" -c "${conffile}" -Ss '%r/%n %v %S' | awk -F/ '$1 == "libre" {print $2}' | while read -a line ; do - ver["${line[0]}"]="${line[1]}" - provides[${line[0]}]="${line[@]:2}" - pkgname=${line[0]} - comparepkgs -done +main "$@" -- cgit v1.2.3-2-g168b From 6ca3d93911463ff646b8eab452d4983342ec72ec Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 19 Jun 2014 20:33:36 -0400 Subject: libredbdiff: Oops, don't hardcode bash location, add copyright header --- src/abslibre-tools/libredbdiff | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/abslibre-tools/libredbdiff') diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff index 47e659f..d2d2505 100755 --- a/src/abslibre-tools/libredbdiff +++ b/src/abslibre-tools/libredbdiff @@ -1,7 +1,24 @@ -#!/bin/bash - +#!/usr/bin/env bash name="Libredbdiff" +# Copyright (C) 2014 Esteban Carnevale +# Copyright (C) 2014 Luke Shumaker +# +# License: GNU GPLv3+ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + baseconfpath="/etc/libredbdiff" basedbpath="/var/lib/libredbdiff" -- cgit v1.2.3-2-g168b