
# *****************************************************************************
#    This script installs or updates SKsh
# *****************************************************************************

options CFIclsw

# *****************************************************************************
# setup variables containing configuration information
# *****************************************************************************

   rel='1.7'
   arcname='SKsh017.lzh'
   relnum=8
   b="$_ANSI_P3"
   e="$_ANSI_P1"
   errorlog='ram:Install_SKsh.err'
   st_file='s:startup-sequence'
   ms_file='ram:ManSteps.txt'
   RECUR_DEPTH=32

# *****************************************************************************
# setup variables containing files we need to install
# *****************************************************************************

  main_files='sksh'

  script_files='scr/chext scr/cleard scr/dstack scr/emacs_mode scr/man
    scr/path scr/popd scr/pushd scr/qrm scr/usage scr/vi_mode scr/histload
    scr/histsave scr/histlist scr/histrm'

  script_s_files='scr_source/chext.s scr_source/cleard.s scr_source/dstack.s
     scr_source/emacs_mode.s scr_source/histlist.s scr_source/histload.s
     scr_source/histrm.s scr_source/histsave.s scr_source/man.s
     scr_source/path.s scr_source/popd.s scr_source/pushd.s scr_source/qrm.s
     scr_source/usage.s scr_source/vi_mode.s'

  bin_files='bin/cat bin/cmp bin/cp bin/crc bin/cut bin/doc2man bin/du
     bin/encr bin/fgrep bin/find bin/grep bin/head bin/indent bin/join
     bin/num bin/split bin/srun bin/strings bin/tail bin/tee bin/view bin/wc
     bin/window bin/xargs bin/xd'

  init_files='init/.skshinit init/.skshinit.pp init/Stuff.sksh init/Stuff.pp
     sksh.msg'

  config_files='init/.skshrc'

  inst_files="Install_$rel.pp README.install"

  misc_files="misc/MiscFiles.lzh"

  doc_files='doc/Addendum1.1.doc doc/Addendum1.1.doc doc/Addendum1.2.doc
     doc/Addendum1.3.doc doc/Addendum1.4.doc doc/Addendum1.5.doc
     doc/Addendum1.6.doc doc/Addendum1.7.doc doc/Bugs.doc doc/Diffs.doc
     doc/ErrorCodes.doc doc/ExtCmds.doc doc/Hints.doc doc/Install.doc
     doc/MiscInfo.doc doc/ReadMe_1st.doc doc/Reference.doc doc/TechNotes.doc
     doc/TinySKsh.doc doc/UserMan.doc doc/View.doc'


# *****************************************************************************
#    cleanup function to remove files we put in ram:
# *****************************************************************************

function cleanup {
   rm -fr ram:cp ram:crc ram:grep ram:cat ram:tail ram:cut >nil:
}

# *****************************************************************************
#    Report an error
# *****************************************************************************

function error {
   echo -c "\n$b" "ERROR: " "$e" "$1\n"
   echo "ERROR: $1\n" >>"$errorlog"
   return 1
}

# *****************************************************************************
#    Report a warning
# *****************************************************************************

function warn {
   echo -c "$b" "WARNING: " "$e" "$1\n"
   echo "WARNING: $1\n" >>"$errorlog"
}

# *****************************************************************************
#    See if we should terminate because of errors
# *****************************************************************************

function ck_terminate {
   if [ -f "$errorlog" ]
   then
      echo "\n${b}Errors were encountered.  Check the file $errorlog.${e}\n"
      cleanup
      return 1 2
   fi
}

# *****************************************************************************
#    Checksum files
# *****************************************************************************

function crc_files {

   local fspec

   fspec=$(tackon "$1" "$2")

   echo -n '.'

   if [ ! -f "$fspec" ]
   then
      echo
      error "this file is missing: $fspec"
   else
      crcval=$(ram:crc -q "$fspec") || error "can't crc $fspec" || ck_terminate

      if [ "$crcval" != "$3" ]
      then
         echo
         error "this file has an incorrect checksum: $fspec"
      fi

      if [ $(expr index "$4" 'p') -gt 0 -a ! -P "$fspec" ]
      then
         echo
         warn "this file should have the pure bit set: $fspec"
      fi

      if [ $(expr index "$4" 's') -gt 0 -a ! -S "$fspec" ]
      then
         echo
         warn "this file should have the script bit set: $fspec"
      fi
   fi
}

