Browse Source

initial commit

master
Pascal Gloor 6 years ago
parent
commit
8346308b80
2 changed files with 129 additions and 0 deletions
  1. 5
    0
      defaults/JIMCUserPreferences.properties
  2. 124
    0
      jimcswitcher.pl

+ 5
- 0
defaults/JIMCUserPreferences.properties View File

@@ -0,0 +1,5 @@
#Wed Feb 20 13:52:19 CET 2019
AUTOSEARCH=0
INCOMPATIBLE_SERVICE_CONNECTIONS=0
BATCH_SIZE=250
PREFERRED_MAC_FORMAT=2

+ 124
- 0
jimcswitcher.pl View File

@@ -0,0 +1,124 @@
#!/usr/bin/perl

use strict;
use File::Basename;
use Data::Dumper;
use warnings;

my $path = dirname($0);

my %conf = (
'jimc' => "jimc.jnlp",
'regions' => "$path/regions",
'deployconf' => "$ENV{HOME}/.jimc",
'defaults' => "$path/defaults",
);

my $regions_list = list_regions();
my $selected_region = select_region($regions_list);
print "REGION: $selected_region\n";
deploy_region($selected_region);
start_jimc($selected_region);

print "NOTE: Close JIMC before saving the region!\n";
print "Do you want to save the region? [y/N] ";
my $sel = <STDIN>;
if ( defined $sel && $sel =~/[yY]/ ) {
save_region($selected_region);
print "Region $selected_region saved\n";
}
print "Done\n";



sub list_regions {
my %r;
opendir(DIR,$conf{regions}) || die "directory $conf{regions} does not exist";
while(readdir DIR) {
next if /^\./;
my $dir = $_;
opendir(DIR2,$conf{regions}.'/'.$dir) || next;
while(readdir DIR2) {
next if /^\./;
my $file = $_;
push @{$r{$dir}}, $file;
}
closedir(DIR2);
}
closedir(DIR);
return \%r;
}

sub select_region {
my($regions) = @_;

my $select;
my $region;

while(1) {

print "=============================================================================\n";
print "== SELECT REGION TO START ==\n";
print "=============================================================================\n";
my @idx;
foreach my $r ( sort keys %{$regions} ) {
push @idx, $r;
printf("== %s) %s\n", scalar(@idx), $r);
}
print "=============================================================================\n";
print "Which region do you want to start? : ";
my $select = <STDIN>;
chomp $select;

if ( defined $select && $select =~ /^\d+$/ && defined $idx[$select-1] ) {
$region = $idx[$select-1];
last;
}
}

return $region;
}

sub deploy_region {
my($region) = @_;

system("rm -f $conf{deployconf}/*");
system("cp $conf{defaults}/* $conf{deployconf}/");
system("cp $conf{regions}/$region/* $conf{deployconf}/");
}

sub start_jimc {
my($region) = @_;

my $jimc = "$conf{regions}/$region/$conf{jimc}" ?
"$conf{regions}/$region/$conf{jimc}" : "$conf{defaults}/$conf{jimc}";

system("open $jimc");
}

sub save_region {
my($region) = @_;

opendir(CONF,$conf{deployconf}) || die "failed to open jimc config dir $conf{deployconf}";
while(readdir CONF) {
next if /^\./;
my $file = $_;

if ( -r "$conf{regions}/$region/$file" ) {
print "Copying $file to region $region\n";
system("cp $conf{deployconf}/$file $conf{regions}/$region/$file");
}
}
closedir(CONF);
}

sub file_ts {
my($file) = @_;

if ( -r $file ) {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($file);
return $mtime > $ctime ? $mtime : $ctime;
}
return 0;
}


Loading…
Cancel
Save