source: client/bin/gutenbach-client-config @ 814d4f8

debianmacno-cups
Last change on this file since 814d4f8 was 814d4f8, checked in by Patrick Hurst <phurst@…>, 14 years ago

change gutenbach-client-config usage documentation

now we store it in a here document and also document the -s option
for setting default

  • Property mode set to 100755
File size: 2.5 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 = <<USAGE;
10Usage: gutenbach-client-config [-l|--list|-a|--add|-d|--delete] [QUEUE] [--host=HOST]
11
12        -l, --list              List available queues
13        -a, --add QUEUE         Add a queue (must be used with -h)
14        -d, --delete QUEUE      Delete a queue
15        -s, --set-default QUEUE Set the default queue
16        -h, --host HOST         Hostname for the queue
17USAGE
18
19my $list = 0;
20my $add = "";
21my $delete = "";
22my $host = "";
23my $default = "";
24
25GetOptions ('l|list' => \$list,
26            's|set-default=s' => \$default,
27            'a|add=s' => \$add,
28            'd|delete=s' => \$delete,
29            'h|host=s' => \$host);
30
31my $configpath = "$ENV{'HOME'}/.gutenbach";
32
33if (! -e $configpath) {
34    mkdir "$configpath";
35}
36#set given queue to default
37if($default and !$add and !$delete and !$list) {
38    unless(-e "$configpath/$default") {
39        print "Error: queue '$default' doesn't exist yet...you should add it first.\n";
40        exit 1;
41    }
42    if( -e "$configpath/DEFAULT"){
43        unlink("$configpath/DEFAULT") or die "Couldn't remove config file '$configpath/DEFAULT'";
44    }
45    my $symlink_exists = eval { symlink("",""); 1 };
46    if ($symlink_exists){
47        symlink("$configpath/$default","$configpath/DEFAULT");
48        print "Changed default queue to $default.\n";
49    }
50    else
51    {
52        print "Error creating symlink to $configpath/$default";
53        exit 1;
54    }
55}
56   
57       
58
59# list the existing queues
60elsif ($list and !$add and !$delete and !$default) {
61    my @queues = glob("$configpath/*") or die "Couldn't find configuration files at '$configpath'";
62
63    print "Queue\t\tHost\n";
64    foreach my $q (@queues) {
65        my ($host, $queue);
66
67        if (-r $q) {
68            local $/;
69            my $fh;
70            open $fh, $q;
71            eval <$fh>;
72        }
73
74        print "$queue\t\t$host\n";
75    }
76}
77
78# add a new queue
79elsif (!$list and $add and !$delete) {
80    if (!$host) {
81        print $usage;
82        exit 1;
83    }
84
85    if (-e "$configpath/$add") {
86        print "Warning: queue '$add' already exists\n";
87    }
88
89    open CONFIG, "> $configpath/$add" or die "Couldn't open config file '$configpath/$add'";
90    print CONFIG "\$host = \"$host\";\n";
91    print CONFIG "\$queue = \"$add\";\n";
92    close CONFIG;
93
94    print "Added queue '$add' on host '$host'\n"
95}
96
97# delete an existing queue
98elsif (!$list and !$add and $delete) {
99    if (! -e "$configpath/$delete") {
100        print "Error: queue '$delete' already exists\n";
101        exit 1;
102    }
103
104    unlink("$configpath/$delete") or die "Couldn't remove config file '$configpath/$delete'";
105}
106
107else {
108    print $usage;
109    exit 1;
110}
Note: See TracBrowser for help on using the repository browser.