| 1 |
#! /bin/sh |
| 2 |
# |
| 3 |
# This library is part of the Firebird project |
| 4 |
# |
| 5 |
# This library is free software; you can redistribute it and/or |
| 6 |
# modify it under the terms of the GNU Lesser General Public |
| 7 |
# License as published by the Free Software Foundation; either |
| 8 |
# version 2.1 of the License, or (at your option) any later version. |
| 9 |
# You may obtain a copy of the Licence at |
| 10 |
# http://www.gnu.org/licences/lgpl.html |
| 11 |
# |
| 12 |
# As a special exception this file can also be included in modules |
| 13 |
# with other source code as long as that source code has been |
| 14 |
# released under an Open Source Initiative certificed licence. |
| 15 |
# More information about OSI certification can be found at: |
| 16 |
# http://www.opensource.org |
| 17 |
# |
| 18 |
# This module is distributed in the hope that it will be useful, |
| 19 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
# GNU Lesser General Public Licence for more details. |
| 22 |
# |
| 23 |
# This module was created by members of the firebird development |
| 24 |
# team. All individual contributions remain the Copyright (C) of |
| 25 |
# those individuals and all rights are reserved. Contributors to |
| 26 |
# this file are either listed below or can be obtained from a CVS |
| 27 |
# history command. |
| 28 |
# |
| 29 |
# Created by: Mark O'Donohue <[email protected]> |
| 30 |
# |
| 31 |
# Contributor(s): |
| 32 |
# Alex Peshkoff |
| 33 |
# |
| 34 |
|
| 35 |
fb_install_prefix=@prefix@ |
| 36 |
|
| 37 |
#------------------------------------------------------------------------------ |
| 38 |
# appendDatabaseEntry |
| 39 |
# check to see if an entry already exists in the databases.conf file |
| 40 |
# if it doesn't append it to the end of the file |
| 41 |
|
| 42 |
appendDatabaseEntry() { |
| 43 |
aliasName=$1 |
| 44 |
newDB=$2 |
| 45 |
|
| 46 |
# check if aliasName already exists |
| 47 |
oldLine=`grep "^$aliasName" $DatabaseFile` |
| 48 |
if [ -z "$oldLine" ] |
| 49 |
then |
| 50 |
# Create the alias file entry |
| 51 |
echo "$aliasName = $newDB" >> $DatabaseFile |
| 52 |
else |
| 53 |
cat <<EOF |
| 54 |
The alias name $aliasName already exists in $DatabaseFile with value: |
| 55 |
$oldLine |
| 56 |
|
| 57 |
A new entry will not be created and the existing one will be used. |
| 58 |
EOF |
| 59 |
|
| 60 |
exit |
| 61 |
fi |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
#------------------------------------------------------------------------------ |
| 67 |
# checkNameStartsWithSlash |
| 68 |
# |
| 69 |
|
| 70 |
checkNameStartsWithSlash() { |
| 71 |
|
| 72 |
name=$1 |
| 73 |
|
| 74 |
letter=`echo $name | cut -c1` |
| 75 |
|
| 76 |
if [ $letter != "/" ] |
| 77 |
then |
| 78 |
cat <<EOF |
| 79 |
The file name "$name" needs to be an absolute path to the file not a |
| 80 |
relative path. |
| 81 |
|
| 82 |
Possibly you want: `pwd`/$name |
| 83 |
for the path name. |
| 84 |
EOF |
| 85 |
exit |
| 86 |
fi |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
#------------------------------------------------------------------------------ |
| 91 |
# checkAccessToFile |
| 92 |
# This routine should check that the firebird user has |
| 93 |
# access to the file if it exists or the directory if it |
| 94 |
# does not. |
| 95 |
|
| 96 |
checkAccessToFile() { |
| 97 |
fileName=$1 |
| 98 |
|
| 99 |
dirName=`dirname $fileName` |
| 100 |
|
| 101 |
echo $fileName |
| 102 |
echo $dirName |
| 103 |
|
| 104 |
userName=`id -un` |
| 105 |
if [ $userName = "root" ] |
| 106 |
then |
| 107 |
result=`su firebird -c " if [ -w $dirName ]; then echo 'Ok'; fi"` |
| 108 |
fi |
| 109 |
|
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
#= Main Post =============================================================== |
| 114 |
|
| 115 |
if [ $# -ne 2 ] |
| 116 |
then |
| 117 |
echo "Usage is registerDatabase.sh <alias> <database>" |
| 118 |
exit |
| 119 |
fi |
| 120 |
|
| 121 |
aliasName=$1 |
| 122 |
newDB=$2 |
| 123 |
|
| 124 |
DatabaseFile=@FB_CONFDIR@/databases.conf |
| 125 |
|
| 126 |
checkNameStartsWithSlash $newDB |
| 127 |
appendDatabaseEntry $aliasName $newDB |
| 128 |
|
| 129 |
# checkAccessToFile $newDB |
| 130 |
|
| 131 |
if [ ! -f $newDB ] |
| 132 |
then |
| 133 |
@FB_BINDIR@/isql <<EOF |
| 134 |
create database '$aliasName'; |
| 135 |
quit; |
| 136 |
EOF |
| 137 |
fi |
| 138 |
|
| 139 |
chown firebird:firebird $newDB |