|
26 | 26 | #
|
27 | 27 | #
|
28 | 28 | # IDENTIFICATION
|
29 |
| -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.66 1999/12/17 01:05:30 momjian Exp $ |
| 29 | +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.67 1999/12/17 01:16:03 momjian Exp $ |
30 | 30 | #
|
31 | 31 | #-------------------------------------------------------------------------
|
32 | 32 |
|
|
152 | 152 | exit 100
|
153 | 153 | fi
|
154 | 154 | ;;
|
155 |
| - --help) |
156 |
| - usage=t |
157 |
| - ;; |
158 |
| - -\?) |
159 |
| - usage=t |
160 |
| - ;; |
161 | 155 | *)
|
162 |
| - echo "Unrecognized option '$1'. Try -? for help." |
163 |
| - exit 100 |
| 156 | + echo "Unrecognized option '$1'. Syntax is:" |
| 157 | + if [ -z "$MULTIBYTE" ];then |
| 158 | + echo "initdb [-t | --template] [-d | --debug]" \ |
| 159 | + "[-n | --noclean]" \ |
| 160 | + "[-u SUPERUSER | --username=SUPERUSER]" \ |
| 161 | + "[-r DATADIR | --pgdata=DATADIR]" \ |
| 162 | + "[-l LIBDIR | --pglib=LIBDIR]" |
| 163 | + else |
| 164 | + echo "initdb [-t | --template] [-d | --debug]" \ |
| 165 | + "[-n | --noclean]" \ |
| 166 | + "[-u SUPERUSER | --username=SUPERUSER]" \ |
| 167 | + "[-r DATADIR | --pgdata=DATADIR]" \ |
| 168 | + "[-l LIBDIR | --pglib=LIBDIR]" \ |
| 169 | + "[-e ENCODING | --pgencoding=ENCODING]" |
| 170 | + fi |
| 171 | + exit 100 |
164 | 172 | esac
|
165 | 173 | shift
|
166 | 174 | done
|
167 | 175 |
|
168 |
| -if [ "$usage" ]; then |
169 |
| - echo "" |
170 |
| - echo "Usage: $CMDNAME [options]" |
171 |
| - echo "" |
172 |
| - echo " -t, --template " |
173 |
| - echo " -d, --debug " |
174 |
| - echo " -n, --noclean " |
175 |
| - echo " -u SUPERUSER, --username=SUPERUSER " |
176 |
| - echo " -r DATADIR, --pgdata=DATADIR " |
177 |
| - echo " -l LIBDIR, --pglib=LIBDIR " |
178 |
| - |
179 |
| - if [ -n "$MULTIBYTE" ]; then |
180 |
| - echo " -e ENCODING, --pgencoding=ENCODING" |
181 |
| - fi |
182 |
| - |
183 |
| - echo " -?, --help " |
184 |
| - echo "" |
185 |
| - |
186 |
| - exit 100 |
187 |
| -fi |
188 |
| - |
189 | 176 | #-------------------------------------------------------------------------
|
190 | 177 | # Make sure he told us where to find the Postgres files.
|
191 | 178 | #-------------------------------------------------------------------------
|
@@ -282,6 +269,300 @@ echo "We are initializing the database system with username" \
|
282 | 269 | echo "This user will own all the files and must also own the server process."
|
283 | 270 | echo
|
284 | 271 |
|
| 272 | +# ----------------------------------------------------------------------- |
| 273 | +# Create the data directory if necessary |
| 274 | +- 26,318 ---- |
| 275 | +# |
| 276 | +# |
| 277 | +# IDENTIFICATION |
| 278 | +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.67 1999/12/17 01:16:03 momjian Exp $ |
| 279 | +# |
| 280 | +#------------------------------------------------------------------------- |
| 281 | + |
| 282 | +function exit_nicely () { |
| 283 | + echo |
| 284 | + echo "$CMDNAME failed." |
| 285 | + if [ $noclean -eq 0 ]; then |
| 286 | + echo "Removing $PGDATA." |
| 287 | + rm -rf $PGDATA || echo "Failed." |
| 288 | + else |
| 289 | + echo "Data directory $PGDATA will not be removed at user's request." |
| 290 | + fi |
| 291 | + exit 1 |
| 292 | +} |
| 293 | + |
| 294 | + |
| 295 | +CMDNAME=`basename $0` |
| 296 | +if [ $EUID -eq 0 ]; then |
| 297 | + echo "You cannot run $CMDNAME as root. Please log in (using, e.g., 'su')" |
| 298 | + echo "as the (unprivileged) user that will own the server process." |
| 299 | + exit 1 |
| 300 | +fi |
| 301 | + |
| 302 | +EffectiveUser=`id -n -u 2> /dev/null` || EffectiveUser=`whoami 2> /dev/null` |
| 303 | +TEMPFILE="/tmp/initdb.$$" |
| 304 | + |
| 305 | +# |
| 306 | +# Find out where we're located |
| 307 | +# |
| 308 | +if echo "$0" | grep -s '/' >& /dev/null ; then |
| 309 | + # explicit dir name given |
| 310 | + PGPATH=`echo $0 | sed 's,/[^/]*$,,'` # (dirname command is not portable) |
| 311 | +else |
| 312 | + # look for it in PATH ('which' command is not portable) |
| 313 | + for dir in `echo $PATH | sed 's/:/ /g'` ; do |
| 314 | + # empty entry in path means current dir |
| 315 | + [ -z "$dir" ] && dir='.' |
| 316 | + if [ -f "$dir/$CMDNAME" ]; then |
| 317 | + PGPATH="$dir" |
| 318 | + break |
| 319 | + fi |
| 320 | + done |
| 321 | +fi |
| 322 | + |
| 323 | +# Check if needed programs actually exist in path |
| 324 | +for prog in postgres pg_version ; do |
| 325 | + if [ ! -x "$PGPATH/$prog" ]; then |
| 326 | + echo "The program $prog needed by $CMDNAME could not be found. It was" |
| 327 | + echo "expected at:" |
| 328 | + echo " $PGPATH/$prog" |
| 329 | + echo "If this is not the correct directory, please start $CMDNAME" |
| 330 | + echo "with a full search path. Otherwise make sure that the program" |
| 331 | + echo "was installed successfully." |
| 332 | + exit 1 |
| 333 | + fi |
| 334 | +done |
| 335 | + |
| 336 | +# 0 is the default (non-)encoding |
| 337 | +MULTIBYTEID=0 |
| 338 | +# This is placed here by configure --with-mb=XXX. |
| 339 | +MULTIBYTE=__MULTIBYTE__ |
| 340 | + |
| 341 | +# Set defaults: |
| 342 | +debug=0 |
| 343 | +noclean=0 |
| 344 | +template_only=0 |
| 345 | + |
| 346 | + |
| 347 | +# Note: There is a single compelling reason that the name of the database |
| 348 | +# superuser be the same as the Unix user owning the server process: |
| 349 | +# The single user postgres backend will only connect as the database |
| 350 | +# user with the same name as the Unix user running it. That's |
| 351 | +# a security measure. It might change in the future (why?), but for |
| 352 | +# now the --username option is only a fallback if both id and whoami |
| 353 | +# fail, and in that case the argument _must_ be the name of the effective |
| 354 | +# user. |
| 355 | +POSTGRES_SUPERUSERNAME=$EffectiveUser |
| 356 | + |
| 357 | +# Note: The sysid can be freely selected. This will probably confuse matters, |
| 358 | +# but if your Unix user postgres is uid 48327 you might chose to start |
| 359 | +# at 0 (or 1) in the database. |
| 360 | +POSTGRES_SUPERUSERID=$EUID |
| 361 | + |
| 362 | +Password='_null_' |
| 363 | + |
| 364 | +while [ $# -gt 0 ] |
| 365 | +do |
| 366 | + case "$1" in |
| 367 | + --help|-\?) |
| 368 | + usage=t |
| 369 | + break |
| 370 | + ;; |
| 371 | + --debug|-d) |
| 372 | + debug=1 |
| 373 | + echo "Running with debug mode on." |
| 374 | + ;; |
| 375 | + --noclean|-n) |
| 376 | + noclean=1 |
| 377 | + echo "Running with noclean mode on. Mistakes will not be cleaned up." |
| 378 | + ;; |
| 379 | + --template|-t) |
| 380 | + template_only=1 |
| 381 | + echo "Updating template1 database only." |
| 382 | + ;; |
| 383 | +# The database superuser. See comments above. |
| 384 | + --username|-u) |
| 385 | + POSTGRES_SUPERUSERNAME="$2" |
| 386 | + shift;; |
| 387 | + --username=*) |
| 388 | + POSTGRES_SUPERUSERNAME=`echo $1 | sed 's/^--username=//'` |
| 389 | + ;; |
| 390 | + -u*) |
| 391 | + POSTGRES_SUPERUSERNAME=`echo $1 | sed 's/^-u//'` |
| 392 | + ;; |
| 393 | +# The sysid of the database superuser. See comments above. |
| 394 | + --sysid|-i) |
| 395 | + POSTGRES_SUPERUSERID="$2" |
| 396 | + shift;; |
| 397 | + --sysid=*) |
| 398 | + POSTGRES_SUPERUSERID=`echo $1 | sed 's/^--sysid=//'` |
| 399 | + ;; |
| 400 | + -i*) |
| 401 | + POSTGRES_SUPERUSERID=`echo $1 | sed 's/^-i//'` |
| 402 | + ;; |
| 403 | +# The default password of the database superuser. |
| 404 | + --password|-W) |
| 405 | + Password="$2" |
| 406 | + shift;; |
| 407 | + --password=*) |
| 408 | + Password=`echo $1 | sed 's/^--password=//'` |
| 409 | + ;; |
| 410 | + -W*) |
| 411 | + Password=`echo $1 | sed 's/^-W//'` |
| 412 | + ;; |
| 413 | +# Directory where to install the data. No default, unless the environment |
| 414 | +# variable PGDATA is set. |
| 415 | + --pgdata|-D) |
| 416 | + PGDATA="$2" |
| 417 | + shift;; |
| 418 | + --pgdata=*) |
| 419 | + PGDATA=`echo $1 | sed 's/^--pgdata=//'` |
| 420 | + ;; |
| 421 | + -D*) |
| 422 | + PGDATA=`echo $1 | sed 's/^-D//'` |
| 423 | + ;; |
| 424 | +# The directory where the database templates are stored (traditionally in |
| 425 | +# $prefix/lib). This is now autodetected for the most common layouts. |
| 426 | + --pglib|-L) |
| 427 | + PGLIB="$2" |
| 428 | + shift;; |
| 429 | + --pglib=*) |
| 430 | + PGLIB=`echo $1 | sed 's/^--pglib=//'` |
| 431 | + ;; |
| 432 | + -L*) |
| 433 | + PGLIB=`echo $1 | sed 's/^-L//'` |
| 434 | + ;; |
| 435 | +# The encoding of the template1 database. Defaults to what you chose |
| 436 | +# at configure time. (see above) |
| 437 | + --pgencoding|-e) |
| 438 | + MULTIBYTE="$2" |
| 439 | + shift;; |
| 440 | + --pgencoding=*) |
| 441 | + MULTIBYTE=`echo $1 | sed 's/^--pgencoding=//'` |
| 442 | + ;; |
| 443 | + -e*) |
| 444 | + MULTIBYTE=`echo $1 | sed 's/^-e//'` |
| 445 | + ;; |
| 446 | + *) |
| 447 | + echo "Unrecognized option '$1'. Try -? for help." |
| 448 | + exit 1 |
| 449 | + ;; |
| 450 | + esac |
| 451 | + shift |
| 452 | +done |
| 453 | + |
| 454 | + |
| 455 | +if [ "$usage" ]; then |
| 456 | + echo "$CMDNAME [-t|--template] [-d|--debug] [-n|--noclean] \\" |
| 457 | + echo " [-u|--username SUPERUSER] [-D|--pgdata DATADIR] \\" |
| 458 | + echo " [-L|--pglib=LIBDIR] [-e|--pgencoding=ENCODING]" |
| 459 | + exit 0 |
| 460 | +fi |
| 461 | + |
| 462 | + |
| 463 | +#------------------------------------------------------------------------- |
| 464 | +# Resolve the multibyte encoding name |
| 465 | +#------------------------------------------------------------------------- |
| 466 | + |
| 467 | +if [ "$MULTIBYTE" ]; then |
| 468 | + MULTIBYTEID=`$PGPATH/pg_encoding $MULTIBYTE` |
| 469 | + if [ $? -ne 0 ]; then |
| 470 | + echo "The program pg_encoding failed. Perhaps you did not configure" |
| 471 | + echo "PostgreSQL for multibyte support or the program was not success-" |
| 472 | + echo "fully installed." |
| 473 | + exit 1 |
| 474 | + fi |
| 475 | + if [ -z "$MULTIBYTEID" ]; then |
| 476 | + echo "$CMDNAME: $MULTIBYTE is not a valid encoding name." |
| 477 | + exit 1 |
| 478 | + fi |
| 479 | +fi |
| 480 | + |
| 481 | + |
| 482 | +#------------------------------------------------------------------------- |
| 483 | +# Make sure he told us where to build the database system |
| 484 | +#------------------------------------------------------------------------- |
| 485 | + |
| 486 | +if [ -z "$PGDATA" ]; then |
| 487 | + echo "$CMDNAME: You must identify where the the data for this database" |
| 488 | + echo "system will reside. Do this with either a --pgdata invocation" |
| 489 | + echo "option or a PGDATA environment variable." |
| 490 | + echo |
| 491 | + exit 1 |
| 492 | +fi |
| 493 | + |
| 494 | +# The data path must be absolute, because the backend doesn't like |
| 495 | +# '.' and '..' stuff. (Should perhaps be fixed there.) |
| 496 | + |
| 497 | +if ! echo $PGDATA | grep -s '^/' >& /dev/null ; then |
| 498 | + echo "$CMDNAME: The data path must be specified as an absolute path." |
| 499 | + exit 1 |
| 500 | +fi |
| 501 | + |
| 502 | +#--------------------------------------------------------------------------- |
| 503 | +# Figure out who the Postgres superuser for the new database system will be. |
| 504 | +#--------------------------------------------------------------------------- |
| 505 | + |
| 506 | +# This means they have neither 'id' nor 'whoami'! |
| 507 | +if [ -z "$POSTGRES_SUPERUSERNAME" ]; then |
| 508 | + echo "$CMDNAME: Could not determine what the name of the database" |
| 509 | + echo "superuser should be. Please use the --username option." |
| 510 | + exit 1 |
| 511 | +fi |
| 512 | + |
| 513 | +echo "This database system will be initialized with username \"$POSTGRES_SUPERUSERNAME\"." |
| 514 | +echo "This user will own all the data files and must also own the server process." |
| 515 | +echo |
| 516 | + |
| 517 | + |
| 518 | +#------------------------------------------------------------------------- |
| 519 | +# Find the input files |
| 520 | +#------------------------------------------------------------------------- |
| 521 | + |
| 522 | +if [ -z "$PGLIB" ]; then |
| 523 | + for dir in "$PGPATH/../lib" "$PGPATH/../lib/pgsql"; do |
| 524 | + if [ -f "$dir/global1.bki.source" ]; then |
| 525 | + PGLIB=$dir |
| 526 | + break |
| 527 | + fi |
| 528 | + done |
| 529 | +fi |
| 530 | + |
| 531 | +if [ -z "$PGLIB" ]; then |
| 532 | + echo "$CMDNAME: Could not find the \"lib\" directory, that contains" |
| 533 | + echo "the files needed by initdb. Please specify it with the" |
| 534 | + echo "--pglib option." |
| 535 | + exit 1 |
| 536 | +fi |
| 537 | + |
| 538 | + |
| 539 | +TEMPLATE=$PGLIB/local1_template1.bki.source |
| 540 | +GLOBAL=$PGLIB/global1.bki.source |
| 541 | +PG_HBA_SAMPLE=$PGLIB/pg_hba.conf.sample |
| 542 | + |
| 543 | +TEMPLATE_DESCR=$PGLIB/local1_template1.description |
| 544 | +GLOBAL_DESCR=$PGLIB/global1.description |
| 545 | +PG_GEQO_SAMPLE=$PGLIB/pg_geqo.sample |
| 546 | + |
| 547 | +for PREREQ_FILE in $TEMPLATE $GLOBAL $PG_HBA_SAMPLE; do |
| 548 | + if [ ! -f $PREREQ_FILE ]; then |
| 549 | + echo "$CMDNAME does not find the file '$PREREQ_FILE'." |
| 550 | + echo "This means you have a corrupted installation or identified the" |
| 551 | + echo "wrong directory with the --pglib invocation option." |
| 552 | + exit 1 |
| 553 | + fi |
| 554 | +done |
| 555 | + |
| 556 | +[ "$debug" -ne 0 ] && echo "$CMDNAME: Using $TEMPLATE as input to create the template database." |
| 557 | + |
| 558 | +if [ $template_only -eq 0 ]; then |
| 559 | + [ "$debug" -ne 0 ] && echo "$CMDNAME: Using $GLOBAL as input to create the global classes." |
| 560 | + [ "$debug" -ne 0 ] && echo "$CMDNAME: Using $PG_HBA_SAMPLE as default authentication control file." |
| 561 | +fi |
| 562 | + |
| 563 | +trap 'echo "Caught signal." ; exit_nicely' SIGINT SIGTERM |
| 564 | + |
| 565 | + |
285 | 566 | # -----------------------------------------------------------------------
|
286 | 567 | # Create the data directory if necessary
|
287 | 568 | # -----------------------------------------------------------------------
|
|
0 commit comments