#!/bin/bash # Usage/help function usage() { echo "Usage: $0 ModuleName" echo " ModuleName must start with a capital letter and match a directory under:" echo " ~/SME11/usr/share/smanager/lib/SrvMngr/I18N/Modules/" echo "Example: $0 Useraccounts" exit 1 } # Check parameter if [ -z "$1" ]; then echo "Error: No module name provided." usage fi MODULE_NAME="$1" # Check if parameter starts with a capital letter if [[ ! "$MODULE_NAME" =~ ^[A-Z] ]]; then echo "Error: Module name must start with a capital letter." usage fi # Check if directory exists in output OUTPUT_SRC_DIR=~/clients/SM2/SM2Gen/venv/output OUTPUT_MODULE_DIR="${OUTPUT_SRC_DIR}/${MODULE_NAME}" if [ ! -d "$OUTPUT_MODULE_DIR" ]; then echo "Error: Directory '${OUTPUT_MODULE_DIR}' does not exist." exit 1 #usage fi # Check if directory exists in SME11 SRC_DIR=~/SME11/usr/share/smanager/lib/SrvMngr/I18N/Modules MODULE_DIR="${SRC_DIR}/${MODULE_NAME}" if [ ! -d "$MODULE_DIR" ]; then echo "Error: Directory '${MODULE_DIR}' does not exist." usage fi # Convert to lowercase for filenames MODULE_NAME_LC=$(echo "$MODULE_NAME" | tr '[:upper:]' '[:lower:]') # Paths LEX_FILE="${MODULE_DIR}/${MODULE_NAME_LC}_en.lex" BAK_FILE="${LEX_FILE}.bak" # Define file paths LEX_FILE_NEW1="output/${MODULE_NAME}/${MODULE_NAME_LC}_en.lex.new1" LEX_FILE_NEW="output/${MODULE_NAME}/${MODULE_NAME_LC}_en.lex.new" # Check if 'new1' version exists; if not, fall back to 'new' if [ -f "$LEX_FILE_NEW1" ]; then NEW_LEX_FILE="$LEX_FILE_NEW1" else NEW_LEX_FILE="$LEX_FILE_NEW" fi GENERAL_LEX_FILE="${SRC_DIR}/General/general_en.lex" GENERAL_BAK_FILE="${GENERAL_LEX_FILE}.bak" GENERAL_NEW_LEX_FILE="output/General/general_en.lex.new1" # Move to backup only if .bak does not exist (module file) if [ ! -f "$BAK_FILE" ]; then mv -v "$LEX_FILE" "$BAK_FILE" fi # Move to backup only if .bak does not exist (general file) if [ ! -f "$GENERAL_BAK_FILE" ]; then mv -v "$GENERAL_LEX_FILE" "$GENERAL_BAK_FILE" fi # Copy new lex files cp -v "$NEW_LEX_FILE" "$LEX_FILE" cp -v "$GENERAL_NEW_LEX_FILE" "$GENERAL_LEX_FILE" # Copy template files from output// TEMPLATE_SRC_PARENT="output/${MODULE_NAME}" TEMPLATE_TARGET_BASE=~/SME11/usr/share/smanager/themes if [ -d "$TEMPLATE_SRC_PARENT" ]; then for SUBDIR in "$TEMPLATE_SRC_PARENT"/*/; do [ ! -d "$SUBDIR" ] && continue # skip if no subdirs SUBDIR_NAME=$(basename "$SUBDIR") find "$SUBDIR" -type f | while read -r FILE; do BASENAME=$(basename "$FILE") # Remove the first .new in the name (if any), e.g., foo.html.new.ep => foo.html.ep NEWNAME="${BASENAME/.new/}" if [[ "$BASENAME" == _* ]]; then DEST="$TEMPLATE_TARGET_BASE/$SUBDIR_NAME/templates/partials/" else DEST="$TEMPLATE_TARGET_BASE/$SUBDIR_NAME/templates/" fi mkdir -p "$DEST" cp -v "$FILE" "$DEST/$NEWNAME" done done fi ssh -p 1234 root@SME11.thereadclan.me.uk 'signal-event smanager-refresh'