#!/bin/bash

# generate filename without directory:
FILENAME=$(basename $0)
CAT=$(which cat)


print_help()
{
##########################################################################
$CAT <<EOF

  $0

  author:      Karl Voit, Karl@Voit.net

  date:        2003-02-06

  version:     v0.2

  copyright:   GPL

  usage:       $FILENAME [number]

  description: This script fetches things for a PDA in form of HTMLs:

               * heise newsticker
               * ORF news
               * Kinoprogramm (uncut.at)

               The optional argument "number" is 2, 4 or 7 - according to
               the last days of heise news that should be fetched. Per default, 
               the number is 2.

               Please email me suggestions for improvements and errors!
               I am still learning how to write good shell-scripts *g*

EOF
##########################################################################
}

## 2do:
##      * 
##      * 



########################################################
########################################################
########################################################
##                                                    ##
##                  PERSONALISATION                   ##
##                                                    ##
########################################################
########################################################
########################################################


# filenames to use for ...


## (external) Script to sync the Z
SYNC_SCRIPT_NAME=/home/vk/bin/Zsync.sh

DO_SYNC="no"


BEEP_COMMAND=beep
DO_BEEP="no"


## directory on the local harddisk, from where the syncing takes place:
## PLEASE NOTE that the content of this directory will be DELETED on every
##             call of this script!!!
DEST_DIR=/home/vk/zaurus/mnt/card/root-symlinked/Documents/html/mirrors


# change to "done", if you changed all options above to _your_ needs!
CONFIGURED_="notdone"


########################################################




# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #

# --- normally you DON'T have to change anything below this line! --- #

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #




########################################################
########################################################
########################################################
##                                                    ##
##               hardcoded configuration              ##
##                                                    ##
########################################################
########################################################
########################################################

## generates a timestamp like "2002_Jan_31_-_09h43m03s"
TIMESTAMP=`/bin/date +%Y_%b_%d_-_%Hh%Mm%Ss`



HEISE_DONE_FILE=$DEST_DIR/getHeise_done

KINO_DONE_FILE=$DEST_DIR/getKino_done

ORF_URL=http://test.orf.at/go
ORF_DONE_FILE=$DEST_DIR/getOrf_done
ORF_NEWS_DONE_FILE=$DEST_DIR/getOrf_news_done
ORF_OE_DONE_FILE=$DEST_DIR/getOrf_oe_done

NERD_DONE_FILE=$DEST_DIR/nerd_done


# change to "on" if you want to read the debug-messages (can be much) to trace
# down problems:
export DEBUG="off"


########################################################
########################################################
########################################################
##                                                    ##
##                   F U N C T I O N S                ##
##                                                    ##
########################################################
########################################################
########################################################

## ---------------------------------------------------------

myexit()
{
    doreport debug "function myexit($1) called"

    [ "$1" -lt 1 ] && echo "$FILENAME done."
    [ "$1" -gt 0 ] && echo "$FILENAME aborted with errorcode $1."

#optionally    [ "$1" -gt 0 ] && do_sound_error

    exit $1
}


## ---------------------------------------------------------


## check, if some files needed are not found
testiffound()
{
    doreport debug "function testiffound($1) called"

  if [ -z "$2" ]; then
    doreport debug "The tool \"$1\" is missing (because \"$2\" is empty)."
    doreport notify "The tool \"$1\" could not be located (missing?)"
    export SOMETHINGMISSING="yes"
  fi
}



## ---------------------------------------------------------

report()
{
## reports the parameter to the stdout

  echo
  echo "==============================================================="
  echo "                                                 $FILENAME"
  echo "$1"
  echo
  echo "==============================================================="
  echo

}



## ---------------------------------------------------------

debugthis()
{
## debugs the script
        #echo $FILENAME: DEBUG: $1
        echo "do nothing" >/dev/null
}



## ---------------------------------------------------------


