summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2020-07-14 09:45:44 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2020-11-20 22:53:30 -0500
commit3c86b7cd19def6c0b9c41ab8868ff3c07bf742a3 (patch)
tree29cd8e5419d68afb45b13bed691ef030f5e78cfb /src/lib
parentd3a4b74c817fc8aa7fbcc67195ac2af3f1c7d66b (diff)
whitespace
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/conf.sh.in340
-rwxr-xr-xsrc/lib/libremessages8
2 files changed, 174 insertions, 174 deletions
diff --git a/src/lib/conf.sh.in b/src/lib/conf.sh.in
index 25afa1d..603a28c 100644
--- a/src/lib/conf.sh.in
+++ b/src/lib/conf.sh.in
@@ -19,19 +19,19 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [[ "$(id -u "${SUDO_USER:-root}")" == 0 ]]; then
- unset SUDO_USER
+ unset SUDO_USER
fi
LIBREUSER="${SUDO_USER:-$USER}"
if [[ $LIBREUSER == "$USER" ]]; then
- LIBREHOME=$HOME
+ LIBREHOME=$HOME
else
- eval "LIBREHOME=~$LIBREUSER"
+ eval "LIBREHOME=~$LIBREUSER"
fi
if [[ -z ${XDG_CONFIG_HOME:-} ]]; then
- export XDG_CONFIG_HOME="${LIBREHOME}/.config"
+ export XDG_CONFIG_HOME="${LIBREHOME}/.config"
fi
if [[ -z ${XDG_CACHE_HOME:-} ]]; then
- export XDG_CACHE_HOME="${LIBREHOME}/.cache"
+ export XDG_CACHE_HOME="${LIBREHOME}/.cache"
fi
# Low-level generic functions ##################################################
@@ -40,62 +40,62 @@ fi
# Lists the configuration files to be considered for $slug.
# Later files should take precedence over earlier files.
list_files() {
- local slug=$1
- local sysconfdir=${_librelib_conf_sh_sysconfdir:-@sysconfdir@}
- local pkgconfdir=${_librelib_conf_sh_pkgconfdir:-@pkgconfdir@}
- case $slug in
- abs)
- echo "${sysconfdir}/$slug.conf"
- echo "$LIBREHOME/.$slug.conf"
- ;;
- makepkg)
- local manual="${MAKEPKG_CONF:-}"
- local system="${sysconfdir}/$slug.conf"
- local olduser="$LIBREHOME/.$slug.conf"
- local newuser="$XDG_CONFIG_HOME/pacman/$slug.conf"
- if [[ "$manual" != "$system" && -r "$manual" ]]; then
- # Manually-specified file
- echo "$manual"
- else
- # Normal file lookup
- echo "$system"
- if [[ -r "$olduser" && ! -r "$newuser" ]]; then
- echo "$olduser"
- else
- echo "$newuser"
- fi
- fi
- ;;
- libretools)
- echo "${sysconfdir}/$slug.conf"
- echo "$XDG_CONFIG_HOME/libretools/$slug.conf"
- ;;
- *)
- echo "${pkgconfdir}/$slug.conf"
- echo "$XDG_CONFIG_HOME/libretools/$slug.conf"
- ;;
- esac
+ local slug=$1
+ local sysconfdir=${_librelib_conf_sh_sysconfdir:-@sysconfdir@}
+ local pkgconfdir=${_librelib_conf_sh_pkgconfdir:-@pkgconfdir@}
+ case $slug in
+ abs)
+ echo "${sysconfdir}/$slug.conf"
+ echo "$LIBREHOME/.$slug.conf"
+ ;;
+ makepkg)
+ local manual="${MAKEPKG_CONF:-}"
+ local system="${sysconfdir}/$slug.conf"
+ local olduser="$LIBREHOME/.$slug.conf"
+ local newuser="$XDG_CONFIG_HOME/pacman/$slug.conf"
+ if [[ "$manual" != "$system" && -r "$manual" ]]; then
+ # Manually-specified file
+ echo "$manual"
+ else
+ # Normal file lookup
+ echo "$system"
+ if [[ -r "$olduser" && ! -r "$newuser" ]]; then
+ echo "$olduser"
+ else
+ echo "$newuser"
+ fi
+ fi
+ ;;
+ libretools)
+ echo "${sysconfdir}/$slug.conf"
+ echo "$XDG_CONFIG_HOME/libretools/$slug.conf"
+ ;;
+ *)
+ echo "${pkgconfdir}/$slug.conf"
+ echo "$XDG_CONFIG_HOME/libretools/$slug.conf"
+ ;;
+ esac
}
# Usage: list_envvars $slug
# Lists the environmental variables that take precedence over the configuration
# files for $slug.
list_envvars() {
- local slug=$1
- case $slug in
- makepkg)
- printf '%s\n' \
- PKGDEST SRCDEST SRCPKGDEST LOGDEST \
- BUILDDIR \
- PKGEXT SRCEXT \
- GPGKEY PACKAGER \
- CARCH
- ;;
- libretools)
- printf '%s\n' DIFFPROG
- ;;
- *) :;;
- esac
+ local slug=$1
+ case $slug in
+ makepkg)
+ printf '%s\n' \
+ PKGDEST SRCDEST SRCPKGDEST LOGDEST \
+ BUILDDIR \
+ PKGEXT SRCEXT \
+ GPGKEY PACKAGER \
+ CARCH
+ ;;
+ libretools)
+ printf '%s\n' DIFFPROG
+ ;;
+ *) :;;
+ esac
}
# High-level generic functions #################################################
@@ -105,137 +105,137 @@ list_envvars() {
# Loads the configuration files for $slug in the proper order, and
# optionally verify that certain variables are set.
load_conf() {
- [[ $1 = /* || $1 = *.conf ]] || libremessages panic || exit 1 # $EXIT_FAILURE
- local files envvars
- if [[ $1 = /* ]]; then
- files=("$1")
- envvars=()
- shift
- else
- local slug=${1%.conf}
- shift
- readarray -t files < <(list_files "$slug")
- readarray -t envvars < <(list_envvars "$slug")
- fi
- local var file
-
- # Save the existing versions at _VARNAME
- for var in "${envvars[@]}"; do
- [[ -n ${!var:-} ]] && eval "local _$var=\${$var}"
- done
-
- # Load the files
- for file in "${files[@]}"; do
- if [[ -r $file ]]; then
- source "$file" || return 6 # $EXIT_NOTCONFIGURED
- fi
- done
-
- # Restore the _SAVED versions
- for var in "${envvars[@]}"; do
- eval "$var=\${_$var:-\${$var:-}}"
- done
-
- # Verify that the variables we need were set
- declare -i ret=0 # $EXIT_SUCCESS
- for var in "$@"; do
- if [[ -z ${!var:-} ]]; then
- if [[ ${#files[@]} -gt 1 ]]; then
- libremessages _l print "Configure '%s' in one of:" "$var"
- printf ' -> %s\n' "${files[@]}"
- else
- libremessages _l print "Configure '%s' in '%s'" "$var" "${files[0]}"
- fi
- ret=6 # $EXIT_NOTCONFIGURED
- fi
- done >&2
- return $ret
+ [[ $1 = /* || $1 = *.conf ]] || libremessages panic || exit 1 # $EXIT_FAILURE
+ local files envvars
+ if [[ $1 = /* ]]; then
+ files=("$1")
+ envvars=()
+ shift
+ else
+ local slug=${1%.conf}
+ shift
+ readarray -t files < <(list_files "$slug")
+ readarray -t envvars < <(list_envvars "$slug")
+ fi
+ local var file
+
+ # Save the existing versions at _VARNAME
+ for var in "${envvars[@]}"; do
+ [[ -n ${!var:-} ]] && eval "local _$var=\${$var}"
+ done
+
+ # Load the files
+ for file in "${files[@]}"; do
+ if [[ -r $file ]]; then
+ source "$file" || return 6 # $EXIT_NOTCONFIGURED
+ fi
+ done
+
+ # Restore the _SAVED versions
+ for var in "${envvars[@]}"; do
+ eval "$var=\${_$var:-\${$var:-}}"
+ done
+
+ # Verify that the variables we need were set
+ declare -i ret=0 # $EXIT_SUCCESS
+ for var in "$@"; do
+ if [[ -z ${!var:-} ]]; then
+ if [[ ${#files[@]} -gt 1 ]]; then
+ libremessages _l print "Configure '%s' in one of:" "$var"
+ printf ' -> %s\n' "${files[@]}"
+ else
+ libremessages _l print "Configure '%s' in '%s'" "$var" "${files[0]}"
+ fi
+ ret=6 # $EXIT_NOTCONFIGURED
+ fi
+ done >&2
+ return $ret
}
# Usage: get_var <slug> <var_name> <default_value>
# Does not work with arrays
get_var() (
- set +euE
- local slug=$1
- local setting=$2
- local default=$3
- load_conf "$slug.conf"
- printf '%s' "${!setting:-${default}}"
+ set +euE
+ local slug=$1
+ local setting=$2
+ local default=$3
+ load_conf "$slug.conf"
+ printf '%s' "${!setting:-${default}}"
)
# Usage: set_var <slug> <var_name> <value>
# Does not work with arrays
set_var() {
- local slug=$1
- local key=$2
- local val=$3
- local file
- while read -r file; do
- if [[ -w $file ]]; then
- sed -i "/^\s*$key=/d" "$file"
- printf '%s=%q\n' "$key" "$val" >> "$file"
- return 0 # $EXIT_SUCCESS
- fi
- done < <(list_files "$slug"|tac)
- return 1 # $EXIT_FAILURE
+ local slug=$1
+ local key=$2
+ local val=$3
+ local file
+ while read -r file; do
+ if [[ -w $file ]]; then
+ sed -i "/^\s*$key=/d" "$file"
+ printf '%s=%q\n' "$key" "$val" >> "$file"
+ return 0 # $EXIT_SUCCESS
+ fi
+ done < <(list_files "$slug"|tac)
+ return 1 # $EXIT_FAILURE
}
# PKGBUILD (not configuration, per se) #########################################
unset_PKGBUILD() {
- # This routine is based primarily off of the PKGBUILD(5) man-page,
- # version 4.2.0, dated 2014-12-31
-
- # This is kinda weird, but everything is more readable with
- # this as a utility function, but I didn't want to introduce a
- # new global function, so I just introduced it with the name
- # of a function that we get to unset anyway. So it can't
- # clash with anything!
- mksource() {
- # For each arg, `unset -v` all variables matching ${arg} and ${arg}_*
- local v
- for v in "$@"; do
- # shellcheck disable=228
- unset -v "$v" $(declare -p|sed -rn "s/^declare -\S+ (${v}_[a-zA-Z0-9_]*)=.*/\1/p")
- done
- }
-
- # This line is taken from the makepkg source
- local known_hash_algos=('md5' 'sha1' 'sha224' 'sha256' 'sha384' 'sha512')
-
- # From the "OPTIONS AND DIRECTIVES" section (in order of mention)
- unset -v pkgname pkgver
- unset -f pkgver
- unset -v pkgrel pkgdesc epoch url license install changelog
-
- mksource source
- unset -v validpgpkeys noextract
- local sums=("${known_hash_algos[@]/%/sums}")
- mksource "${sums[@]}"
-
- unset -v groups arch backup
- mksource depends makedepends checkdepends optdepends
- mksource conflicts provides replaces
- unset -v options
-
- # From the "PACKAGING FUNCTIONS" section (in order of mention)
- unset -f package prepare build check
-
- # From the "PACKAGE SPLITTING" section
- unset -f $(declare -f|sed -n 's/^\(package_\S*\) ()\s*$/\1/p')
- unset -v pkgbase
-
- # These are used by the `librefetch` program
- unset -v mksource mknoextract "${sums[@]/#/mk}"
- unset -v mkdepends
- unset -f mksource
+ # This routine is based primarily off of the PKGBUILD(5) man-page,
+ # version 4.2.0, dated 2014-12-31
+
+ # This is kinda weird, but everything is more readable with
+ # this as a utility function, but I didn't want to introduce a
+ # new global function, so I just introduced it with the name
+ # of a function that we get to unset anyway. So it can't
+ # clash with anything!
+ mksource() {
+ # For each arg, `unset -v` all variables matching ${arg} and ${arg}_*
+ local v
+ for v in "$@"; do
+ # shellcheck disable=228
+ unset -v "$v" $(declare -p|sed -rn "s/^declare -\S+ (${v}_[a-zA-Z0-9_]*)=.*/\1/p")
+ done
+ }
+
+ # This line is taken from the makepkg source
+ local known_hash_algos=('md5' 'sha1' 'sha224' 'sha256' 'sha384' 'sha512')
+
+ # From the "OPTIONS AND DIRECTIVES" section (in order of mention)
+ unset -v pkgname pkgver
+ unset -f pkgver
+ unset -v pkgrel pkgdesc epoch url license install changelog
+
+ mksource source
+ unset -v validpgpkeys noextract
+ local sums=("${known_hash_algos[@]/%/sums}")
+ mksource "${sums[@]}"
+
+ unset -v groups arch backup
+ mksource depends makedepends checkdepends optdepends
+ mksource conflicts provides replaces
+ unset -v options
+
+ # From the "PACKAGING FUNCTIONS" section (in order of mention)
+ unset -f package prepare build check
+
+ # From the "PACKAGE SPLITTING" section
+ unset -f $(declare -f|sed -n 's/^\(package_\S*\) ()\s*$/\1/p')
+ unset -v pkgbase
+
+ # These are used by the `librefetch` program
+ unset -v mksource mknoextract "${sums[@]/#/mk}"
+ unset -v mkdepends
+ unset -f mksource
}
load_PKGBUILD() {
- local file=${1:-./PKGBUILD}
- unset_PKGBUILD
- # shellcheck disable=2034
- CARCH="$(get_var makepkg CARCH "$(uname -m)")"
- source "$file"
- pkgbase=${pkgbase:-${pkgname[0]}}
+ local file=${1:-./PKGBUILD}
+ unset_PKGBUILD
+ # shellcheck disable=2034
+ CARCH="$(get_var makepkg CARCH "$(uname -m)")"
+ source "$file"
+ pkgbase=${pkgbase:-${pkgname[0]}}
}
diff --git a/src/lib/libremessages b/src/lib/libremessages
index 43779af..19ceece 100755
--- a/src/lib/libremessages
+++ b/src/lib/libremessages
@@ -18,9 +18,9 @@
if [[ "${0##*/}" != libremessages ]]; then
- source "$(librelib messages)"
+ source "$(librelib messages)"
else
- set -euE
- source "$(librelib messages)"
- "$@"
+ set -euE
+ source "$(librelib messages)"
+ "$@"
fi