#!/usr/bin/env 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; # } # } #} sub debug() { 0 } # append something while testing #my $test = "-NEW"; #use Data::Dumper; sub say { print join('', @_); # if $test; } sub sys { print join(' ', @_), "\n" if debug; if (system(@_)) { if ($? == -1) { print "\t{failed to execute: $!}\n"; } elsif ($? & 127) { printf "\t{command died with sig %d, %s core dump}\n", ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "\t{command exited with value %d}\n", $? >> 8; } exit $? if $?; exit $@ if $@; } } ### MAIN ### # if you are manually compiling an ldmud, rename it or change here. my $driver = 'psyclpc'; my $newbie = 0; 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*$/; $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 $execs = "$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 $execs/$driver\n"; unless (-x $execs && -x "$execs/$driver") { $execs = "$base/bin-$_type_system"; say "Looking for driver in $execs/$driver\n"; unless (-x $execs && -x "$execs/$driver") { $execs = "$base/bin-linux"; say "Looking for driver in $execs/$driver\n"; unless (-x $execs && -x "$execs/$driver") { $execs = "$base/bin"; say "Looking for driver in $execs/$driver\n"; unless (-x $execs && -x "$execs/$driver") { $execs = "/usr/local/sbin"; say "Looking for driver in $execs/$driver\n"; unless (-x $execs && -x "$execs/$driver") { $execs = "/usr/sbin"; say "Looking for driver in $execs/$driver\n"; 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 = "$execs/$driver -DDEBUG=$db"; my $torify = ""; 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 say "Your hostname will be assigned as $fqdn.\n"; if ($c{_basic_host_domain} eq 'onion') { $torify = "torsocks"; say "Enabling PSYC federation over Tor: Using " . "torsocks wrapper around psyced.\n"; say "Warning: Make sure either dnsmasq.conf or " . "unbound.conf are in\n" . "place for .onion resolution to function.\n"; } } ## 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 <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 <', $t or die "Cannot write to $t"; print O <