doreport_internal_writestring()
{
## !! for use withing function "doreport" only !!
## prints out all strings on stdout

## 2do: error-msg written with { echo 1>&2 "text" } (stderr)

        echo
        echo "===$1============================================"
        echo "                                                 $FILENAME"


## FIXXME:
## 2DO: loop instead of this quick-hack!!!

        if [ ! -z "$2" ]; then
	    echo "$2"
        fi
        if [ ! -z "$3" ]; then
	    echo "$3"
        fi
        if [ ! -z "$4" ]; then
	    echo "$4"
        fi
        if [ ! -z "$5" ]; then
	    echo "$5"
        fi
        if [ ! -z "$6" ]; then
	    echo "$6"
        fi
        if [ ! -z "$7" ]; then
	    echo "$7"
        fi
        if [ ! -z "$8" ]; then
	    echo "$8"
        fi

        echo
        echo "===============================================================";
        echo

}



## ---------------------------------------------------------


doreport()
{
## reports the parameter to the stdout

## usage: (shortnote|notify|error|debug) string1 [string2] [string3] [...] [string7]

## NEEDS: doreport_internal_writestring


    case "$1" in

    "shortnote") 
	echo "$FILENAME: $2 $3 $4 $5 $6 $7";;

    "notify") 
	doreport_internal_writestring " notification ==" "$2" "$3" "$4" "$5" "$6" "$7";;

    "error") 
        doreport_internal_writestring " ERROR =========" "$2" "$3" "$4" "$5" "$6" "$7"
        myexit 1;;

    "debug") 
        ## debugs the script
        if [[ "$DEBUG" = "on" ]]; then echo "$FILENAME: DEBUG: $2 $3 $4 $5 $6 $7"; fi;
        echo "do nothing" >/dev/null;;

    *)
        doreport_internal_writestring " INTERNAL ERROR " "An error occured, while calling function \"doreport\":" "The parameter that was given ($1) has no target/handle." "Aborting.";
        myexit 1;;

    esac
}




## ---------------------------------------------------------

ask()
{
## asks something (parameter 1) the user

  echo
  echo "=== question =================================================="
  echo "                                                 $FILENAME"
  echo "$1"
  echo
  echo "==============================================================="
  echo

## example: ##  ask "Do you want this?"
## example: ##  read ANSWER
## example: ##  echo  
## example: ##  case "$ANSWER" in
## example: ##  
## example: ##  y)
## example: ##    CDCPY_docover ;;
## example: ##  *)
## example: ##    echo "  OK, maybe you're right." ;
## example: ##    echo "  We don't need these fancy stuff anyway ..." ;
## example: ##    echo ;;
## example: ##
## example: ##  esac

}


## ---------------------------------------------------------

## checks, if the directory given exists and tries to create it, if necessary
## returns: 0 = "exists"/"created" or 1 = "error"
makesure_directory_exists()
{
    doreport debug "function makesure_directory_exists($1) called"

    if [ ! -d "$1" ]; then

      doreport debug "Directory \"$1\" not found! So I try to make it now..."
      mkdir "$1"

      if [ $? -eq 0 ]        # Test exit status
       then
           doreport debug "Directory $1 successfully created!"
	   return 0
       else 
           doreport error "Could NOT create directory $1!" "Most likely: no write-permission OR non existing parent-directory."
	   return 1
       fi

    else
	doreport debug "Directory already found"
	return 0
    fi

## EXAMPLE:
##        makesure_directory_exists "$(dirname $FILENAME)"
##	## check, if given dir is really a directory:
##	if [ -d "$DIRNAME" ]; then
##	  doreport debug "Directory $DIRNAME is checked as a valid directory"
##        else  
##          print_help
##          doreport "error" "Directory $DIRNAME is not an existing directory! (see error-output above for possible reason!)" "aborting."
##          exit 1
##	fi


## unsure, because returns also exits current region!
## if [[ $(makesure_directory_exists "$(dirname $A_file)") ]]; then
##     doreport error "The directory for the tempfile could not be found or generated!"
##     myexit 1
## else
##     doreport debug "Directory exists."
## fi


}


