source: gutenbach-client/debian/bin/gutenbach-client-config @ 3b403dc

debianmacno-cupsweb
Last change on this file since 3b403dc was 3b403dc, checked in by Jessica B. Hamrick <jhamrick@…>, 14 years ago

Added gutenbach-client-config, a script to list, add, or delete remote gutenbach queues

  • Property mode set to 100755
File size: 1.7 KB
RevLine 
[3b403dc]1#!/usr/bin/perl
2
3# Written by Jessica Hamrick, (C) 2010
4
5use strict;
6use warnings;
7use Getopt::Long;
8
9my $usage = 
10    "Usage: gutenbach-client-config [-l|--list|-a|--add|-d|--delete] [QUEUE] [--host=HOST]\n" .
11    "\n" .
12    "\t-l, --list\t\tList available queues\n" .
13    "\t-a, --add QUEUE\t\tAdd a queue (must be used with -h)\n" .
14    "\t-d, --delete QUEUE\tDelete a queue)\n" .
15    "\t-h, --host HOST\t\tHostname for the queue\n";
16
17my $list = 0;
18my $add = "";
19my $delete = "";
20my $host = "";
21
22GetOptions ('l|list' => \$list,
23            'a|add=s' => \$add,
24            'd|delete=s' => \$delete,
25            'h|host=s' => \$host);
26
27my $configpath = "$ENV{'HOME'}/.gutenbach";
28
29# list the existing queues
30if ($list and !$add and !$delete) {
31    my @queues = glob("$configpath/*") or die "Couldn't find configuration files at '$configpath'";
32
33    print "Queue\t\tHost\n";
34    foreach my $q (@queues) {
35        my ($host, $queue);
36
37        if (-r $q) {
38            local $/;
39            my $fh;
40            open $fh, $q;
41            eval <$fh>;
42        }
43
44        print "$queue\t\t$host\n";
45    }
46}
47
48# add a new queue
49elsif (!$list and $add and !$delete) {
50    if (!$host) {
51        print $usage;
52        exit 1;
53    }
54
55    if (-e "$configpath/$add") {
56        print "Warning: queue '$add' already exists\n";
57    }
58
59    open CONFIG, "> $configpath/$add" or die "Couldn't open config file '$configpath/$add'";
60    print CONFIG "\$host = \"$host\";\n";
61    print CONFIG "\$queue = \"$add\";\n";
62    close CONFIG;
63
64    print "Added queue '$add' on host '$host'\n"
65}
66
67# delete an existing queue
68elsif (!$list and !$add and $delete) {
69    if (! -e "$configpath/$delete") {
70        print "Error: queue '$delete' already exists\n";
71        exit 1;
72    }
73
74    unlink("$configpath/$delete") or die "Couldn't remove config file '$configpath/$delete'";
75}
76
77else {
78    print $usage;
79    exit 1;
80}
Note: See TracBrowser for help on using the repository browser.