]>
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() { | |
f3931677 | 45 | t=$(getopt -o hc: --long help -n "$PROGRAM" -- "$@") |
7f66e69d ER |
46 | [ $? != 0 ] && exit $? |
47 | eval set -- "$t" | |
48 | ||
49 | while :; do | |
50 | case "$1" in | |
51 | -h|--help) | |
52 | usage | |
53 | exit 0 | |
54 | ;; | |
f3931677 ER |
55 | -c) |
56 | shift | |
57 | poldek_conf=$1 | |
58 | ;; | |
7f66e69d ER |
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 | ||
79 | main() { | |
80 | parse_arguments "$@" | |
81 | ||
82 | case "$command" in | |
83 | ignore|hold) | |
84 | option_set "$command" "$arguments" | |
85 | ;; | |
5eb4cc67 ER |
86 | keep_downloads) |
87 | option_set "keep downloads" "$arguments" | |
88 | ;; | |
6e7e163c ER |
89 | cachedir|cache_dir) |
90 | option_set "cachedir" "$arguments" | |
91 | ;; | |
7f66e69d ER |
92 | *) |
93 | die "Unknown command: $command" | |
94 | ;; | |
95 | esac | |
96 | } | |
97 | ||
98 | PROGRAM="${0##*/}" | |
99 | poldek_conf=/etc/poldek/poldek.conf | |
100 | ||
101 | main "$@" |