## ---------------------------------------------------------

## checks if file exists; if it does not exist, it will be created
makeSureTheFileExists()
{
    doreport debug "function makeSureTheFileExists($1) called"

    ## wether "touch" exists, is to be checked in preconditions!
    [ -e "$1" ] || `which touch` "$1"
}


## ---------------------------------------------------------

precondition_asserts()
{
## * test for things that are needed
## * check, if caller = root-user
## * check, if everything was configured by the user
## * check, if a parameter is given:

      export SOMETHINGMISSING="no"


      RM=$(which rm)
      testiffound rm $RM
      
      WGET=$(which wget)
      testiffound wget $WGET
      
      TOUCH=$(which touch)
      testiffound touch $TOUCH
      
      SED=`which sed`
      testiffound sed $SED
      
      CONVERT=$(which convert)
      testiffound convert $CONVERT
      
      SLEEP=`which sleep`
      testiffound sleep $SLEEP
      
      SYNC_SCRIPT=`which $SYNC_SCRIPT_NAME`
      testiffound $SYNC_SCRIPT_NAME $SYNC_SCRIPT


    ## check, if any tool was NOT found
    doreport debug "CHECK: any tool missing?"
    if [ "$SOMETHINGMISSING" = "yes" ]; then
      print_help
      doreport error "One or more tool(s), that are needed are missing! (See output above!)" "Please make sure, that you those tools are installed properly and try again." "aborting."
    fi



      ## check, if everything was configured by the user
      if [ ! "$CONFIGURED_" = "done" ]; then
        print_help
	doreport "error" "Please make sure, that you checked/modified all options" "to meet your requirements!" "(see section "PERSONALISATION" in file $0)"
      fi
      
      
      
      ## check, if a parameter is given:
      if [ -z "$1" ]; then
        FILE_TO_FETCH=paket2.html
      else
        doreport debug "parameter 1 was found: $1"

        case "$1" in
    
        "2") 
        FILE_TO_FETCH=paket2.html;;
    
        "4") 
        FILE_TO_FETCH=paket4.html;;
    
        "7") 
        FILE_TO_FETCH=paket7.html;;
    
        *)
        print_help
        doreport error "Unknown parameter ($1). Please use only parameter \"2\", \"4\" or \"7\".";;
        esac
        
        doreport debug "user wants to fetch file $FILE_TO_FETCH"
      fi


	## check, if $DEST_DIR is a directory:
      if [ -d "$DEST_DIR" ]; then
        doreport debug "\"$DEST_DIR\" is checked as a directory."
      else  
        print_help
        doreport "error" "\"$DEST_DIR\" is not an existing directory! (correct configuration in this file)" "aborting."
        exit 1
      fi

      

    doreport debug "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< all checks OK!"
    export PRECONDITIONS_CHECKED="yes"


}



## ---------------------------------------------------------

postcondition_asserts()
{

## * deletes temporary files
## * ...

##  if [ -z "???filename" ]; then
##    ???
##  fi

echo "donothing" >/dev/null

}


## ---------------------------------------------------------

getHeise()
{

  ## parse parameter 1 (errors were found out in precond.!)
  case "$1" in
      
      "2") 
      FILE_TO_FETCH="paket2.html"
      DAYS=2;;
  
      "4") 
      FILE_TO_FETCH="paket4.html"
      DAYS=4;;
  
      "7") 
      FILE_TO_FETCH="paket7.html"
      DAYS=7;;
  
      "help"|"--help"|"?"|"/?")
  	doreport debug "getHeise: Parameter help|--help|?|/? detected"
  	print_help;
  	myexit 0;;
  
      *)
      FILE_TO_FETCH="paket2.html"
      DAYS=2;;
  
  esac
  
  BASEURL_HEISE=http://www.heise.de/newsticker/pda/data
  HEISE_DEST_DIR="$DEST_DIR/heise-newsticker"
  HEISE_COMPLETE_URL="$BASEURL_HEISE/$FILE_TO_FETCH"

  doreport shortnote "getHeise: removing old files"
  ${RM} -rf ${HEISE_DEST_DIR}

