summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile2
-rw-r--r--src/lib/conf.sh121
2 files changed, 123 insertions, 0 deletions
diff --git a/src/lib/Makefile b/src/lib/Makefile
new file mode 100644
index 0000000..0c69ba3
--- /dev/null
+++ b/src/lib/Makefile
@@ -0,0 +1,2 @@
+libre_datadir=$(datadir)/libretools
+include ../../common.mk
diff --git a/src/lib/conf.sh b/src/lib/conf.sh
new file mode 100644
index 0000000..43a30af
--- /dev/null
+++ b/src/lib/conf.sh
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+INCLUDE_CONF_SH=conf.sh
+
+LIBREUSER="${SUDO_USER:-$USER}"
+LIBREHOME="$(eval echo ~$LIBREUSER)"
+if [[ -z ${XDG_CONFIG_HOME:-} ]]; then
+ export XDG_CONFIG_HOME="${LIBREHOME}/.config"
+fi
+
+# Generic functions ############################################################
+
+get_files() {
+ local slug=$1
+ case $slug in
+ makepkg.conf)
+ if [[ $MAKEPKG_CONF != /etc/$slug && -r $MAKEPKG_CONF ]]; then
+ echo "$MAKEPKG_CONF"
+ else
+ echo /etc/$slug
+ echo "$LIBREHOME/.$slug"
+ fi
+ ;;
+ libretools.conf)
+ echo /etc/$slug
+ echo "$XDG_CONFIG_HOME/libretools/$slug"
+ ;;
+ *.conf)
+ echo /etc/libretools.d/$slug
+ echo "$XDG_CONFIG_HOME/libretools/$slug"
+ ;;
+ esac
+}
+
+load_files() {
+ for file in $(get_files $1.conf); do
+ if [[ -r $file ]]; then
+ . "$file"
+ fi
+ done
+}
+
+check_vars() {
+ local slug=$1
+ shift
+ local ret=0
+ for VAR in "$@"; do
+ if [[ -z ${!VAR} ]]; then
+ if [[ $(get_files $slug|wc -l) > 1 ]]; then
+ echo "Configure '$VAR' in one of:"
+ get_files $slug | sed 's/./ -> &/'
+ else
+ echo "Configure '$VAR' in $(get_files $slug)"
+ fi
+ ret=1
+ fi >>/dev/stderr
+ done
+ if [[ $ret != 0 ]]; then
+ return 1
+ fi
+}
+
+# makepkg configuration ########################################################
+
+[[ -n ${MAKEPKG_CONF:-} ]] || MAKEPKG_CONF=/etc/makepkg.conf
+
+load_conf_makepkg() {
+ load_files makepkg
+}
+
+get_conf_makepkg() (
+ set +euE
+ local setting=$1
+ local default=$2
+ load_conf_makepkg
+ printf '%s\n' "${!setting:-${default}}"
+)
+
+set_conf_makepkg() {
+ local key=$1
+ local val=$2
+ for file in `get_files makepkg.conf|tac`; do
+ if [[ -w $file ]]; then
+ sed -i "/^\s*$key=/d" "$file"
+ echo "$key='$val'" >> "$file"
+ return 0
+ fi
+ done
+ return 1
+}
+
+
+# libretools configuration #####################################################
+
+check_conf_libretools() {
+ check_vars libretools.conf \
+ PARABOLAHOST LIBREDESTDIR BLACKLIST WORKDIR REPOS ARCHES \
+ ABSLIBREGIT DIFFTOOL FULLBUILDCMD SIGEXT SIGID
+}
+
+load_conf_libretools() {
+ load_files libretools
+ check_conf_libretools
+}
+
+load_conf_libretools_chroot() {
+ load_files chroot
+ # Exclude CHROOTEXTRAPKG from the checks because an empty value is valid
+ if [[ -f /.arch-chroot ]]; then
+ # inside of a chroot, only CHROOTEXTRAPKG needs to be set, but
+ # as stated above, we don't check for it.
+ :
+ else
+ check_vars chroot.conf CHROOTDIR CHROOT
+ fi
+}
+
+load_conf_libretools_librefetch() {
+ load_files librefetch
+ check_vars librefetch.conf MIRROR DOWNLOADER
+}