These are the scripts I use to start freenet, update unstable,
and to mail fred status to Toad.

Use ./start-freenet --unstable

These attempt to avoid downloading the same snapshots repeatedly,
but because the snapshots directory doesn't avoid changing the
creation time of files which haven't changed, they get download
anyway.

eaa106aa562ae8ac6aacf7f041ef7832  start-freenet.sh
266a956cabc0e8f20d6016a7d135b572  update-unstable.sh
a0ae761d71e48097617a2becfb8a9f6d  mailFredStatus
27f3573bbf0a39946e66df6b6b767470  mailFredStatus.asc

-- 
Edward J. Huff <[EMAIL PROTECTED]>
#!/bin/sh

# timestamping sets the correct date on the retrieved file and avoids
# retrieving it if the remote date is not newer.  Does not work correctly
# together with the -O option for specifying a new output filename.
cp -pf freenet-unstable.jar freenet-unstable-latest.jar
wget --timestamping http://freenetproject.org/snapshots/freenet-unstable-latest.jar
# test -s FILE
#  FILE exists and has a size greater than zero
if test -s freenet-unstable-latest.jar; then
    # if new file is different from the old one, make backup.
    if ! cmp freenet-unstable-latest.jar freenet-unstable.jar; then
        mv -f freenet-unstable.jar freenet-unstable-old.jar
	echo 'old freenet-unstable.jar saved'
    fi
    # always use the date/time from the project site.
    mv freenet-unstable-latest.jar freenet-unstable.jar
else
    rm -f freenet-unstable-latest.jar
fi
cp -pf seednodes-unstable.ref unstable.ref
wget --timestamping http://freenetproject.org/snapshots/unstable.ref
ls -l unstable.ref
if test -s unstable.ref; then
    if ! cmp unstable.ref seednodes-unstable.ref; then
        mv -f seednodes-unstable.ref unstable-old.ref
	echo 'old unstable seednodes file saved'
    fi
    cp -pf unstable.ref seednodes-unstable.ref
else
    cp -pf seednodes-unstable.ref unstable.ref
fi
cp -pf seednodes-unstable.ref seednodes.ref
touch -t "197001011200" seednodes.ref || touch -d "1/1/1970" seednodes.ref
# so we don't reseed unless necessary
ls -l freenet*.jar seednodes*.ref
#!/bin/sh

if [ -f freenet.pid ] ; then
  echo stopping freenet process id `cat freenet.pid`
  kill `cat freenet.pid`
  sleep 1
  while ps -p `cat freenet.pid` | grep "^`cat freenet.pid` "; do
      echo "Freddy isn't dead yet!"
      ps -fp `cat freenet.pid`
      sleep 5
  done
  rm freenet.pid
fi

FREENET_JAR=freenet.jar
JAVA_MEMORY='-Xmx256m'

while [[ $# > 0 ]] ; do
    case "$1" in
	--jar)
	    FREENET_JAR=$2
	    shift;;
	--meg|Meg|MEG)
	    JAVA_MEMORY=-Xmx${2}m
	    shift;;
	--sta*)
	    FREENET_JAR=freenet-stable.jar
	    ;;
	--uns*)
	    FREENET_JAR=freenet-unstable.jar
	    ;;
	--exp*)
	    FREENET_JAR=freenet-exp.jar
	    ;;
	--cvs)
	    FREENET_JAR=freenet-cvs.jar
	    ;;
    esac
    shift
done

# Check to see whether we use echo -n or echo "\c" to suppress newlines.
case "`echo 'hi there\c'; echo ' '`" in
  *c*) n='-n'; c='';;
  *)   n=''; c='\c';;
esac

# and get java implementation too, Sun JDK or Kaffe
JAVA_IMPL=`java -version 2>&1 | head -1 | cut -f1 -d' '`

if test ! -f freenet-ext.jar; then
  echo freenet-ext.jar not found.  It can be downloaded from
  echo http://freenetproject.org/snapshots/freenet-ext.jar
  echo
  echo $n "Would you like me to download it now? [Y/n] $c"
  read resp
  case "$resp" in
    [Nn]*) exit 0;;
  esac
  wget http://freenetproject.org/snapshots/freenet-ext.jar
  if test ! -f freenet-ext.jar; then
    echo "Sorry, I couldn't download it.  Aborting."
    exit 1
  fi
fi

CLASSPATH=fec-linux-x86.jar:$FREENET_JAR:freenet-ext.jar:$CLASSPATH 
export CLASSPATH
# Why are we permanently altering the environment?
# We aren't.  This change affects only this process and it's children.
# Environment changes in scripts do not propagate to the invoking shell
# unless the script is run using the "source" (or ".") command.

