diff --git a/endpoints/endpoint-get-delete.sh b/endpoints/endpoint-get-delete.sh index 70d8ce5..5629d59 100755 --- a/endpoints/endpoint-get-delete.sh +++ b/endpoints/endpoint-get-delete.sh @@ -14,25 +14,30 @@ cd /var/www/sites/${SITE} echo # if module does not exist -../vendor/drush/drush/drush pml | grep "(endpoint_get_${NODE})" +../vendor/drush/drush/drush pml --fields=name,status | grep "endpoint_get_${NODE}" if [ $? -ne 0 ];then - echo -n " 🌈 Cannot found module ${B}endpoint_get_${NODE}${E}" + echo -n " 🌈 Cannot find module ${B}endpoint_get_${NODE}${E}" exit fi echo -e " 🍓 Found module ${B}endpoint_get_${NODE}${E}" +../vendor/drush/drush/drush cr + # if is enabled, disable it -../vendor/drush/drush/drush pml | grep -e "Enabled" | grep "(endpoint_get_${NODE})" &> /dev/null +../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml +cat /tmp/.drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}" +# cat ./drush.pml | grep -e "Enabled" | grep "(endpoint_get_${NODE})" &> /dev/null if [ $? -eq 0 ];then echo -n " 🍓 Disabling module ${B}endpoint_get_${NODE}${E}" ../vendor/drush/drush/drush pmu "endpoint_get_${NODE}" - ../vendor/drush/drush/drush pml | grep "(endpoint_get_${NODE})" fi # if is not disabled, dont delete it -../vendor/drush/drush/drush pml | grep -e "Disabled" | grep "(endpoint_get_${NODE})" &> /dev/null -if [ $? -ne 0 ];then - echo -n " 🌈 Cannot deleting enabled module ${B}endpoint_get_${NODE}${E}" +../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml +cat ./drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}" +if [ $? -eq 0 ];then + echo -n " 🌈 Cannot delete enabled module ${B}endpoint_get_${NODE}${E}" + ../vendor/drush/drush/drush pml --fields=name,status | grep "endpoint_get_${NODE}" exit fi diff --git a/endpoints/endpoint-get.sh b/endpoints/endpoint-get.sh index 05571fc..dd7f1f2 100755 --- a/endpoints/endpoint-get.sh +++ b/endpoints/endpoint-get.sh @@ -6,6 +6,8 @@ B="\e[0;34m" W="\e[0;97m" E="\e[00m" +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname ${SCRIPT_PATH}) SOURCE="/root/dev/endpoints" BASE_DIR="/var/www/sites" MODULES="modules/custom" @@ -32,97 +34,121 @@ function quit() { function log() { - [ $1 == 0 ] && echo -e " ${G}[ OK ]${E}"; return - echo -e " ${R}[FAIL]${E}" - exit + if [ $? -eq 0 ]; then + echo -e "${G}[ OK ]${E}" + return 0 + else + echo -e "${G}[FAIL]${E}" + return 1 + fi +} + + +function copy_template() { + echo + echo -en " 📂 Copy template module dir to ${B}${SITE}${E} " + cp -r "${SOURCE}/endpoint_get_AAAAA" "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}" + log $? + echo + cd "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}" } -echo -echo -en " 📂 Copy template module dir to ${B}${SITE}${E}" -cp -r "${SOURCE}/endpoint_get_AAAAA" "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}" -log $? -echo - -cd "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}" - - # Rename files +function rename_info() { + echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.info.yml${E} file " + mv "endpoint_get_AAAAA.info.yml" "endpoint_get_${NODE}.info.yml" &> /dev/null + log $? +} + +function rename_routing() { + echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.routing.yml${E} file " + mv "endpoint_get_AAAAA.routing.yml" "endpoint_get_${NODE}.routing.yml" &> /dev/null + log $? +} -echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.info.yml${E} file" -mv "endpoint_get_AAAAA.info.yml" "endpoint_get_${NODE}.info.yml" -log $? -echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.routing.yml${E} file" -mv "endpoint_get_AAAAA.routing.yml" "endpoint_get_${NODE}.routing.yml" -log $? # Edit files -echo -echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.info.yml${E} file" -sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.info.yml" -log $? - -echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.routing.yml${E} file" -sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.routing.yml" -log $? - -echo -en " ⭐ Edit ${B}src/Controller/NodeController.php${E} file" -sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodeController.php" -log $? - -echo -en " ⭐ Edit ${B}src/Controller/NodesController.php${E} file" -sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodesController.php" -log $? - -echo -en " ⭐ Edit ${B}src/Controller/CategoryController.php${E} file" -sed -i "s/AAAAA/${NODE}/g" "src/Controller/CategoryController.php" -log $? -echo - - -# Filesystem -chown -R apache:apache "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}" - - -# Enable module -echo -e " 🌈 Enable module" -cd /var/www/sites/${SITE} -../vendor/drush/drush/drush en "endpoint_get_${NODE}" - -# Test endpoint -BASE_URL="http://$(ls -l /var/www/ | grep ${SITE} | awk {'print $9'}).vm7" -API_URL="api/el" -NODE_URL="${BASE_URL}/${API_URL}/${NODE}" -NODES_URL="${BASE_URL}/${API_URL}/${NODE}s" - -ENDPOINTS=( - api/en/${NODE}s - api/el/${NODE}s -) - -for ENDPOINT in ${ENDPOINTS[@]}; do - ENDPOINT_STATUS=$(curl -sI --location --request GET $BASE_URL/$ENDPOINT?_format=json \ - -b cookie.txt \ - --header "Content-type: application/json" | grep HTTP | awk {'print $2'}) - RESPONSE=$(curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c100) - - echo -e "\n 🍒 GET $BASE_URL/$ENDPOINT $ENDPOINT_STATUS" - [ "${ENDPOINT_STATUS}" == "200" ] && curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c75 +function edit_files() { echo -done -echo + echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.info.yml${E} file " + sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.info.yml" + log $? + [ $? -ne 0 ] && return 1 + + echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.routing.yml${E} file " + sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.routing.yml" + log $? + [ $? -ne 0 ] && return 1 + + echo -en " ⭐ Edit ${B}src/Controller/NodeController.php${E} file " + sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodeController.php" + log $? + [ $? -ne 0 ] && return 1 + + echo -en " ⭐ Edit ${B}src/Controller/NodesController.php${E} file " + sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodesController.php" + log $? + [ $? -ne 0 ] && return 1 + + echo -en " ⭐ Edit ${B}src/Controller/CategoryController.php${E} file " + sed -i "s/AAAAA/${NODE}/g" "src/Controller/CategoryController.php" + log $? + [ $? -ne 0 ] && return 1 + + return 0 +} + +function file_permissions() { + echo + echo -en " 🫐 chown -R apache:apache ${B}/endpoint_get_${NODE}${E} " + chown -R apache:apache "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}" + log $? + [ $? -ne 0 ] && return 1 + return 0 +} + +function enable_module() { + return 0 + echo + echo -en " 🌈 Enable module" + cd /var/www/sites/${SITE} + ../vendor/drush/drush/drush en "endpoint_get_${NODE}" + log $? + [ $? -ne 0 ] && return 1 + return 0 +} + +function test_module() { + BASE_URL="http://$(ls -l /var/www/ | grep ${SITE} | awk {'print $9'}).vm7" + API_URL="api/el" + NODE_URL="${BASE_URL}/${API_URL}/${NODE}" + NODES_URL="${BASE_URL}/${API_URL}/${NODE}s" + + ENDPOINTS=( + api/en/${NODE}s + api/el/${NODE}s + ) + + for ENDPOINT in ${ENDPOINTS[@]}; do + ENDPOINT_STATUS=$(curl -sI --location --request GET $BASE_URL/$ENDPOINT?_format=json \ + -b cookie.txt \ + --header "Content-type: application/json" | grep HTTP | awk {'print $2'}) + RESPONSE=$(curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c100) + + echo -e "\n 🍒 GET $BASE_URL/$ENDPOINT $ENDPOINT_STATUS" + [ "${ENDPOINT_STATUS}" == "200" ] && curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c75 + echo + done + echo + return 0 +} -echo -echo -e "Relmember to check the settings for:" -echo -e " - Permissions" -echo -e " - Translations" -echo -e " - Aliases" -echo function add_fields () { - for FIELD in $(bash ./get-fields.sh ${SITE} node ${NODE});do + for FIELD in $(bash ${SCRIPT_DIR}/get-fields.sh ${SITE} node ${NODE});do FIELD_NAME=$(echo $FIELD | awk '{print $1}') FIELD_TYPE=$(echo $FIELD | awk '{print $2}') echo @@ -136,3 +162,20 @@ function add_fields () { 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 + fi + fi + fi +fi + +echo +echo -e "Relmember to check the settings for:" +echo -e " - Permissions" +echo -e " - Translations" +echo -e " - Aliases" +echo + diff --git a/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php b/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php index 0dd3890..c04d073 100644 --- a/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php +++ b/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php @@ -62,7 +62,7 @@ class NodeController extends ControllerBase { } /* Build the response */ - $this->buildNodeResponse($lang, $alias, $nid) + $this->buildNodeResponse($lang, $alias, $nid); return new JsonResponse($this->response, $this->statusCode); } diff --git a/endpoints/get-fields.sh b/endpoints/get-fields.sh index 6d78d91..fc2f539 100755 --- a/endpoints/get-fields.sh +++ b/endpoints/get-fields.sh @@ -11,13 +11,13 @@ # IFS=$'\n' -DIR=$1 +SITE_DIR=$1 TYPE=$2 NAME=$3 -cd /var/www/sites/$DIR +cd /var/www/sites/$SITE_DIR -for FIELD in $(vendor/drush/drush/drush fi ${TYPE} ${NAME} | tail -n +3 | grep -v '\-\-\-'); do +for FIELD in $(../vendor/drush/drush/drush fi ${TYPE} ${NAME} | tail -n +3 | grep -v '\-\-\-'); do NAME=$(echo $FIELD | awk '{print $1}') TYPE=$(echo $FIELD | awk '{print $2}') COUNT=$(echo $TYPE | wc -c)