# *****************************************************************************
#    Verify that files exist
# *****************************************************************************

function check_files {

   local notfound file

   notfound='0'
   sty="$1"; shift

   for file in $1
   do
      if [ "$sty" != 'PATH' -a ! -f "$file" -o
           "$sty" =  'PATH' -a -z $(which -s "$file") ]
      then
        error "The '$file' file must be present for this script to
       operate properly.  Please install it in the appropriate
       place and run this script again."
        notfound=1
      fi
      shift
   done

   return "$notfound"
}


# *****************************************************************************
#    Install files
# *****************************************************************************

function install_files {

   local install_dir chmod_flags overwrite fspec file

   install_dir = "$1"
   chmod_flags = "$2"
   overwrite   = "$3"
   shift 3

   for file in $1
   do
      echo -n '.'
      fspec=$(tackon "$install_dir" $(basename "$file"))
      if [ -f "$fspec" ]
      then
         if [ "$overwrite" = 'Y' ]
         then
            chmod +wd "$fspec" >nil: ||
               error "can't chmod +wd $fspec" || ck_terminate
            ow='Y'
         else
            ow='N'
         fi
      else
         ow='Y'
      fi

      if [ -f "$file" ]
      then
         if [ "$ow" = 'Y' ]
         then
            ram:cp "$file" "$fspec" >nil: ||
                  error "can't copy $file to $fspec" || ck_terminate
            chmod "$chmod_flags" "$fspec" >nil: ||
                  error "can't change $fspec mode to $chmod_flags" ||
                  ck_terminate
         fi
      else
         echo
         error "The file '$file' is missing from the current directory."
         return 1
      fi
   done
}

# *****************************************************************************
#    Read dir name (or file name)
# *****************************************************************************

function read_dir {

   local in_dir read_dir; in_dir=''

   while [ -z "$in_dir" -o "$4" = 'directory' -a ! -d "$in_dir" -o 
           "$4" = 'file' -a ! -f "$in_dir" ]
   do
      echo
      echo "$1"

      line read_dir "$2 $b\[$3]$e ? > " 20

      in_dir=$(pathconv -a "$read_dir")

      if [ "$4" = 'directory' -a ! -d "${in_dir:=$3}" -o
           "$4" = 'file'      -a ! -f "${in_dir:=$3}" ]
      then
         echo "\n$in_dir is not a valid $4 name."

         if [ "$4" = 'directory' ]
         then
            line yn "Do you wish to create it? $b[y/N]$e > " 20
            if [ $(expr substr $(toupper "$yn") 1 1) = 'Y' ]
            then
               mkdir -p "$in_dir" || error "can't create directory $in_dir"
            fi
         fi
      fi
   done

   export -l in_dir
}

# *****************************************************************************
#   Resolve a device name
# *****************************************************************************

function resolve_dir {
   if [ $(expr index "$1" ':') -gt 0 ]
   then
      dev_name=$(car "$1" ':')
      f_name=$(cdr "$1" ':')
      tackon $(info "$dev_name:" | ram:tail -1 | ram:cut -c66-200) $f_name
   else
      echo "$1"
   fi
}

# *****************************************************************************
#    Check a device assignment
# *****************************************************************************

