|
| 1 | +#!/bin/sh |
| 2 | +#------------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# initarea.sh-- |
| 5 | +# Create (initialize) a secondary Postgres database storage area. |
| 6 | +# |
| 7 | +# A database storage area contains individual Postgres databases. |
| 8 | +# |
| 9 | +# To create the database storage area, we create a root directory tree. |
| 10 | +# |
| 11 | +# Copyright (c) 1994, Regents of the University of California |
| 12 | +# |
| 13 | +# |
| 14 | +# IDENTIFICATION |
| 15 | +# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation,v 1.1 1997/11/07 06:21:38 thomas Exp $ |
| 16 | +# |
| 17 | +#------------------------------------------------------------------------- |
| 18 | + |
| 19 | +CMDNAME=`basename$0` |
| 20 | + |
| 21 | +while ["$#"-gt 0 ] |
| 22 | +do |
| 23 | +case"$1"in |
| 24 | +--location=*) PGALTDATA="`echo$1| sed's/^--pgdata=//'`"; ;; |
| 25 | +--username=*) POSTGRES_SUPERUSERNAME="`echo$1| sed's/^--username=//'`" ;; |
| 26 | + |
| 27 | +--location)shift; PGALTDATA="$1"; ;; |
| 28 | +--username)shift; POSTGRES_SUPERUSERNAME="$1"; ;; |
| 29 | + |
| 30 | +-u)shift; POSTGRES_SUPERUSERNAME="$1"; ;; |
| 31 | +-D)shift; PGALTDATA="$1"; ;; |
| 32 | +-*) badparm=$1; usage=1; ;; |
| 33 | +*) PGALTDATA="$1"; ;; |
| 34 | +esac |
| 35 | +shift |
| 36 | +done |
| 37 | + |
| 38 | +if [!-z"$badparm" ];then |
| 39 | +echo"$CMDNAME: Unrecognized parameter '$badparm'" |
| 40 | +fi |
| 41 | + |
| 42 | +if [!-z"$usage" ];then |
| 43 | +echo"Usage:$CMDNAME [-u SUPERUSER] DATADIR" |
| 44 | +exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +#------------------------------------------------------------------------- |
| 48 | +# Make sure he told us where to build the database area |
| 49 | +#------------------------------------------------------------------------- |
| 50 | + |
| 51 | +if [-z"$PGALTDATA" ];then |
| 52 | +echo"$CMDNAME: You must identify the target area, where the new data" |
| 53 | +echo"for this database system can reside. Do this with --location" |
| 54 | +exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +#--------------------------------------------------------------------------- |
| 58 | +# Figure out who the Postgres superuser for the new database system will be. |
| 59 | +#--------------------------------------------------------------------------- |
| 60 | + |
| 61 | +if [ 1-eq 0 ];then |
| 62 | +if [-z"$POSTGRES_SUPERUSERNAME" ];then |
| 63 | +$POSTGRES_SUPERUSERNAME=pg_id |
| 64 | +fi |
| 65 | + |
| 66 | +if [-z"$POSTGRES_SUPERUSERNAME" ];then |
| 67 | +echo"Can't tell what username to use. You don't have the USER" |
| 68 | +echo"environment variable set to your username and didn't specify the" |
| 69 | +echo"--username option" |
| 70 | +exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +POSTGRES_SUPERUID=`pg_id$POSTGRES_SUPERUSERNAME` |
| 74 | + |
| 75 | +if [$POSTGRES_SUPERUID= NOUSER ];then |
| 76 | +echo"Valid username not given. You must specify the username for" |
| 77 | +echo"the Postgres superuser for the database system you are" |
| 78 | +echo"initializing, either with the --username option or by default" |
| 79 | +echo"to the USER environment variable." |
| 80 | +exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +if [$POSTGRES_SUPERUID-ne`pg_id`-a`pg_id`-ne 0 ];then |
| 84 | +echo"Only the unix superuser may initialize a database with a different" |
| 85 | +echo"Postgres superuser. (You must be able to create files that belong" |
| 86 | +echo"to the specified unix user)." |
| 87 | +exit 1 |
| 88 | +fi |
| 89 | + |
| 90 | +echo"We are initializing the database area with username" \ |
| 91 | +"$POSTGRES_SUPERUSERNAME (uid=$POSTGRES_SUPERUID)." |
| 92 | +echo"This user will own all the files and must also own the server process." |
| 93 | +echo |
| 94 | +fi |
| 95 | + |
| 96 | +# ----------------------------------------------------------------------- |
| 97 | +# Create the data directory if necessary |
| 98 | +# ----------------------------------------------------------------------- |
| 99 | + |
| 100 | +# umask must disallow access to group, other for files and dirs |
| 101 | +umask 077 |
| 102 | + |
| 103 | +if [!-d$PGALTDATA ];then |
| 104 | +echo"Creating Postgres database system directory$PGALTDATA" |
| 105 | +echo |
| 106 | +mkdir$PGALTDATA |
| 107 | +if [$?-ne 0 ];thenexit 1;fi |
| 108 | +fi |
| 109 | +if [!-d$PGALTDATA/base ];then |
| 110 | +echo"Creating Postgres database system directory$PGALTDATA/base" |
| 111 | +echo |
| 112 | +mkdir$PGALTDATA/base |
| 113 | +if [$?-ne 0 ];thenexit 1;fi |
| 114 | +fi |
| 115 | + |
| 116 | +exit |