From e7edcfde77b0752480db7b4ede5f1a541ee97a88 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 26 Aug 2018 16:23:41 -0400 Subject: librefetch: Drop a file in /etc/makepkg.d/ rather than editing makepkg.conf The librefetch-install program will stick around for a while (1 year; 2019-08-26) so that it can be used from a post_upgrade hook to remove the old edits, in order to seamlessly migrate people. https://git.parabola.nu/abslibre.git/commit/?id=73982c5ad7057ce2fdec669d962aec6c9caf28c8 --- po/es/libretools.po | 30 +++----- src/librefetch/.gitignore | 3 +- src/librefetch/Makefile | 11 ++- src/librefetch/librefetch-install | 81 +++++++++++++++++++++ src/librefetch/librefetch-install.in | 114 ------------------------------ src/librefetch/librefetch-makepkg.conf.in | 16 ----- src/librefetch/makepkg-librefetch.conf.in | 16 +++++ 7 files changed, 115 insertions(+), 156 deletions(-) create mode 100755 src/librefetch/librefetch-install delete mode 100644 src/librefetch/librefetch-install.in delete mode 100644 src/librefetch/librefetch-makepkg.conf.in create mode 100644 src/librefetch/makepkg-librefetch.conf.in diff --git a/po/es/libretools.po b/po/es/libretools.po index cc36588..b0ee284 100644 --- a/po/es/libretools.po +++ b/po/es/libretools.po @@ -1508,35 +1508,23 @@ msgstr "%: se encontraron argumentos no-opciones extras: %s" msgid "%s: %d non-flag arguments found, expected 1 or 2: %s" msgstr "%s: %d argumentos no-opciones encontrados, esperado 1 o 2: %s" -#: src/librefetch/librefetch-install:58 -msgid ":: %s: librefetch is already in %q" -msgstr ":: %s: librefetch ya está en %q" - -#: src/librefetch/librefetch-install:62 -msgid ":: %s: ... but it's an old version" -msgstr ":: %s: ... pero es una versión antigua" - -#: src/librefetch/librefetch-install:69 -msgid ":: %s: adding librefetch to %q" -msgstr ":: %s: agregando librefetch a %q" - -#: src/librefetch/librefetch-install:77 +#: src/librefetch/librefetch-install:49 msgid ":: %s: removing librefetch from %q" msgstr ":: %s: quitando librefetch de %q" -#: src/librefetch/librefetch-install:91 -msgid "Usage: %s [install|remove] MAKEPKG_CONF_FILE" -msgstr "Uso: %s [install|remove] ARCHIVO_CONF_DE_MAKEPKG" +#: src/librefetch/librefetch-install:59 +msgid "Usage: %s remove MAKEPKG_CONF_FILE" +msgstr "Uso: %s remove ARCHIVO_CONF_DE_MAKEPKG" -#: src/librefetch/librefetch-install:92 -msgid "Adds or removes librefetch to/from makepkg.conf:DLAGENTS" -msgstr "Agrega o quita librefetch a/de makepkg.conf:DLAGENTS" +#: src/librefetch/librefetch-install:60 +msgid "Removes librefetch to/from makepkg.conf:DLAGENTS" +msgstr "Quita librefetch a/de makepkg.conf:DLAGENTS" -#: src/librefetch/librefetch-install:102 +#: src/librefetch/librefetch-install:70 msgid "%s: does not exist: %q" msgstr "%s: no existe: %q" -#: src/librefetch/librefetch-install:105 +#: src/librefetch/librefetch-install:73 msgid "%s: cannot write to file: %q" msgstr "%s: no se puede escribir al archivo: %q" diff --git a/src/librefetch/.gitignore b/src/librefetch/.gitignore index d34a2fc..369c107 100644 --- a/src/librefetch/.gitignore +++ b/src/librefetch/.gitignore @@ -1,2 +1 @@ -librefetch-install -librefetch-makepkg.conf +/makepkg-librefetch.conf diff --git a/src/librefetch/Makefile b/src/librefetch/Makefile index f11f0ed..cee8ca8 100644 --- a/src/librefetch/Makefile +++ b/src/librefetch/Makefile @@ -2,12 +2,17 @@ include $(dir $(lastword $(MAKEFILE_LIST)))/../../config.mk include $(topsrcdir)/build-aux/Makefile.head.mk libretools.out.bins = librefetch librefetch-install -libretools.out.confs = $(libretools.src.conf) librefetch-makepkg.conf +libretools.out.confs = $(libretools.src.conf) libretools.out.libexecs = $(filter librefetchdir/%,$(libretools.src.exec)) libretools.out.libs = $(filter-out $(libretools.out.libexecs),$(filter librefetchdir/%,$(libretools.src.git))) libretools.pots = $(libretools.out.bins) +libretools.out = makepkg-librefetch.conf -$(outdir)/librefetch-install: $(var.)pkgconfdir -$(outdir)/librefetch-makepkg.conf: $(var.)bindir +files.sys.all += /etc/makepkg.d/librefetch.conf + +$(outdir)/makepkg-librefetch.conf: $(var.)bindir + +$(DESTDIR)/etc/makepkg.d/librefetch.conf: $(outdir)/makepkg-librefetch.conf + install -T -Dm644 '$<' '$@' include $(topsrcdir)/build-aux/Makefile.tail.mk diff --git a/src/librefetch/librefetch-install b/src/librefetch/librefetch-install new file mode 100755 index 0000000..2cdb014 --- /dev/null +++ b/src/librefetch/librefetch-install @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +# lirefetch-install: (un)install librefetch to /etc/makepkg.conf +# +# Copyright (C) 2013-2015, 2017 Luke Shumaker +# +# License: GNU GPLv3+ +# +# This file is part of Parabola. +# +# Parabola 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. +# +# Parabola 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 Parabola. If not, see . + +set -ueE +. "$(librelib messages)" + +# These lines were installed by previous versions of this script +old_code=( + '# The following line is added by the libretools post_install script' + '[[ ! -x /usr/bin/librefetch ]] || DLAGENTS+=("libre::/usr/bin/librefetch -p \"\$BUILDFILE\" %u %o")' + '[[ ! -x /usr/bin/librefetch ]] || DLAGENTS+=({https,libre}"::/usr/bin/librefetch -p \"\$BUILDFILE\" -- %u %o")' + 'DLAGENTS+=({https,libre}"::/usr/bin/librefetch -p $(printf "%q" "$BUILDFILE") -- %u %o")' + 'DLAGENTS+=({https,libre}'\''::/usr/bin/librefetch -p "$BUILDFILE" -- %u %o'\'')' + '. /etc/libretools.d/librefetch-makepkg.conf # This line was added by librefetch-install' +) + +# del_line $file $line +del_line() { + local file=$1 + local line=$2 + local lineno=($(grep -Fxn -- "$line" "$file" | cut -d: -f1)) + if [[ "${#lineno[@]}" -gt 0 ]]; then + sed -i "$(printf '%dd;' "${lineno[@]}")" "$file" + fi +} + +# pre_remove $file +pre_remove() { + local file=$1 + print ":: %s: removing librefetch from %q" "${0##*/}" "$(realpath -s "$file")" + + sed -ri 's/^#(.*) # commented out by the libretools post_install script/\1/' "$file" + local line + for line in "${old_code[@]}"; do + del_line "$file" "$line" + done +} + +usage() { + print "Usage: %s remove MAKEPKG_CONF_FILE" "${0##*/}" + print "Removes librefetch to/from makepkg.conf:DLAGENTS" +} + +main() { + if [[ $# != 2 ]]; then + usage >&2 + return 1 + fi + local file=$2 + if [[ ! -f "$file" ]]; then + error "%s: does not exist: %q" "${0##*/}" "$(realpath -s "$file")" + fi + if [[ ! -w "$file" ]]; then + error "%s: cannot write to file: %q" "${0##*/}" "$(realpath -s "$file")" + fi + case "$1" in + remove) pre_remove "$file";; + *) usage >&2; return 1;; + esac +} + +main "$@" diff --git a/src/librefetch/librefetch-install.in b/src/librefetch/librefetch-install.in deleted file mode 100644 index e4756f4..0000000 --- a/src/librefetch/librefetch-install.in +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env bash -# lirefetch-install: (un)install librefetch to /etc/makepkg.conf -# -# Copyright (C) 2013-2015, 2017 Luke Shumaker -# -# License: GNU GPLv3+ -# -# This file is part of Parabola. -# -# Parabola 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. -# -# Parabola 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 Parabola. If not, see . - -set -ueE -. "$(librelib messages)" - -# This line should be installed -new_code='. @pkgconfdir@/librefetch-makepkg.conf # This line was added by librefetch-install' - -# These lines were installed by previous versions of this script -old_code=( - '# The following line is added by the libretools post_install script' - '[[ ! -x /usr/bin/librefetch ]] || DLAGENTS+=("libre::/usr/bin/librefetch -p \"\$BUILDFILE\" %u %o")' - '[[ ! -x /usr/bin/librefetch ]] || DLAGENTS+=({https,libre}"::/usr/bin/librefetch -p \"\$BUILDFILE\" -- %u %o")' - 'DLAGENTS+=({https,libre}"::/usr/bin/librefetch -p $(printf "%q" "$BUILDFILE") -- %u %o")' - 'DLAGENTS+=({https,libre}'\''::/usr/bin/librefetch -p "$BUILDFILE" -- %u %o'\'')' -) - -# has_line $file $line -has_line() { - local file=$1 - local line=$2 - grep -Fxq -- "$line" "$file" -} -# del_line $file $line -del_line() { - local file=$1 - local line=$2 - local lineno=($(grep -Fxn -- "$line" "$file" | cut -d: -f1)) - if [[ "${#lineno[@]}" -gt 0 ]]; then - sed -i "$(printf '%dd;' "${lineno[@]}")" "$file" - fi -} - -# post_install $file -post_install() { - local file=$1 - if grep -q 'librefetch' "$file"; then - print ":: %s: librefetch is already in %q" "${0##*/}" "$(realpath -s "$file")" - local line - for line in "${old_code[@]}"; do - if has_line "$file" "$line"; then - print ":: %s: ... but it's an old version" "${0##*/}" - pre_remove "$file" - post_install "$file" - return - fi - done - else - print ":: %s: adding librefetch to %q" "${0##*/}" "$(realpath -s "$file")" - printf '%s\n' "$new_code" >> "$file" - fi -} - -# pre_remove $file -pre_remove() { - local file=$1 - print ":: %s: removing librefetch from %q" "${0##*/}" "$(realpath -s "$file")" - - # Check for the old stuff - sed -ri 's/^#(.*) # commented out by the libretools post_install script/\1/' "$file" - local line - for line in "${old_code[@]}"; do - del_line "$file" "$line" - done - - # Check for the current stuff - del_line "$file" "$new_code" -} - -usage() { - print "Usage: %s [install|remove] MAKEPKG_CONF_FILE" "${0##*/}" - print "Adds or removes librefetch to/from makepkg.conf:DLAGENTS" -} - -main() { - if [[ $# != 2 ]]; then - usage >&2 - return 1 - fi - local file=$2 - if [[ ! -f "$file" ]]; then - error "%s: does not exist: %q" "${0##*/}" "$(realpath -s "$file")" - fi - if [[ ! -w "$file" ]]; then - error "%s: cannot write to file: %q" "${0##*/}" "$(realpath -s "$file")" - fi - case "$1" in - install) post_install "$file";; - remove) pre_remove "$file";; - *) usage >&2; return 1;; - esac -} - -main "$@" diff --git a/src/librefetch/librefetch-makepkg.conf.in b/src/librefetch/librefetch-makepkg.conf.in deleted file mode 100644 index 723bc15..0000000 --- a/src/librefetch/librefetch-makepkg.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -#!/hint/bash - -# This file should be 'source'd by makepkg.conf to enable librefetch -edit_dlagents() { - local dlagent="@bindir@/librefetch -p $(printf %q "$(realpath -Lm "${BUILDFILE:-${BUILDSCRIPT:-PKGBUILD}}")") -- %u %o" - - local i - for i in "${!DLAGENTS[@]}"; do - if [[ "${DLAGENTS[$i]}" = https::* ]]; then - DLAGENTS[$i]="https::$dlagent" - fi - done - DLAGENTS+=("libre::$dlagent") -} -edit_dlagents -unset -f edit_dlagents diff --git a/src/librefetch/makepkg-librefetch.conf.in b/src/librefetch/makepkg-librefetch.conf.in new file mode 100644 index 0000000..723bc15 --- /dev/null +++ b/src/librefetch/makepkg-librefetch.conf.in @@ -0,0 +1,16 @@ +#!/hint/bash + +# This file should be 'source'd by makepkg.conf to enable librefetch +edit_dlagents() { + local dlagent="@bindir@/librefetch -p $(printf %q "$(realpath -Lm "${BUILDFILE:-${BUILDSCRIPT:-PKGBUILD}}")") -- %u %o" + + local i + for i in "${!DLAGENTS[@]}"; do + if [[ "${DLAGENTS[$i]}" = https::* ]]; then + DLAGENTS[$i]="https::$dlagent" + fi + done + DLAGENTS+=("libre::$dlagent") +} +edit_dlagents +unset -f edit_dlagents -- cgit v1.2.2