]>
Commit | Line | Data |
---|---|---|
7f66e69d ER |
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 | ||
12 | usage() { | |
13 | cat <<EOF | |
14 | Usage: $0 [options] command | |
15 | ||
16 | Commands: | |
17 | ||
18 | ignore [PACKAGE] [PACKAGE...] | |
19 | Ignore package list - packages fits given mask will be invisible. | |
20 | ||
21 | hold [PACKAGE] [PACKAGE...] | |
22 | Prevent package listed from being upgraded if they are already installed. | |
23 | ||
5eb4cc67 ER |
24 | keep_downloads yes|no |
25 | Do not remove downloaded packages after its successful installation. | |
26 | ||
6e7e163c ER |
27 | cachedir /var/cache/poldek |
28 | Cache directory for downloaded files. NOTE that parent directory of cachedir must exist. | |
29 | ||
7f66e69d ER |
30 | EOF |
31 | } | |
32 | ||
33 | die() { | |
34 | echo >&2 "$PROGRAM: $*" | |
35 | exit 1 | |
36 | } | |
37 | ||
38 | option_set() { | |
39 | local option="$1"; shift | |
6e7e163c | 40 | sed -i -re "/^#?$option\s*=/ s#.*#$option = $*#" "$poldek_conf" |
7f66e69d ER |
41 | } |
42 | ||
43 | # parse command line args | |
44 | parse_arguments() { | |
45 | t=$(getopt -o h --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 | --) | |
56 | shift | |
57 | break | |
58 | ;; | |
59 | *) | |
60 | die "Internal error: [$1] not recognized!" | |
61 | ;; | |
62 | esac | |
63 | shift | |
64 | done | |
65 | ||
66 | if [ $# = 0 ]; then | |
67 | usage | |
68 | exit 1 | |
69 | fi | |
70 | ||
71 | command=$1; shift | |
72 | arguments="$*" | |
73 | } | |
74 | ||
75 | main() { | |
76 | parse_arguments "$@" | |
77 | ||
78 | case "$command" in | |
79 | ignore|hold) | |
80 | option_set "$command" "$arguments" | |
81 | ;; | |
5eb4cc67 ER |
82 | keep_downloads) |
83 | option_set "keep downloads" "$arguments" | |
84 | ;; | |
6e7e163c ER |
85 | cachedir|cache_dir) |
86 | option_set "cachedir" "$arguments" | |
87 | ;; | |
7f66e69d ER |
88 | *) |
89 | die "Unknown command: $command" | |
90 | ;; | |
91 | esac | |
92 | } | |
93 | ||
94 | PROGRAM="${0##*/}" | |
95 | poldek_conf=/etc/poldek/poldek.conf | |
96 | ||
97 | main "$@" |