##  if [ -e "$HEISE_DEST_DIR/index.html" ]; then
##      doreport debug "getHeise: deleting old files from " "\"$HEISE_DEST_DIR\""
##      $RM -rf $HEISE_DEST_DIR/* || doreport error "getHeise: Error while deleting old HTML-files from " "\"$HEISE_DEST_DIR\""
##  fi
  
  doreport shortnote "getHeise: getting heise news for the last $DAYS days"
  $WGET -r -l 1 -q -nd -P $HEISE_DEST_DIR $HEISE_COMPLETE_URL || doreport error "getHeise: Error while getting HTML-files!"
  
  doreport debug "getHeise: renaming startpage to \"index.html\" (and correcting links)"
  $SED 's#/pda/newsticker/##g' $HEISE_DEST_DIR/$FILE_TO_FETCH >$HEISE_DEST_DIR/index.html  || doreport error "getHeise: Error while correcting HTML-files!"

  $RM $HEISE_DEST_DIR/$FILE_TO_FETCH

  $TOUCH $HEISE_DONE_FILE
  doreport shortnote "Heise finished."
  
}


waitHeise()
{
  doreport debug "waitHeise: waiting for getHeise() to be finished..."
  while [ ! -e $HEISE_DONE_FILE ]; do
      $SLEEP 1
  done
  $RM $HEISE_DONE_FILE
  doreport debug "waitHeise: getHeise() finished."
}

## ---------------------------------------------------------


getOrf_news()
{
    wget -q -nd -r -l3 -P $DEST_DIR/orf/news $ORF_URL/news/
    #$SLEEP 6
    $TOUCH $ORF_NEWS_DONE_FILE
}

getOrf_oe()
{
    wget -P $DEST_DIR/orf/oe -q -nd -r -l3 $ORF_URL/oe/
    #$SLEEP 4
    $TOUCH $ORF_OE_DONE_FILE
}


