home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lansystk.zip / MPTSUTIL / APPLETS / CASINST.CMD < prev    next >
OS/2 REXX Batch file  |  1998-05-08  |  16KB  |  590 lines

  1. /* Stripped by STRIPRX.EXE */
  2. CASINST:
  3. parse upper arg inparms
  4. signal ON HALT NAME stopit
  5. goodrc = 0
  6. badrc = 1
  7. stdout = "STDOUT:"
  8. target = ""
  9. source = ""
  10. logfile= ""
  11. first = ""
  12. last = ""
  13. writeit = 0
  14. badparmf = 0
  15. parse source . . srccmd 
  16. srcdrv = strip(filespec('drive',srccmd),"B","\")
  17. srcpath = strip(filespec('path',srccmd),"B","\")
  18. srcdir = srcdrv"\"srcpath 
  19. if srcpath <> ""
  20. then msgfile = srcdrv||"\"||srcpath||"\CASSETUP.MSG"
  21. else msgfile = srcdrv||"\CASSETUP.MSG"
  22. StartingDir = Directory() 
  23. xrc = badrc
  24. if testparms() = goodrc THEN do 
  25. if testenv() = goodrc THEN do 
  26. if chkdrive() = goodrc THEN do 
  27. if installit() = goodrc THEN do 
  28. xrc = UpdateConfigSys() 
  29. end
  30. end
  31. end
  32. end
  33. "@ERASE " errfile ">NUL 2>NUL"
  34. if logfile <> stdout & logfile <> "" then 
  35. rc = stream(logfile,'c','close')
  36. CALL Directory(savetardir)
  37. CALL DIRECTORY StartingDir
  38. exit xrc
  39. TESTPARMS:
  40. xrc = 0
  41. inparms = strip(inparms,"B")
  42. if inparms = "?" | inparms = "/?" then signal givehelp
  43. rc = RxFuncAdd("SYSLOADFUNCS","REXXUTIL","SYSLOADFUNCS")
  44. rc = SysLoadFuncs()
  45. syslvl = SysOS2Ver()
  46. head = "--------------------------------------------------------------------"
  47. if syslvl = "" then do
  48. rc = lineout(logfile,head)
  49. rc = lineout(logfile,"          Date: "date("L")"        Time:" time())
  50. rc = lineout(logfile,"Unable to load RexxUtils which is required for the install.")
  51. rc = lineout(logfile,"Terminating install processing.")
  52. rc = lineout(logfile,head)
  53. return badrc
  54. end
  55. parmt_ckt = 0 
  56. parms_ckt = 0 
  57. parml_ckt = 0 
  58. DO WHILE badparmf<>1 & inparms <> ""
  59. PARSE VAR inparms iphead inparms
  60. badparms = iphead
  61. iphead = TRANSLATE(iphead)
  62. sep = SUBSTR(iphead,3,1)
  63. IF sep <> ":" & sep <> "=" THEN
  64. DO
  65. badparmf = 1
  66. ITERATE
  67. END
  68. SELECT
  69. WHEN LEFT(iphead,2) = "/T" THEN
  70. DO
  71. parmt_ckt = parmt_ckt+1 
  72. target = SUBSTR(iphead,4)
  73. IF target = "" | target = "\" | target = " " THEN
  74. badparmf = 1
  75. END
  76. WHEN LEFT(iphead,2) = "/S" THEN
  77. DO
  78. parms_ckt = parms_ckt+1 
  79. source = SUBSTR(iphead,4)
  80. IF source = "" | source = "\" | source = " " THEN
  81. badparmf = 1
  82. END
  83. WHEN LEFT(iphead,2) = "/L" THEN do
  84. parml_ckt = parml_ckt+1 
  85. logfile = SUBSTR(iphead,4)
  86. end
  87. OTHERWISE
  88. badparmf = 1
  89. END 
  90. END
  91. if parml_ckt > 1 then do 
  92. badparmf = 1
  93. badparms = "Multiple /L= parameters"
  94. end
  95. if parms_ckt > 1 then do 
  96. badparmf = 1
  97. badparms = "Multiple /S= parameters"
  98. end
  99. if parmt_ckt > 1 then do 
  100. badparmf = 1
  101. badparms = "Multiple /T= parameters"
  102. end
  103. IF logfile = "" THEN
  104. logfile = stdout
  105. xrc = stream(logfile,'c','open write')
  106. if xrc <> "READY:" then do
  107. say "Unable to open logfile ("logfile")."
  108. say "Return code from open file attempt ("xrc")".
  109. logfile = ""
  110. return badrc
  111. end
  112. IF badparmf <> 1 THEN do
  113. source = STRIP(source,'t','\')
  114. target = STRIP(target,'t','\')
  115. IF source = "" THEN
  116. source = STRIP(srcdir,'t','\') 
  117. IF target = "" THEN
  118. target = source
  119. IF IsFullyQualifiedPath(source,0) = 0 THEN
  120. DO
  121. CALL LINEOUT logfile, "Bad Source parameter."
  122. badparmf = 1
  123. badparms = "/S="source
  124. RETURN goodrc
  125. END
  126. IF IsFullyQualifiedPath(target,1) = 0 THEN
  127. DO
  128. CALL LINEOUT logfile, "Bad Target parameter."
  129. badparmf = 1
  130. badparms = "/T="target
  131. RETURN goodrc
  132. END
  133. qrc = SysFileTree(source||"\*.*","stemv","F")
  134. if stemv.0 = 0 then do
  135. CALL LINEOUT logfile,"No files found in source directory."
  136. badparmf = 1
  137. badparms = "/S="||strip(source,"T","\")
  138. end
  139. end
  140. return goodrc
  141. IsFullyQualifiedPath: PROCEDURE 
  142. parse arg pathname,create
  143. ThisDir = DIRECTORY()
  144. IF DATATYPE(SUBSTR(pathname,1,1),"M") = 0 THEN
  145. RETURN 0
  146. IF SUBSTR(pathname,2,1) <> ":" THEN
  147. RETURN 0
  148. IF LENGTH(pathname) > 2 & SUBSTR(pathname,3,1) <> "\" THEN
  149. RETURN 0
  150. IF LENGTH(pathname) = 2 THEN
  151. pathname = pathname"\"
  152. IF create = 1 THEN
  153. CALL CreateDir pathname
  154. PathDrive = FILESPEC("D",pathname)
  155. PathDriveHome = DIRECTORY(pathdrive)
  156. NewDir = DIRECTORY(pathname)
  157. IF TRANSLATE(pathname) <> TRANSLATE(NewDir) THEN
  158. DO
  159. CALL DIRECTORY PathDriveHome
  160. CALL DIRECTORY ThisDir
  161. RETURN 0
  162. END
  163. CALL DIRECTORY PathDriveHome
  164. CALL DIRECTORY ThisDir
  165. RETURN 1
  166. TESTENV:
  167. xrc = 0
  168. dummy = Logmsg(1","msgfile)
  169. title = LogMsg(92","msgfile)
  170. terminate = LogMsg(94","msgfile)
  171. rc = lineout(logfile,"  ")
  172. rc = lineout(logfile,"  ")
  173. rc = lineout(logfile,head)
  174. rc = lineout(logfile,"          Date: "date("L")"        Time: "time())
  175. rc = lineout(logfile,"               "title)
  176. rc = lineout(logfile,head)
  177. parse var syslvl first"."level
  178. if first < 2 then do
  179. msg = LogMsg(93","msgfile","syslvl)
  180. rc = lineout(logfile,msg)
  181. msg = terminate
  182. rc = lineout(logfile,94)
  183. rc = lineout(logfile,head)
  184. xrc = badrc
  185. end
  186. else do 
  187. if badparmf = 1 then do
  188. msg = LogMsg(107","msgfile","badparms)
  189. rc = lineout(logfile,msg)
  190. rc = lineout(logfile,terminate)
  191. rc = lineout(logfile,head)
  192. xrc = badrc
  193. end
  194. end
  195. return xrc
  196. CHKDRIVE:
  197. xrc = 0
  198. drivemap = SysDriveMap()
  199. drive = Filespec("drive",target)
  200. parse upper var drive drive
  201. if translate(drive) = "A:" | translate(drive) = "B:" then do 
  202. msg = LogMsg(124","msgfile","target)
  203. rc = lineout(logfile,msg)
  204. rc = lineout(logfile,terminate)
  205. rc = lineout(logfile,head)
  206. xrc = badrc
  207. end
  208. else do
  209. if wordpos(drive,drivemap) = 0 | drive = "" then do
  210. msg = LogMsg(97","msgfile","target)
  211. rc = lineout(logfile,msg)
  212. rc = lineout(logfile,terminate)
  213. rc = lineout(logfile,head)
  214. xrc = badrc
  215. end
  216. end
  217. return xrc
  218. INSTALLIT:
  219. tardrive = FILESPEC("D",target)
  220. savetardir = DIRECTORY(tardrive)
  221. CALL DIRECTORY target
  222. if logfile <> stdout then do
  223. xpath = filespec("path",logfile)
  224. xdrive = filespec("drive",logfile)
  225. errfile = SysTempFileName(xdrive||xpath||"XX????.TMP")
  226. end
  227. xrc = 0
  228. IF TRANSLATE(source) <> TRANSLATE(target) THEN DO
  229. msg = LogMsg(100","msgfile)
  230. rc = lineout(logfile,msg)
  231. target = target"\"
  232. source = source"\"
  233. if logfile = stdout
  234. then "@copy " source||"CAS*.*  >>NUL"
  235. else "@copy " source||"CAS*.*  >>"errfile "2>&1"
  236. xrc = chkcopy(rc)
  237. if xrc = 0 then do
  238. if logfile = stdout
  239. then "@copy " source||"*.pro  >>NUL"
  240. else "@copy " source||"*.pro  >>"errfile "2>&1"
  241. xrc = chkcopy(rc)
  242. if xrc = 0 then do
  243. if logfile = stdout
  244. then "@copy " source||"*.scr  >>NUL"
  245. else "@copy " source||"*.scr  >>"errfile "2>&1"
  246. xrc = chkcopy(rc)
  247. if xrc = 0 then do
  248. if logfile = stdout
  249. then "@copy " source||"CMSGBOX.EXE >>NUL"
  250. else "@copy " source||"CMSGBOX.EXE >>"errfile "2>&1"
  251. xrc = chkcopy(rc)
  252. end
  253. end
  254. end
  255. END
  256. if xrc = 0 then do
  257. msg = LogMsg(101","msgfile)
  258. rc = lineout(logfile,msg)
  259. keypath = target
  260. keypath = STRIP(keypath,'t','\')
  261. profile = "CASSETUP.DAT"
  262. zrc = stream(profile,"c","open read")
  263. if zrc <> "READY:" then do
  264. msg = LogMsg(102","msgfile","zrc)
  265. rc = lineout(logfile,msg)
  266. end
  267. z = 0
  268. do while lines(profile) > 0
  269. z = z+1
  270. line.z = linein(profile)
  271. line.z = strip(line.z,"B")
  272. if substr(line.z,1,8) = "NISTDIR=" then do
  273. line.z = "NISTDIR="||keypath
  274. end
  275. end
  276. rc = stream(profile,"c","close")
  277. "@ERASE " profile ">>NUL"
  278. rc = stream(profile,"c","open write")
  279. do i = 1 to z
  280. rc = lineout(profile,line.i)
  281. end
  282. rc = stream(profile,"c","close")
  283. msg = LogMsg(103","msgfile)
  284. rc = lineout(logfile,msg)
  285. parms = "PROGTYPE=PM;",
  286. ||"OBJECTID=<WP_SURI>;",
  287. ||"EXENAME="||keypath||"\CASSETUP.EXE;",
  288. ||"STARTUPDIR="keypath||";",
  289. ||"ICONFILE=CASSETUP.ICO;"
  290. zrc = SysCreateObject(,
  291. "WPProgram",, 
  292. "Code Server^Setup",, 
  293. "<WP_DESKTOP>",, 
  294. parms,, 
  295. "replace") 
  296. if zrc = 1 then do
  297. msg = LogMsg(104","msgfile)
  298. rc = lineout(logfile,msg)
  299. end
  300. else do
  301. msg = LogMsg(105","msgfile","zrc)
  302. rc = lineout(logfile,msg)
  303. xrc = badrc
  304. end
  305. rc = lineout(logfile,head)
  306. msg = LogMsg(106","msgfile)
  307. rc = lineout(logfile,msg)
  308. end
  309. return xrc
  310. UpdateConfigSys: 
  311. CALL LINEOUT logfile,"Updating config.sys..."
  312. nowdir = Directory() 
  313. ADDRESS CMD "@casbootd"
  314. bootd = SUBSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ",rc,1)
  315. configsys = bootd":\CONFIG.SYS"
  316. path_found = 0
  317. dpath_found = 0
  318. libpath_found = 0
  319. config_updated = 0
  320. IF STREAM(configsys,'c','query exists') = "" THEN
  321. DO
  322. CALL LINEOUT logfile, "Unable to find" configsys"."
  323. CALL LINEOUT logfile, "You should manually add "nowdir" to PATH and LIBPATH."
  324. RETURN x2d('0816')
  325. END
  326. tempfile = SysTempFileName(bootd":\XX????.TMP")
  327. DO WHILE LINES(configsys) > 0
  328. line = LINEIN(configsys)
  329. sline = TRANSLATE(STRIP(line))
  330. PARSE VAR sline first rest
  331. first = TRANSLATE(STRIP(first))
  332. rest = TRANSLATE(STRIP(rest))
  333. IF LEFT(first,8) = "LIBPATH=" THEN
  334. DO
  335. libpath_found = 1
  336. line = UpdateLine(line,nowdir)
  337. END
  338. ELSE
  339. IF first = "SET" THEN
  340. IF LEFT(rest,5) = "PATH=" THEN
  341. DO
  342. path_found = 1
  343. line = UpdateLine(line,nowdir)
  344. END
  345. ELSE
  346. IF LEFT(rest,6) = "DPATH=" THEN
  347. DO
  348. dpath_found = 1
  349. line = UpdateLine(line,nowdir)
  350. END
  351. CALL LINEOUT tempfile,line
  352. END
  353. CALL STREAM configsys,'c','CLOSE'
  354. CALL STREAM tempfile,'c','CLOSE'
  355. badcs = 0
  356. IF path_found = 0 THEN
  357. DO
  358. CALL LINEOUT logfile,"No SET PATH= statement was found in config.sys"
  359. badcs = 1
  360. END
  361. IF dpath_found = 0 THEN
  362. DO
  363. CALL LINEOUT logfile,"No SET DPATH= statement was found in config.sys"
  364. badcs = 1
  365. END
  366. IF libpath_found = 0 THEN
  367. DO
  368. CALL LINEOUT logfile, "No LIBPATH= statement was found in config.sys"
  369. badcs = 1
  370. END
  371. IF badcs = 0 & config_updated = 1 THEN
  372. DO
  373. bkpfile = SysTempFileName(bootd":\config.???")
  374. IF bkpfile = "" THEN
  375. DO
  376. CALL LINEOUT logfile,"Unable to back up your existing config.sys."
  377. CALL LINEOUT logfile,"The updated config.sys is in file "tempfile
  378. RETURN x2d('0816')
  379. END
  380. CALL ON ERROR NAME ucsError
  381. ADDRESS CMD "@COPY "configsys bkpfile
  382. xrc = rc
  383. CALL OFF ERROR
  384. IF xrc <> 0 THEN
  385. DO
  386. CALL LINEOUT logfile, "Unable to back up your existing config.sys."
  387. CALL LINEOUT logfile, "The updated config.sys is in file "tempfile
  388. RETURN x2d('0816')
  389. END
  390. CALL ON ERROR NAME ucsError
  391. ADDRESS CMD "@COPY "tempfile configsys
  392. xrc = rc
  393. CALL OFF ERROR
  394. IF xrc <> 0 THEN
  395. DO
  396. CALL LINEOUT logfile, "Unable to write the updated config.sys."
  397. CALL LINEOUT logfile, "A backup copy of your original config.sys is in file "bkpfile
  398. CALL LINEOUT logfile, "The updated config.sys is in file "tempfile
  399. RETURN
  400. END
  401. CALL LINEOUT logfile, "Your original config.sys was backed up in file "bkpfile
  402. CALL LINEOUT logfile, "Your config.sys has been updated.  Reboot before running CASSETUP."
  403. CALL SysFileDelete(tempfile)
  404. END
  405. ELSE
  406. IF badcs = 1 THEN
  407. DO
  408. CALL LINEOUT logfile, configsys" was not updated."
  409. CALL LINEOUT logfile, "You should manually add "nowdir" to PATH and LIBPATH, then reboot."
  410. END
  411. ELSE
  412. DO
  413. CALL LINEOUT logfile, "Your config.sys was already correct. It was not updated."
  414. CALL LINEOUT logfile, "You may use CASSETUP without rebooting."
  415. CALL SysFileDelete(tempfile)
  416. CALL SysFileDelete(bkpfile)
  417. END
  418. RETURN x2d('ff00')
  419. ucsError:
  420. nop
  421. RETURN
  422. UpdateLine: PROCEDURE EXPOSE config_updated
  423. parse arg line,dir
  424. PARSE VAR line first"="rest
  425. rest = strip(rest,'t')
  426. trest = TRANSLATE(rest)
  427. tdir = TRANSLATE(dir)
  428. DO WHILE trest <> ""
  429. PARSE VAR trest ThisPath";"trest
  430. IF ThisPath = tdir THEN
  431. RETURN line
  432. END
  433. rest = strip(rest,'t',';')||";"||STRIP(dir,'t',';')||';'
  434. config_updated = 1
  435. RETURN first"="rest
  436. GIVEHELP:
  437. "@CLS"
  438. say ""
  439. say ""
  440. say "------------------------------------------------------------------ "
  441. say "  Name:          CASINST                    Version:  1.2          "
  442. say "  Function:      CASSETUP installation program                     "
  443. say "                 - Creates user inputted <target_path>             "
  444. say "                   directory structure.                            "
  445. say "                 - Copies the following files from source directory"
  446. say "                   .  CAS*.*           (CASSETUP source files)     "
  447. say "                   .  *.PRO            (Application profiles)      "
  448. say "                   .  *.SCR            (Appl create disk scripts)  "
  449. say "                   .  CMSGBOX.EXE      (Message box routine)       "
  450. say "                 - Updates CASSETUP.DAT (GUI profile) to reflect   "
  451. say "                   user target path information.                   "
  452. say "                 - Creates WorkPlace shell program object.         "
  453. say "                 - Updates config.sys "
  454. say "                                                                   "
  455. say "  Syntax:        CASINST /T=<fully qualified drive and path>       "
  456. say "                         /S=<fully qualified drive and path>       "
  457. say "                         /L=<fully qualified file specification>   "
  458. say "                                                                   "
  459. say "  Dependencies:  REXX & REXUTILS,  OS/2 version 2.+                "
  460. say "                 CASSETUP.MSG,     casbootd.exe    CASSETUP Images "
  461. say "  Return code:   0 = successful, non-zero = ended in error         "
  462. say "------------------------------------------------------------------ "
  463. exit goodrc
  464. CHKCOPY: procedure expose badrc logfile errfile msgfile terminate head xdrive xpath stdout
  465. parse arg zrc
  466. xrc = 0
  467. if zrc <> 0 then do
  468. msg = LogMsg(99","msgfile","zrc)
  469. rc = lineout(logfile,msg)
  470. rc = lineout(logfile,terminate)
  471. rc = lineout(logfile,head)
  472. xrc = badrc
  473. if logfile <> stdout then do
  474. rc = lineout(logfile)
  475. tmpfile = SysTempFileName(xdrive||xpath||"XX????.TMP")
  476. "@TYPE " errfile ">" tmpfile
  477. "@COPY " logfile" /A + "tmpfile logfile " /B >>NUL"
  478. "@ERASE " tmpfile ">>NUL"
  479. end
  480. end
  481. return xrc
  482. LogMsg: procedure expose logfile
  483. parse arg inparms
  484. Parse var inparms msgno","msgfile","parm.1","parm.2","parm.3","parm.4","parm.5","parm.6","parm.7","parm.8","parm.9 . 
  485. msgfile = strip(msgfile,"B")
  486. msg = ""
  487. msgno = strip(msgno,"B")
  488. if STREAM(msgfile, 'c', 'query exists') == "" then do
  489. rc = lineout(logfile,'Log Message File' msgfile 'not found.')
  490. rc = lineout(logfile,'Can not log message number' msgno'.  Message parms were:')
  491. do i = 1 to 9
  492. if parm.i == ""
  493. then LEAVE
  494. else rc = lineout(logfile,"   "parm.i)
  495. end
  496. msg = ""
  497. end
  498. else do 
  499. xrc = STREAM(msgfile, 'c', 'open read')
  500. if xrc = "READY:" then do
  501. if DATATYPE(msgno) == 'NUM' then do
  502. OffsetX = CHARIN(msgfile, 32 + (msgno * 2), 2)
  503. wkvar = SUBSTR(OffsetX, 2, 1) || SUBSTR(OffsetX, 1, 1)
  504. StartingOffsetD = C2D(wkvar)
  505. OffsetX = CHARIN(msgfile, 32 + ((msgno+1) * 2), 2)
  506. wkvar = SUBSTR(OffsetX, 2, 1) || SUBSTR(OffsetX, 1, 1)
  507. EndingOffsetD = C2D(wkvar)
  508. startchar = StartingOffSetD
  509. endchar = EndingOffSetD
  510. lin=CHARIN(msgfile, startchar+1, endchar-startchar)
  511. do i = 1 to 9 
  512. n = POS("%" || i, lin)
  513. if (n <> 0) then do
  514. lin = DELSTR(lin, n, 2)
  515. temp = STRIP(parm.i)
  516. lin = INSERT(temp, lin, n-1)
  517. end
  518. end
  519. header = "CAS"
  520. n = LENGTH(msgno)
  521. do i = 4 to (7-n) 
  522. header = header || '0'
  523. end
  524. msgt = substr(lin,1,1) 
  525. lin = substr(lin,2)
  526. msg = lin
  527. end
  528. else do
  529. rc = lineout(logfile,'Invalid log message number' msgno'.  Message parms were:')
  530. do i = 1 to 9
  531. if parm.i == ""
  532. then LEAVE
  533. else rc = lineout(logfile,"   "parm.i)
  534. end
  535. msg = ""
  536. end
  537. rc = stream(msgfile,'c','close')
  538. end
  539. else do
  540. rc = lineout(logfile,'Unable to open Message file ('msgfile'), rc('xrc').')
  541. msg = ""
  542. end
  543. end
  544. RETURN msg
  545. CreateDir: PROCEDURE
  546. arg path
  547. workpath = path
  548. segments.0 = 0
  549. CALL SysMkDir workpath
  550. MyStem.0 = 0
  551. CALL SysFileTree workpath,"MYSTEM","D"
  552. IF MyStem.0 > 0 THEN
  553. RETURN 0
  554. DO while workpath <> ""
  555. PARSE VAR workpath ThisSeg"\"workpath
  556. i = segments.0 + 1
  557. segments.i = ThisSeg
  558. segments.0 = i
  559. END
  560. workpath = segments.1
  561. CALL SysMkDir workpath
  562. DO i = 2 to segments.0
  563. workpath = workpath || "\" || segments.i
  564. CALL SysMkDir workpath
  565. END
  566. RETURN 0
  567. DIRECTORY: procedure
  568. parse arg indir
  569. whereami = ""
  570. getflag = 1
  571. if indir <> "" then do
  572. whereami = "DIRECTORY"(indir)
  573. if whereami = "" then getflag = 0
  574. end
  575. if getflag = 1 then do
  576. temp = RXQUEUE("DELETE","DIRQUE1")
  577. nq = RXQUEUE("CREATE","DIRQUE1")
  578. oq = RXQUEUE("SET",nq)
  579. do i =1 to queued()
  580. pull zzz
  581. end
  582. "@CD |" RXQUEUE nq
  583. parse pull whereami
  584. temp = RXQUEUE("DELETE",nq)
  585. nq = RXQUEUE("SET",oq)
  586. end
  587. return whereami
  588. STOPIT:
  589. exit 1
  590.