- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/bin/gutenbach-client-config
r7cdd65d rfc8707b 1 1 #!/usr/bin/perl 2 2 3 # Written by Jessica Hamrick, (C) 2010 3 # This script was largely written by Jessica Hamrick (jhamrick), with 4 # help from Kyle Brogle (broglek) 4 5 5 6 use strict; … … 7 8 use Getopt::Long; 8 9 9 my $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"; 10 # the usage for the program 11 my $usage = <<USAGE; 12 Usage: gutenbach-client-config [options] 16 13 14 -l, --list List available queues 15 -a, --add QUEUE Add a queue (must be used with -h) 16 -d, --delete QUEUE Delete a queue 17 -s, --set-default QUEUE Set the default queue 18 -h, --host HOST Hostname for the queue (must be used with -a) 19 -H, --help Print this message 20 USAGE 21 22 # initialize the variables that will hold the arguments 17 23 my $list = 0; 18 24 my $add = ""; … … 20 26 my $host = ""; 21 27 my $default = ""; 28 my $help = 0; 22 29 30 # get the options from the command line 23 31 GetOptions ('l|list' => \$list, 24 32 's|set-default=s' => \$default, 25 33 'a|add=s' => \$add, 26 34 'd|delete=s' => \$delete, 27 'h|host=s' => \$host); 35 'h|host=s' => \$host, 36 'H|help' => \$help); 28 37 38 # if the -H flag was passed, then print the usage and exit 39 if ($help) { 40 print $usage; 41 exit 0; 42 } 43 44 # set the path where the configuration files live 29 45 my $configpath = "$ENV{'HOME'}/.gutenbach"; 30 46 47 # if the configuration path doens't exist, then make it 31 48 if (! -e $configpath) { 32 49 mkdir "$configpath"; 33 50 } 34 #set given queue to default 51 52 # if the 'default' option was specified, then set given queue to 53 # default 35 54 if($default and !$add and !$delete and !$list) { 55 # if the specified queue doesn't exist, then throw an error 36 56 unless(-e "$configpath/$default") { 37 57 print "Error: queue '$default' doesn't exist yet...you should add it first.\n"; 38 58 exit 1; 39 59 } 60 61 # if there already exists a default, then remove it so we can 62 # replace it with the new default 40 63 if( -e "$configpath/DEFAULT"){ 41 64 unlink("$configpath/DEFAULT") or die "Couldn't remove config file '$configpath/DEFAULT'"; 42 65 } 66 67 # check to make sure we can create symlinks 43 68 my $symlink_exists = eval { symlink("",""); 1 }; 69 70 # if so, then create the symlink and report it 44 71 if ($symlink_exists){ 45 72 symlink("$configpath/$default","$configpath/DEFAULT"); 46 73 print "Changed default queue to $default.\n"; 47 74 } 75 76 # otherwise, throw an error 48 77 else 49 78 { … … 52 81 } 53 82 } 54 55 56 83 57 # list the existing queues84 # if the 'list' option was specified, then list the existing queues 58 85 elsif ($list and !$add and !$delete and !$default) { 86 # get the config files in the configuration path -- these are the queues 59 87 my @queues = glob("$configpath/*") or die "Couldn't find configuration files at '$configpath'"; 60 88 89 # for each of the queues, load the configuration file and print 90 # the queue name and the host it's on 61 91 print "Queue\t\tHost\n"; 62 92 foreach my $q (@queues) { … … 74 104 } 75 105 76 # add a new queue106 # if the 'add' option was specified, then add a new queue 77 107 elsif (!$list and $add and !$delete) { 108 109 # make sure there was a host specified as well (otherwise, we 110 # won't know where to print to) 78 111 if (!$host) { 79 112 print $usage; … … 81 114 } 82 115 116 # if the queue already exists, then print a warning 83 117 if (-e "$configpath/$add") { 84 118 print "Warning: queue '$add' already exists\n"; 85 119 } 86 120 121 # create the configuration file 87 122 open CONFIG, "> $configpath/$add" or die "Couldn't open config file '$configpath/$add'"; 88 123 print CONFIG "\$host = \"$host\";\n"; … … 93 128 } 94 129 95 # delete an existing queue130 # if the 'delete' option was specified, then delete an existing queue 96 131 elsif (!$list and !$add and $delete) { 132 133 # if the queue doesn't exist, then print an error and exit 97 134 if (! -e "$configpath/$delete") { 98 print "Error: queue '$delete' already exists\n";135 print "Error: queue '$delete' does not exist\n"; 99 136 exit 1; 100 137 } 101 138 139 # otherwise, remove the configuration file 102 140 unlink("$configpath/$delete") or die "Couldn't remove config file '$configpath/$delete'"; 103 141 } 104 142 143 # otherwise, it's an unrecognized option, so print the usage and exit 105 144 else { 106 145 print $usage;
Note: See TracChangeset
for help on using the changeset viewer.