Complete.Org: Mailing Lists: Archives: freeciv: July 2004:
[Freeciv] Re: Help---default save dir
Home

[Freeciv] Re: Help---default save dir

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv@xxxxxxxxxxx
Subject: [Freeciv] Re: Help---default save dir
From: rp@xxxxxxxxxx (Reinier Post)
Date: Fri, 30 Jul 2004 19:17:53 +0000 (UTC)

Joshua Laferriere wrote:

>Thanks for taking your time to answer this question, I looked in the faq an=
>d didn't see anything on the issue, where is the default save dir?

It is the current directory at the time the server excutable was started.
Perhaps you find the following wrapper helpful.  Note that two more
auxiliaries follow.  I think they will pass through Usenet unharmed
but you have to split them up yourself.  (I'm not going to use shar.)

#!/bin/sh
#
# cs - start a civserver
#
# this script differs from 'ser' in two ways:
#
# - it uses $FREECIV_PATH or its default to locate a civserver binary
# - it uses separate working directories to store the game data
#
# $Id: cs,v 1.11 2003/09/19 20:46:04 gamecvs Exp $

# if a working directory is supplied in $CSDIR, it will use that

#exec > /tmp/cs.$$.log 2>&1; set -x  # temporary, I hope - rp
  # problem: this will leave civserver.out empty

# remember the default location of civserver

# find civserver in $PATH; don't use which, it's poisoned on Solaris
#
for d in `echo "$PATH" | sed 's/:/  /g'`
do
  if [ -x $d/civserver ]
  then
    if expr X"$d" : X/ >/dev/null  # it's an absolute path
    then
      civserver=$d/civserver
    else
      civserver=`/bin/pwd`/$d/civserver
    fi
  fi
done

PATH=/bin:/usr/bin; export PATH
me=`basename $0`

#--- config ---#
#

playground=$HOME/.freeciv/games
cwd=`/bin/pwd`
default_freeciv_path=$cwd/data:$cwd/share/freeciv:$HOME/.freeciv:$HOME/.freeciv/data:$HOME/.freeciv/share
  # we should use what Freeciv uses, I suppose

Die()
{
  echo "$me: fatal error: $@" 1>&2
  exit 1
}

Remark()
{
  echo "$me: $@" 1>&2
}

newsubdir=`dirname $0`/newsubdir
civpath2server=`dirname $0`/civpath2server

[ -x $newsubdir ]  || Die "cannot find required executable '$newsubdir'"
[ -x $civpath2server ]  || Die "cannot find required executable 
'$civpath2server'"
[ -d $playground ] || mkdir -p "$playground" ||
  Die "cannot cd to working directory '$playground'"


#--- set $FREECIV_PATH if not set yet ---#
#

[ X != X"$FREECIV_PATH" ] || FREECIV_PATH=$default_freeciv_path
export FREECIV_PATH

civserver=`$civpath2server` ||
    Die "cannot find a civserver binary along \$FREECIV_PATH '$FREECIV_PATH'"

Remark "using binary '$civserver'"


#--- create a separate working directory for this game and run it there ---#
#

(cd $playground || Die "cannot cd to $playground/")
[ $? -eq 0 ] || exit $?

if [ X != X"$CSDIR" ]
then
  # use $CSDIR
  [ -d "$CSDIR" ] || Die "working dir $CSDIR is not a directory"
  [ -w "$CSDIR" ] || Die "working dir $CSDIR is not writable"
  d="$CSDIR"
else
  d=`$newsubdir $playground`
  [ $? = 0 ] && [ X != X"$d" ] || Die "cannot create working directory '$d'"
fi

Remark "using directory '$d'"

cd $d || Die "cannot cd to '$d'"

env > $d/env
echo $civserver "$@" > $d/cmdline

$civserver "$@"
exit $?

#
#--- end of script


#!/bin/sh
#
# newsubdir - creates a new subdir in the given dir, and returns its name
#
# $Id: newsubdir,v 1.2 2001/08/14 18:59:51 gamecvs Exp $

# the subdir is created so we have the effect of 'locking'
# (although it isn't perfect)

PATH=/bin:/usr/bin:/usr/ucb; export PATH

me=`basename $0`

Die()
{
  echo "$me: fatal error: $@" 1>&2
  exit 1
}

d=$1

[ X != X"$d" ] || Die "supply a directory as argument"
[ -d $d ]      || Die "argument must be an existing directory"
cd $d          || Die "cannot cd to $d"


nextdir="`ls -t | grep '^[0-9][0-9]*$' | sort -n | tail -1`"
case "$nextdir" in
"")
  nextdir=0
  ;;
*)
  nextdir=`expr "$nextdir" + 1`
 ;;
esac

while :
do
  mkdir $nextdir 2>/dev/null && break  # success
  [ -d $nextdir ]            || Die "cannot create subdir '$d/$nextdir'"
  nextdir=`expr "$nextdir" + 1`
done

echo "$d/$nextdir"

#
#--- end of script ---#


#!/bin/sh
#
# civpath2server - returns a civserver binary along $FREECIV_PATH
#
# $Id: civpath2server,v 2.1 2002/10/30 13:18:10 gamecvs Exp $

IFS=:

for fp in $FREECIV_PATH
do
  if [ ! -d $fp/default ]
  then
    continue
  fi

  for d in $fp $fp/.. $fp/../server $fp/../bin $fp/../../bin
  do
    if [ -x $d/civserver ]
    then
      echo $d/civserver
      exit 0
    fi
  done
done

#echo no civserver binary found for \$FREECIV_PATH $FREECIV_PATH 1>&2
  # leave this to the callers

exit 1



[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv] Re: Help---default save dir, Reinier Post <=