if test ! -f seednodes.ref; then
  echo seednodes.ref not found, would you like to download some seeds
  echo from http://hawk.freenetproject.org/~freenet4/seednodes.ref?
  echo $n "[y/N] $c"
  read resp
  case "$resp" in
    [yY]*) wget http://hawk.freenetproject.org/~freenet4/seednodes.ref;;
  esac
fi

if test ! -f freenet.conf; then
  echo It appears that this is your first time running Freenet.  You
  echo should read the README file as it contains important instructions
  echo and advice.
  echo
  echo First we must generate a freenet.conf file.  I will now run
  echo Freenet in configure mode, and it will ask you a number of
  echo questions.  If you don\'t understand the question, hitting "enter"
  echo without typing anything will go with the default which is likely
  echo to be the right thing.
  echo
  sh preconfig.sh
  java freenet.node.Main --config
fi

# if Sun JDK set -server option as suggested on mailing list
#if java -help 2>&1 | grep "[-]server" >/dev/null ;
#then
#  JAVA_ARGS="-server"
#else
#  JAVA_ARGS=""
#fi
# multiple reports that -server option seems to cause crashes
if test /etc/redhat-release
then
  export LD_ASSUME_KERNEL=2.4.1
fi
if [ -f freenet.log ] ; then
    echo "Saving old log file"
    logfilename=freenet-$(ls -l --time-style=full-iso freenet.log | gawk '{print $6"-"$7}').log
    mv freenet.log $logfilename
    ls -l $logfilename
    gzip $logfilename
    ls -l $logfilename.gz
fi
echo
echo "JVM environment:"
java freenet.node.Main --system
echo 
echo "Freenet version:"
java freenet.node.Main --version
echo
echo "Non-default non-bookmark freenet.conf settings:"
grep '^[ 	]*[a-zA-Z]' freenet.conf | grep -v bookmark
echo JAVA_MEMORY=$JAVA_MEMORY
echo '$@ is '\'"$@"\'
echo $n "Starting Freenet now: `date --utc` `date '+%H:%M:%S %Z: '`$c"
nice -n 10 -- java $JAVA_MEMORY $JAVA_ARGS freenet.node.Main "$@" &
echo $! > freenet.pid
echo "Done, freenet process id is `cat freenet.pid`."
(
echo LD_ASSUME_KERNEL=$LD_ASSUME_KERNEL
echo CLASSPATH=$CLASSPATH
echo JAVA_IMPL=$JAVA_IMPL
echo JAVA_MEMORY=$JAVA_MEMORY
echo JAVA_ARGS=$JAVA_ARGS
echo '$@ is '\'"$@"\'
ls -l --full-time $FREENET_JAR
echo nice -n 10 -- java $JAVA_MEMORY $JAVA_ARGS freenet.node.Main "$@"
ls -l --full-time freenet.pid
echo "Freenet process id is `cat freenet.pid`"
) > freenet.last-startup
#!/bin/bash

# if you edit your copy of this script, change the version.
VERSION='$Id: mailFredStatus,v 1.3 2003/10/22 21:15:22 ejhuff Exp $'

printMailHeaders() {
    echo "To: $TO"
    echo "From: $FROM"
    echo "Errors-To: $FROM"
    echo "Bcc: $BCC"
    echo "Subject: Success probabilities $(date --utc)"
    echo
}

