/* * INSTALL.CMD - NOSA Client V1.10 - cla@clanganke.de - 1999-2008 * * Syntax: install [/Reset] * * /Reset - resets all values to default * */ /* First comment is used as help text */ /* CHECKVER */ /* ***** BEGIN LICENSE BLOCK ***** * Version: CDDL 1.0 * * The contents of this file are subject to the COMMON DEVELOPMENT AND * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at http://www.sun.com/cddl/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is * "netlabs.org Open Source Archive Administrator/Client" * * The Original Distribution Package is named * "netlabs.org Open Source Archive Administrator/Client" * and maintained and distributed by the Initial Developer * and/or netlabs.org only. * * In addition to the CDDL the following applies: * If you modify the Original Code, you may distribute it only * as a part of a distribution package where * - the name of the package, created directories or * OS2.INI entries do not contain any of the terms * - "netlabs.org Open Source Archive" * - "NOSA" * - "NOSAC" * - "NOSAADM" * - neither netlabs.org nor the Initial Developer is stated as * the vendor or originator of the resulting Distribution Package, * which contains the Modified Code. * * The Initial Developer of the Original Code is * netlabs.org: Christian Langanke . * Portions created by the Initial Developer are Copyright (C) 1999-2008 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ SIGNAL ON HALT TitleLine = STRIP(SUBSTR(SourceLine(2), 3)); PARSE VAR TitleLine CmdName'.CMD 'Info Title = CmdName Info env = 'OS2ENVIRONMENT'; TRUE = (1 = 1); FALSE = (0 = 1); Redirection = '> NUL 2>&1'; CrLf = "0d0a"x; '@ECHO OFF' /* OS/2 errorcodes */ ERROR.NO_ERROR = 0; ERROR.INVALID_FUNCTION = 1; ERROR.FILE_NOT_FOUND = 2; ERROR.PATH_NOT_FOUND = 3; ERROR.ACCESS_DENIED = 5; ERROR.NOT_ENOUGH_MEMORY = 8; ERROR.INVALID_FORMAT = 11; ERROR.INVALID_DATA = 13; ERROR.NO_MORE_FILES = 18; ERROR.WRITE_FAULT = 29; ERROR.READ_FAULT = 30; ERROR.GEN_FAILURE = 31; ERROR.INVALID_PARAMETER = 87; GlobalVars = 'Title CmdName env TRUE FALSE Redirection ERROR. CrLf'; /* show help */ ARG Parm . IF (POS('?', Parm) > 0) THEN DO rc = ShowHelp(); EXIT(ERROR.INVALID_PARAMETER); END; /* load RexxUtil */ CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'; CALL SysLoadFuncs; /* Defaults */ rc = ERROR.NO_ERROR; GlobalVars = GlobalVars ''; IniAppName = 'NOSAC'; OutDatedStamps = '19990524140000 19991111220000 20040223133000'; OutDatedFiles = 'cvsreport.cmd cvswps.cmd install.cmd nosac.hlp nosac.inf'; BootDrive = GetInstDrive(); CallDir = GetCallDir(); PromptServer = 'netlabs.org Open Source Archive Server' CRLF; PromptArchiveRoot = 'root directory of the netlabs.org Open Source Archive'CRLF; PromptWorkRoot = 'root directory for working directories on your computer'CRLF; PromptInitCommand = 'Init Command for project windows (optional)'CRLF; PromptUser = 'CVS User Id (specify guest for readonly access)'CRLF; PromptHome = 'CVS home directory'CRLF; PromptPager = 'pager executable'CRLF; DO UNTIL (TRUE) /* cleanup old files */ rcx = RemoveOldFiles( OutDatedStamps , OutDatedFiles); /* put window in front */ CtlExec = STREAM( CallDir'\..\bin\pgmcntrl.exe', 'C', 'QUERY EXISTS'); IF (CtlExec \= '') THEN '' CtlExec '/ACTIVATE'; /* reset to default ? */ ARG Option . IF (POS( Option, '/RESET') = 1) THEN DO 'CLS' SAY; SAY Title SAY; SAY; SAY 'Restored to default values !'; SAY; rcx = SysIni(, IniAppName, 'DELETE:'); 'PAUSE'; END; /* get init vars */ CvsExe = ReadIniValue(, IniAppName, 'CVS_EXE'); CvsServer = ReadIniValue(, IniAppName, 'CVS_SERVER', 'cvs.netlabs.org'); CvsBinRoot = ReadIniValue(, IniAppName, 'CVS_BINROOT'); CvsWorkRoot = ReadIniValue(, IniAppName, 'CVS_WORKROOT'); CvsInitCommand = ReadIniValue(, IniAppName, 'CVS_INITCOMMAND'); CvsUser = ReadIniValue(, IniAppName, 'CVS_USER', VALUE('USER',,env)); CvsHome = ReadIniValue(, IniAppName, 'CVS_HOME', VALUE('HOME',,env)); CvsPager = ReadIniValue(, IniAppName, 'CVS_PAGER', 'more'); /* set some defaults */ IF (CvsWorkRoot = '') THEN CvsWorkRoot = 'c:\work'; IF (Cvshome = '') THEN CvsHome = 'c:\home'; DO WHILE (TRUE) 'CLS'; SAY; SAY Title SAY; SAY 'Please enter/modify the following values:'; SAY '- press Enter if the default value in brackets applies'; SAY '- press Ctrl-Break and Enter to abort'; SAY '- specify a drive to only modify the drive of the value'; SAY '- path values must be specified with a drive letter'; CvsServer = STRIP(PullVariable( CvsServer, PromptServer)); CvsServer = SPACE( CvsServer, 0); CvsWorkRoot = STRIP( PullPathVariable( CvsWorkRoot, PromptWorkRoot)); rcx = CreateCvsDir( CvsWorkRoot); CvsHome = STRIP( PullPathVariable( CvsHome, PromptHome)); rcx = CreateCvsDir( CvsHome); IF (\FileExist( CvsHome)) THEN 'COPY' CallDir'\samples\.cvsrc' CvsHome'\' Redirection; CvsInitCommand = STRIP(PullVariable( CvsInitCommand, PromptInitCommand)); CvsUser = STRIP(PullVariable( CvsUser, PromptUser)); CvsPager = STRIP(PullVariable( CvsPager, PromptPager)); /* check for CVS.EXE */ CvsExe = SysSearchPath('PATH', 'CVS.EXE'); fCvsInPath = (CvsExe \= ''); IF (fCvsInPath) THEN DO /* determine directory of CVS exe */ CvsBinRoot = LEFT( CvsExe, LASTPOS( '\', CvsExe) - 1); END; ELSE DO CvsBinRoot = STRIP(PullVariable( CvsBinRoot, 'Directory of CVS installation'CRLF)); CvsExe = CvsBinRoot'\bin\cvs.exe'; END; IF (ProceedWith('Are these values correct')) THEN DO MissingVar = ''; SELECT WHEN (CvsServer = '') THEN MissingVar = PromptServer; WHEN (CvsWorkRoot = '') THEN MissingVar = PromptWorkRoot; WHEN (CvsUser = '') THEN MissingVar = PromptUser WHEN (CvsHome = '') THEN MissingVar = PromptHome; OTHERWISE NOP; END; IF (MissingVar \= '') THEN DO SAY CmdName': Error: The value for the'; SAY ' "'MissingVar'"'; SAY 'may not be empty.'; 'PAUSE' ITERATE; END; /* check Cvs bin */ IF (\fCvsInPath) THEN IF (\FileExist( CvsBinRoot'\BIN\CVS.EXE')) THEN DO SAY CmdName': Error: CVS.EXE not found in' CvsBinRoot'\bin'; 'PAUSE' ITERATE; END; /* all values ok */ LEAVE; END; END; /* write new values */ rcx = SysIni(, IniAppName, 'CVS_SERVER', CvsServer); rcx = SysIni(, IniAppName, 'CVS_WORKROOT', CvsWorkRoot); rcx = SysIni(, IniAppName, 'CVS_INITCOMMAND', CvsInitCommand); rcx = SysIni(, IniAppName, 'CVS_USER', CvsUser); rcx = SysIni(, IniAppName, 'CVS_HOME', CvsHome); IF (STRIP(CvsPager) = '') THEN CvsPager = 'more'; rcx = SysIni(, IniAppName, 'CVS_PAGER', CvsPager); rcx = SysIni(, IniAppName, 'CVS_BINROOT', CvsBinRoot); rcx = SysIni(, IniAppName, 'CVS_EXE', CvsExe); /* install folder now ? */ IF (\SysSetObjectData( '', ';')) THEN 'CALL' CallDir'\cvswps'; END; EXIT( rc); /* ------------------------------------------------------------------------- */ HALT: SAY; SAY 'Interrupted by user.'; EXIT(ERROR.GEN_FAILURE); /* ------------------------------------------------------------------------- */ ShowHelp: PROCEDURE EXPOSE (GlobalVars) SAY; SAY Title; SAY; PARSE SOURCE . . ThisFile DO i = 1 TO 3 rc = LINEIN(ThisFile); END; ThisLine = LINEIN(Thisfile); DO WHILE (ThisLine \= ' */') SAY SUBSTR(ThisLine, 7); ThisLine = LINEIN(Thisfile); END; rc = LINEOUT(Thisfile); RETURN(''); /* ------------------------------------------------------------------------- */ FileExist: PROCEDURE PARSE ARG FileName RETURN(STREAM(Filename, 'C', 'QUERY EXISTS') > ''); /* ========================================================================= */ ReadIniValue: PROCEDURE PARSE ARG IniFile, IniAppname, IniKeyName, Default IniValue = SysIni(IniFile, IniAppname, IniKeyName); IF (IniValue = 'ERROR:') THEN IniValue = ''; IF ((IniValue \= '') & (RIGHT(IniValue, 1) = "00"x)) THEN IniValue = LEFT( IniValue, LENGTH( IniValue) - 1); IF (IniValue = '') THEN IniValue = Default; RETURN( IniValue); /* ------------------------------------------------------------------------- */ PullVariable: PROCEDURE PARSE ARG Default, Message SAY; CALL CHAROUT, Message '['Default'] : '; PARSE PULL PullVar; IF (LENGTH(PullVar) > 0) THEN RETURN(PullVar); ELSE RETURN(Default); /* ========================================================================= */ PullPathVariable: PROCEDURE PARSE ARG Default, Message DO WHILE (1) Result = PullVariable( Default, Message); IF (POS( ':', Result) = 0) THEN DO SAY 'error: no drive specified!'; ITERATE; END; /* if only drive given, append default path to it */ PARSE VAR Result ThisDrive':'ThisPath; IF (ThisPath = '') THEN DO PARSE VAR Default .':'DefaultPath; Result = ThisDrive':'DefaultPath; END; IF (POS( ':\', Result) = 0) THEN DO SAY 'error: no fully qualified path specified!'; ITERATE; END; /* everything fine here */ LEAVE; END; RETURN( Result); /* ------------------------------------------------------------------------- */ ProceedWith: PROCEDURE PARSE ARG Prompt ResponseKeys = 'Y N A R I'; /* SysGetMessage(0); */ Yes = WORD(ResponseKeys, 1); No = WORD(ResponseKeys, 2); ch = ' '; ValidResponse = Yes||No; SAY; CALL CHAROUT ,Prompt '('Yes'/'No') ' DO WHILE (POS(ch, ValidResponse) = 0) ch = SysGetKey('NOECHO'); ch = TRANSLATE(ch); IF (POS(ch, ValidResponse) = 0) THEN BEEP(800, 200); END; SAY; SAY; RETURN(ch = Yes); /* ------------------------------------------------------------------------- */ GetInstDrive: PROCEDURE EXPOSE env ARG DirName, EnvVarName /* Default: OS2-Verzeichnis -> ermittelt BootDrive */ IF (DirName = '') THEN DirName = '\OS2'; /* Default: PATH */ IF (EnvVarName = '') THEN EnvVarName = 'PATH'; /* Wert holen */ PathValue = VALUE(EnvVarName,,env); /* Eintrag suchen und Laufwerk zurckgeben */ DirName = ':'DirName';'; EntryPos = POS(DirName, PathValue) - 1; IF (EntryPos = -1) THEN RETURN(''); InstDrive = SUBSTR(PathValue, EntryPos, 2); RETURN(InstDrive); /* ------------------------------------------------------------------------- */ DirExist: PROCEDURE PARSE ARG Dirname IF (Dirname = '') THEN RETURN(0); /* use 'QUERY EXISTS' with root directories (???) */ IF (RIGHT(DirName, 2) = ':\') THEN RETURN(STREAM(Dirname, 'C', 'QUERY EXISTS') \= ''); /* query other directories this way */ IF ((STREAM(Dirname, 'C', 'QUERY EXISTS') = '') &, (STREAM(Dirname, 'C', 'QUERY DATETIME') \= '')) THEN RETURN(1); ELSE RETURN(0); /* ------------------------------------------------------------------------- */ GetCalldir: PROCEDURE PARSE SOURCE . . CallName CallDir = FILESPEC('Drive', CallName)||FILESPEC('Path', CallName); RETURN(LEFT(CallDir, LENGTH(CallDir) - 1)); /* ========================================================================= */ MakePath: PROCEDURE EXPOSE (GlobalVars) PARSE ARG PathName PARSE SOURCE . . CallName FileName = SUBSTR( CallName, LASTPOS( '\', CallName) + 1); 'XCOPY' CallName PathName'\' Redirection; rcx = SysFileDelete( PathName'\'FileName); RETURN( rc); /* ========================================================================= */ CreateCvsDir: PROCEDURE EXPOSE (GlobalVars) PARSE ARG Dirname; Dirname =STRIP( Dirname); IF (Dirname = '') THEN RETURN(''); IF (\DirExist( DirName)) THEN DO IF (ProceedWith( 'The directory' Dirname' does not yes exist.'CrLf'Should it be created now')) THEN rcx = MakePath( DirName); END; RETURN(DirName); /* ========================================================================= */ RemoveOldFiles: PROCEDURE EXPOSE (GlobalVars) PARSE ARG StampList, FileList; rc = ERROR.NO_ERROR; CallDir = GetCallDir(); BaseDir = LEFT( CallDir, LASTPOS( '\', CallDir) - 1); DO 1 /* read files from directory tree */ rc = SysFileTree( BaseDir'\*', 'File.', 'FOS'); IF (rc \= 0) THEN DO SAY 'error in SysFileTree, reboot req.'; LEAVE: END; /* seach and delete outdated files */ DO f = 1 TO File.0 FileStamp = FileStamp( File.f); IF (WORDPOS( FileStamp, StampList) > 0) THEN rcx = SysFileDelete( File.f); END; /* search files matching by name */ DO WHILE (FileList \= '') PARSE VAR FileList ThisFile FileList; CheckFile = BaseDir'\'ThisFile; IF (FileExist( CheckFile)) THEN rcx = SysFileDelete( CheckFile); END; /* remove empty directories */ rc = SysFileTree( BaseDir'\*', 'Dir.', 'DOS'); DO d = Dir.0 TO 1 BY -1 rcx = SysRmDir( Dir.d); END; END; RETURN( 0); /* ========================================================================= */ FileStamp: PROCEDURE PARSE ARG File; RETURN( TRANSLATE( 'abcdefghijklmn',, STREAM( File, 'C', 'QUERY TIMESTAMP'),, 'abcd-ef-gh ij:kl:mn'));