#!/bin/bash # Create a Drupal installation profile # # Copyright (C) 2017 Antonio Ospite # # 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. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . set -e usage() { cat < Create an installation profile from the installed project. Options: -h, --help display this usage message and exit EOF } while [ $# -gt 0 ]; do case "$1" in -h|--help) usage exit 0 ;; -*) echo "Error: Unknown option '${1}'" 1>&2 ;; *) break ;; esac shift done [ "x$1" = "x" -o "x$2" = "x" ] && { usage 1>&2; exit 1; } PROFILE_TITLE="$1" PROFILE_MACHINE_NAME="$2" WEB_ROOT="${PWD}/web" [ -d "$WEB_ROOT" ] || { echo "Aborting, run this command from the Drupal project directory." 1>&2; exit 1; } PROJECT_ROOT="$PWD" DRUPAL_CONSOLE="${PROJECT_ROOT}/vendor/bin/drupal" 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; } pushd "$WEB_ROOT" # 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: # # sed -e '/module:/,/^[^ ]/!d;//d' -e 's/^[ ]*\(.*\):.*$/\1/' config/install/core.extension.yml # # or # # $DRUPAL_CONSOLE yaml:get:value "$PWD/$PROFILE_MACHINE_NAME/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' ',')" rm -rf "${WEB_ROOT}/profiles/$PROFILE_MACHINE_NAME" $DRUPAL_CONSOLE generate:profile \ --profile="$PROFILE_TITLE" \ --machine-name="$PROFILE_MACHINE_NAME" \ --description="Drupal installation profile for $PROFILE_TITLE" \ --dependencies=$ENABLED_MODULES \ --themes=$ENABLED_THEMES \ --no-interaction cp -a "${WEB_ROOT}/profiles/${PROFILE_MACHINE_NAME}" "$PROJECT_ROOT" # 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" # The reference to the core version could be removed, but this is not strictly necessary #find "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/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 # Export the default content if the default_content module is there if echo $ENABLED_MODULES | grep -q default_content; then $DRUSH default-content-export-references --folder="${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/content" node fi popd