2626#
2727#
2828# IDENTIFICATION
29- # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.78 2000/01/13 18:22:10 petere Exp $
29+ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.79 2000/01/15 18:30:31 petere Exp $
3030#
3131# -------------------------------------------------------------------------
3232
3333exit_nicely (){
34+ sttyecho >& /dev/null
3435echo
3536echo " $CMDNAME failed."
3637if [" $noclean " -eq 0 ]; then
6061 TEMPFILE=" /tmp/initdb.$$ "
6162fi
6263
64+
65+ # Check for echo -n vs echo \c
66+ if echo ' \c' | grep -s c> /dev/null2>&1
67+ then
68+ ECHO_N=" echo -n"
69+ ECHO_C=" "
70+ else
71+ ECHO_N=" echo"
72+ ECHO_C=' \c'
73+ fi
74+
75+
6376#
6477# Find out where we're located
6578#
98111
99112# 0 is the default (non-)encoding
100113MULTIBYTEID=0
101- # This is placed here by configure --with-mb =XXX.
114+ # This is placed here by configure --enable-multibyte[ =XXX] .
102115MULTIBYTE=__MULTIBYTE__
103116
104117# Set defaults:
@@ -118,8 +131,6 @@ template_only=0
118131POSTGRES_SUPERUSERNAME=" $EffectiveUser "
119132POSTGRES_SUPERUSERID=" ` id -u2> /dev/null|| echo 0` "
120133
121- Password=' _null_'
122-
123134while [" $# " -gt 0 ]
124135do
125136case " $1 " in
160171 POSTGRES_SUPERUSERID=` echo$1 | sed' s/^-i//' `
161172 ;;
162173# The default password of the database superuser.
163- --password|-W)
164- Password=" $2 "
165- shift ;;
166- --password=* )
167- Password=` echo$1 | sed' s/^--password=//' `
168- ;;
169- -W* )
170- Password=` echo$1 | sed' s/^-W//' `
174+ # Make initdb prompt for the default password of the database superuser.
175+ --pwprompt|-W)
176+ PwPrompt=1
171177 ;;
172178# Directory where to install the data. No default, unless the environment
173179# variable PGDATA is set.
193199 ;;
194200# The encoding of the template1 database. Defaults to what you chose
195201# at configure time. (see above)
196- --pgencoding |-e)
202+ --encoding |-e)
197203 MULTIBYTE=" $2 "
198204shift ;;
199- --pgencoding =* )
200- MULTIBYTE=` echo$1 | sed' s/^--pgencoding =//' `
205+ --encoding =* )
206+ MULTIBYTE=` echo$1 | sed' s/^--encoding =//' `
201207 ;;
202208 -e* )
203209 MULTIBYTE=` echo$1 | sed' s/^-e//' `
204210 ;;
205211* )
206- echo " Unrecognized option '$1 '. Try -? for help."
207- exit 1
212+ PGDATA=$1
208213 ;;
209214esac
210215shift
211216done
212217
213- if [" $usage " ]
214- then
215- echo " "
216- echo " Usage:$CMDNAME [options]"
217- echo " "
218- echo " -t, --template"
219- echo " -d, --debug"
220- echo " -n, --noclean"
221- echo " -i SYSID, --sysid=SYSID"
222- echo " -W PASSWORD, --password=PASSWORD"
223- echo " -u SUPERUSER, --username=SUPERUSER"
224- echo " -D DATADIR, --pgdata=DATADIR"
225- echo " -L LIBDIR, --pglib=LIBDIR"
226-
218+ if [" $usage " ]; then
219+ echo " initdb initialized a PostgreSQL database."
220+ echo
221+ echo " Usage:"
222+ echo " $CMDNAME [options] datadir"
223+ echo
224+ echo " Options:"
225+ echo " [-D, --pgdata] <datadir> Location for this database"
226+ echo " -W, --pwprompt Prompt for a password for the new superuser's"
227227if [-n " $MULTIBYTE " ]
228228then
229- echo " -e ENCODING, --pgencoding=ENCODING "
229+ echo " -e, --encoding <encoding> Set the default multibyte encoding for new databases "
230230fi
231- echo " -?, --help"
232- echo " "
231+ echo " -i, --sysid <sysid> Database sysid for the superuser"
232+ echo " Less commonly used options:"
233+ echo " -L, --pglib <libdir> Where to find the input files (should happend automatically"
234+ echo " -t, --template Re-initialize template database only"
235+ echo " -d, --debug Generate lots of debugging output"
236+ echo " -n, --noclean Do not clean up after errors"
237+ echo
238+ echo " Report bugs to <bugs@postgresql.org>."
233239exit 0
234240fi
235241
239245
240246if [" $MULTIBYTE " ]
241247then
242- MULTIBYTEID=` $PGPATH /pg_encoding$MULTIBYTE `
248+ MULTIBYTEID=` $PGPATH /pg_encoding$MULTIBYTE 2> /dev/null `
243249if [" $? " -ne 0 ]
244250then
245- echo " The program pg_encoding failed. Perhaps you did not configure"
246- echo " PostgreSQL for multibyte support or the program was not success-"
247- echo " fully installed."
251+ echo " $CMDNAME : pg_encoding failed"
252+ echo
253+ echo " Perhaps you did not configure PostgreSQL for multibyte support or"
254+ echo " the program was not successfully installed."
248255exit 1
249256fi
250257if [-z " $MULTIBYTEID " ]
251258then
252- echo " $CMDNAME :$MULTIBYTE is not a valid encoding name. "
259+ echo " $CMDNAME :$MULTIBYTE is not a valid encoding name"
253260exit 1
254261fi
255262fi
273280
274281if ! echo " $PGDATA " | grep' ^/' > /dev/null2>&1
275282then
276- echo " $CMDNAME :The data path must be specified as an absolute path. "
283+ echo " $CMDNAME : data path must be specified as an absolute path"
277284exit 1
278285fi
279286
284291# This means they have neither 'id' nor 'whoami'!
285292if [-z " $POSTGRES_SUPERUSERNAME " ]
286293then
287- echo " $CMDNAME : Could not determine what the name of the database"
288- echo " superuser should be. Please use the --username option."
294+ echo " $CMDNAME : Could not the determine current username. Please use the -u option."
289295exit 1
290296fi
291297
431437 cat" $GLOBAL " \
432438| sed -e" s/POSTGRES/$POSTGRES_SUPERUSERNAME /g" \
433439 -e" s/PGUID/$POSTGRES_SUPERUSERID /g" \
434- -e" s/PASSWORD/$Password /g" \
435440| " $PGPATH " /postgres$BACKENDARGS template1 \
436441|| exit_nicely
437442
@@ -470,17 +475,35 @@ echo "CREATE TRIGGER pg_sync_pg_pwd AFTER INSERT OR UPDATE OR DELETE ON pg_shado
470475" FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd()" \
471476| " $PGPATH " /postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
472477
473- # Create the initial pg_pwd (flat-file copy of pg_shadow)
474- echo " Writing password file."
475- echo " COPY pg_shadow TO '$PGDATA /pg_pwd' USING DELIMITERS '\\ t'" \
478+ # needs to be done before alter user
479+ echo " REVOKE ALL on pg_shadow FROM public" \
476480| " $PGPATH " /postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
477481
478- # An ordinary COPY will leave the file too loosely protected.
479- # Note: If you lied above and specified a --username different from the one
480- # you really are, this will manifest itself in this command failing because
481- # of a missing file, since the COPY command above failed. It would perhaps
482- # be better if postgres returned an error code.
483- chmod go-rw" $PGDATA " /pg_pwd|| exit_nicely
482+ # set up password
483+ if [" $PwPrompt " ]; then
484+ $ECHO_N " Enter new superuser password:" $ECHO_C
485+ stty -echo>& /dev/null
486+ read FirstPw
487+ sttyecho >& /dev/null
488+ echo
489+ $ECHO_N " Enter it again:" $ECHO_C
490+ stty -echo>& /dev/null
491+ read SecondPw
492+ sttyecho >& /dev/null
493+ echo
494+ if [" $FirstPw " != " $SecondPw " ]; then
495+ echo " Passwords didn't match."
496+ exit_nicely
497+ fi
498+ echo " ALTER USER\" $POSTGRES_SUPERUSERNAME \" WITH PASSWORD '$FirstPw '" \
499+ | " $PGPATH " /postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
500+ if [! -f $PGDATA /pg_pwd ]; then
501+ echo " The password file wasn't generated. Please report this problem."
502+ exit_nicely
503+ fi
504+ echo " Setting password"
505+ fi
506+
484507
485508echo " Creating view pg_user."
486509echo " CREATE VIEW pg_user AS\
@@ -496,9 +519,6 @@ echo "CREATE VIEW pg_user AS \
496519 FROM pg_shadow" \
497520| " $PGPATH " /postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
498521
499- echo " REVOKE ALL on pg_shadow FROM public" \
500- | " $PGPATH " /postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
501-
502522echo " Creating view pg_rules."
503523echo " CREATE VIEW pg_rules AS\
504524 SELECT\
@@ -569,9 +589,9 @@ echo "VACUUM ANALYZE" \
569589
570590echo
571591echo " $CMDNAME completed successfully. You can now start the database server."
572- echo " ( $PGPATH /postmaster -D$PGDATA ) "
592+ echo " $PGPATH /postmaster -D$PGDATA "
573593echo " or"
574- echo " ( $PGPATH /pg_ctl -D$PGDATA start) "
594+ echo " $PGPATH /pg_ctl -D$PGDATA start"
575595echo
576596
577597exit 0