X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=poldek-config.sh;fp=poldek-config.sh;h=795e894883115630d8cfe3ac6a6685b6c39bcd71;hb=c0bfb17fffd4e4288119d89d14b2cfad3e951cfd;hp=0000000000000000000000000000000000000000;hpb=357fa302779d1fb1443f41d9f03c5afa87a937ad;p=packages%2Fpoldek.git diff --git a/poldek-config.sh b/poldek-config.sh new file mode 100755 index 0000000..795e894 --- /dev/null +++ b/poldek-config.sh @@ -0,0 +1,101 @@ +#!/bin/sh +# +# poldek-config - poldek(1) configuration program +# +# poldek-config is an program to provide consistent configurability. +# It accesses the main configuration file /etc/poldek/poldek.conf(5) +# in a manner that is easy to use by scripted applications. +# +# Author: Elan Ruusamäe +# Date: 2015-11-13 + +usage() { + cat <&2 "$PROGRAM: $*" + exit 1 +} + +option_set() { + local option="$1"; shift + sed -i -re "/^#?$option\s*=/ s#.*#$option = $*#" "$poldek_conf" +} + +# parse command line args +parse_arguments() { + t=$(getopt -o hc: --long help -n "$PROGRAM" -- "$@") + [ $? != 0 ] && exit $? + eval set -- "$t" + + while :; do + case "$1" in + -h|--help) + usage + exit 0 + ;; + -c) + shift + poldek_conf=$1 + ;; + --) + shift + break + ;; + *) + die "Internal error: [$1] not recognized!" + ;; + esac + shift + done + + if [ $# = 0 ]; then + usage + exit 1 + fi + + command=$1; shift + arguments="$*" +} + +main() { + parse_arguments "$@" + + case "$command" in + ignore|hold) + option_set "$command" "$arguments" + ;; + keep_downloads) + option_set "keep downloads" "$arguments" + ;; + cachedir|cache_dir) + option_set "cachedir" "$arguments" + ;; + *) + die "Unknown command: $command" + ;; + esac +} + +PROGRAM="${0##*/}" +poldek_conf=/etc/poldek/poldek.conf + +main "$@"