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.
This commit is contained in:
@@ -12,7 +12,7 @@ Linted by [#ShellCheck](https://github.com/koalaman/shellcheck)
|
|||||||
---
|
---
|
||||||
# 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
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
@@ -144,4 +144,4 @@ $ octojpack --uninstall
|
|||||||
```txt
|
```txt
|
||||||
@copyright Copyright (C) 2021 Llewellyn van der Merwe. All rights reserved.
|
@copyright Copyright (C) 2021 Llewellyn van der Merwe. All rights reserved.
|
||||||
@license GNU General Public License version 2; see LICENSE
|
@license GNU General Public License version 2; see LICENSE
|
||||||
```
|
```
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
# Program name
|
# Program name
|
||||||
PROGRAM_NAME="Octojpack"
|
PROGRAM_NAME="Octojpack"
|
||||||
PROGRAM_CODE="octojpack"
|
PROGRAM_CODE="octojpack"
|
||||||
PROGRAM_VERSION="1.3.3"
|
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}"
|
||||||
|
|
||||||
@@ -680,6 +680,7 @@ 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
|
||||||
@@ -1182,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 . -type f -name '*.xml' > tmp
|
|
||||||
# Loop through the list of XML files.
|
|
||||||
while IFS= read -r file
|
|
||||||
do
|
|
||||||
# Skip XML files named config.xml, access.xml, or default.xml.
|
|
||||||
if [[ "$file" == *"config.xml" ]] || [[ "$file" == *"access.xml" ]] || [[ "$file" == *"default.xml" ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
# Retrieve the version number from the XML file.
|
|
||||||
v=$(grep -o -P '(?<=\<version>).*?(?=\</version>)' "$file")
|
|
||||||
# Check if the file is an update server file (which should not be used).
|
|
||||||
e=$(grep -o -P '\<extension' "$file")
|
|
||||||
# If a version number have been retrieved, and the file is not an update server file, continue processing.
|
|
||||||
if [ -n "$v" ] && [ -n "$e" ]; then
|
|
||||||
# Count the folder depth.
|
|
||||||
# shellcheck disable=SC2001
|
|
||||||
p=$(echo "$file" | sed 's|[^/]||g')
|
|
||||||
# Keep the value of the shortest path.
|
|
||||||
if [[ "${#p}" -lt $len ]]; then
|
|
||||||
# Update the length.
|
|
||||||
len="${#p}"
|
|
||||||
# Set the version.
|
|
||||||
version="$v"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# Clear variables for each loop.
|
|
||||||
unset v
|
|
||||||
unset n
|
|
||||||
unset e
|
|
||||||
done < tmp
|
|
||||||
|
|
||||||
# Clear variables for each loop.
|
# Find XML files excluding config.xml, access.xml, default.xml
|
||||||
rm tmp
|
while IFS= read -r file; do
|
||||||
|
# Ensure file does not match exclusions
|
||||||
|
case "$file" in
|
||||||
|
*config.xml|*access.xml|*default.xml) continue ;;
|
||||||
|
esac
|
||||||
|
|
||||||
# If a version number was found and starts with v
|
# Ensure it's an extension XML and not an update XML
|
||||||
if [ -z "$version" ]; then
|
grep -q '<extension' "$file" || continue
|
||||||
|
|
||||||
|
# Extract version if present in XML
|
||||||
|
v=$(sed -n 's|.*<version>\([^<]*\)</version>.*|\1|p' "$file")
|
||||||
|
|
||||||
|
# Determine folder depth (count slashes)
|
||||||
|
depth=$(awk -F'/' '{print NF}' <<< "$file")
|
||||||
|
|
||||||
|
# Choose the file with the shortest path (highest in folder stack)
|
||||||
|
if [[ -n "$v" && "$depth" -lt "$shortest_depth" ]]; then
|
||||||
|
shortest_depth="$depth"
|
||||||
|
version="$v"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done < <(find . -type f -name '*.xml')
|
||||||
|
|
||||||
|
# Return failure if no version is found
|
||||||
|
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
|
||||||
}
|
}
|
||||||
@@ -1306,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
|
||||||
|
Reference in New Issue
Block a user