/*  */
'@echo off'
call RxFuncAdd 'WriteIniString', 'VioTitle', 'WriteIniString'
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

arg fcpath instdrv
if instdrv='' then signal hello

inipath=instdrv'\os2ldr.ini'

call checkfile 'os2ldr'
call checkfile 'os2krnl.pat'

'cmd /c vpatch.cmd os2krnl.pat 'fcpath' os2krnl.os4'
if exist('os2krnl.os4')==0 then
do
  say 'Failed to patch, exiting...'
  exit
end

say 'Installing to drive 'instdrv
'attrib -R -S -H 'instdrv'\os2ldr >nul'
'attrib -R -S -H 'instdrv'\os2krnl.os4 >nul'

call WriteIniString inipath,'config','default','1'
call WriteIniString inipath,'config','timeout','5'

if exist(instdrv'\os2ldr')==0 then
do
  say 'Warning! os2ldr is not present on 'instdrv
end
else
do
if exist(instdrv'\os2ldr.ibm')==0 then
do
  'rename 'instdrv'\os2ldr os2ldr.ibm'
end
call WriteIniString inipath,'kernel','os2ldr.ibm','Original boot, RESTART'
end

copy os2ldr instdrv'\os2ldr >nul'
copy os4logo instdrv'\os4logo >nul'
copy os2krnl.os4 instdrv'\os2krnl.os4 >nul'
'attrib +R +S +H 'instdrv'\os2krnl.os4'

call WriteIniString inipath,'kernel','os2krnl','IBM kernel'
call WriteIniString inipath,'kernel','os2krnl.os4','OS/4 kernel, LOGSIZE=256, zeromem'

if exist(instdrv'\os2ldr')==0 then
do
  say '[1;33mUnable to find 'instdrv'\os2ldr, restore it from backup before next boot!![0;37m'
  exit
end
'attrib +R +S +H 'instdrv'\os2ldr'
say
say 'Done! ;)'

exit

hello:
  say 
  say '[1;33mThis command file install OS/4 kernel over you system![1;37m'
  say 
  say 'arguments are:[0;37m'
  say '  install.cmd <full_path_to_104a_debug_IBM_kernel> <drive_to_install>'
  say 
  say '[1;37mfor example:[0;37m'
  say '  install.cmd os2krnl d:'
  say 
  say '[1;37m104a debug kernel can be downloaded from here:[0;37m'
  say "  http://www.os2site.com/sw/upgrades/kernel/smp20050811d.zip"
  say 
  exit

checkfile:
  arg name
  if exist(name)==0 then
  do
    say 'Where is my 'name'?'
    exit
  end
  return

exist:
  arg name
  if stream(name, 'C', 'QUERY EXISTS') \='' then
    return 1
  return 0

