Debian Codegraph @

builds/install/posix-common/posixLibrary.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 all contributors signed below.
19 #
20 # All Rights Reserved.
21 # Contributor(s): ______________________________________.
22 # Alex Peshkoff
23 #
24
25 fb_install_prefix=@prefix@
26 default_prefix=@prefix@
27 fb_startup_name=firebird
28
29 #------------------------------------------------------------------------
30 # Build startup name from install path
31
32 startupName() {
33 # sanity check
34 if [ -z "${fb_install_prefix}" ]
35 then
36 echo "Empty install path - can not proceed"
37 exit 1
38 fi
39
40 if [ "${fb_install_prefix}" = "${default_prefix}" ]
41 then
42 fb_startup_name=firebird
43 else
44 # strip first '/' if present
45 fb_startup_name=`echo ${fb_install_prefix} | colrm 2`
46 if [ ${fb_startup_name} = / ]
47 then
48 fb_startup_name=`echo ${fb_install_prefix} | colrm 1 1`
49 if [ -z "$fb_startup_name" ]
50 then
51 # root specified - hmmm...
52 fb_startup_name=root
53 fi
54 else
55 echo "Parameter (${fb_install_prefix}) for -path option should start with /"
56 exit 1
57 fi
58
59 # build final name
60 fb_startup_name=firebird.`echo $fb_startup_name | tr / _`
61 fi
62 }
63
64 startupName ## build it for what's present in current file
65
66
67 #------------------------------------------------------------------------
68 # Adds parameter to $PATH if it's missing in it
69
70 Add2Path() {
71 Dir=${1}
72 x=`echo :${PATH}: | grep :$Dir:`
73 if [ -z "$x" ]
74 then
75 PATH=$PATH:$Dir
76 export PATH
77 fi
78 }
79
80 #------------------------------------------------------------------------
81 # Global stuff init
82
83 Answer=""
84 OrigPasswd=""
85 TmpFile=""
86 MANIFEST_TXT=""
87 Manifest=manifest.txt
88 SecurityDatabase=security4.fdb
89 DefaultLibrary=libfbclient
90 UninstallScript=FirebirdUninstall.sh
91 XINETD=/etc/xinetd.d/
92 ArchiveDateTag=`date +"%Y%m%d_%H%M"`
93 export ArchiveDateTag
94 ArchiveMainFile="@FB_CONFDIR@_${ArchiveDateTag}"
95 export ArchiveMainFile
96 #this solves a problem with sudo env missing sbin
97 Add2Path /usr/sbin
98 Add2Path /sbin
99
100 #------------------------------------------------------------------------
101 # Create temporary file. In case mktemp failed, do something...
102
103 MakeTemp() {
104 TmpFile=`mktemp $mktOptions /tmp/firebird_install.XXXXXX`
105 if [ $? -ne 0 ]
106 then
107 for n in `seq 1000`
108 do
109 TmpFile=/tmp/firebird_install.$n
110 if [ ! -e $TmpFile ]
111 then
112 touch $TmpFile
113 return
114 fi
115 done
116 fi
117 }
118
119 #------------------------------------------------------------------------
120 # Prompt for response, store result in Answer
121
122 AskQuestion() {
123 Test=$1
124 DefaultAns=$2
125 printf %s "$Test"
126 Answer="$DefaultAns"
127 read Answer
128
129 if [ -z "$Answer" ]
130 then
131 Answer="$DefaultAns"
132 fi
133 }
134
135
136 #------------------------------------------------------------------------
137 # Prompt for yes or no answer - returns non-zero for no
138
139 AskYNQuestion() {
140 while true
141 do
142 printf %s "${*} (y/n): "
143 read answer rest
144 case $answer in
145 [yY]*)
146 return 0
147 ;;
148 [nN]*)
149 return 1
150 ;;
151 *)
152 echo "Please answer y or n"
153 ;;
154 esac
155 done
156 }
157
158
159 #------------------------------------------------------------------------
160 # Run $1. If exit status is not zero, show output to user.
161
162 runSilent() {
163 MakeTemp
164 rm -f $TmpFile
165 $1 >>$TmpFile 2>>$TmpFile
166 if [ $? -ne 0 ]
167 then
168 cat $TmpFile
169 echo ""
170 rm -f $TmpFile
171 return 1
172 fi
173 rm -f $TmpFile
174 return 0
175 }
176
177
178 #------------------------------------------------------------------------
179 # Check for a user, running install, to be root
180
181 checkRootUser() {
182
183 if [ "`whoami`" != "root" ];
184 then
185 echo ""
186 echo "--- Stop ----------------------------------------------"
187 echo ""
188 echo " You need to be 'root' user to do this change"
189 echo ""
190 exit 1
191 fi
192 }
193
194 #alias
195 checkInstallUser() {
196 checkRootUser
197 }
198
199
200 #------------------------------------------------------------------------
201 # Report missing library error and exit
202
203 missingLibrary() {
204 libName=${1}
205 echo "Please install required library '$libName' before firebird, after it repeat firebird install"
206 exit 1
207 }
208
209
210 #------------------------------------------------------------------------
211 # Check library presence, errorexit when missing
212
213 checkLibrary() {
214 libList=${1}
215 for libName in $libList
216 do
217 haveLibrary $libName || missingLibrary $libName
218 done
219 }
220
221
222 #------------------------------------------------------------------------
223 # Make sure we have required libraries installed
224 checkLibraries() {
225 if [ "@TOMMATH_BUILD@" != "Y" -o "${fb_install_prefix}" != "${default_prefix}" ]
226 then
227 fixTommath=
228 checkLibrary tommath
229 haveLibrary libtommath.so.0 || [ "$fixTommath" ] && $fixTommath
230 fi
231
232 # if [ "@TOMCRYPT_BUILD@" != "Y" -o "${fb_install_prefix}" != "${default_prefix}" ]
233 if [ "@TOMCRYPT_BUILD@" != "Y" ]
234 then
235 [ -z "$LIBTOMCRYPT" ] && LIBTOMCRYPT=tomcrypt
236 checkLibrary $LIBTOMCRYPT
237 fi
238
239 checkLibrary icudata
240
241 [ "$LIBCURSES" ] && checkLibrary $LIBCURSES
242 }
243
244
245 #------------------------------------------------------------------------
246 # grep process by name
247
248 grepProcess() {
249 processList=$1
250 eol=\$
251 ps $psOptions | egrep "\<($processList)($eol|[[:space:]])" | grep -v grep | grep -v -w '\-path'
252 }
253
254
255 #------------------------------------------------------------------------
256 # check if it is running
257
258 checkIfServerRunning() {
259
260 if [ "$1" != "install-embedded" ]
261 then
262 stopSuperServerIfRunning
263 fi
264
265
266 # Check is server is being actively used.
267
268 checkString=`grepProcess "firebird"`
269 if [ ! -z "$checkString" ]
270 then
271 echo "An instance of the Firebird server seems to be running."
272 echo "Please quit all Firebird applications and then proceed."
273 exit 1
274 fi
275
276 checkString=`grepProcess "fb_smp_server"`
277 if [ ! -z "$checkString" ]
278 then
279 echo "An instance of the Firebird SuperClassic server seems to be running."
280 echo "Please quit all Firebird applications and then proceed."
281 exit 1
282 fi
283
284 checkString=`grepProcess "fbserver|fbguard"`
285 if [ ! -z "$checkString" ]
286 then
287 echo "An instance of the Firebird Super server seems to be running."
288 echo "Please quit all Firebird applications and then proceed."
289 exit 1
290 fi
291
292 checkString=`grepProcess "fb_inet_server|gds_pipe"`
293 if [ ! -z "$checkString" ]
294 then
295 echo "An instance of the Firebird Classic server seems to be running."
296 echo "Please quit all Firebird applications and then proceed."
297 exit 1
298 fi
299
300
301 # The following check for running interbase or firebird 1.0 servers.
302
303 checkString=`grepProcess "ibserver|ibguard"`
304 if [ ! -z "$checkString" ]
305 then
306 echo "An instance of the Firebird/InterBase Super server seems to be running."
307 echo "(the ibserver or ibguard process was detected running on your system)"
308 echo "Please quit all Firebird applications and then proceed."
309 exit 1
310 fi
311
312 checkString=`grepProcess "gds_inet_server|gds_pipe"`
313 if [ ! -z "$checkString" ]
314 then
315 echo "An instance of the Firebird/InterBase Classic server seems to be running."
316 echo "(the gds_inet_server or gds_pipe process was detected running on your system)"
317 echo "Please quit all Firebird applications and then proceed."
318 exit 1
319 fi
320 }
321
322
323 #------------------------------------------------------------------------
324 # ask user to enter CORRECT original DBA password
325
326 askForOrigDBAPassword() {
327 OrigPasswd=""
328 while [ -z "$OrigPasswd" ]
329 do
330 AskQuestion "Please enter current password for SYSDBA user: "
331 OrigPasswd=$Answer
332 if ! runSilent "@FB_BINDIR@/gsec -user sysdba -password $OrigPasswd -di"
333 then
334 OrigPasswd=""
335 fi
336 done
337 }
338
339
340 #------------------------------------------------------------------------
341 # Ask user to enter new DBA password string
342 # !! This routine is interactive !!
343
344 getNewDBAPasswordFromUser()
345 {
346 AskQuestion "Please enter new password for SYSDBA user: "
347 NewPasswd=$Answer
348 }
349
350
351 #------------------------------------------------------------------------
352 # add a line in the (usually) /etc/services or /etc/inetd.conf file
353 # Here there are three cases, not found => add
354 # found & different => replace
355 # found & same => do nothing
356 #
357
358 replaceLineInFile() {
359 FileName="$1"
360 newLine="$2"
361 oldLine=`grep "$3" $FileName`
362
363 if [ -z "$oldLine" ]
364 then
365 echo "$newLine" >> "$FileName"
366 elif [ "$oldLine" != "$newLine" ]
367 then
368 MakeTemp
369 grep -v "$oldLine" "$FileName" > "$TmpFile"
370 echo "$newLine" >> $TmpFile
371 cp $TmpFile $FileName && rm -f $TmpFile
372 echo "Updated $1"
373 fi
374 }
375
376
377 #------------------------------------------------------------------------
378 # "edit" file $1 - replace line starting from $2 with $3
379
380 editFile() {
381 FileName=$1
382 Starting=$2
383 NewLine=$3
384
385 AwkProgram="(/^$Starting.*/ || \$1 == \"$Starting\") {\$0=\"$NewLine\"} {print \$0}"
386 MakeTemp
387 awk "$AwkProgram" <$FileName >$TmpFile && mv $TmpFile $FileName || rm -f $TmpFile
388 }
389
390
391 #------------------------------------------------------------------------
392 # remove line from config file if it exists in it.
393
394 removeLineFromFile() {
395 FileName=$1
396 oldLine=$2
397
398 if [ ! -z "$oldLine" ]
399 then
400 cat $FileName | grep -v "$oldLine" > ${FileName}.tmp
401 cp ${FileName}.tmp $FileName && rm -f ${FileName}.tmp
402 fi
403 }
404
405
406 #------------------------------------------------------------------------
407 # Write new password to the @FB_CONFDIR@/SYSDBA.password file
408
409 writeNewPassword() {
410 NewPasswd=$1
411 DBAPasswordFile=@FB_CONFDIR@/SYSDBA.password
412 FB_HOST=`hostname`
413 FB_TIME=`date`
414
415 cat <<EOT >$DBAPasswordFile
416 #
417 # Firebird generated password for user SYSDBA is:
418 #
419 ISC_USER=sysdba
420 ISC_PASSWORD=$NewPasswd
421 #
422 # Also set legacy variable though it can't be exported directly
423 #
424 ISC_PASSWD=$NewPasswd
425 #
426 # generated on $FB_HOST at time $FB_TIME
427 #
428 # Your password can be changed to a more suitable one using
429 # SQL operator ALTER USER.
430 #
431 EOT
432
433 chmod u=r,go= $DBAPasswordFile
434 }
435
436
437 #------------------------------------------------------------------------
438 # Set sysdba password.
439
440 setDBAPassword() {
441 writePassword=
442
443 if [ -z "$InteractiveInstall" ]
444 then
445 passwd=`createNewPassword`
446 writePassword=yes
447 else
448 NewPasswd=""
449 getNewDBAPasswordFromUser
450 passwd=$NewPasswd
451
452 if [ -z "$passwd" ]
453 then
454 echo " "
455 echo "Press enter once more if you need random password"
456 echo "or enter non-empty password."
457 echo " "
458 getNewDBAPasswordFromUser
459 passwd=$NewPasswd
460
461 if [ -z "$passwd" ]
462 then
463 passwd=`createNewPassword`
464 writePassword=yes
465 fi
466 fi
467 fi
468
469 if [ -z "$passwd" ]
470 then
471 passwd=masterkey
472 fi
473
474 runSilent "@FB_BINDIR@/gsec -add sysdba -pw $passwd"
475
476 if [ "$writePassword" ]
477 then
478 writeNewPassword $passwd
479 fi
480 }
481
482
483 #------------------------------------------------------------------------
484 # buildUninstallFile
485 # This will work only for the .tar.gz install and it builds an
486 # uninstall shell script.
487
488 buildUninstallFile() {
489 cd "$origDir"
490
491 if [ ! -f $Manifest ] # Only exists if we are a .tar.gz install
492 then
493 return
494 fi
495
496 MANIFEST_TXT=@FB_MISCDIR@/$Manifest
497 if [ "${fb_install_prefix}" = "${default_prefix}" ]
498 then
499 cp $Manifest $MANIFEST_TXT
500 else
501 newManifest $Manifest $MANIFEST_TXT
502 fi
503
504 [ -f @FB_SBINDIR@/$UninstallScript ] && chmod u=rx,go= @FB_SBINDIR@/$UninstallScript
505 }
506
507
508 #------------------------------------------------------------------------
509 # newManifest
510 # Create new manifest replacing default_prefix with fb_install_prefix
511 # in existing manifest
512
513 newManifest() {
514 ExistingManifestFile=${1}
515 CreateManifestFile=${2}
516
517 rm -f $CreateManifestFile
518 oldPath=".${default_prefix}"
519
520 for line in `grep "^${oldPath}" $ExistingManifestFile | colrm 1 ${#oldPath}`
521 do
522 echo ".${fb_install_prefix}${line}" >>$CreateManifestFile
523 done
524
525 newPath=`dirname "${fb_install_prefix}"`
526 while [ ${#newPath} -gt 1 ]
527 do
528 echo ".${newPath}" >>$CreateManifestFile
529 newPath=`dirname $newPath`
530 done
531 }
532
533 #------------------------------------------------------------------------
534 # Remove if only a link
535
536 removeIfOnlyAlink() {
537 Target=$1
538
539 if [ -L $Target ]
540 then
541 rm -f $Target
542 fi
543 }
544
545
546 #------------------------------------------------------------------------
547 # re-link new file only if target is a link or missing
548
549 safeLink() {
550 Source=$1
551 Target=$2
552 Manifest=$3
553
554 if [ $Source != $Target -a "${fb_install_prefix}" = "${default_prefix}" ]
555 then
556 removeIfOnlyAlink $Target
557 if [ ! -e $Target ]
558 then
559 ln -s $Source $Target
560 if [ -f "$Manifest" ]
561 then
562 echo $Target >>$Manifest
563 fi
564 fi
565 fi
566 }
567
568
569 #------------------------------------------------------------------------
570 # createLinksForBackCompatibility
571 # Create links for back compatibility to InterBase and Firebird1.0
572 # linked systems.
573
574 createLinksForBackCompatibility() {
575
576 # These two links are required for compatibility with existing ib programs
577 # If the program had been linked with libgds.so then this link is required
578 # to ensure it loads the fb equivalent. MOD 7-Nov-2002.
579
580 newLibrary=@FB_LIBDIR@/$DefaultLibrary.@SHRLIB_EXT@
581 LibDir=`CorrectLibDir @libdir@`
582 safeLink $newLibrary $LibDir/libgds.@SHRLIB_EXT@
583 safeLink $newLibrary $LibDir/libgds.@[email protected]
584 }
585
586
587 #------------------------------------------------------------------------
588 # createLinksInSystemLib
589 # Create links to firebird client library in system directory.
590
591 createLinksInSystemLib() {
592 LibDir=`CorrectLibDir @libdir@`
593 libtom='libtom*.@SHRLIB_EXT@*'
594 tomdir=@FB_LIBDIR@/.tm
595 origDirLinksInSystemLib=`pwd`
596
597 cd @FB_LIBDIR@
598 Libraries=`echo libfbclient.@SHRLIB_EXT@* libib_util.@SHRLIB_EXT@`
599
600 cd /
601 for l in $Libraries
602 do
603 safeLink @FB_LIBDIR@/$l .$LibDir/$l ${MANIFEST_TXT}
604 done
605
606 if [ -d $tomdir ]; then
607 cd $tomdir
608 Libraries=`echo ${libtom}`
609
610 cd /
611 for l in $Libraries
612 do
613 [ -f .$LibDir/$l ] || safeLink @FB_LIBDIR@/.tm/$l .$LibDir/$l ${MANIFEST_TXT}
614 done
615 fi
616
617 cd $origDirLinksInSystemLib
618
619 reconfigDynamicLoader
620 }
621
622 #------------------------------------------------------------------------
623 # removeLinksForBackCompatibility
624 # Remove links for back compatibility to InterBase and Firebird1.0
625 # linked systems.
626
627 removeLinksForBackCompatibility() {
628 LibDir=`CorrectLibDir @libdir@`
629
630 removeIfOnlyAlink $LibDir/libgds.@SHRLIB_EXT@
631 removeIfOnlyAlink $LibDir/libgds.@[email protected]
632 }
633
634
635 #------------------------------------------------------------------------
636 # Run process and check status
637
638 runAndCheckExit() {
639 Cmd=$*
640
641 $Cmd
642 ExitCode=$?
643
644 if [ $ExitCode -ne 0 ]
645 then
646 echo "Install aborted: The command $Cmd "
647 echo " failed with error code $ExitCode"
648 exit $ExitCode
649 fi
650 }
651
652
653 #------------------------------------------------------------------------
654 # Display message if this is being run interactively.
655
656 displayMessage() {
657 msgText=$1
658
659 if [ ! -z "$InteractiveInstall" ]
660 then
661 echo $msgText
662 fi
663 }
664
665
666 #------------------------------------------------------------------------
667 # Archive any existing prior installed files.
668 # The 'cd' stuff is to avoid the "leading '/' removed message from tar.
669 # for the same reason the DestFile is specified without the leading "/"
670
671 archivePriorInstallSystemFiles() {
672 if [ -z ${ArchiveMainFile} ]
673 then
674 echo "Variable ArchiveMainFile not set - exiting"
675 exit 1
676 fi
677
678 tarArc=${ArchiveMainFile}.$tarExt
679 oldPWD=`pwd`
680 distManifest=${oldPWD}/manifest.txt
681 archiveFileList=""
682 archiveDelTemp=""
683
684 if [ "${fb_install_prefix}" != "${default_prefix}" ]
685 then
686 TmpFile=""
687 MakeTemp
688 newManifest $distManifest $TmpFile
689 distManifest=$TmpFile
690 archiveDelTemp=$TmpFile
691 fi
692
693
694 cd /
695
696 if [ -f ${distManifest} ]; then
697 manifest=`cat ${distManifest}`
698 for i in $manifest; do
699 if [ -f $i ]; then
700 i=${i#/} # strip off leading /
701 archiveFileList="$archiveFileList $i"
702 fi
703 done
704 fi
705
706 rm -f "$archiveDelTemp"
707
708 DestFile=@FB_CONFDIR@
709 if [ -e "$DestFile" ]
710 then
711 echo ""
712 echo ""
713 echo ""
714 echo "--- Warning ----------------------------------------------"
715 echo " The installation target directory $DestFile already exists."
716 echo " This and other related files found will be"
717 echo " archived in the file : ${tarArc}"
718 echo ""
719
720 if [ ! -z "$InteractiveInstall" ]
721 then
722 AskQuestion "Press return to continue or ^C to abort"
723 fi
724
725 if [ -e $DestFile ]
726 then
727 archiveFileList="$archiveFileList $DestFile"
728 fi
729 fi
730
731 if [ "${fb_install_prefix}" = "${default_prefix}" ]
732 then
733 for i in ibase.h ib_util.h
734 do
735 DestFile=usr/include/$i
736 if [ -e $DestFile ]; then
737 if [ ! "`echo $archiveFileList | grep $DestFile`" ]; then
738 archiveFileList="$archiveFileList $DestFile"
739 fi
740 fi
741 done
742
743 for i in libib_util.@SHRLIB_EXT@ libfbclient.@SHRLIB_EXT@*
744 do
745 for DestFile in usr/lib/$i
746 do
747 if [ -e $DestFile ]; then
748 if [ ! "`echo $archiveFileList | grep $DestFile`" ]; then
749 archiveFileList="$archiveFileList $DestFile"
750 fi
751 fi
752 done
753 done
754
755 for i in usr/sbin/rcfirebird etc/init.d/firebird etc/rc.d/init.d/firebird
756 do
757 DestFile=./$i
758 if [ -e $DestFile ]; then
759 if [ ! "`echo $archiveFileList | grep $DestFile`" ]; then
760 archiveFileList="$archiveFileList $DestFile"
761 fi
762 fi
763 done
764 fi
765
766 if [ ! -z "$archiveFileList" ]
767 then
768 displayMessage "Archiving..."
769 runAndCheckExit "tar -cv${tarOptions}f $tarArc $archiveFileList"
770 displayMessage "Done."
771
772 displayMessage "Deleting..."
773 for i in $archiveFileList
774 do
775 rm -rf $i
776 done
777 displayMessage "Done."
778 fi
779
780 cd $oldPWD
781 }
782
783
784 #------------------------------------------------------------------------
785 # removeInstalledFiles
786 #
787 removeInstalledFiles() {
788
789 origDir=`pwd`
790 cd /
791
792 for manifestFile in @FB_MISCDIR@/manifest*.txt
793 do
794 if [ -f "$manifestFile" ]
795 then
796 for i in `cat $manifestFile`
797 do
798 if [ -f $i -o -L $i ]
799 then
800 rm -f $i
801 #echo $i
802 fi
803 done
804 fi
805 done
806
807 cd "$origDir"
808 }
809
810
811 #------------------------------------------------------------------------
812 # removeUninstallFiles
813 # Under the install directory remove all the empty directories
814 # If some files remain then
815
816 removeUninstallFiles() {
817 # remove the uninstall files
818 rm -f @FB_MISCDIR@/manifest*.txt
819 rm -f @FB_SBINDIR@/$UninstallScript
820 }
821
822
823 #------------------------------------------------------------------------
824 # removeEmptyDirs
825 # Under the install directory remove all the empty directories
826 # This routine loops, since deleting a directory possibly makes
827 # the parent empty as well
828
829 removeEmptyDirs() {
830
831 dirContentChanged='yes'
832 while [ "$dirContentChanged" ]; do
833 dirContentChanged=''
834
835 for rootDir in @FB_BINDIR@ @FB_SBINDIR@ @FB_LIBDIR@ @FB_INCDIR@ @FB_DOCDIR@ @FB_SAMPLEDIR@ @FB_SAMPLEDBDIR@ \
836 @FB_HELPDIR@ @FB_INTLDIR@ @FB_MISCDIR@ @FB_SECDBDIR@ @FB_MSGDIR@ @FB_LOGDIR@ @FB_GUARDDIR@ @FB_PLUGDIR@ \
837 @FB_TZDATADIR@ @FB_CONFDIR@; do
838
839 if [ -d $rootDir ]; then
840 for i in `find $rootDir -type d -print`; do
841 rmdir $i >/dev/null 2>/dev/null && dirContentChanged=$i
842 done
843 fi
844
845 done
846 done
847 }
848
849
850 #------------------------------------------------------------------------
851 # For security reasons most files in firebird installation are
852 # root-owned and world-readable(executable) only (including firebird).
853
854 # For some files RunUser and RunGroup (firebird)
855 # must have write access - lock and log for example.
856
857 MakeFileFirebirdWritable() {
858 FileName=$1
859 chown $RunUser:$RunGroup $FileName
860
861 if [ "$RunUser" = "root" ]
862 # In that case we must open databases, locks, etc. to the world...
863 # That's a pity, but required if root RunUser choosen.
864 then
865 chmod a=rw $FileName
866 else
867 # This is good secure setting
868 chmod ug=rw,o= $FileName
869 fi
870 }
871
872
873 #------------------------------------------------------------------------
874 # fixFilePermissions
875 # Change the permissions to restrict access to server programs to
876 # firebird group only. This is MUCH better from a safety point of
877 # view than installing as root user, even if it requires a little
878 # more work.
879
880 fixFilePermissions() {
881 # First of all set owneship of all files to root
882 # Build list of interesting directories all over the FS
883 dirs="@FB_BINDIR@ @FB_SBINDIR@ @FB_CONFDIR@ @FB_LIBDIR@ @FB_INCDIR@/firebird @FB_DOCDIR@/sql.extensions \
884 @FB_SAMPLEDIR@ @FB_SAMPLEDBDIR@ @FB_HELPDIR@ @FB_INTLDIR@ @FB_MISCDIR@ @FB_SECDBDIR@ @FB_MSGDIR@ @FB_LOGDIR@ \
885 @FB_GUARDDIR@ @FB_PLUGDIR@ @FB_TZDATADIR@"
886 dirs2=`for i in $dirs; do echo $i; done|sort|uniq`
887
888 MakeTemp
889 tmp1=$TmpFile
890 MakeTemp
891 tmp2=$TmpFile
892 MakeTemp
893 tmp3=$TmpFile
894 MakeTemp
895 tmp4=$TmpFile
896
897 # Extract list of our files in that directories from manifest
898 manifest=@FB_MISCDIR@/manifest.txt
899 for i in $dirs2
900 do
901 grep $i manifest.txt >$tmp1
902 echo $i > $tmp3
903 for j in $dirs2
904 do
905 if [ $i != $j ]
906 then
907 if ! grep -q $j $tmp3
908 then
909 grep -v $j $tmp1 >$tmp2
910 rm -f $tmp1
911 mv $tmp2 $tmp1
912 fi
913 fi
914 done
915 cat $tmp1 >> $tmp4
916 done
917
918 # Change ownership
919 rundir=`pwd`
920 cd /
921 for f in `cat $tmp4`
922 do
923 chown root:root $f
924 done
925 cd $rundir
926
927 rm -f $tmp1 $tmp2 $tmp3 $tmp4
928
929 # Lock files
930 cd @FB_GUARDDIR@
931 for FileName in fb_guard
932 do
933 touch $FileName
934 MakeFileFirebirdWritable $FileName
935 done
936
937 # Log file
938 cd @FB_LOGDIR@
939 touch firebird.log
940 MakeFileFirebirdWritable firebird.log
941 touch replication.log
942 MakeFileFirebirdWritable replication.log
943
944 # Security database
945 cd @FB_SECDBDIR@
946 MakeFileFirebirdWritable $SecurityDatabase
947
948 # make examples DB(s) writable
949 for i in `find @FB_SAMPLEDBDIR@ -name '*.fdb' -print`
950 do
951 MakeFileFirebirdWritable $i
952 done
953
954 # Fix QLI help
955 cd @FB_HELPDIR@
956 chmod a=r help.fdb
957 }
958
959
960 fbUsage() {
961 pf=""
962 if [ "@CHANGE_PATH_SUPPORT@" = "yes" ]
963 then
964 pf=', -path <install path>'
965 fi
966
967 echo "$1 option: $2. Known option(s): -silent${pf}."
968 exit 1
969 }
970
971
972 #------------------------------------------------------------------------
973 # parseArgs
974 # Parse passed arguments.
975 # Set appropriate global flags.
976
977 parseArgs() {
978 flSilent=0
979
980 while [ -n "$1" ]; do
981 case "$1" in
982 -silent)
983 flSilent=1
984 ;;
985 -path)
986 if [ "@CHANGE_PATH_SUPPORT@" = "yes" ]
987 then
988 { fb_install_prefix="$2"; }
989 if [ -z "${fb_install_prefix}" ]
990 then
991 fbUsage "Missing argument for" "$1"
992 fi
993 shift
994 startupName
995 else
996 fbUsage "Not supported" "$1"
997 fi
998 ;;
999 *)
1000 fbUsage Invalid "$1"
1001 ;;
1002 esac
1003 shift
1004 done
1005
1006 if [ $flSilent -eq 0 ]; then
1007 InteractiveInstall=1
1008 export InteractiveInstall
1009 fi
1010 }
1011
1012
1013 #---------------------------------------------------------------------------
1014 # set new prefix for fb installation
1015
1016 setNewPrefix() {
1017 binlist="@FB_BINDIR@/changeServerMode.sh @FB_BINDIR@/fb_config @FB_BINDIR@/registerDatabase.sh @FB_BINDIR@/FirebirdUninstall.sh"
1018 filelist="$binlist @FB_MISCDIR@/firebird.init.d.*"
1019 for file in $filelist
1020 do
1021 editFile $file fb_install_prefix "fb_install_prefix=${fb_install_prefix}"
1022 done
1023 for file in $binlist
1024 do
1025 chmod 0700 $file
1026 done
1027 }
1028
1029
1030 #---------------------------------------------------------------------------
1031 # extract installation archive
1032
1033 extractBuildroot() {
1034 displayMessage "Extracting install data"
1035
1036 if [ "${fb_install_prefix}" = "${default_prefix}" ]
1037 then
1038 # Extract archive in root directory
1039 cd /
1040 tar -xzof "$origDir/buildroot.tar.gz"
1041 else
1042 mkdir -p ${fb_install_prefix}
1043 cd ${fb_install_prefix}
1044 defDir=".${default_prefix}"
1045 if [ -d $defDir ]
1046 then
1047 echo "${default_prefix} should not exist in ${fb_install_prefix}"
1048 fi
1049
1050 tar -xzof "$origDir/buildroot.tar.gz" ${defDir}
1051 for p in ${defDir}/*
1052 do
1053 mv $p .
1054 done
1055
1056 while [ ${#defDir} -gt 2 ]
1057 do
1058 rm -rf ${defDir}
1059 defDir=`dirname $defDir`
1060 done
1061 fi
1062
1063 cd "$origDir"
1064 }
1065
1066
1067 #---------------------------------------------------------------------------
1068 # starts firebird server
1069
1070 startFirebird() {
1071 if [ "${fb_install_prefix}" = "${default_prefix}" ]
1072 then
1073 startService
1074 fi
1075 }