]> git.pld-linux.org Git - packages/poldek.git/blob - poldek-config.sh
Update to 0.32.0
[packages/poldek.git] / poldek-config.sh
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
24 keep_downloads yes|no
25     Do not remove downloaded packages after its successful installation.
26
27 EOF
28 }
29
30 die() {
31         echo >&2 "$PROGRAM: $*"
32         exit 1
33 }
34
35 option_set() {
36         local option="$1"; shift
37         sed -i -re "/^#?$option\s*=/ s/.*/$option = $*/" "$poldek_conf"
38 }
39
40 # parse command line args
41 parse_arguments() {
42         t=$(getopt -o h --long help -n "$PROGRAM" -- "$@")
43         [ $? != 0 ] && exit $?
44         eval set -- "$t"
45
46         while :; do
47                 case "$1" in
48                 -h|--help)
49                         usage
50                         exit 0
51                 ;;
52                 --)
53                         shift
54                         break
55                 ;;
56                 *)
57                         die "Internal error: [$1] not recognized!"
58                 ;;
59                 esac
60                 shift
61         done
62
63         if [ $# = 0 ]; then
64                 usage
65                 exit 1
66         fi
67
68         command=$1; shift
69         arguments="$*"
70 }
71
72 main() {
73         parse_arguments "$@"
74
75         case "$command" in
76                 ignore|hold)
77                         option_set "$command" "$arguments"
78                         ;;
79                 keep_downloads)
80                         option_set "keep downloads" "$arguments"
81                         ;;
82                 *)
83                         die "Unknown command: $command"
84                         ;;
85         esac
86 }
87
88 PROGRAM="${0##*/}"
89 poldek_conf=/etc/poldek/poldek.conf
90
91 main "$@"
This page took 0.038997 seconds and 3 git commands to generate.