- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
DataStoreServer/scripts/dsprodtool (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/DataStoreServer/scripts/dsprodtool
r24196 r27840 12 12 use PS::IPP::Metadata::Config; 13 13 use File::Copy; 14 15 use Term::ReadKey; 14 16 15 17 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 36 38 my $dsroot; 37 39 my $dbname; 40 my $dbserver; 41 my $dbpass; 38 42 39 43 my $add; … … 58 62 'ps7=s' => \$ps7, 59 63 'dbname=s' => \$dbname, 64 'dbserver=s' => \$dbserver, 60 65 'dsroot=s' => \$dsroot, 61 66 ) or pod2usage(2); … … 64 69 65 70 # will exit if neither or both -add and -del were specified 66 $err .= "Must specify either --add or --del.\n" 71 show_usage( "Must specify either --add or --del.") 67 72 unless $add xor $del; 68 73 … … 76 81 } 77 82 78 } els e{83 } elsif ($del) { 79 84 $product = $del; 85 if (! -t STDIN) { 86 die "cannot delete product from script\n"; 87 } 88 print "*** Delete the Data Store Product $product? ***\n"; 89 print "*** to delete $product answer YES, and give password ***\n"; 90 print "*** WARNING this action is permanant *** \n"; 91 print "Delete? (YES/[n]): "; 92 93 my $line = ReadLine(0); 94 chomp $line; 95 exit 1 if !$line or ($line ne "YES"); 96 97 print "password: "; 98 ReadMode('noecho'); 99 $line = ReadLine(0); 100 ReadMode('normal'); 101 print "\n"; 102 chomp $line; 103 $dbpass = $line; 80 104 } 81 105 … … 93 117 } 94 118 95 my $root_index_script = "$dsroot/index.txt ";119 my $root_index_script = "$dsroot/index.txt.template"; 96 120 if (!stat($root_index_script)) { 97 121 $err .= "Data Store not found at '$dsroot'.\n" … … 102 126 if ($err); 103 127 104 my $dbserver = metadataLookupStr($siteConfig, 'DS_DBSERVER'); 128 $dbserver = metadataLookupStr($siteConfig, 'DS_DBSERVER') 129 unless defined $dbserver; 105 130 $dbname = metadataLookupStr($siteConfig, 'DS_DBNAME') 106 131 unless defined $dbname; 107 132 my $dbuser = metadataLookupStr($siteConfig, 'DS_DBUSER'); 108 my $dbpass = metadataLookupStr($siteConfig, 'DS_DBPASSWORD');133 $dbpass = metadataLookupStr($siteConfig, 'DS_DBPASSWORD') if !$dbpass; 109 134 exit ($PS_EXIT_CONFIG_ERROR) unless defined $dbserver and $dbname and $dbuser and $dbpass; 110 135 111 136 my $dsn = "DBI:mysql:host=$dbserver;database=$dbname"; 112 113 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";114 115 137 116 138 my $product_dir = "$dsroot/$product"; … … 118 140 119 141 if ($del) { 142 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n"; 120 143 # 121 144 # delete product … … 129 152 } 130 153 my $prod_id = $prod_row->{prod_id}; 131 132 # if requested, remove the product directory133 if ($remove) {134 if (system "rm -r $product_dir") {135 die("failed to remove $product_dir");136 }137 } else {138 # otherwise just zap the index script139 unlink("$index_script_name");140 }141 154 142 155 … … 152 165 $dbh->do("DELETE from dsProduct where prod_id = $prod_id"); 153 166 167 print "Product $product deleted.\n"; 168 169 # if requested, remove the product directory 170 if ($remove) { 171 print "Removing files from $product.\n"; 172 if (system "rm -r $product_dir") { 173 die("failed to remove $product_dir"); 174 } 175 } else { 176 # otherwise just zap the index script 177 unlink("$index_script_name"); 178 } 179 154 180 exit 0; 155 181 … … 158 184 # add a new product 159 185 # 186 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n"; 187 160 188 my $stmt = $dbh->prepare("SELECT prod_id FROM dsProduct WHERE prod_name = \'$product\'"); 161 189 $stmt->execute(); … … 167 195 168 196 # set up the product directory 197 # if there is an old index file delete it 198 if (-e $index_script_name ) { 199 if (!unlink($index_script_name)) { 200 die("failed trying to remove old $index_script_name"); 201 } 202 } 169 203 if (! -e $product_dir) { 170 204 $we_created_dir = 1; … … 172 206 die("failed trying to make product directory $product_dir"); 173 207 } 174 } 175 if (-e $index_script_name ) {176 if (!unlink($index_script_name)) {177 die("failed trying to remove old $index_script_name");178 }179 } 208 } else { 209 # directory alrady exists make sure that it's empty 210 my @dirlist = glob("$product_dir/*"); 211 die ("existing product directory $product_dir is not empty") if scalar @dirlist; 212 } 213 180 214 if (!copy($root_index_script, $index_script_name)) { 181 215 print STDERR "failed trying to copy($root_index_script, $index_script_name)";
Note:
See TracChangeset
for help on using the changeset viewer.
