#!/bin/bash C="\e[0;36m" G="\e[0;32m" B="\e[0;34m" W="\e[0;97m" E="\e[00m" SOURCE="/root/dev/endpoints" BASE_DIR="/var/www/sites" MODULES="modules/custom" SITE=${1} NODE=${2} IFS=$'\n' function quit() { echo echo -e "Syntax:" echo -e "${W}./endpoint-get ${E}" echo echo -e "Example:" echo -e "${W}./endpoint-get mysite4 events${E}" echo exit } [ "$#" -lt 2 ] && echo "Argument missing" && quit [ ! -d ${SITE} ] && echo "Directory ${SITE} does not exist" && quit [ -d ${SITE}/web ] && SITE=${SITE}/web function log() { [ $1 == 0 ] && echo -e " ${G}[ OK ]${E}"; return echo -e " ${R}[FAIL]${E}" exit } 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 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 echo done echo 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 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 done }