9 my $opt_smb_conf = undef;
13 my $result = GetOptions(
14 'help|h|?' => \$opt_help,
15 'smb_conf|s=s' => \$opt_smb_conf,
17 'delete|d' => \$opt_delete
24 print $msg."\n\n" if defined($msg);
28 --help|-h|-? Show this help.
30 --smb_conf|-s <path> Path of the 'smb.conf' file.
32 --add|-a 'add' a printer.
33 --delete|-d 'delete' a printer.
35 printer_name share_name port_name driver_name location XX remote_machine
40 usage(1) if (not $result);
42 usage(0) if ($opt_help);
44 if (!$opt_add && !$opt_delete) {
45 usage(1, "invalid: neither --add|-a nor --delete|-d set");
49 usage(1, "invalid: no smb.conf file set");
54 my $printer_name = shift(@argv);
55 my $share_name = shift(@argv);
56 my $port_name = shift(@argv);
57 my $driver_name = shift(@argv);
58 my $location = shift(@argv);
59 my $win9x_driver_location = shift(@argv);
60 my $remote_machine = shift(@argv);
62 if (!defined($share_name) || length($share_name) == 0) {
63 $share_name = $printer_name;
66 if (!defined($share_name)) {
67 die "share name not defined";
70 my $tmp = $opt_smb_conf.$$;
73 my $within_section = 0;
74 my $found_section = 0;
76 open(CONFIGFILE_NEW, "+>$tmp") || die "Unable top open conf file $tmp";
78 open (CONFIGFILE, "+<$opt_smb_conf") || die "Unable to open config file $opt_smb_conf";
79 while (<CONFIGFILE>) {
84 if (($_ =~ /^#/) || ($_ =~ /^;/)) {
85 print CONFIGFILE_NEW $line;
88 if ($_ =~ /^\[.*\]$/) {
89 $_ = substr($_, 1, length($_)-2);
93 die "invalid section found";
95 if ($section eq $share_name) {
98 die("share $share_name already exists\n");
105 print CONFIGFILE_NEW $line;
110 if ($within_section == 1) {
113 print CONFIGFILE_NEW $line;
117 print CONFIGFILE_NEW "[$share_name]\n\tprintable = yes\n\tpath = /tmp\n";
120 close (CONFIGFILE_NEW);
122 if ($opt_delete && ($found_section == 0)) {
123 die "share $share_name not found";
125 system("cp", "$tmp", "$opt_smb_conf");