$! install the library under OpenVMS
$! use code of SAMBA installation procedure
$! written by Jean-Francois Pieronne <jf.pieronne@laposte.net>
$
$ on error then goto exit
$ on control_y then goto exit
$ set on
$ save_ver = f$verify(0)
$ copy := copy
$ status = 1
$
$ old_def = f$env("default")
$ proc = f$environment("PROCEDURE")
$ cur_dev = f$parse(proc,,,"DEVICE","SYNTAX_ONLY")
$ cur_dir = f$parse(proc,,,"DIRECTORY","SYNTAX_ONLY")
$ set default 'cur_dev''cur_dir'
$
$ root = f$trnlnm("LIBZ")
$ if root .eqs. ""
$ then
$     root = cur_dev + cur_dir
$ endif
$
$ ask_root:
$       read/end=exit/error=exit -
        /prompt="Enter directory name for LIBZ [''root']: " -
        sys$output line
$       if line .eqs. "" then line = root
$       root_dev = f$parse(line,root,,"DEVICE","NO_CONCEAL")
$       root_dir = f$parse(line,root,,"DIRECTORY","NO_CONCEAL")
$       root = line
$       if f$parse(root_dev+root_dir) .eqs. ""
$       then
$               read/end=exit/error=exit/prompt= -
"Directory ''root_dev'''root_dir' does not exist. Create it [Y]: " -
                sys$output yn
$               yn = f$edit(yn,"UPCASE,TRIM,COLLAPSE,UNCOMMENT")
$               if yn .eqs. "N"
$               then
$                       write sys$output "Installation aborted."
$                       goto exit
$               endif
$               create/directory 'root_dev''root_dir'
$       endif
$       write sys$output ""
$       call set_dirprot 'root_dev''root_dir' w:re
$       define/system/exec/nolog LIBZ 'root'
$
$!
$! Copy files
$!
$ write sys$output "Copying files..."
$ copy/log *.h libz:
$ copy/log *.olb libz:
$ if f$getsyi("ARCH_TYPE").gt. 1 
$ then
$     copy/log libzshr*.exe libz:
$ endif
$ 
$!
$! Create startup file
$!
$ file := SYS$COMMON:[SYS$STARTUP]LIBZ_STARTUP.COM
$ write sys$output "Creating startup file ''file'..."
$ create 'file'
$ open/append chan 'file'
$ write chan "$ define/system/exec/nolog LIBZ ''root'"
$ if f$getsyi("ARCH_TYPE").gt. 1 
$ then
$     write chan "$ define/system/exec/nolog LIBZ_SHR32 LIBZ:libzshr32-1_1_4.exe"
$     write chan "$ define/system/exec/nolog LIBZ_SHR64 LIBZ:libzshr64-1_1_4.exe"
$ endif
$ close chan
$ 
$ type sys$input

        zlib library for VMS has been installed successfully.

        The file SYS$STARTUP:LIBZ_STARTUP.COM has been provided to
        start zlib library for VMS.

        Include the line "@SYS$STARTUP:LIBZ_STARTUP" in the system
        startup file SYS$MANAGER:SYSTARTUP_VMS.COM


$ 
$ exit:
$!      Let's return to the directory where we started so the user is
$!      not lost.
$!
$       set default 'old_def'
$       if f$trnlnm("chan") .nes. "" then close chan
$       exit status + (0 * 'f$verify(save_ver)')
$
$!
$ set_dirprot:
$!
$! Input:
$!      P1      - directory spec (e.g. [mydir.subdir])
$!      P2      - protection (e.g. w:re)
$ subroutine
$       dev = f$parse(P1,,,"DEVICE","NO_CONCEAL")
$       dir = f$parse(P1,,,"DIRECTORY","NO_CONCEAL") - "]["
$       gosub make_dirfile
$       set file/protection='P2' 'dev''dirfile'
$       set file/acl/acl=(default_prot,s:rwed,o:rwed,g:rw,'P2') 'dev''dirfile'
$       exit
$!
$ make_dirfile:
$!
$! Input:
$!      dir     - directory spec (e.g. [mydir.subdir])
$! Output:
$!      dirfile - directory file spec (e.g. [mydir]subdir.dir)
$!
$       d = f$parse(dir - "]" + ".-]",,,"DIRECTORY")
$       a = d - "[" - "]"
$       b = dir - "[" - "]"
$       c = b - a - "."
$       dirfile = d + c + ".DIR"
$       return
$ endsubroutine
