source: gutenbach-client/debian/bin/gutenbach-client-config @ 85a1ac1

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

Create .gutenbach directory if it does not exist
Add more error checking for the gb* scripts

  • Property mode set to 100755
File size: 1.8 KB
Line 
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
29if (! -e $configpath) {
30    mkdir "$configpath";
31}
32
33# list the existing queues
34if ($list and !$add and !$delete) {
35    my @queues = glob("$configpath/*") or die "Couldn't find configuration files at '$configpath'";
36
37    print "Queue\t\tHost\n";
38    foreach my $q (@queues) {
39        my ($host, $queue);
40
41        if (-r $q) {
42            local $/;
43            my $fh;
44            open $fh, $q;
45            eval <$fh>;
46        }
47
48        print "$queue\t\t$host\n";
49    }
50}
51
52# add a new queue
53elsif (!$list and $add and !$delete) {
54    if (!$host) {
55        print $usage;
56        exit 1;
57    }
58
59    if (-e "$configpath/$add") {
60        print "Warning: queue '$add' already exists\n";
61    }
62
63    open CONFIG, "> $configpath/$add" or die "Couldn't open config file '$configpath/$add'";
64    print CONFIG "\$host = \"$host\";\n";
65    print CONFIG "\$queue = \"$add\";\n";
66    close CONFIG;
67
68    print "Added queue '$add' on host '$host'\n"
69}
70
71# delete an existing queue
72elsif (!$list and !$add and $delete) {
73    if (! -e "$configpath/$delete") {
74        print "Error: queue '$delete' already exists\n";
75        exit 1;
76    }
77
78    unlink("$configpath/$delete") or die "Couldn't remove config file '$configpath/$delete'";
79}
80
81else {
82    print $usage;
83    exit 1;
84}
Note: See TracBrowser for help on using the repository browser.