| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
#------------------------------------------------------------------------ |
| 4 |
# Prompt for response, store result in Answer |
| 5 |
|
| 6 |
Answer="" |
| 7 |
|
| 8 |
AskQuestion() { |
| 9 |
Test=$1 |
| 10 |
DefaultAns=$2 |
| 11 |
echo -n "${1}" |
| 12 |
Answer="$DefaultAns" |
| 13 |
read Answer |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
#------------------------------------------------------------------------ |
| 18 |
# add a service line in the (usually) /etc/services or /etc/inetd.conf file |
| 19 |
# Here there are three cases, not found => add service line, |
| 20 |
# found & different => ask user to check |
| 21 |
# found & same => do nothing |
| 22 |
# |
| 23 |
|
| 24 |
replaceLineInFile() { |
| 25 |
|
| 26 |
FileName=$1 |
| 27 |
newLine=$2 |
| 28 |
oldLine=$3 |
| 29 |
Silent=$4 |
| 30 |
|
| 31 |
if [ -z "$oldLine" ] |
| 32 |
then |
| 33 |
echo "$newLine" >> $FileName |
| 34 |
|
| 35 |
elif [ "$oldLine" != "$newLine" ] |
| 36 |
then |
| 37 |
if [ "$Silent" != "Silent" ] |
| 38 |
then |
| 39 |
echo "" |
| 40 |
echo "--- Warning ----------------------------------------------" |
| 41 |
echo "" |
| 42 |
echo " In file $FileName found line: " |
| 43 |
echo " $oldLine" |
| 44 |
echo " Which differs from the expected line:" |
| 45 |
echo " $newLine" |
| 46 |
echo "" |
| 47 |
fi |
| 48 |
|
| 49 |
# AskQuestion "Press return to update file or ^C to abort install" |
| 50 |
|
| 51 |
cat $FileName | grep -v "$oldLine" > ${FileName}.tmp |
| 52 |
mv ${FileName}.tmp $FileName |
| 53 |
echo "$newLine" >> $FileName |
| 54 |
echo "Updated $FileName." |
| 55 |
|
| 56 |
fi |
| 57 |
} |
| 58 |
|
| 59 |
#------------------------------------------------------------------------ |
| 60 |
# Add new user and group |
| 61 |
TryAddGroup() { |
| 62 |
testStr=`grep firebird /etc/group` |
| 63 |
|
| 64 |
if [ -z "$testStr" ]; then |
| 65 |
groupadd firebird |
| 66 |
fi |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
TryAddUser() { |
| 72 |
testStr=`grep firebird /etc/passwd` |
| 73 |
|
| 74 |
if [ -z "$testStr" ]; then |
| 75 |
useradd -d $FBRootDir -s /bin/false \ |
| 76 |
-c "Firebird Database Administrator" -g firebird firebird |
| 77 |
fi |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
addFirebirdUser() { |
| 83 |
TryAddGroup "-g 84 -r" >/dev/null 2>&1 |
| 84 |
TryAddGroup "-g 84" >/dev/null 2>&1 |
| 85 |
TryAddGroup "-r" >/dev/null 2>&1 |
| 86 |
TryAddGroup " " |
| 87 |
|
| 88 |
TryAddUser "-u 84 -r" >/dev/null 2>&1 |
| 89 |
TryAddUser "-u 84" >/dev/null 2>&1 |
| 90 |
TryAddUser "-r" >/dev/null 2>&1 |
| 91 |
TryAddUser " " |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
#------------------------------------------------------------------------ |
| 97 |
# changeInitPassword |
| 98 |
|
| 99 |
changeInitPassword() { |
| 100 |
|
| 101 |
NewPasswd=$1 |
| 102 |
|
| 103 |
InitFile=/sbin/init.d/firebird |
| 104 |
|
| 105 |
if [ -f $InitFile ] |
| 106 |
then |
| 107 |
echo "" |
| 108 |
echo Running ex to modify /sbin/init.d/firebird |
| 109 |
|
| 110 |
# to be sure that `ex' can write to file |
| 111 |
chmod u=rwx,g=rx,o= $InitFile |
| 112 |
|
| 113 |
ex -s $InitFile <<EOF |
| 114 |
/ISC_PASSWORD/s/ISC_PASSWORD=.*/ISC_PASSWORD=$NewPasswd/g |
| 115 |
w |
| 116 |
q |
| 117 |
EOF |
| 118 |
chmod u=rwx,g=rx,o= $InitFile |
| 119 |
|
| 120 |
fi |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
#------------------------------------------------------------------------ |
| 125 |
# Write new password to the @prefix@/SYSDBA.password file |
| 126 |
|
| 127 |
writeNewPassword() { |
| 128 |
NewPasswd=$1 |
| 129 |
|
| 130 |
echo "# Firebird generated password for user SYSDBA is: " > $DBAPasswordFile |
| 131 |
echo "" >> $DBAPasswordFile |
| 132 |
|
| 133 |
echo "ISC_USER=sysdba" >> $DBAPasswordFile |
| 134 |
echo "ISC_PASSWD=$NewPasswd" >> $DBAPasswordFile |
| 135 |
echo "" >> $DBAPasswordFile |
| 136 |
|
| 137 |
if [ $NewPasswd = "masterkey" ] |
| 138 |
then |
| 139 |
echo "# for install on `hostname` at time `date`" >> $DBAPasswordFile |
| 140 |
echo "# You should change this password at the earliest oportunity" >> $DBAPasswordFile |
| 141 |
else |
| 142 |
echo "# generated on `hostname` at time `date`" >> $DBAPasswordFile |
| 143 |
fi |
| 144 |
echo "" >> $DBAPasswordFile |
| 145 |
echo "# Your password can be changed to a more suitable one using the" >> $DBAPasswordFile |
| 146 |
echo "# @prefix@/bin/changeDBAPassword.sh script" >> $DBAPasswordFile |
| 147 |
|
| 148 |
# Additional instructions for super server |
| 149 |
echo "" >> $DBAPasswordFile |
| 150 |
echo "# For superserver you will also want to check the password in the" >> $DBAPasswordFile |
| 151 |
echo "# daemon init routine in the file /sbin/init.d/firebird" >> $DBAPasswordFile |
| 152 |
|
| 153 |
echo "" >> $DBAPasswordFile |
| 154 |
chmod u=r $DBAPasswordFile |
| 155 |
|
| 156 |
|
| 157 |
# Only if we have changed the password from the default do we need |
| 158 |
# to update the entry in the database |
| 159 |
|
| 160 |
if [ $NewPasswd != "masterkey" ] |
| 161 |
then |
| 162 |
@FB_BINDIR@/gsec -user sysdba -password masterkey <<EOF |
| 163 |
modify sysdba -pw $NewPasswd |
| 164 |
EOF |
| 165 |
fi |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
#------------------------------------------------------------------------ |
| 170 |
# Generate new sysdba password - this routine is used only in the |
| 171 |
# rpm file not in the install acript. |
| 172 |
|
| 173 |
|
| 174 |
generateNewDBAPassword() { |
| 175 |
DBAPasswordFile=$FBRootDir/SYSDBA.password |
| 176 |
|
| 177 |
# openssl generates random data. |
| 178 |
if [ -f /usr/bin/openssl ] |
| 179 |
then |
| 180 |
# We generate 20 random chars, strip any '/''s and get the first 8 |
| 181 |
NewPasswd=`openssl rand -base64 20 | tr -d '/' | cut -c1-8` |
| 182 |
fi |
| 183 |
|
| 184 |
# mkpasswd is a bit of a hassle, but check to see if it's there |
| 185 |
if [ -z "$NewPasswd" ] |
| 186 |
then |
| 187 |
if [ -f /usr/bin/mkpasswd ] |
| 188 |
then |
| 189 |
NewPasswd=`/usr/bin/mkpasswd -l 8` |
| 190 |
fi |
| 191 |
fi |
| 192 |
|
| 193 |
|
| 194 |
# So we failed to generate a new password, so keep the original |
| 195 |
# installed one. |
| 196 |
|
| 197 |
if [ -z "$NewPasswd" ] |
| 198 |
then |
| 199 |
NewPasswd="masterkey" |
| 200 |
fi |
| 201 |
|
| 202 |
writeNewPassword $NewPasswd |
| 203 |
changeInitPassword "$NewPasswd" |
| 204 |
|
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
#------------------------------------------------------------------------ |
| 211 |
# Change sysdba password - this routine is interactive and is only |
| 212 |
# used in the install shell script not the rpm one. |
| 213 |
|
| 214 |
|
| 215 |
askUserForNewDBAPassword() { |
| 216 |
NewPasswd="" |
| 217 |
|
| 218 |
echo "" |
| 219 |
while [ -z "$NewPasswd" ] |
| 220 |
do |
| 221 |
AskQuestion "Please enter new password for SYSDBA user: " |
| 222 |
NewPasswd=$Answer |
| 223 |
if [ ! -z "$NewPasswd" ] |
| 224 |
then |
| 225 |
echo "" |
| 226 |
writeNewPassword $NewPasswd |
| 227 |
changeInitPassword "$NewPasswd" |
| 228 |
fi |
| 229 |
|
| 230 |
done |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
#------------------------------------------------------------------------ |
| 235 |
# Change sysdba password - this routine is interactive and is only |
| 236 |
# used in the install shell script not the rpm one. |
| 237 |
|
| 238 |
# On some systems the mkpasswd program doesn't appear and on others |
| 239 |
# there is another mkpasswd which does a different operation. So if |
| 240 |
# the specific one isn't available then keep the original password. |
| 241 |
|
| 242 |
|
| 243 |
changeDBAPassword() { |
| 244 |
if [ -z "$InteractiveInstall" ] |
| 245 |
then |
| 246 |
generateNewDBAPassword |
| 247 |
else |
| 248 |
askUserForNewDBAPassword |
| 249 |
fi |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
#------------------------------------------------------------------------ |
| 254 |
# installInitdScript |
| 255 |
# Everbody stores this one in a seperate location, so there is a bit of |
| 256 |
# running around to actually get it for each packager. |
| 257 |
# Update rcX.d with Firebird initd entries |
| 258 |
# initd script for SuSE >= 7.2 is a part of RPM package |
| 259 |
|
| 260 |
installInitdScript() { |
| 261 |
|
| 262 |
# HPUX... |
| 263 |
|
| 264 |
if [ -d /sbin/init.d ] |
| 265 |
then |
| 266 |
srcScript=firebird.init.d.hpux |
| 267 |
initScript=/sbin/init.d/firebird |
| 268 |
fi |
| 269 |
|
| 270 |
# Install the firebird init.d script |
| 271 |
cp $FBRootDir/misc/$srcScript $initScript |
| 272 |
chown root:root $initScript |
| 273 |
chmod u=rx,g=rx,o= $initScript # contains password hence no world read. |
| 274 |
|
| 275 |
} |
| 276 |
|
| 277 |
#------------------------------------------------------------------------ |
| 278 |
# startInetService |
| 279 |
# Now that we've installed it start up the service. |
| 280 |
|
| 281 |
startInetService() { |
| 282 |
initScript=/sbin/init.d/firebird |
| 283 |
if [ ! -f $initScript ] |
| 284 |
then |
| 285 |
initScript=/sbin/init.d/firebird |
| 286 |
fi |
| 287 |
|
| 288 |
if [ -f $initScript ] |
| 289 |
then |
| 290 |
$initScript start |
| 291 |
checkString=`ps -ef | grep fbserver |grep -v grep` |
| 292 |
|
| 293 |
if [ -z "$checkString" ] |
| 294 |
then |
| 295 |
# server didn't start - possible reason bad shell /bin/false |
| 296 |
echo |
| 297 |
echo Fixing firebird\'s shell to /bin/sh |
| 298 |
echo |
| 299 |
usermod -s /bin/sh firebird |
| 300 |
$initScript start |
| 301 |
fi |
| 302 |
fi |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
#------------------------------------------------------------------------ |
| 307 |
# UpdateHostsDotEquivFile |
| 308 |
# The /etc/hosts.equiv file is needed to allow local access for super server |
| 309 |
# from processes on the machine to port @FB_SERVICE_PORT@ on the local machine. |
| 310 |
# The two host names that are needed there are |
| 311 |
# localhost.localdomain and whatever hostname returns. |
| 312 |
|
| 313 |
updateHostsDotFile() { |
| 314 |
hostEquivFile=$1 |
| 315 |
|
| 316 |
if [ ! -f $hostEquivFile ] |
| 317 |
then |
| 318 |
touch $hostEquivFile |
| 319 |
chown root:root $hostEquivFile |
| 320 |
chmod u=rw,g=r,o=r $hostEquivFile |
| 321 |
fi |
| 322 |
|
| 323 |
newLine="localhost" |
| 324 |
oldLine=`grep "^$newLine\$" $hostEquivFile` |
| 325 |
replaceLineInFile "$hostEquivFile" "$newLine" "$oldLine" |
| 326 |
|
| 327 |
newLine="localhost.localdomain" |
| 328 |
oldLine=`grep "^$newLine\$" $hostEquivFile` |
| 329 |
replaceLineInFile "$hostEquivFile" "$newLine" "$oldLine" |
| 330 |
|
| 331 |
newLine="`hostname`" |
| 332 |
oldLine=`grep "^$newLine\$" $hostEquivFile` |
| 333 |
replaceLineInFile "$hostEquivFile" "$newLine" "$oldLine" |
| 334 |
|
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
#------------------------------------------------------------------------ |
| 339 |
# buildUninstallFile |
| 340 |
# This will work only for the .tar install and it builds an |
| 341 |
# uninstall shell script. |
| 342 |
|
| 343 |
|
| 344 |
buildUninstallFile() { |
| 345 |
cd "$origDir" |
| 346 |
|
| 347 |
if [ ! -f manifest.txt ] # Only do this if we are a .tar install |
| 348 |
then |
| 349 |
return |
| 350 |
fi |
| 351 |
|
| 352 |
cp manifest.txt $FBRootDir/misc |
| 353 |
|
| 354 |
cp -r scripts $FBRootDir/misc/ |
| 355 |
cp scripts/tarmainUninstall.sh $FBRootDir/bin/uninstall.sh |
| 356 |
|
| 357 |
} |
| 358 |
|
| 359 |
#------------------------------------------------------------------------ |
| 360 |
# createLinksForBackCompatibility |
| 361 |
# Create links for back compatibility to InterBase and Firebird1.0 |
| 362 |
# linked systems. |
| 363 |
|
| 364 |
createLinksForBackCompatibility() { |
| 365 |
# These two links are required for compatibility with existing ib programs |
| 366 |
# If the program had been linked with libgds.so then this link is required |
| 367 |
# to ensure it loads the fb equivalent. Eventually these should be |
| 368 |
# optional and in a seperate rpm install. MOD 7-Nov-2002. |
| 369 |
|
| 370 |
|
| 371 |
# Althhough classic has two options for libgds.so super server has only |
| 372 |
# one: |
| 373 |
# 1) The multithreaded client only libfbclient.so |
| 374 |
# MOD 23-Dec-2003 |
| 375 |
|
| 376 |
newLibrary=$FBRootDir/lib/libfbclient.so |
| 377 |
#newLibrary=$FBRootDir/lib/libfbembed.so |
| 378 |
|
| 379 |
# Remove if only a link |
| 380 |
if [ -L @libdir@/libgds.so ] |
| 381 |
then |
| 382 |
rm -f @libdir@/libgds.so |
| 383 |
fi |
| 384 |
|
| 385 |
if [ ! -e @libdir@/libgds.so ] |
| 386 |
then |
| 387 |
ln -s $newLibrary @libdir@/libgds.so |
| 388 |
fi |
| 389 |
|
| 390 |
# Remove if only a link |
| 391 |
if [ -L @libdir@/libgds.so.0 ] |
| 392 |
then |
| 393 |
rm -f @libdir@/libgds.so.0 |
| 394 |
fi |
| 395 |
|
| 396 |
if [ ! -e @libdir@/libgds.so.0 ] |
| 397 |
then |
| 398 |
ln -s $newLibrary @libdir@/libgds.so.0 |
| 399 |
fi |
| 400 |
|
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
#------------------------------------------------------------------------ |
| 405 |
# For security reasons most files in firebird installation are |
| 406 |
# root-owned and world-readable(executable) only (including firebird). |
| 407 |
|
| 408 |
# For some files RunUser (firebird) must have write access - |
| 409 |
# lock and log are such. |
| 410 |
|
| 411 |
|
| 412 |
MakeFileFirebirdWritable() { |
| 413 |
FileName=$1 |
| 414 |
chown firebird:firebird $FileName |
| 415 |
chmod 0644 $FileName |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
#------------------------------------------------------------------------ |
| 420 |
# remove line from config file if it exists in it. |
| 421 |
|
| 422 |
removeLineFromFile() { |
| 423 |
FileName=$1 |
| 424 |
oldLine=$2 |
| 425 |
|
| 426 |
if [ -f $FileName ] |
| 427 |
then |
| 428 |
if [ ! -z "$oldLine" ] |
| 429 |
then |
| 430 |
cat $FileName | grep -v "$oldLine" > ${FileName}.tmp |
| 431 |
mv ${FileName}.tmp $FileName |
| 432 |
echo "Updated." |
| 433 |
fi |
| 434 |
fi |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
#= Main Post =============================================================== |
| 440 |
# Make sure the links are in place |
| 441 |
if [ ! -L @prefix@ -a ! -d @prefix@ ] |
| 442 |
then |
| 443 |
# Main link and... |
| 444 |
ln -s $RPM_INSTALL_PREFIX/interbase @prefix@ |
| 445 |
fi |
| 446 |
|
| 447 |
origDir=`pwd` |
| 448 |
|
| 449 |
# RunUser=root |
| 450 |
RunUser=firebird |
| 451 |
DBAPasswordFile=@FB_CONFDIR@/SYSDBA.password |
| 452 |
export RunUser |
| 453 |
export DBAPasswordFile |
| 454 |
|
| 455 |
|
| 456 |
# Update /etc/services |
| 457 |
# The \n is needed, some /etc/services files are missing a trailing |
| 458 |
# line feed - MOD 12-Dec-2003 |
| 459 |
|
| 460 |
FileName=/etc/services |
| 461 |
newLine="@FB_SERVICE_NAME@ @FB_SERVICE_PORT@/tcp # Firebird SQL Database Remote Protocol" |
| 462 |
oldLine=`grep "^@FB_SERVICE_NAME@" $FileName` |
| 463 |
|
| 464 |
if [ -z "$oldLine" ] |
| 465 |
then |
| 466 |
echo "" >> $FileName |
| 467 |
echo $newLine >> $FileName |
| 468 |
echo "" >> $FileName |
| 469 |
# replaceLineInFile "$FileName" "$newLine" "$oldLine" |
| 470 |
fi |
| 471 |
|
| 472 |
|
| 473 |
# Add entries to host.equiv & hosts.allow files |
| 474 |
updateHostsDotFile /etc/hosts.equiv |
| 475 |
# updateHostsDotFile /etc/hosts.allow |
| 476 |
|
| 477 |
|
| 478 |
# remove any @FB_SERVICE_NAME@ line in the /etc/inetd.conf |
| 479 |
FileName=/etc/inetd.conf |
| 480 |
if [ -f $FileName ] |
| 481 |
then |
| 482 |
oldLine=`grep "^@FB_SERVICE_NAME@" $FileName` |
| 483 |
|
| 484 |
removeLineFromFile "$FileName" "$oldLine" |
| 485 |
fi |
| 486 |
|
| 487 |
|
| 488 |
# Get inetd to reread new init files. |
| 489 |
|
| 490 |
if [ -f /var/run/inetd.pid ] |
| 491 |
then |
| 492 |
kill -HUP `cat /var/run/inetd.pid` |
| 493 |
fi |
| 494 |
|
| 495 |
|
| 496 |
# Update ownership of files |
| 497 |
if [ $RunUser = firebird ] |
| 498 |
then |
| 499 |
# Prepare firebird user |
| 500 |
addFirebirdUser |
| 501 |
fi |
| 502 |
|
| 503 |
# For security reasons initially force all root:root non-writable |
| 504 |
chown -R root:root $FBRootDir |
| 505 |
chmod -R u-w,g-w,a-w $FBRootDir |
| 506 |
|
| 507 |
# Create the fbmgr shell script. |
| 508 |
cat > @FB_SBINDIR@/fbmgr <<EOF |
| 509 |
#!/bin/sh |
| 510 |
FIREBIRD=@FB_CONFDIR@ |
| 511 |
export FIREBIRD |
| 512 |
exec @FB_SBINDIR@/fbmgr.bin \$@ |
| 513 |
EOF |
| 514 |
|
| 515 |
|
| 516 |
# Everyone may execute clients |
| 517 |
chmod 0555 * |
| 518 |
|
| 519 |
# Shell scripts changing security attributes are for root only |
| 520 |
chmod 0500 *.sh |
| 521 |
|
| 522 |
# These two should only be executed by firebird user. |
| 523 |
#fbservices=fbguard fbserver |
| 524 |
#chown firebird:firebird $fbserveces |
| 525 |
#chmod 0544 $fbservices |
| 526 |
|
| 527 |
|
| 528 |
# Lock files |
| 529 |
cd $FBRootDir |
| 530 |
|
| 531 |
for i in isc_init1 isc_lock1 isc_event1 isc_guard1 |
| 532 |
do |
| 533 |
FileName=$i.`hostname` |
| 534 |
touch $FileName |
| 535 |
MakeFileFirebirdWritable $FileName |
| 536 |
done |
| 537 |
|
| 538 |
touch firebird.log |
| 539 |
MakeFileFirebirdWritable firebird.log |
| 540 |
|
| 541 |
# Security database |
| 542 |
# Nobody besides firebird permitted to even read this file |
| 543 |
chown firebird:firebird security.fdb |
| 544 |
chmod 0600 security.fdb |
| 545 |
|
| 546 |
# make examples writable by firebird |
| 547 |
for i in examples/*.fdb |
| 548 |
do |
| 549 |
MakeFileFirebirdWritable $i |
| 550 |
done |
| 551 |
|
| 552 |
# Set up Firebird for run with init.d |
| 553 |
installInitdScript |
| 554 |
|
| 555 |
|
| 556 |
createLinksForBackCompatibility |
| 557 |
|
| 558 |
buildUninstallFile |
| 559 |
|
| 560 |
# start the db server so we can change the password |
| 561 |
startInetService |
| 562 |
|
| 563 |
# Change sysdba password |
| 564 |
cd $FBRootDir |
| 565 |
changeDBAPassword |