diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-08-26 16:23:41 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-08-26 16:27:43 -0400 |
commit | e7edcfde77b0752480db7b4ede5f1a541ee97a88 (patch) | |
tree | e8334af8fc5ee4a2c73a792c4311ff05fe2b1374 /src/librefetch/librefetch-install | |
parent | 3d380700d49dd6faeb793834079724b5c0b93e92 (diff) |
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
Diffstat (limited to 'src/librefetch/librefetch-install')
-rwxr-xr-x | src/librefetch/librefetch-install | 81 |
1 files changed, 81 insertions, 0 deletions
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 <lukeshu@parabola.nu> +# +# 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 <http://www.gnu.org/licenses/>. + +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 "$@" |