Debian Codegraph @

builds/install/arch-specific/hpux/misc/createaliasDB.sh.in

raw
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 #
33 #
34
35 fb_install_prefix=@prefix@
36
37 #------------------------------------------------------------------------
38 # Prompt for response, store result in Answer
39
40 Answer=""
41
42 AskQuestion() {
43 Test=$1
44 DefaultAns=$2
45 echo -n "${1}"
46 Answer="$DefaultAns"
47 read Answer
48 }
49
50
51
52 #------------------------------------------------------------------------------
53 # appendAliasEntry
54 # check to see if an entry already exists in the databases.conf file
55 # if it doesn't append it to the end of the file
56
57 appendAliasEntry() {
58 aliasName=$1
59 newDB=$2
60
61 # check if aliasName already exists
62 oldLine=`grep "^$aliasName" $AliasFile`
63 if [ -z $oldLine ]
64 then
65 # Create the alias file entry
66 echo "$aliasName = $newDB" >> $AliasFile
67 else
68 cat <<EOF
69 The alias name $aliasName already exists in $AliasFile
70 with value:
71 $oldLine
72
73 A new entry will not be created and the existing one will be used.
74 EOF
75
76 AskQuestion "Press return to continue or ^C to abort"
77 fi
78
79 }
80
81
82 #------------------------------------------------------------------------------
83 # checkNameStartsWithSlash
84 #
85
86 checkNameStartsWithSlash() {
87
88 name=$1
89
90 letter=`echo $name | cut -c1`
91
92 if [ $letter != "/" ]
93 then
94 cat <<EOF
95 The file name "$name" needs to be an absolute path to the file not a
96 relative path.
97
98 Possibly you want: `pwd`/$name
99 for the path name.
100 EOF
101 exit
102 fi
103 }
104
105
106 #------------------------------------------------------------------------------
107 # checkAccessToFile
108 # This routine should check that the firebird user has
109 # access to the file if it exists or the directory if it
110 # does not.
111
112 checkAccessToFile() {
113 fileName=$1
114
115 dirName=`dirname $fileName`
116
117 echo $fileName
118 echo $dirName
119
120 userName=`id -un`
121 if [ $userName = "root" ]
122 then
123 result=`su firebird -c " if [ -w $dirName ]; then echo 'Ok'; fi"`
124 fi
125
126
127 }
128
129 #= Main Post ===============================================================
130
131
132 if [ $# -ne 2 ]
133 then
134 echo "Usage is createAliasDB.sh <name> <newDB>"
135 exit
136 fi
137
138 aliasName=$1
139 newDB=$2
140
141 AliasFile=@FB_CONFDIR@/databases.conf
142
143
144 checkNameStartsWithSlash $newDB
145 appendAliasEntry $aliasName $newDB
146
147 # checkAccessToFile $newDB
148
149 if [ ! -f $newDB ]
150 then
151 @FB_BINDIR@/isql <<EOF
152 create database 'localhost:$aliasName';
153 quit;
154 EOF
155 fi
156
157