diff --git a/Makefile.in b/Makefile.in index 251a874d1c..6c3f629b45 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,13 +2,12 @@ HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) - ALL_DEPENDS=common_sql login_sql char_sql map_sql tools import + ALL_DEPENDS=sql tools SQL_DEPENDS=common_sql login_sql char_sql map_sql import COMMON_SQL_DEPENDS=mt19937ar libconfig LOGIN_SQL_DEPENDS=mt19937ar libconfig common_sql CHAR_SQL_DEPENDS=mt19937ar libconfig common_sql MAP_SQL_DEPENDS=mt19937ar libconfig common_sql - CONVERTERS_DEPENDS=common_sql else ALL_DEPENDS=needs_mysql SQL_DEPENDS=needs_mysql @@ -20,7 +19,7 @@ endif ##################################################################### -.PHONY: sql \ +.PHONY: all sql \ common_sql \ mt19937ar \ login_sql \ @@ -29,7 +28,8 @@ endif tools \ import \ test \ - clean help + clean help \ + install uninstall bin-clean \ all: $(ALL_DEPENDS) @@ -38,12 +38,6 @@ sql: $(SQL_DEPENDS) common_sql: $(COMMON_SQL_DEPENDS) @$(MAKE) -C src/common sql -mt19937ar: - @$(MAKE) -C 3rdparty/mt19937ar - -libconfig: - @$(MAKE) -C 3rdparty/libconfig - login_sql: $(LOGIN_SQL_DEPENDS) @$(MAKE) -C src/login sql @@ -53,6 +47,12 @@ char_sql: $(CHAR_SQL_DEPENDS) map_sql: $(MAP_SQL_DEPENDS) @$(MAKE) -C src/map sql +mt19937ar: + @$(MAKE) -C 3rdparty/mt19937ar + +libconfig: + @$(MAKE) -C 3rdparty/libconfig + tools: @$(MAKE) -C src/tool @@ -94,46 +94,22 @@ help: @echo " 'map_sql' and 'import')" @echo "'test' - builds tests" @echo "'clean' - cleans builds and objects" + @echo "'install' - run installer wich setup rathena in /opt/" + @echo "'bin-clean' - delete binary installed" + @echo "'uninstall' - run uninstaller wich erase all install change" @echo "'help' - outputs this message" -##################################################################### - needs_mysql: @echo "MySQL not found or disabled by the configure script" @exit 1 -##################################################################### -# TODO - -install: conf/%.conf conf/%.txt - $(shell read -p "WARNING: This target does not work properly yet. Press Ctrl+C to cancel or Enter to continue.") - $(shell mkdir -p /opt/rathena/bin/) - $(shell mkdir -p /opt/rathena/etc/rathena/) - $(shell mkdir -p /opt/rathena/var/log/rathena/) - $(shell mv save /opt/rathena/etc/rathena/save) - $(shell mv db /opt/rathena/etc/rathena/db) - $(shell mv conf /opt/rathena/etc/rathena/conf) - $(shell mv npc /opt/rathena/etc/rathena/npc) - $(shell mv log/* /opt/rathena/var/log/rathena/) - $(shell cp *-server* /opt/rathena/bin/) - $(shell ln -s /opt/rathena/etc/rathena/save/ /opt/rathena/bin/) - $(shell ln -s /opt/rathena/etc/rathena/db/ /opt/rathena/bin/) - $(shell ln -s /opt/rathena/etc/rathena/conf/ /opt/rathena/bin/) - $(shell ln -s /opt/rathena/etc/rathena/npc/ /opt/rathena/bin/) - $(shell ln -s /opt/rathena/var/log/rathena/ /opt/rathena/bin/log) +install: + @sh ./install.sh bin-clean: - $(shell rm /opt/rathena/bin/login-server*) - $(shell rm /opt/rathena/bin/char-server*) - $(shell rm /opt/rathena/bin/map-server*) + @sh ./uninstall.sh bin uninstall: - $(shell read -p "WARNING: This target does not work properly yet. Press Ctrl+C to cancel or Enter to continue.") - bin-clean - $(shell rm /opt/rathena/bin/save) - $(shell rm /opt/rathena/bin/db) - $(shell rm /opt/rathena/bin/conf) - $(shell rm /opt/rathena/bin/npc) - $(shell rm /opt/rathena/bin/log) - $(shell rm -rf /opt/rathena/etc/rathena) - $(shell rm -rf /opt/rathena/var/log/rathena) + @sh ./uninstall.sh all + +##################################################################### diff --git a/athena-start b/athena-start index 2b9fcc38e3..4aeccda077 100755 --- a/athena-start +++ b/athena-start @@ -1,72 +1,119 @@ #!/bin/sh -# athena starting script by rowla -# modified by shazeya@syafi.com (NL101541) + +#source var/function +. ./function.sh +inst_launch_workaround PATH=./:$PATH - -L_SRV=login-server_sql -C_SRV=char-server_sql -M_SRV=map-server_sql - print_start() { -# more << EOF -echo "Athena Starting..." -echo " (c) 2003 Athena Project" -echo " modified by shazeya@syafi.com" -echo "" -#echo "Debug informations will appear," -#echo "since this is a test release." -#echo "" -echo "checking..." -#EOF + # more << EOF + echo "Athena Starting..." + echo " (c) 2013 rAthena Project" + echo "" + echo "" + echo "checking..." + #EOF } -check_files() { +get_status(){ + PIDFILE=.$1.pid + if [ -e ${PIDFILE} ]; then + ISRUN=$(ps ax | grep $(cat ${PIDFILE}) | grep $1) + PSRUN=$(echo "$ISRUN" | awk '{ print substr( $0, 0, 7) }') + fi + return $PSRUN +} - for i in ${L_SRV} ${C_SRV} ${M_SRV} +#cheking if already started, launch and mark in log +start_serv(){ + LOGFILE="log/$1.log" + get_status $1 + echo "My logfile=${LOGFILE}" + if [ -z ${PSRUN} ]; then + exec ./$1& + echo $! > .$1.pid + echo "Server '$1' started at `date +"%m-%d-%H:%M-%S"`" + echo "Server '$1' started at `date +"%m-%d-%H:%M-%S"`" >> ${LOGFILE} + else + echo "Can't start '$1', cause is already running p${PSRUN}" + echo "Can't start '$1', cause is already running p${PSRUN}" >> ${LOGFILE} + fi +} + +#experimental +watch_serv(){ + LOGFILE=./log/$1.log + ulimit -Sc unlimited + + while true; do + get_status $1 + if [ -z ${PSRUN} ]; then + $count=$count+1 + echo "server '$1' is down" >> ${LOGFILE} + echo "restarting server at time at `date +"%m-%d-%H:%M-%S"`">> ${LOGFILE} + exec ./$1& + echo $! > .$1.pid + if [ $3 ] && [ $3 -lt $count ]; then break; fi + else sleep $2 + fi + done +} + +restart(){ + $0 stop + for i in ${L_SRV} ${C_SRV} ${M_SRV} do - if [ ! -f ./$i ]; then - echo "$i does not exist, or can't run." - echo "Stop. Check your compile." - exit 1; - fi + while true; do + get_status ${i} + if [ ${PSRUN} ]; then echo "'${i}' is still running p${PSRUN} waiting end"; sleep 2; + else break; fi done - -# more << EOF -echo "Check complete." -echo "Looks good, a nice Athena!" -#EOF + done + $0 start } - case $1 in 'start') print_start check_files - - exec ./${L_SRV}& - echo $! > .${L_SRV}.pid - exec ./${C_SRV}& - echo $! > .${C_SRV}.pid - exec ./${M_SRV}& - echo $! > .${M_SRV}.pid - + echo "Check complete." + echo "Looks good, a nice Athena!" + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + start_serv $i + done echo "Now Started Athena." ;; + 'watch') + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + watch_serv $i 10 3 + done + echo "Now watching Athena." +;; 'stop') - for i in .${L_SRV}.pid .${C_SRV}.pid .${M_SRV}.pid + for i in ${L_SRV} ${C_SRV} ${M_SRV} do - if [ -e ./$i ]; then - kill $(cat $i) - rm $i + PIDFILE=.${i}.pid + if [ -e ./${PIDFILE} ]; then + kill $(cat ${PIDFILE}) + rm ${PIDFILE} fi done ;; 'restart') - $0 stop - $0 start + restart ;; + 'status') + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + get_status ${i} + if [ ${PSRUN} ]; then echo "'${i}' is running p${PSRUN}"; else echo "'${i}' seem down"; fi + done +;; *) - echo "Usage: athena-start { start | stop | restart }" + echo "Usage: athena-start { start | stop | restart | status | watch }" ;; esac + + diff --git a/char-server.sh b/char-server.sh deleted file mode 100644 index 9e7e6840a6..0000000000 --- a/char-server.sh +++ /dev/null @@ -1,16 +0,0 @@ -#/bin/sh -#Hi my naem is Kirt and I liek anime - -ulimit -Sc unlimited - -while [ 3 ] ; do -if [ -f .stopserver3 ] ; then -echo server marked down >> servlog.txt -else -echo restarting server at time at `date +"%m-%d-%H:%M-%S"`>> startlog.txt -./char-server_sql -fi - -sleep 5 - -done diff --git a/config.pl b/config.pl new file mode 100755 index 0000000000..9a8edd53ac --- /dev/null +++ b/config.pl @@ -0,0 +1,538 @@ +#!/usr/bin/perl +# config script by lighta +#TODO list : +#- don't always override import/file, sed grep ? + +use CPAN; +use strict; +use constant { + SERV_UID => "Serv_userid", + SERV_PW => "Serv_userpass", + SERV_WAN_IP => "Serv_wan_ip", + MAP_PORT => "Map_port", + CHAR_PORT => "Char_port", + LOGIN_PORT => "Login_port", + MD5_ENABLE => "enable_MD5", + 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", + + MAP_CONF_FILE => "map_conf.txt", + CHAR_CONF_FILE => "char_conf.txt", + LOGIN_CONF_FILE => "login_conf.txt", + INTER_CONF_FILE => "inter_conf.txt", + DESD_CONF_FILE => ".tmp-desd_conf.yml", + MIN_PORT => 2000, #below are usually reserved for system + MAX_PORT => 65535, +}; +BEGIN { #check and install module + my @aCheckModule = ("DBI","DBD::mysql","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; +my $sForce = 0; +my $sClean = 0; +my $sTarget = "All"; +my $sHelp = 0; +GetArgs(); +Main(); + +sub GetArgs { + GetOptions( + 'f=s' => \$sDsdFile, #give desired conf file + 'auto=i' => \$sAutoyes, #Force (auto-yes) + 'C=i' => \$sClean, #Clean (like force but remove before adding) + 'target=s' => \$sTarget, #Target (wich setup to run) + 'Force=i' => \$sForce, #Force (bypass verification) + 'help!' => \$sHelp, + ) or $sHelp=1; #display help if invalid option + my $sValidTarget = "All|Conf|DB|Inst"; + + if( $sHelp ) { + print "Incorect option specified, available option are:\n" + ."\t --f filename => file (specify desiredconf to use)\n" + ."\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"; + exit; + } + unless($sTarget =~ /$sValidTarget/){ + print "Incorect target specified, available target are:\n" + ."\t --target => target (specify wich setup to run [(default)$sValidTarget])\n"; + exit; + } + if($sDsdFile ne DESD_CONF_FILE && !(-e -r $sDsdFile)){ + print "Incorect file specified: '$sDsdFile'\n" + ."\t this file doesn't seem to appear on filesystem or unable to read\n"; + exit; + } +} + +sub Main { + print "Welcome to athena config-tool\n"; + #default conf + my %hDefConf = ( SERV_UID => "s1", + SERV_PW => "p1", + SERV_WAN_IP => "localhost", + MAP_PORT => "5121", + CHAR_PORT => "6121", + LOGIN_PORT => "6900", + MD5_ENABLE => "yes", + SQL_HOST => "localhost", + SQL_PORT => "3306", + SQL_UID => "ragnarok", + SQL_PW => "ragnarok", + SQL_MAIN_DB => "ragnarok", + SQL_LOG_DB => ,"ragnarok", + ); + + my $sBasedir = getcwd; #for setupdb + if($sTarget =~ /All|Inst/){ InstallSoft(); } + if($sTarget =~ /All|Conf/) { ConfigConf(\%hDefConf); chdir "$sBasedir"; } + if($sTarget =~ /All|DB/) { ConfigDB(\%hDefConf); chdir "$sBasedir"; } + 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 InstallSoft { + print "\n Starting InstallSoft \n"; + print "This autoinstall feature is experimental, package name varies from distri and version, couldn't support them all\n"; + #yes we could $^0 or uname -r but $^0 only give perl binary build OS and uname hmm... + my @aSupportedOS = ("Debian","Ubuntu","Fedora","CentOs"); + my $sOSregex = join("|",@aSupportedOS); + my $sOS; + until($sOS =~ /$sOSregex/i){ + print "Please enter your OS:[$sOSregex] or enter 'quit' to exit\n"; + $sOS = <>; chomp($sOS); + last if($sOS eq "quit"); + } + if($sOS eq "quit"){ print "Skipping Software installation\n"; return; } + elsif($sOS =~ /Ubuntu|Debian/i) { #tested on ubuntu 12.10 + my @aListSoft = ("gcc","gdb","zlibc","zlib1g-dev","make","subversion","mysql-client","mysql-server","mysql-common","libmysqlclient-dev","phpmyadmin","libpcre3-dev"); + print "Going to install: @aListSoft\n"; + system("sudo apt-get install @aListSoft"); + } + elsif($sOS =~ /Fedora|CentOs/i){ #tested on fedora 18 + my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","subversion","mysql-server","phpmyadmin","pcre-devel"); + system("sudo yum install @aListSoft"); + } +} + +sub ConfigConf { my ($rhDefConf) = @_; + print "\n Starting ConfigConf \n"; + my $rhUserConf; + while(1) { + $rhUserConf = GetDesiredConf($rhDefConf); + print "SetupConf using conf : \n"; + ShowConfig($rhUserConf); + last if($sForce || AutoCheckConf($rhUserConf)); + } + ApplySetupConf($rhUserConf); +} + +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)); + } + ApplySetupDB($rhUserConf); +} + +#conf function +sub ApplySetupConf { my ($rhConfig) = @_; + print "\nApplying conf \n"; + my @aTargetfile = (MAP_CONF_FILE,CHAR_CONF_FILE,LOGIN_CONF_FILE,INTER_CONF_FILE); + my $sConfDir = "conf"; + my $sUserConfDir = "import"; + + die "$sConfDir doesn't seem to exist or coudldn't be read/writte" unless(-d -r -w "../$sConfDir"); + chdir "../$sConfDir"; + print "Saving tmp user-conf \n"; + 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"; } + mkdir "$sUserConfDir"; + } + chdir $sUserConfDir; + + if($sClean){ unlink @aTargetfile; } #deleting file before applying conf if clean + opendir(DIR, ".") or die $!; + my @aDirfile = grep { /\.txt/ && -f "$_" } readdir(DIR); + close DIR; + print "Current file in directory = [@aDirfile] target = [@aTargetfile] \n"; + + foreach my $sCurfile(@aTargetfile) { + print "Checking if target file: [$sCurfile] exist ? "; + if(-e -r $sCurfile) { + print "Yes\n"; + print "$sCurfile seem to exist, overwritte it [y/n] ?\n"; + if(GetValidAnwser("y|o|n") =~ /n/i) { + print "Only overwritte option supported atm skip file\n\n"; + next; + } + } + else { print "No\n" }; + + print "\t Writting file $sCurfile \n"; + if($sCurfile eq MAP_CONF_FILE) { ApplyMapConf($rhConfig,$sCurfile); } + elsif($sCurfile eq CHAR_CONF_FILE) { ApplyCharConf($rhConfig,$sCurfile); } + elsif($sCurfile eq LOGIN_CONF_FILE) { ApplyLoginConf($rhConfig,$sCurfile); } + elsif($sCurfile eq INTER_CONF_FILE) { ApplyInterConf($rhConfig,$sCurfile); } + } +} + +sub ApplyMapConf { my ($rhUserConf,$sCurfile) = @_; + open FILE, "> $sCurfile" || die "couldn't openfile/create $sCurfile \n"; + print FILE "userid: " . $$rhUserConf{SERV_UID}."\n"; + print FILE "passwd: " . $$rhUserConf{SERV_PW}."\n\n"; + + print FILE "map_ip: " . $$rhUserConf{SERV_WAN_IP}."\n"; + print FILE "map_port: " . $$rhUserConf{MAP_PORT}."\n"; + print FILE "char_port: " . $$rhUserConf{CHAR_PORT}."\n"; +} + +sub ApplyCharConf { my ($rhUserConf,$sCurfile) = @_; + open FILE, "> $sCurfile" || die "couldn't openfile $sCurfile \n"; + print FILE "userid: " . $$rhUserConf{SERV_UID}."\n"; + print FILE "passwd: " . $$rhUserConf{SERV_PW}."\n\n"; + + print FILE "char_ip: " . $$rhUserConf{SERV_WAN_IP}."\n"; + print FILE "char_port: " . $$rhUserConf{CHAR_PORT}."\n"; + print FILE "login_port: " . $$rhUserConf{LOGIN_PORT}."\n"; +} + +sub ApplyLoginConf { my ($rhUserConf,$sCurfile) = @_; + open FILE, "> $sCurfile" || die "couldn't openfile $sCurfile \n"; + print FILE "login_port: " . $$rhUserConf{LOGIN_PORT}."\n"; + print FILE "use_MD5_passwords: " . $$rhUserConf{MD5_ENABLE}."\n"; +} + +sub ApplyInterConf { my ($rhUserConf,$sCurfile) = @_; + open FILE, "> $sCurfile" || die "couldn't openfile $sCurfile \n"; + + print FILE "sql.db_hostname: " . $$rhUserConf{SQL_HOST}."\n"; + print FILE "sql.db_port: " . $$rhUserConf{SQL_PORT}."\n"; + print FILE "sql.db_username: " . $$rhUserConf{SQL_UID}."\n"; + print FILE "sql.db_password: " . $$rhUserConf{SQL_PW}."\n"; + print FILE "sql.db_database: " . $$rhUserConf{SQL_MAIN_DB}."\n\n"; + + print FILE "char_server_ip: " . $$rhUserConf{SQL_HOST}."\n"; + print FILE "char_server_port: " . $$rhUserConf{SQL_PORT}."\n"; + print FILE "char_server_id: " . $$rhUserConf{SQL_UID}."\n"; + print FILE "char_server_pw: " . $$rhUserConf{SQL_PW}."\n"; + print FILE "char_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n"; + + print FILE "sql.map_server_ip: " . $$rhUserConf{SQL_HOST}."\n"; + print FILE "sql.map_server_port: " . $$rhUserConf{SQL_PORT}."\n"; + print FILE "map_server_id: " . $$rhUserConf{SQL_UID}."\n"; + print FILE "map_server_pw: " . $$rhUserConf{SQL_PW}."\n"; + print FILE "map_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n"; + + #todo may we want 2 schema ?? + print FILE "log_db_ip: " . $$rhUserConf{SQL_HOST} ."\n"; + print FILE "log_db_port: " . $$rhUserConf{SQL_PORT}."\n"; + print FILE "log_db_id: " . $$rhUserConf{SQL_UID}."\n"; + print FILE "log_db_pw: " . $$rhUserConf{SQL_PW}."\n"; + print FILE "log_db_db: " . $$rhUserConf{SQL_LOG_DB}."\n\n"; +} + +sub AutoCheckConf { my ($rhConfig) = @_; + print "\n AutoCheckConf, \n you can use option --force=1 to bypass this \n"; + foreach my $sKeys (keys %$rhConfig){ + my $sVal = $$rhConfig{$sKeys}; + if($sKeys =~ /PORT/) { #chek if valid port + if(($sValMAX_PORT)) { + warn "Invalid port specified for $sKeys => $sVal, must be in [".MIN_PORT.":".MAX_PORT."]\n"; + return 0; + } + elsif(!($sKeys =~ /SQL/) && CheckUsedPort($sVal)) { #skip SQL service + warn "Port:$sVal seem to be already in use by system \n"; + return 0; + } + elsif(CheckDupPort($rhConfig,$sKeys)) { + warn "Port:$sVal seem to be already used by other key in config \n"; + return 0; + } + } + elsif($sKeys =~ /IP|HOST/){ #chek if ip valid, can we reach it ? trough SYN ACK + my $p = Net::Ping->new("syn"); + my $sTest = $p->ping($sVal); + $p->close(); + unless($sTest) { + print "Invalide IP/Host, ping couldn't reach $sKeys => $sVal \n NB : ICMP may just be unallowed\n"; + return 0; + } + } + } + return 1; +} + +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); + } + return 0; +} +sub CheckUsedPort { my($sPort) = @_; + open PIPE,"netstat -nat |" or die $!; + my @line = grep { /$sPort/ } ; + return scalar(@line); +} + +#Db function +sub ApplySetupDB { my($rhConfig) = @_; + my $sDbH; #db handle + my $sHost = $$rhConfig{SQL_HOST}; + my $sPort = $$rhConfig{SQL_PORT}; + my $sDsn = "dbi:mysql::$sHost:$sPort"; #don't try to auto connect to db + $$rhConfig{"Dsn"} = $sDsn; + + $sDbH = RootCo($rhConfig); + CreateDB($sDbH,$rhConfig); #create db if not exist + $sDbH = CreateUser($sDbH,$rhConfig); #loged as user now + LoadSqlFile($sDbH,$rhConfig); #Load .sql file into db + CreateServUser($sDbH,$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"; + my $sDBn = $$rhConfig{SQL_MAIN_DB}; + my $sLogDBn = $$rhConfig{SQL_LOG_DB}; + my @aQuery = ("create database IF NOT EXISTS $sDBn;","create database IF NOT EXISTS $sLogDBn;"); + if($sClean){ #deleting database if clean + unshift(@aQuery,"drop database IF EXISTS $sDBn;"); + unshift(@aQuery,"drop database IF EXISTS $sLogDBn;"); + } + else { + my $sRes = $sDbH->selectcol_arrayref('show databases'); + foreach my $db (@$sRes){ #relevant later for import + if($db eq "$sDBn") { ValidateDBMerge($db); } #may exit here + elsif ($db eq "$sLogDBn") { ValidateDBMerge($db); } #may exit here + } + } + ExeQuery($sDbH,@aQuery); +} + +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) { + print "Exiting setup, please either setup with another dbname or manually\n"; + exit; + } +} + +sub CreateUser { my($sDbH,$rhConfig) = @_; + print "\n Entering CreateUser \n"; + my $sDsn = $$rhConfig{"Dsn"}; + print "My dsn = $sDsn \n"; + my $sHost = $$rhConfig{SQL_HOST}; + my $sPw = $$rhConfig{SQL_PW}; + my $sUser = $$rhConfig{SQL_UID}; + my $sDBn = $$rhConfig{SQL_MAIN_DB}; + my $sLogDBn = $$rhConfig{SQL_LOG_DB}; + + my @aQuery= ("GRANT ALL PRIVILEGES ON $sDBn.* TO $sUser\@'$sHost' IDENTIFIED BY '$sPw' WITH GRANT OPTION", #maindb + "GRANT ALL PRIVILEGES ON $sLogDBn.* TO $sUser\@'$sHost' IDENTIFIED BY '$sPw' WITH GRANT OPTION"); #logdb + my $sUserDbh = DBI->connect($sDsn, $sUser, $sPw, {"PrintError" => 0}); #try connect with user + + if($sUserDbh && !$sClean) { + print "User : $sUser seem to already exist, skipping creation\n" + ."NB please check if you have correct privilege set for db: $sDBn \n"; + } + else { #create user only if not exist (or mode clean) + if($sClean && $sUser ne "root"){ unshift(@aQuery,"DELETE FROM mysql.user WHERE User = '$sUser';"); } + print "Creating user $sUser for dbs : $sDBn and $sLogDBn on $sHost \n"; + ExeQuery($sDbH,@aQuery); + $sUserDbh = DBI->connect($sDsn, $sUser, $sPw); + } + return $sUserDbh; #drop old co and connect with user now +} + +sub LoadSqlFile { my($sDbH,$rhConfig) = @_; + print "\n Entering LoadSqlFile \n"; + my $sDBn = $$rhConfig{SQL_MAIN_DB}; + my $sLogDBn = $$rhConfig{SQL_LOG_DB}; + + my $sSqldir = "sql-files"; + my @aMainFiles = ("main.sql"); #add other file to load for main db here + my @aLogFiles = ("logs.sql"); #add other file to load for log db here + + die "$sSqldir doesn't seem to exist or coudldn't be read" unless(-d -r "../$sSqldir"); + chdir "../$sSqldir"; + print "Checking if target files exist :\n\tMain: [@aMainFiles]\n\tLog: [@aLogFiles]\n"; + + CheckAndLoad(\@aMainFiles,$rhConfig,$sDBn); + CheckAndLoad(\@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) = @_; +# my @aQuery = (); +# foreach(@$raFiles) { +# unless(-f -r $_){ +# print "File : $_ doesn't seem to exist or was unreadable skipped\n"; +# next; +# } +# my $sFileFullPath = Cwd::abs_path($_); +# my $sInfileQuery = "source $sFileFullPath"; +# #my $sInfileQuery = "\\. $sFileFullPath;"; +# push(@aQuery,$sInfileQuery); +# +# } +# return \@aQuery; +#} + +sub CreateServUser { my($sDbH,$rhConfig) = @_; + my $sUid = $$rhConfig{SERV_UID}; + my $sUpw = $$rhConfig{SERV_PW}; + my $sMD5 = $$rhConfig{MD5_ENABLE}; + my $sDBn = $$rhConfig{SQL_MAIN_DB}; + my @aQuery = ("use $sDBn;","DELETE FROM login WHERE sex='S';"); + if($sMD5){ push(@aQuery,"INSERT INTO login(account_id, userid, user_pass, sex) values(1,'$sUid',MD5('$sUpw'),'S');"); } + else { push(@aQuery,"INSERT INTO login(account_id, userid, user_pass, sex) values(1,'$sUid','$sUpw','S');"); } + 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; + my $sDesdConfFile = $sDsdFile; + #if default search in conf otherwise get specified name with cwd + if($sDsdFile eq DESD_CONF_FILE) { $sDesdConfFile = "../conf/".$sDsdFile; } + + print "Checking if there an Desiredconf file \n"; + if(-e -r $sDesdConfFile) { + print "Found Desiredconf \n"; + $rhUserConf = YAML::XS::LoadFile($sDesdConfFile); + if(!($rhUserConf)){ + print "Desiredconf seem invalid or empty, please check file and relaunch setup or entry Config\n"; + $rhUserConf=GetValidateConf($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 + print "DesiredConf not applyed, please enter config\n"; + $rhUserConf=GetValidateConf($rhDefConf); + } + } + } + else { #no files take user entry + print "No Desiredconf found, please enter config \n"; + $rhUserConf=GetValidateConf($rhDefConf); + } + return $rhUserConf; +} \ No newline at end of file diff --git a/configure b/configure index 63471a51cf..d9b9e17b7f 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 17061 . +# From configure.in Revision: 17159 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.68. # @@ -5886,9 +5886,9 @@ if test "$want_pcre" = "no" ; then $as_echo "$as_me: ignoring PCRE (optional)" >&6;} else host_os="`uname`" - if test "$host_os" = "FreeBSD" ; then PCRE_HOME="/usr/local"; fi - { $as_echo "$as_me:${as_lineno-$LINENO}: bsddebug, pcrehome=($PCRE_HOME)" >&5 -$as_echo "$as_me: bsddebug, pcrehome=($PCRE_HOME)" >&6;} + if test "$host_os" = "FreeBSD" ; then + if test -z "$PCRE_HOME" ; then PCRE_HOME="/usr/local"; fi + fi if test -z "$PCRE_HOME" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pcre_study" >&5 $as_echo_n "checking for library containing pcre_study... " >&6; } diff --git a/configure.in b/configure.in index 5958bf6ffc..cedc7369d3 100644 --- a/configure.in +++ b/configure.in @@ -780,8 +780,9 @@ if test "$want_pcre" = "no" ; then AC_MSG_NOTICE([ignoring PCRE (optional)]) else host_os="`uname`" - if test "$host_os" = "FreeBSD" ; then PCRE_HOME="/usr/local"; fi - AC_MSG_NOTICE([bsddebug, pcrehome=($PCRE_HOME)]) + if test "$host_os" = "FreeBSD" ; then + if test -z "$PCRE_HOME" ; then PCRE_HOME="/usr/local"; fi + fi if test -z "$PCRE_HOME" ; then AC_SEARCH_LIBS([pcre_study], [pcre], [HAVE_PCRE="yes"], []) if test "$HAVE_PCRE" = "yes" ; then diff --git a/function.sh b/function.sh new file mode 100755 index 0000000000..00f8130dfe --- /dev/null +++ b/function.sh @@ -0,0 +1,26 @@ +L_SRV=login-server_sql +C_SRV=char-server_sql +M_SRV=map-server_sql +INST_PATH=/opt +PKG=rathena +PKG_PATH=$INST_PATH/$PKG + +check_files() { + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + if [ ! -f ./$i ]; then + echo "$i does not exist extiting" + exit 1; + fi + done +} + +check_inst_right(){ + if [ ! -w $INST_PATH ]; then echo "You must have sudo right to use this install (writte/read permission in /opt/ )" && exit; fi +} + +inst_launch_workaround(){ + if [ -d $PKG_PATH ]; then + if [ $(pwd) != $PKG_PATH ]; then cd $PKG_PATH; fi + fi +} diff --git a/install.sh b/install.sh new file mode 100755 index 0000000000..592cc8743c --- /dev/null +++ b/install.sh @@ -0,0 +1,25 @@ +#!/bin/sh +#source var/function +. ./function.sh + +check_inst_right +check_files +read -p "WARNING: This target dis experimental. Press Ctrl+C to cancel or Enter to continue." readEnterKey +mkdir -p $PKG_PATH/bin/ +mkdir -p $PKG_PATH/etc/$PKG/ +mkdir -p $PKG_PATH/var/$PKG/ + +#we copy all file into opt/ dir and treat dir like normal unix arborescence +rsync -r --exclude .svn db/ $PKG_PATH/var/$PKG/db +rsync -r --exclude .svn log/ $PKG_PATH/var/$PKG/log +rsync -r --exclude .svn conf/ $PKG_PATH/etc/$PKG/conf +rsync -r --exclude .svn npc/ $PKG_PATH/npc +cp athena-start $PKG_PATH/ +mv *-server* $PKG_PATH/bin/ + +ln -fs $PKG_PATH/var/$PKG/db/ $PKG_PATH/db +ln -fs $PKG_PATH/var/$PKG/log/ $PKG_PATH/log +ln -fs $PKG_PATH/etc/$PKG/conf/ $PKG_PATH/conf +ln -fs $PKG_PATH/athena-start /usr/bin/$PKG +for f in $(ls $PKG_PATH/bin/) ; do ln -fs $PKG_PATH/bin/$f $PKG_PATH/$f; done +echo "Installation is done you can now control server with '$PKG start'" diff --git a/login-server.sh b/login-server.sh deleted file mode 100644 index 5cddb968a3..0000000000 --- a/login-server.sh +++ /dev/null @@ -1,16 +0,0 @@ -#/bin/sh -#Hi my naem is Kirt and I liek anime - -ulimit -Sc unlimited - -while [ 2 ] ; do -if [ -f .stopserver2 ] ; then -echo server marked down >> servlog.txt -else -echo restarting server at time at `date +"%m-%d-%H:%M-%S"`>> startlog.txt -./login-server_sql -fi - -sleep 5 - -done diff --git a/map-server.sh b/map-server.sh deleted file mode 100644 index d1acd8f692..0000000000 --- a/map-server.sh +++ /dev/null @@ -1,16 +0,0 @@ -#/bin/sh -#Hi my naem is Kirt and I liek anime - -ulimit -Sc unlimited - -while [ 1 ] ; do -if [ -f .stopserver ] ; then -echo server marked down >> servlog.txt -else -echo restarting server at time at `date +"%m-%d-%H:%M-%S"`>> startlog.txt -./map-server_sql -fi - -sleep 5 - -done diff --git a/src/char/Makefile.in b/src/char/Makefile.in index bfe9d15852..5ec0a458e8 100644 --- a/src/char/Makefile.in +++ b/src/char/Makefile.in @@ -20,36 +20,39 @@ CHAR_OBJ = obj_sql/char.o obj_sql/inter.o obj_sql/int_party.o obj_sql/int_guild. CHAR_H = char.h inter.h int_party.h int_guild.h int_storage.h int_pet.h int_homun.h int_mail.h int_auction.h int_quest.h int_mercenary.h int_elemental.h HAVE_MYSQL=@HAVE_MYSQL@ -ifeq ($(HAVE_MYSQL),yes) - CHAR_SERVER_SQL_DEPENDS=obj_sql $(CHAR_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) +ifeq ($(HAVE_MYSQL),yes) + SQL_DEPENDS=char-server_sql else - CHAR_SERVER_SQL_DEPENDS=needs_mysql + SQL_DEPENDS=needs_mysql endif +ALL_DEPENDS=sql @SET_MAKE@ ##################################################################### -.PHONY : all char-server_sql clean help +.PHONY : all sql clean help -all: char-server_sql +all: $(ALL_DEPENDS) -char-server_sql: $(CHAR_SERVER_SQL_DEPENDS) - @echo " LD $@" - @@CC@ @LDFLAGS@ -o ../../char-server_sql@EXEEXT@ $(CHAR_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@ +sql: $(SQL_DEPENDS) clean: @echo " CLEAN char" @rm -rf *.o obj_sql ../../char-server_sql@EXEEXT@ help: - @echo "possible targets are 'char-server_sql' 'all' 'clean' 'help'" - @echo "'char-server_sql' - char server (SQL version)" + @echo "possible targets are 'sql' 'all' 'clean' 'help'" + @echo "'sql' - char server (SQL version)" @echo "'all' - builds all above targets" @echo "'clean' - cleans builds and objects" @echo "'help' - outputs this message" ##################################################################### +char-server_sql: obj_sql $(CHAR_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) + @echo " LD $@" + @@CC@ @LDFLAGS@ -o ../../char-server_sql@EXEEXT@ $(CHAR_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@ + needs_mysql: @echo "MySQL not found or disabled by the configure script" @exit 1 diff --git a/src/common/Makefile.in b/src/common/Makefile.in index 3a4697eb60..90ea2c74d2 100644 --- a/src/common/Makefile.in +++ b/src/common/Makefile.in @@ -24,11 +24,11 @@ LIBCONFIG_INCLUDE = -I../../3rdparty/libconfig HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) - ALL_DEPENDS=sql SQL_DEPENDS=common common_sql else SQL_DEPENDS=needs_mysql endif +ALL_DEPENDS=sql @SET_MAKE@ diff --git a/src/login/Makefile.in b/src/login/Makefile.in index d0fc347564..c789e0d38d 100644 --- a/src/login/Makefile.in +++ b/src/login/Makefile.in @@ -19,19 +19,20 @@ LOGIN_H = login.h account.h ipban.h loginlog.h HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) - LOGIN_SERVER_SQL_DEPENDS=obj_sql $(LOGIN_SQL_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) + SQL_DEPENDS=login-server_sql else - LOGIN_SERVER_SQL_DEPENDS=needs_mysql + SQL_DEPENDS=needs_mysql endif +ALL_DEPENDS= sql @SET_MAKE@ ##################################################################### .PHONY :all sql clean help -all: sql +all: $(ALL_DEPENDS) -sql: obj_sql login-server_sql +sql: $(SQL_DEPENDS) clean: @echo " CLEAN login" @@ -58,7 +59,7 @@ obj_sql: #executables -login-server_sql: $(LOGIN_SERVER_SQL_DEPENDS) +login-server_sql: obj_sql $(LOGIN_SQL_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) @echo " LD $@" @@CC@ @LDFLAGS@ -o ../../login-server_sql@EXEEXT@ $(LOGIN_SQL_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@ diff --git a/src/map/Makefile.in b/src/map/Makefile.in index 8e97221a78..6c398a800b 100644 --- a/src/map/Makefile.in +++ b/src/map/Makefile.in @@ -31,13 +31,11 @@ MAP_H = map.h chrif.h clif.h pc.h status.h npc.h \ HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) - ALL_DEPENDS=txt sql SQL_DEPENDS=map-server_sql else - ALL_TARGET=txt SQL_DEPENDS=needs_mysql endif -TXT_DEPENDS=map-server +ALL_DEPENDS=sql HAVE_PCRE=@HAVE_PCRE@ ifeq ($(HAVE_PCRE),yes) @@ -49,12 +47,10 @@ endif @SET_MAKE@ ##################################################################### -.PHONY : all txt sql clean help +.PHONY : all sql clean help all: $(ALL_DEPENDS) -txt: $(TXT_DEPENDS) - sql: $(SQL_DEPENDS) clean: @@ -62,13 +58,8 @@ clean: @rm -rf *.o obj_txt obj_sql ../../map-server@EXEEXT@ ../../map-server_sql@EXEEXT@ help: -ifeq ($(HAVE_MYSQL),yes) @echo "possible targets are 'sql' 'txt' 'all' 'clean' 'help'" @echo "'sql' - map server (SQL version)" -else - @echo "possible targets are 'txt' 'all' 'clean' 'help'" -endif - @echo "'txt' - map server (TXT version)" @echo "'all' - builds all above targets" @echo "'clean' - cleans builds and objects" @echo "'help' - outputs this message" @@ -80,9 +71,6 @@ needs_mysql: @exit 1 # object directories -obj_txt: - @echo " MKDIR obj_txt" - @-mkdir obj_txt obj_sql: @echo " MKDIR obj_sql" diff --git a/src/test/Makefile.in b/src/test/Makefile.in index c601de9cb3..e3a763789d 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -15,31 +15,38 @@ LIBCONFIG_INCLUDE = -I../../3rdparty/libconfig TEST_SPINLOCK_OBJ=obj/test_spinlock.o TEST_SPINLOCK_H= TEST_SPINLOCK_DEPENDS=obj $(TEST_SPINLOCK_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) - + @SET_MAKE@ ##################################################################### -.PHONY :all test_spinlock +.PHONY :all test clean -all: test_spinlock +all: test + +test: test_spinlock clean: @echo " CLEAN test" - @rm -rf *.o obj ../../test_spinlock@EXEEXT@ + @rm -rf *.o obj ../../test_spinlock@EXEEXT@ + +help: + @echo "possible targets are 'all' 'test' 'clean' 'help'" + @echo "'test' - builds test_spinlock test atm" + @echo "'all' - builds all above targets" + @echo "'clean' - cleans builds and objects" + @echo "'help' - outputs this message" ##################################################################### +test_spinlock: $(TEST_SPINLOCK_DEPENDS) + @echo " LD $@" + @@CC@ @LDFLAGS@ -o ../../test_spinlock@EXEEXT@ $(TEST_SPINLOCK_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@ + # object directories obj: @echo " MKDIR obj" @-mkdir obj - -#executables - -test_spinlock: $(TEST_SPINLOCK_DEPENDS) - @echo " LD $@" - @@CC@ @LDFLAGS@ -o ../../test_spinlock@EXEEXT@ $(TEST_SPINLOCK_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@ # login object files diff --git a/start b/start deleted file mode 100755 index bd12a5e885..0000000000 --- a/start +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# modified by shazeya@syafi.com (NL130240) - -./athena-start start -sleep 30 - -while [ true ]; do - if [ " 0" = "$(ps | grep -e log | wc -l)" ] || -# if [ " 0" = "$(ps | grep -e login | wc -l)" ] || - [ " 0" = "$(ps | grep -e char | wc -l)" ] || - [ " 0" = "$(ps | grep -e map | wc -l)" ]; then - printf "Error:" - date - sleep 10 - printf "Checking:" - date - if [ " 0" = "$(ps | grep -e log | wc -l)" ] || -# if [ " 0" = "$(ps | grep -e login | wc -l)" ] || - [ " 0" = "$(ps | grep -e char | wc -l)" ] || - [ " 0" = "$(ps | grep -e map | wc -l)" ]; then - printf "Error Confirmation:" - date - printf "Restoration:" - date - ./athena-start start - else - printf "Check Miss Sorry:" - date - fi -# else -# printf "Check OK:" -# date - fi - sleep 10 -done diff --git a/tools/config.pl b/tools/config.pl index 9a8edd53ac..b59e08a19c 100755 --- a/tools/config.pl +++ b/tools/config.pl @@ -65,7 +65,7 @@ sub GetArgs { ."\t --Force => Force (bypass verification)\n"; exit; } - unless($sTarget =~ /$sValidTarget/){ + unless($sTarget =~ /$sValidTarget/i){ print "Incorect target specified, available target are:\n" ."\t --target => target (specify wich setup to run [(default)$sValidTarget])\n"; exit; @@ -96,9 +96,9 @@ sub Main { ); my $sBasedir = getcwd; #for setupdb - if($sTarget =~ /All|Inst/){ InstallSoft(); } - if($sTarget =~ /All|Conf/) { ConfigConf(\%hDefConf); chdir "$sBasedir"; } - if($sTarget =~ /All|DB/) { ConfigDB(\%hDefConf); chdir "$sBasedir"; } + if($sTarget =~ /All|Inst/i){ InstallSoft(); } + if($sTarget =~ /All|Conf/i) { ConfigConf(\%hDefConf); chdir "$sBasedir"; } + if($sTarget =~ /All|DB/i) { ConfigDB(\%hDefConf); chdir "$sBasedir"; } 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"; } @@ -107,7 +107,7 @@ sub InstallSoft { print "\n Starting InstallSoft \n"; print "This autoinstall feature is experimental, package name varies from distri and version, couldn't support them all\n"; #yes we could $^0 or uname -r but $^0 only give perl binary build OS and uname hmm... - my @aSupportedOS = ("Debian","Ubuntu","Fedora","CentOs"); + my @aSupportedOS = ("Debian","Ubuntu","Fedora","CentOs","FreeBSD"); my $sOSregex = join("|",@aSupportedOS); my $sOS; until($sOS =~ /$sOSregex/i){ @@ -122,9 +122,21 @@ sub InstallSoft { system("sudo apt-get install @aListSoft"); } elsif($sOS =~ /Fedora|CentOs/i){ #tested on fedora 18 - my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","subversion","mysql-server","phpmyadmin","pcre-devel"); + my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","subversion","mysql-server","mysql-devel","phpmyadmin","pcre-devel"); system("sudo yum install @aListSoft"); } + elsif($sOS =~ /FreeBSD/i){ #tested on FreeBSD 9.01 + system("portsnap fetch extract && portsnap update"); #fetch port lib and extract + my @aDevel = ("binutils","subversion","autoconf","pcre","gmake","gdb"); + foreach(@aDevel){ + system("cd /usr/ports/devel/$_ && make install clean"); #install devels + } +# system("cd /usr/ports/lang/gcc46 && make install"); #gcc4.6 use latest ? 4.8 ? + system("cd /usr/ports/databases/mysql55-server && make install clean"); + #other utils ? + system("cd /usr/ports/www/wget && make install clean"); + system("cd /usr/ports/archivers/unrar && make install clean") + } } sub ConfigConf { my ($rhDefConf) = @_; diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000000..cb718007a9 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,23 @@ +#!/bin/sh +#source var/function +. ./function.sh +echo "My pkg path is $PKG_PATH" + +check_inst_right +read -p "WARNING: This target dis experimental. Press Ctrl+C to cancel or Enter to continue." readEnterKey +case $1 in + 'bin') + echo "Starting binary cleanup" + rm -rf $PKG_PATH/bin/* + echo "Binary file was deleted" + ;; + 'all') + echo "Starting uninstalling " + rm -rf $PKG_PATH + rm -rf /usr/bin/$PKG + echo "Uninstallation succed" + ;; + '*') + echo "Please enter a target usage './uninstall { all | bin }'" +esac +