26
26
#
27
27
#
28
28
# IDENTIFICATION
29
- # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.81 2000/01/19 20:08:24 petere Exp $
29
+ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.82 2000/01/20 21:51:05 petere Exp $
30
30
#
31
31
# -------------------------------------------------------------------------
32
32
@@ -47,14 +47,7 @@ exit_nicely(){
47
47
48
48
49
49
CMDNAME=` basename$0 `
50
- if [" $USER " = ' root' -o " $LOGNAME " = ' root' ]
51
- then
52
- echo " You cannot run$CMDNAME as root. Please log in (using, e.g., 'su')"
53
- echo " as the (unprivileged) user that will own the server process."
54
- exit 1
55
- fi
56
50
57
- EffectiveUser=` id -n -u2> /dev/null|| whoami2> /dev/null`
58
51
if [" $TMPDIR " ]; then
59
52
TEMPFILE=" $TMPDIR /initdb.$$ "
60
53
else
95
88
fi
96
89
97
90
# Check if needed programs actually exist in path
98
- for prog in postgres pg_version
91
+ for prog in postgres pg_version pg_id
99
92
do
100
93
if [! -x " $PGPATH /$prog " ]
101
94
then
109
102
fi
110
103
done
111
104
105
+
106
+ # Gotta wait for pg_id existence check above
107
+ EffectiveUser=` $PGPATH /pg_id -n -u`
108
+ if [-z " $EffectiveUser " ]; then
109
+ echo " Could not determine current user name. You are really hosed."
110
+ exit 1
111
+ fi
112
+
113
+ if [` $PGPATH /pg_id -u` -eq 0 ]
114
+ then
115
+ echo " You cannot run$CMDNAME as root. Please log in (using, e.g., 'su')"
116
+ echo " as the (unprivileged) user that will own the server process."
117
+ exit 1
118
+ fi
119
+
120
+
112
121
# 0 is the default (non-)encoding
113
122
MULTIBYTEID=0
114
123
# This is placed here by configure --enable-multibyte[=XXX].
@@ -124,12 +133,9 @@ template_only=0
124
133
# superuser be the same as the Unix user owning the server process:
125
134
# The single user postgres backend will only connect as the database
126
135
# user with the same name as the Unix user running it. That's
127
- # a security measure. It might change in the future (why?), but for
128
- # now the --username option is only a fallback if both id and whoami
129
- # fail, and in that case the argument _must_ be the name of the effective
130
- # user.
136
+ # a security measure.
131
137
POSTGRES_SUPERUSERNAME=" $EffectiveUser "
132
- POSTGRES_SUPERUSERID=" ` id -u2> /dev/null || echo 0 ` "
138
+ POSTGRES_SUPERUSERID=` $PGPATH /pg_id -u`
133
139
134
140
while [" $# " -gt 0 ]
135
141
do
150
156
template_only=1
151
157
echo " Updating template1 database only."
152
158
;;
153
- # The database superuser. See comments above.
154
- --username|-u)
155
- POSTGRES_SUPERUSERNAME=" $2 "
156
- shift ;;
157
- --username=* )
158
- POSTGRES_SUPERUSERNAME=` echo$1 | sed' s/^--username=//' `
159
- ;;
160
- -u* )
161
- POSTGRES_SUPERUSERNAME=` echo$1 | sed' s/^-u//' `
162
- ;;
163
- # The sysid of the database superuser. See comments above.
159
+ # The sysid of the database superuser. Can be freely changed.
164
160
--sysid|-i)
165
161
POSTGRES_SUPERUSERID=" $2 "
166
162
shift ;;
@@ -284,21 +280,6 @@ then
284
280
exit 1
285
281
fi
286
282
287
- # ---------------------------------------------------------------------------
288
- # Figure out who the Postgres superuser for the new database system will be.
289
- # ---------------------------------------------------------------------------
290
-
291
- # This means they have neither 'id' nor 'whoami'!
292
- if [-z " $POSTGRES_SUPERUSERNAME " ]
293
- then
294
- echo " $CMDNAME : Could not the determine current username. Please use the -u option."
295
- exit 1
296
- fi
297
-
298
- echo " This database system will be initialized with username\" $POSTGRES_SUPERUSERNAME \" ."
299
- echo " This user will own all the data files and must also own the server process."
300
- echo
301
-
302
283
303
284
# -------------------------------------------------------------------------
304
285
# Find the input files
355
336
356
337
trap ' echo "Caught signal." ; exit_nicely' 1 2 3 15
357
338
339
+ # Let's go
340
+ echo " This database system will be initialized with username\" $POSTGRES_SUPERUSERNAME \" ."
341
+ echo " This user will own all the data files and must also own the server process."
342
+ echo
358
343
359
344
# -----------------------------------------------------------------------
360
345
# Create the data directory if necessary