summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/librefetch/Makefile2
-rwxr-xr-xsrc/librefetch/librefetch-install.in112
-rw-r--r--src/librefetch/librefetch-makepkg.conf.in16
3 files changed, 130 insertions, 0 deletions
diff --git a/src/librefetch/Makefile b/src/librefetch/Makefile
index 2c76089..d797daf 100644
--- a/src/librefetch/Makefile
+++ b/src/librefetch/Makefile
@@ -1 +1,3 @@
include ../../common.mk
+progs = librefetch-install
+confs = librefetch-makepkg.conf
diff --git a/src/librefetch/librefetch-install.in b/src/librefetch/librefetch-install.in
new file mode 100755
index 0000000..13ac876
--- /dev/null
+++ b/src/librefetch/librefetch-install.in
@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+# lirefetch-install: (un)install librefetch to /etc/makepkg.conf
+#
+# Copyright (C) 2013-2015 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# 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/>.
+
+. "$(librelib messages)"
+
+# This line should be installed
+new_code='. @sysconfdir@/libretools/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
+ msg2 "%s: librefetch is already in %q" "${0##*/}" "$(realpath -s "$file")"
+ local line del=false
+ for line in "${old_code[@]}"; do
+ if has_line "$line"; then
+ pre_remove
+ post_install
+ return $?
+ fi
+ done
+ else
+ msg2 "%s: adding librefetch to %1" "${0##*/}" "$(realpath -s "$file")"
+ printf '%s\n' "$new_code" >> "$file"
+ fi
+}
+
+# pre_remove $file
+pre_remove() {
+ local file=$1
+ msg2 "%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 "$line"
+ done
+
+ # Check for the current stuff
+ del_line "$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
+ msg2 "%s: does not exist: %q" "${0##*/}" "$(realpath -s "$file")"
+ fi
+ if [[ ! -w "$file" ]]; then
+ msg2 "%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
new file mode 100644
index 0000000..d6bc93e
--- /dev/null
+++ b/src/librefetch/librefetch-makepkg.conf.in
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash # non-executable, but put this there as a hint to text editors
+
+# This file should be 'source'd by makepkg.conf to enable librefetch
+edit_dlagents() {
+ local dlagent="@bindir@/librefetch -p $(printf %q "${BUILDFILE:-$BUILDSCRIPT}") -- %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