6 Commits

Author SHA1 Message Date
3e0cdc9628 Update version to 1.3.4 and optimize XML version detection
Bumped the program version from 1.3.3 to 1.3.4. Simplified and improved the _xml_version function for better clarity, performance, and accuracy in finding the shortest depth XML version. Updated the URL structure for fetching the latest script during updates to align with GitHub's raw content.
2025-03-19 11:14:47 +02:00
ce947c5826 Add limit on data set returned when tags are used 2024-08-21 23:00:02 +02:00
ee4b5003cd Make sure we have the right branch. 2024-05-21 17:11:34 +02:00
5aa4369f83 changed to declare to set global values. 2024-05-18 22:08:23 +02:00
69738f8be6 Add bash logo, written by, linted by to README. 2024-03-20 16:30:31 +02:00
0cacdd8ed5 Fix versioning in xml 2024-03-02 18:50:51 +02:00
2 changed files with 67 additions and 58 deletions

View File

@ -1,12 +1,18 @@
# Octojpack - Easy Joomla Extension Packaging <h2><img align="middle" src="https://raw.githubusercontent.com/odb/official-bash-logo/master/assets/Logos/Icons/PNG/64x64.png" >
Octojpack - Easy Joomla Extension Packaging
</h2>
Written by Llewellyn van der Merwe (@llewellynvdm)
With this script we can easily package multiple extensions in an automated way from a json configuration file, and environment variables. With this script we can easily package multiple extensions in an automated way from a json configuration file, and environment variables.
Linted by [#ShellCheck](https://github.com/koalaman/shellcheck)
> program only for ubuntu/debian and Gitea systems at this time (should you like to use it on other OS's please open and issue...) > program only for ubuntu/debian and Gitea systems at this time (should you like to use it on other OS's please open and issue...)
--- ---
# Install # Install
```shell ```shell
$ sudo curl -L "https://git.vdm.dev/api/v1/repos/octoleo/octojpack/raw/src/octojpack" -o /usr/local/bin/octojpack $ sudo curl -L "https://raw.githubusercontent.com/octoleo/octojpack/refs/heads/master/src/octojpack" -o /usr/local/bin/octojpack
$ sudo chmod +x /usr/local/bin/octojpack $ sudo chmod +x /usr/local/bin/octojpack
``` ```
--- ---

View File

@ -3,7 +3,7 @@
# Program name # Program name
PROGRAM_NAME="Octojpack" PROGRAM_NAME="Octojpack"
PROGRAM_CODE="octojpack" PROGRAM_CODE="octojpack"
PROGRAM_VERSION="1.3.0" PROGRAM_VERSION="1.3.4"
PROGRAM_V="1.3" PROGRAM_V="1.3"
PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}" PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}"
@ -249,7 +249,7 @@ function setValueFromJson() {
} }
# Safely use eval to dynamically set the value # Safely use eval to dynamically set the value
eval "$target_var"=\'"$value"\' declare -g "$target_var"="$value"
} }
# Get value from JSON # Get value from JSON
@ -680,12 +680,20 @@ function callGiteaAPI() {
local token="${5}" local token="${5}"
local json_data local json_data
local message local message
local url
# each time reset # each time reset
unset VDM_API_BUCKET unset VDM_API_BUCKET
# give message # give message
_echo "[info] Getting ${mode} information from ${owner}/${repo} repository." _echo "[info] Getting ${mode} information from ${owner}/${repo} repository."
# get the json data # get the json data
json_data=$(curl -s -H "Authorization: token ${token}" -H 'accept: application/json' -X 'GET' "${api}/repos/${owner}/${repo}/${mode}") # Check if mode is "tags"
if [ "${mode}" = "tags" ]; then
url="${api}/repos/${owner}/${repo}/${mode}?page=1"
else
url="${api}/repos/${owner}/${repo}/${mode}"
fi
# get the json data
json_data=$(curl -s -H "Authorization: token ${token}" -H 'accept: application/json' -X 'GET' "${url}")
# check for error # check for error
if [[ "${json_data}" =~ '"errors"' ]] && [[ "${json_data}" =~ '"message"' ]]; then if [[ "${json_data}" =~ '"errors"' ]] && [[ "${json_data}" =~ '"message"' ]]; then
# get the message # get the message
@ -795,10 +803,9 @@ function setPackageXml() {
_echo "[info] Setting the Package XML..." _echo "[info] Setting the Package XML..."
# set the local version # set the local version
local version local version
# remove all but numbers and points # remove the v in front of the version (number-state-number)
# TODO we need to allow only stable versions (when getting the tags) version="${VDM_PACKAGE_VERSION:-1.0.0}"
# shellcheck disable=SC2001 version="${version/#v/}"
version=$(echo "${VDM_PACKAGE_VERSION:-1.0.0}" | sed 's/[^0-9.]//g')
# add the package details # add the package details
{ {
echo '<?xml version="1.0" encoding="utf-8"?>' echo '<?xml version="1.0" encoding="utf-8"?>'
@ -1005,8 +1012,6 @@ function setRepository() {
if $update_repo && [[ -z $(git status --porcelain) ]]; then if $update_repo && [[ -z $(git status --porcelain) ]]; then
_echo "[info] No changes found in (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" _echo "[info] No changes found in (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository"
else else
# add user details
setUserDetails
# check if we must update or create repository # check if we must update or create repository
if $update_repo; then if $update_repo; then
# make API call # make API call
@ -1019,6 +1024,8 @@ function setRepository() {
else else
message="Update" message="Update"
fi fi
# add user details
setUserDetails
# get the repository last tag # get the repository last tag
makeGitCommit "${message}" "${VDM_PACKAGE_VERSION:-1.0.0}" "$VDM_TAG_EXIST" || return 28 makeGitCommit "${message}" "${VDM_PACKAGE_VERSION:-1.0.0}" "$VDM_TAG_EXIST" || return 28
# give little notice of progress # give little notice of progress
@ -1034,7 +1041,11 @@ function setRepository() {
# give little notice of progress # give little notice of progress
_echo "[info] Pushing (TO CREATE) changes to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" _echo "[info] Pushing (TO CREATE) changes to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository"
# push to creat the repository (if allowed) # push to creat the repository (if allowed)
if [[ "${VDM_PACKAGE_REPO_BRANCH}" == 'default' ]]; then
git push -u origin master >/dev/null 2>&1 || return 30 git push -u origin master >/dev/null 2>&1 || return 30
else
git push -u origin "${VDM_PACKAGE_REPO_BRANCH:-master}" >/dev/null 2>&1 || return 30
fi
git push --tags >/dev/null 2>&1 || return 30 git push --tags >/dev/null 2>&1 || return 30
fi fi
fi fi
@ -1051,7 +1062,7 @@ function getExistingRepository() {
git clone "ssh://git@${VDM_PACKAGE_URL}/${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 23 git clone "ssh://git@${VDM_PACKAGE_URL}/${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 23
else else
# clone the existing repository # clone the existing repository
git clone -b "${VDM_PACKAGE_REPO_BRANCH}" "ssh://git@${VDM_PACKAGE_URL}/${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 23 git clone -b "${VDM_PACKAGE_REPO_BRANCH:-master}" "ssh://git@${VDM_PACKAGE_URL}/${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 23
fi fi
# success # success
return 0 return 0
@ -1073,6 +1084,8 @@ function setGitRepository() {
_echo "[info] Initializing the (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository" _echo "[info] Initializing the (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository"
# initialize the repository # initialize the repository
git init >/dev/null 2>&1 || return 29 git init >/dev/null 2>&1 || return 29
# add user details
setUserDetails
# add the first commit # add the first commit
makeGitCommit "First Commit - ${VDM_PACKAGE_VERSION:-1.0.0}" "${VDM_PACKAGE_VERSION:-1.0.0}" >/dev/null 2>&1 || return 28 makeGitCommit "First Commit - ${VDM_PACKAGE_VERSION:-1.0.0}" "${VDM_PACKAGE_VERSION:-1.0.0}" >/dev/null 2>&1 || return 28
# little information of progress # little information of progress
@ -1170,56 +1183,46 @@ function getUniqueFileName() {
# get the version from the current directory # get the version from the current directory
function _xml_version() { function _xml_version() {
local version local version=""
local len=100 local shortest_depth=100
local file local file
local v local v
local e local depth
local p
# Create a list of all XML files in the current directory. # Find XML files excluding config.xml, access.xml, default.xml
find . -type f -name '*.xml' > tmp while IFS= read -r file; do
# Loop through the list of XML files. # Ensure file does not match exclusions
while IFS= read -r file case "$file" in
do *config.xml|*access.xml|*default.xml) continue ;;
# Skip XML files named config.xml, access.xml, or default.xml. esac
if [[ "$file" == *"config.xml" ]] || [[ "$file" == *"access.xml" ]] || [[ "$file" == *"default.xml" ]]; then
continue # Ensure it's an extension XML and not an update XML
fi grep -q '<extension' "$file" || continue
# Retrieve the version number from the XML file.
v=$(grep -o -P '(?<=\<version>).*?(?=\</version>)' "$file") # Extract version if present in XML
# Check if the file is an update server file (which should not be used). v=$(sed -n 's|.*<version>\([^<]*\)</version>.*|\1|p' "$file")
e=$(grep -o -P '\<extension' "$file")
# If a version number have been retrieved, and the file is not an update server file, continue processing. # Determine folder depth (count slashes)
if [ -n "$v" ] && [ -n "$e" ]; then depth=$(awk -F'/' '{print NF}' <<< "$file")
# Count the folder depth.
# shellcheck disable=SC2001 # Choose the file with the shortest path (highest in folder stack)
p=$(echo "$file" | sed 's|[^/]||g') if [[ -n "$v" && "$depth" -lt "$shortest_depth" ]]; then
# Keep the value of the shortest path. shortest_depth="$depth"
if [[ "${#p}" -lt $len ]]; then
# Update the length.
len="${#p}"
# Set the version.
version="$v" version="$v"
fi fi
fi
# Clear variables for each loop.
unset v
unset n
unset e
done < tmp
# Clear variables for each loop. done < <(find . -type f -name '*.xml')
rm tmp
# If a version number was found and starts with v # Return failure if no version is found
if [ -z "$version" ]; then if [[ -z "$version" ]]; then
return 14 return 14
elif [[ $version != v* ]]; then
version="v${version}"
fi fi
VDM_ZIP_VERSION="$version" # Ensure version starts with 'v'
export VDM_ZIP_VERSION [[ $version != v* ]] && version="v${version}"
# Export version
export VDM_ZIP_VERSION="$version"
return 0 return 0
} }
@ -1294,7 +1297,7 @@ function runUpdate() {
sudo mv "/usr/local/bin/${PROGRAM_CODE}" "/usr/local/bin/${PROGRAM_CODE}.bak" sudo mv "/usr/local/bin/${PROGRAM_CODE}" "/usr/local/bin/${PROGRAM_CODE}.bak"
fi fi
# pull the latest version. Master is always the latest # pull the latest version. Master is always the latest
if sudo curl --fail -L "https://git.vdm.dev/api/v1/repos/octoleo/${PROGRAM_CODE}/raw/src/${PROGRAM_CODE}?ref=${branch:-master}" -o "/usr/local/bin/${PROGRAM_CODE}" 2>/dev/null; then if sudo curl --fail -L "https://raw.githubusercontent.com/octoleo/${PROGRAM_CODE}/refs/heads/${branch:-master}/src/${PROGRAM_CODE}" -o "/usr/local/bin/${PROGRAM_CODE}" 2>/dev/null; then
# give success message # give success message
echo "[success] Update was successful." echo "[success] Update was successful."
# do we have a backup # do we have a backup