drupal-setup.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!@l_bash@
  2. ##
  3. ## drupal-setup.sh -- Drupal RDBMS Setup Utility
  4. ##
  5. # command line argument sanity check
  6. if [ $# -eq 0 ]; then
  7. echo "$0:ERROR: invalid command line" 1>&2
  8. echo "$0:USAGE: $0 install [<database-directory>]" 1>&2
  9. echo "$0:USAGE: $0 uninstall" 1>&2
  10. exit 1
  11. fi
  12. # database configuration
  13. db_dir="@l_prefix@/var/drupal/db"
  14. db_type="@l_dbtype@"
  15. db_name="drupal"
  16. db_user="drupal"
  17. db_pass="drupal"
  18. # determine RDBMS-specific details
  19. if [ ".$db_type" = .mysql ]; then
  20. db_sname="mysql"
  21. db_suser=`grep "^user" @l_prefix@/etc/mysql/my.pwd |\
  22. sed -e 's;^user[^=]*= *;;' -e 's; *$;;'`
  23. db_spass=`grep "^password" @l_prefix@/etc/mysql/my.pwd |\
  24. sed -e 's;^password[^=]*= *;;' -e 's; *$;;'`
  25. elif [ ".$db_type" = .pgsql ]; then
  26. db_sname=`grep "^superuser_database" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
  27. sed -e 's;^ *superuser_database="\(.*\)".*;\1;'`
  28. db_suser=`grep "^superuser_username" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
  29. sed -e 's;^ *superuser_username="\(.*\)".*;\1;'`
  30. db_spass=`grep "^superuser_password" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
  31. sed -e 's;^ *superuser_password="\(.*\)".*;\1;'`
  32. fi
  33. # dispatch operation
  34. cmd="${1:-"install"}"
  35. shift
  36. case "$cmd" in
  37. install )
  38. # create the database
  39. if [ $# -gt 0 ]; then
  40. db_dir="$1"
  41. shift
  42. fi
  43. if [ ".$db_type" = .mysql ]; then
  44. # FIXME: MySQL 5.0 still doesn't allow easy relocation of tablespaces
  45. @l_prefix@/bin/mysqladmin --user="$db_suser" --password="$db_spass" create "$db_name"
  46. ( echo "GRANT ALL PRIVILEGES ON $db_name.* TO $db_user@localhost IDENTIFIED BY '$db_pass';"
  47. echo "FLUSH PRIVILEGES;"
  48. ) | @l_prefix@/bin/mysql --user="$db_suser" --password="$db_spass" "$db_sname"
  49. elif [ ".$db_type" = .pgsql ]; then
  50. ( echo "CREATE ROLE $db_user LOGIN ENCRYPTED PASSWORD '$db_pass' NOCREATEDB NOCREATEUSER;"
  51. echo "CREATE TABLESPACE $db_name OWNER $db_user LOCATION '$db_dir';"
  52. echo "CREATE DATABASE $db_name OWNER $db_user TABLESPACE $db_name ENCODING 'UTF8';"
  53. ) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
  54. fi
  55. # activate configuration directory
  56. # (is automatically deactivated by installer afterwards)
  57. chmod 777 @l_prefix@/share/drupal/sites/default
  58. ;;
  59. uninstall )
  60. # remove the database
  61. if [ ".$db_type" = .mysql ]; then
  62. ( echo "DROP DATABASE $db_name;"
  63. ) | @l_prefix@/bin/mysql --user="$db_suser" --password="$db_spass" "$db_sname"
  64. elif [ ".$db_type" = .pgsql ]; then
  65. ( echo "DROP DATABASE $db_name;"
  66. echo "DROP TABLESPACE $db_name;"
  67. echo "DROP ROLE $db_user;"
  68. ) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
  69. fi
  70. # remove the generated configuration
  71. rm -f @l_prefix@/share/drupal/sites/default/settings.php
  72. ;;
  73. esac