function check_assign {

   local device loc descr defdir change

   device = "$1"
   defdir = "$2"
   loc    = "$3"
   descr  = "$4"
   change = ''

   echo -n "Checking the $device: device..."

   if [ -m "$device:" ]
   then

      if [ $(tolower "$defdir") != $(tolower "$loc") ]
      then
         change='TRUE'
         clear
         echo "${b}Incorrect assignment of $device:${e} - should be $loc."

         echo "The '$b$device:$e' assignment currently points to the '$b$defdir$e'
directory.  You previoulsy installed the $descr
files in '$b$loc$e' directory.

This assignment must be changed for SKsh to operate correctly."

      fi
   else
      change='TRUE'
      clear
      echo "
The '$b$device:$e' assignment does not currently exist.
This device must be assigned to the directory containing
the $descr files.

You previously installed these files in the '$b$loc$e'
directory.
"
   fi

   if [ -n "$change" ]
   then
      echo
      line yn "Press return to continue: > "

      echo -n "
If you wish, this script will now assign '$b$device:$e' to the
'$b$loc$e' directory.  ${b}NOTE:${e} This will ONLY be in affect until
you reboot your computer.  To make this change permanent, you must
modify your ${b}${st_file}${e} file and make it create these
assignments.

If you type 'Y' at the prompt below, the following assignment will be
made:

   ${b}assign $device: $loc${e}

Do you want to make this assignment now? [Y/n] > "

      read yn

      if [ $(expr substr $(toupper "$yn") 1 1) != 'N' ]
      then
          echo "Executing ${b}assign $device: $loc${e}..."
          assign "$device:" "$loc"
      else
          echo "Assignment not made.  You ${b}must${e} make it manually."
          warn "Incorrect assignment of $device: - should be $loc." >nil:
      fi
      echo
      line yn "Press return to continue: > "

   else
      echo "${b}OK${e}"
   fi
}

# *****************************************************************************
#    Verify a line in the startup sequence
# *****************************************************************************

function check_ss {
   if eval "$1"
   then return 0
   else
      echo "   $stepnum) $2"
      echo "   $stepnum) $2" >> "$ms_file"
      if [ -n "$3" ]
      then
         inc stepnum
         echo "   $stepnum) $3"
         echo "   $stepnum) $3" >> "$ms_file"
      fi
      return 1
   fi
}

# *****************************************************************************
#   start of "main" script - check system setup and prerequisites
# *****************************************************************************

clear

if [ ! -m 'ram:' ]
then
   echo "${b}ERROR${e}: This script requires the ram: disk to be temporarily mounted.
       Also, you can assign ram: to another location.  In any case, please
       fix this and run this script again.\n"
   cleanup
   return 0
fi

if [ "$LINES" -lt 22 -o "$COLUMNS" -lt 72 ]
then
   error "This script requires a larger window size.  Please make
       your window at least 22 lines by 72 columns and run this
       script again."
   ck_terminate
fi

#if [ $(cdr $(stack) ':') -lt 8000 ]
#then
#   error "Please set the stack size to at least 8000 bytes and run
#       this script again."
#   ck_terminate
#fi

if [ $(version -s) -lt "$relnum" ]
then
   error "This script must be run under SKsh $rel or later.  Please
       dearchive SKsh $rel, and type 'sksh -n Install_$rel.sksh' to
       run this script."
   ck_terminate
fi

if [ ! -d 'bin' -o ! -d 'doc' -o ! -d 'init' -o ! -d 'misc' -o ! -d 'scr' ]
then
   error "This script must be invoked from the directory in which
       you unarchived the main $arcname file.  You can use the -m
       option to lharc to automatically create directories:

          lharc -m x $arcname"
   ck_terminate
fi

if [ ! -m 't:' ]
then
   mkdir -p ram:tmp
   assign t: ram:tmp || error "can't assign t: to ram:tmp" || ck_terminate
fi

check_files 'PATH' assign || ck_terminate
check_files 'PWD' 'bin/grep bin/cp bin/cat bin/crc' || ck_terminate

chmod +wd ram:grep ram:cp ram:cat ram:crc >nil:

bin/cp bin/cp    ram:cp   || error "can't copy 'cp' to ram" || ck_terminate
install_files 'ram:' 'rwedp' 'Y' \
  "bin/crc bin/grep bin/cat bin/cut bin/tail" || ck_terminate

# *****************************************************************************
#    End of checking.  Start actual steps
# *****************************************************************************

clear

echo "${b}SKsh $rel installation script ----------------------------------${e}

This script will assist you in installing SKsh $rel by performing
tasks which can be easily automated.  It will do the following:

   1) Check that all files are present from archive.
   2) Input destination directory names for install.
   3) Install SKsh files into above dirs (this step can be skipped).
   4) check device assignments (sksh:, etc)
   5) check integrity of installed SKsh commands
   6) Update or create .pp (faster script) files (optional)
   7) Install SKsh man pages (optional)
   8) Report additional manual activities which are necessary

To run this script, the main SKsh archive (called $arcname)
must have been de-archived in the current directory.  You should have
invoked this by typing 'sksh -n Install_$rel.pp' from an AmigaDos CLI.
"

