]> git.pld-linux.org Git - packages/poldek.git/blame_incremental - poldek-config.sh
- release 2 (by relup.sh)
[packages/poldek.git] / poldek-config.sh
... / ...
CommitLineData
1#!/bin/sh
2#
3# poldek-config - poldek(1) configuration program
4#
5# poldek-config is an program to provide consistent configurability.
6# It accesses the main configuration file /etc/poldek/poldek.conf(5)
7# in a manner that is easy to use by scripted applications.
8#
9# Author: Elan Ruusamäe <glen@pld-linux.org>
10# Date: 2015-11-13
11
12usage() {
13 cat <<EOF
14Usage: $0 [options] command
15
16Commands:
17
18ignore [PACKAGE] [PACKAGE...]
19 Ignore package list - packages fits given mask will be invisible.
20
21hold [PACKAGE] [PACKAGE...]
22 Prevent package listed from being upgraded if they are already installed.
23
24keep_downloads yes|no
25 Do not remove downloaded packages after its successful installation.
26
27cachedir /var/cache/poldek
28 Cache directory for downloaded files. NOTE that parent directory of cachedir must exist.
29
30EOF
31}
32
33die() {
34 echo >&2 "$PROGRAM: $*"
35 exit 1
36}
37
38option_set() {
39 local option="$1"; shift
40 sed -i -re "/^#?$option\s*=/ s#.*#$option = $*#" "$poldek_conf"
41}
42
43# parse command line args
44parse_arguments() {
45 t=$(getopt -o hc: --long help -n "$PROGRAM" -- "$@")
46 [ $? != 0 ] && exit $?
47 eval set -- "$t"
48
49 while :; do
50 case "$1" in
51 -h|--help)
52 usage
53 exit 0
54 ;;
55 -c)
56 shift
57 poldek_conf=$1
58 ;;
59 --)
60 shift
61 break
62 ;;
63 *)
64 die "Internal error: [$1] not recognized!"
65 ;;
66 esac
67 shift
68 done
69
70 if [ $# = 0 ]; then
71 usage
72 exit 1
73 fi
74
75 command=$1; shift
76 arguments="$*"
77}
78
79main() {
80 parse_arguments "$@"
81
82 case "$command" in
83 ignore|hold)
84 option_set "$command" "$arguments"
85 ;;
86 keep_downloads)
87 option_set "keep downloads" "$arguments"
88 ;;
89 cachedir|cache_dir)
90 option_set "cachedir" "$arguments"
91 ;;
92 *)
93 die "Unknown command: $command"
94 ;;
95 esac
96}
97
98PROGRAM="${0##*/}"
99poldek_conf=/etc/poldek/poldek.conf
100
101main "$@"
This page took 0.043479 seconds and 4 git commands to generate.