From 72dadb55231e4393f0c52a6876e2fd93e4abcf1d Mon Sep 17 00:00:00 2001 From: Ste Vaidis Date: Wed, 21 Feb 2024 10:53:20 +0200 Subject: [PATCH] new.sh --- endpoints/add-fields.sh | 47 +----- endpoints/endpoint-get.sh | 61 ++++---- .../endpoint_get_fields/string-extractor | 1 - .../endpoint_get_fields/text_with_summary | 0 .../text_with_summary-extractor | 4 + .../text_with_summary-response | 1 + testxxx.sh | 13 ++ toolbox/new.sh | 139 +++++++++++++----- 8 files changed, 162 insertions(+), 104 deletions(-) delete mode 100644 endpoints/endpoint_get_fields/text_with_summary create mode 100644 endpoints/endpoint_get_fields/text_with_summary-extractor create mode 100644 endpoints/endpoint_get_fields/text_with_summary-response create mode 100755 testxxx.sh diff --git a/endpoints/add-fields.sh b/endpoints/add-fields.sh index 939ef41..80f368f 100755 --- a/endpoints/add-fields.sh +++ b/endpoints/add-fields.sh @@ -14,30 +14,30 @@ B="\e[0;34m" W="\e[0;97m" E="\e[00m" -# Check for 3 parameters -[ $# -ne 3 ] && echo 'Parameter missing' && exit +# CHECK 3 parameters +[ $# -ne 3 ] && echo 'Parameter missing. All I got is: ' && exit -# Check Target file +# CHECK target file DST_FILE="${1}" [ ! -f ${DSTS_FILE} ] && echo 'File ${DSTS_FILE} does not exist' && exit -# Field name -NAME="${3}" - -# Field source files +# CHECK source files TYPE="${2}" FIELD_DIR="/root/dev/endpoints/endpoint_get_fields/" ls -1 $FIELD_DIR | grep -E "${TYPE}-(extractor|response|splitter)" > /dev/null [ "$?" -ne 0 ] && echo -e "File for field ${R}${TYPE}${E} not found" +NAME="${3}" + # -# Iterate source files +# Add source to destination # for SRC_FILE in `ls -1 $FIELD_DIR | grep -E "^${TYPE}-(extractor|response|splitter)"`; do COMMENT=$(echo ${SRC_FILE} | awk -F- '{print "// AUTO_ADD_CODE_BELLOW_"$2}') NEW_CODE=$(cat ${FIELD_DIR}/${SRC_FILE} | sed -e "s/FFFFF/${NAME}/g") COMMENT_LINE=$(grep -n "$COMMENT" "$DST_FILE" | cut -d ":" -f 1) INSERT_LINE=$((${COMMENT_LINE} + 1)) + echo -e " 📦 ${W}SOURCE :${E} ${SRC_FILE}" echo -e " 📦 ${W}DESTGINATION :${E} $(basename ${DST_FILE})" echo -e " 🏁 ${W}AFTER COMMENT :${E} ${COMMENT}" @@ -49,34 +49,3 @@ for SRC_FILE in `ls -1 $FIELD_DIR | grep -E "^${TYPE}-(extractor|response|splitt echo done -exit - - -comment="// FIELDS " ${} - -exit -# new_code=$(cat << 'EOF' -# -# EOF -# ) - - -# Find the line number of the comment -comment_line=$(grep -n "$comment" "$DST_FILE" | cut -d ":" -f 1) - -if [[ -n "$comment_line" ]]; then - # Calculate the line number to insert the new code - insert_line=$((comment_line + 1)) - - # Insert the new code into the PHP file - awk -v insert="$insert_line" -v text="$NEW_CODE" 'NR == insert {print text} {print}' "$DST_FILES" > tmpfile && mv tmpfile "$DST_FILE" - - echo "New code added successfully!" -else - echo "Comment not found!" -fi - - diff --git a/endpoints/endpoint-get.sh b/endpoints/endpoint-get.sh index 90edc3a..5cd1874 100755 --- a/endpoints/endpoint-get.sh +++ b/endpoints/endpoint-get.sh @@ -1,10 +1,10 @@ #!/bin/bash -C="\e[0;36m" -G="\e[0;32m" -R="\e[0;31m" -B="\e[0;34m" -W="\e[0;97m" +C="\e[1;36m" +G="\e[1;32m" +R="\e[1;31m" +B="\e[1;34m" +W="\e[1;97m" E="\e[00m" SCRIPT_PATH=$(realpath $0) @@ -156,31 +156,42 @@ function add_fields () { for FIELD in $(bash ${SCRIPT_DIR}/get-fields.sh ${SITE_COMPOSER} node ${NODE});do FIELD_NAME=$(echo $FIELD | awk '{print $1}') FIELD_TYPE=$(echo $FIELD | awk '{print $2}') - echo - echo -en " 🍏 Add field ${C}${FIELD_NAME}${E} of type ${C}${FIELD_TYPE}${E} ? [y/n] " - read -n 1 response - echo - if [[ "$response" =~ ^([yY])$ ]] - then - echo do_something - fi + DST_FILES=("NodesController.php" "NodeController.php") + DST_PATH="${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}/src/Controller" + + for DST_FILE in ${DST_FILES}; do + echo + echo -en " 🍄 ${W}${DST_FILE}${E} : Add field ${B}${FIELD_TYPE}${E} with name ${B}${FIELD_NAME}${E}? [y/n] " + read -n 1 response + echo + if [[ "$response" =~ ^([yY])$ ]]; then + echo ${DST_PATH}/${DST_FILE} + echo ${FIELD_TYPE} + echo ${FIELD_NAME} + ${SCRIPT_DIR}/add-fields.sh "${DST_PATH}/${DST_FILE}" ${FIELD_TYPE} ${FIELD_NAME} + fi + done done } -if copy_template; then - if rename_info && rename_routing; then - if edit_files && file_permissions; then - if enable_module && test_module; then - add_fields +function main() { + if copy_template; then + if rename_info && rename_routing; then + if edit_files && file_permissions; then + if enable_module && test_module; then + add_fields + fi fi fi fi -fi -echo -echo -e "Relmember to check the settings for:" -echo -e " - Permissions" -echo -e " - Translations" -echo -e " - Aliases" -echo + echo + echo -e "Relmember to check the settings for:" + echo -e " - Permissions" + echo -e " - Translations" + echo -e " - Aliases" + echo +} + +main diff --git a/endpoints/endpoint_get_fields/string-extractor b/endpoints/endpoint_get_fields/string-extractor index 8bd8b71..9f35beb 100644 --- a/endpoints/endpoint_get_fields/string-extractor +++ b/endpoints/endpoint_get_fields/string-extractor @@ -3,4 +3,3 @@ if ($node->hasField('FFFFF') && !$node->get('FFFFF')->isEmpty()) { $manager = $node->get('FFFFF')->value; } - diff --git a/endpoints/endpoint_get_fields/text_with_summary b/endpoints/endpoint_get_fields/text_with_summary deleted file mode 100644 index e69de29..0000000 diff --git a/endpoints/endpoint_get_fields/text_with_summary-extractor b/endpoints/endpoint_get_fields/text_with_summary-extractor new file mode 100644 index 0000000..5f4f0f7 --- /dev/null +++ b/endpoints/endpoint_get_fields/text_with_summary-extractor @@ -0,0 +1,4 @@ + $FFFFF = ''; + if ($node->hasField('FFFFF') && !$node->get('FFFFF')->isEmpty()) { + $FFFFF = $node->get('FFFFF')->value; + } diff --git a/endpoints/endpoint_get_fields/text_with_summary-response b/endpoints/endpoint_get_fields/text_with_summary-response new file mode 100644 index 0000000..6510504 --- /dev/null +++ b/endpoints/endpoint_get_fields/text_with_summary-response @@ -0,0 +1 @@ + 'FFFFF' => $FFFFF, diff --git a/testxxx.sh b/testxxx.sh new file mode 100755 index 0000000..dcf5da7 --- /dev/null +++ b/testxxx.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +NAME=$1 + +echo +ls -l --color=auto /var/www/site[1234567890] +echo +echo -en "Enter directory to link the new site (0-9) (y/n): " +read -n 1 answer +if [[ "$answer" =~ ^([0123456789])$ ]]; then + ./site${answer} ${NAME}/web +fi + diff --git a/toolbox/new.sh b/toolbox/new.sh index 9f09b1a..b116bb7 100755 --- a/toolbox/new.sh +++ b/toolbox/new.sh @@ -5,34 +5,36 @@ # + database user # -RED="\e[0;31m" -GRN="\e[0;32m" -BLU="\e[0;34m" -WHT="\e[0;97m" +D="\e[0;31m" +G="\e[0;32m" +B="\e[0;34m" +W="\e[0;97m" BOLDRED="\e[1;31m" BOLDGRN="\e[1;32m" BOLDBLU="\e[1;34m" BOLDWHT="\e[1;97m" -END="\e[00m" +E="\e[00m" DBUSER="root" DBPASS="1234" NAME=$1 +SITES="/var/www/sites" +DRUSH_DIR="${SITES}/${NAME}/vendor/drush/drush" function ok() { - echo -e "${BOLDGRN} [ OK ]${END}" + echo -e "${BOLDGRN} [ OK ]${E}" } function fail() { - echo -e "${BOLDRED} [FAIL]${END}" + echo -e "${BOLDRED} [FAIL]${E}" echo exit } echo -echo -ne " 💧 Create new drupal in dir ${WHT}$NAME${END} ..." -composer --no-interaction create-project drupal/recommended-project $NAME +echo -ne " 💧 Create new drupal in dir ${W}$NAME${E} ..." +COMPOSER_ALLOW_SUPERUSER=1 composer --no-interaction create-project drupal/recommended-project $NAME # CMD="composer --no-interaction create-project drupal/recommended-project $NAME" # sudo su -l apache -s /bin/bash -c "$CMD" # sudo su -l apache -s /bin/bash -c "cd $PWD; $CMD" @@ -42,15 +44,15 @@ composer --no-interaction create-project drupal/recommended-project $NAME #CMD="composer create-project drupal/recommended-project:9 $NAME" if [ $? = 0 ]; then ok; else fail; fi -echo -ne " 🐬 Create database ${WHT}$NAME${END} ..." +echo -ne " 🐬 Create database ${W}$NAME${E} ..." mysql -uroot -p1234 -e "CREATE DATABASE $NAME" if [ $? = 0 ]; then ok; else fail; fi -echo -ne " 🐬 Create database user ${WHT}$NAME${END} with password '1234' ..." +echo -ne " 🐬 Create database user ${W}$NAME${E} with password '1234' ..." mysql -uroot -p1234 -e "CREATE USER $NAME@localhost IDENTIFIED BY \"1234\"" if [ $? = 0 ]; then ok; else fail; fi -echo -ne " 🐬 Grand user ${WHT}${NAME}${END} permissions to database ${WHT}${NAME}${END} ..." +echo -ne " 🐬 Grand user ${W}${NAME}${E} permissions to database ${W}${NAME}${E} ..." mysql -uroot -p1234 -e "GRANT ALL ON $NAME.* TO $NAME@localhost" if [ $? = 0 ]; then ok; else fail; fi @@ -58,9 +60,9 @@ echo -ne " 🐬 Flush privilages ..." mysql -uroot -p1234 -e "FLUSH PRIVILEGES" if [ $? = 0 ]; then ok; else fail; fi -echo -ne " 🍒 Drupal settings.php" cd $NAME/web +# echo -e " 🍒 Drupal settings.php" # cp sites/default/default.settings.php sites/default/settings.php # cat >> sites/default/settings.php <