line yn "Do you wish to continue? $b[y/N]$e > " 20
echo

if [ $(expr substr $(toupper "$yn") 1 1) != 'Y' ]
then
  echo "Ok, bye."
  cleanup
  return
fi

rm -f "$errorlog" >nil:
chmod +s scr/emacs_mode
scr/emacs_mode >nil: || error "unable to set editing mode" || ck_terminate


# -------------- step 1 -----------------------------------------------

clear
echo "${b}STEP ONE: Check unarchived files ---------------------------------${e}"

echo "
The files in the current working directory will now be checked to
insure that they all have been unarchived in the proper locations.
"

echo -n "Checking main sksh binary..."
check_files 'PWD' "$main_files" || ck_terminate

echo -n "${b}OK${e}\nChecking external binary commands..."
check_files 'PWD' "$bin_files" || ck_terminate

echo -n "${b}OK${e}\nChecking external script commands..."
check_files 'PWD' "$script_files" || ck_terminate
check_files 'PWD' "$script_s_files" || ck_terminate

echo -n "${b}OK${e}\nChecking initialization files..."
check_files 'PWD' "$init_files" || ck_terminate
check_files 'PWD' "$config_files" || ck_terminate

echo -n "${b}OK${e}\nChecking documentation..."
check_files 'PWD' "$doc_files"      || ck_terminate

echo -n "${b}OK${e}\nChecking installation files..."
check_files 'PWD' "$inst_files" || ck_terminate

echo -n "${b}OK${e}\nChecking misc files..."
check_files 'PWD' "$misc_files" || ck_terminate

echo -n "${b}OK${e}\n\n\nThe necessary files were found.  Press return to continue: > "
read yn

# -------------- step 2 -----------------------------------------------

clear
echo "${b}STEP TWO: input directories --------------------------------------${e}"

echo -n "
This script must know the locations of several directories in
order to properly install the SKsh files.  Defaults will given in
brackets for each directory - you may press <return> to accept the
default, or type in a legal directory name.
"

read_dir "Please enter the directory which will contain the main SKsh " \
         "binary" "c:" 'directory'

sksh_dir=$(resolve_dir "$in_dir")

[ -m sksh: ] && devsksh=$(resolve_dir 'sksh:')

read_dir "Please enter the directory which will contain the .skshinit " \
         "and .skshrc startup files" "${devsksh:-s:}" 'directory'

init_dir=$(resolve_dir "$in_dir")

[ -m skshbin: ] && devbin=$(resolve_dir 'skshbin:')

read_dir "Please enter the directory which will contain the SKsh " \
         "external binary commands" "${devbin:-sys:bin}" 'directory'

bin_dir=$(resolve_dir "$in_dir")

[ -m skshscr: ] && devscr=$(resolve_dir 'skshscr:')

read_dir "Please enter the directory which will contain the SKsh " \
         "external scripts" "${devscr:-sys:scr}" 'directory'

scr_dir=$(resolve_dir "$in_dir")

echo
line yn "Do you wish to install the documentation files? $b[Y/n]$e > " 20

doc_dir=''

if [ $(expr substr $(toupper "$yn") 1 1) != 'N' ]
then
   read_dir "Please enter the directory which will contain the SKsh " \
            "documentation files." "sys:doc" 'directory'
   doc_dir=$(resolve_dir "$in_dir")
fi



# -------------- step 3 -----------------------------------------------

clear
echo "${b}STEP THREE: install files ------------------------------------${e}"

echo -n "
The SKsh files will now be installed in the locations you chose in
${b}step 2${e}.  Configuration files such as .skshrc will ${b}not${e} be
overwritten if they exist so that this script can be used for either
a new install, or an update to a later SKsh version.  You may choose to
skip this step, although no files will be installed if you do.  Choose
Y or press return to perform the installation.

"

line yn "Do you wish to perform this step? $b[Y/n]$e > " 20
echo

if [ $(expr substr $(toupper "$yn") 1 1) = 'N' ]
then
   echo "File installation skipped - No files installed."
