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