This commit is contained in:
Ste Vaidis 2024-02-21 10:53:20 +02:00
parent f5abdd8ed9
commit 72dadb5523
8 changed files with 162 additions and 104 deletions

View File

@ -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'
# <?php
# // Your new code here
# $new_variable = 'New value';
# ?>
# 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

View File

@ -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

View File

@ -3,4 +3,3 @@
if ($node->hasField('FFFFF') && !$node->get('FFFFF')->isEmpty()) {
$manager = $node->get('FFFFF')->value;
}

View File

@ -0,0 +1,4 @@
$FFFFF = '';
if ($node->hasField('FFFFF') && !$node->get('FFFFF')->isEmpty()) {
$FFFFF = $node->get('FFFFF')->value;
}

View File

@ -0,0 +1 @@
'FFFFF' => $FFFFF,

13
testxxx.sh Executable file
View File

@ -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

View File

@ -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 <<EOL
# \$databases['default']['default'] = array (
@ -77,17 +79,17 @@ cd $NAME/web
# EOL
# if [ $? = 0 ]; then ok; else fail; fi
echo -ne " 🐷 Change files owner to user ${WHT}apache${END}"
mkdir sites/default/files
cd ../..
chown apache:apache $NAME -R
find $NAME -type d -exec chmod 755 {} \;
find $NAME -type f -exec chmod 644 {} \;
echo -ne " 🐷 Change files owner to user ${W}apache${E}"
chown apache:apache ${SITES}/${NAME}/web -R
if [ $? = 0 ]; then ok; else fail; fi
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
#echo -ne " 🍒 link html to ${WHT}$NAME${END}"
#echo -ne " 🍒 link html to ${W}$NAME${E}"
#unlink /var/www/html
#ln -s /var/www/sites/$NAME/web /var/www/html
#if [ $? = 0 ]; then ok; else fail; fi
@ -96,6 +98,14 @@ echo
ls -l --color=auto /var/www/site[1234567890]
echo
echo -en "Enter directory to link the new site (0-9): "
read -n 1 answer
if [[ "$answer" =~ ^([0123456789])$ ]]; then
/var/www/sites/site${answer} ${NAME}/web
fi
# echo -ne " 🌈 Restart httpd "
# systemctl restart httpd
# if [ $? = 0 ]; then ok; else fail; fi
@ -108,44 +118,95 @@ echo
# systemctl restart mysql
# if [ $? = 0 ]; then ok; else fail; fi
echo
echo -e "Finish the installation..."
echo
echo -e "Database: ${NAME}"
echo -e "Username: ${NAME}"
echo -e "Password: 1234"
echo -e "${W}Database${E}: ${NAME}"
echo -e "${W}Username${E}: ${NAME}"
echo -e "${W}Password${E}: 1234"
echo
read -p "...and press [ENTER] to continue installing extra modules"
echo
echo -e "🍓"
cd ${SITES}/${NAME}
function rest() {
drush en serialization
drush en rest
composer require 'drupal/restui:^1.21'
drush en restui
composer require 'drupal/rest_views:^2.0'
drush en rest_views
function add_drush() {
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drush/drush' --no-interaction
}
echo -en "Enable module ${R}rest${E} (y/n): "
echo -e "${W}Drush${E}"
echo -e " 📦 drush"
echo -en "Enable modules? (y/n): "
read -n 1 answer
[ $answer = "y" ] && rest
[ $answer = "y" ] && add_drush
echo
function rest() {
drush en jsonapi
function add_aliases() {
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/pathauto' --no-interaction
${DRUSH_DIR}/drush en pathauto -y
}
echo -en "Enable module ${R}rest${E} (y/n): "
echo -e "${W}URL Aliases${E}"
echo -e " 📦 pathauto"
echo -en "Enable modules? (y/n): "
read -n 1 answer
[ $answer = "y" ] && jsonapi
[ $answer = "y" ] && add_aliases
echo
function add_rest() {
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/restui' --no-interaction
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/rest_views' --no-interaction
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/rest_export_nested' --no-interaction
${DRUSH_DIR}/drush en serialization -y
${DRUSH_DIR}/drush en rest -y
${DRUSH_DIR}/drush en restui -y
${DRUSH_DIR}/drush en rest_views -y
${DRUSH_DIR}/drush en rest_export_nested -y
}
echo -e "${W}Rest API Server${E}"
echo -e " 📦 serialization"
echo -e " 📦 rest"
echo -e " 📦 restui"
echo -e " 📦 restviews"
echo -e " 📦 rest_export_nested"
echo -en "Enable modules? (y/n): "
read -n 1 answer
[ $answer = "y" ] && add_rest
echo
function add_import() {
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/feeds' --no-interaction
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/feeds_tamper' --no-interaction
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/delete_all' --no-interaction
${DRUSH_DIR}/drush en feeds -y
${DRUSH_DIR}/drush en feeds_tamper -y
${DRUSH_DIR}/drush en delete_all -y
}
echo -e "${W}Import Data${E}"
echo -e " 📦 feeds"
echo -e " 📦 feeds_tamper"
echo -e " 📦 delete_all"
echo -en "Enable modules? (y/n): "
read -n 1 answer
[ $answer = "y" ] && add_import
echo
function add_devel() {
COMPOSER_ALLOW_SUPERUSER=1 composer require 'drupal/devel' --no-interaction
${DRUSH_DIR}/drush cr
${DRUSH_DIR}/drush en devel_generate -y
}
echo -e "${W}Import Data${E}"
echo -en "Enable modules? (y/n): "
read -n 1 answer
[ $answer = "y" ] && add_devel
echo
# composer require 'drupal/rpb:^1.0@beta'