printAssortedData() {
    echo $VERSION
    echo SERVLET=$SERVLET
    date --utc
    wget -O - "http://$SERVLET/servlet/nodeinfo/performance/general"; 2>/dev/null \
	| tr -d "\n" \
	| sed 's/<tr>/@<tr>/g' \
	| sed 's|</tr>|</tr>@|' \
	| sed 's/<[^>]*>/ /g; s/ * @/@/g; s/@  */@/g; s/   */ /g' \
	| sed 's/Uptime[@ ]*&nbsp;/Uptime /g' \
	| tr '@' "\n" \
	| egrep 'Version|Build|Uptime|Current|Active' \
	| grep -v 'README'
    wget -O - "http://$SERVLET/servlet/nodeinfo/networking/ocm?setLevel=1&setMode=new"; 2>/dev/null \
	| egrep '^<tr><td>[^<]' \
	| sed 's/<[^>]*>/ /g; s/^  *//g; s/   */ /g; s/&nbsp;/ /g'
    echo
    echo "Network Load:"
    wget -O - "http://$SERVLET/servlet/nodeinfo/networking/loadstats"; 2>/dev/null \
	| sed 's/<[^>]*>/ /g; s/^  *//g; s/   */ /g; s/&nbsp;/ /g' \
	| grep '^[A-Za-z() ]*:'
    # FIXME:  how to tell re: Frost etc.
    echo "Frost etc. are not running."
    echo "Traffic shaping:"
    echo $TC '-s qdisc show dev eth0 | head -3'
    $TC -s qdisc show dev eth0 | head -3
    echo Non-default non-bookmark freenet.conf lines
    grep '^[a-zA-Z]' freenet.conf | grep -v bookmark
    echo 
    echo Parameters to last startup:
    ls -l --full-time freenet.last-startup
    cat freenet.last-startup
    echo
    echo "$NETSTAT -n --inet | egrep -v :6000\|:8888\|\^tcp\ \*0\ \*0\  | grep ESTAB | sort -k 2nr,2 -k 3nr,3"
    $NETSTAT -n --inet | head -2
    $NETSTAT -n --inet | egrep -v :6000\|:8888\|\^tcp\ \*0\ \*0\  | grep ESTAB | sort -k 2nr,2 -k 3nr,3
    echo
    wget -O - http://$SERVLET/servlet/nodestatus/psuccess_data.txt 2>/dev/null
    echo
    wget -O - http://$SERVLET/servlet/nodeinfo/internal/env 2>/dev/null \
	| grep '^<tr><td>' \
	| sed 's/<[^>]*>/ /g; s/^  *//g; s/   */ /g' \
	| egrep 'Architecture|processors|Operating|Version|JVM|Maximum|Percent|Total'
    echo
    wget -O - http://$SERVLET/servlet/nodestatus/nodestatus.html 2>/dev/null \
	| grep '^<tr><td>' \
	| grep -v '<b>' \
	| sed 's/<[^>]*>/ /g; s/^  *//g; s/   */ /g'
    echo
    wget -O - http://localhost:8888/servlet/nodestatus/diagnostics/requestSuccessRatio/raw 2>/dev/null \
	| egrep 'minute|#'
    wget -O - http://localhost:8888/servlet/nodestatus/diagnostics/requestSuccessRatio/raw 2>/dev/null \
	| grep hour | tail -3
    echo
    wget -O - http://localhost:8888/servlet/nodestatus/diagnostics/routingSuccessRatio/raw 2>/dev/null \
	| egrep 'minute|#'
    wget -O - http://localhost:8888/servlet/nodestatus/diagnostics/routingSuccessRatio/raw 2>/dev/null \
	| grep hour | tail -3
    echo
    wget -O - http://localhost:8888/servlet/nodestatus/diagnostics/localQueryTraffic/raw 2>/dev/null \
	| egrep 'minute|#'
    wget -O - http://localhost:8888/servlet/nodestatus/diagnostics/localQueryTraffic/raw 2>/dev/null \
	| grep hour | tail -3
    date --utc
}

[ -z "$TO" ] && TO="Toad <[EMAIL PROTECTED]>"
[ -z "$FROM" ] && FROM="[EMAIL PROTECTED]:-localhost}"
[ -z "$BCC" ] && BCC="[EMAIL PROTECTED]:-localhost}"
[ -z "$INTERVAL" ] && INTERVAL=3600
[ -z "$SERVLET" ] && SERVLET=127.0.0.1:8888
[ -z "$FREENETHOME" ] && FREENETHOME=$HOME/freenet/
[ -z "$VERBOSE" ] && VERBOSE=
[ -z "$GOLIVE" ] && GOLIVE=
[ -z "$SENDMAIL" ] && SENDMAIL=/usr/sbin/sendmail
[ -z "$TC" ] && TC=/sbin/tc
[ -z "$NETSTAT" ] && NETSTAT=/bin/netstat

HELP=
WRITEDEFAULTS=

if [ -f ~/.mailFredStatus ] ; then
    source ~/.mailFredStatus
fi

while [[ $# > 0 ]] ; do
    case "$1" in
	--to)
	    TO=$2
	    shift;;
	--from)
	    FROM=$2
	    shift;;
	--BCC)
	    BCC=$2
	    shift;;
	--interval)
	    INTERVAL=$2
	    shift;;
	--servlet)
	    SERVLET=$2
	    shift;;
	--FreenetHOME|--freenetHOME|--FreeNetHOME|--freenethome)
	    FREENETHOME=$2
	    shift;;
	--verbose)
	    VERBOSE=-v
	    ;;
	--sendmail)
	    SENDMAIL=$2
	    shift;;
	--tc)
	    TC=$2
	    shift;;
	--netstat)
	    NETSTAT=$2
	    shift;;
	--dryrun)
	    GOLIVE=
	    ;;
	--golive)
	    GOLIVE=TRUE
	    ;;
	--v*|--V*|-v|-V)
	    echo $VERSION
	    echo mailFredStatus --help for help.
	    exit 0
	    ;;
	--write*|-w*)
	    WRITEDEFAULTS=TRUE
	    ;;
	--h*|-h*)
	    HELP=TRUE
	    ;;
	*)
	    HELP=TRUE
	    echo "$1 interpreted as --help"
	    ;;
    esac
    shift
done