else
   echo -n "Installing sksh binary."
   install_files "$sksh_dir" "rep" 'Y' "$main_files"     || ck_terminate

   echo -n "${b}OK${e}\nInstalling external binary commands."
   install_files "$bin_dir" "rep" 'Y' "$bin_files"       || ck_terminate

   echo -n "${b}OK${e}\nInstalling external script commands."
   install_files "$scr_dir" "res" 'Y' "$script_files"    || ck_terminate

   echo -n "${b}OK${e}\nInstalling initialization files."
   install_files "$init_dir" "res" 'Y' "$init_files"     || ck_terminate
   install_files "$init_dir" "res" 'N' "$config_files"   || ck_terminate

   if [ -n "$doc_dir" ]
   then
      echo -n "${b}OK${e}\nInstalling documentation."
      install_files "$doc_dir" "r" 'Y' "$doc_files"      || ck_terminate
   fi

   echo -n "${b}OK${e}\n\nFile installation complete.  "
fi

echo -n "Press return to continue: > "; read yn

# -------------- step 4 -----------------------------------------------

clear
echo "${b}STEP FOUR: check device assignments --------------------------${e}"

echo -n "
SKsh needs several AmigaDos device assignments in order to operate
correctly.  This step will check that those assignments have been made
correctly.

Press return to continue: > "
read yn

echo

check_assign 'sksh'    "$devsksh" "$init_dir" 'SKsh binary'
check_assign 'skshbin' "$devbin"  "$bin_dir"  'SKsh external binary'
check_assign 'skshscr' "$devscr"  "$scr_dir"  'SKsh external script'

echo -n "\nPress return to continue: > "
read yn

# -------------- step 5 -----------------------------------------------

clear
echo "${b}STEP FIVE: check integrity of installed files ----------------${e}"

echo -n "
This step will verify that the installed files are in place and that
they have proper checksums.  No errors should be reported.

Press return to continue: > "

read yn;

echo -n "\nChecking sksh binary."

crc_files "$sksh_dir" sksh          '     71380    5631852 1839896023' 'p'

echo -n "${b}OK${e}\nChecking initialization files."

crc_files "$init_dir" sksh.msg      '      6160     507141 1969742648' 's'
crc_files "$init_dir" .skshinit     '      1699     101524 1008357631' 's'
crc_files "$init_dir" .skshinit.pp  '       981      58735 1046829638' 's'
crc_files "$init_dir" Stuff.sksh    '      3346     233003  111354638' 's'
crc_files "$init_dir" Stuff.pp      '      1880     115336 2072644645' 's'

echo -n "${b}OK${e}\nChecking external binary commands."

crc_files "$bin_dir"  cat           '      2164     164842  766981691' 'p'
crc_files "$bin_dir"  cmp           '      2572     195291 1994119554' 'p'
crc_files "$bin_dir"  cp            '      4044     335129 1073694252' 'p'
crc_files "$bin_dir"  crc           '      2256     172206  766982743' 'p'
crc_files "$bin_dir"  cut           '      3160     252382 1073706073' 'p'
crc_files "$bin_dir"  doc2man       '      3128     246846 1994126919' 'p'
crc_files "$bin_dir"  du            '      2960     221083 1380556482' 'p'
crc_files "$bin_dir"  encr          '      3404     264713 1687271068' 'p'
crc_files "$bin_dir"  fgrep         '      5464     399663  690205810' 'p'
crc_files "$bin_dir"  find          '      6016     465405  920283952' 'p'
crc_files "$bin_dir"  grep          '     11724     928329 1764136740' 'p'
crc_files "$bin_dir"  head          '      2220     168607 1994115742' 'p'
crc_files "$bin_dir"  indent        '      2912     209666 1840670621' 'p'
crc_files "$bin_dir"  join          '      2436     187812 1380551729' 'p'
crc_files "$bin_dir"  num           '      2392     181575 1380550838' 'p'
crc_files "$bin_dir"  split         '      2520     194062 1687281161' 'p'
crc_files "$bin_dir"  srun          '      2424     179586 1687283229' 'p'
crc_files "$bin_dir"  strings       '      2328     178198  766983599' 'p'
crc_files "$bin_dir"  tail          '      2820     223470 1380556823' 'p'
crc_files "$bin_dir"  tee           '      2436     193881 1380552596' 'p'
crc_files "$bin_dir"  view          '      5612     471187  153458698' 'p'
crc_files "$bin_dir"  wc            '      2696     206692  153420913' 'p'
crc_files "$bin_dir"  window        '      3988     309859 1610568774' 'p'
crc_files "$bin_dir"  xargs         '      3868     307488  767002069' 'p'
crc_files "$bin_dir"  xd            '      2924     222704 1840731781' 'p'

