From f63d343e40f7f07c7a900cbb7445bbefa0997259 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sat, 22 Oct 2022 15:49:57 +0200 Subject: config: implemented simple config module to store token and settings --- src/lib/config.sh | 27 +++++++++++++++++++++++++++ src/pkgctl.in | 4 ++++ 2 files changed, 31 insertions(+) create mode 100644 src/lib/config.sh (limited to 'src') diff --git a/src/lib/config.sh b/src/lib/config.sh new file mode 100644 index 0000000..5034c6e --- /dev/null +++ b/src/lib/config.sh @@ -0,0 +1,27 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +[[ -z ${DEVTOOLS_INCLUDE_CONFIG_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_CONFIG_SH=1 + +set -e + +readonly XDG_DEVTOOLS_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/devtools" +readonly XDG_DEVTOOLS_GITLAB_CONFIG="${XDG_DEVTOOLS_DIR}/gitlab.conf" + +# default config variables +export GITLAB_TOKEN="" + +load_devtools_config() { + if [[ ! -f "${XDG_DEVTOOLS_GITLAB_CONFIG}" ]]; then + GITLAB_TOKEN="" + return + fi + GITLAB_TOKEN=$(grep GITLAB_TOKEN "${XDG_DEVTOOLS_GITLAB_CONFIG}"|cut -d= -f2|cut -d\" -f2) +} + +save_devtools_config() { + mkdir -p "${XDG_DEVTOOLS_DIR}" + printf 'GITLAB_TOKEN="%s"\n' "${GITLAB_TOKEN}" > "${XDG_DEVTOOLS_GITLAB_CONFIG}" +} diff --git a/src/pkgctl.in b/src/pkgctl.in index 64d9bcd..35305c1 100644 --- a/src/pkgctl.in +++ b/src/pkgctl.in @@ -5,6 +5,8 @@ _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} # shellcheck source=src/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh +# shellcheck source=src/lib/config.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/config.sh set -e @@ -32,6 +34,8 @@ fi export _DEVTOOLS_COMMAND='pkgctl' +load_devtools_config + # command checking while (( $# )); do case $1 in -- cgit v1.2.3-70-g09d2