| 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 |
RunUser=firebird |
| 26 |
export RunUser |
| 27 |
RunGroup=firebird |
| 28 |
export RunGroup |
| 29 |
PidDir=/var/run/firebird |
| 30 |
export PidDir |
| 31 |
|
| 32 |
#------------------------------------------------------------------------ |
| 33 |
# Get correct options & misc. |
| 34 |
|
| 35 |
psOptions=-efaww |
| 36 |
export psOptions |
| 37 |
mktOptions=-q |
| 38 |
export mktOptions |
| 39 |
tarOptions=z |
| 40 |
export tarOptions |
| 41 |
tarExt=tar.gz |
| 42 |
export tarExt |
| 43 |
|
| 44 |
#------------------------------------------------------------------------ |
| 45 |
# Add new user and group |
| 46 |
|
| 47 |
TryAddGroup() { |
| 48 |
|
| 49 |
AdditionalParameter=$1 |
| 50 |
testStr=`grep $RunGroup /etc/group` |
| 51 |
|
| 52 |
if [ -z "$testStr" ] |
| 53 |
then |
| 54 |
groupadd $AdditionalParameter $RunGroup |
| 55 |
fi |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
TryAddUser() { |
| 61 |
|
| 62 |
AdditionalParameter=$1 |
| 63 |
testStr=`grep $RunUser /etc/passwd` |
| 64 |
|
| 65 |
if [ -z "$testStr" ] |
| 66 |
then |
| 67 |
useradd $AdditionalParameter -d @FB_CONFDIR@ -s /sbin/nologin \ |
| 68 |
-c "Firebird Database Owner" -g $RunUser $RunGroup |
| 69 |
fi |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
addFirebirdUser() { |
| 75 |
|
| 76 |
TryAddGroup "-g 84 -r" >/dev/null 2>/dev/null |
| 77 |
TryAddGroup "-g 84" >/dev/null 2>/dev/null |
| 78 |
TryAddGroup "-r" >/dev/null 2>/dev/null |
| 79 |
TryAddGroup " " |
| 80 |
|
| 81 |
TryAddUser "-u 84 -r -M" >/dev/null 2>/dev/null |
| 82 |
TryAddUser "-u 84 -M" >/dev/null 2>/dev/null |
| 83 |
TryAddUser "-r -M" >/dev/null 2>/dev/null |
| 84 |
TryAddUser "-M" >/dev/null 2>/dev/null |
| 85 |
TryAddUser "-u 84 -r" >/dev/null 2>/dev/null |
| 86 |
TryAddUser "-u 84" >/dev/null 2>/dev/null |
| 87 |
TryAddUser "-r" >/dev/null 2>/dev/null |
| 88 |
TryAddUser " " |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
#------------------------------------------------------------------------ |
| 94 |
# print location of init script |
| 95 |
|
| 96 |
getInitScriptLocation() { |
| 97 |
if [ -f /etc/rc.d/init.d/${fb_startup_name} ] |
| 98 |
then |
| 99 |
printf %s /etc/rc.d/init.d/${fb_startup_name} |
| 100 |
elif [ -f /etc/rc.d/rc.${fb_startup_name} ] |
| 101 |
then |
| 102 |
printf %s /etc/rc.d/rc.${fb_startup_name} |
| 103 |
elif [ -f /etc/init.d/${fb_startup_name} ] |
| 104 |
then |
| 105 |
printf %s /etc/init.d/${fb_startup_name} |
| 106 |
fi |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
#------------------------------------------------------------------------ |
| 111 |
# register/start/stop server using systemd |
| 112 |
|
| 113 |
SYSTEMCTL=systemctl |
| 114 |
CTRL=${fb_startup_name}.service |
| 115 |
SYSTEMD_DIR=/usr/lib/systemd/system |
| 116 |
[ -d $SYSTEMD_DIR ] || SYSTEMD_DIR=/lib/systemd/system |
| 117 |
TMPFILE_CONF=/usr/lib/tmpfiles.d/firebird.conf |
| 118 |
|
| 119 |
systemdPresent() { |
| 120 |
proc1=`ps -p 1 -o comm=` |
| 121 |
|
| 122 |
[ "${proc1}" = systemd ] && return 0 |
| 123 |
return 1 |
| 124 |
} |
| 125 |
|
| 126 |
systemdError() { |
| 127 |
echo "Fatal error running '${1}' - exiting" |
| 128 |
exit 1 |
| 129 |
} |
| 130 |
|
| 131 |
installSystemdCtrlFiles() { |
| 132 |
if systemdPresent |
| 133 |
then |
| 134 |
if [ ! -d ${SYSTEMD_DIR} ] |
| 135 |
then |
| 136 |
echo Missing /usr/lib/systemd/system or /lib/systemd/system |
| 137 |
echo but systemd seems to be running. |
| 138 |
echo Misconfigured - can not proceed with FB install. |
| 139 |
exit 1 |
| 140 |
fi |
| 141 |
|
| 142 |
editFile "@FB_MISCDIR@/firebird.service" ExecStart "ExecStart=${fb_install_prefix}/bin/fbguard -daemon -forever" |
| 143 |
cp @FB_MISCDIR@/firebird.service "${SYSTEMD_DIR}/${fb_startup_name}.service" |
| 144 |
|
| 145 |
mkdir -p ${PidDir} |
| 146 |
chown $RunUser:$RunGroup ${PidDir} |
| 147 |
chmod 0775 ${PidDir} |
| 148 |
echo "d ${PidDir} 0775 $RunUser $RunGroup -" >${TMPFILE_CONF} |
| 149 |
fi |
| 150 |
} |
| 151 |
|
| 152 |
osRemoveStartupFiles() { |
| 153 |
rm -f ${SYSTEMD_DIR}/${fb_startup_name}.* |
| 154 |
rm -f ${TMPFILE_CONF} |
| 155 |
} |
| 156 |
|
| 157 |
systemdSrv() { |
| 158 |
op=${1} |
| 159 |
ctrl=${2} |
| 160 |
|
| 161 |
if systemdPresent |
| 162 |
then |
| 163 |
if [ "${op}" = "stop" -o "${op}" = "disable" ] |
| 164 |
then |
| 165 |
if [ ! -f ${SYSTEMD_DIR}/${ctrl} ] |
| 166 |
then |
| 167 |
return 0 |
| 168 |
fi |
| 169 |
fi |
| 170 |
|
| 171 |
${SYSTEMCTL} --quiet ${op} ${ctrl} || systemdError "${SYSTEMCTL} --quiet ${op} ${ctrl}" |
| 172 |
return 0 |
| 173 |
fi |
| 174 |
return 1 |
| 175 |
} |
| 176 |
|
| 177 |
superSrv() { |
| 178 |
op=${1} |
| 179 |
|
| 180 |
systemdSrv ${op} ${CTRL} |
| 181 |
} |
| 182 |
|
| 183 |
registerSuperServer() { |
| 184 |
installSystemdCtrlFiles |
| 185 |
|
| 186 |
if [ "${fb_install_prefix}" = "${default_prefix}" ] |
| 187 |
then |
| 188 |
superSrv enable && return 0 |
| 189 |
return 1 |
| 190 |
fi |
| 191 |
|
| 192 |
systemdPresent && return 0 |
| 193 |
return 1 |
| 194 |
} |
| 195 |
|
| 196 |
unregisterSuperServer() { |
| 197 |
superSrv disable && return 0 |
| 198 |
} |
| 199 |
|
| 200 |
startSuperServer() { |
| 201 |
superSrv start && return 0 |
| 202 |
} |
| 203 |
|
| 204 |
stopSuperServer() { |
| 205 |
superSrv stop && return 0 |
| 206 |
|
| 207 |
init_d=`getInitScriptLocation` |
| 208 |
if [ -x "$init_d" ] |
| 209 |
then |
| 210 |
$init_d stop |
| 211 |
return 0 |
| 212 |
fi |
| 213 |
|
| 214 |
return 1 |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
#------------------------------------------------------------------------ |
| 220 |
# stop super server if it is running |
| 221 |
|
| 222 |
stopSuperServerIfRunning() { |
| 223 |
checkString=`grepProcess "fbserver|fbguard|fb_smp_server|firebird"` |
| 224 |
|
| 225 |
if [ ! -z "$checkString" ] |
| 226 |
then |
| 227 |
i=1 |
| 228 |
while [ $i -le 20 ] |
| 229 |
do |
| 230 |
stopSuperServer || return # silently giveup |
| 231 |
sleep 1 |
| 232 |
checkString=`grepProcess "fbserver|fbguard|fb_smp_server|firebird"` |
| 233 |
if [ -z "$checkString" ] |
| 234 |
then |
| 235 |
return |
| 236 |
fi |
| 237 |
i=$((i+1)) |
| 238 |
done |
| 239 |
fi |
| 240 |
} |
| 241 |
|
| 242 |
#------------------------------------------------------------------------ |
| 243 |
# Create new password string - this routine is used only in |
| 244 |
# silent mode of the install script. |
| 245 |
|
| 246 |
createNewPassword() { |
| 247 |
# openssl generates random data. |
| 248 |
openssl </dev/null >/dev/null 2>/dev/null |
| 249 |
if [ $? -eq 0 ] |
| 250 |
then |
| 251 |
# We generate 40 random chars, strip any '/''s and get the first 20 |
| 252 |
NewPasswd=`openssl rand -base64 40 | tr -d '/' | cut -c1-20` |
| 253 |
fi |
| 254 |
|
| 255 |
# If openssl is missing... |
| 256 |
if [ -z "$NewPasswd" ] |
| 257 |
then |
| 258 |
NewPasswd=`dd if=/dev/urandom bs=10 count=1 2>/dev/null | od -x | head -n 1 | tr -d ' ' | cut -c8-27` |
| 259 |
fi |
| 260 |
|
| 261 |
# On some systems even this routines may be missing. So if |
| 262 |
# the specific one isn't available then keep the original password. |
| 263 |
if [ -z "$NewPasswd" ] |
| 264 |
then |
| 265 |
NewPasswd="masterkey" |
| 266 |
fi |
| 267 |
|
| 268 |
echo "$NewPasswd" |
| 269 |
} |
| 270 |
|
| 271 |
#------------------------------------------------------------------------ |
| 272 |
# installInitdScript |
| 273 |
# Everbody stores this one in a seperate location, so there is a bit of |
| 274 |
# running around to actually get it for each packager. |
| 275 |
# Update rcX.d with Firebird initd entries |
| 276 |
# initd script for SuSE >= 7.2 is a part of RPM package |
| 277 |
|
| 278 |
installInitdScript() { |
| 279 |
# systemd case |
| 280 |
registerSuperServer && return 0 # systemd's service file takes care about PidDir |
| 281 |
|
| 282 |
srcScript="" |
| 283 |
initScript= |
| 284 |
|
| 285 |
# SuSE specific |
| 286 |
|
| 287 |
if [ -r /etc/SuSE-release ] |
| 288 |
then |
| 289 |
srcScript=firebird.init.d.suse |
| 290 |
initScript=/etc/init.d/${fb_startup_name} |
| 291 |
rm -f /usr/sbin/rc${fb_startup_name} |
| 292 |
ln -s ../../etc/init.d/${fb_startup_name} /usr/sbin/rc${fb_startup_name} |
| 293 |
|
| 294 |
# Debian specific |
| 295 |
|
| 296 |
elif [ -r /etc/debian_version ] |
| 297 |
then |
| 298 |
srcScript=firebird.init.d.debian |
| 299 |
initScript=/etc/init.d/${fb_startup_name} |
| 300 |
rm -f /usr/sbin/rc${fb_startup_name} |
| 301 |
ln -s ../../etc/init.d/${fb_startup_name} /usr/sbin/rc${fb_startup_name} |
| 302 |
|
| 303 |
# Slackware specific |
| 304 |
|
| 305 |
elif [ -r /etc/slackware-version ] |
| 306 |
then |
| 307 |
srcScript=firebird.init.d.slackware |
| 308 |
initScript=/etc/rc.d/rc.${fb_startup_name} |
| 309 |
rclocal=/etc/rc.d/rc.local |
| 310 |
if ! grep -q "$initScript" $rclocal |
| 311 |
then |
| 312 |
cat >>$rclocal <<EOF |
| 313 |
if [ -x $initScript ] ; then |
| 314 |
$initScript start |
| 315 |
fi |
| 316 |
EOF |
| 317 |
fi |
| 318 |
|
| 319 |
# Gentoo specific |
| 320 |
|
| 321 |
elif [ -r /etc/gentoo-release ] |
| 322 |
then |
| 323 |
srcScript=firebird.init.d.gentoo |
| 324 |
initScript=/etc/init.d/${fb_startup_name} |
| 325 |
|
| 326 |
# This is for RH and MDK specific |
| 327 |
|
| 328 |
elif [ -e /etc/rc.d/init.d/functions ] # very generic check - may be should go later to avoid fault mandrake detection ??? |
| 329 |
then |
| 330 |
srcScript=firebird.init.d.mandrake |
| 331 |
initScript=/etc/rc.d/init.d/${fb_startup_name} |
| 332 |
|
| 333 |
# Generic... |
| 334 |
|
| 335 |
elif [ -d /etc/rc.d/init.d ] |
| 336 |
then |
| 337 |
srcScript=firebird.init.d.generic |
| 338 |
initScript=/etc/rc.d/init.d/${fb_startup_name} |
| 339 |
fi |
| 340 |
|
| 341 |
|
| 342 |
if [ "$initScript" ] |
| 343 |
then |
| 344 |
# Install the firebird init.d script |
| 345 |
cp @FB_MISCDIR@/$srcScript $initScript |
| 346 |
chown root:root $initScript |
| 347 |
chmod u=rwx,g=rx,o=r $initScript |
| 348 |
|
| 349 |
if [ "${fb_install_prefix}" = "${default_prefix}" ] |
| 350 |
then |
| 351 |
# RedHat and Mandrake specific |
| 352 |
if [ -x /sbin/chkconfig ] |
| 353 |
then |
| 354 |
/sbin/chkconfig --add ${fb_startup_name} |
| 355 |
|
| 356 |
# Gentoo specific |
| 357 |
elif [ -x /sbin/rc-update ] |
| 358 |
then |
| 359 |
/sbin/rc-update add ${fb_startup_name} default |
| 360 |
|
| 361 |
# Suse specific |
| 362 |
elif [ -x /sbin/insserv ] |
| 363 |
then |
| 364 |
/sbin/insserv /etc/init.d/${fb_startup_name} |
| 365 |
|
| 366 |
# One more way to register service - used in Debian |
| 367 |
elif [ -x /usr/sbin/update-rc.d ] |
| 368 |
then |
| 369 |
/usr/sbin/update-rc.d -f ${fb_startup_name} remove |
| 370 |
/usr/sbin/update-rc.d -f ${fb_startup_name} defaults |
| 371 |
fi |
| 372 |
|
| 373 |
# More SuSE - rc.config fillup |
| 374 |
if [ -f /etc/rc.config ] |
| 375 |
then |
| 376 |
if [ -x /bin/fillup ] |
| 377 |
then |
| 378 |
/bin/fillup -q -d = /etc/rc.config @FB_MISCDIR@/rc.config.firebird |
| 379 |
fi |
| 380 |
elif [ -d /etc/sysconfig ] |
| 381 |
then |
| 382 |
cp @FB_MISCDIR@/rc.config.firebird /etc/sysconfig/firebird |
| 383 |
fi |
| 384 |
fi |
| 385 |
|
| 386 |
else |
| 387 |
echo "Couldn't autodetect linux type. You must select" |
| 388 |
echo "the most appropriate startup script in @FB_MISCDIR@" |
| 389 |
echo "and manually register it in your OS." |
| 390 |
fi |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
#------------------------------------------------------------------------ |
| 395 |
# start init.d service |
| 396 |
|
| 397 |
startService() { |
| 398 |
# systemd case |
| 399 |
startSuperServer && return 0 |
| 400 |
|
| 401 |
InitFile=`getInitScriptLocation` |
| 402 |
if [ -f "$InitFile" ]; then |
| 403 |
"$InitFile" start |
| 404 |
|
| 405 |
checkString=`grepProcess "firebird"` |
| 406 |
if [ -z "$checkString" ] |
| 407 |
then |
| 408 |
# server didn't start - wait a bit and recheck |
| 409 |
sleep 2 |
| 410 |
"$InitFile" start |
| 411 |
|
| 412 |
checkString=`grepProcess "firebird"` |
| 413 |
if [ -z "$checkString" ] |
| 414 |
then |
| 415 |
echo "Looks like standalone server failed to start" |
| 416 |
echo "Trying to continue anyway..." |
| 417 |
fi |
| 418 |
fi |
| 419 |
fi |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
#------------------------------------------------------------------------ |
| 424 |
# If we have right systems remove the service autostart stuff. |
| 425 |
|
| 426 |
removeServiceAutostart() { |
| 427 |
if standaloneServerInstalled |
| 428 |
then |
| 429 |
# Must try to stop server cause it can be started manually when -path is used |
| 430 |
|
| 431 |
# systemd case |
| 432 |
unregisterSuperServer && return 0 |
| 433 |
|
| 434 |
# Unregister using OS command |
| 435 |
if [ -x /sbin/insserv ]; then |
| 436 |
/sbin/insserv /etc/init.d/ |
| 437 |
fi |
| 438 |
|
| 439 |
if [ -x /sbin/chkconfig ]; then |
| 440 |
/sbin/chkconfig --del ${fb_startup_name} |
| 441 |
fi |
| 442 |
|
| 443 |
if [ -x /sbin/rc-update ]; then |
| 444 |
/sbin/rc-update del ${fb_startup_name} |
| 445 |
fi |
| 446 |
|
| 447 |
# Remove /usr/sbin/rcfirebird symlink |
| 448 |
if [ -e /usr/sbin/rc${fb_startup_name} ] |
| 449 |
then |
| 450 |
rm -f /usr/sbin/rc${fb_startup_name} |
| 451 |
fi |
| 452 |
|
| 453 |
# Remove initd script |
| 454 |
rm -f $InitFile |
| 455 |
fi |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
#------------------------------------------------------------------------ |
| 460 |
# Returns TRUE if SA server is installed |
| 461 |
|
| 462 |
standaloneServerInstalled() { |
| 463 |
if systemdPresent; then |
| 464 |
${SYSTEMCTL} --quiet is-enabled ${CTRL} && return 0 |
| 465 |
return 1 |
| 466 |
fi |
| 467 |
|
| 468 |
InitFile=`getInitScriptLocation` |
| 469 |
if [ -f "$InitFile" ]; then |
| 470 |
return 0 |
| 471 |
fi |
| 472 |
return 1 |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
#------------------------------------------------------------------------ |
| 477 |
# Corrects build-time "libdir" value |
| 478 |
|
| 479 |
CorrectLibDir() { |
| 480 |
ld=${1} |
| 481 |
l=/usr/lib |
| 482 |
l64=/usr/lib64 |
| 483 |
|
| 484 |
if [ "$ld" = "$l64" ] |
| 485 |
then |
| 486 |
if [ -d "$l" ] |
| 487 |
then |
| 488 |
if [ ! -d "$l64" ] |
| 489 |
then |
| 490 |
ld="$l" |
| 491 |
fi |
| 492 |
fi |
| 493 |
fi |
| 494 |
|
| 495 |
echo "$ld" |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
#------------------------------------------------------------------------ |
| 500 |
# Validate library name |
| 501 |
|
| 502 |
checkLibName() { |
| 503 |
grepFlag=-v |
| 504 |
[ "@CPU_TYPE@" = "amd64" ] && grepFlag= |
| 505 |
ldconfig -p | grep -w "${1}" | grep $grepFlag 'x86-64' |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
#------------------------------------------------------------------------ |
| 510 |
# Checks for presence of libName in OS |
| 511 |
|
| 512 |
haveLibrary() { |
| 513 |
libName=${1} |
| 514 |
[ -z "$libName" ] && return 1 |
| 515 |
|
| 516 |
fixTommath=fixTomMath |
| 517 |
|
| 518 |
checkLibName "$libName" >/dev/null 2>/dev/null && return 0 |
| 519 |
|
| 520 |
checkLibName "lib$libName" >/dev/null 2>/dev/null |
| 521 |
|
| 522 |
return $? |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
#------------------------------------------------------------------------ |
| 527 |
# Fix .so version of libtommath |
| 528 |
|
| 529 |
fixTomMath() { |
| 530 |
tm1=`checkLibName libtommath.so.1 | awk '{print $4}'` |
| 531 |
[ -z "$tm1" ] && return |
| 532 |
tm0=`dirname $tm1`/`basename $tm1 .1`.0 |
| 533 |
[ -e "$tm0" ] && return |
| 534 |
ln -s $tm1 $tm0 |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
#------------------------------------------------------------------------ |
| 539 |
# refresh cache of dynamic loader after add/delete files in system libdir |
| 540 |
|
| 541 |
reconfigDynamicLoader() { |
| 542 |
ldconfig |
| 543 |
} |