8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 19:23:03 +01:00
firebird-mirror/builds/install/misc/posixLibrary.sh.in

812 lines
19 KiB
Bash
Raw Normal View History

2005-04-29 20:16:46 +02:00
#!/bin/sh
#
# The contents of this file are subject to the Initial
# Developer's Public License Version 1.0 (the "License");
# you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
# http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
#
# Software distributed under the License is distributed AS IS,
# WITHOUT WARRANTY OF ANY KIND, either express or implied.
# See the License for the specific language governing rights
# and limitations under the License.
#
# The Original Code was created by Mark O'Donohue
# for the Firebird Open Source RDBMS project.
#
# Copyright (c) Mark O'Donohue <mark.odonohue@ludwig.edu.au>
# and all contributors signed below.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# Alex Peshkoff
#
2005-04-29 20:16:46 +02:00
#------------------------------------------------------------------------
# Global stuff init
Answer=""
OrigPasswd=""
TmpFile=""
FBRootDir=@prefix@
2005-08-16 12:04:13 +02:00
export FBRootDir
2005-04-29 20:16:46 +02:00
FBBin=$FBRootDir/bin
2005-08-16 12:04:13 +02:00
export FBBin
2005-04-29 20:16:46 +02:00
SecurityDatabase=security2.fdb
2005-08-16 12:04:13 +02:00
ArchiveDateTag=`date +"%Y%m%d_%H%M"`
export ArchiveDateTag
2008-12-26 15:39:06 +01:00
ArchiveMainFile="${FBRootDir}_${ArchiveDateTag}"
2005-08-16 12:04:13 +02:00
export ArchiveMainFile
2005-04-29 20:16:46 +02:00
#------------------------------------------------------------------------
# Create temporary file. In case mktemp failed, do something...
MakeTemp() {
2008-12-26 15:39:06 +01:00
TmpFile=`mktemp $mktOptions /tmp/firebird_install.XXXXXX`
2005-04-29 20:16:46 +02:00
if [ $? -ne 0 ]
then
TmpFile=/tmp/firebird_install
touch $TmpFile
fi
}
#------------------------------------------------------------------------
# Prompt for response, store result in Answer
AskQuestion() {
Test=$1
DefaultAns=$2
echo -n "${1}"
Answer="$DefaultAns"
read Answer
2005-08-16 12:04:13 +02:00
if [ -z "$Answer" ]
then
Answer="$DefaultAns"
fi
2005-04-29 20:16:46 +02:00
}
#------------------------------------------------------------------------
# Prompt for yes or no answer - returns non-zero for no
AskYNQuestion() {
while echo -n "${*} (y/n): "
do
read answer rest
case $answer in
[yY]*)
return 0
;;
[nN]*)
return 1
;;
*)
echo "Please answer y or n"
;;
esac
done
}
#------------------------------------------------------------------------
# Run $1. If exit status is not zero, show output to user.
runSilent() {
MakeTemp
$1 >$TmpFile 2>&1
if [ $? -ne 0 ]
then
cat $TmpFile
echo ""
rm -f $TmpFile
return 1
fi
rm -f $TmpFile
return 0
}
2006-04-24 12:08:16 +02:00
2005-04-29 20:16:46 +02:00
#------------------------------------------------------------------------
# Check for a user, running install, to be root
checkRootUser() {
if [ "`whoami`" != "root" ];
then
echo ""
2006-04-24 12:08:16 +02:00
echo "--- Stop ----------------------------------------------"
2005-04-29 20:16:46 +02:00
echo ""
echo " You need to be 'root' user to do this change"
echo ""
exit 1
fi
}
#alias
checkInstallUser() {
checkRootUser
}
2006-04-24 12:08:16 +02:00
#------------------------------------------------------------------------
# resetInetdServer
# Works for both inetd and xinetd
resetInetdServer() {
2008-12-26 15:39:06 +01:00
pid=`ps -eaf$psOptions | grep inetd | grep -v grep | awk '{print $2}'`
2006-04-24 12:08:16 +02:00
if [ "$pid" ]
then
kill -HUP $pid
fi
}
#------------------------------------------------------------------------
# remove the xinetd config file(s)
# take into account possible pre-firebird xinetd services
removeXinetdEntry() {
2008-12-26 15:39:06 +01:00
for i in `grep -l "service @FB_SERVICE_NAME@" /etc/xinetd.d/*`
2006-04-24 12:08:16 +02:00
do
rm -f $i
done
}
#------------------------------------------------------------------------
# remove the line from inetd file
removeInetdEntry() {
FileName=/etc/inetd.conf
2008-12-26 15:39:06 +01:00
oldLine=`grep "^@FB_SERVICE_NAME@" $FileName`
2006-04-24 12:08:16 +02:00
removeLineFromFile "$FileName" "$oldLine"
}
#------------------------------------------------------------------------
# Remove (x)inetd service entry and restart the service.
# Check to see if we have xinetd installed or plain inetd.
# Install differs for each of them.
removeInetdServiceEntry() {
if [ -d /etc/xinetd.d ]
then
removeXinetdEntry
elif [ -f /etc/inetd.conf ]
then
removeInetdEntry
fi
# make [x]inetd reload configuration
resetInetdServer
}
2005-04-29 20:16:46 +02:00
#------------------------------------------------------------------------
# check if it is running
checkIfServerRunning() {
2008-12-26 15:39:06 +01:00
checkString=`ps -ef$psOptions | egrep "\b(fbserver|fbguard|fb_smp_server)\b" |grep -v grep`
if [ ! -z "$checkString" ]
then
serverMode=super
fi
2009-02-05 14:22:31 +01:00
# have to be root to stop the server
if [ "$1" != "install-embedded" ]
then
stopSuperServerIfRunning
fi
2005-04-29 20:16:46 +02:00
# Check is server is being actively used.
2008-12-26 15:39:06 +01:00
checkString=`ps -ef$psOptions | egrep "\b(fb_smp_server)\b" |grep -v grep`
if [ ! -z "$checkString" ]
then
echo "An instance of the Firebird SuperClassic server seems to be running."
echo "Please quit all Firebird applications and then proceed."
exit 1
fi
2008-12-26 15:39:06 +01:00
checkString=`ps -ef$psOptions | egrep "\b(fbserver|fbguard)\b" |grep -v grep`
2005-04-29 20:16:46 +02:00
if [ ! -z "$checkString" ]
2005-08-16 12:04:13 +02:00
then
2006-04-24 12:08:16 +02:00
echo "An instance of the Firebird Super server seems to be running."
2006-04-25 04:16:33 +02:00
echo "Please quit all Firebird applications and then proceed."
2005-04-29 20:16:46 +02:00
exit 1
fi
2008-12-26 15:39:06 +01:00
checkString=`ps -ef$psOptions | egrep "\b(fb_inet_server|gds_pipe)\b" |grep -v grep`
2005-04-29 20:16:46 +02:00
if [ ! -z "$checkString" ]
2005-08-16 12:04:13 +02:00
then
2006-04-24 12:08:16 +02:00
echo "An instance of the Firebird Classic server seems to be running."
2006-04-25 04:16:33 +02:00
echo "Please quit all Firebird applications and then proceed."
2005-04-29 20:16:46 +02:00
exit 1
fi
2005-08-16 12:04:13 +02:00
# The following check for running interbase or firebird 1.0 servers.
2008-12-26 15:39:06 +01:00
checkString=`ps -ef$psOptions | egrep "\b(ibserver|ibguard)\b" |grep -v grep`
2005-08-16 12:04:13 +02:00
if [ ! -z "$checkString" ]
then
echo "An instance of the Firebird/InterBase Super server seems to be running."
echo "(the ibserver or ibguard process was detected running on your system)"
2006-04-25 04:16:33 +02:00
echo "Please quit all Firebird applications and then proceed."
2005-08-16 12:04:13 +02:00
exit 1
fi
2008-12-26 15:39:06 +01:00
checkString=`ps -ef$psOptions | egrep "\b(gds_inet_server|gds_pipe)\b" |grep -v grep`
2005-08-16 12:04:13 +02:00
if [ ! -z "$checkString" ]
then
2006-04-24 12:08:16 +02:00
echo "An instance of the Firebird/InterBase Classic server seems to be running."
2005-08-16 12:04:13 +02:00
echo "(the gds_inet_server or gds_pipe process was detected running on your system)"
echo "Please quit all Firebird applications and then proceed."
exit 1
fi
2009-02-05 14:22:31 +01:00
# have to be root to modify (x)inetd
if [ "$1" != "install-embedded" ]
then
removeInetdServiceEntry
fi
2005-04-29 20:16:46 +02:00
}
#------------------------------------------------------------------------
# ask user to enter CORRECT original DBA password
askForOrigDBAPassword() {
OrigPasswd=""
while [ -z "$OrigPasswd" ]
do
AskQuestion "Please enter current password for SYSDBA user: "
OrigPasswd=$Answer
if ! runSilent "$FBBin/gsec -user sysdba -password $OrigPasswd -di"
then
OrigPasswd=""
fi
done
}
#------------------------------------------------------------------------
# Modify DBA password to value, asked from user.
# $1 may be set to original DBA password
# !! This routine is interactive !!
askUserForNewDBAPassword() {
if [ -z $1 ]
then
askForOrigDBAPassword
else
OrigPasswd=$1
fi
NewPasswd=""
while [ -z "$NewPasswd" ]
do
AskQuestion "Please enter new password for SYSDBA user: "
NewPasswd=$Answer
if [ ! -z "$NewPasswd" ]
then
if ! runSilent "$FBBin/gsec -user sysdba -password $OrigPasswd -modify sysdba -pw $NewPasswd"
then
NewPasswd=""
fi
fi
done
}
#------------------------------------------------------------------------
# add a line in the (usually) /etc/services or /etc/inetd.conf file
# Here there are three cases, not found => add
# found & different => replace
# found & same => do nothing
#
replaceLineInFile() {
FileName="$1"
newLine="$2"
oldLine=`grep "$3" $FileName`
if [ -z "$oldLine" ]
2008-12-26 15:39:06 +01:00
then
2005-04-29 20:16:46 +02:00
echo "$newLine" >> "$FileName"
elif [ "$oldLine" != "$newLine" ]
2008-12-26 15:39:06 +01:00
then
2005-04-29 20:16:46 +02:00
MakeTemp
grep -v "$oldLine" "$FileName" > "$TmpFile"
echo "$newLine" >> $TmpFile
2006-04-24 12:08:16 +02:00
cp $TmpFile $FileName && rm -f $TmpFile
2005-04-29 20:16:46 +02:00
echo "Updated $1"
fi
}
#------------------------------------------------------------------------
# "edit" file $1 - replace line starting from $2 with $3
# This should stop ed/ex/vim/"what else editor" battle.
# I hope awk is present in any posix system? AP.
editFile() {
FileName=$1
Starting=$2
NewLine=$3
AwkProgram="(/^$Starting.*/ || \$1 == \"$Starting\") {\$0=\"$NewLine\"} {print \$0}"
2005-04-29 20:16:46 +02:00
MakeTemp
awk "$AwkProgram" <$FileName >$TmpFile && mv $TmpFile $FileName || rm -f $TmpFile
}
2006-04-24 12:08:16 +02:00
#------------------------------------------------------------------------
# remove line from config file if it exists in it.
removeLineFromFile() {
FileName=$1
oldLine=$2
if [ ! -z "$oldLine" ]
then
cat $FileName | grep -v "$oldLine" > ${FileName}.tmp
cp ${FileName}.tmp $FileName && rm -f ${FileName}.tmp
fi
}
2005-04-29 20:16:46 +02:00
#------------------------------------------------------------------------
# Write new password to the @prefix@/SYSDBA.password file
writeNewPassword() {
NewPasswd=$1
DBAPasswordFile=$FBRootDir/SYSDBA.password
cat <<EOT >$DBAPasswordFile
# Firebird generated password for user SYSDBA is:
ISC_USER=sysdba
ISC_PASSWD=$NewPasswd
EOT
if [ $NewPasswd = "masterkey" ]
then
echo "# for install on `hostname` at time `date`" >> $DBAPasswordFile
echo "# You should change this password at the earliest oportunity" >> $DBAPasswordFile
else
echo "# generated on `hostname` at time `date`" >> $DBAPasswordFile
fi
cat <<EOT >>$DBAPasswordFile
# Your password can be changed to a more suitable one using the
# @prefix@/bin/gsec utility.
2005-04-29 20:16:46 +02:00
EOT
chmod u=r,go= $DBAPasswordFile
# Only if we have changed the password from the default do we need
# to update the entry in the database
if [ $NewPasswd != "masterkey" ]
then
runSilent "$FBBin/gsec -user sysdba -password masterkey -modify sysdba -pw $NewPasswd"
fi
}
#------------------------------------------------------------------------
# Change sysdba password.
changeDBAPassword() {
if [ -z "$InteractiveInstall" ]
then
generateNewDBAPassword
else
askUserForNewDBAPassword masterkey
fi
}
#------------------------------------------------------------------------
# buildUninstallFile
# This will work only for the .tar.gz install and it builds an
# uninstall shell script. The RPM system, if present, takes care of it's own.
buildUninstallFile() {
cd "$origDir"
if [ ! -f manifest.txt ] # Only exists if we are a .tar.gz install
then
return
fi
2008-12-26 15:39:06 +01:00
cp manifest.txt $FBRootDir/misc
2005-04-29 20:16:46 +02:00
2008-12-26 15:39:06 +01:00
cp -r scripts $FBRootDir/misc/
[ -f scripts/tarMainUninstall.sh ] && cp scripts/tarMainUninstall.sh $FBRootDir/bin/uninstall.sh
[ -f scripts/tarmainUninstall.sh ] && cp scripts/tarmainUninstall.sh $FBRootDir/bin/uninstall.sh
[ -f $FBRootDir/bin/uninstall.sh ] && chmod u=rx,go= $FBRootDir/bin/uninstall.sh
cd $FBRootDir
2005-04-29 20:16:46 +02:00
}
#------------------------------------------------------------------------
# Remove if only a link
removeIfOnlyAlink() {
Target=$1
if [ -L $Target ]
then
rm -f $Target
fi
}
2005-08-19 02:53:24 +02:00
2005-04-29 20:16:46 +02:00
#------------------------------------------------------------------------
# re-link new file only if target is a link or missing
safeLink() {
Source=$1
Target=$2
removeIfOnlyAlink $Target
if [ ! -e $Target ]
then
ln -s $Source $Target
fi
}
#------------------------------------------------------------------------
# createLinksForBackCompatibility
# Create links for back compatibility to InterBase and Firebird1.0
# linked systems.
createLinksForBackCompatibility() {
# These two links are required for compatibility with existing ib programs
# If the program had been linked with libgds.so then this link is required
# to ensure it loads the fb equivalent. Eventually these should be
# optional and in a seperate rpm install. MOD 7-Nov-2002.
cd $FBRootDir
2005-08-16 12:04:13 +02:00
if [ "$1" ]
then
# Use library name from parameter
newLibrary=$FBRootDir/lib/$1
else
# Use DefaultLibrary, set by appropriate install library
newLibrary=$FBRootDir/lib/$DefaultLibrary.so
fi
2005-04-29 20:16:46 +02:00
safeLink $newLibrary @libdir@/libgds.so
safeLink $newLibrary @libdir@/libgds.so.0
}
#------------------------------------------------------------------------
# removeLinksForBackCompatibility
# Remove links for back compatibility to InterBase and Firebird1.0
# linked systems.
removeLinksForBackCompatibility() {
removeIfOnlyAlink @libdir@/libgds.so
removeIfOnlyAlink @libdir@/libgds.so.0
}
#------------------------------------------------------------------------
# Set correct permissions for $FbRoot/doc tree
fixDocPermissions() {
cd $FBRootDir
for i in `find doc -print`; do
chown root:root $i
if [ -d $i ]; then
chmod 0755 $i
else
chmod 0644 $i
fi
done
}
2005-04-29 20:16:46 +02:00
#------------------------------------------------------------------------
# Run process and check status
runAndCheckExit() {
Cmd=$*
$Cmd
ExitCode=$?
if [ $ExitCode -ne 0 ]
then
echo "Install aborted: The command $Cmd "
echo " failed with error code $ExitCode"
exit $ExitCode
fi
}
#------------------------------------------------------------------------
# Display message if this is being run interactively.
displayMessage() {
msgText=$1
if [ ! -z "$InteractiveInstall" ]
then
echo $msgText
fi
}
#------------------------------------------------------------------------
# Archive any existing prior installed files.
# The 'cd' stuff is to avoid the "leading '/' removed message from tar.
# for the same reason the DestFile is specified without the leading "/"
archivePriorInstallSystemFiles() {
if [ -z ${ArchiveMainFile} ]
then
echo "Variable ArchiveMainFile not set - exiting"
exit 1
fi
2008-12-26 15:39:06 +01:00
tarArc=${ArchiveMainFile}.$tarExt
2005-04-29 20:16:46 +02:00
oldPWD=`pwd`
archiveFileList=""
cd /
DestFile=${FBRootDir#/} # strip off leading /
if [ -e "$DestFile" ]
then
echo ""
echo ""
echo ""
echo "--- Warning ----------------------------------------------"
echo " The installation target directory: $FBRootDir"
echo " Already contains a prior installation of InterBase/Firebird."
echo " This and files found in /usr/include and @libdir@ will be"
2008-12-26 15:39:06 +01:00
echo " archived in the file : ${tarArc}"
2005-04-29 20:16:46 +02:00
echo ""
if [ ! -z "$InteractiveInstall" ]
then
AskQuestion "Press return to continue or ^C to abort"
fi
if [ -e $DestFile ]
then
archiveFileList="$archiveFileList $DestFile"
fi
fi
for i in ibase.h ib_util.h
do
DestFile=usr/include/$i
if [ -e $DestFile ]
then
archiveFileList="$archiveFileList $DestFile"
fi
done
2005-08-16 12:04:13 +02:00
for i in libib_util.so libfbclient.so*
do
for DestFile in usr/lib/$i
do
if [ -e $DestFile ]
then
archiveFileList="$archiveFileList $DestFile"
fi
done
done
# for i in `cat manifest.txt`
# do
# if [ ! -d /$i ] # Ignore directories
# then
# if [ -e /$i ]
# then
# archiveFileList="$archiveFileList $i"
# fi
# fi
# done
for i in usr/sbin/rcfirebird etc/init.d/firebird etc/rc.d/init.d/firebird
2005-04-29 20:16:46 +02:00
do
2005-08-16 12:04:13 +02:00
DestFile=./$i
if [ -e /$DestFile ]
2005-04-29 20:16:46 +02:00
then
archiveFileList="$archiveFileList $DestFile"
fi
done
2005-08-16 12:04:13 +02:00
2005-04-29 20:16:46 +02:00
if [ ! -z "$archiveFileList" ]
then
displayMessage "Archiving..."
2008-12-26 15:39:06 +01:00
runAndCheckExit "tar -cv${tarOptions}f $tarArc $archiveFileList"
2005-04-29 20:16:46 +02:00
displayMessage "Done."
displayMessage "Deleting..."
for i in $archiveFileList
do
rm -rf $i
done
displayMessage "Done."
fi
cd $oldPWD
}
2005-08-16 12:04:13 +02:00
#------------------------------------------------------------------------
# removeInstalledFiles
#
removeInstalledFiles() {
manifestFile=$FBRootDir/misc/manifest.txt
if [ ! -f $manifestFile ]
then
return
fi
origDir=`pwd`
cd /
for i in `cat $manifestFile`
do
if [ -f $i -o -L $i ]
then
rm -f $i
#echo $i
fi
done
cd "$origDir"
}
#------------------------------------------------------------------------
# removeUninstallFiles
# Under the install directory remove all the empty directories
# If some files remain then
removeUninstallFiles() {
# remove the uninstall scripts files.
#echo $FBRootDir/misc/scripts
rm -rf $FBRootDir/misc/scripts
rm -f $FBRootDir/misc/manifest.txt
rm -f $FBRootDir/bin/uninstall.sh
}
#------------------------------------------------------------------------
# removeEmptyDirs
# Under the install directory remove all the empty directories
# If some files remain then
2005-08-19 02:53:24 +02:00
# This routine loops, since deleting a directory possibly makes
2005-08-16 12:04:13 +02:00
# the parent empty as well
removeEmptyDirs() {
dirContentChanged='yes'
while [ ! -z $dirContentChanged ]
do
dirContentChanged=''
2008-12-26 15:39:06 +01:00
for i in `find $FBRootDir -type d -print`; do
ls $i/* >/dev/null 2>&1
if [ $? -ne 0 ]; then
rmdir $i
dirContentChanged=$i
fi
2005-08-16 12:04:13 +02:00
done
if [ ! -d $FBRootDir ] # end loop if the FBRootDir was deleted.
then
dirContentChanged=''
fi
done
}
#------------------------------------------------------------------------
# fixFilePermissions
# Change the permissions to restrict access to server programs to
2008-12-25 11:40:30 +01:00
# firebird group only. This is MUCH better from a safety point of
# view than installing as root user, even if it requires a little
# more work.
fixFilePermissions() {
cd $FBRootDir
# For security reasons initially force all root:root non-writable
chown -R root:root $FBRootDir
chmod -R uga-w $FBRootDir
# Set up configuration files - make them root-writable
cd $FBRootDir
chmod u+w *.conf
# Prepare bin
cd $FBBin
# Everyone may execute clients
chmod a=rx *
# Shell scripts changing security attributes are for root only
chmod u=rx,go= *.sh
# Lock files
cd $FBRootDir
for i in init1 lock1 event1 guard1 monitor1 sem1
do
FileName=isc_$i.`hostname`
touch $FileName
MakeFileFirebirdWritable $FileName
done
# Log file
touch firebird.log
MakeFileFirebirdWritable firebird.log
# Security database
MakeFileFirebirdWritable $SecurityDatabase
2009-03-24 14:08:26 +01:00
# set up libraries & plugins - everyone may use them
cd $FBRootDir
chmod a=rx lib/lib* plugins/lib*
# set up include files - everyone may use them
cd $FBRootDir/include
chmod a=r *
# fix up examples' permissions
cd $FBRootDir/examples
# set a default of read all files in examples
for i in `find . -name '*' -type f -print`
do
chmod a=r $i
done
# set a default of read&search all dirs in examples
for i in `find . -name '*' -type d -print`
do
chmod a=rx $i
done
# make examples DB(s) writable
for i in `find . -name '*.fdb' -print`
do
MakeFileFirebirdWritable $i
done
# fix up doc permissions
cd $FBRootDir
fixDocPermissions
# Architecture (CS/SS) specific permissions
cd $FBRootDir
fixArcSpecificPermissions
cd $FBRootDir
}