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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#!/bin/sh
set -e
# postgresql Debian package - post-installation script
#
# Put the ~/.profile in the postgres home directory
# If there is not already a database, create one
SHELL=/bin/sh
TMPFILE=`mktemp /tmp/pg.XXXXXX` || exit 1
trap "rm -f ${TMPFILE}" 0
. /etc/postgresql/postmaster.init
# If the preinst script set the flag file (that points PGDATA to
# /var/lib/postgresql/data), read it and then delete it.
if [ -f /var/postgres/dpkg-postinst-flag ]
then
. /var/postgres/dpkg-postinst-flag
rm /var/postgres/dpkg-postinst-flag
cp /etc/postgresql/postmaster.init ${TMPFILE}
sed "/^# POSTGRES_DATA=/s|^.*$|POSTGRES_DATA=${POSTGRES_DATA}|" <${TMPFILE} >/etc/postgresql/postmaster.init
> ${TMPFILE}
fi
PGDATA=${POSTGRES_DATA:=/var/postgres/data}
PGBASE=/usr/lib/postgresql
PGLIB=${PGBASE}/lib
PATH=${PATH}:${PGBASE}/bin
export PGDATA PGLIB PATH
PGHOME=${POSTGRES_HOME:=`dirname ${PGDATA}`}
if [ ! -d "${PGHOME}" -a ! -f "${PGHOME}" ]
then
echo Creating missing home directory ${PGHOME} for postgres
install -m 700 -o postgres -g postgres -d ${PGHOME}
fi
if [ ! -d "${PGHOME}" ]
then
echo Cannot create home directory ${PGHOME} for postgres
exit 1
fi
PGSHELL=`grep -s '^postgres:' /etc/passwd | awk -F: '{print $7}'`
if [ -z "${PGSHELL}" ]
then
PGSHELL=/bin/sh
fi
PGSHELL=`basename ${PGSHELL}`
case ${PGSHELL} in
bash)
PROFILE=.bash_profile
;;
sh | ksh)
PROFILE=.profile
;;
csh | tcsh)
PROFILE=.login
;;
*)
PROFILE=.profile
;;
esac
install -m 700 -o postgres -g postgres -d ${PGDATA}
grep -q -s postmaster.init ${PGHOME}/${PROFILE} ||
(echo Updating ${PGHOME}/${PROFILE} ...
echo . /etc/postgresql/postmaster.init >>${PGHOME}/${PROFILE}
if [ ${PROFILE} = .login ]
then
# C-shell syntax...
echo setenv PATH /bin:/usr/bin:${PGBASE}/bin >>${PGHOME}/${PROFILE}
echo setenv PGDATA \${POSTGRES_DATA:-/var/postgres/data} >>${PGHOME}/${PROFILE}
echo setenv PGLIB ${PGLIB} >>${PGHOME}/${PROFILE}
else
echo PATH=/bin:/usr/bin:${PGBASE}/bin >>${PGHOME}/${PROFILE}
echo PGDATA=\${POSTGRES_DATA:-/var/postgres/data} >>${PGHOME}/${PROFILE}
echo PGLIB=${PGLIB} >>${PGHOME}/${PROFILE}
echo export PGLIB PGDATA >>${PGHOME}/${PROFILE}
fi)
chown -R postgres.postgres ${PGDATA} ${PGHOME}
# Make sure we have the shared library (from libpgsql)
if [ -f /usr/lib/libpq.so.1.1 ]
then
if [ $1 = configure ]
then
ldconfig
fi
else
echo The shared library /usr/lib/libpq.so.1.1 is not present. Package
echo libpgsql must be installed before we can continue.
exit 1
fi
if [ ! -f ${PGDATA}/PG_VERSION ]
then
echo Now installing the PostgreSQL database files in ${PGDATA}
echo su - postgres -c "PATH=${PATH}:${PGBASE}/bin; initdb -l ${PGLIB} -r ${PGDATA} -u postgres"
su - postgres -c "PATH=${PATH}:${PGBASE}/bin; initdb -l ${PGLIB} -r ${PGDATA} -u postgres"
echo PostgreSQL database now installed.
echo Use /usr/bin/createdb to create a specific database and
echo /usr/bin/createuser to enable other users to connect to a
echo PostgreSQL database.
echo
echo In the first instance, these commands must be run by the
echo user \'postgres\'.
echo
fi
if [ "$1" = configure ]
then
if [ -z "$2" -o "$2" = "<unknown>" ]
then
cp /etc/postgresql/postmaster.init ${TMPFILE}
echo -n "Please choose the standard default date format for the backend to use; the
choice is European (dd-mm-yy) or American (mm-dd-yy): [E/a] "
read ans
case $ans in
A|a|American|american)
sed -e "/PGDATESTYLE/s/^.*$/PGDATESTYLE=American/" <${TMPFILE} \
>/etc/postgresql/postmaster.init
;;
*)
sed -e "/PGDATESTYLE/s/^.*$/# PGDATESTYLE=European/" <${TMPFILE} \
>/etc/postgresql/postmaster.init
;;
esac
rm ${TMPFILE}
fi
fi
# Make a symbolic link to the authorisation file
if [ ! -L ${PGDATA}/pg_hba.conf ]
then
ln -sf /etc/postgresql/pg_hba.conf ${PGDATA}/pg_hba.conf
fi
echo
echo The file /etc/postgresql/postgresql.env provides the normal set-up for
echo an ordinary user running PostgreSQL. It is automatically read by the
echo wrapper script for PostgreSQL user commands.
echo
#
# We may need to tidy up /etc/crontab from previous violations of policy
if grep -qs '^#-- postgresql begin *$' /etc/crontab
then
TMP=`mktemp /tmp/pg.XXXXXX` || exit 1
awk 'BEGIN {found=0}
/^#-- postgresql begin *$/ {found = 1}
/^#-- postgresql end *$/ {found = -1}
{if (!found) print}
{if (found == -1) found=0}
END {if (found) exit 1}' /etc/crontab >$TMP &&
if [ -f $TMP ]
then
mv $TMP /etc/crontab
fi
fi
#
# These bits would be added by debhelper if we didn't need to tweak the
# last item
if [ -x /usr/bin/update-menus ] ; then update-menus ; fi
update-rc.d postgresql defaults >/dev/null
/etc/init.d/postgresql start ||
if [ $? -ne 255 ]
then
exit $?
fi
#
|