|
1 | 1 | #! /bin/sh
|
2 | 2 | #-------------------------------------------------------------------------
|
3 | 3 | #
|
4 |
| -# initdb creates (initializes) a Postgres database cluster (site, |
| 4 | +# initdb creates (initializes) a PostgreSQL database cluster (site, |
5 | 5 | # instance, installation, whatever). A database cluster is a
|
6 |
| -# collection of Postgres databases all managed by the same postmaster. |
| 6 | +# collection of PostgreSQL databases all managed by the same postmaster. |
7 | 7 | #
|
8 | 8 | # To create the database cluster, we create the directory that contains
|
9 | 9 | # all its data, create the files that hold the global tables, create
|
10 | 10 | # a few other control files for it, and create one database: the
|
11 | 11 | # template database.
|
12 | 12 | #
|
13 |
| -# The template database is an ordinary Postgres database. Its data |
14 |
| -# never changes, though. It exists to make it easy for Postgres to |
| 13 | +# The template database is an ordinary PostgreSQL database. Its data |
| 14 | +# never changes, though. It exists to make it easy for PostgreSQL to |
15 | 15 | # create other databases -- it just copies.
|
16 | 16 | #
|
17 | 17 | # Optionally, we can skip creating the complete database cluster and
|
|
23 | 23 | #
|
24 | 24 | # Copyright (c) 1994, Regents of the University of California
|
25 | 25 | #
|
26 |
| -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.106 2000/10/22 17:55:45 pjw Exp $ |
| 26 | +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.107 2000/10/28 22:14:14 petere Exp $ |
27 | 27 | #
|
28 | 28 | #-------------------------------------------------------------------------
|
29 | 29 |
|
|
85 | 85 | if echo "$0" | grep '/' > /dev/null 2>&1
|
86 | 86 | then
|
87 | 87 | # explicit dir name given
|
88 |
| - PGPATH=`echo $0 | sed 's,/[^/]*$,,'` # (dirname command is not portable) |
| 88 | + self_path=`echo $0 | sed 's,/[^/]*$,,'` # (dirname command is not portable) |
89 | 89 | else
|
90 | 90 | # look for it in PATH ('which' command is not portable)
|
91 | 91 | for dir in `echo "$PATH" | sed 's/:/ /g'`
|
|
94 | 94 | [ -z "$dir" ] && dir='.'
|
95 | 95 | if [ -f "$dir/$CMDNAME" ]
|
96 | 96 | then
|
97 |
| - PGPATH="$dir" |
| 97 | + self_path="$dir" |
98 | 98 | break
|
99 | 99 | fi
|
100 | 100 | done
|
101 | 101 | fi
|
102 | 102 |
|
103 |
| -if [ x"$PGPATH" = x"" ] ; then |
104 |
| - PGPATH=$bindir |
| 103 | + |
| 104 | +# Check for right version of backend. First we check for an |
| 105 | +# executable in the same directory is this initdb script (presuming |
| 106 | +# the above code worked). Then we fall back to the hard-wired bindir. |
| 107 | +# We do it in this order because during upgrades users might move |
| 108 | +# their trees to backup places, so $bindir might be inaccurate. |
| 109 | + |
| 110 | +if [ x"$self_path" != x"" ] \ |
| 111 | + && [ -x "$self_path/postgres" ] \ |
| 112 | + && [ x"`$self_path/postgres --version 2>/dev/null`" == x"postgres (PostgreSQL) $VERSION" ] |
| 113 | +then |
| 114 | + PGPATH=$self_path |
| 115 | +elif [ -x "$bindir/postgres" ]; then |
| 116 | + if [ x"`$bindir/postgres --version 2>/dev/null`" == x"postgres (PostgreSQL) $VERSION" ] |
| 117 | + then |
| 118 | + PGPATH=$bindir |
| 119 | + else |
| 120 | + echo "The program '$bindir/postgres' needed by $CMDNAME does not belong to" |
| 121 | + echo "PostgreSQL version $VERSION. Check your installation." |
| 122 | + exit 1 |
| 123 | + fi |
| 124 | +else |
| 125 | + echo "The program 'postgres' is needed by $CMDNAME but was not found in" |
| 126 | + echo "the directory '$bindir'. Check your installation." |
| 127 | + exit 1 |
105 | 128 | fi
|
106 | 129 |
|
107 |
| -# Check if needed programs actually exist in path |
108 |
| -for prog in postgres pg_id |
109 |
| -do |
110 |
| - if [ ! -x "$PGPATH/$prog" ] |
111 |
| - then |
112 |
| - echo "The program \`$prog' needed by $CMDNAME could not be found. It was" |
113 |
| - echo "expected at:" |
114 |
| - echo " $PGPATH/$prog" |
115 |
| - echo "If this is not the correct directory, please start $CMDNAME" |
116 |
| - echo "with a full search path. Otherwise make sure that the program" |
117 |
| - echo "was installed successfully." |
118 |
| - exit 1 |
119 |
| - fi |
120 |
| -done |
| 130 | + |
| 131 | +# Now we can assume that 'pg_id' belongs to the same version as the |
| 132 | +# verified 'postgres' in the same directory. |
| 133 | +if [ ! -x "$PGPATH/pg_id" ]; then |
| 134 | + echo "The program 'pg_id' is needed by $CMDNAME but was not found in" |
| 135 | + echo "the directory '$PGPATH'. Check your installation." |
| 136 | + exit 1 |
| 137 | +fi |
121 | 138 |
|
122 | 139 |
|
123 |
| -# Gotta wait for pg_id existence check above |
124 | 140 | EffectiveUser=`$PGPATH/pg_id -n -u`
|
125 | 141 | if [ -z "$EffectiveUser" ]; then
|
126 |
| - echo "Could not determine current user name. You are really hosed." |
| 142 | + echo "$CMDNAME: could not determine current user name" |
127 | 143 | exit 1
|
128 | 144 | fi
|
129 | 145 |
|
|
275 | 291 |
|
276 | 292 | if [ "$MULTIBYTE" ]
|
277 | 293 | then
|
278 |
| - MULTIBYTEID=`$PGPATH/pg_encoding $MULTIBYTE 2> /dev/null` |
| 294 | + MULTIBYTEID=`$PGPATH/pg_encoding $MULTIBYTE` |
279 | 295 | if [ "$?" -ne 0 ]
|
280 | 296 | then
|
281 | 297 | echo "$CMDNAME: pg_encoding failed"
|
|
354 | 370 | fi
|
355 | 371 | done
|
356 | 372 |
|
| 373 | +for file in "$TEMPLATE1_BKI" "$GLOBAL_BKI"; do |
| 374 | + if [ x"`sed 1q $file`" != x"# PostgreSQL $short_version" ]; then |
| 375 | + echo "The input file '$file' needed by $CMDNAME does not" |
| 376 | + echo "belong to PostgreSQL $VERSION. Check your installation or specify the" |
| 377 | + echo "correct path using the -L option." |
| 378 | + exit 1 |
| 379 | + fi |
| 380 | +done |
| 381 | + |
357 | 382 |
|
358 | 383 | trap 'echo "Caught signal." ; exit_nicely' 1 2 3 15
|
359 | 384 |
|
|
0 commit comments