#!/usr/bin/perl ### -I/opt/psyced/utility # the include path would help finding INI.pm, but what if you the user # have decided to install psyced elsewhere? # # psyconf(8) - tool that generates psyc configuration # files out of a common psyced.ini # # $Id: psyconf,v 1.80 2008/10/26 15:24:01 lynx Exp $ =head1 NAME psyconf - a configuration tool for PSYCED =head1 SYNOPSIS Usage: psyconf [ ] The default configuration file used is either ./psyced.ini or /etc/psyc/psyced.ini =cut use File::Spec; # this approach still doesn't work when installing on gentoo # we need a seperate ebuild for INI.pm. until then we will use # the stupid parser # #BEGIN { # BEGIN just in case somebody ever accesses INI::something by hand # unless (%INI::) { # get INI, if it isn't in this file (somewhere above) # my @dir; # my $inilocation; # # @dir = File::Spec->splitdir($0); # pop @dir; # $inilocation = File::Spec->catfile(@dir, qw".. utility INI.pm"); # # if (-f $inilocation) { # require $inilocation; # } else { # require INI; # } # } #} # append something while testing #my $test = "-NEW"; use Data::Dumper; sub say { print join('', @_); # if $test; } ### MAIN ### # if you are manually compiling an ldmud, rename it or change here. my $driver = 'psyclpc'; use Getopt::Std; &getopt; print STDERR '$Id: psyconf,v 1.80 2008/10/26 15:24:01 lynx Exp $', "\n"; my $conf = shift || 'psyced.ini'; $conf = '/etc/psyc/psyced.ini' unless -r $conf; # should we complain if two psyced.ini files exist? # lymeca got confused at this point, expecting the systemwide # psyced.ini to be used, but actually having a local copy say "The PSYCED configuration tool. Looking at $conf\n\n"; # this is the super-duper fancy amazing INI handler # #use INI; # ":verbose"; # my %c; # tie(%c, INI, $conf, 5); # and this is the stupider INI parser in a couple of lines # cute, but we'd like to have the features of INI.pm one happy day my %c, $f = ""; open C, $conf; while() { next if /^;/; next if /^\s*$/; $f = $1, next if /^\[(\w+)\]\s*$/; # Room name 'ornia ' is not permitted. # isn't this stripping trailing whitespace properly? # should it read \S.+\S ? or at least .+\S ? $c{"$f$1"} = $2, next if /^(\w+)\s*=\s*(.+)\s*$/; die "cannot parse line $. in $conf:\n\t$_\n"; } close C; if ($opt_D) { if ($c{_basic_list_script_init}) { foreach (split /\s+/, $c{_basic_list_script_init}) { say "Deinstallation! Removing $_\n"; unlink $_; } } exit; } use POSIX; my @uname = POSIX::uname(); # if POSIX.pm is unavailable, this also works: # @uname = split ' ', `uname -s -r -n -m -v`; #print Dumper(@uname); my $_type_machine = $uname[$#uname]; $_ = $uname[2]; /^(\w+\.\w+)\b/ or /^(\w+)\b/; my $_type_system = "\L$uname[0]\E"; my $_version_system = "$uname[0]/$1"; my $_type_architecture = lc "$_type_machine-$uname[0]"; say "Machine Type: $_type_machine. OS Type: $_type_system. ", "Arch: $_type_architecture\n"; #Typical outputs: # Machine Type: i686. OS Type: linux. Arch: i686-linux # Machine Type: x86_64. OS Type: linux. Arch: x86_64-linux # Machine Type: Power Macintosh. OS Type: darwin. Arch: power macintosh-darwin my $base = $c{_basic_path_base}; die "_basic_path_base not defined in config" unless $base; die "Base directory $base defined as _basic_path_base not available" unless -x $base; my $sandbox = "$base/world"; die "psyced library $sandbox does not exist" unless -x $sandbox; my $arch = "$base/bin-$_type_architecture"; my $config = $c{_basic_path_configuration} || $base; # this isn't taking $ARCH_DIR from install.sh into account # but maybe it shouldn't anyway.. say "Looking for driver in $arch/$driver\n"; unless (-x $arch && -x "$arch/$driver") { $arch = "$base/bin-$_type_system"; say "Looking for driver in $arch/$driver\n"; unless (-x $arch && -x "$arch/$driver") { $arch = "$base/bin-linux"; say "Looking for driver in $arch/$driver\n"; if (-x $arch && -x "$arch/$driver") { say "\nBug in $0: We didn't find $base/bin-linux in the appropriate way.\nThat's not nice. Continuing however.\n" } elsif (not -x ($arch = "$base/bin") && -x "$arch/$driver") { say "Looking for driver in $arch/$driver\n"; # bad place for psyclpc really.. # since it is usually of no commandline use # but where else should psyclpc.ebuild # install it? in /opt/psyclpc? for two files? $arch = "/usr/sbin"; say "Looking for driver in $arch/$driver\n"; # the following is very unlikely to happen: die <', $t or die "Cannot write to $t"; print O <; } else { foreach (split /\s+/, $c{_administrators_list_nicks}) { my $ni = lc($_); push @adm, $ni; $t = "$base/data/person/$ni.o$test"; next if -e $t; say "Creating administrator in $t\n"; open O, '>', $t or die "Cannot write to $t"; my $pw = $c{_administrators_password_default}; unless ($pw) { print STDERR "Please input a password for $_: "; $pw = ; chomp $pw; } print O <', $t or die "Cannot write to $t"; print O <', $t or die "Cannot write to $t"; my $db = $c{_optional_level_debug} || '0'; my $psyced = "$arch/$driver -DDEBUG=$db"; my $debugfile; if ( $c{_optional_use_file_debug} ) { $debugfile = "$sandbox/log/psyced.debug"; $psyced .= " --debug-file ". $debugfile; # since psyclpc 4.0.4 backtraces are also in the regular console log.. yippie! # say "ATTENTION: $debugfile will contain runtime error backtraces.\n"; } # else: ldmud tries to create $hostname.debug.log in $sandbox # psyclpc is good boy instead. so we can keep this optional. my $hc = 0; ## ldmud bug number one: you have to provide hostname AFTER hostaddr if ($c{_basic_host_IP} =~ /^[0-9\.]+$/) { $psyced .= " --hostaddr $c{_basic_host_IP}"; $hc = 1; # problem? } if ($c{_basic_host_domain} and $c{_basic_host_name}) { my $fqdn = "$c{_basic_host_name}.$c{_basic_host_domain}"; $psyced .= " --hostname $fqdn"; $hc = 0; # no problem } ## ldmud bug number two #WARNING: Because of some funny bug the driver will probably not bind properly #to _basic_host_IP as it also needs _basic_host_name and _basic_host_domain #to be provided. Hopefully this shortcoming will soon be history. #In the meantime please re-edit the psyced.ini to provide all variables. print STDERR < press enter)" ## (cd $sandbox/.. && cvs login && cvs -q update -dP && cvs logout) echo "" echo "Fetching update from public git repository..." echo "" (cd $sandbox/.. && git fetch origin) echo "" echo "You can now read the changes using ${hi}\$0 -d${lo}" echo "or activate the changes using ${hi}\$0 -m${lo}" fi if ! test -e $sandbox/status-0-beta-OK then echo "" echo "${hi}ATTENTION:${lo}" echo "The version of psyced you are using is outdated. You cannot" echo "get new updates because of incompatibility." echo "" echo "More information following.." echo "" cat $sandbox/status-0-DEPRECATED echo "" echo "The file you just saw is: ${hi}${lib}/status-0-DEPRECATED${lo}." exit 1 else echo "It may be a good idea to run ${hi}\$0${lo} again before you continue." fi exit fi if test "\$1" = "-d" then ## (cd $base && cvs -q diff -ur HEAD|\$PAGER) (cd $base && git diff master..origin/master | \$PAGER) exit fi if test "\$1" = "-m" then # git is seriously unsuited for this job. we need to "check in" the changes # to file permissions etc or otherwise we can't update things at all... (cd $base && git commit -a -m 'automatic by psyced -m') # merging will of course fail.. sigh (cd $base && git merge -s resolve origin) exit fi # if your ldmud is too old, it may not understand --pidfile and --tls-* commandline="$psyced -s 0 -s v0 --swap-file $base/psyced.swap --erq $arch/erq --pidfile $sandbox/data/$driver.pid -m $sandbox -u $portUDP $ports" # keep the pid of this wrapper process, too echo \$\$ >data/psyced.pid # neat feature of gnu mv VERSION_CONTROL=numbered; export VERSION_CONTROL # rm'ing this allows the administrator commands in psyced to stop the loop touch $sandbox/data/.autorestart while [ -r $sandbox/data/.autorestart ] do X # we can presume gnu mv on linux #my $domv = $_type_system eq 'linux' ? 'mv -b' : 'mv -f'; # yes, but all these backups are overkill # who needs these debug logs archived for all eternity anyway? my $domv = 'mv -f'; # maybe we should develop a strategy for all the OTHER logfiles..... # but luckily psyclpc has some support for that itself print O <>$sandbox/log/psyced.out date >>$sandbox/log/psyced.out echo ---------------------------------------- >>$sandbox/log/psyced.out \$commandline >>$sandbox/log/psyced.out 2>>$sandbox/log/psyced.err X } print O <', $t or die "Cannot write to $t"; print O </dev/null 2>&1 kill -3 \`cat $sandbox/data/psyced.pid\` && echo "OK" fi ;; kill) echo -n "Killing psyced brutally ... " kill -3 \`cat $sandbox/data/psyced.pid\` && echo "OK" ;; restart) echo -n "Instructing psyced to restart ... " kill -1 \`cat $sandbox/data/$driver.pid\` && echo "OK" ;; status) ;; *) echo "Usage: \$0 {start|stop|restart|kill}" exit 1 ;; esac X close O; chmod 0744, $t; if ($c{_basic_list_script_init}) { foreach (split /\s+/, $c{_basic_list_script_init}) { say "... copying to $_\n"; `cp "$t" "$_"`; } } chdir "$sandbox/net/place" or die "Where is my net/place? $!"; ## start of former archetype.pl # generate psyced place models using combinations of archetype flags my @opts, @predef, %map; open(I, "archetype.gen") or die <) { if (m!define\s(\w+)\s*//\s\[(.)\]!) { if ($2 eq '+') { push @predef, $1; } else { $map{$2} = $1; push(@opts, $2); } } elsif (/^#endif/) { last; } } close I; print "Generating archetype place models...\n"; # print join("\n", @opts), "\n\n"; # print "$_\n" foreach ( %map ); open (O, ">../include/place.i") or die $!; print O <.cvsignore") or print <_$f.c") or die $!; # proud and noisy.. for a week or two at least ;) #echo loading model '_$f' generated by '$0' print O <