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