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