if [ ! -z "$WRITEDEFAULTS" ] ; then
    echo "Making current options the defaults in ~/.mailFredStatus"
    (cat <<EOF
    TO="$TO"
    FROM="$FROM"
    BCC="$BCC"
    INTERVAL="$INTERVAL"
    SERVLET="$SERVLET" 
    FREENETHOME="$FREENETHOME"
    VERBOSE="$VERBOSE"
    SENDMAIL="$SENDMAIL"
    TC="$TC"
    NETSTAT="$NETSTAT"
    GOLIVE="$GOLIVE"
EOF
    ) > ~/.mailFredStatus
    echo New contents of ~/.mailFredStatus:
    cat ~/.mailFredStatus
    echo
    echo Done.
    exit 0
fi

if [ ! -z "$HELP" ] ; then
    
# will do $VAR substitution in the text.
    cat <<EOF

NAME

    mailFredStatus - Mail Freenet REference Daemon status to Toad

SYNOPSIS

    mailFredStatus [ --help | -h | --version | -v ]

    mailFredStatus [ --to '$TO' ] 
	[ --from '$FROM' ] 
        [ --BCC '$BCC' ]
        [ --interval '$INTERVAL' ] 
        [ --servlet '$SERVLET' ] 
        [ --FreenetHOME '$FREENETHOME' ]
        [ --dryrun | --golive ]
        [ --sendmail '$SENDMAIL' ]
        [ --tc '$TC' ]
        [ --verbose ]
        [ --writedefaults ]

DESCRIPTION

    mailFredStatus will collect status information from
    the Fred FProxy server at localhost:8888, from freenet.conf,
    and from netstat, and mail it to Toad once an hour.

    The command never exits unless interrupted or killed.
    Uses sleep to delay, so intervals are approximate.

    The --golive option must be specified to actually
    send any mail.  To make --golive the default, use
    this command, with desired defaults specified.

        mailFredStatus [defaults] --golive --writedefaults

    This will not actually go live, but the next time
    mailFredStatus is invoked, it will start running.

    --verbose will cause the -v option to be passed
    to $SENDMAIL.

FILES

    ~/.mailFredStatus  

        If ~/.mailFredStatus exists then this script
        sources it.  It should assign default values to
        the environment variables.  The --writedefaults
        will overwrite any existing ~/.mailFredStatus
        specifying the options from the command line as
        the new defaults.  Remove the file to use the
        original defaults.

ENVIRONMENT

    PATH must include wget head egrep grep sort sed date

    If exported to the environment, these environment variables
    will be used as the defaults for the corresponding options.
    Or, if defined in ~/.mailFredStatus, then those values
    will override environment or script defaults.
    They do not override command line options.
    Shown are the values which were in effect after
    processing the command line which caused this printout.

    TO="$TO"
    FROM="$FROM"
    BCC="$BCC"
    INTERVAL="$INTERVAL"
    SERVLET="$SERVLET" 
    FREENETHOME="$FREENETHOME"
    VERBOSE="$VERBOSE"
    SENDMAIL="$SENDMAIL"
    TC="$TC"
    NETSTAT="$NETSTAT"
    GOLIVE="$GOLIVE"

AUTHOR

    Edward J. Huff <[EMAIL PROTECTED]>  ejhuff on sourceforge.
    Report problems on the Freenet devloment list:

    Discussion of development issues <[EMAIL PROTECTED]>

FEATURES

    Only works on Linux.  Uses bash-isms.
    Uses wget to read data from servlet on port 8888.

BUGS

    Extracts data from web pages, so that innocent changes
    to fproxy formatting may break this script.  

    Isn't written in [ perl | java | /bin/sh | ... ]

    Uses sendmail to send mail.

VERSION

    $VERSION

EOF
    exit 0
fi

echo Changing directory to $FREENETHOME
cd $FREENETHOME
if [[ -z "$GOLIVE" ]] ; then
    echo This is a dry run.  
    echo To go live, you must specify --golive.
    echo To make --golive the default, specify --golive --writedefaults.
    echo Mail headers would be:
    printMailHeaders
    echo
    echo The mail body would be:
    printAssortedData
    exit 0
fi

echo
echo Mail headers will be:
printMailHeaders
echo
echo "Type ^C to abort.  First mail goes out in about $INTERVAL seconds."
echo -n "That will be about "
date --date "today $INTERVAL seconds"

while true; do
    sleep $INTERVAL
    (
	printMailHeaders
	printAssortedData
	echo '.'
    ) | $SENDMAIL $VERBOSE -t -f "$FROM"
done
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQA/lvsRJfKDstX6FxkRAid+AKDLdA6DmhMRTtF/mC76gPxKB1BX9QCgoWfa
ghAsHxihjX7XXQGhQGvcXCo=
=mU7C
-----END PGP SIGNATURE-----

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Devl mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to