This repository has been archived on 2024-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
joomla/bin/component_zip.sh

51 lines
1.4 KiB
Bash

#!/bin/bash
###################################################################################################
# INSTRUCTIONS
# Move to the directory of the component
# Run this script with component name (com_name)
###################################################################################################
# Check if the component name is provided as the first parameter
if [ -n "$1" ]; then
componentName="$1"
else
# Prompt for the name of the component
read -p "Enter the name of the component (including com_): " componentName
fi
# Check if the component name starts with 'com_'
if [[ $componentName != com_* ]]; then
echo "Invalid component name. The name should start with 'com_'"
exit 1
fi
# Check if the component folder exists
if [ ! -d "$componentName" ]; then
echo "Component folder '$componentName' does not exist."
exit 1
fi
# Extract the name by removing the first four characters
name="${componentName:4}"
# Read the contents of $name/$name.xml file
xml_file="$componentName/$name.xml"
if [ -f "$xml_file" ]; then
xml_contents=$(cat "$xml_file")
else
echo "XML file '$xml_file' not found."
exit 1
fi
# Extract the version from the XML contents
regex="<version>(.*?)<\/version>"
if [[ $xml_contents =~ $regex ]]; then
version="${BASH_REMATCH[1]}"
else
echo "Version not found in the XML file."
exit 1
fi
zip_filename="$name-$version.zip"
cd "$componentName" && 7z a "../$zip_filename" *