Delete all shell script files, keeping only Python versions
Co-authored-by: jmiller-moko <230051081+jmiller-moko@users.noreply.github.com>
This commit is contained in:
@@ -1,233 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# ============================================================================
|
||||
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
|
||||
#
|
||||
# This file is part of a Moko Consulting project.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program (./LICENSE.md).
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# FILE INFORMATION
|
||||
# ============================================================================
|
||||
# DEFGROUP: Script.Library
|
||||
# INGROUP: Common
|
||||
# REPO: https://github.com/mokoconsulting-tech
|
||||
# PATH: /scripts/lib/common.sh
|
||||
# VERSION: 01.00.00
|
||||
# BRIEF: Unified shared shell utilities for all CI and local scripts
|
||||
# NOTE:
|
||||
# ============================================================================
|
||||
|
||||
set -eu
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Environment normalization
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
export LC_ALL=C
|
||||
export LANG=C
|
||||
|
||||
is_ci() {
|
||||
[ "${CI:-}" = "true" ]
|
||||
}
|
||||
|
||||
require_cmd() {
|
||||
command -v "$1" >/dev/null 2>&1 || {
|
||||
printf '%s\n' "ERROR: Required command not found: $1" >&2
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Logging
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
log_info() {
|
||||
printf '%s\n' "INFO: $*"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
printf '%s\n' "WARN: $*" >&2
|
||||
}
|
||||
|
||||
log_error() {
|
||||
printf '%s\n' "ERROR: $*" >&2
|
||||
}
|
||||
|
||||
die() {
|
||||
log_error "$*"
|
||||
if [ "${VERBOSE_ERRORS:-true}" = "true" ]; then
|
||||
echo "" >&2
|
||||
echo "Stack trace (last 10 commands):" >&2
|
||||
if [ -n "${BASH_VERSION:-}" ]; then
|
||||
history | tail -10 >&2 2>/dev/null || true
|
||||
fi
|
||||
echo "" >&2
|
||||
echo "Environment:" >&2
|
||||
echo " PWD: $(pwd)" >&2
|
||||
echo " USER: ${USER:-unknown}" >&2
|
||||
echo " SHELL: ${SHELL:-unknown}" >&2
|
||||
echo " CI: ${CI:-false}" >&2
|
||||
echo "" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Validation helpers
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
assert_file_exists() {
|
||||
[ -f "$1" ] || die "Required file missing: $1"
|
||||
}
|
||||
|
||||
assert_dir_exists() {
|
||||
[ -d "$1" ] || die "Required directory missing: $1"
|
||||
}
|
||||
|
||||
assert_non_empty() {
|
||||
[ -n "${1:-}" ] || die "Expected non empty value"
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Path helpers
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
script_root() {
|
||||
cd "$(dirname "$0")/.." && pwd
|
||||
}
|
||||
|
||||
normalize_path() {
|
||||
printf '%s\n' "$1" | sed 's|\\|/|g'
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# JSON utilities
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
json_escape() {
|
||||
require_cmd python3
|
||||
python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$1"
|
||||
}
|
||||
|
||||
json_output() {
|
||||
local status="$1"
|
||||
shift
|
||||
require_cmd python3
|
||||
python3 - <<PY "$status" "$@"
|
||||
import json
|
||||
import sys
|
||||
status = sys.argv[1]
|
||||
pairs = sys.argv[2:]
|
||||
data = {"status": status}
|
||||
for pair in pairs:
|
||||
if "=" in pair:
|
||||
k, v = pair.split("=", 1)
|
||||
data[k] = v
|
||||
print(json.dumps(data, ensure_ascii=False))
|
||||
PY
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Guardrails
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
fail_if_root() {
|
||||
[ "$(id -u)" -eq 0 ] && die "Script must not run as root"
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Enterprise features
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# Check for required dependencies at script start
|
||||
check_dependencies() {
|
||||
local missing=0
|
||||
local missing_cmds=()
|
||||
|
||||
for cmd in "$@"; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
log_error "Required command not found: $cmd"
|
||||
missing=$((missing + 1))
|
||||
missing_cmds+=("$cmd")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$missing" -gt 0 ]; then
|
||||
echo "" >&2
|
||||
echo "Missing required dependencies:" >&2
|
||||
for cmd in "${missing_cmds[@]}"; do
|
||||
echo " - $cmd" >&2
|
||||
done
|
||||
echo "" >&2
|
||||
echo "Installation guides:" >&2
|
||||
for cmd in "${missing_cmds[@]}"; do
|
||||
case "$cmd" in
|
||||
python3)
|
||||
echo " python3: apt-get install python3 (Debian/Ubuntu) or brew install python3 (macOS)" >&2
|
||||
;;
|
||||
git)
|
||||
echo " git: apt-get install git (Debian/Ubuntu) or brew install git (macOS)" >&2
|
||||
;;
|
||||
php)
|
||||
echo " php: apt-get install php-cli (Debian/Ubuntu) or brew install php (macOS)" >&2
|
||||
;;
|
||||
xmllint)
|
||||
echo " xmllint: apt-get install libxml2-utils (Debian/Ubuntu) or brew install libxml2 (macOS)" >&2
|
||||
;;
|
||||
*)
|
||||
echo " $cmd: Please install via your system package manager" >&2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo "" >&2
|
||||
die "Missing $missing required command(s)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Timeout wrapper for long-running commands
|
||||
run_with_timeout() {
|
||||
local timeout="$1"
|
||||
shift
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
timeout "$timeout" "$@"
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Add script execution timestamp
|
||||
log_timestamp() {
|
||||
if command -v date >/dev/null 2>&1; then
|
||||
printf '%s\n' "$(date -u '+%Y-%m-%d %H:%M:%S UTC')"
|
||||
fi
|
||||
}
|
||||
|
||||
# Calculate and log execution duration
|
||||
log_duration() {
|
||||
local start="$1"
|
||||
local end="$2"
|
||||
local duration=$((end - start))
|
||||
if [ "$duration" -ge 60 ]; then
|
||||
local minutes=$((duration / 60))
|
||||
local seconds=$((duration % 60))
|
||||
printf '%dm %ds\n' "$minutes" "$seconds"
|
||||
else
|
||||
printf '%ds\n' "$duration"
|
||||
fi
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# ============================================================================
|
||||
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
|
||||
#
|
||||
# This file is part of a Moko Consulting project.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program (./LICENSE.md).
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# FILE INFORMATION
|
||||
# ============================================================================
|
||||
# DEFGROUP: Script.Library
|
||||
# INGROUP: Joomla.Manifest
|
||||
# REPO: https://github.com/mokoconsulting-tech
|
||||
# PATH: /scripts/lib/joomla_manifest.sh
|
||||
# VERSION: 01.00.00
|
||||
# BRIEF: Joomla manifest parsing and validation utilities
|
||||
# NOTE: Provides reusable functions for working with Joomla extension manifests
|
||||
# ============================================================================
|
||||
|
||||
set -eu
|
||||
|
||||
# Resolve script directory properly - works when sourced
|
||||
if [ -n "${SCRIPT_DIR:-}" ]; then
|
||||
# Already set by caller
|
||||
SCRIPT_LIB_DIR="${SCRIPT_DIR}/lib"
|
||||
else
|
||||
# Determine from this file's location
|
||||
SCRIPT_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
||||
fi
|
||||
|
||||
# Shared utilities
|
||||
. "${SCRIPT_LIB_DIR}/common.sh"
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Manifest discovery
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# Find the primary Joomla manifest in the given directory
|
||||
# Usage: find_manifest <src_dir>
|
||||
# Returns: path to manifest file or exits with error
|
||||
find_manifest() {
|
||||
local src_dir="${1:-src}"
|
||||
|
||||
[ -d "${src_dir}" ] || die "Source directory missing: ${src_dir}"
|
||||
|
||||
# Candidate discovery policy: prefer explicit known names
|
||||
local candidates=""
|
||||
|
||||
# Template
|
||||
if [ -f "${src_dir}/templateDetails.xml" ]; then
|
||||
candidates="${src_dir}/templateDetails.xml"
|
||||
fi
|
||||
|
||||
# Package
|
||||
if [ -z "${candidates}" ]; then
|
||||
candidates="$(find "${src_dir}" -maxdepth 4 -type f -name 'pkg_*.xml' 2>/dev/null | head -1 || true)"
|
||||
fi
|
||||
|
||||
# Component
|
||||
if [ -z "${candidates}" ]; then
|
||||
candidates="$(find "${src_dir}" -maxdepth 4 -type f -name 'com_*.xml' 2>/dev/null | head -1 || true)"
|
||||
fi
|
||||
|
||||
# Module
|
||||
if [ -z "${candidates}" ]; then
|
||||
candidates="$(find "${src_dir}" -maxdepth 4 -type f -name 'mod_*.xml' 2>/dev/null | head -1 || true)"
|
||||
fi
|
||||
|
||||
# Plugin
|
||||
if [ -z "${candidates}" ]; then
|
||||
candidates="$(find "${src_dir}" -maxdepth 6 -type f -name 'plg_*.xml' 2>/dev/null | head -1 || true)"
|
||||
fi
|
||||
|
||||
# Fallback: any XML containing <extension ...>
|
||||
if [ -z "${candidates}" ]; then
|
||||
candidates="$(grep -Rsl --include='*.xml' '<extension' "${src_dir}" 2>/dev/null | head -1 || true)"
|
||||
fi
|
||||
|
||||
[ -n "${candidates}" ] || die "No Joomla manifest XML found under ${src_dir}"
|
||||
[ -s "${candidates}" ] || die "Manifest is empty: ${candidates}"
|
||||
|
||||
printf '%s\n' "${candidates}"
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Manifest parsing
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# Extract version from manifest XML
|
||||
# Usage: get_manifest_version <manifest_path>
|
||||
# Returns: version string or exits with error
|
||||
get_manifest_version() {
|
||||
local manifest="$1"
|
||||
|
||||
[ -f "${manifest}" ] || die "Manifest not found: ${manifest}"
|
||||
|
||||
require_cmd python3
|
||||
|
||||
python3 - "${manifest}" <<'PY'
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
manifest_path = sys.argv[1]
|
||||
|
||||
try:
|
||||
tree = ET.parse(manifest_path)
|
||||
root = tree.getroot()
|
||||
version_el = root.find("version")
|
||||
if version_el is not None and version_el.text:
|
||||
print(version_el.text.strip())
|
||||
sys.exit(0)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sys.exit(1)
|
||||
PY
|
||||
}
|
||||
|
||||
# Extract extension name from manifest XML
|
||||
# Usage: get_manifest_name <manifest_path>
|
||||
# Returns: name string or exits with error
|
||||
get_manifest_name() {
|
||||
local manifest="$1"
|
||||
|
||||
[ -f "${manifest}" ] || die "Manifest not found: ${manifest}"
|
||||
|
||||
require_cmd python3
|
||||
|
||||
python3 - "${manifest}" <<'PY'
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
manifest_path = sys.argv[1]
|
||||
|
||||
try:
|
||||
tree = ET.parse(manifest_path)
|
||||
root = tree.getroot()
|
||||
name_el = root.find("name")
|
||||
if name_el is not None and name_el.text:
|
||||
print(name_el.text.strip())
|
||||
sys.exit(0)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sys.exit(1)
|
||||
PY
|
||||
}
|
||||
|
||||
# Extract extension type from manifest XML
|
||||
# Usage: get_manifest_type <manifest_path>
|
||||
# Returns: type string (template, component, module, plugin, etc.) or exits with error
|
||||
get_manifest_type() {
|
||||
local manifest="$1"
|
||||
|
||||
[ -f "${manifest}" ] || die "Manifest not found: ${manifest}"
|
||||
|
||||
require_cmd python3
|
||||
|
||||
python3 - "${manifest}" <<'PY'
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
manifest_path = sys.argv[1]
|
||||
|
||||
try:
|
||||
tree = ET.parse(manifest_path)
|
||||
root = tree.getroot()
|
||||
ext_type = root.attrib.get("type", "").strip().lower()
|
||||
if ext_type:
|
||||
print(ext_type)
|
||||
sys.exit(0)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sys.exit(1)
|
||||
PY
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# ============================================================================
|
||||
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
|
||||
#
|
||||
# This file is part of a Moko Consulting project.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program (./LICENSE.md).
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# FILE INFORMATION
|
||||
# ============================================================================
|
||||
# DEFGROUP: Script.Library
|
||||
# INGROUP: Logging
|
||||
# REPO: https://github.com/mokoconsulting-tech
|
||||
# PATH: /scripts/lib/logging.sh
|
||||
# VERSION: 01.00.00
|
||||
# BRIEF: Enhanced logging utilities with structured output support
|
||||
# NOTE: Provides colored output, log levels, and structured logging
|
||||
# ============================================================================
|
||||
|
||||
set -eu
|
||||
|
||||
# Resolve script directory properly - works when sourced
|
||||
if [ -n "${SCRIPT_DIR:-}" ]; then
|
||||
# Already set by caller
|
||||
SCRIPT_LIB_DIR="${SCRIPT_DIR}/lib"
|
||||
else
|
||||
# Determine from this file's location
|
||||
SCRIPT_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
||||
fi
|
||||
|
||||
# Shared utilities
|
||||
. "${SCRIPT_LIB_DIR}/common.sh"
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Color codes (if terminal supports it)
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# Check if we're in a terminal and colors are supported
|
||||
use_colors() {
|
||||
[ -t 1 ] && [ "${CI:-false}" != "true" ]
|
||||
}
|
||||
|
||||
if use_colors; then
|
||||
COLOR_RESET='\033[0m'
|
||||
COLOR_RED='\033[0;31m'
|
||||
COLOR_YELLOW='\033[0;33m'
|
||||
COLOR_GREEN='\033[0;32m'
|
||||
COLOR_BLUE='\033[0;34m'
|
||||
COLOR_CYAN='\033[0;36m'
|
||||
else
|
||||
COLOR_RESET=''
|
||||
COLOR_RED=''
|
||||
COLOR_YELLOW=''
|
||||
COLOR_GREEN=''
|
||||
COLOR_BLUE=''
|
||||
COLOR_CYAN=''
|
||||
fi
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Enhanced logging functions
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
log_debug() {
|
||||
if [ "${DEBUG:-false}" = "true" ]; then
|
||||
printf '%b[DEBUG]%b %s\n' "${COLOR_CYAN}" "${COLOR_RESET}" "$*"
|
||||
fi
|
||||
}
|
||||
|
||||
log_success() {
|
||||
printf '%b[SUCCESS]%b %s\n' "${COLOR_GREEN}" "${COLOR_RESET}" "$*"
|
||||
}
|
||||
|
||||
log_step() {
|
||||
printf '%b[STEP]%b %s\n' "${COLOR_BLUE}" "${COLOR_RESET}" "$*"
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Structured logging
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# Log a key-value pair
|
||||
log_kv() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
printf ' %b%s:%b %s\n' "${COLOR_BLUE}" "${key}" "${COLOR_RESET}" "${value}"
|
||||
}
|
||||
|
||||
# Log a list item
|
||||
log_item() {
|
||||
printf ' %b•%b %s\n' "${COLOR_GREEN}" "${COLOR_RESET}" "$*"
|
||||
}
|
||||
|
||||
# Log a separator line
|
||||
log_separator() {
|
||||
printf '%s\n' "========================================="
|
||||
}
|
||||
|
||||
# Log a section header
|
||||
log_section() {
|
||||
printf '\n%b=== %s ===%b\n' "${COLOR_BLUE}" "$*" "${COLOR_RESET}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user