/* */
call RxFuncAdd 'SysIni', 'REXXUTIL', 'SysIni'
call RxFuncAdd 'SysSleep', 'REXXUTIL', 'SysSleep'
call RxFuncAdd 'SysGetKey', 'REXXUTIL', 'SysGetKey'
call RxFuncAdd 'SysCreateObject', 'REXXUTIL', 'SysCreateObject'
srcDir = directory()
installProg = stream(srcdir||'\inst2.exe', 'C', 'QUERY EXISTS')
if (installProg \= "") then do
   address cmd "@inst2.exe /s:"||srcDir
   /* say "Install prog returned: "||rc */
   /* if rc = 0 then do */
      rootPath=SysIni(SYSTEM, "Norman Data Defense Systems", "NsePath")
      if (rootPath \= "ERROR:") then do
         rootPath=left(rootPath, lastpos("\", rootPath)-1)
         if (pos("\Nvc", rootPath) > 0) then
            rootPath=left(rootPath, lastpos("\", rootPath)-1)

         say
         say "Installing Cat's Claw for OS/2"
         say
         say "Select:"
         say "  (1) Install/Update Cat's Claw for OS/2"
         say "  (2) Uninstall Cat's Claw for OS/2"
         say "  (3) Exit (no action)"
         say
         do until (choice='1')|(choice='2')|(choice='3')
            choice = SysGetKey('NOECHO');
         end
         select
            when choice = '1' then do
               say "Installing Cat's Claw for OS/2"
               say "Please wait..."
               address cmd '@gi.exe /root:'||rootPath
               address cmd '@copy Data\Nvc\Bin\Nvchook.sys '||GetBootDrive()||'\ > nul 2> nul'
               installProg = stream(rootPath||'\Nvc\Bin\CClaw.exe', 'C', 'QUERY EXISTS')
               if (installProg \= "") then do
                  address cmd '@cmd.exe /c "set beginlibpath='||rootPath||'\Nvc\Bin & '||installProg||' /Unload"'
                  call SysSleep 2
                  address cmd '@copy '||srcDir||'\Data\Nvc\Bin\CClaw.exe '||rootPath||'\Nvc\Bin > nul 2> nul'
                  address cmd '@cmd.exe /c "set beginlibpath='||rootPath||'\Nvc\Bin & '||installProg||' /Install"'
               end
               say
               say "Installation complete!"
               say "Please restart your computer now to activate the changes."
               say
               call SysGetKey 'NOECHO'
            end
            when choice = '2' then do
               installProg = stream(rootPath||'\Nvc\Bin\CClaw.exe', 'C', 'QUERY EXISTS')
               if (installProg \= "") then do
                  say "Uninstalling Cat's Claw for OS/2"
                  say "Please wait..."
                  address cmd '@cmd.exe /c "set beginlibpath='||rootPath||'\Nvc\Bin & '||installProg||' /Uninstall"'
                  call SysSleep 2
                  fileName = GetBootDrive()||'\delcc2.cmd'
                  call stream fileName, 'C', 'OPEN WRITE'
                  call lineout fileName, "/* Deletes NVC v5 from the system */"
                  call lineout fileName, "say 'Removing Cat''s Claw for OS/2 from the system'"
                  call lineout fileName, "say 'Please wait...'"
                  call lineout fileName, "call RxFuncAdd 'SysDestroyObject', 'REXXUTIL', 'SysDestroyObject'"
                  call lineout fileName, "call RxFuncAdd 'SysSleep', 'REXXUTIL', 'SysSleep'"
                  call lineout fileName, "address cmd '@delnvc5.exe > nul 2> nul'"
                  call lineout fileName, "address cmd '@del delnvc5.exe > nul 2> nul'"
                  call lineout fileName, "address cmd '@del "||fileName||" > nul 2> nul'"
                  call lineout fileName, "call SysDestroyObject '<NVC5_DEL_ME>'"
                  call lineout fileName, "say 'Cat''s Claw removed from system!'"
                  call lineout fileName, "call SysSleep 5"
                  address cmd '@copy delnvc5.exe '||GetBootDrive()||'\ > nul 2> nul'
                  call SysCreateObject 'WPProgram', 'Delete NVC 5', '<WP_START>', 'EXENAME='||fileName||';STARTUPDIR='||GetBootDrive()||'\;OBJECTID=<NVC5_DEL_ME>', 'U'
                  say
                  say "First phase complete!"
                  say "Please restart your computer to complete the removal of Cat's Claw for OS/2."
                  say
                  call SysSleep 2
                  call SysGetKey 'NOECHO'
               end
            end
            when choice = '3' then do
                exit 0
            end
         end
      end
   /* end */
end
else do
   say "ERROR: Run the install program from the source directory!"
   exit 2
end

exit 0

/*
GetBootDrive
   Use SysBootDrive (RexxUtils) if it is available, use RxBootDrive
   (RxExtras) if it is available, or use an alternate method to get the
   value if neither is available.  Uncomment following if GetBootDrive
   is imbedded in a routine.

   ***********************************************
      Snipped from the Pillarsoft Rexx page:
      http://www.pillarsoft.net/rexx/rexx.html
   ***********************************************
*/

GetBootDrive: Procedure
If \Rxfuncquery('SysBootDrive') Then
   bootdrive = SysBootDrive()       /* Object or Updated Classic Rexx */
Else
   Do
      If \Rxfuncquery('RxBootDrive') Then
         bootdrive = RxBootDrive()                        /* RxExtras */
      Else
         Do                       /* Examine various config.sys items */
            Parse Upper Value Value('PATH', ,'OS2ENVIRONMENT') ,
               With ':\OS2\SYSTEM' - 1 bootdrive + 2
            If bootdrive = '' Then
               bootdrive = ,
               Substr(Value('RUNWORKPLACE', ,'OS2ENVIRONMENT'), 1, 2 )
            If bootdrive = '' Then
               bootdrive = ,
               Substr(Value('COMSPEC', ,'OS2ENVIRONMENT'), 1, 2)
            If bootdrive = '' Then
               bootdrive = ,
               Substr(Value('OS2_SHELL', ,'OS2ENVIRONMENT'), 1, 2)
            If bootdrive = '' Then
               bootdrive = ,
               Substr(Value('SYSTEM_INI', ,'OS2ENVIRONMENT'), 1, 2)
            If bootdrive = '' Then
               bootdrive = ,
               Substr(Value('USER_INI', ,'OS2ENVIRONMENT'), 1, 2)
            If bootdrive = '' Then                      /* no guesses */
               bootdrive = 0
         End
   End
Return bootdrive               /* Returns BootDrive, letter and colon */

NCls: procedure
   call charout ,d2c(27)||'[37;46;1m'||d2c(27)||'[2J'
   return

NExit: procedure /* 1 arg, return code */ expose crlf
   /* call charout ,d2c(27)||'[24;5H'||d2c(27)||'[37;2m'||d2c(7) */
   call charout ,crlf||crlf||"[Press any key]"
   call SysGetKey 'NOECHO'
   call charout ,d2c(27)||'[0m'||d2c(27)||'[2J'
   parse arg rc
   exit rc

