2 # Create a Drupal installation profile
4 # Copyright (C) 2017 Antonio Ospite <ao2@ao2.it>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 usage: drin $(basename "$0" .sh) [-h|--help] <title> <machine_name>
25 Create an installation profile from the installed project.
28 -h, --help display this usage message and exit
40 echo "Error: Unknown option '${1}'" 1>&2
50 { [ "x$1" = "x" ] || [ "x$2" = "x" ]; } && { usage 1>&2; exit 1; }
53 PROFILE_MACHINE_NAME="$2"
57 [ -d "$WEB_ROOT" ] || { echo "Aborting, run this command from the Drupal project directory." 1>&2; exit 1; }
61 DRUPAL_CONSOLE="${PROJECT_ROOT}/vendor/bin/drupal"
62 DRUSH="${PROJECT_ROOT}/vendor/bin/drush"
64 [ -x "$DRUSH" ] || { echo "Aborting, '$DRUSH' not available." 1>&2; exit 1; }
65 [ -x "$DRUPAL_CONSOLE" ] || { echo "Aborting, '$DRUPAL_CONSOLE' not available." 1>&2; exit 1; }
67 [ -d "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}" ] && { echo "Aborting, ${PROJECT_ROOT}/${PROFILE_MACHINE_NAME} already exists." 1>&2; exit 1; }
71 # The list of modules and themes could also be obtained by exporting the
72 # configuration first and then looking at: config/install/core.extension.yml
75 # sed -e '/module:/,/^[^ ]/!d;//d' -e 's/^[ ]*\(.*\):.*$/\1/' config/install/core.extension.yml
79 # $DRUPAL_CONSOLE yaml:get:value "$PWD/$PROFILE_MACHINE_NAME/config/install/core.extension.yml" dependencies
81 # However getting them before exporting the configuration and generating the
84 ENABLED_MODULES="$($DRUSH pm-list --type=module --status=enabled --pipe | tr '\n' ',')"
85 ENABLED_THEMES="$($DRUSH pm-list --type=theme --status=enabled --pipe | tr '\n' ',')"
87 $DRUPAL_CONSOLE generate:profile \
88 --profile="$PROFILE_TITLE" \
89 --machine-name="$PROFILE_MACHINE_NAME" \
90 --description="Drupal installation profile for $PROFILE_TITLE" \
91 --dependencies="$ENABLED_MODULES" \
92 --themes="$ENABLED_THEMES" \
93 --profile-path="$PROJECT_ROOT" \
96 # Basically do what's suggested in the "Configuration" section here:
97 # https://www.drupal.org/docs/8/creating-distributions/how-to-write-a-drupal-8-installation-profile
98 $DRUPAL_CONSOLE config:export --directory="${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install" --remove-uuid --remove-config-hash
99 rm "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install/core.extension.yml"
101 # The reference to the core version could be removed, even though it is not strictly necessary.
102 find "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install" -type f -exec sed -i -e '/^_core: { }/d' {} \;
104 # Since the profile generated by `$DRUPAL_CONSOLE generate:profile` calls in
105 # the standard profile, some duplicated config files could be removed in the
106 # new profile, but that's not strictly necessary either.
107 #fdupes -f -1 "${WEB_ROOT}/core/profiles/standard/config/install/" "${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/config/install/" | xargs rm
109 # Export the default content if the default_content module is there
110 if echo "$ENABLED_MODULES" | grep -q default_content;
112 $DRUSH default-content-export-references --folder="${PROJECT_ROOT}/${PROFILE_MACHINE_NAME}/content" node