Merge tag 'v0.1.2' into debian/master
authorAntonio Ospite <ao2@ao2.it>
Mon, 27 Aug 2018 16:12:34 +0000 (18:12 +0200)
committerAntonio Ospite <ao2@ao2.it>
Mon, 27 Aug 2018 16:12:34 +0000 (18:12 +0200)
Release v0.1.2

Makefile
NEWS
drin.rst
libexec/bootstrap.sh
libexec/clean.sh
libexec/create-profile.sh
libexec/new.sh

index 49a32a6..67c8d6f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ LIBEXEC_DIR ?= $(prefix)/share/drin/libexec
 BIN_DIR := $(prefix)/bin
 MAN_DIR := $(prefix)/share/man
 
-.PHONY: all local installdocs install clean
+.PHONY: all local docs installdocs install clean
 
 all: drin
 
@@ -18,7 +18,9 @@ local: LIBEXEC_DIR := $(PWD)/libexec
 local: clean drin
        touch drin.in
 
-installdocs: drin.1
+docs: drin.1
+
+installdocs: docs
        install -d $(DESTDIR)$(MAN_DIR)/man1
        install -m644 drin.1 $(DESTDIR)$(MAN_DIR)/man1
 
diff --git a/NEWS b/NEWS
index 51f374b..2cabc43 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+News for v0.1.2:
+================
+
+  * Fix a problem with drush and base_path()
+    https://github.com/drush-ops/drush/issues/3463
+  * Improve creating a profile from an existing installation
+  * Update code to work with Drush 9
+  * Support both password and unix_socket access to the database
+  * Add a "docs" target tot he Makefile
+  * Misc documentation fixes
+
 News for v0.1.1:
 ================
 
index 9d4ba31..b2effe9 100644 (file)
--- a/drin.rst
+++ b/drin.rst
@@ -22,12 +22,14 @@ DESCRIPTION
 
 Helper commands to create and install new Drupal projects.
 
-When setting up a new Drupal project with drupal-composer/drupal-project drush
-and drupal-console are not available yet and some repetitive tasks can use
-a nicer command line interface.
+One problem with setting up a new Drupal project with
+drupal-composer/drupal-project is that drush and drupal-console are not
+available until the site dependencies have been downloaded, drupal-init-tools
+helps to solve this and also adds a nicer command line interface to some
+repetitive tasks.
 
-These scripts are especially useful when setting up projects in user web
-directories[1].
+drupal-init-tools commands are especially useful when setting up projects in
+user web directories[1].
 
 [1] http://httpd.apache.org/docs/current/howto/public_html.html
 
@@ -84,6 +86,99 @@ Clean and rebuild the whole project to verify that installing from scratch works
   drin clean
   drin bootstrap
 
