]> gitweb.fluxo.info Git - puppet-drupal.git/commitdiff
Support for drush site-install at drupal install
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 30 Sep 2011 18:59:41 +0000 (15:59 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 30 Sep 2011 18:59:41 +0000 (15:59 -0300)
templates/drupal.sh.erb

index bb65c5cbc3f2e54e5f64f849faa27324da75b5f0..826059c2940854931e4b3caad683484bcc30fcf2 100644 (file)
@@ -7,6 +7,26 @@ SITES="<%= apache_sites_folder %>"
 BASE="<%= apache_www_folder %>"
 SERIES="5 6 7"
 
+# Read a parameter from user
+function drupal_user_input {
+  local input
+  param="$1"
+  default="$2"
+  shift 2
+
+  if echo $param | grep -q 'passwd'; then
+    read -reps "$* (defaults to $default): " input
+  else
+    read -rep "$* (defaults to $default): " input
+  fi
+
+  if [ -z "$input" ]; then
+    export $param=$default
+  else
+    export $param=$input
+  fi
+}
+
 # Get drupal major version
 function drupal_get_major {
   echo $1 | sed -e 's/\(^.\).*/\1/'
@@ -234,18 +254,19 @@ function drupal_install {
   echo "Creating $SITES/$site/drupal/ structure..."
   mkdir -p $SITES/$site/drupal/files
 
+  echo "Copying default configuration file..."
+  cp $BASE/drupal-$series/sites/default/default.settings.php $SITES/$site/drupal/settings.php
+  chmod 640 $SITES/$site/drupal/settings.php
+
   # Set files folder permission
   if grep -qe "^$site:" /etc/passwd; then
+    chown root.$site  $SITES/$site/drupal/settings.php
     chown $site.$site $SITES/$site/drupal/files
   else
+    chown root.www-data     $SITES/$site/drupal/settings.php
     chown www-data.www-data $SITES/$site/drupal/files
   fi
 
-  echo "Copying default configuration file..."
-  cp $BASE/drupal-$series/sites/default/default.settings.php $SITES/$site/drupal/settings.php
-  chown root.root $SITES/$site/drupal/settings.php
-  chmod 640 $SITES/$site/drupal/settings.php
-
   (
   echo "Creating symlinks..."
   cd $BASE/drupal-$series/sites
@@ -257,7 +278,42 @@ function drupal_install {
   done
   )
 
-  echo "Done. Now please edit settings.php, change it's permission an run drush site-install"
+  # Installation parameters
+  drupal_user_input profile     "Installation profile"  "standard"
+  drupal_user_input locale      "Installation language" "pt_BR"
+  drupal_user_input admin       "Admin user"            "$site"
+  drupal_user_input admin_email "Admin email"           "$site@`facter domain`"
+  drupal_user_input name        "Site name"             "$site"
+  drupal_user_input dbname      "Database name"         "$site"
+  drupal_user_input dbuser      "Database user"         "$site"
+  drupal_user_input dbpasswd    "Database passwd"       "$site"
+
+  echo "Configuring settings.php"
+  if [ "$series" == "7" ]; then
+    cat >> $SITES/$site/drupal/settings.php <<-EOF
+\$databases['default']['default'] = array(
+'driver'   => 'mysql',
+'database' => '$dbname',
+'username' => '$dbuser',
+'password' => '$dbpasswd',
+'host'     => 'localhost',
+'prefix'   => '',
+);
+    EOF
+  elif [ "$series" == "6" ]; then
+    cat >> $SITES/$site/drupal/settings.php <<-EOF
+\$db_url = 'mysql://$dbuser:$dbpasswd@localhost/$dbname';
+    EOF
+  fi
+
+  (
+  echo "Installing drupal $series for $site using $profile profile..."
+  cd $BASE/drupal-$series/
+  drush site-install $profile --site-name="$name" --site-email="email" --locale=$locale \
+    --uri="$site" --sites-subdir="$site" --account-name="$admin" --account-email="$admin_email"
+  )
+
+  echo "Done. Please check your installation."
 }
 
 # Main procedure