ULTRAPOSSUMMARK=ULTRAPOSSUM$ULTRAPOSSUM_PROJECT

backslash() {
  ( IFS="\n"; while read line
  do
    echo "$line\\"
  done )
}

# replace_vaconf <config> <contents> <id>
replace_vaconf() {
    /bin/cp -p $1 $1.tmp
    sed -e "/$ULTRAPOSSUMMARK\-$3 START/,/$ULTRAPOSSUMMARK\-$3 END/ c\\" -e "`cat $2 | backslash` " < $1 > $1.tmp
    /bin/mv $1.tmp $1
}
                                                                                
# strip_vaconf <config> <id>
strip_vaconf() {
    /bin/cp -p $1 $1.tmp
    sed -e "/$ULTRAPOSSUMMARK\-$2 START/,/$ULTRAPOSSUMMARK\-$2 END/ d" < $1 > $1.tmp
    /bin/mv $1.tmp $1
}
                                                                                
# add_end_vaconf <config> <contents> <id>
add_end_vaconf() {
  if grep "$ULTRAPOSSUMMARK-$3 START" $1 > /dev/null; then
    replace_vaconf $1 $2 $3
  else
    cat $2 >> $1
  fi
}
                                                                                
# add_vaconf <config> <contents> <id>
add_vaconf() {
  if grep "$ULTRAPOSSUMMARK-$3 START" $1 > /dev/null; then
    replace_vaconf $1 $2 $3
  else
    /bin/cp -p $1 $2.tmp
    cat $2 > $2.tmp
    cat $1 >> $2.tmp
    /bin/mv $2.tmp $1
  fi
}

# add_startmark <prefix> <id>
add_startmark() {
  echo "$1 $ULTRAPOSSUMMARK-$2 START DO NOT MODIFY HERE"
}

# add_endmark <prefix> <id>
add_endmark() {
  echo "$1 $ULTRAPOSSUMMARK-$2 END DO NOT MODIFY HERE"
}
