|
|
@ -0,0 +1,175 @@ |
|
|
|
# --- ROCK-COPYRIGHT-NOTE-BEGIN --- |
|
|
|
# |
|
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch. |
|
|
|
# Please add additional copyright information _after_ the line containing |
|
|
|
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by |
|
|
|
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text! |
|
|
|
# |
|
|
|
# ROCK Linux: rock-src/package/michiel/postgresql/stone_mod_postgresql.sh |
|
|
|
# ROCK Linux is Copyright (C) 1998 - 2005 Clifford Wolf |
|
|
|
# |
|
|
|
# This program is free software; you can redistribute it and/or modify |
|
|
|
# it under the terms of the GNU General Public License as published by |
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
|
|
|
# (at your option) any later version. A copy of the GNU General Public |
|
|
|
# License can be found at Documentation/COPYING. |
|
|
|
# |
|
|
|
# Many people helped and are helping developing ROCK Linux. Please |
|
|
|
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM |
|
|
|
# file for details. |
|
|
|
# |
|
|
|
# --- ROCK-COPYRIGHT-NOTE-END --- |
|
|
|
# |
|
|
|
# [MAIN] 75 pgsql PostgreSQL Database Setup |
|
|
|
|
|
|
|
pgsql_start() { |
|
|
|
gui_cmd 'starting postgresql server' "rc postgresql start" |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_stop() { |
|
|
|
gui_cmd 'stopping postgresql server' "rc postgresql stop" |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_initdb() { |
|
|
|
export `locale` |
|
|
|
locale="" |
|
|
|
encoding="" |
|
|
|
|
|
|
|
if gui_yesno "Initialize the database with the current system locale? ($LANG)" ; then |
|
|
|
locale=$LANG |
|
|
|
else |
|
|
|
gui_input "Locale to initialize the DB with: " "$locale" "locale" |
|
|
|
fi |
|
|
|
|
|
|
|
if gui_yesno "Initialize the database with the default encoding for the locale $locale ?" ; then |
|
|
|
encoding="" |
|
|
|
else |
|
|
|
gui_input "Encoding to initialize the DB with (i.e. UNICODE): " "$encoding" "encoding" |
|
|
|
fi |
|
|
|
|
|
|
|
gui_cmd "Initializing PostgreSQL Database (locale: $locale)" \ |
|
|
|
"su postgres -c \"D_prefix/bin/initdb --locale=$locale --encoding=$encoding\"" |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_create_user() { |
|
|
|
gui_input "User to create: " "$username" "username" |
|
|
|
|
|
|
|
if ! grep "^$username:" /etc/passwd > /dev/null 2>&1 ; then |
|
|
|
gui_message "$username is not a valid system user!" ; |
|
|
|
else |
|
|
|
gui_cmd "Creating ProstgreSQL User $username" \ |
|
|
|
"su postgres -c \"D_prefix/bin/createuser $username\"" |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_user_menu() { |
|
|
|
function=$1 |
|
|
|
umenu="gui_menu pgsql_users 'Please select user:'" |
|
|
|
for uname in `su postgres -c "D_prefix/bin/psql -c '\du' template1" | tail -n+4 | head -n-2 \ |
|
|
|
| awk -F'|' '{ print $1 ; }' | tr -d ' '| grep -v postgres`; do |
|
|
|
umenu="$umenu '$uname' '$function $uname'" |
|
|
|
done; |
|
|
|
unset uname function |
|
|
|
eval $umenu |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_db_menu() { |
|
|
|
user=$1 |
|
|
|
function=$2 |
|
|
|
dmenu="gui_menu pgsql_dbs 'Please select database:'" |
|
|
|
for db in `su postgres -c "D_prefix/bin/psql -l" | tail -n+4 | head -n-2 | grep " | $user.[ ]*|" \ |
|
|
|
|awk -F'|' '{ print $1 ; }' | tr -d ' '| grep -v template` ; do |
|
|
|
dmenu="$dmenu '$db' '$function $db'" |
|
|
|
done; |
|
|
|
unset user function |
|
|
|
eval $dmenu |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_drop_user() { |
|
|
|
if [ -z "$1" ] ; then |
|
|
|
pgsql_user_menu pgsql_drop_user |
|
|
|
else |
|
|
|
uname=$1 |
|
|
|
if gui_yesno "are you sure you want to drop the user '$uname' ?" ; then |
|
|
|
gui_cmd "Dropping User $uname" "su postgres -c \"D_prefix/bin/dropuser $uname\"" |
|
|
|
else |
|
|
|
gui_message "hey, know what? i already deleted the account. just kidding ;-)" |
|
|
|
fi |
|
|
|
unset uname |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_create_db() { |
|
|
|
if [ -z "$1" -a -z "$uname" ] ; then |
|
|
|
pgsql_user_menu pgsql_create_db ; |
|
|
|
return |
|
|
|
fi |
|
|
|
[ -z "$uname" -a -n "$1" ] && uname=$1 |
|
|
|
|
|
|
|
gui_input "Name of the database to create for user $uname:" "$dbname" "dbname" |
|
|
|
|
|
|
|
[ -z "$dbname" ] && return; |
|
|
|
|
|
|
|
gui_cmd "Creating database $dbname for user $uname" \ |
|
|
|
"su $uname -c \"D_prefix/bin/createdb $dbname\"" |
|
|
|
|
|
|
|
unset dbname uname |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_drop_db() { |
|
|
|
if [ -z "$1" -a -z "$uname" ] ; then |
|
|
|
pgsql_user_menu pgsql_drop_db ; |
|
|
|
return |
|
|
|
fi |
|
|
|
[ -z "$uname" -a -n "$1" ] && uname=$1 |
|
|
|
|
|
|
|
if [ -z "$2" -a -z "$dbname" ] ; then |
|
|
|
pgsql_db_menu $uname "pgsql_drop_db $uname "; |
|
|
|
return |
|
|
|
fi |
|
|
|
[ -z "$dbname" -a -n "$2" ] && dbname=$2 |
|
|
|
|
|
|
|
[ -z "$dbname" -o -z "$uname" ] && return; |
|
|
|
|
|
|
|
if gui_yesno "Are you sure you want to drop $uname's database $dbname?" ; then |
|
|
|
gui_cmd "Dropping database $dbname for user $uname" \ |
|
|
|
"su $uname -c \"D_prefix/bin/dropdb $dbname\"" |
|
|
|
fi |
|
|
|
|
|
|
|
unset dbname uname |
|
|
|
} |
|
|
|
|
|
|
|
pgsql_gen_menu () { |
|
|
|
eval `su postgres -c "D_prefix/bin/initdb --show" 2>&1 | grep PGDATA` |
|
|
|
PGPID="`su postgres -c "D_prefix/bin/pg_ctl status" | grep -o 'PID: .[^)]*' | tr -d 'PID: '`" |
|
|
|
|
|
|
|
echo "gui_menu pgsql 'PostgresQL Database Setup'" |
|
|
|
# initialisation is needed once, so we note if it seems done |
|
|
|
echo " 'Initialize database system'" |
|
|
|
echo " 'pgsql_initdb'" |
|
|
|
if [ -f $PGDATA/postgresql.conf ] ; then |
|
|
|
echo " 'note: this seems to be done already' ''" |
|
|
|
echo " '' ''" |
|
|
|
if [ -z "$PGPID" ] ; then |
|
|
|
echo " 'note: postgres needs to be running for more options' ''" |
|
|
|
echo " '' ''" |
|
|
|
echo " 'Start PostgreSQL Server' 'pgsql_start'" |
|
|
|
else |
|
|
|
echo " 'Create a user' 'pgsql_create_user'" |
|
|
|
echo " 'Drop a user' 'pgsql_drop_user'" |
|
|
|
echo " '' ''" |
|
|
|
echo " 'Create a database' 'pgsql_create_db'" |
|
|
|
echo " 'Drop a database' 'pgsql_drop_db'" |
|
|
|
echo " '' ''" |
|
|
|
echo " 'Stop PostgreSQL Server' 'pgsql_stop'" |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
main() { |
|
|
|
|
|
|
|
while |
|
|
|
eval `pgsql_gen_menu` |
|
|
|
do : ; done |
|
|
|
} |
|
|
|
|