echo -n "${b}OK${e}\nChecking external script commands."

crc_files "$scr_dir"  chext         '       724      45783  156338274' 's'
crc_files "$scr_dir"  cleard        '       239      14129  111842316' 's'
crc_files "$scr_dir"  dstack        '       374      22387 1962381090' 's'
crc_files "$scr_dir"  emacs_mode    '      1664      86891 1741126506' 's'
crc_files "$scr_dir"  histlist      '       543      35191  402881538' 's'
crc_files "$scr_dir"  histload      '       445      28405 1393911568' 's'
crc_files "$scr_dir"  histrm        '       286      17219 1355833554' 's'
crc_files "$scr_dir"  histsave      '       435      27818  220244877' 's'
crc_files "$scr_dir"  man           '      1083      67777 1491596828' 's'
crc_files "$scr_dir"  path          '      1621      93619 1270108958' 's'
crc_files "$scr_dir"  popd          '       594      36313  103051252' 's'
crc_files "$scr_dir"  pushd         '       418      25010  501725995' 's'
crc_files "$scr_dir"  qrm           '       573      35576 1652620235' 's'
crc_files "$scr_dir"  usage         '       351      22122  900170573' 's'
crc_files "$scr_dir"  vi_mode       '      2066     107198 1741129407' 's'

if [ -n "$doc_dir" ]
then
  echo -n "${b}OK${e}\nChecking documentation."

  crc_files "$doc_dir" Addendum1.1.doc '      6617     507608  846261981' ''
  crc_files "$doc_dir" Addendum1.2.doc '      8613     665741 1607987136' ''
  crc_files "$doc_dir" Addendum1.3.doc '     18429    1473628  232823865' ''
  crc_files "$doc_dir" Addendum1.4.doc '     23004    1790308 1459997937' ''
  crc_files "$doc_dir" Addendum1.5.doc '     27235    2199926  380648497' ''
  crc_files "$doc_dir" Addendum1.6.doc '     13165    1036769  994386100' ''
  crc_files "$doc_dir" Addendum1.7.doc '     31923    2555942 1607740513' ''
  crc_files "$doc_dir" Bugs.doc        '      1922     145726 1295230009' ''
  crc_files "$doc_dir" Diffs.doc       '      5096     398610 1139424173' ''
  crc_files "$doc_dir" ErrorCodes.doc  '      1883     134329 1753028684' ''
  crc_files "$doc_dir" ExtCmds.doc     '     52474    3718919  163638410' ''
  crc_files "$doc_dir" Hints.doc       '      6269     494803  376114250' ''
  crc_files "$doc_dir" Install.doc     '      9034     703354  163348651' ''
  crc_files "$doc_dir" MiscInfo.doc    '      5113     413233 1100231556' ''
  crc_files "$doc_dir" Readme_1st.doc  '      6088     457640  126908301' ''
  crc_files "$doc_dir" Reference.doc   '    161996   11458458 1366932363' ''
  crc_files "$doc_dir" TechNotes.doc   '      4710     379193  653633332' ''
  crc_files "$doc_dir" TinySKsh.doc    '      2886     207444  774303615' ''
  crc_files "$doc_dir" UserMan.doc     '     96850    7691838 1391480519' ''
  crc_files "$doc_dir" View.doc        '     11125     886892 1088844887' ''
fi

echo -n "${b}OK${e}\n\nIntegrity check complete.  Press return to continue: > "
read yn


# -------------- step 6 -----------------------------------------------

clear
echo "${b}STEP SIX: Re-create .skshrc.pp -------------------------------${e}"

echo -n "
Sksh permits a special form of script file, known as a .pp file, to
be executed faster than a plain script file.  If you use one for
your .skshrc init file, invocation time will be improved.

If you wish to use a .skshrc.pp, it must match have been created
by SKsh version $rel.  This step will allow you to create a new
.skshrc.pp file if you wish.

"

line yn "Do you wish to perform this step? $b[Y/n]$e > " 20
echo

rcfile=$(tackon "$init_dir" .skshrc)

