You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
3.1 KiB

#!@l_bash@
##
## drupal-setup.sh -- Drupal RDBMS Setup Utility
##
# command line argument sanity check
if [ $# -eq 0 ]; then
echo "$0:ERROR: invalid command line" 1>&2
echo "$0:USAGE: $0 install [<database-directory>]" 1>&2
echo "$0:USAGE: $0 uninstall" 1>&2
exit 1
fi
# database configuration
db_dir="@l_prefix@/var/drupal/db"
db_type="@l_dbtype@"
db_name="drupal"
db_user="drupal"
db_pass="drupal"
# determine RDBMS-specific details
if [ ".$db_type" = .mysql ]; then
db_sname="mysql"
db_suser=`grep "^user" @l_prefix@/etc/mysql/my.pwd |\
sed -e 's;^user[^=]*= *;;' -e 's; *$;;'`
db_spass=`grep "^password" @l_prefix@/etc/mysql/my.pwd |\
sed -e 's;^password[^=]*= *;;' -e 's; *$;;'`
elif [ ".$db_type" = .pgsql ]; then
db_sname=`grep "^superuser_database" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
sed -e 's;^ *superuser_database="\(.*\)".*;\1;'`
db_suser=`grep "^superuser_username" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
sed -e 's;^ *superuser_username="\(.*\)".*;\1;'`
db_spass=`grep "^superuser_password" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
sed -e 's;^ *superuser_password="\(.*\)".*;\1;'`
fi
# dispatch operation
cmd="${1:-"install"}"
shift
case "$cmd" in
install )
# create the database
if [ $# -gt 0 ]; then
db_dir="$1"
shift
fi
if [ ".$db_type" = .mysql ]; then
# FIXME: MySQL 5.0 still doesn't allow easy relocation of tablespaces
@l_prefix@/bin/mysqladmin --user="$db_suser" --password="$db_spass" create "$db_name"
( echo "GRANT ALL PRIVILEGES ON $db_name.* TO $db_user@localhost IDENTIFIED BY '$db_pass';"
echo "FLUSH PRIVILEGES;"
) | @l_prefix@/bin/mysql --user="$db_suser" --password="$db_spass" "$db_sname"
elif [ ".$db_type" = .pgsql ]; then
( echo "CREATE ROLE $db_user LOGIN ENCRYPTED PASSWORD '$db_pass' NOCREATEDB NOCREATEUSER;"
echo "CREATE TABLESPACE $db_name OWNER $db_user LOCATION '$db_dir';"
echo "CREATE DATABASE $db_name OWNER $db_user TABLESPACE $db_name ENCODING 'UTF8';"
) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
fi
# activate configuration directory
# (is automatically deactivated by installer afterwards)
chmod 777 @l_prefix@/share/drupal/sites/default
;;
uninstall )
# remove the database
if [ ".$db_type" = .mysql ]; then
( echo "DROP DATABASE $db_name;"
) | @l_prefix@/bin/mysql --user="$db_suser" --password="$db_spass" "$db_sname"
elif [ ".$db_type" = .pgsql ]; then
( echo "DROP DATABASE $db_name;"
echo "DROP TABLESPACE $db_name;"
echo "DROP ROLE $db_user;"
) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
fi
# remove the generated configuration
rm -f @l_prefix@/share/drupal/sites/default/settings.php
;;
esac