source: trunk/guitools/shared/cltinit.vrs@ 1022

Last change on this file since 1022 was 1017, checked in by Alex Taylor, 8 years ago

Update logic for locating Samba Client Tools binaries to support ArcaOS (and be slightly smarter in some other cases).

File size: 11.1 KB
Line 
1/* Perform basic Samba Client init stuff */
2
3/*:VRX */
4_CltInit:
5 IF options.!debug == 1 THEN say time()' _CltInit() started'
6 IF options.!debug == 1 THEN say ' Checking Samba Client setup...'
7
8 /* debuglevel when executing Samba binaries */
9 debuglevel = ' --debuglevel=0'
10
11 /* Error status and file variables */
12 ErrorState = 0 /* _ErrorBinaryNotFound() changes this variable */
13 DataErrorState = 0 /* _ErrorDataFileNotFound() changes this variable */
14
15 /* Evaluate environment */
16 ETC = value('ETC',,'OS2ENVIRONMENT')
17 IF options.!debug == 1 THEN say ' ETC = "'ETC'"'
18
19 UnixRoot = value("UNIXROOT",,'OS2ENVIRONMENT')
20 if UnixRoot = "" then do
21 UnixRoot = left(ETC,length(ETC)-4)
22 say ' WARNING! Setting missing UNIXROOT variable to "'UnixRoot'".'
23 ok = value("UNIXROOT",UnixRoot,'OS2ENVIRONMENT')
24 end
25
26 IF options.!debug == 1 THEN say ' UnixRoot = "'UnixRoot'"'
27
28 unixetc = UnixRoot'\etc'
29 IF options.!debug == 1 THEN say ' Unixetc = "'unixetc'"'
30
31 /* Find all executables */
32
33 /* Get the path to this file */
34 samba.!tools = VRParseFilename(VRGet("Application", "Program"),'DP')
35 if samba.!tools = '' then do
36 parse source . . script
37 samba.!tools = VRParseFilename(script,'DP')
38 end
39 IF options.!debug == 1 THEN say ' Samba tools = "'samba.!tools'"'
40 say ' Changing into tools "'directory(samba.!tools)'"'
41
42 /* smbclient.exe */
43 samba.!smbclientexe = ""
44 if samba.!smbclientexe = "" then do /* wellknown locations */
45 Osdir = value("OSDIR",,'OS2ENVIRONMENT')
46 if Osdir <> '' THEN
47 WellKnown = Osdir"\apps\smbclnt;"Osdir"\system\samba;"sysBootdrive()"\samba"
48 else
49 WellKnown = sysBootdrive()"\ecs\system\samba;"sysBootdrive()"\samba"
50 Programs = value("PROGRAMS",,'OS2ENVIRONMENT')
51 if Programs <> "" then WellKnown = Wellknown';'Programs'\samba'
52 Tools = value("TOOLS",,'OS2ENVIRONMENT')
53 if Programs <> "" then WellKnown = Wellknown';'Tools'\samba'
54 say Wellknown
55 call charout , " Are binaries in wellknown locations? "
56 ok = VRFindFile("smbclient.exe",WellKnown)
57 if ok <> "" then say "Yes."; else say "No."
58 if ok <> "" then samba.!smbclientexe = ok
59 drop Wellknown
60 end
61 if samba.!smbclientexe = "" then do /* in current directory? */
62 call charout , " Are binaries in current directory? "
63 ok = SysFileTree('.\smbclient.exe', exist.,'FO')
64 if exist.0 = 1 then say "Yes."; else say "No."
65 if exist.0 = 1 then samba.!smbclientexe = exist.1
66 end
67 if samba.!smbclientexe = "" then do /* RPM/YUM/FHS tree */
68 call charout , " Are binaries in RPM/YUM/FHS tree? "
69 ok = SysFileTree(UnixRoot'\usr\bin\smbclient.exe', exist.,'FO')
70 if exist.0 = 1 then say "Yes."; else say "No."
71 if exist.0 = 1 then samba.!smbclientexe = exist.1
72 end
73 if samba.!smbclientexe = "" then do /* in parent directory? */
74 call charout , " Are binaries in parent directory? "
75 ok = SysFileTree('..\smbclient.exe', exist.,'FO')
76 if exist.0 = 1 then say "Yes."; else say "No."
77 if exist.0 = 1 then samba.!smbclientexe = exist.1
78 end
79 if samba.!smbclientexe = "" then do /* in ..\BIN directory? */
80 call charout , " Are binaries in ..\BIN directory? "
81 ok = SysFileTree('..\bin\smbclient.exe', exist.,'FO')
82 if exist.0 = 1 then say "Yes."; else say "No."
83 if exist.0 = 1 then samba.!smbclientexe = exist.1
84 end
85 if samba.!smbclientexe = "" then do /* in SMB_EXE ? */
86 call charout , " Are binaries in SMB_EXE path? "
87 samba.!smbclientexe = SysSearchPath("SMB_EXE","smbclient.EXE")
88 if samba.!smbclientexe = "" then say "No."; else say "Yes."
89 end
90 if samba.!smbclientexe = "" then do /* in PATH ? */
91 call charout , " Are binaries in PATH? "
92 samba.!smbclientexe = SysSearchPath("PATH","smbclient.EXE")
93 if samba.!smbclientexe = "" then say "No."; else say "Yes."
94 end
95
96 if samba.!smbclientexe = "" then call _ErrorBinaryNotFound " could not find smbclient.exe!"
97
98 samba.!bin = VRParseFileName(samba.!smbclientexe,'DP')
99 IF options.!debug == 1 THEN say ' Samba binaries = "'samba.!bin'"'
100
101 /* net.exe */
102 samba.!netexe = samba.!bin'\net.exe'
103 if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound " could not find net.exe!"
104 IF options.!debug == 1 THEN say ' net.exe = "'samba.!netexe'"'
105
106 /* testparm.exe */
107 samba.!testparmexe = samba.!bin'\testparm.exe'
108 if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound " could not find testparm.exe!"
109 IF options.!debug == 1 THEN say ' testparm.exe = "'samba.!testparmexe'"'
110
111 /* smbtree.exe */
112 samba.!smbtreeexe = samba.!bin'\smbtree.exe'
113 if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound " could not find smbtree.exe!"
114 IF options.!debug == 1 THEN say ' smbtree.exe = "'samba.!smbtreeexe'"'
115
116 /* nmblookup.exe */
117 samba.!nmblookupexe = samba.!bin'\nmblookup.exe'
118 if \VRFileExists(samba.!nmblookupexe) then call _ErrorBinaryNotFound " could not find nmblookup.exe!"
119 IF options.!debug == 1 THEN say ' nmblookup.exe = "'samba.!nmblookupexe'"'
120
121 /* smbspool.exe */
122 samba.!smbspoolexe = samba.!bin'\smbspool.exe'
123 if \VRFileExists(samba.!smbspoolexe) then call _ErrorBinaryNotFound " could not find smbspool.exe!"
124 IF options.!debug == 1 THEN say ' smbspool.exe = "'samba.!smbspoolexe'"'
125
126 /* rpcclient.exe */
127 samba.!rpcclientexe = samba.!bin'\rpcclient.exe'
128 if \VRFileExists(samba.!rpcclientexe) then call _ErrorBinaryNotFound " could not find rpcclient.exe!"
129 IF options.!debug == 1 THEN say ' rpcclient.exe = "'samba.!rpcclientexe'"'
130
131 /* smb.conf */
132 samba.!smbconf = ETC'\samba\smb.conf'
133 if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.'
134 IF options.!debug == 1 THEN say ' Samba smb.conf = "'samba.!smbconf'"'
135
136 /* complete shadow copy of smb.conf in temporary directory - should always be created on the fly */
137 /* before reading from it */
138 samba.!shadowsmbconf = TempDir||'smb.conf'
139
140 /* lmhosts */
141 samba.!lmhosts = ETC'\samba\lmhosts'
142 if \VRFileExists(samba.!lmhosts) then call _ErrorDataFileNotFound samba.!lmhosts' is not present.'
143 IF options.!debug == 1 THEN say ' Samba lmhosts = "'samba.!lmhosts'"'
144
145 /* FIXME: Needs to be changed for Samba 3.3+ */
146 /* upcase table files - several utilities need these */
147 if (\VRFileExists(samba.!bin'\lib\upcase.dat')) |,
148 (\VRFileExists(samba.!bin'\lib\lowcase.dat')) |,
149 (\VRFileExists(samba.!bin'\lib\valid.dat')) then call _ErrorDataFileNotFound 'upcase table files not present.'
150
151 /* the password files - we'll create them if they don't exist */
152 samba.!masterpasswd = unixetc'\master.passwd'
153 if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound 'Could not find "'samba.!masterpasswd'"!'
154 IF options.!debug == 1 then say ' master.passwd = "'samba.!masterpasswd'"'
155
156 samba.!pwddb = unixetc'\pwd.db'
157 if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!pwddb'"!'
158 IF options.!debug == 1 then say ' pwd.db = "'samba.!pwddb'"'
159
160 samba.!spwddb = unixetc'\spwd.db'
161 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!spwddb'"!'
162 IF options.!debug == 1 then say ' spwd.db = "'samba.!spwddb'"'
163
164 samba.!group = unixetc'\group'
165 if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound 'Could not find "'samba.!group'"!'
166 IF options.!debug == 1 then say ' group = "'samba.!group'"'
167
168 samba.!printcap = unixetc'\printcap'
169 if \VRFileExists(samba.!printcap) then call _ErrorDataFileNotFound 'Could not find "'samba.!printcap'"!'
170 IF options.!debug == 1 then say ' printcap = "'samba.!printcap'"'
171
172 /* Create these directories to make sure they do exist */
173 ok = SysMkDir(unixetc)
174 ok = SysMkDir(etc'\samba')
175 ok = SysMkDir(etc'\samba\pid')
176 ok = SysMkDir(etc'\samba\lock')
177 /* This EA makes the testparm warning about browsing go away. */
178 /* Note: The EA is NOT marked critical as it should be, neverthelesse this fix works */
179 ok = SysPutEA(etc||'\samba\lock',"MODE", "FEFF0400ED410000"x)
180
181 /* Messages from Samba will go here */
182 samba.!error = SysTempFileName(TempDir'smb_err.???')
183 IF options.!debug == 1 THEN say ' samba.!error = "'samba.!error'"'
184 samba.!msg = SysTempFileName(TempDir'smb_msg.???')
185 IF options.!debug == 1 THEN say ' samba.!msg = "'samba.!msg'"'
186 /* Use of this file is deprecated */
187 ErrorFile = Tempdir'smbutil.error'
188
189 IF options.!debug == 1 then do
190 if ErrorState then say " One or more basic Samba Client setup errors detected!"
191 else say " No basic Samba Client setup errors detected!"
192 end
193 IF options.!debug == 1 THEN say time()' _CltInit() done, Errorstate = 'Errorstate
194return
195
196/*:VRX */
197_SambaFinish:
198 /* Do some basic housekeeping when leaving */
199 ok = SysFileTree(TempDir'smb_???.???', garbage., 'FO')
200 do I = 1 to garbage.0
201 ok = stream(garbage.I,'c','close')
202 ok = SysFileDelete(garbage.I)
203 end
204return
205
206/*:VRX */
207_ErrorBinaryNotFound:
208 /* Set error status variable and show a short message - incomplete! */
209 msg = arg(1)
210 say "ERROR: "msg
211 id = VRMessage( VRWindow(), msg, "Samba Client Installation", "E" )
212 ErrorState = (1|ErrorState)
213return
214
215/*:VRX */
216_ErrorDataFileNotFound:
217 /* Set error status variable and show a short message - incomplete! */
218 msg = arg(1)
219 say "ERROR: "msg
220 DataErrorState = (1|DataErrorState)
221return
222
223/*:VRX */
224_SambaExtendSearchPath:
225 IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() started'
226 /* Add binary and tools path to the PATH variable */
227 old_path = value('PATH',, 'OS2ENVIRONMENT')
228 if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
229 if samba.!bin = samba.!tools then new_path = samba.!bin';'
230 else new_path = samba.!bin';'samba.!tools';'
231 ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
232 drop new_path
233 end
234 drop old_path
235
236 /* Add binary and tools path to the BEGINLIBPATH variable */
237 old_beginlibpath = SysQueryExtLibPath("B")
238 if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
239 if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
240 else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
241 ok = SysSetExtLibPath( new_beginlibpath, "B")
242 drop new_beginlibpath
243 end
244 drop old_beginlibpath
245
246 /* Set LIBPATHSTRICT (this is an option - disabled by default) */
247 /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */
248
249 IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() done'
250return
Note: See TracBrowser for help on using the repository browser.