Debian Codegraph @

builds/install/arch-specific/freebsd/freebsdLibrary.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 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=-ajx
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 addFirebirdUser() {
48
49 nofbuid=0
50 fbUID=`id -u firebird 2>/dev/null`
51 if [ $? -ne 0 ]; then
52 fbUID=90
53 while [ ! -z `id -un $fbUID 2>/dev/null` ]
54 do
55 fbUID=$(($fbUID+1))
56 done
57 nofbuid=1
58 fi
59
60 fbGID=`pw groupshow firebird 2>/dev/null`
61 if [ $? -ne 0 ]; then
62 fbGID=90
63 while [ ! -z `id -gn $fbGID 2>/dev/null` ]
64 do
65 fbGID=$(($fbGID+1))
66 done
67 echo "firebird:*:$fbGID:" >> /etc/group
68 else
69 fbGID=`echo $fbGID | awk -F: '{print $3}'`
70 fi
71
72 echo "firebird user using uid $fbUID"
73 echo "firebird user using gid $fbGID"
74
75 if which -s pw; then
76 if [ $nofbuid -ne 0 ]; then
77 pw useradd firebird -u $fbUID -g $fbGID -h - -s /bin/sh \
78 -d @FB_CONFDIR@ -c "Firebird Database Administrator"
79 fi
80 else
81 echo -n "unable to create user firebird - please create it manually,"
82 echo " before reinstalling this package."
83 exit 1
84 fi
85
86 }
87
88
89 #------------------------------------------------------------------------
90 # print location of init script
91
92 getInitScriptLocation() {
93 if [ -f /etc/rc.d/init.d/*firebird* ]
94 then
95 echo -n /etc/rc.d/init.d/*firebird*
96 elif [ -f /etc/rc.d/*firebird* ]
97 then
98 echo -n /etc/rc.d/*firebird*
99 elif [ -f /etc/init.d/*firebird* ]
100 then
101 echo -n /etc/init.d/*firebird*
102 fi
103 }
104
105
106 #------------------------------------------------------------------------
107 # stop super server if it is running
108
109 stopSuperServerIfRunning() {
110 checkString=`ps -af | egrep "\b(fbserver|fbguard|fb_smp_server)\b" |grep -v grep`
111
112 if [ ! -z "$checkString" ]
113 then
114 init_d=`getInitScriptLocation`
115
116 if [ -x "$init_d" ]
117 then
118 i=1
119 while [ $i -le 20 ]
120 do
121 $init_d stop
122 sleep 1
123 checkString=`ps -eaf | egrep "\b(fbserver|fbguard|fb_smp_server)\b" |grep -v grep`
124 if [ -z "$checkString" ]
125 then
126 return
127 fi
128 i=$((i+1))
129 done
130 fi
131 fi
132 }
133
134 #------------------------------------------------------------------------
135 # Generate new sysdba password - this routine is used only in the
136 # rpm file not in the install script.
137
138 generateNewDBAPassword() {
139 # openssl generates random data.
140 openssl </dev/null >/dev/null 2>/dev/null
141 if [ $? -eq 0 ]
142 then
143 # We generate 20 random chars, strip any '/''s and get the first 8
144 NewPasswd=`openssl rand -base64 20 | tr -d '/' | cut -c1-8`
145 fi
146
147 # mkpasswd is a bit of a hassle, but check to see if it's there
148 if [ -z "$NewPasswd" ]
149 then
150 if [ -f /usr/bin/mkpasswd ]
151 then
152 NewPasswd=`/usr/bin/mkpasswd -l 8`
153 fi
154 fi
155
156 # On some systems the mkpasswd program doesn't appear and on others
157 # there is another mkpasswd which does a different operation. So if
158 # the specific one isn't available then keep the original password.
159 if [ -z "$NewPasswd" ]
160 then
161 NewPasswd="masterkey"
162 fi
163
164 writeNewPassword $NewPasswd
165 }
166
167 #------------------------------------------------------------------------
168 # change init.d RunUser
169
170 changeInitRunUser() {
171 NewUser=$1
172
173 InitFile=`getInitScriptLocation`
174 if [ -f "$InitFile" ]
175 then
176 editFile "$InitFile" FBRunUser "FBRunUser=$NewUser"
177 chmod u=rwx,g=rx,o= "$InitFile"
178 fi
179 }
180
181
182 #------------------------------------------------------------------------
183 # installInitdScript
184 # Everbody stores this one in a seperate location, so there is a bit of
185 # running around to actually get it for each packager.
186 # Update rcX.d with Firebird initd entries
187 # initd script for SuSE >= 7.2 is a part of RPM package
188
189 installInitdScript() {
190 Arch=$1
191 if [ "$Arch" != super ]; then
192 return 0
193 fi
194
195 # dummy for a while
196 return 1
197 }
198
199
200 #------------------------------------------------------------------------
201 # start init.d service
202
203 startService() {
204 Arch=$1
205 if [ "$Arch" != super ]; then
206 return 0
207 fi
208
209 InitFile=`getInitScriptLocation`
210 if [ -f "$InitFile" ]
211 then
212 "$InitFile" start
213
214 checkString=`ps -af | egrep "\b(fbserver|fb_smp_server)\b" |grep -v grep`
215 if [ -z "$checkString" ]
216 then
217 # server didn't start - possible reason bad shell /bin/false for user "firebird"
218 echo
219 echo Fixing firebird\'s shell to /bin/sh
220 echo
221 pw usermod firebird -s /bin/sh
222 "$InitFile" start
223 fi
224 fi
225 }
226
227 #------------------------------------------------------------------------
228 # If we have right systems remove the service autostart stuff.
229
230 removeServiceAutostart() {
231 # dummy for a while
232 return 1
233 }