#!/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 # and all contributors signed below. # # All Rights Reserved. # Contributor(s): ______________________________________. # Alex Peshkoff # RunUser=firebird export RunUser RunGroup=firebird export RunGroup PidDir=/var/run/firebird export PidDir #------------------------------------------------------------------------ # Get correct options & misc. psOptions=-efaww export psOptions mktOptions=-q export mktOptions tarOptions=z export tarOptions tarExt=tar.gz export tarExt #------------------------------------------------------------------------ # Add new user and group TryAddGroup() { AdditionalParameter=$1 testStr=`grep $RunGroup /etc/group` if [ -z "$testStr" ] then groupadd $AdditionalParameter $RunGroup fi } TryAddUser() { AdditionalParameter=$1 testStr=`grep $RunUser /etc/passwd` if [ -z "$testStr" ] then useradd $AdditionalParameter -d @FB_CONFDIR@ -s /sbin/nologin \ -c "Firebird Database Owner" -g $RunUser $RunGroup fi } addFirebirdUser() { TryAddGroup "-g 84 -r" >/dev/null 2>/dev/null TryAddGroup "-g 84" >/dev/null 2>/dev/null TryAddGroup "-r" >/dev/null 2>/dev/null TryAddGroup " " TryAddUser "-u 84 -r -M" >/dev/null 2>/dev/null TryAddUser "-u 84 -M" >/dev/null 2>/dev/null TryAddUser "-r -M" >/dev/null 2>/dev/null TryAddUser "-M" >/dev/null 2>/dev/null TryAddUser "-u 84 -r" >/dev/null 2>/dev/null TryAddUser "-u 84" >/dev/null 2>/dev/null TryAddUser "-r" >/dev/null 2>/dev/null TryAddUser " " } #------------------------------------------------------------------------ # print location of init script getInitScriptLocation() { if [ -f /etc/rc.d/init.d/${fb_startup_name} ] then printf %s /etc/rc.d/init.d/${fb_startup_name} elif [ -f /etc/rc.d/rc.${fb_startup_name} ] then printf %s /etc/rc.d/rc.${fb_startup_name} elif [ -f /etc/init.d/${fb_startup_name} ] then printf %s /etc/init.d/${fb_startup_name} fi } #------------------------------------------------------------------------ # register/start/stop server using systemd SYSTEMCTL=systemctl CTRL=${fb_startup_name}.service SYSTEMD_DIR=/usr/lib/systemd/system [ -d $SYSTEMD_DIR ] || SYSTEMD_DIR=/lib/systemd/system TMPFILE_CONF=/usr/lib/tmpfiles.d/firebird.conf systemdPresent() { proc1=`ps -p 1 -o comm=` [ "${proc1}" = systemd ] && return 0 return 1 } systemdError() { echo "Fatal error running '${1}' - exiting" exit 1 } installSystemdCtrlFiles() { if systemdPresent then if [ ! -d ${SYSTEMD_DIR} ] then echo Missing /usr/lib/systemd/system or /lib/systemd/system echo but systemd seems to be running. echo Misconfigured - can not proceed with FB install. exit 1 fi editFile "@FB_MISCDIR@/firebird.service" ExecStart "ExecStart=${fb_install_prefix}/bin/fbguard -pidfile $PidDir/${fb_startup_name}.pid -daemon -forever" editFile "@FB_MISCDIR@/firebird.service" PIDFile "PIDFile=$PidDir/${fb_startup_name}.pid" cp @FB_MISCDIR@/firebird.service "${SYSTEMD_DIR}/${fb_startup_name}.service" mkdir -p ${PidDir} chown $RunUser:$RunGroup ${PidDir} chmod 0775 ${PidDir} echo "d ${PidDir} 0775 $RunUser $RunGroup -" >${TMPFILE_CONF} fi } osRemoveStartupFiles() { rm -f ${SYSTEMD_DIR}/${fb_startup_name}.* rm -f ${TMPFILE_CONF} } systemdSrv() { op=${1} ctrl=${2} if systemdPresent then if [ "${op}" = "stop" -o "${op}" = "disable" ] then if [ ! -f ${SYSTEMD_DIR}/${ctrl} ] then return 0 fi fi ${SYSTEMCTL} --quiet ${op} ${ctrl} || systemdError "${SYSTEMCTL} --quiet ${op} ${ctrl}" return 0 fi return 1 } superSrv() { op=${1} systemdSrv ${op} ${CTRL} } registerSuperServer() { installSystemdCtrlFiles if [ "${fb_install_prefix}" = "${default_prefix}" ] then superSrv enable && return 0 return 1 fi systemdPresent && return 0 return 1 } unregisterSuperServer() { superSrv disable && return 0 } startSuperServer() { superSrv start && return 0 } stopSuperServer() { superSrv stop && return 0 init_d=`getInitScriptLocation` if [ -x "$init_d" ] then $init_d stop return 0 fi return 1 } #------------------------------------------------------------------------ # stop super server if it is running stopSuperServerIfRunning() { checkString=`grepProcess "fbserver|fbguard|fb_smp_server|firebird"` if [ ! -z "$checkString" ] then i=1 while [ $i -le 20 ] do stopSuperServer || return # silently giveup sleep 1 checkString=`grepProcess "fbserver|fbguard|fb_smp_server|firebird"` if [ -z "$checkString" ] then return fi i=$((i+1)) done fi } #------------------------------------------------------------------------ # Create new password string - this routine is used only in # silent mode of the install script. createNewPassword() { # openssl generates random data. openssl /dev/null 2>/dev/null if [ $? -eq 0 ] then # We generate 40 random chars, strip any '/''s and get the first 20 NewPasswd=`openssl rand -base64 40 | tr -d '/' | cut -c1-20` fi # If openssl is missing... if [ -z "$NewPasswd" ] then NewPasswd=`dd if=/dev/urandom bs=10 count=1 2>/dev/null | od -x | head -n 1 | tr -d ' ' | cut -c8-27` fi # On some systems even this routines may be missing. So if # the specific one isn't available then keep the original password. if [ -z "$NewPasswd" ] then NewPasswd="masterkey" fi echo "$NewPasswd" } #------------------------------------------------------------------------ # installInitdScript # Everbody stores this one in a seperate location, so there is a bit of # running around to actually get it for each packager. # Update rcX.d with Firebird initd entries # initd script for SuSE >= 7.2 is a part of RPM package installInitdScript() { # systemd case registerSuperServer && return 0 # systemd's service file takes care about PidDir srcScript="" initScript= # SuSE specific if [ -r /etc/SuSE-release ] then srcScript=firebird.init.d.suse initScript=/etc/init.d/${fb_startup_name} rm -f /usr/sbin/rc${fb_startup_name} ln -s ../../etc/init.d/${fb_startup_name} /usr/sbin/rc${fb_startup_name} # Debian specific elif [ -r /etc/debian_version ] then srcScript=firebird.init.d.debian initScript=/etc/init.d/${fb_startup_name} rm -f /usr/sbin/rc${fb_startup_name} ln -s ../../etc/init.d/${fb_startup_name} /usr/sbin/rc${fb_startup_name} # Slackware specific elif [ -r /etc/slackware-version ] then srcScript=firebird.init.d.slackware initScript=/etc/rc.d/rc.${fb_startup_name} rclocal=/etc/rc.d/rc.local if ! grep -q "$initScript" $rclocal then cat >>$rclocal </dev/null 2>/dev/null && return 0 libName="lib${libName}" checkLibName "$libName" >/dev/null 2>/dev/null return $? } #------------------------------------------------------------------------ # Fix .so version of libtommath fixTomMath() { tm1=`checkLibName libtommath.so.1 | awk '{print $4}'` [ -z "$tm1" ] && return tm0=`dirname $tm1`/`basename $tm1 .1`.0 [ -e "$tm0" ] && return ln -s $tm1 $tm0 } #------------------------------------------------------------------------ # refresh cache of dynamic loader after add/delete files in system libdir reconfigDynamicLoader() { ldconfig }