/* Samba Server for eComStation (OS/2) tools (c) 2007-2016 Herwig Bauernfeind for bww bitwise works GmbH. Script: B4SMB.CMD, requires REXX. Purpose: This script is executed before the Samba daemons are actually started. You may put arbitrary tasks in here. There are several task templates implemented using status flags - set to 1 to enable the feature, or any other value to disable the feature Syntax: No parameters. */ setupCMD = SysBootDrive()'\MPTN\BIN\Setup.CMD' ArchLogs = 1 /* Move previous logfiles to archive (by Yuri Dario) */ DelLogs = 0 /* Remove previous logfiles only */ KeepGens = 10 /* Keep last 10 generations of log files, 0 = all */ SaveCfg = 1 /* Save a snapshot of the current Samba configuration */ DelTDBs = 1 /* Remove transient .tdb files */ DHCPWait = 1 /* wait until an address was obtained by the DHCP server */ /* Setup places */ ETC = value("ETC",,"OS2ENVIRONMENT") UNIXETC = value("UNIXROOT",,"OS2ENVIRONMENT")'\etc' SMB_LOGS = value("SMB_LOGS",,"OS2ENVIRONMENT") SMB_LOCK = value("SMB_LOCK",,"OS2ENVIRONMENT") '@echo off' do while lines(SetupCMD) > 0 /* Check interfaces for fixed IP address */ SL = translate(linein(SetupCMD)) if word(SL,1) = "IFCONFIG" & word(SL,2) <> "LO" then do IF = word(SL,2) IP = word(SL,3) address cmd '@ifconfig 'IF' | rxqueue' if queued() > 1 then do parse pull . parse pull ipline ipc rest if ipc = IP then do DHCPWait = 0 say IF': Fixed IP 'IP', valid.' end end else say IF': Fixed IP 'IP', invalid.' end if word(SL,1) = "DHCPSTRT" then do say "DHCP for "word(SL,3)' not recommended for Samba, waiting...' DHCPWait = 1 end end ok = stream(SetupCMD,'c','close') do while queued() > 0 parse pull . end if ArchLogs = 1 then do /* Creative logfile archive */ ok = SysMkDir(SMB_LOGS'\Archive') Archive = SMB_LOGS||'\Archive\logarc-'||date('S')'-'right('0'||time('M'),4) address cmd' zip -jmo9 'Archive' 'SMB_LOGS'\log.?mbd* 'SMB_LOGS'\log.winb*' if KeepGens > 0 then do /* Eventually purge old logfile archives */ ok = SysFileTree(SMB_LOGS||'\Archive\logarc*.zip',logarchs.,"FO") if logarchs.0 > KeepGens then do do I = 1 to (logarchs.0-KeepGens) address cmd' del "'logarchs.I end end end end if DelLogs = 1 then do /* Remove previous logfiles only */ say 'Removing previous logfiles' address cmd' del 'SMB_LOGS'\log.?mbd* 2>NUL' address cmd' del 'SMB_LOGS'\log.winb* 2>NUL' end if SaveCfg = 1 then do /* Take config snapshot */ ok = SysMkDir(ETC'\SmbBackup') Backup = ETC'\SmbBackup\smbcfg-'date('S')'-'right('0'||time('M'),4) address cmd' zip -rpo9 'Backup' 'ETC'\samba\* 'UNIXETC'\*pwd* 'UNIXETC'\*passw* -x 'ETC'\samba\*.zip 'ETC'\samba\log\log* >SmbBackup' if KeepGens > 0 then do /* Eventually purge old snapshots */ ok = SysFileTree(ETC'\SmbBackup\smbcfg-*',snapshots.,"FO") if snapshots.0 > KeepGens then do do I = 1 to (snapshots.0-KeepGens) address cmd' del "'snapshots.I end end end end if DelTDBs = 1 then do /* remove transient .tdb files */ /* Documentation: http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/tdb.html */ ok = SysFileDelete(SMB_LOCK||'\brlock.tdb') ok = SysFileDelete(SMB_LOCK||'\browse.dat') ok = SysFileDelete(SMB_LOCK||'\connections.tdb') ok = SysFileDelete(SMB_LOCK||'\gencache.tdb') ok = SysFileDelete(SMB_LOCK||'\locking.tdb') ok = SysFileDelete(SMB_LOCK||'\login_cache.tdb') ok = SysFileDelete(SMB_LOCK||'\messages.tdb') ok = SysFileDelete(SMB_LOCK||'\sessionid.tdb') ok = SysFileDelete(SMB_LOCK||'\unexpected.tdb') ok = SysFileDelete(SMB_LOCK||'\winbindd_cache.tdb') ok = SysFileDelete(SMB_LOCK||'\wins.dat') /* Do not remove wins.tdb unless it is damaged */ /* ok = SysFileDelete(SMB_LOCK||'\wins.tdb') */ end if DHCPWait then do /* Make sure we got network interfaces up and running */ address cmd' dhcpstrt' end say 'b4smb done.'