Explorar o código

Tools update

Upd .gitignore to ignore object everywhere
Add update.pl, a small perl script to auto git update and apply db
update in sql.
Add setup_perl.sh, to setup perl environnement for module used by perl.
Move some function into rA_common.pm
Lighta %!s(int64=10) %!d(string=hai) anos
pai
achega
af0da61426
Modificáronse 6 ficheiros con 415 adicións e 158 borrados
  1. 3 1
      .gitignore
  2. 59 157
      tools/config.pl
  3. 109 0
      tools/rA_Common.pm
  4. 3 0
      tools/setup_perl.sh
  5. 1 0
      tools/stackdump
  6. 240 0
      tools/update.pl

+ 3 - 1
.gitignore

@@ -22,6 +22,9 @@ Thumbs.db
 /*.sdf
 /*.stackdump
 /*.suo
+*.o
+*.a
+*.yml
 /char-server
 /char-server
 /config.log
@@ -124,4 +127,3 @@ Thumbs.db
 /vcproj-9/login-server
 /vcproj-9/map-server
 /vcproj-9/mapcache
-/conf/.tmp-desd_conf.yml

+ 59 - 157
tools/config.pl

@@ -11,6 +11,7 @@ use Cwd;
 use Getopt::Long;
 use Net::Ping;
 use strict;
+use rA_Common;
 
 use constant {
     SERV_UID => "Serv_userid",
@@ -35,14 +36,6 @@ use constant {
     MIN_PORT => 2000, #below are usually reserved for system
     MAX_PORT => 65535,
 };
-#BEGIN { #check and install module
-#    my @aCheckModule = ("File::Basename","DBI","DBD::mysql","YAML","YAML::XS","Cwd","Getopt::Long","Net::Ping");
-#    my @aMarkInst = ();
-#    foreach(@aCheckModule) { eval "require $_" or push(@aMarkInst,$_); }
-#    CPAN::install("@aMarkInst") if(@aMarkInst > 0);
-#    foreach(@aCheckModule) { $_->import(); }
-#}
-
 # setup my defaults option
 my $sDsdFile    = DESD_CONF_FILE;
 my $sAutoyes    = 0;
@@ -73,7 +66,7 @@ sub GetArgs {
 	    ."\t --auto => auto-yes to question ? \n"
 	    ."\t --C => Clean (remove file, db, user before adding new)\n"
 	    ."\t --target => target (specify wich setup to run [$sValidTarget])\n"
-	    ."\t --Force => Force (bypass verification)\n";
+	    ."\t --Force => Force (bypass verification)\n"
 	    ."\t --OS => (specify the os you wish to use and avoid check)";
 	exit;
     }
@@ -109,40 +102,40 @@ sub Main {
 			SQL_LOG_DB => ,"ragnarok",
 			);
 
-    my $sBasedir = getcwd; #for setupdb
-    if($sTarget =~ /All|Inst/i){ InstallSoft(); }
-    if($sTarget =~ /All|Conf/i) { ConfigConf(\%hDefConf); chdir "$sBasedir"; }
-    if($sTarget =~ /All|DB/i) { ConfigDB(\%hDefConf); chdir "$sBasedir"; }
-    if($sTarget =~ /All|Dump/i) { chdir "~"; EnableCoredump(); }
-    print "Config done, you should be able to launch and connect server now\n";
-    print "NB : Don't forget to update your client clieninfo.xml to match change\n";
+	my $sBasedir = getcwd; #for setupdb
+	if($sTarget =~ /All|Inst/i){ InstallSoft(); }
+	if($sTarget =~ /All|Conf/i) { ConfigConf(\%hDefConf); chdir "$sBasedir"; }
+	if($sTarget =~ /All|DB/i) { ConfigDB(\%hDefConf); chdir "$sBasedir"; }
+	if($sTarget =~ /All|Dump/i) { chdir "~"; EnableCoredump(); }
+	print "Config done, you should be able to launch and connect server now\n";
+	print "NB : Don't forget to update your client clieninfo.xml to match change\n";
 }
 
 
 sub EnableCoredump { 
-    print "\n Starting Enabling coredump \n";
-    my $sCurfile = "~/.bashrc";
-    my @lines = ();
-    my $sJump = .0;
-    open PIPE,"sudo less $sCurfile |" or die $!;
-    foreach(<PIPE>){
+	print "\n Starting Enabling coredump \n";
+	my $sCurfile = "~/.bashrc";
+	my @lines = ();
+	my $sJump = .0;
+	open PIPE,"sudo less $sCurfile |" or die $!;
+	foreach(<PIPE>){
 		if($_ =~ /ulimit -c unlimited/){
 			$sJump = 1; #already in here nothing to do
 			last; 
 		}
 		push(@lines,$_) if /ulimit/;
-    }
-    if(scalar(@lines)>0){
-	print "ulimit instruction found in file=$sCurfile\n"
-	    ."\t lines= \n @lines \n"
-	    ."are you sure you want to continue ? [y/n] \n";
-	$sJump=1 if(GetValidAnwser("y|o|n") =~ /n/i);
-    }
-    system("sudo echo \"ulimit -c unlimited\" >> $sCurfile") if $sJump==0;
-    $sJump=0;
-    
-    $sOS = GetOS() unless($sOS);
-    if($sOS =~ /Fedora|CentOs/i){;
+	}
+	if(scalar(@lines)>0){
+		print "ulimit instruction found in file=$sCurfile\n"
+			."\t lines= \n @lines \n"
+			."are you sure you want to continue ? [y/n] \n";
+		$sJump=1 if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i);
+	}
+	system("sudo echo \"ulimit -c unlimited\" >> $sCurfile") if $sJump==0;
+	$sJump=0;
+
+	$sOS = GetOS() unless($sOS);
+	if($sOS =~ /Fedora|CentOs/i){;
 		open FILE, "</etc/security/limits.conf" || die;
 		open FILE_TMP, ">tmp_limits.conf" || die;
 		while(<FILE>){
@@ -160,24 +153,24 @@ sub EnableCoredump {
 		unlink "tmp_limits.conf";
 	}
 
-    $sCurfile = "/etc/sysctl.conf";
-    @lines = ();
-    open PIPE,"sudo less $sCurfile |" or die $!;
-    foreach(<PIPE>){
-	push(@lines,$_) if /^kernel.core/;
-    }
-    if(scalar(@lines)>0){
-	print "ulimit instruction found in file=$sCurfile\n"
-	    ."\t line= \n @lines \n"
-	    ."are you sure you want to continue ? [y/n] \n";
-	$sJump=2 if(GetValidAnwser("y|o|n") =~ /n/i);
-    }
+	$sCurfile = "/etc/sysctl.conf";
+	@lines = ();
+	open PIPE,"sudo less $sCurfile |" or die $!;
+	foreach(<PIPE>){
+		push(@lines,$_) if /^kernel.core/;
+	}
+	if(scalar(@lines)>0){
+		print "ulimit instruction found in file=$sCurfile\n"
+			."\t line= \n @lines \n"
+			."are you sure you want to continue ? [y/n] \n";
+		$sJump=2 if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i);
+	}
     unless($sJump==2){
-	system('sudo su root -c "echo \"echo kernel.core_uses_pid = 1 >> /etc/sysctl.conf\" | sudo bash"');
-	system('sudo su root -c "echo \"echo kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t >> /etc/sysctl.conf\" | sudo bash"');
-	system('sudo su root -c "echo \"echo fs.suid_dumpable = 1 >> /etc/sysctl.conf\" | sudo bash"');
-	system('sudo su root -c "sysctl -p"');
-    }
+		system('sudo su root -c "echo \"echo kernel.core_uses_pid = 1 >> /etc/sysctl.conf\" | sudo bash"');
+		system('sudo su root -c "echo \"echo kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t >> /etc/sysctl.conf\" | sudo bash"');
+		system('sudo su root -c "echo \"echo fs.suid_dumpable = 1 >> /etc/sysctl.conf\" | sudo bash"');
+		system('sudo su root -c "sysctl -p"');
+	}
 }
 
 sub GetOS {
@@ -213,7 +206,7 @@ sub InstallSoft {
 	system("sudo apt-get install @aListSoft");
 	}
 	elsif($sOS =~ /Fedora|CentOs/i){ #tested on fedora 18,19,20 /centos 5,6,7
-	my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","git","mariadb-server","maria","mariadb-devel","phpmyadmin","pcre-devel");
+	my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","git","mariadb-server","mariadb","mariadb-devel","phpmyadmin","pcre-devel");
 #	my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","git","mysql-server","mysql-devel","phpmyadmin","pcre-devel");
 	system("sudo yum install @aListSoft");
     }
@@ -247,10 +240,10 @@ sub ConfigDB { my ($rhDefConf) = @_;
     print "\n Starting ConfigDB \n";
     my $rhUserConf;
     while(1) {
-	$rhUserConf = GetDesiredConf($rhDefConf);
-	print "SetupDb using conf : \n";
-	ShowConfig($rhUserConf);
-	last if($sForce || AutoCheckConf($rhUserConf));
+		$rhUserConf = GetDesiredConf($rhDefConf);
+		print "SetupDb using conf : \n";
+		ShowConfig($rhUserConf);
+		last if($sForce || AutoCheckConf($rhUserConf));
     }
     ApplySetupDB($rhUserConf);
 }
@@ -268,7 +261,7 @@ sub ApplySetupConf { my ($rhConfig) = @_;
     YAML::XS::DumpFile(DESD_CONF_FILE,$rhConfig);
     unless(-d "$sUserConfDir") {
 	print "conf/import directory doesn't exist, create it ? [y/n] (will be generated by compilation otherwise) \n";
-	if(GetValidAnwser("y|o|n") =~ /n/i) { die "Couldn't apply conf without import folder\n"; }
+	if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) { die "Couldn't apply conf without import folder\n"; }
 	mkdir "$sUserConfDir";
     }
     chdir $sUserConfDir;
@@ -284,7 +277,7 @@ sub ApplySetupConf { my ($rhConfig) = @_;
 	if(-e -r $sCurfile) {
 	    print "Yes\n";
 	    print "$sCurfile seem to exist, overwritte it [y/n] ?\n";
-	    if(GetValidAnwser("y|o|n") =~ /n/i) {
+	    if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) {
 		print "Only overwritte option supported atm skip file\n\n";
 		next;
 	    }
@@ -388,18 +381,14 @@ sub AutoCheckConf { my ($rhConfig) = @_;
 sub CheckDupPort { my ($rhConfig,$sChkKeys) = @_;
     my $sChkport = $$rhConfig{$sChkKeys};
     foreach my $sKeys (keys %$rhConfig){
-	next if($sKeys eq $sChkKeys); #skip ourself
-	my $sVal = $$rhConfig{$sKeys};
-	return 1 if($sChkport eq $sVal);
+		next if($sKeys eq $sChkKeys); #skip ourself
+		my $sVal = $$rhConfig{$sKeys};
+		return 1 if($sChkport eq $sVal);
     }
     return 0;
 }
 
-sub CheckUsedPort { my($sPort) = @_;
-    open PIPE,"netstat -nat |" or die $!;
-    my @line = grep { /$sPort/ } <PIPE>;
-    return scalar(@line);
-}
+
 
 #Db function
 sub ApplySetupDB { my($rhConfig) = @_;
@@ -417,25 +406,7 @@ sub ApplySetupDB { my($rhConfig) = @_;
     print "SetupDb done \n";
 }
 
-sub RootCo { my($rhConfig) = @_;
-    print "\n Entering RootCo \n";
-    my $sDbH;
-    my $sDsn = $$rhConfig{"Dsn"}; #mysql server dest
-    my $sUser = $$rhConfig{SQL_UID}; #verify desired user
-    print "My dsn = $sDsn \n";
-    if($sUser eq "root"){
-	my $sPw = $$rhConfig{SQL_PW};
-	$sDbH = DBI->connect($sDsn, "root", $sPw);
-	unless($sDbH) { warn "Your root password doesn't seem valid for mysql, your desired-conf is wrong \n"; }
-    }
-    while($sDbH == 0) { #if can't use user to connect user root
-	print "Please inser DB root passeword (this won't be saved in any configuration file, needed to create dbs and user)\n";
-	my $sRPw = <>; chop($sRPw);
-	$sDbH = DBI->connect($sDsn, "root", $sRPw);
-    }
 
-    return $sDbH;
-}
 
 sub CreateDB { my($sDbH,$rhConfig) = @_;
     print "\n Entering CreateDB \n";
@@ -459,7 +430,7 @@ sub CreateDB { my($sDbH,$rhConfig) = @_;
 sub ValidateDBMerge { my($sDBn) = @_;
     warn "Database: '$sDBn' seem to already exist exiting\n";
     warn "Continue will load data in existing db would you like to continue ? [y/n] \n";
-    if(GetValidAnwser("y|o|n") =~ /n/i) {
+    if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) {
 	print "Exiting setup, please either setup with another dbname or manually\n";
 	exit;
     }
@@ -505,28 +476,14 @@ sub LoadSqlFile { my($sDbH,$rhConfig) = @_;
     chdir "../$sSqldir";
     print "Checking if target files exist :\n\tMain: [@aMainFiles]\n\tLog: [@aLogFiles]\n";
 
-    CheckAndLoad(\@aMainFiles,$rhConfig,$sDBn);
-    CheckAndLoad(\@aLogFiles,$rhConfig,$sLogDBn);
+    CheckAndLoadSQL(\@aMainFiles,$rhConfig,$sDBn);
+    CheckAndLoadSQL(\@aLogFiles,$rhConfig,$sLogDBn);
 
 #    my $raMainQuerys = CheckAndAddQuery(\@aMainFiles,$rhConfig);
 #    my $raLogQuerys = CheckAndAddQuery(\@aLogFiles,$rhConfig);
 #    ExeQuery($sDbH,"use $sDBn;",@$raMainQuerys,"use $sLogDBn;", @$raLogQuerys);
 }
 
-sub CheckAndLoad { my ($raFiles,$rhConfig,$sDBn) = @_;
-    my $sHost = $$rhConfig{SQL_HOST};
-    my $sPw = $$rhConfig{SQL_PW};
-    my $sUser = $$rhConfig{SQL_UID};
-
-    foreach(@$raFiles) {
-	unless(-f -r $_){
-	    print "File : $_ doesn't seem to exist or was unreadable skipped\n";
-	    next;
-	}
-	my $sFileFullPath = Cwd::abs_path($_);
-	system("mysql -u $sUser --password=$sPw -h $sHost $sDBn < $sFileFullPath");
-    }
-}
 
 # query failure atm (shitty perl)
 #sub CheckAndAddQuery { my ($raFiles) = @_;
@@ -556,61 +513,6 @@ sub CreateServUser { my($sDbH,$rhConfig) = @_;
     ExeQuery($sDbH,@aQuery);
 }
 
-sub ExeQuery { my $sDbH = shift;
-    my @aQuery = @_;
-    print "my querys are = [ @aQuery ]\n";
-    foreach(@aQuery) {
-	unless($sDbH->do($_)){ print "Failed to execute query : $_ =>  $DBI::errstr \n"; }
-    }
-}
-
-#Common
-sub GetValidateConf { my($rhConfig) = @_;
-    my $rhUserConf;
-    while (1) {
-	$rhUserConf = GetUserConf($rhConfig);
-	print "\n Please Check desired conf \n";
-	ShowConfig($rhUserConf);
-	print "Would you like to apply those setting ? [y/n] ";
-	last if(GetValidAnwser("y|o|n") =~ /y|o/i);
-	print "\n Restarting configuration sequence \n";
-    }
-    return $rhUserConf;
-}
-
-sub GetUserConf { my ($rhDefConf) = @_;
-    my %hConf;
-    my @sortedkeys = sort keys (%$rhDefConf);
-    foreach my $sKey (@sortedkeys){
-	my $sVal = $$rhDefConf{$sKey};
-	print "$sKey : [$sVal] ";
-	my $sAnwser = <>; chop($sAnwser);
-	$hConf{"$sKey"} = $sAnwser || $sVal;
-    }
-    return \%hConf;
-}
-
-sub ShowConfig { my ($rhUserConf) = @_;
-    my @sortedkeys = sort keys (%$rhUserConf);
-    foreach my $sKey (@sortedkeys){
-	my $sVal = $$rhUserConf{$sKey};
-	if(ref($sVal) eq 'ARRAY') {  print " $sKey => [@$sVal] \n";}
-	else { print " $sKey => [$sVal] \n"; }
-    }
-}
-
-sub GetValidAnwser { my($sOptReg) = @_;
-    my $sAnwser = "";
-    if($sAutoyes) { $sAnwser="y"; print "\n"; }
-    else {
-	while(!($sAnwser =~ /$sOptReg/i)) {
-	    $sAnwser = <>; chop($sAnwser);
-	    print "Please enter a valid option : $sOptReg " unless($sAnwser =~ /$sOptReg/i);
-	}
-    }
-    return $sAnwser;
-}
-
 sub GetDesiredConf { my ($rhDefConf) = @_;
     print "Please enter desired confiration\n";
     my $rhUserConf;
@@ -629,7 +531,7 @@ sub GetDesiredConf { my ($rhDefConf) = @_;
 	else {
 	    ShowConfig($rhUserConf);
 	    print "Would you like to apply those setting ? [y/n] ";
-	    if(GetValidAnwser("y|o|n") =~ /n/i) {  #no take user entry
+	    if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) {  #no take user entry
 		print "DesiredConf not applyed, please enter config\n";
 		$rhUserConf=GetValidateConf($rhDefConf);
 	    }

+ 109 - 0
tools/rA_Common.pm

@@ -0,0 +1,109 @@
+package rA_Common;
+use strict;
+use warnings;
+use Exporter;
+
+our @ISA= qw( Exporter );
+
+# these CAN be exported.
+our @EXPORT_OK = qw( GetValidateConf GetUserConf ExeQuery GetUserConf 
+	GetValidAnwser GetValidateConf RootCo ShowConfig CheckUsedPort CheckAndLoadSQL);
+# these are exported by default.
+our @EXPORT = @EXPORT_OK; # qw( GetValidateConf GetUserConf ExeQuery GetUserConf GetValidAnwser GetValidateConf RootCo ShowConfig CheckUsedPort CheckAndLoadSQL);
+
+sub GetValidateConf { my($rhConfig) = @_;
+	my $rhUserConf;
+	while (1) {
+		$rhUserConf = GetUserConf($rhConfig);
+		print "\n Please Check desired conf \n";
+		ShowConfig($rhUserConf);
+		print "Would you like to apply those setting ? [y/n] ";
+		last if(GetValidAnwser("y|o|n") =~ /y|o/i);
+		print "\n Restarting configuration sequence \n";
+	}
+	return $rhUserConf;
+}
+
+#remplis tous un hash
+sub GetUserConf { my ($rhDefConf) = @_;
+	my %hConf;
+	my @sortedkeys = sort keys (%$rhDefConf);
+	foreach my $sKey (@sortedkeys){
+		my $sVal = $$rhDefConf{$sKey};
+		print "$sKey : [$sVal] ";
+		my $sAnwser = <>; chop($sAnwser);
+		$hConf{"$sKey"} = $sAnwser || $sVal;
+	}
+	return \%hConf;
+}
+
+sub ShowConfig { my ($rhUserConf) = @_;
+	my @sortedkeys = sort keys (%$rhUserConf);
+	foreach my $sKey (@sortedkeys){
+		my $sVal = $$rhUserConf{$sKey};
+		if(ref($sVal) eq 'ARRAY') {  print " $sKey => [@$sVal] \n";}
+		else { print " $sKey => [$sVal] \n"; }
+	}
+}
+
+sub GetValidAnwser { my($sOptReg,$sAutoyes) = @_;
+	my $sAnwser = "";
+	if($sAutoyes) { $sAnwser="y"; print "\n"; }
+	else {
+	while(!($sAnwser =~ /$sOptReg/i)) {
+	    $sAnwser = <>; chop($sAnwser);
+	    print "Please enter a valid option : $sOptReg " unless($sAnwser =~ /$sOptReg/i);
+	}
+    }
+    return $sAnwser;
+}
+
+sub CheckUsedPort { my($sPort) = @_;
+    open PIPE,"netstat -nat |" or die $!;
+    my @line = grep { /$sPort/ } <PIPE>;
+    return scalar(@line);
+}
+
+
+sub RootCo { my($rhConfig) = @_;
+	print "\n Entering RootCo \n";
+	my $sDbH = 0;
+	my $sDsn = $$rhConfig{"Dsn"}; #mysql server dest
+	my $sUser = $$rhConfig{SQL_UID}; #verify desired user
+	print "My dsn = $sDsn \n";
+	if($sUser eq "root"){
+		my $sPw = $$rhConfig{SQL_PW};
+		$sDbH = DBI->connect($sDsn, "root", $sPw);
+		unless($sDbH) { warn "Your root password doesn't seem valid for mysql, your desired-conf is wrong \n"; }
+	}
+	while($sDbH == 0) { #if can't use user to connect user root
+		print "Please inser DB root passeword (this won't be saved in any configuration file, needed to create dbs and user)\n";
+		my $sRPw = <>; chop($sRPw);
+		$sDbH = DBI->connect($sDsn, "root", $sRPw);
+	}
+
+	return $sDbH;
+}
+
+sub CheckAndLoadSQL { my ($raFiles,$rhConfig,$sDBn) = @_;
+    my $sHost = $$rhConfig{SQL_HOST};
+    my $sPw = $$rhConfig{SQL_PW};
+    my $sUser = $$rhConfig{SQL_UID};
+
+    foreach(@$raFiles) {
+	unless(-f -r $_){
+	    print "File : $_ doesn't seem to exist or was unreadable skipped\n";
+	    next;
+	}
+	my $sFileFullPath = Cwd::abs_path($_);
+	system("mysql -u $sUser --password=$sPw -h $sHost $sDBn < $sFileFullPath");
+    }
+}
+
+sub ExeQuery { my $sDbH = shift;
+    my @aQuery = @_;
+    print "my querys are = [ @aQuery ]\n";
+    foreach(@aQuery) {
+	unless($sDbH->do($_)){ print "Failed to execute query : $_ =>  $DBI::errstr \n"; }
+    }
+}

+ 3 - 0
tools/setup_perl.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+#simple script to setupperl environnement with all module dependancy needed
+cpan install File::Basename Getopt::Long DBI DBD::mysql YAML YAML:XS Cwd Net::Ping Scalar::Util Git::Repository;

+ 1 - 0
tools/stackdump

@@ -1,4 +1,5 @@
 #!/bin/bash
+# !TODO upd me
 
 case "$1" in
 	map|char|login)

+ 240 - 0
tools/update.pl

@@ -0,0 +1,240 @@
+#!/usr/bin/perl
+# upgrading rA emulator, (src,npc,db..).
+# perform sql db update
+# perform binary recompilation
+
+use strict;
+use Getopt::Long;
+use Cwd;
+use Git::Repository;
+use File::Copy;
+use DBI;
+use DBD::mysql;
+use YAML::XS;
+
+use lib "./"; #use current path for out lib as well
+use rA_Common;
+
+#prgm option
+my $sHelp	= 0;
+my $sValidTarget = "All|DB|Compile|Restart|Upd";
+my $srABaseGitHttp	= 'https://github.com/rathena/rathena.git';
+my $srABaseGitSSH	= 'git@github.com:rathena/rathena.git';
+use constant {
+	STATE_FILE => "SQL_Status.yml",
+	ST_OLD => "old",
+	ST_SK => "skipped",
+    SQL_HOST => "SQL_host",
+    SQL_PORT => "SQL_port",
+    SQL_UID => "SQL_userid",
+    SQL_PW => "SQL_userpass",
+    SQL_MAIN_DB => "SQL_maindb",
+    SQL_LOG_DB => ,"SQL_logdb"
+};
+my %hFileState = ();
+
+#those following could be edited by user
+my $sAutoDB    = 0;	#by default we ask for db setting
+my $sTarget = "Upd|DB|Compile"; #default target doesn't restart
+my %hDefConf = (
+	SQL_HOST => "localhost",
+	SQL_PORT => "3306",
+	SQL_UID => "ragnarok",
+	SQL_PW => "ragnarok",
+	SQL_MAIN_DB => "ragnarok",
+	SQL_LOG_DB => ,"ragnarok",
+);
+
+			
+GetArgs();
+Main();
+
+sub GetArgs {
+    GetOptions(
+    'target=s'	=> \$sTarget,	 #Target (wich setup to run)=
+    'help!' => \$sHelp,
+    ) or $sHelp=1; #display help if invalid option	
+	
+    if( $sHelp ) {
+	print "Incorect option specified, available option are:\n"
+	    ."\t --target => target (specify wich check to ignore [$sValidTarget])\n";
+	exit;
+    }
+    if(!$sTarget || !($sTarget =~ /$sValidTarget/i)){
+    	print "Incorect target specified, available target are:\n"
+	    ."\t --target => target (specify wich check to ignore [(default)$sValidTarget])\n 
+				NB restart is compiling dependant\n";
+		exit;
+    }
+}
+
+sub Main {
+	my $sCurdir = getcwd;
+	chdir "..";
+	
+	UpdateSQL($sCurdir,1,\%hFileState);
+	if($sTarget =~ "All|Upd") { GitUpdate($sCurdir); }
+	if($sTarget =~ "All|DB") { UpdateSQL($sCurdir,0,\%hFileState); }
+	if($sTarget =~ "All|Compile") { RunCompilation($sCurdir,$sTarget); }
+}
+
+sub UpdateSQL  { my($sBaseDir,$sInit,$rhFileState) = @_;
+	#my @aMapDBFiles;
+	my @aCharDBFiles; #for now we assum they all in same DB
+	#my @aLoginDBFiles;
+	my @aLogDBFiles;
+
+	chdir "sql-files/upgrades";
+	opendir (DIR, "./") or die $!;
+	my @aFiles 
+		= grep { 
+		/^(?!\.)/      # not begins with a period
+		&& /\.sql$/      # finish by .sql
+		&& -f "./$_"   # and is a file
+	} readdir(DIR);
+
+	print "Preparing SQL folder\n" if($sInit==1);
+	if(-e -r STATE_FILE) {
+		print "Reading file status \n";
+		$rhFileState = YAML::XS::LoadFile(STATE_FILE);
+	}
+		
+	foreach my $sFile (@aFiles){
+		#print "Cur file = $sFile \n";
+		
+		next if(exists($rhFileState->{$sFile}) ); #either old or skipped
+			
+		if($sInit==1){ #move all file into old
+			if( $sFile =~ /_opt_/){
+				$$rhFileState{$sFile} = ST_SK;
+				next; # by default optional updated are put in skipped dir
+			}
+			$$rhFileState{$sFile} = ST_OLD;
+		}
+		else {
+			
+			
+			if( $sFile =~ /_log.sql$/) { 
+				print "Found log file = $sFile \n";
+				push(@aLogDBFiles,$sFile);
+			}
+			else { 
+				print "Found file = $sFile \n";
+				push(@aCharDBFiles,$sFile);
+			}
+			
+		# This part is for distributed DB, not supported yet
+		# proposed nomenclature [lighta] : update_date_{opt_}(map|chr|acc|log).sql
+		# (e.g : update_20141218_opt_map.sql or update_20141218_acc.sql
+		
+		#	if( $sFile =~ /_map.sql$/) { 
+		#		print "Found log file = $sFile \n";
+		#		push(@aMapDBFiles,$sFile);
+		#		
+		#	}
+		#	elsif( $sFile =~ /_acc.sql$/) { 
+		#		print "Found log file = $sFile \n";
+		#		push(@aLoginDBFiles,$sFile);
+		#		
+		#	}
+		#	elsif( $sFile =~ /_chr.sql$/) { 
+		#		print "Found log file = $sFile \n";
+		#		push(@aCharDBFiles,$sFile);
+		#		
+		#	}
+		}
+	}
+	if($sInit==1){
+		print "Saving stateFile \n";
+		YAML::XS::DumpFile(STATE_FILE,$rhFileState);
+	}
+	else{ #apply update
+		if( scalar(@aCharDBFiles)==0 and  scalar(@aLogDBFiles)==0 
+		# and  scalar(@aMapDBFiles)==0 and  scalar(@aLoginDBFiles)==0
+		){
+			print "No SQL Update to perform\n";
+		}
+		else {
+			print "Updating DB \n";
+			my $rhUserConf;
+			if($sAutoDB==0){
+				$rhUserConf=GetValidateConf(\%hDefConf);
+				print "To make this step auto you can edit hDefConf and set sAutoDB to 1.
+					both parameter at the begining of file for the moment\n";
+			}
+			else {
+				$rhUserConf=\%hDefConf; #we assum it's set correctly
+			}
+			
+			#CheckAndLoadSQL(\@aMapDBFiles,$rhUserConf,$$rhUserConf{SQL_MAP_DB});
+			CheckAndLoadSQL(\@aCharDBFiles,$rhUserConf,$$rhUserConf{SQL_MAIN_DB});
+			#CheckAndLoadSQL(\@aLoginDBFiles,$rhUserConf,$$rhUserConf{SQL_ACC_DB});
+			CheckAndLoadSQL(\@aLogDBFiles,$rhUserConf,$$rhUserConf{SQL_LOG_DB});
+		}
+	}
+	
+	chdir "../..";
+}
+
+sub RunCompilation { my($sBaseDir,$sTarget) = @_;
+	if($^O =~ "linux"){
+		print "Recompiling \n";
+		system('./configure && make clean server');
+		if($sTarget =~ "All|Restart") {
+			print "Restarting \n";
+			system('./athena-start restart');
+		}
+	}
+	else {
+		print "AutoCompilation ain't supported for this OS yet (OS detected=$^O \n";
+	}
+}
+
+sub GitUpdate { my($sBaseDir) = @_;
+	my $sGit = Git::Repository->new(
+		work_tree => "$sBaseDir/..",
+	);
+	
+	my $sIsOrigin = CheckRemote($sGit);
+	if($sIsOrigin==0){
+		print "Saving current work\n";
+		$sGit->run( "stash" );
+		print "Fetching new content and merging\n";
+		$sGit->run( "pull" );
+		print "Attempt applying save work\n";
+		$sGit->run( "stash" => "pop" );
+	}
+	else { #it's a fork
+		print "Fetching upstream\n";
+		$sGit->run( "fetch" => "upstream" );
+		print "Switching to master branch\n";
+		$sGit->run( "checkout" => "master" );
+		print "Merging upstream with master\n";
+		$sGit->run( "merge" => "upstream/master" );
+	}
+}
+
+#Checking rA as a remote or origin
+sub CheckRemote { my($sGit) = @_;
+	my $sRaOrigin=0;
+	my $sRaUpstream=0;
+	
+	print "Checking remotes\n";
+	my @aRemotes = $sGit->run("remote" => "-v");	
+	
+	#print "My Remotes are\n";
+	foreach my $sCurRem (@aRemotes){
+		my @aCol = split(' ',$sCurRem);
+		#print "$sCurRem\n";
+		if( $aCol[1] =~ "$srABaseGitHttp" or $aCol[1] =~ "$srABaseGitSSH"){
+			#print "Has rA as origin\n";
+			if($aCol[0] =~ "origin") { $sRaOrigin = 1; }
+			if($aCol[0] =~ "upstream") { $sRaUpstream = 1; }
+		}
+	}
+	if($sRaOrigin==0 and $sRaUpstream==0){
+		print "Adding rA as a upstream\n";
+		$sGit->run("remote" => "add" => "upstream" => "$srABaseGitHttp");
+	}
+	return ($sRaOrigin==0);
+}