home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ezirc12o.zip / setup.cmd < prev   
OS/2 REXX Batch file  |  1997-12-26  |  10KB  |  348 lines

  1. /*    Setup script for EZirc
  2.  
  3.   Creates folder and various other objects
  4.   Adjust paths in INI and scripts for INSTALL path.
  5. */
  6.  
  7. Call Init
  8.  
  9. Setup:
  10. call getkeypress
  11. if proceed = "QUIT" then signal end
  12. if proceed = "NO" then signal setup
  13.  
  14. Lets_Go:
  15. say '     * Please wait while EZirc is installed to 'dir
  16. say ' '
  17.  
  18. /* Check that destination exists, if not make it. */
  19. call Directory_Make
  20.  
  21. /* Define Files to setup on the desktop */
  22. docs = dir"\html\EZIRC.HTM"
  23. exename = dir'\EZIRC.EXE'
  24.  
  25. say '     Unpacking Distribution Package to 'dir
  26. '@unzip install -d 'dir' > nul'
  27.  
  28. say '     Customizing the INI'
  29. call ModifyINI
  30. say '     Customizing paths in scripts.'
  31. call ModifyScripts
  32. say '     Creating WPS objects'
  33. call CreateObjects
  34. call SysOpenObject "<EZIRC_FLDR>","DEFAULT","TRUE"
  35.  
  36. End:
  37. say '     ALL DONE!'
  38. return
  39.  
  40. /* ===================================================== */
  41. /*               procedures below here.                  */
  42. /* ===================================================== */
  43.  
  44. Init :
  45.  
  46.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  47.   call SysLoadFuncs
  48.  
  49. /* Define Variables */
  50. dir = directory()
  51. env='OS2ENVIRONMENT'
  52. UserIdent=value('user',,env)
  53. if UserIdent = '' then UserIdent = 'yourID'
  54. testid=pos('@',UserIdent)
  55. if testid > 0 then UserIdent = 'yourID'
  56. realname = 'Your Realname String'
  57. nickname = 'YourNick'
  58.  
  59. /* trace ?r */
  60. return
  61.  
  62. greeting:
  63.  
  64. call SysCls
  65. Say ' '
  66. Say ' '
  67. say '     EZirc Installation.'
  68. say ' '
  69. Say '     This Script will install EZIRC and customise files for you.'
  70. Say ' '
  71. Say '     Current Settings for installation :'
  72. Say ' '
  73. Say '        1)  Install Path : 'dir
  74. Say '        2)  Your User ID : 'UserIdent
  75. Say '        3) Your Realname : 'realname
  76. Say '        4) Your NickName : 'nickname
  77. Say ' '
  78. Say '     Press Enter to Install with above Settings, or # to change. Q to Quit.'
  79. proceed = "NO"
  80. return
  81.  
  82. getkeypress:
  83. call greeting
  84. say ' '
  85. key = SysGetKey(NOECHO)
  86. say ' '
  87. keyhex = C2X(key)
  88. if keyhex='0D'
  89.    then  /* if key is RETURN */
  90.      proceed = "YES"
  91.    else
  92.     do
  93.       key = translate(key)
  94.       if key = 1
  95.          then
  96.            do
  97.              Say '    Enter Full path to install to, without the trailing /'
  98.              Say '    ie  d:\ezirc     or  d:\internet\ezirc'
  99.              Say ' '
  100.              result=charout(,'    Path : ')
  101.              string = '                                                                                '
  102.              Parse Upper Pull string .
  103.              dir = string
  104.              Call Directory_Check
  105.            end
  106.          else
  107.            if key = 2
  108.               then
  109.                 do
  110.                 Say '    Enter your User ID from your ID in your email address'
  111.                 Say '    ie if your email is xyz@provider.com  you enter xyz'
  112.                 Say ' '
  113.                 result=charout(,'    UserID : ')
  114.                 string = '                                                                                '
  115.                 Parse Pull string .
  116.                 UserIdent = String
  117.                 end
  118.               else
  119.                 if key = 3
  120.                    then
  121.                      do
  122.                      Say '    Enter the string you want in your Realname Field when you are connected.'
  123.                      Say '    A typical string might be    Firstname in City/state'
  124.                      Say ' '
  125.                      result=charout(,'    Realname : ')
  126.                      string = '                                                                                '
  127.                      Parse Pull string
  128.                      Realname = string
  129.                      end
  130.                    else
  131.                      if key = 4
  132.                         then
  133.                           do
  134.                           Say '    Enter the NICKNAME you would like to use while on IRC.'
  135.                           Say '    Rules for Nicknames are Max 9 Char. And no special Characters'
  136.                           Say '    Characters like _ for a space are allowed.'
  137.                           Say '    Avoid the | char, as it is used in scripts to seperate multiple commands.'
  138.                           Say ' '
  139.                           result=charout(,'    NickName : ')
  140.                           string = '                                                                                '
  141.                           Parse Pull string .
  142.                           NickName = String
  143.                           end
  144.                         else
  145.                           if key = 'Q'
  146.                              then
  147.                                proceed = "QUIT"
  148.     end
  149. return
  150.  
  151. Directory_Check:
  152.        /* Check the DRIVE exists */
  153.        testdrive=substr(dir,1,2)
  154.        info = SysDriveInfo(testdrive)
  155.        if info = ''
  156.          then /* No Drive, then lets go back for a new KEY Press */
  157.            do
  158.              say '     Destination Drive Doesn'"'"'t Exist.'
  159.              say '     Resetting to current path'
  160.              dir = directory()
  161.              say '     Press any key to continue'
  162.              key = SysGetKey()
  163.            end
  164.          else
  165.            do
  166.              /* in case user entered a trailing /  Strip it. */
  167.              dir = strip(dir,'T','/')
  168.              dir = strip(dir,'T','\')
  169.            end
  170. return
  171.  
  172. Directory_Make:
  173.  
  174. /* Drive Exists, so lets make the path */
  175. say '     Creating Path 'dir
  176. rc = SysMkDir(dir)
  177. if rc = 0
  178.    then
  179.     say'     Directory creation was successful.'
  180.    else
  181.     if rc = 5
  182.        then
  183.         say '     Directory Already Exists. So lets use it.'
  184.        else
  185.         DO
  186.          /* Any other Return Code is an Error, so report and FAIL */
  187.          if rc = 2   then say'     * Error.  File not found.'
  188.          if rc = 3   then say'     * Error.  Path not found.'
  189.          if rc = 26  then say'     * Error.  Not a DOS disk.'
  190.          if rc = 87  then say'     * Error.  Invalid parameter.'
  191.          if rc = 108 then say'     * Error.  Drive locked.'
  192.          if rc = 206 then say'     * Error.  Filename exceeds range.'
  193.          say '     * Fatal Error, can not continue.'
  194.          Signal End
  195.         END
  196. return
  197.  
  198. ModifyINI:
  199. /* Source File to patch */
  200. source= dir"\ezirc.ini"
  201.  
  202. /* Lets Load it */
  203. call loadfile
  204.  
  205. /* for all the following Set the Old and New strings then Search & Replace */
  206.  
  207. ReplaceString = '.\'
  208. newstring = dir"\"
  209. call SearchnReplace
  210.  
  211. replacestring = 'yourID'
  212. newstring = UserIdent
  213. call SearchnReplace
  214.  
  215. replacestring = 'Your_Realname_String'
  216. newstring = realname
  217. call SearchnReplace
  218.  
  219. replacestring = 'YourNick'
  220. newstring = nickname
  221. call SearchnReplace
  222.  
  223. /* Done with this file, lets save it. */
  224. Call SaveFile
  225.  
  226. Return
  227.  
  228. ModifyScripts:
  229. /* adjust driver letters in scripts/aliases from x: to install_drive */
  230. ReplaceString = 'x:'
  231. newstring = "="dir
  232.  
  233. source= dir"\alias\type_it.cmd"
  234. call ProcessFile
  235.  
  236. source= dir"\script\finger.cmd"
  237. call ProcessFile
  238.  
  239. source= dir"\script\page.cmd"
  240. call ProcessFile
  241.  
  242. source= dir"\script\sendfile.cmd"
  243. call ProcessFile
  244.  
  245. source= dir"\script\sidoh.cmd"
  246. call ProcessFile
  247.  
  248. source= dir"\script\siwoohoo.cmd"
  249. call ProcessFile
  250.  
  251. Return
  252.  
  253. ProcessFile:
  254. call loadfile
  255. call SearchnReplace
  256. Call savefile
  257. return
  258.  
  259. CreateObjects:
  260.  
  261.     If  SysCreateObject("WPFolder","EZirc for Os/2 ","<WP_DESKTOP>","OBJECTID=<EZIRC_FLDR>") then
  262.     do
  263.           If SysCreateObject("WPProgram", "EZirc", "<EZIRC_FLDR>","EXENAME="exename";STARTUPDIR="dir";PROGTYPE=PM")  Then
  264.           do
  265.                Say '     Folder and program objects have been created'
  266.                url1 = 'file:///'docs
  267.                rc = SysCreateObject( 'WPUrl', 'EZirc Manual', '<EZIRC_FLDR>', 'OBJECTID=<EZIRC_MANUAL>;URL='url1';', 'replace' )
  268.           end
  269.           Else
  270.              Say '     * Could not create program object'
  271.     End
  272.     Else
  273.        Say '     * Could not create folder '
  274.  
  275. return
  276.  
  277. LoadFile:
  278.  
  279. lines.0=0
  280.    /* open file for read */
  281.    resultCode = stream( source , 'C', 'OPEN READ')
  282.    if resultCode  \= 'READY:' then
  283.    do
  284.       say 'stream open of 'source' returned "'resultCode'"'
  285.       exit
  286.    end
  287.    /* load each line and store in array lines */
  288.    do while lines( source )
  289.       newline = linein( source )
  290.       /* Store lines in Array LINES */
  291.       count= lines.0 + 1
  292.       lines.0 = count
  293.       lines.count=newline
  294.    end
  295.    /* close file */
  296.    resultCode = stream( source, 'C', 'CLOSE')
  297.    if resultCode  \= 'READY:' then
  298.    do
  299.       say 'stream close returned "'resultCode'"'
  300.       exit
  301.    end
  302.  
  303. Return
  304.  
  305. SearchnReplace:
  306. /* Search for replacestring and replace with NewString */
  307.  
  308. do i=1 to lines.0
  309.    replace_len=length(replacestring)
  310.    dlexist = pos(replacestring,lines.i)
  311.    if dlexist > 0
  312.     then
  313.       do
  314.       lines.i = delstr(lines.i,dlexist,replace_len)
  315.       lines.i = insert(newstring,lines.i,dlexist-1)
  316.       end
  317.     else
  318.       NOP
  319. end
  320. Return
  321.  
  322. SaveFile:
  323.    '@del 'source
  324.    /* open file for write */
  325.    resultCode = stream( source , 'C', 'OPEN WRITE')
  326.    if resultCode  \= 'READY:' then
  327.    do
  328.       say 'stream open of 'source' returned "'resultCode'"'
  329.       exit
  330.    end
  331.  
  332.    /* load each line and store in array lines */
  333.    do i=1 to lines.0
  334.       writeline = lines.i
  335.       rc = lineout( source , writeline )
  336.    end
  337.  
  338.    /* close file */
  339.    resultCode = stream( source, 'C', 'CLOSE')
  340.    if resultCode  \= 'READY:' then
  341.    do
  342.       say 'stream close returned "'resultCode'"'
  343.       exit
  344.    end
  345.  
  346. return
  347.  
  348.