[ -f "$rcfile" ] || error "No .skshrc file found in $init_dir" ||
                    ck_terminate

if [ $(expr substr $(toupper "$yn") 1 1) = 'N' ]
then
   echo "\nStep skipped, no .skshrc.pp file created."
else
   if [ -f "${rcfile}.pp" ]
   then echo "Re-creating .skshrc.pp from .skshrc..."
   else echo "No .skshrc.pp file found, creating new one..."
   fi
   preparse < "$rcfile" > "${rcfile}.pp" ||
       error "Unable to create .skshrc.pp file in $init_dir" ||
       ck_terminate
       
   echo "Process complete."
fi

echo -n "\nPress return to continue: > "
read yn


# -------------- step 7 -----------------------------------------------

clear
echo "${b}STEP SEVEN: Install SKsh manual pages ------------------------${e}"

echo "
If you wish to use the SKsh 'man' program to access the manual pages
for commands, variables, and aliases supplied by SKsh, you will need
to perform this step.  It is automated.  SKsh manpages reside in the
MAN:SKsh directory, where man points to any valid AmigaDos directory.
This step will create such a directory if it does not exist, and copy
the manpages there.  The manpages are extracted from the Reference.doc
and ExtCmds.doc files in the doc directory.  You must have enough disk
space to store the manpages.

You may choose to skip this step, but if you do, you will be unable to
use the SKsh manpages.
"

perf_man=FALSE
line yn "Do you wish to perform this step? $b[Y/n]$e > " 20

if [ $(expr substr $(toupper "$yn") 1 1) != 'N' ]
then
   perf_man=TRUE
   clear
   if [ ! -m 'MAN:' ]
   then
      echo "You do not currently have a MAN: assignment.  You must make
one now in order to install the manpages.\n"

      man_dir='sys:man'
   else
      man_dir=$(resolve_dir "MAN:")
      echo "Your current MAN: directory is $man_dir.  Press return to
use this directory, or type in a new one."
   fi

   read_dir "Please enter the directory which will contain the SKsh" \
            "manpage entries" "$man_dir" 'directory'
   man_dir=$(resolve_dir "$in_dir")

   assign MAN: "$man_dir"
   
   sman_dir=$(tackon "$man_dir" SKsh)
   mkdir -p "$sman_dir" || error "Can't create $sman_dir" || ck_terminate
   
   check_files 'PWD' 'bin/doc2man' || ck_terminate
   
   clear
   echo "Extracting manpages.....\n"
   bin/doc2man doc/Reference.doc doc/ExtCmds.doc
   echo
   line yn "Done extracting SKsh manpages.  Press return > " 0
else
   echo
   line yn "Skipping manpage extraction.  Press return > " 0
fi


# -------------- step 8 -----------------------------------------------

clear
echo "${b}STEP EIGHT: manual steps -------------------------------------${e}"

echo "
Some manual steps may be necessary to finish installing SKsh.  A
list of these steps will be generated here."

read_dir "Please enter the file name which contains your AmigaDos " \
         "startup instructions" "$st_file" 'file'

st_file="$in_dir"

echo -n "Press return to continue: > "

read yn;

stepnum=1
rm -f "$ms_file" >nil:

clear
echo '\n--- Manual Steps Necessary for SKsh Installation --------------\n'
echo '\n--- Manual Steps Necessary for SKsh Installation --------------\n' \
     >> "$ms_file"

ss_cont=$(ram:cat "$st_file")    # store away startup-sequence in variable

if check_ss 'echo "$ss_cont" | ram:grep -is ".bra "' \
   "Insert '.bra [' in $st_file (unless c:execute is Arp)"
then true; else inc stepnum; fi

if check_ss 'echo "$ss_cont" | ram:grep -is ".ket "' \
   "Insert '.ket ]' in $st_file (unless c:execute is Arp)"
then true; else inc stepnum; fi

if check_ss 'echo "$ss_cont" | ram:grep -is "stack "' \
   "Insert 'stack 8000' (or larger) in $st_file"
then true; else inc stepnum; fi

if check_ss 'echo "$ss_cont" | ram:grep -i "t: " | ram:grep -si "assign "' \
   "Insert 'makedir >nil: ram:tmp' in $st_file" \
   "Insert 'assign t: ram:tmp' in $st_file"
