diff --git a/src/octojpack b/src/octojpack
index 24ca3b8..09e88df 100755
--- a/src/octojpack
+++ b/src/octojpack
@@ -3,8 +3,8 @@
# Program name
PROGRAM_NAME="Octojpack"
PROGRAM_CODE="octojpack"
-PROGRAM_VERSION="1.2.0"
-PROGRAM_V="1.2"
+PROGRAM_VERSION="1.3.0"
+PROGRAM_V="1.3"
PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}"
# Do some prep work
@@ -20,10 +20,14 @@ command -v jq >/dev/null 2>&1 || {
echo >&2 "[error] We require jq for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting."
exit 1
}
+command -v unzip >/dev/null 2>&1 || {
+ echo >&2 "[error] We require unzip for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not installed. Aborting."
+ exit 1
+}
# main function ˘Ô≈ôﺣ
function main() {
- # check if we have project overides for the environment variables
+ # check if we have project overrides for the environment variables
# shellcheck disable=SC2015
[ -f "$VDM_PACKAGE_CONF_FILE" ] && getProjectEnvironment || {
echo >&2 "[error] We require config file with correct packaging details for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not found in/at $VDM_PACKAGE_CONF_FILE. Aborting."
@@ -575,30 +579,52 @@ function getFileByReleases() {
# get the file by key
function getFileByKey() {
+ # set some local values
+ local folder_path
+ local zip_name
# get the name
VDM_ZIP_NAME="${VDM_MODE}"
# get the message
VDM_ZIP_MESSAGE="${VDM_MODE}"
- # get the name
- setValueFromJson "VDM_ZIP_VERSION" ".[0].name" "${VDM_API_BUCKET}" || {
- _echo "[error] Tag name not found in VDM_API_BUCKET. (but ignored since we are getting file by key)"
- VDM_ZIP_VERSION="${VDM_MODE}"
- }
+ # set the zip name
+ zip_name="${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip"
+ # set the folder path
+ folder_path="${VDM_OWNER}_${VDM_REPO}_${VDM_ZIP_NAME}"
# download the zip file if not already set
- if [ ! -f "${VDM_PACKAGE_SRC_DIR}/${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip" ]; then
+ if [ ! -f "${VDM_PACKAGE_SRC_DIR}/${zip_name}" ]; then
# give message
_echo "[info] Downloading the (${VDM_OWNER}-${VDM_REPO}-${VDM_ZIP_NAME}.zip) package."
# download the zip file
- curl -s -H "Authorization: token ${VDM_TOKEN}" -L "${VDM_API}/repos/${VDM_OWNER}/${VDM_REPO}/archive/${VDM_ZIP_NAME}.zip" -o "${VDM_PACKAGE_SRC_DIR}/${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip"
+ curl -s -H "Authorization: token ${VDM_TOKEN}" -L "${VDM_API}/repos/${VDM_OWNER}/${VDM_REPO}/archive/${VDM_ZIP_NAME}.zip" -o "${VDM_PACKAGE_SRC_DIR}/${zip_name}"
else
# zip already set
- _echo "[error] ${VDM_OWNER}__${VDM_REPO}__${VDM_ZIP_NAME}.zip already set."
+ _echo "[error] ${zip_name} already set."
return 12
fi
+ # unzip this zip file
+ _unzip "${zip_name}" "${folder_path}" || {
+ _echo "[error] We encountered and error, we could not unzip (${VDM_PACKAGE_SRC_DIR}/${zip_name}) in to (${VDM_PACKAGE_GIT_DIR}/${folder_path})"
+ # so we skip this package
+ return 12
+ }
+ # check if we have a folder to access
+ if ! cd "${VDM_PACKAGE_GIT_DIR}/${folder_path}"; then
+ _echo "[error] We could not open the package folder."
+ exit 13
+ fi
+ # get the version from the current directory
+ _xml_version || {
+ _echo "[error] Version name not found in package. (but ignored since we are getting file by key)"
+ VDM_ZIP_VERSION="${VDM_MODE}"
+ export VDM_ZIP_VERSION
+ }
+ # move out of the directory
+ cd "${VDM_MAIN_DIR}" || exit 13
+ # always remove the package folder again
+ rm -fr "${VDM_PACKAGE_GIT_DIR:?}/${folder_path:?}"
# move the tag values to global scope
export VDM_ZIP_NAME
export VDM_ZIP_MESSAGE
- export VDM_ZIP_VERSION
# add file to xml
setFileToXML
# update the readme
@@ -1142,6 +1168,62 @@ function getUniqueFileName() {
echo "${hash:0:10}"
}
+# get the version from the current directory
+function _xml_version() {
+ local version
+ local len=100
+ local file
+ local v
+ local e
+ 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 '(?<=\).*?(?=\)' "$file")
+ # Check if the file is an update server file (which should not be used).
+ e=$(grep -o -P '\/dev/null 2>&1; then
+ _echo "[info] Successfully unzipped the package ($zip_name)"
+ return 0
+ fi
+
+ # Return 1 if the unzip operation was unsuccessful.
+ return 1
+}
+
# uninstalls the octojpack program.
function runUninstall() {
# now remove the script