+NOTES ON DATABASE SETUP
+=======================
+
+The `bootstrap` command in `drupal-init-tools` uses `drush` for the site
+installation, and `drush` requires MySQL super-user access to create new MySQL
+users and databases.
+
+On some Linux distributions, like Debian, the MariaDB server is configured by
+default to only allow access to the `root` user via the `unix_socket` plugin,
+making it unusable by `drush`. In these cases it's recommended to create e new
+MySQL super-user.
+
+For password-less access create a MySQL admin user correspondent to the system
+user which will execute `drush` (e.g. the current user):
+
+::
+
+  sudo /usr/bin/mysql -e "GRANT ALL ON *.* TO '$USER'@'localhost' IDENTIFIED VIA unix_socket WITH GRANT OPTION"
+
+
+For password regulated access create a user with a password:
+
+::
+
+  sudo /usr/bin/mysql -e "GRANT ALL ON *.* TO 'USERNAME'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION"
+
+
+For details see also the **PASSWORDS** section in the README.Debian file
+provided by the mariadb-server Debian package, either in
+`/usr/share/doc/mariadb-server-10.1/README.Debian.gz` or at 
+https://salsa.debian.org/mariadb-team/mariadb-10.1/blob/stretch/debian/mariadb-server-10.1.README.Debian#L73
+
+The settings in the `bootstrap.conf` file have to be adjusted according to how
+super-user access has been configured.
+
+
+NOTES ON WEB SERVER SETUP
+=========================
+
+The `bootstrap` command in  `drupal-init-tools` supports installing new sites
+in *user dirs*; this means that users can have the Drupal sites in their home
+directories, usually under the `public_html/` sub-directory.
+
+This may make development more comfortable, as new work can be done in the
+usual development environment (git and ssh configuration, editor settings,
+etc.).
+
+To configure the Apache web server to enable *user dirs*, first enable the
+module:
+
+::
+
+  sudo a2enmod userdir
+
+And then make sure that the configuration is compatible with Drupal, changes
+like the following may be necessary, depending on the distribution:
+
+::
+
+  diff --git a/apache2/mods-available/php7.2.conf b/apache2/mods-available/php7.2.conf
+  index d4df3e5..0758ea6 100644
+  --- a/apache2/mods-available/php7.2.conf
+  +++ b/apache2/mods-available/php7.2.conf
+  @@ -18,8 +18,8 @@
+   # To re-enable PHP in user directories comment the following lines
+   # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
+   # prevents .htaccess files from disabling it.
+  -<IfModule mod_userdir.c>
+  -    <Directory /home/*/public_html>
+  -        php_admin_flag engine Off
+  -    </Directory>
+  -</IfModule>
+  +#<IfModule mod_userdir.c>
+  +#    <Directory /home/*/public_html>
+  +#        php_admin_flag engine Off
+  +#    </Directory>
+  +#</IfModule>
+  diff --git a/apache2/mods-available/userdir.conf b/apache2/mods-available/userdir.conf
+  index 2c334ec..737abdf 100644
+  --- a/apache2/mods-available/userdir.conf
+  +++ b/apache2/mods-available/userdir.conf
+  @@ -3,7 +3,7 @@
+          UserDir disabled root
+
+          <Directory /home/*/public_html>
+  -            AllowOverride FileInfo AuthConfig Limit Indexes
+  +            AllowOverride FileInfo AuthConfig Limit Indexes Options
+                  Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
+                  Require method GET POST OPTIONS
+          </Directory>
+
+These changes are typically only applied once, after the first installation of
+the web server.
 
 SEE ALSO
 ========
index 4670cef..bb1968e 100755 (executable)
@@ -26,7 +26,8 @@ Bootstrap a Drupal project, using settings from a 'bootstrap.conf' file.
 
 Options:
   --devel              install drupal/devel and use a settings.local.php file
-  --overwrite-profile  allow overwriting the current installation profile
+  --overwrite-profile  allow overwriting the installation profile of the site
+                       with a profile copied from the current working directory
   -h, --help           display this usage message and exit
 
 EOF
@@ -75,12 +76,36 @@ declare -p WEB_SERVER_GROUP
 
 [ "x$INSTALLATION_PROFILE" = "x" ] && { echo "INSTALLATION_PROFILE not specified, using the \"standard\" profile!"; INSTALLATION_PROFILE="standard"; }
 
-if [ "x$MYSQL_ROOT_PASSWORD" = "x" ];
+if [ "$MYSQL_PASSWORDLESS_ACCESS" = true ];
 then
-  read -r -s -p "MySQL root password: " MYSQL_ROOT_PASSWORD
-  echo
+  MYSQL_SU_USER="${USER}"
+else
+  # XXX Deprecate MYSQL_ROOT_PASSWORD, it will be removed eventually,
+  # but for now add some backwards compatibility mapping.
+  if [ "x$MYSQL_ROOT_PASSWORD" != "x" ];
+  then
+    echo "WARN: MYSQL_ROOT_PASSWORD is deprecated, use MYSQL_SU_USER and MYSQL_SU_PASSWORD" 1>&2
+    MYSQL_SU_USER="root"
+    MYSQL_SU_PASSWORD="$MYSQL_ROOT_PASSWORD"
+  fi
+
+  if [ "x$MYSQL_SU_USER" = "x" ];
+  then
+    echo "Aborting, for password regulated access specify MYSQL_SU_USER in bootstrap.conf" 1>&2
+    exit 1
+  fi
+
+  if [ "x$MYSQL_SU_PASSWORD" = "x" ];
+  then
+    read -r -s -p "MySQL password for \"${MYSQL_SU_USER}\": " MYSQL_SU_PASSWORD
+    echo
+  fi
+
+  DRUSH_DB_SU_CREDENTIALS=(--db-su-pw'='"${MYSQL_SU_PASSWORD}")
 fi
 
+DRUSH_DB_SU_CREDENTIALS+=(--db-su'='"${MYSQL_SU_USER}")
+
 WEB_ROOT="${PWD}/web"
 
 command -v composer &> /dev/null || { echo "Aborting, 'composer' not available." 1>&2; exit 1; }
@@ -94,8 +119,8 @@ DRUPAL_CONSOLE="${PWD}/vendor/bin/drupal"
 [ -x "$DRUSH" ] || { echo "Aborting, '$DRUSH' not available." 1>&2; exit 1; }
 [ -x "$DRUPAL_CONSOLE" ] || { echo "Aborting, '$DRUPAL_CONSOLE' not available." 1>&2; exit 1; }
 
-# This becomes unnecessary if the installation profile gets pulled in by
-# composer.json, like suggested in
+# The following becomes unnecessary if the installation profile gets pulled in
+# by composer.json, like suggested in
 # https://github.com/drupal-composer/drupal-project/issues/249
 if ! echo "$INSTALLATION_PROFILE" | grep -q -E "^(minimal|standard)$";
 then
@@ -105,13 +130,31 @@ then
     echo "Use --overwrite-profile to copy over it." 1>&2
     exit 1
   else
-    cp -a "$INSTALLATION_PROFILE" "${WEB_ROOT}/profiles"
+    if [ -d "$INSTALLATION_PROFILE" ];
+    then
+      cp -a "$INSTALLATION_PROFILE" "${WEB_ROOT}/profiles"
+    else
+      echo "Local installation profile '$INSTALLATION_PROFILE' not found." 1>&2
+      echo "Cannot honour the --overwrite-profile option." 1>&2
+    fi
   fi
 fi
 
+# Make sure that drush knows what the actual base URI is, this is needed to
+# have a consistent behavior between the cli and the web interface, for
+# example in the case of modules that use base_path().
+if grep -q "^[[:space:]]*uri:" drush/drush.yml;
+then
+  sed -i -e "s@^\([[:space:]]*\)uri: .*@\1uri: 'http://localhost/${SITE_BASE_PATH}'@g" drush/drush.yml
+else
+  echo "" >> drush/drush.yml
+  echo "options:" >> drush/drush.yml
+  echo "  uri: 'http://localhost/${SITE_BASE_PATH}'" >> drush/drush.yml
+fi
+
 pushd "$WEB_ROOT"
 
-# Update the install_profile if it's already there
+# Update the install_profile setting if it's already there
 if grep -q "^\\\$settings\['install_profile'\] =" sites/default/settings.php;
 then
   chmod 755 sites/default
@@ -121,19 +164,20 @@ then
   chmod 555 sites/default
 fi
 
+# Install the site
 $DRUSH --verbose --yes \
   site-install \
-  --db-su=root \
-  --db-su-pw="$MYSQL_ROOT_PASSWORD" \
+  "${DRUSH_DB_SU_CREDENTIALS[@]}" \
   --db-url="mysql://${DB_USER}:${DB_PASS}@localhost/${DB_NAME}" \
   --site-name="$SITE_NAME" \
   --site-mail="$SITE_MAIL" \
+  --sites-subdir="default" \
   --account-name="$ACCOUNT_NAME" \
   --account-pass="$ACCOUNT_PASS" \
   --account-mail="$ACCOUNT_MAIL" \
   "$INSTALLATION_PROFILE"
 
-if $DRUSH pm-info --fields=status locale | grep -q enabled;
+if $DRUSH pm-list --type=module --field=name --status=enabled --pipe | grep -q "^locale$";
 then
   # This is necessary for multi-language sites, it fixes some issues like:
   #   "The Translation source field needs to be installed."
@@ -149,8 +193,8 @@ sudo chgrp -R "$WEB_SERVER_GROUP" sites/default/files
 
 [ -d ../config/sync ] && sudo chgrp -R "$WEB_SERVER_GROUP" ../config/sync
 
-# Enables clean URLs
-sed -i "s@# RewriteBase /drupal\$@RewriteBase ${SITE_BASE_PATH}@" .htaccess
+# Enable clean URLs
+sed -i "s@\(# \)\{0,1\}RewriteBase .*\$@RewriteBase ${SITE_BASE_PATH}@" .htaccess
 
 chmod 755 sites/default
 chmod 644 sites/default/settings.php
@@ -199,8 +243,10 @@ chmod 555 sites/default
 if [ -d core/.git ];
 then
   git -C core/ config --local alias.core-diff "diff --src-prefix=a/core/ --dst-prefix=b/core/"
-  echo "Added a 'git core-diff' to the drupal/core repository clone."
-  echo "This command helps creating core patches ready for upstream."
+  git -C core/ config --local alias.core-format-patch "format-patch --src-prefix=a/core/ --dst-prefix=b/core/"
+  echo "Added 'git core-diff' and 'git core-format-patch' commands to the drupal/core"
+  echo "repository clone. These commands help creating core patches ready for upstream"
+  echo "in a split-core setup."
 fi
 
 popd
index b1b4c16..794e221 100755 (executable)
@@ -57,4 +57,4 @@ run() {
   "$@"
 }
 
-[ "$INPUT" = "$CONFIRMATION_STRING" ] && run sudo rm -rf config/ web/ vendor/ composer.lock
+[ "$INPUT" = "$CONFIRMATION_STRING" ] && run sudo --reset-timestamp rm -rf config/ web/ vendor/ composer.lock
index fae4bcc..57e3731 100755 (executable)
@@ -64,10 +64,17 @@ DRUSH="${PROJECT_ROOT}/vendor/bin/drush"
 [ -x "$DRUSH" ] || { echo "Aborting, '$DRUSH' not available." 1>&2; exit 1; }
 [ -x "$DRUPAL_CONSOLE" ] || { echo "Aborting, '$DRUPAL_CONSOLE' not available." 1>&2; exit 1; }
 
-[ -d "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}" ] && { echo "Aborting, ${PROJECT_ROOT}/${PROFILE_MACHINE_NAME} already exists." 1>&2; exit 1; }
+PROFILE_DEST_DIR="${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}"
+
+[ -d "${PROFILE_DEST_DIR}" ] && { echo "Aborting, '${PROFILE_DEST_DIR}' already exists." 1>&2; exit 1; }
 
 pushd "$WEB_ROOT"
 
+CURRENT_PROFILE="$($DRUSH php-eval "echo drupal_get_profile();")"
+CURRENT_PROFILE_PATH="$($DRUSH php-eval "echo drupal_get_path('profile', '${CURRENT_PROFILE}');")"
+
+[ -d "$CURRENT_PROFILE_PATH" ] || { echo "Aborting, the current profile path is not valid." 1>&2; exit 1; }
+
 # The list of modules and themes could also be obtained by exporting the
 # configuration first and then looking at: config/install/core.extension.yml
 # like this:
@@ -76,13 +83,13 @@ pushd "$WEB_ROOT"
 #
 # or
 #
-#  $DRUPAL_CONSOLE yaml:get:value "$PWD/$PROFILE_MACHINE_NAME/config/install/core.extension.yml" dependencies
+#  $DRUPAL_CONSOLE yaml:get:value "${PROFILE_DEST_DIR}/config/install/core.extension.yml" dependencies
 #
 # However getting them before exporting the configuration and generating the
 # profile is cleaner.
 #
-ENABLED_MODULES="$($DRUSH pm-list --type=module --status=enabled --pipe | tr '\n' ',')"
-ENABLED_THEMES="$($DRUSH pm-list --type=theme --status=enabled --pipe | tr '\n' ',')"
+ENABLED_MODULES="$($DRUSH pm-list --type=module --field=name --status=enabled --pipe | tr '\n' ',' | sed 's/,$//')"
+ENABLED_THEMES="$($DRUSH pm-list --type=theme --field=name --status=enabled --pipe | tr '\n' ',' | sed 's/,$//')"
 
 $DRUPAL_CONSOLE generate:profile \
   --profile="$PROFILE_TITLE" \
@@ -93,23 +100,56 @@ $DRUPAL_CONSOLE generate:profile \
   --profile-path="$PROJECT_ROOT" \
   --no-interaction
 
+# Copy private code and data from the currently installed profile
+pushd "$CURRENT_PROFILE_PATH"
+
+find . -maxdepth 1 -type d ! -name "tests" -printf "%P\n" |
+  while read -r dir;
+  do
+    [ -d "$dir" ] && cp -r "$dir" "${PROFILE_DEST_DIR}/"
+  done
+
+find . -maxdepth 1 -type f ! -name "*.info.yml" -printf "%P\n" |
+  while read -r original_file;
+  do
+    DESTINATION_FILE="${PROFILE_DEST_DIR}/${original_file/#${CURRENT_PROFILE}/${PROFILE_MACHINE_NAME}}"
+    cp "${original_file}" "$DESTINATION_FILE"
+    if file "$original_file" | grep -q PHP;
+    then
+      sed -i \
+        -e "s/^function ${CURRENT_PROFILE}_/function ${PROFILE_MACHINE_NAME}_/g" \
+        -e "s/\$form\['#submit'\]\[\] = '${CURRENT_PROFILE}_/\$form\['#submit'\]\[\] = '${PROFILE_MACHINE_NAME}_/g" \
+        "$DESTINATION_FILE"
+    fi
+  done
+
+popd
+
 # Basically do what's suggested in the "Configuration" section here:
 # https://www.drupal.org/docs/8/creating-distributions/how-to-write-a-drupal-8-installation-profile
-$DRUPAL_CONSOLE config:export --directory="${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install" --remove-uuid --remove-config-hash
-rm "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install/core.extension.yml"
+$DRUPAL_CONSOLE config:export --directory="${PROFILE_DEST_DIR}/config/install" --remove-uuid --remove-config-hash
+rm "${PROFILE_DEST_DIR}/config/install/core.extension.yml"
 
 # The reference to the core version could be removed, even though it is not strictly necessary.
-find "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install" -type f -exec sed -i -e '/^_core: {  }/d' {} \;
+find "${PROFILE_DEST_DIR}/config/install" -type f -exec sed -i -e '/^_core: {  }/d' {} \;
 
 # Since the profile generated by `$DRUPAL_CONSOLE generate:profile` calls in
 # the standard profile, some duplicated config files could be removed in the
 # new profile, but that's not strictly necessary either.
-#fdupes -f -1 "${WEB_ROOT}/core/profiles/standard/config/install/" "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install/" | xargs rm
+#fdupes -f -1 "${WEB_ROOT}/core/profiles/standard/config/install/" "${PROFILE_DEST_DIR}/config/install/" | xargs rm
 
 # Export the default content if the default_content module is there
-if echo "$ENABLED_MODULES" | grep -q default_content;
+if $DRUSH pm-list --type=module --field=name --status=enabled --pipe | grep -q "^default_content$";
+then
+  $DRUSH default-content-export-references --folder="${PROFILE_DEST_DIR}/content" node
+fi
+
+# The code copied over from the current profile may refer to the old name.
+# Warn the user about that.
+if [ "$PROFILE_MACHINE_NAME" != "$CURRENT_PROFILE" ];
 then
-  $DRUSH default-content-export-references --folder="${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/content" node
+  echo "The newly created profile has a name different from the current profile."
+  echo "Check that the code of the created profile refers to the new profile name."
 fi
 
 popd
index bc88c00..890b1d0 100755 (executable)
@@ -106,10 +106,21 @@ cat > bootstrap.conf <<EOF
 #  "ip6-localhost"
 #  )
 
-#MYSQL_ROOT_PASSWORD="password"
+# See the 'drin' man page for details about database access.
+
+# Set MYSQL_PASSWORDLESS_ACCESS to 'true' if the database is configured to
+# allow administrative password-less access to the user who will execute the
+# 'drin boostrap' command.
+#MYSQL_PASSWORDLESS_ACCESS=true
+
+# If, instead,  administrative access requires a password, uncomment and
+# change the values of the following variables.
+#MYSQL_SU_USER='root'
+#MYSQL_SU_PASSWORD='password'
 EOF
 
-cat > .gitignore <<EOF
+cat >> .gitignore <<EOF
+
 # Ignore the configuration for the bootstrap script
 bootstrap.conf
 EOF