then true; else inc stepnum 2; fi

if check_ss 'echo "$ss_cont" | ram:grep -i "env: " | ram:grep -si "assign "' \
   "Insert 'makedir >nil: t:env' in $st_file" \
   "Insert 'assign env: t:env' in $st_file"
then true; else inc stepnum 2; fi

if check_ss 'echo "$ss_cont" | ram:grep -i "sksh: " | ram:grep -si "assign "' \
   "Insert 'assign sksh: $init_dir' in $st_file"
then
   if check_ss 'echo "$ss_cont" | ram:grep -i "sksh: " | ram:grep -i "assign " | \
      ram:grep -si "$init_dir"' \
      "modify the the 'assign sksh:' statement in $st_file
      to read 'assign sksh: $init_dir'"
   then true; else inc stepnum; fi
else inc stepnum; fi

if check_ss 'echo "$ss_cont" | ram:grep -i "skshbin: " | ram:grep -si "assign "' \
   "Insert 'assign skshbin: $bin_dir' in $st_file"
then
   if check_ss 'echo "$ss_cont" | ram:grep -i "skshbin: " | ram:grep -i "assign " | \
      ram:grep -si "$bin_dir"' \
      "modify the the 'assign sksh:' statement in $st_file
      to read 'assign sksh: $bin_dir'"
   then true; else inc stepnum; fi
else inc stepnum; fi

if check_ss 'echo "$ss_cont" | ram:grep -i "skshscr: " | ram:grep -si "assign "' \
   "Insert 'assign skshscr: $scr_dir' in $st_file"
then
   if check_ss 'echo "$ss_cont" | ram:grep -i "skshscr: " | ram:grep -i "assign " | \
      ram:grep -si "$scr_dir"' \
      "modify the the 'assign sksh:' statement in $st_file
       to read 'assign sksh: $scr_dir'"
   then true; else inc stepnum; fi
else inc stepnum; fi

if check_ss 'echo "$ss_cont" | ram:grep -i "vmagic: " | ram:grep -si "assign "' \
   "Insert 'assign vmagic: <dir containing view magic files>'
       in $st_file (use step $stepnum only if you wish
       to use the SKsh 'view' utility)"
then true
else inc stepnum; fi


if [ "$perf_man" = 'TRUE' ]
then
if check_ss 'echo "$ss_cont" | ram:grep -i "man: " | ram:grep -si "assign "' \
   "Insert 'assign MAN: $man_dir' in $st_file"
then
   if check_ss 'echo "$ss_cont" | ram:grep -i "skshscr: " | ram:grep -i "assign " | \
      ram:grep -si "$scr_dir"' \
      "modify the the 'assign MAN:' statement in $st_file
       to read 'assign sksh: $man_dir'"
   then true; else inc stepnum; fi
else inc stepnum; fi
fi

mypath=$(tackon "$sksh_dir" 'sksh')

if check_ss 'echo "$ss_cont" | ram:grep -i "resident " | ram:grep -si "sksh"' \
   "Insert 'c:resident $mypath' in $st_file (this step
       optional, but it will save memory if SKsh is invoked
       from a NewCLI window)"
then true
else inc stepnum; fi

if [ "$stepnum" -le 1 ]
then
   echo "\n** No manual steps necessary **\n"
   rm -f "$ms_file" >nil:
else
   echo "\nA listing of the manual steps has been placed in '$ms_file'\n"
fi

line yn "Press return to continue: > "

# -------------- done -------------------------------------------------

clear
echo "${b}DONE: installation complete ----------------------------------${e}"

echo "
The SKsh installation is complete.  If you performed step 3 (install
files), then the files in this directory have been copied to their
proper installation directories, and you may delete the files in this
directory.   However, the files in the 'scr_source' and 'misc'
directories have not been installed, as they are not necessary to run
SKsh.  If you wish to keep them, you should copy or move them to a
safe place.

${b}SKsh is freely distributable software.  It is copyrighted, and is
_not_ public domain.${e}  Please see UserMan.doc for copyright details.
"

if [ -f "$ms_file" ]
then
   echo "Don't forget to perform the manual steps which are listed in the
'$ms_file' file.
"
fi

cleanup
ck_terminate
