This commit is contained in:
mguschin
2026-02-02 19:52:58 +03:00
parent f74a5041f8
commit 053fa62395
26 changed files with 866 additions and 0 deletions

34
run/evo/clear.sh Executable file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# This script cleans all EVO-related directories
# It removes all files from products, groups and stores directories
# Get the directory where this script is located
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Load constants and functions
source $SCRIPT_DIR/constants.sh
source $SCRIPT_DIR/functions.sh
# Initialize logging system
setup_logging
# Ensure we clean up properly even if script is interrupted
trap 'cleanup 1' HUP INT QUIT TERM
# Begin cleanup process
echo "$(timestamp) [INFO] Starting EVO cleanup process" >> "$LOG_FILE"
# Clean EVO content directories
echo "$(timestamp) [INFO] Cleaning EVO directories" >> "$LOG_FILE"
# Remove product files
echo "$(timestamp) [INFO] Removing product files" >> "$LOG_FILE"
echo "rm -f $EVO_PRODUCTS_PATH/*" && rm -rf $EVO_PRODUCTS_PATH/*
# Remove group files
echo "$(timestamp) [INFO] Removing group files" >> "$LOG_FILE"
echo "rm -f $EVO_GROUPS_PATH/*" && rm -rf $EVO_GROUPS_PATH/*
# Remove store files
echo "$(timestamp) [INFO] Removing store files" >> "$LOG_FILE"
echo "rm -rf $EVO_STORES_PATH/*" && rm -rf $EVO_STORES_PATH/*
echo "$(timestamp) [INFO] EVO cleanup completed successfully" >> "$LOG_FILE"
cleanup 0

21
run/evo/constants.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
ROOT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT_DIR+='/../..'
EVO_STORE_PERIOD_HOURS=2
EVO_STORE_PERIOD_MINUTES=$((EVO_STORE_PERIOD_HOURS * 60))
EVO_PRODUCTS_PATH="$ROOT_DIR/evo/products"
EVO_GROUPS_PATH="$ROOT_DIR/evo/groups"
EVO_STORES_PATH="$ROOT_DIR/evo/stores"
EVO_EXAMPLE_PATH="$ROOT_DIR/evo/examples"
EVO_RESPONSE_FILE_NAME_FORMAT="%(%Y-%m-%d_%H:%M:%S)T"
EVO_RESPONSE_FILE_NAME_EXT="json"
EVO_API_HOST="https://api.evotor.ru"
EVO_API_TOKEN=`cat "$ROOT_DIR/evo/api.credentials.token"`
EVO_API_STORE_ID=`cat "$ROOT_DIR/evo/api.credentials.store_id"`
EVO_API_ACCEPT=`cat "$ROOT_DIR/evo/api.credentials.accept"`
EVO_API_CONTENT_TYPE=`cat "$ROOT_DIR/evo/api.credentials.content_type"`
EVO_API_GET_PRODUCTS="$EVO_API_HOST/stores/$EVO_API_STORE_ID/products"
EVO_API_GET_GROUPS="$EVO_API_HOST/stores/$EVO_API_STORE_ID/product-groups"
EVO_API_GET_STORES="$EVO_API_HOST/stores"

45
run/evo/functions.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Setup timestamp function
timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}
# Setup process cleanup
cleanup() {
# Kill all child processes of this script
pkill -P $$
exit $1
}
# Function to handle API requests and save response
handle_request() {
local request_type=$1
local api_endpoint=$2
local path=$3
local fileName=$4
echo "$(timestamp) [REQUEST] Getting $request_type" >> "$LOG_FILE"
response=$(curl -s -w "%{http_code}" -H "Accept: $EVO_API_ACCEPT" \
-H "Content-Type: $EVO_API_CONTENT_TYPE" \
-H "Authorization: $EVO_API_TOKEN" \
-X GET \
$api_endpoint)
http_code=${response: -3}
response_body=${response:0:-3}
if [ "$http_code" = "200" ]; then
touch "$path/$fileName"
echo "$response_body" > "$path/$fileName"
fi
echo "$(timestamp) [RESPONSE] code=$http_code" >> "$LOG_FILE"
# Delete old files (files older than configured period)
find $path ! -type d -mmin +$EVO_STORE_PERIOD_MINUTES -delete
}
# Setup logging function
setup_logging() {
LOG_DIR="$ROOT_DIR/logs"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/$(date +%Y%m%d).log"
}

21
run/evo/get-groups.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/constants.sh
source $SCRIPT_DIR/functions.sh
# Setup logging
setup_logging
# Trap signals to ensure proper cleanup
trap 'cleanup 1' HUP INT QUIT TERM
path=$EVO_GROUPS_PATH/$EVO_API_STORE_ID
printf -v fileName "$EVO_RESPONSE_FILE_NAME_FORMAT.$EVO_RESPONSE_FILE_NAME_EXT" -1
mkdir -p $path
# Handle request for groups
handle_request "groups" "$EVO_API_GET_GROUPS" "$path" "$fileName"
# Use the cleanup function instead of directly exiting
cleanup 0

21
run/evo/get-products.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/constants.sh
source $SCRIPT_DIR/functions.sh
# Setup logging
setup_logging
# Trap signals to ensure proper cleanup
trap 'cleanup 1' HUP INT QUIT TERM
path=$EVO_PRODUCTS_PATH/$EVO_API_STORE_ID
printf -v fileName "$EVO_RESPONSE_FILE_NAME_FORMAT.$EVO_RESPONSE_FILE_NAME_EXT" -1
mkdir -p $path
# Handle request for products
handle_request "products" "$EVO_API_GET_PRODUCTS" "$path" "$fileName"
# Use the cleanup function instead of directly exiting
cleanup 0

21
run/evo/get-stores.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/constants.sh
source $SCRIPT_DIR/functions.sh
# Setup logging
setup_logging
# Trap signals to ensure proper cleanup
trap 'cleanup 1' HUP INT QUIT TERM
path=$EVO_STORES_PATH/$EVO_API_STORE_ID
printf -v fileName "$EVO_RESPONSE_FILE_NAME_FORMAT.$EVO_RESPONSE_FILE_NAME_EXT" -1
mkdir -p $path
# Handle request for stores
handle_request "stores" "$EVO_API_GET_STORES" "$path" "$fileName"
# Use the cleanup function instead of directly exiting
cleanup 0