Debian Codegraph @

builds/install/arch-specific/freebsd/install.sh.in

raw
1 #!/bin/sh
2 #
3 # The contents of this file are subject to the Initial
4 # Developer's Public License Version 1.0 (the "License");
5 # you may not use this file except in compliance with the
6 # License. You may obtain a copy of the License at
7 # http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
8 #
9 # Software distributed under the License is distributed AS IS,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied.
11 # See the License for the specific language governing rights
12 # and limitations under the License.
13 #
14 # The Original Code was created by Mark O'Donohue
15 # for the Firebird Open Source RDBMS project.
16 #
17 # Copyright (c) Mark O'Donohue <[email protected]>
18 # and Chris Knight <[email protected]>
19 # and all contributors signed below.
20 #
21 # All Rights Reserved.
22 # Contributor(s): ______________________________________.
23 # Alex Peshkoff
24 #
25
26 fb_install_prefix=@prefix@
27
28 # Script to copy install files from the build/transport area
29
30
31 # This script builds an image of the installed system into
32 # the gen/buildroot directory.
33
34 if [ "`whoami`" != "root" ]; then
35 echo 'You must be root to install'
36 exit 1
37 fi
38
39 # Making an assumption that this program is being run in the gen directory
40 BuildRootDir=..
41 BuiltFBDir=./firebird # Where the just build fb exists.
42 TargetDir= # Install in real FS
43 SecurityDatabase=security2.fdb
44 RunUser=firebird
45 RunGroup=firebird
46
47
48 #------------------------------------------------------------------------
49 # addLibs
50 # Add required libraries in the beginning of script.
51 # Place it to target directory.
52
53 addLibs() {
54 libSdir=$1
55 libScript=$2
56 libTdir=$3
57 libTarget=$libTdir/$libScript
58
59 rm -f $libTarget
60 touch $libTarget
61 for i in posixLibrary.sh freebsdLibrary.sh
62 do
63 echo "# $i" >>$libTarget
64 cat $libSdir/$i >>$libTarget
65 echo "" >>$libTarget # avoid missing linefeed
66 done
67 cat $libSdir/$libScript >>$libTarget
68 }
69
70
71 #------------------------------------------------------------------------
72 # copyIfExists
73 # Copy file if it exists
74 #
75
76 copyIfExists() {
77 Files=""
78 while [ ${#} -gt 1 ]; do
79 Files="$Files ${1}"
80 shift
81 done
82 NewDir=${1}
83
84 for OldFile in $Files; do
85 if [ -f $OldFile ]; then
86 cp -Rf $OldFile $NewDir
87 fi
88 done
89 }
90
91
92 #------------------------------------------------------------------------
93 # linkFiles
94 # This function creates soft links
95
96 linkFiles() {
97 From=$1
98 Files=$2
99 To=$3
100 Check=$4
101
102 if [ "$To" = "$Check" ]; then
103 return 0
104 fi
105
106 for file in $Files; do
107 rm -f $To/$file
108 ln -s $From/$file $To/$file
109 done
110 }
111
112
113 #------------------------------------------------------------------------
114 # makeDirs
115 # Make paths, passed as a list in 1st arg
116
117 makeDirs() {
118 Dirs=$1
119 for d in $Dirs; do
120 Dir=${TargetDir}${d}
121 if [ ! -d $Dir ]; then
122 rm -f $Dir
123 mkdir -p $Dir
124 chown root:wheel $Dir
125 chmod 0755 $Dir
126 fi
127 done
128 }
129
130
131 #------------------------------------------------------------------------
132 # copyFiles
133 # This function copies all the files into the installation directory(ies).
134
135 copyFiles() {
136 # The guts of the tranfer of files and other directories
137
138 #directories
139 makeDirs "@FB_BINDIR@ @FB_SBINDIR@ @FB_CONFDIR@ @FB_LIBDIR@ @FB_INCDIR@ @FB_DOCDIR@/sql.extensions @FB_SAMPLEDIR@ \
140 @FB_SAMPLEDBDIR@ @FB_HELPDIR@ @FB_INTLDIR@ @FB_MISCDIR@ @FB_SECDBDIR@ @FB_MSGDIR@ @FB_LOGDIR@ \
141 @FB_GUARDDIR@ @FB_PLUGDIR@ @FB_TZDATADIR@"
142
143 for i in metadata security; do
144 makeDirs @FB_MISCDIR@/upgrade/$i
145 done
146
147 makeDirs @libdir@
148 makeDirs /usr/include
149
150 #bin
151 cp $BuiltFBDir/bin/gbak ${TargetDir}@FB_BINDIR@/gbak
152 cp $BuiltFBDir/bin/gdef ${TargetDir}@FB_BINDIR@/gdef
153 cp $BuiltFBDir/bin/gfix ${TargetDir}@FB_BINDIR@/gfix
154 cp $BuiltFBDir/bin/gpre ${TargetDir}@FB_BINDIR@/gpre
155 cp $BuiltFBDir/bin/gsec ${TargetDir}@FB_BINDIR@/gsec
156 cp $BuiltFBDir/bin/nbackup ${TargetDir}@FB_BINDIR@/nbackup
157 copyIfExists $BuiltFBDir/bin/gsplit ${TargetDir}@FB_BINDIR@
158 cp $BuiltFBDir/bin/gstat ${TargetDir}@FB_BINDIR@/gstat
159 copyIfExists $BuiltFBDir/bin/fbsvcmgr ${TargetDir}@FB_BINDIR@
160 copyIfExists $BuiltFBDir/bin/fbtracemgr ${TargetDir}@FB_BINDIR@
161 cp $BuiltFBDir/bin/isql ${TargetDir}@FB_BINDIR@/isql
162 cp $BuiltFBDir/bin/qli ${TargetDir}@FB_BINDIR@/qli
163
164 chown root:wheel ${TargetDir}@FB_BINDIR@/*
165 chmod 0755 ${TargetDir}@FB_BINDIR@/*
166
167 #sbin
168 copyIfExists $BuiltFBDir/bin/fb_smp_server ${TargetDir}@FB_SBINDIR@
169 copyIfExists $BuiltFBDir/bin/fbserver ${TargetDir}@FB_SBINDIR@
170 cp -f $BuiltFBDir/bin/fbguard ${TargetDir}@FB_SBINDIR@
171 copyIfExists $BuiltFBDir/bin/fb_lock_print ${TargetDir}@FB_SBINDIR@
172 copyIfExists $BuiltFBDir/bin/fbmgr.bin ${TargetDir}@FB_SBINDIR@
173
174 addLibs $BuildRootDir/gen/firebird/bin changeRunUser.sh ${TargetDir}@FB_SBINDIR@
175 addLibs $BuildRootDir/gen/firebird/bin restoreRootRunUser.sh ${TargetDir}@FB_SBINDIR@
176 addLibs $BuildRootDir/gen/firebird/bin changeDBAPassword.sh ${TargetDir}@FB_SBINDIR@
177 addLibs $BuildRootDir/gen/firebird/bin changeServerMode.sh ${TargetDir}@FB_SBINDIR@
178 addLibs $BuiltFBDir/bin changeGdsLibraryCompatibleLink.sh ${TargetDir}@FB_SBINDIR@
179 cp $BuiltFBDir/bin/createAliasDB.sh ${TargetDir}@FB_SBINDIR@
180 cp $BuiltFBDir/bin/fb_config ${TargetDir}@FB_SBINDIR@
181
182 chown root:wheel ${TargetDir}@FB_SBINDIR@/*
183 chmod 0755 ${TargetDir}@FB_SBINDIR@/*
184 chmod 0700 ${TargetDir}@FB_SBINDIR@/*.sh
185
186 #install scripts
187 addLibs $BuildRootDir/gen/firebird/bin tarMainInstall.sh $BuildRootDir/gen/install/scripts
188 addLibs $BuildRootDir/gen/firebird/bin tarinstall.sh $BuildRootDir/gen/install/scripts
189 addLibs $BuildRootDir/gen/firebird/bin preinstall.sh $BuildRootDir/gen/install/scripts
190 addLibs $BuildRootDir/gen/firebird/bin postinstall.sh $BuildRootDir/gen/install/scripts
191 addLibs $BuildRootDir/gen/firebird/bin preuninstall.sh $BuildRootDir/gen/install/scripts
192 addLibs $BuildRootDir/gen/firebird/bin postuninstall.sh $BuildRootDir/gen/install/scripts
193 addLibs $BuildRootDir/gen/firebird/bin taruninstall.sh $BuildRootDir/gen/install/scripts
194 addLibs $BuildRootDir/gen/firebird/bin tarMainUninstall.sh $BuildRootDir/gen/install/scripts
195
196 #examples - copy only if we have them
197 exampleFiles=`find $BuiltFBDir/examples/README -type f -print`
198 if [ -z "$exampleFiles" ]; then
199 echo "Example files have not been built!"
200 else
201 (cd $BuiltFBDir/examples; tar cf - .) | (cd ${TargetDir}@FB_SAMPLEDIR@; tar xf -)
202 rm -rf ${TargetDir}@FB_SAMPLEDIR@/empbuild
203
204 for i in `find ${TargetDir}@FB_SAMPLEDIR@ -type d -print`
205 do
206 chown root:wheel $i
207 chmod 0555 $i
208 done
209 for i in `find ${TargetDir}@FB_SAMPLEDIR@ -type f -print`
210 do
211 chown root:wheel $i
212 chmod 0444 $i
213 done
214
215 makeDirs @FB_SAMPLEDBDIR@
216 cp $BuiltFBDir/examples/empbuild/*.fdb ${TargetDir}@FB_SAMPLEDBDIR@
217
218 chown root:wheel ${TargetDir}@FB_SAMPLEDBDIR@/*.fdb
219 chmod 0444 ${TargetDir}@FB_SAMPLEDBDIR@/*.fdb
220 fi
221
222 #QLI help
223 copyIfExists $BuiltFBDir/help/help.gbak ${TargetDir}@FB_HELPDIR@
224 cp $BuiltFBDir/help/help.fdb ${TargetDir}@FB_HELPDIR@
225
226 chown root:wheel ${TargetDir}@FB_HELPDIR@/*.fdb
227 chmod 0444 ${TargetDir}@FB_HELPDIR@/*.fdb
228
229 #message file
230 cp $BuiltFBDir/*.msg ${TargetDir}@FB_MSGDIR@
231
232 chown root:wheel ${TargetDir}@FB_MSGDIR@/*.msg
233 chmod 0444 ${TargetDir}@FB_MSGDIR@/*.msg
234
235 #secureDB (access rights will be set at install time)
236 cp $BuiltFBDir/$SecurityDatabase ${TargetDir}@FB_SECDBDIR@
237
238 #.h files
239 cp $BuiltFBDir/include/*.h ${TargetDir}@FB_INCDIR@
240
241 chown root:wheel ${TargetDir}@FB_INCDIR@/*.h
242 chmod 0444 ${TargetDir}@FB_INCDIR@/*.h
243
244 #lib
245 copyIfExists $BuiltFBDir/lib/libfbembed.so* ${TargetDir}@FB_LIBDIR@
246 cp -f $BuiltFBDir/lib/libfbclient.so* ${TargetDir}@FB_LIBDIR@
247 cp -f $BuiltFBDir/lib/libib_util.so ${TargetDir}@FB_LIBDIR@/libib_util.so
248 copyIfExists $BuiltFBDir/lib/libicu*.so* ${TargetDir}@FB_LIBDIR@
249
250 chown root:wheel ${TargetDir}@FB_LIBDIR@/*.so*
251 chmod 0755 ${TargetDir}@FB_LIBDIR@/*.so*
252
253 #plugins
254 cp -f $BuiltFBDir/plugins/* ${TargetDir}@FB_PLUGDIR@
255
256 chown root:wheel ${TargetDir}@FB_PLUGDIR@/*.so*
257 chmod 0755 ${TargetDir}@FB_PLUGDIR@/*.so*
258
259 makeDirs ${TargetDir}@FB_TZDATADIR@
260 cp $BuiltFBDir/tzdata/*.res ${TargetDir}@FB_TZDATADIR@
261 chmod 0444 ${TargetDir}@FB_TZDATADIR@/*.res
262
263 #intl
264 cp $BuiltFBDir/intl/libfbintl.so ${TargetDir}@FB_INTLDIR@/fbintl
265 cp $BuiltFBDir/intl/fbintl.conf ${TargetDir}@FB_INTLDIR@
266
267 chown root:wheel ${TargetDir}@FB_INTLDIR@/fbintl*
268 chmod 0755 ${TargetDir}@FB_INTLDIR@/fbintl
269 chmod 0644 ${TargetDir}@FB_INTLDIR@/fbintl.conf
270
271 # Note that the following items copy files from outside the build tree.
272
273 #doc
274 cp $BuildRootDir/doc/README.* ${TargetDir}@FB_DOCDIR@
275 cp $BuildRootDir/doc/sql.extensions/README* ${TargetDir}@FB_DOCDIR@/sql.extensions
276 cp $BuildRootDir/*.md ${TargetDir}@FB_CONFDIR@
277
278 chown -R root:wheel ${TargetDir}@FB_MISCDIR@
279 for i in `find ${TargetDir}@FB_MISCDIR@ -print`; do
280 chown root:wheel $i
281 if [ -d $i ]; then
282 chmod 0755 $i
283 else
284 chmod 0644 $i
285 fi
286 done
287
288 #misc
289 cp $BuildRootDir/src/misc/intl.sql ${TargetDir}@FB_MISCDIR@
290 cp $BuildRootDir/src/misc/upgrade/v3.0/security_database* ${TargetDir}@FB_MISCDIR@/upgrade/security
291
292 chown -R root:wheel ${TargetDir}@FB_MISCDIR@
293 chmod -R go-rwx ${TargetDir}@FB_MISCDIR@
294
295 #conf
296 cp $BuiltFBDir/firebird.conf ${TargetDir}@FB_CONFDIR@
297 cp $BuiltFBDir/databases.conf ${TargetDir}@FB_CONFDIR@
298 cp $BuiltFBDir/fbtrace.conf ${TargetDir}@FB_CONFDIR@
299 cp $BuiltFBDir/plugins.conf ${TargetDir}@FB_CONFDIR@
300 cp $BuiltFBDir/replication.conf ${TargetDir}@FB_CONFDIR@
301
302 chown root:wheel ${TargetDir}@FB_CONFDIR@/*.conf
303 chmod 0644 ${TargetDir}@FB_CONFDIR@/*.conf
304
305 # Create links from @libdir@ to install area.
306 origDir=`pwd`
307 cd $BuiltFBDir/lib
308 Libraries=`echo libfb*.so* libib_util.so`
309 cd $origDir
310 linkFiles "@FB_LIBDIR@" "$Libraries" "${TargetDir}@libdir@" "${TargetDir}@FB_LIBDIR@"
311
312 # link include files to /usr/include
313 linkFiles "@FB_INCDIR@" "iberror.h ibase.h ib_util.h" "${TargetDir}/usr/include" "${TargetDir}@FB_INCDIR@"
314
315 }
316
317
318 #------------------------------------------------------------------------
319 # For security reasons most files in firebird installation are
320 # root-owned and world-readable(executable) only (including firebird).
321
322 # For some files RunUser and RunGroup (firebird)
323 # must have write access - lock and log for example.
324
325 MakeFileFirebirdWritable() {
326 FileName=$1
327 chown $RunUser:$RunGroup $FileName
328
329 if [ "$RunUser" = "root" ]
330 # In that case we must open databases, locks, etc. to the world...
331 # That's a pity, but required if root RunUser choosen.
332 then
333 chmod a=rw $FileName
334 else
335 # This is good secure setting
336 chmod ug=rw,o= $FileName
337 fi
338 }
339
340
341 #------------------------------------------------------------------------
342 # fixFilePermissions
343 # Change the permissions to restrict access to server programs to
344 # firebird group only. This is MUCH better from a safety point of
345 # view than installing as root user, even if it requires a little
346 # more work.
347
348 fixFilePermissions() {
349 # Lock files
350 cd @FB_GUARDDIR@
351 for FileName in fb_guard
352 do
353 touch $FileName
354 MakeFileFirebirdWritable $FileName
355 done
356
357 # Log file
358 cd @FB_LOGDIR@
359 touch firebird.log
360 MakeFileFirebirdWritable firebird.log
361
362 # Security database
363 cd @FB_SECDBDIR@
364 MakeFileFirebirdWritable $SecurityDatabase
365
366 # make examples DB(s) writable
367 for i in `find @FB_SAMPLEDBDIR@ -name '*.fdb' -print`
368 do
369 MakeFileFirebirdWritable $i
370 done
371
372 cd @FB_HELPDIR@
373 chmod a=r help.fdb
374 }
375
376
377 #=== MAIN ====================================================================
378
379 copyFiles
380
381 # add firebird user
382 nofbuid=0
383 fbUID=`id -u firebird 2>/dev/null`
384 if [ $? -ne 0 ]; then
385 fbUID=90
386 while [ ! -z `id -un $fbUID 2>/dev/null` ]
387 do
388 fbUID=$(($fbUID+1))
389 done
390 nofbuid=1
391 fi
392
393 fbGID=`pw groupshow firebird 2>/dev/null`
394 if [ $? -ne 0 ]; then
395 fbGID=90
396 while [ ! -z `id -gn $fbGID 2>/dev/null` ]
397 do
398 fbGID=$(($fbGID+1))
399 done
400 echo "firebird:*:$fbGID:" >> /etc/group
401 else
402 fbGID=`echo $fbGID | awk -F: '{print $3}'`
403 fi
404
405 echo "firebird user using uid $fbUID"
406 echo "firebird user using gid $fbGID"
407
408 if which -s pw; then
409 if [ $nofbuid -ne 0 ]; then
410 pw useradd firebird -u $fbUID -g $fbGID -h - -s /bin/sh \
411 -d @FB_CONFDIR@ -c "Firebird Database Administrator"
412 fi
413 else
414 echo -n "unable to create user firebird - please create it manually,"
415 echo " before reinstalling this package."
416 exit 1
417 fi
418
419 fixFilePermissions
420
421 # remove any existing gds service
422 cp /etc/services /etc/services.old
423 cp /etc/inetd.conf /etc/inetd.conf.old
424 cat /etc/services |grep -v @FB_SERVICE_NAME@ >/etc/services.new
425 cat /etc/inetd.conf |grep -v @FB_SERVICE_NAME@ >/etc/inetd.conf.new
426 mv /etc/services.new /etc/services
427 mv /etc/inetd.conf.new /etc/inetd.conf
428
429 # reset make env
430 FIREBIRD_LOCK=
431 export FIREBIRD_LOCK
432 FIREBIRD=
433 export FIREBIRD
434
435 # add the gds service and restart inetd
436 cat >>/etc/services <<EOF
437 @FB_SERVICE_NAME@ @FB_SERVICE_PORT@/tcp #Firebird Database Remote Protocol
438 EOF
439 cat >>/etc/inetd.conf <<EOF
440 @FB_SERVICE_NAME@ stream tcp nowait firebird ${TargetDir}@FB_SBINDIR@/fb_smp_server fb_smp_server
441 EOF
442 if [ -f /var/run/inetd.pid ]; then
443 kill -HUP `cat /var/run/inetd.pid`
444 fi
445
446 # shared lib startup script
447 if [ -d /etc/rc.d ]; then
448 (
449 echo "#!/bin/sh"; echo "[ -d @FB_LIBDIR@ ] && /sbin/ldconfig -m @FB_LIBDIR@"
450 ) > /etc/rc.d/000.firebird.sh
451 chmod a=rx /etc/rc.d/000.firebird.sh
452 fi