Updated script with better messaging and to check composer version since the script won't run on composer 1.

This commit is contained in:
alex 2021-05-27 13:31:20 -06:00
parent 81b23d7b69
commit 07a04b19af

View File

@ -1,39 +1,70 @@
echo Would you like to install a theme using the FE Setup script? \(y/n\) Be sure not to overwrite an existing theme. #!/bin/bash
read install_theme
if [ $install_theme == 'y' -o $install_theme == 'Y' ] # Setup colours for us in our output messages.
BLACK_TXT=`tput setaf 0`
RED_TXT=`tput setaf 1`
GREEN_TXT=`tput setaf 2`
YELLOW_TXT=`tput setaf 3`
BLACK_BG=`tput setab 0`
RED_BG=`tput setab 1`
GREEN_BG=`tput setab 2`
YELLOW_BG=`tput setab 3`
RESET=`tput sgr0`
# Get composer version because in order to run properly this script requires
# Composer 2. See: https://github.com/composer/composer/issues/3299.
# Cuts will return overall composer version (ie. 1 or 2).
COMPOSER_VERSION_COMMAND="composer --version --no-ansi | cut -d \" \" -f 3 | cut -d \".\" -f 1"
COMPOSER_VERSION=$(eval "$COMPOSER_VERSION_COMMAND")
if [ "$COMPOSER_VERSION" -lt 2 ]
then then
echo What is the theme name? \(This value should be all lowercase, and will replace \'yellowpencil\' in the starter theme.\) echo "${YELLOW_BG}${BLACK_TXT} Theme setup script requires Composer 2. Please note the rest of the composer install command has still be ran as expected - the theme setup is an optional step. ${RESET}";
read theme_name echo "${YELLOW_BG}${BLACK_TXT} If you are setting up a site please also note that the site installation profile will still be able to be installed. ${RESET}";
echo What is the URL of the project repository? \(This should follow the format \'https://git.yellowpencil.com/yellowpencil/theme-name\'.\)
read repo_url
SEARCH_PATH=web/themes
SEARCH=yellowpencil
SEARCH_R=[Yy]ellow[Pp]encil
REPLACE=$theme_name
REPO=$repo_url
if [ -d "$SEARCH_PATH/$REPLACE" -a ! -h "$SEARCH_PATH/$REPLACE" ]
then
BLACK_BG=`tput setaf 0`
YELLOW_TXT=`tput setab 3`
RESET=`tput sgr0`
echo "${YELLOW_TXT}${BLACK_BG} Theme already exists. ${RESET}";
exit 0; exit 0;
fi fi
git clone git@git.yellowpencil.com:yellowpencil/yp_drupal8_theme.git $SEARCH_PATH/$REPLACE
mv $SEARCH_PATH/$REPLACE/yellowpencil/* $SEARCH_PATH/$REPLACE # Check if the user actually wants to run the install script or not.
rm -r $SEARCH_PATH/$REPLACE/yellowpencil echo "Would you like to install a theme using the starter theme front-end setup script? (${GREEN_TXT}Y${RESET}/${RED_TXT}N${RESET})";
rm -rf $SEARCH_PATH/$REPLACE/.git read install_theme
rm -rf $SEARCH_PATH/$REPLACE/.gitignore if [ "$install_theme" != 'y' -a "$install_theme" != 'Y' ]
find ${SEARCH_PATH} -type f -name "*${SEARCH}*" | while read FILENAME ; do then
echo "${YELLOW_BG}${BLACK_TXT} Theme will not be setup. Please note the rest of the composer install command has still be ran as expected - the theme setup is an optional step. ${RESET}";
echo "${YELLOW_BG}${BLACK_TXT} If you are setting up a site please also note that the site installation profile will still be able to be installed. ${RESET}";
exit 0;
fi
# fe_setup.sh script runs from here on.
echo What is the theme name? \(This value should be all lowercase, and will replace \'yellowpencil\' in the starter theme.\)
read theme_name
echo What is the URL of the project repository? \(This should follow the format \'https://git.yellowpencil.com/yellowpencil/theme-name\'.\)
read repo_url
SEARCH_PATH=web/themes
SEARCH=yellowpencil
SEARCH_R=[Yy]ellow[Pp]encil
REPLACE=$theme_name
REPO=$repo_url
# Check if the theme already exists and is so exit so we don't accidentally
# overwrite anything.
if [ -d "$SEARCH_PATH/$REPLACE" -a ! -h "$SEARCH_PATH/$REPLACE" ]
then
echo "${YELLOW_BG}${BLACK_TXT} Theme already exists. Please note the rest of the composer install command has still be ran as expected - the theme setup is an optional step. ${RESET}";
echo "${YELLOW_BG}${BLACK_TXT} If you are setting up a site please also note that the site installation profile will still be able to be installed. ${RESET}";
exit 0;
fi
git clone git@git.yellowpencil.com:yellowpencil/yp_drupal8_theme.git $SEARCH_PATH/$REPLACE
mv $SEARCH_PATH/$REPLACE/yellowpencil/* $SEARCH_PATH/$REPLACE
rm -r $SEARCH_PATH/$REPLACE/yellowpencil
rm -rf $SEARCH_PATH/$REPLACE/.git
rm -rf $SEARCH_PATH/$REPLACE/.gitignore
find ${SEARCH_PATH} -type f -name "*${SEARCH}*" | while read FILENAME ; do
NEW_FILENAME="$(echo ${FILENAME} | sed -e "s/${SEARCH}/${REPLACE}/g")"; NEW_FILENAME="$(echo ${FILENAME} | sed -e "s/${SEARCH}/${REPLACE}/g")";
mv "${FILENAME}" "${NEW_FILENAME}"; mv "${FILENAME}" "${NEW_FILENAME}";
done done
find ${SEARCH_PATH} -type f -name "*.twig" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g" find ${SEARCH_PATH} -type f -name "*.twig" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g"
find ${SEARCH_PATH} -type f -name "*.theme" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g" find ${SEARCH_PATH} -type f -name "*.theme" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g"
find ${SEARCH_PATH} -type f -name "*.yml" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g" find ${SEARCH_PATH} -type f -name "*.yml" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g"
find ${SEARCH_PATH} -type f -name "*.txt" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g" find ${SEARCH_PATH} -type f -name "*.txt" -print0 | xargs -0 sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g"
PACKAGE_FILE=$(find ${SEARCH_PATH}/${REPLACE} -type f -name "package.json" -print0) PACKAGE_FILE=$(find ${SEARCH_PATH}/${REPLACE} -type f -name "package.json" -print0)
sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g" $PACKAGE_FILE sed -i '' -e "s/${SEARCH_R}/${REPLACE}/g" $PACKAGE_FILE
sed -i '' -e "s,https:\/\/[^\"#]*,${REPO},g" $PACKAGE_FILE sed -i '' -e "s,https:\/\/[^\"#]*,${REPO},g" $PACKAGE_FILE
echo $REPO_REPLACE echo "${GREEN_TXT}The '${theme_name}' theme has been successfully created.${RESET}";
fi