#! /bin/bash
#
# The System Manager
# An Administration Tool For UNIX
#
# Copyright (c) 1994 Stuart Herbert
# Released under the GNU GPL v2
#
# Bugs/comments/contributions to S.Herbert@Sheffield.ac.uk

function main()
{
  local MenuLine
  local x

  if [ -f $SysmanFile1 ]; then rm -f $SysmanFile1 ; fi
  touch $SysmanFile1
  
  pushd . > /dev/null
  cd /var/news
  for x in * ; do
    if [ -f $x -a -r $x -a -w $x ]; then
      echo -n "$x $x off " >> $SysmanFile1
    fi
  done
  popd > /dev/null
  
  if [ -s $SysmanFile1 ]; then
    MenuList="`cat $SysmanFile1`"
    Dialog --checklist "Which news do you want to edit?" 22 71 15 $MenuList 2> $SysmanFile1
    
    if [ -s $SysmanFile1 ]; then
      MenuList="`cat $SysmanFile1 | tr -d "\042"`"
      
      for x in $MenuList ; do
        if [ "$EDITOR" = "" ]; then
	  vi $x
	else
	  $EDITOR $x
	fi
      done
    fi
  else
    Abort "You don't have the right to edit the news"
  fi
}

# main code
if [ -n "$1" ]; then
  case "$1" in
    --SysmanInstall)
      echo "Y : Y : EDIT : Edit The News :$0"
      exit
      ;;
    --SysmanAuthor)
      echo "EDIT : Edit The News"
      echo "Copyright (c) 1994 Stuart Herbert"
      exit
      ;;
  esac
else
  main
fi

# clean up here
for x in $SysmanFile1 $SysmanFile2 $SysmanFile3 ; do
  if [ -f $x ]; then rm -f $x ; fi
done

# that's it, folks