getOrf()
{

  doreport shortnote "getOrf:   getting data from server"

  getOrf_news &
  getOrf_oe &
  
  doreport debug "getOrf: waiting for \"news\" to be finished..."
  
  while [ ! -e $ORF_NEWS_DONE_FILE ]; do
      $SLEEP 1
  done
  
  doreport debug "getOrf: \"news\" finished, waiting for \"oe\""
  
  $RM $ORF_NEWS_DONE_FILE
  
  while [ ! -e $ORF_OE_DONE_FILE ]; do
      $SLEEP 1
  done
  
  $RM $ORF_OE_DONE_FILE
  
  doreport debug "getOrf: \"oe\" finished"
  
  
  ## MANIPULATION
  
  #perl -pi -e 's/wordToFind/replaceWithThisWord/gi'*.fileExtension

  doreport debug "getOrf: deleting files like *html.*"
  $RM $DEST_DIR/orf/news/*html.*
  $RM $DEST_DIR/orf/oe/*html.*

  doreport debug "getOrf: correcting relative links in HTML-files for \"news\""
  perl -pi -e 's#http://test.orf.at/go/oe/#../oe/#gi' $DEST_DIR/orf/news/*.html
  
  doreport debug "getOrf: correcting relative links in HTML-files for \"oe\""
  perl -pi -e 's#http://test.orf.at/go/news/#../news/#gi' $DEST_DIR/orf/oe/*.html
  
  $TOUCH $ORF_DONE_FILE
  doreport shortnote "ORF finished."
}


waitOrf()
{
  doreport debug "waitOrf: waiting for getOrf() to be finished..."
  while [ ! -e $ORF_DONE_FILE ]; do
      $SLEEP 1
  done
  $RM $ORF_DONE_FILE
  doreport debug "waitOrf: getOrf() finished."
}


## ---------------------------------------------------------

getKino()
{
  KINO_URL="http://www.uncut.at/graz/programm.php?weekday=week"
  KINO_DEST_DIR="$DEST_DIR/kino"

  doreport shortnote "getKino:  removing old files"
  ${RM} -rf ${KINO_DEST_DIR}

  doreport shortnote "getKino:  getting data from server"
  $WGET -P "$KINO_DEST_DIR" -q "$KINO_URL"
  
  doreport debug "getKino: cleaning HTML for PDA-usage (JavaScript, Advertisment, ...)"
  $SED -e 's/language="JavaScript"/language="NoJavaScript"/' \
      -e 's/<TD VALIGN=top COLSPAN=2 WIDTH=183>/<!--<TD VALIGN=top COLSPAN=2 WIDTH=183>/' \
      -e 's/<TD VALIGN=top WIDTH=428>/--><TD VALIGN=top WIDTH=428>/' \
      -e 's/<img src/<not-img src/' \
      "$KINO_DEST_DIR/programm.php?weekday=week" >"$KINO_DEST_DIR/index.html"

  $RM -f "$KINO_DEST_DIR/progr*"
  
  ## INFO: erstes s/<TD... steht ca. vor "<IMG SRC="pic/linie-blau.gif" WIDTH=111 HEIGHT=40 ALIGN=bottom><BR>..."
  ##       zweites s/<TD... steht ca. vor "Kinoprogramm f&uuml;r 31. J&auml;nner - 6. Februar 2003<br>"
  
  $TOUCH $KINO_DONE_FILE
  ## workarond because Kino is too fast ;-)
  $SLEEP 2
  doreport shortnote "Kino finished."
}


waitKino()
{
  doreport debug "waitKino: waiting for getKino() to be finished..."
  while [ ! -e $KINO_DONE_FILE ]; do
      $SLEEP 1
  done
  $RM $KINO_DONE_FILE
  doreport debug "waitKino: getKino() finished."
}

## ---------------------------------------------------------

getNerd()
{
    doreport shortnote "getNerd:  getting data from server (using external script ~/bin/getnerds.sh)"
    ~/bin/getnerds.sh 2>&1 >/dev/null

##old:   NERD_DEST_DIR=$DEST_DIR/nerd
##old:   NERD_URL=http://www.ash.de/clip
##old: 
##old:   doreport shortnote "getNerd:  getting data from server"
##old:   $WGET -P $NERD_DEST_DIR -q \
##old:                      $NERD_URL/dilbert.gif \
##old:                      $NERD_URL/calvinandhobbes.gif \
##old:                      $NERD_URL/uf.gif \
##old:                      $NERD_URL/tom.gif \
##old:                      $NERD_URL/garfield.gif \
##old:                      $NERD_URL/peanuts.gif
##old: 
##old:   doreport debug "getNerd: converting images to jpeg-format"
##old:   $CONVERT $NERD_DEST_DIR/dilbert.gif $NERD_DEST_DIR/dilbert.jpg
##old:   $CONVERT $NERD_DEST_DIR/calvinandhobbes.gif $NERD_DEST_DIR/calvinandhobbes.jpg
##old:   $CONVERT $NERD_DEST_DIR/uf.gif $NERD_DEST_DIR/uf.jpg
##old:   $CONVERT $NERD_DEST_DIR/tom.gif $NERD_DEST_DIR/tom.jpg
##old:   $CONVERT $NERD_DEST_DIR/garfield.gif $NERD_DEST_DIR/garfield.jpg
##old:   $CONVERT $NERD_DEST_DIR/peanuts.gif $NERD_DEST_DIR/peanuts.jpg
##old:   doreport debug "getNerd: removing old gif-files"
##old:   $RM $NERD_DEST_DIR/*.gif
##old: 
##old:   doreport debug "getNerd: generating index.html for Nerd Clippings"
##old:   cd $DEST_DIR/nerd/
##old:   cat << ende > index.html
##old: <html>
##old: <head>
##old: <title>Nerd Clippings (Comics)</title>
##old: </head>
##old: <body>
##old: Dilbert:<br>
##old: <img src="dilbert.jpg" /><br>
##old: 
##old: <br>Calvin and Hobbes:<br>
##old: <img src="calvinandhobbes.jpg" /><br>
##old: 
##old: <br>User Friendly:<br>
##old: <img src="uf.jpg" /><br>
##old: 
##old: <br>Tom Touche:<br>
##old: <img src="tom.jpg" /><br>
##old: 
##old: <br>Garfield:<br>
##old: <img src="garfield.jpg" /><br>
##old: 
##old: <br>Peanuts:<br>
##old: <img src="peanuts.jpg" />
##old: 
##old: </body>
##old: </html>
##old: ende
##old:   
  $TOUCH $NERD_DONE_FILE
  doreport shortnote "Nerd finished."
}


waitNerd()
{
  doreport debug "waitNerd: waiting for getNerd() to be finished..."
  while [ ! -e $NERD_DONE_FILE ]; do
      $SLEEP 1
  done
  $RM $NERD_DONE_FILE
  doreport debug "waitNerd: getNerd() finished."
}

## ---------------------------------------------------------

askForSync()
{
  ask "Do you want to sync with Zaurus?"
  read ANSWER
  echo  
  case "$ANSWER" in
  
  y|yes|j|ja)
    doreport debug "askForSync: calling external sync-program \"$SYNC_SCRIPT\""
    doreport notify "Sync'ing with Zaurus... (may take some time)"
    $SYNC_SCRIPT;;
  
  *)
    doreport debug "askForSync: no sync-program called.";;
  
  esac
}

## ---------------------------------------------------------

generateIndexpage()
{

cd $DEST_DIR
cat << ende > index.html
<html>
<head>
<title>Zget.sh - Webseiten</title>
</head>
<body>
<h1 align=center>Zget.sh - Webseiten</h1>
<p>
<a href="./heise-newsticker/index.html">Heise Newsticker</a><br>
<!--
<a href="./orf/news/index.html">ORF News</a><br>
-->
<a href="./kino/index.html">Kinoprogramm</a><br>
<a href="./nerd/index.html">Nerd Clippings</a><br>
</p>
</body>
</html>
ende

}

## ---------------------------------------------------------

########################################################
########################################################
########################################################
##                                                    ##
##                S C R I P T                         ##
##                                                    ##
########################################################
########################################################
########################################################


## test for important stuff:
precondition_asserts "$1" "$2" "$3" "$4" "$4" "$5" "$6" "$7" "$8" "$9"

#doreport debug "main: removing old data"
#$RM -rf $DEST_DIR/
## -> being done by the subroutines

# ---------------------------------------------
doreport debug "main: getting data (in background)"

#getOrf &
getHeise $1 &
getNerd &
getKino &

# ---------------------------------------------
$SLEEP 2 && doreport notify "getting data in background (may take a while) ..."

waitKino

waitNerd

waitHeise

#waitOrf

# ---------------------------------------------
doreport debug "main: generating indexpage"

generateIndexpage

# ---------------------------------------------
#doreport debug "main: ASKING: may I sync?"
#askForSync

[ "${DO_BEEP}" = "yes" ] && ${BEEP_COMMAND}

[ "${DO_SYNC}" = "yes" ] && ( $SYNC_SCRIPT )

[ "${DO_BEEP}" = "yes" ] && ${BEEP_COMMAND}

########################################################


## test for important stuff:
postcondition_asserts

myexit 0


########################################################
##                      E N D                         ##
########################################################

