head 1.15; access; symbols OPENPKG_E1_MP_HEAD:1.9 OPENPKG_E1_MP:1.9 OPENPKG_E1_MP_2_STABLE:1.8 OPENPKG_E1_FP:1.8 OPENPKG_2_STABLE_MP:1.10 OPENPKG_2_STABLE_20061018:1.8 OPENPKG_2_STABLE_20060622:1.8 OPENPKG_2_STABLE:1.8.0.2 OPENPKG_2_STABLE_BP:1.8 OPENPKG_2_5_RELEASE:1.7 OPENPKG_2_5_SOLID:1.7.0.4 OPENPKG_2_5_SOLID_BP:1.7 OPENPKG_2_4_RELEASE:1.7 OPENPKG_2_4_SOLID:1.7.0.2 OPENPKG_2_4_SOLID_BP:1.7 OPENPKG_CW_FP:1.6 OPENPKG_2_3_RELEASE:1.6 OPENPKG_2_3_SOLID:1.6.0.2 OPENPKG_2_3_SOLID_BP:1.6 OPENPKG_2_2_RELEASE:1.5 OPENPKG_2_2_SOLID:1.5.0.6 OPENPKG_2_2_SOLID_BP:1.5 OPENPKG_2_1_RELEASE:1.5 OPENPKG_2_1_SOLID:1.5.0.4 OPENPKG_2_1_SOLID_BP:1.5 OPENPKG_2_0_RELEASE:1.5 OPENPKG_2_0_SOLID:1.5.0.2 OPENPKG_2_0_SOLID_BP:1.5 OPENPKG_1_3_RELEASE:1.2.2.2 OPENPKG_1_3_SOLID:1.2.2.2.0.2 OPENPKG_1_3_SOLID_BP:1.2.2.2 OPENPKG_1_STABLE_MP:1.4 OPENPKG_1_2_RELEASE:1.2 OPENPKG_1_2_SOLID:1.2.0.4 OPENPKG_1_2_SOLID_BP:1.2 OPENPKG_1_STABLE:1.2.0.2 OPENPKG_1_STABLE_BP:1.2; locks; strict; comment @# @; 1.15 date 2009.07.13.20.14.52; author rse; state Exp; branches; next 1.14; commitid yc2X4AheweRhDAVt; 1.14 date 2009.07.13.20.07.24; author rse; state Exp; branches; next 1.13; commitid FQ7Zki0zFv4JAAVt; 1.13 date 2009.07.13.20.04.33; author rse; state Exp; branches; next 1.12; commitid Z5JdupeoJriKzAVt; 1.12 date 2007.09.06.09.25.38; author rse; state Exp; branches; next 1.11; commitid tJBBgJXjswHKLEws; 1.11 date 2007.04.18.21.46.19; author thl; state Exp; branches; next 1.10; commitid WyQKNMwmoITBoBes; 1.10 date 2007.01.06.21.00.19; author rse; state Exp; branches; next 1.9; commitid mhYtR7Z2GOMlqu1s; 1.9 date 2007.01.01.17.41.10; author rse; state Exp; branches; next 1.8; commitid BicZD6VUl7GuqP0s; 1.8 date 2006.01.01.13.20.49; author rse; state Exp; branches 1.8.2.1; next 1.7; commitid otZG8yKMCw1JFTfr; 1.7 date 2005.03.24.11.20.05; author rse; state Exp; branches; next 1.6; 1.6 date 2005.01.21.07.52.34; author rse; state Exp; branches; next 1.5; 1.5 date 2003.11.17.09.06.58; author rse; state Exp; branches; next 1.4; 1.4 date 2003.07.15.10.08.30; author rse; state Exp; branches; next 1.3; 1.3 date 2003.02.05.15.52.53; author rse; state Exp; branches; next 1.2; 1.2 date 2002.12.30.22.06.16; author rse; state Exp; branches 1.2.2.1 1.2.4.1; next 1.1; 1.1 date 2002.12.03.12.10.43; author rse; state Exp; branches; next ; 1.8.2.1 date 2007.02.06.08.43.32; author rse; state Exp; branches; next ; commitid PFqVZq8HqyoOlp5s; 1.2.2.1 date 2003.02.16.09.18.15; author rse; state Exp; branches; next 1.2.2.2; 1.2.2.2 date 2003.07.24.20.45.06; author rse; state Exp; branches; next ; 1.2.4.1 date 2003.02.16.09.18.29; author rse; state Exp; branches; next ; desc @@ 1.15 log @fix pg_migrate once again @ text @#!/bin/sh ## ## pg_migrate -- PostgreSQL Database Migration Utility ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. ## Copyright (c) 2000-2007 Ralf S. Engelschall ## ## Permission to use, copy, modify, and distribute this software for ## any purpose with or without fee is hereby granted, provided that ## the above copyright notice and this permission notice appear in all ## copies. ## ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. ## # configuration l_prefix="@@l_prefix@@" l_rusr="@@l_rusr@@" l_rgrp="@@l_rgrp@@" # load superuser information l_pgdata="" l_pguser="" l_pgpass="" if [ ! -r $l_prefix/var/postgresql/db/pg_superuser.conf ]; then echo "$0:ERROR: unable to read file \"$l_prefix/var/postgresql/db/pg_superuser.conf\" (use pg_passwd(1) to create)" 1>&2 exit 1 fi eval `. $l_prefix/var/postgresql/db/pg_superuser.conf; \ echo l_pgdata=\"$superuser_database\"; \ echo l_pguser=\"$superuser_username\"; \ echo l_pgpass=\"$superuser_password\"` # establish sane environment LC_CTYPE=C export LC_CTYPE umask 022 # check command line if [ $# -ne 1 -a $# -ne 2 ]; then echo "$0:ERROR: invalid command line" 1>&2 echo "$0:USAGE: $0 dump|restore []" 1>&2 exit 1 fi cmd="$1"; shift if [ $# -eq 1 ]; then l_pgpass="$1"; shift fi # dispatch into commands case $cmd in dump ) echo "++ enforcing full-superuser access policy" cp -p $l_prefix/var/postgresql/db/pg_hba.conf \ $l_prefix/var/postgresql/db/pg_hba.conf.orig ( echo "local all all trust" echo "host all all 127.0.0.1/32 trust" ) >$l_prefix/var/postgresql/db/pg_hba.conf ( eval `${l_prefix}/bin/openpkg rc postgresql status 2>/dev/null` echo "postgresql_active=\"$postgresql_active\"" ) 2>/dev/null if [ ".$postgresql_active" = .yes ]; then echo "++ reloading already running database engine" $l_prefix/bin/openpkg rc postgresql reload sleep 2 epilog=reload else echo "++ temporarily starting database engine" $l_prefix/bin/openpkg rc postgresql start sleep 4 epilog=stop fi echo "++ rotating dump files $l_prefix/var/postgresql/db.dump*.sql.bz2" i=9 rm -f $l_prefix/var/postgresql/db.dump.$i.sql.bz2 >/dev/null 2>&1 || true while [ $i -gt 0 ]; do j=$i i=`expr $i - 1` if [ $i -eq 0 ]; then prev="$l_prefix/var/postgresql/db.dump.sql.bz2" next="$l_prefix/var/postgresql/db.dump.$j.sql.bz2" else prev="$l_prefix/var/postgresql/db.dump.$i.sql.bz2" next="$l_prefix/var/postgresql/db.dump.$j.sql.bz2" fi if [ -f $prev ]; then mv $prev $next fi done echo "++ dumping all databases into $l_prefix/var/postgresql/db.dump.sql.bz2" PGPASSWORD="$l_pgpass" \ $l_prefix/bin/pg_dumpall \ -U "$l_pguser" -o |\ $l_prefix/lib/openpkg/bzip2 -9 \ >$l_prefix/var/postgresql/db.dump.sql.bz2 chown ${l_rusr}:${l_rgrp} $l_prefix/var/postgresql/db.dump.sql.bz2 chmod 700 $l_prefix/var/postgresql/db.dump.sql.bz2 echo "++ restoring original access policy" cp -p $l_prefix/var/postgresql/db/pg_hba.conf.orig \ $l_prefix/var/postgresql/db/pg_hba.conf rm -f $l_prefix/var/postgresql/db/pg_hba.conf.orig if [ ".$epilog" = .reload ]; then echo "++ reloading already running database engine (again)" $l_prefix/bin/openpkg rc postgresql reload sleep 2 else echo "++ stopping temporarily started database engine" $l_prefix/bin/openpkg rc postgresql stop sleep 4 fi ;; restore ) if [ ".`$l_prefix/bin/openpkg rc postgresql status 2>&1 | grep 'is running'`" != . ]; then echo "++ stopping already running database engine" $l_prefix/bin/openpkg rc postgresql stop sleep 2 epilog=start else epilog=none fi echo "++ rotating database directories $l_prefix/var/postgresql/db.old*/" i=9 rm -rf $l_prefix/var/postgresql/db.old.$i >/dev/null 2>&1 || true while [ $i -gt 0 ]; do j=$i i=`expr $i - 1` if [ $i -eq 0 ]; then prev="$l_prefix/var/postgresql/db" next="$l_prefix/var/postgresql/db.old.$j" else prev="$l_prefix/var/postgresql/db.old.$i" next="$l_prefix/var/postgresql/db.old.$j" fi if [ -d $prev ]; then mv $prev $next fi done echo "++ creating new database directory $l_prefix/var/postgresql/db/" mkdir $l_prefix/var/postgresql/db chown ${l_rusr}:${l_rgrp} $l_prefix/var/postgresql/db chmod 700 $l_prefix/var/postgresql/db su - ${l_rusr} -c \ "LC_CTYPE=C; export LC_CTYPE; umask 022; \ echo $l_pgpass >$l_prefix/var/postgresql/run/pw; \ $l_prefix/bin/pg_initdb \ -U $l_pguser --pwfile=$l_prefix/var/postgresql/run/pw \ -D $l_prefix/var/postgresql/db; \ rm -f $l_prefix/var/postgresql/run/pw" 2>&1 |\ $l_prefix/lib/openpkg/shtool prop \ -p "++ creating new database data" echo "++ restoring database configurations" for conf in pg_hba.conf pg_ident.conf postgresql.conf; do cp -p $l_prefix/var/postgresql/db.old.1/$conf \ $l_prefix/var/postgresql/db/ done echo "++ enforcing full-superuser access policy" cp -p $l_prefix/var/postgresql/db/pg_hba.conf \ $l_prefix/var/postgresql/db/pg_hba.conf.orig ( echo "local all all trust" echo "host all all 127.0.0.1/32 trust" ) >$l_prefix/var/postgresql/db/pg_hba.conf if [ ".$epilog" = .start ]; then echo "++ starting database engine" else echo "++ temporarily starting database engine" fi $l_prefix/bin/openpkg rc postgresql start sleep 4 echo "++ restoring all databases from $l_prefix/var/postgresql/db.dump.sql.bz2" $l_prefix/lib/openpkg/bzip2 -c -d \ $l_prefix/var/postgresql/db.dump.sql.bz2 |\ $l_prefix/bin/psql -U "$l_pguser" -d "$l_pgdata" 2>&1 |\ tee $l_prefix/var/postgresql/db.log |\ $l_prefix/lib/openpkg/shtool prop \ -p "++ restoring data (see $l_prefix/var/postgresql/db.log)" echo "++ restoring original access policy" cp -p $l_prefix/var/postgresql/db/pg_hba.conf.orig \ $l_prefix/var/postgresql/db/pg_hba.conf rm -f $l_prefix/var/postgresql/db/pg_hba.conf.orig if [ ".$epilog" = .start ]; then echo "++ reloading already running database engine" $l_prefix/bin/openpkg rc postgresql reload sleep 2 else echo "++ stopping temporarily started database engine" $l_prefix/bin/openpkg rc postgresql stop sleep 4 fi ;; * ) echo "$0:ERROR: unknown command \"$cmd\"" 1>&2 exit 1 ;; esac @ 1.14 log @fix paths @ text @d66 2 a67 2 ( echo "local all trust" echo "host all 127.0.0.1 255.255.255.255 trust" d180 2 a181 2 ( echo "local all trust" echo "host all 127.0.0.1 255.255.255.255 trust" @ 1.13 log @improve pg_migrate script @ text @d35 2 a36 2 if [ ! -r $l_prefix/var/db/postgresql/pg_superuser.conf ]; then echo "$0:ERROR: unable to read file \"$l_prefix/var/db/postgresql/pg_superuser.conf\" (use pg_passwd(1) to create)" 1>&2 d39 1 a39 1 eval `. $l_prefix/var/db/postgresql/pg_superuser.conf; \ @ 1.12 log @improve PostgreSQL packaging: 1. replace pg_hba.conf hacks with pg_initdb options; 2. enforce the default SQL_ASCII encoding C locale for template0/template1; 3. introduce pg_superuser.conf where the superuser credentials are stored (important for other packages who have to create databases -- also similar to what we are doing for MySQL, btw); 4. provide a convenience utility pg_passwd for changing the PostgreSQL account password (which especially is aware of the superuser and automatically maintains the pg_superuser.conf for it, too); 5. some some cosmetics to the packaging @ text @d35 3 a37 5 if [ -r @@l_prefix@@/var/db/postgresql/pg_superuser.conf ]; then eval `. @@l_prefix@@/var/db/postgresql/pg_superuser.conf; \ echo l_pgdata=\"$superuser_database\"; \ echo l_pguser=\"$superuser_username\"; \ echo l_pgpass=\"$superuser_password\"` d39 4 d70 4 a73 1 if [ ".`$l_prefix/bin/openpkg rc postgresql status 2>&1 | grep 'is running'`" != . ]; then d106 1 a106 1 -U $l_pguser -o |\ d195 1 a195 1 $l_prefix/bin/psql -U $l_pguser -d $l_pgdata 2>&1 |\ @ 1.11 log @get rid of direct /etc/rc call and replace them with openpkg @ text @d30 11 a40 2 l_pguser="@@l_pguser@@" l_pgpass="@@l_pgpass@@" d190 1 a190 1 $l_prefix/bin/psql -U $l_pguser -d template1 2>&1 |\ @ 1.10 log @allow one to pass a non-standard superuser password @ text @d59 1 a59 1 if [ ".`$l_prefix/etc/rc postgresql status 2>&1 | grep 'is running'`" != . ]; then d61 1 a61 1 $l_prefix/etc/rc postgresql reload d66 1 a66 1 $l_prefix/etc/rc postgresql start d105 1 a105 1 $l_prefix/etc/rc postgresql reload d109 1 a109 1 $l_prefix/etc/rc postgresql stop d115 1 a115 1 if [ ".`$l_prefix/etc/rc postgresql status 2>&1 | grep 'is running'`" != . ]; then d117 1 a117 1 $l_prefix/etc/rc postgresql stop d175 1 a175 1 $l_prefix/etc/rc postgresql start d193 1 a193 1 $l_prefix/etc/rc postgresql reload d197 1 a197 1 $l_prefix/etc/rc postgresql stop @ 1.9 log @Welcome Year 2007! @ text @d39 1 a39 1 if [ $# -ne 1 ]; then d41 1 a41 1 echo "$0:USAGE: $0 dump|restore" 1>&2 d44 4 a49 2 cmd="$1" shift @ 1.8 log @adjust copyrights for new year 2006 @ text @d4 2 a5 2 ## Copyright (c) 2000-2006 OpenPKG Foundation e.V. ## Copyright (c) 2000-2006 Ralf S. Engelschall @ 1.8.2.1 log @MFC security fixed version from CURRENT @ text @d4 2 a5 2 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. ## Copyright (c) 2000-2007 Ralf S. Engelschall d39 1 a39 1 if [ $# -ne 1 -a $# -ne 2 ]; then d41 1 a41 1 echo "$0:USAGE: $0 dump|restore []" 1>&2 a43 4 cmd="$1"; shift if [ $# -eq 1 ]; then l_pgpass="$1"; shift fi d46 2 @ 1.7 log @Adjust the copyright declaration in this (RSE's) copy of the OpenPKG source code now that the fork point for C&W was established (CVS tag OPENPKG_CW_FP), the shared copyright agreement between RSE and C&W is no longer active (as C&W no longer officially sponsors OpenPKG) and the new shared copyright from RSE can be taken over by the newly established juristic entity OpenPKG Foundation e.V. (instead of the non-juristic entity OpenPKG Project). @ text @d4 2 a5 2 ## Copyright (c) 2000-2005 OpenPKG Foundation e.V. ## Copyright (c) 2000-2005 Ralf S. Engelschall @ 1.6 log @finally get the dump/restore and initdb steps right under PostgreSQL 8.0 @ text @d4 2 a5 3 ## Copyright (c) 2000-2003 The OpenPKG Project ## Copyright (c) 2000-2003 Ralf S. Engelschall ## Copyright (c) 2000-2003 Cable & Wireless @ 1.5 log @fix pg_migrate and for those running 7.3 (with the broken pg_migrate) tell them how to dump and restore manually @ text @d148 7 a154 4 (echo $l_pguser; echo $l_pgpass) |\ $l_prefix/bin/pg_initdb -U $l_pguser -W -D $l_prefix/var/postgresql/db" 2>&1 |\ $l_prefix/lib/openpkg/shtool prop \ -p "++ creating new database data" @ 1.4 log @adjust some remaining copyright messages @ text @d39 8 d89 1 d91 1 a91 1 -U $l_pguser -S$l_pgpass -o -Xuse-set-session-authorization |\ d196 4 @ 1.3 log @be brain-dead enough and add full compatibility option @ text @a3 1 ## Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH d6 1 @ 1.2 log @bump of Copyright messages for forthcoming years 2003 @ text @d31 2 d82 1 a82 1 -U postgresql -Spostgresql -o -Xuse-set-session-authorization |\ d139 2 a140 2 (echo 'postgresql'; echo 'postgresql') |\ $l_prefix/bin/pg_initdb -U postgresql -W -D $l_prefix/var/postgresql/db" 2>&1 |\ d168 1 a168 1 $l_prefix/bin/psql -U postgresql -d template1 2>&1 |\ @ 1.2.4.1 log @MFS: mass merge all packaging fixes @ text @a30 2 l_pguser="@@l_pguser@@" l_pgpass="@@l_pgpass@@" d80 1 a80 1 -U $l_pguser -S$l_pgpass -o -Xuse-set-session-authorization |\ d137 2 a138 2 (echo $l_pguser; echo $l_pgpass) |\ $l_prefix/bin/pg_initdb -U $l_pguser -W -D $l_prefix/var/postgresql/db" 2>&1 |\ d166 1 a166 1 $l_prefix/bin/psql -U $l_pguser -d template1 2>&1 |\ @ 1.2.2.1 log @MFC: mass merge all packaging fixes @ text @a30 2 l_pguser="@@l_pguser@@" l_pgpass="@@l_pgpass@@" d80 1 a80 1 -U $l_pguser -S$l_pgpass -o -Xuse-set-session-authorization |\ d137 2 a138 2 (echo $l_pguser; echo $l_pgpass) |\ $l_prefix/bin/pg_initdb -U $l_pguser -W -D $l_prefix/var/postgresql/db" 2>&1 |\ d166 1 a166 1 $l_prefix/bin/psql -U $l_pguser -d template1 2>&1 |\ @ 1.2.2.2 log @mass Merge-From-CURRENT (MFC) in preparation for OpenPKG 1.3 [class BASE only] @ text @d4 1 a6 1 ## Copyright (c) 2000-2003 Cable & Wireless @ 1.1 log @add optional migration support; add engine stop/start support on upgrades @ text @d4 3 a6 3 ## Copyright (c) 2000-2002 Cable & Wireless Deutschland GmbH ## Copyright (c) 2000-2002 The OpenPKG Project ## Copyright (c) 2000-2002 Ralf S. Engelschall @