Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
54227596c2
|
|||
f480b6f1f3
|
|||
052353765d
|
|||
288f45832c
|
|||
3e0cdc9628
|
|||
ce947c5826
|
@ -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
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
115
src/octojpack
115
src/octojpack
@ -3,7 +3,7 @@
|
|||||||
# Program name
|
# Program name
|
||||||
PROGRAM_NAME="Octojpack"
|
PROGRAM_NAME="Octojpack"
|
||||||
PROGRAM_CODE="octojpack"
|
PROGRAM_CODE="octojpack"
|
||||||
PROGRAM_VERSION="1.3.2"
|
PROGRAM_VERSION="1.3.8"
|
||||||
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,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
|
||||||
@ -987,7 +995,7 @@ function setRepository() {
|
|||||||
# check if the repository exist on our gitea instance
|
# check if the repository exist on our gitea instance
|
||||||
local update_repo
|
local update_repo
|
||||||
# shellcheck disable=SC2015
|
# shellcheck disable=SC2015
|
||||||
if git ls-remote "ssh://git@${VDM_PACKAGE_URL}/${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" -q >/dev/null 2>&1; then
|
if git ls-remote --exit-code --heads "git@${VDM_PACKAGE_URL}:${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1; then
|
||||||
getExistingRepository || return 23
|
getExistingRepository || return 23
|
||||||
update_repo=true
|
update_repo=true
|
||||||
else
|
else
|
||||||
@ -1001,13 +1009,11 @@ function setRepository() {
|
|||||||
# move all new files into repository
|
# move all new files into repository
|
||||||
setRepositoryNewFiles || return 27
|
setRepositoryNewFiles || return 27
|
||||||
# check if we have changes
|
# check if we have changes
|
||||||
if $update_repo && [[ -z $(git status --porcelain) ]]; then
|
if [[ "${update_repo}" == true && -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}" == true ]]; then
|
||||||
# make API call
|
# make API call
|
||||||
callGiteaAPI "tags" "${VDM_PACKAGE_OWNER}" "${VDM_PACKAGE_REPO}" "${VDM_PACKAGE_API}" "${VDM_PACKAGE_TOKEN}" || return 28
|
callGiteaAPI "tags" "${VDM_PACKAGE_OWNER}" "${VDM_PACKAGE_REPO}" "${VDM_PACKAGE_API}" "${VDM_PACKAGE_TOKEN}" || return 28
|
||||||
# check if tag exists
|
# check if tag exists
|
||||||
@ -1018,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
|
||||||
@ -1051,10 +1059,10 @@ function getExistingRepository() {
|
|||||||
_echo "[info] Getting (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository"
|
_echo "[info] Getting (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository"
|
||||||
if [[ "${VDM_PACKAGE_REPO_BRANCH}" == 'default' ]]; then
|
if [[ "${VDM_PACKAGE_REPO_BRANCH}" == 'default' ]]; then
|
||||||
# clone the existing repository
|
# clone the existing repository
|
||||||
git clone "ssh://git@${VDM_PACKAGE_URL}/${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 23
|
git clone "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:-master}" "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}" "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
|
||||||
@ -1076,12 +1084,14 @@ 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
|
||||||
_echo "[info] Adding remote branch to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository"
|
_echo "[info] Adding remote branch to (${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}) repository"
|
||||||
# add the remote branch
|
# add the remote branch
|
||||||
git remote add origin "ssh://git@${VDM_PACKAGE_URL}/${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 29
|
git remote add origin "git@${VDM_PACKAGE_URL}:${VDM_PACKAGE_OWNER}/${VDM_PACKAGE_REPO}.git" >/dev/null 2>&1 || return 29
|
||||||
# Check if a specific branch is set and it is not 'default'
|
# Check if a specific branch is set and it is not 'default'
|
||||||
if [ "${VDM_PACKAGE_REPO_BRANCH}" != "default" ]; then
|
if [ "${VDM_PACKAGE_REPO_BRANCH}" != "default" ]; then
|
||||||
_echo "[info] Setting branch to ${VDM_PACKAGE_REPO_BRANCH}"
|
_echo "[info] Setting branch to ${VDM_PACKAGE_REPO_BRANCH}"
|
||||||
@ -1171,58 +1181,57 @@ function getUniqueFileName() {
|
|||||||
echo "${hash:0:10}"
|
echo "${hash:0:10}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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
|
|
||||||
|
# Ensure it's an extension XML (check if it has a <extension> root tag anywhere)
|
||||||
|
if ! grep -iq '^[[:space:]]*<extension[[:space:]>]' "$file"; then
|
||||||
continue
|
continue
|
||||||
fi
|
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.
|
# Extract version if present in XML
|
||||||
rm tmp
|
v=$(sed -n 's|.*<version>\(.*\)</version>.*|\1|p' "$file" | head -n1)
|
||||||
|
|
||||||
# If a version number was found and starts with v
|
# Skip if no version found
|
||||||
if [ -z "$version" ]; then
|
[[ -z "$v" ]] && continue
|
||||||
|
|
||||||
|
# Determine folder depth (count slashes)
|
||||||
|
depth=$(tr -cd '/' <<< "$file" | wc -c)
|
||||||
|
|
||||||
|
# Choose the file with the shortest path (highest in folder stack)
|
||||||
|
if (( depth < shortest_depth )); then
|
||||||
|
shortest_depth=$depth
|
||||||
|
version=$v
|
||||||
|
|
||||||
|
# Since we want the highest-up file, and this is the shallowest so far,
|
||||||
|
# we can break early if it's at root level (depth 1)
|
||||||
|
(( depth <= 1 )) && break
|
||||||
|
fi
|
||||||
|
|
||||||
|
done < <(find . -type f -iname '*.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
|
||||||
}
|
}
|
||||||
@ -1297,7 +1306,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