Files
2026-11-20 07:58:09 -05:00

201 lines
6.8 KiB
Bash
Executable File

#!/bin/bash
set -e
# either side can be any version the URL hook understands (e.g. "6.3", "beta", "beta-6.3.0.36") so two betas
# can be compared with: GA_OMADA_VER=beta-6.4.0.30 BETA_OMADA_VER=beta-6.4.0.33 ./compare_files.sh
# GA_URL/BETA_URL can also be set directly to skip the URL hook lookup entirely
GA_OMADA_VER="${GA_OMADA_VER:-6.3}"
BETA_OMADA_VER="${BETA_OMADA_VER:-beta}"
GA_URL="${GA_URL:-$(wget -q -O - "https://omada-controller-url.mbentley.net/hooks/omada_ver_to_url?omada-ver=${GA_OMADA_VER}")}"
BETA_URL="${BETA_URL:-$(wget -q -O - "https://omada-controller-url.mbentley.net/hooks/omada_ver_to_url?omada-ver=${BETA_OMADA_VER}")}"
if [ -z "${GA_URL}" ] || [ -z "${BETA_URL}" ]
then
echo "ERROR: unable to determine download URL(s) (GA_URL='${GA_URL}', BETA_URL='${BETA_URL}')"
exit 1
fi
# CACHE=true will store downloaded files in CACHE_DIR and reuse them on subsequent runs
CACHE="${CACHE:-true}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CACHE_DIR="${SCRIPT_DIR}/.cache"
# fetch a URL into DEST_DIR, using/populating CACHE_DIR when CACHE=true
download_file() {
local URL="$1"
local DEST_DIR="$2"
local FILENAME
FILENAME="$(basename "${URL}")"
if [ "${CACHE}" = "true" ] && [ -f "${CACHE_DIR}/${FILENAME}" ]
then
echo "INFO: found cached file, skipping download: ${FILENAME}"
cp "${CACHE_DIR}/${FILENAME}" "${DEST_DIR}/${FILENAME}"
return
fi
(cd "${DEST_DIR}" && wget -q --show-progress "${URL}")
if [ "${CACHE}" = "true" ]
then
mkdir -p "${CACHE_DIR}"
echo "INFO: caching downloaded file: ${FILENAME}"
cp "${DEST_DIR}/${FILENAME}" "${CACHE_DIR}/${FILENAME}"
fi
}
# extract a package in the current directory (may be a plain .tar.gz or a .tar.gz wrapped in a .zip)
extract_package() {
local PKG="$1"
case "${PKG}" in
*.zip)
unzip -q "${PKG}"
tar xzf ./*.tar.gz
;;
*.tar.gz)
tar xzf "${PKG}"
;;
*)
echo "ERROR: unknown file extension for package (${PKG})"
exit 1
;;
esac
}
# create temp directory
TEMP_DIR="$(mktemp -d)"
# cleanup temp directory on exit (handles errors and normal exits)
trap 'echo "INFO: cleaning up temp directory: ${TEMP_DIR}"; rm -rf "${TEMP_DIR}"' EXIT
cd "${TEMP_DIR}"
# create subdirectories for each version
mkdir -p ga beta
# download the latest versions
echo "INFO: downloading the latest GA and Beta versions..."
echo " GA URL: ${GA_URL}"
echo " BETA URL: ${BETA_URL}"
download_file "${GA_URL}" "${TEMP_DIR}/ga"
GA_TAR="$(ls "${TEMP_DIR}/ga")"
download_file "${BETA_URL}" "${TEMP_DIR}/beta"
BETA_TAR="$(ls "${TEMP_DIR}/beta")"
echo ""
# extract both versions
echo "INFO: extracting GA version..."
cd "${TEMP_DIR}/ga" || exit 1
extract_package "${GA_TAR}"
echo "INFO: extracting BETA version..."
cd "${TEMP_DIR}/beta" || exit 1
extract_package "${BETA_TAR}"
cd "${TEMP_DIR}" || exit 1
echo ""
# find the extracted directories (get just the directory names)
GA_DIR_NAME="$(cd ga && ls -d Omada_*/ 2>/dev/null | sed 's|/$||')"
BETA_DIR_NAME="$(cd beta && ls -d Omada_*/ 2>/dev/null | sed 's|/$||')"
echo "INFO: GA directory: ga/${GA_DIR_NAME}"
echo "INFO: BETA directory: beta/${BETA_DIR_NAME}"
echo ""
# compare install.sh files
echo "========================================"
echo "Comparing install.sh"
echo "========================================"
if git diff --no-index --color=always --src-prefix= --dst-prefix= \
"ga/${GA_DIR_NAME}/install.sh" "beta/${BETA_DIR_NAME}/install.sh"
then
echo "INFO: install.sh files are identical"
else
echo "INFO: install.sh files differ (see above)"
fi
echo ""
# compare properties/omada.properties files
echo "========================================"
echo "Comparing properties/omada.properties"
echo "========================================"
if git diff --no-index --color=always --src-prefix= --dst-prefix= \
"ga/${GA_DIR_NAME}/properties/omada.properties" "beta/${BETA_DIR_NAME}/properties/omada.properties"
then
echo "INFO: properties/omada.properties files are identical"
else
echo "INFO: properties/omada.properties files differ (see above)"
fi
echo ""
# compare bin/control.sh files
echo "========================================"
echo "Comparing bin/control.sh"
echo "========================================"
if git diff --no-index --color=always --src-prefix= --dst-prefix= \
"ga/${GA_DIR_NAME}/bin/control.sh" "beta/${BETA_DIR_NAME}/bin/control.sh"
then
echo "INFO: bin/control.sh files are identical"
else
echo "INFO: bin/control.sh files differ (see above)"
fi
echo ""
# compare the file tree (excluding lib/) to catch new or removed scripts and files
echo "========================================"
echo "Comparing file tree (excluding lib/)"
echo "========================================"
if diff <(cd "ga/${GA_DIR_NAME}" && find . -not -path './lib/*' | sort) <(cd "beta/${BETA_DIR_NAME}" && find . -not -path './lib/*' | sort)
then
echo "INFO: file trees are identical"
else
echo "INFO: file trees differ (see above; < is GA, > is BETA)"
fi
echo ""
# print "<artifact> <version[,version...]>" for each jar in a lib directory
jar_versions() {
find "$1" -maxdepth 1 -name '*.jar' -exec basename {} \; | sed -nE 's/^(.+)-([0-9][0-9A-Za-z._-]*)\.jar$/\1 \2/p' | sort |\
awk '{v[$1]=($1 in v)?v[$1]","$2:$2} END {for (a in v) print a, v[a]}' | sort
}
# compare bundled libraries by artifact name; skip TP-Link jars that only bump to the controller version
echo "========================================"
echo "Comparing lib/ (bundled libraries)"
echo "========================================"
GA_VER="$(echo "${GA_DIR_NAME}" | sed -E 's/.*_v([0-9.]+)_.*/\1/')"
BETA_VER="$(echo "${BETA_DIR_NAME}" | sed -E 's/.*_v([0-9.]+)_.*/\1/')"
echo "INFO: $(find "ga/${GA_DIR_NAME}/lib" -name '*.jar' | wc -l | tr -d ' ') jars in GA; $(find "beta/${BETA_DIR_NAME}/lib" -name '*.jar' | wc -l | tr -d ' ') jars in BETA"
join -a1 -a2 -e '-' -o 0,1.2,2.2 <(jar_versions "ga/${GA_DIR_NAME}/lib") <(jar_versions "beta/${BETA_DIR_NAME}/lib") |\
awk -v ga="${GA_VER}" -v beta="${BETA_VER}" '
$2 == "-" { added[++na] = " + " $1 " " $3; next }
$3 == "-" { removed[++nr] = " - " $1 " " $2; next }
$2 != $3 && !($2 == ga && $3 == beta) { changed[++nc] = " ~ " $1 " " $2 " -> " $3 }
END {
print "Added (" na+0 "):"; for (i = 1; i <= na; i++) print added[i]
print "Removed (" nr+0 "):"; for (i = 1; i <= nr; i++) print removed[i]
print "Changed (" nc+0 "):"; for (i = 1; i <= nc; i++) print changed[i]
}'
echo ""
# compare readme.txt files
echo "========================================"
echo "Comparing readme.txt"
echo "========================================"
if git diff --no-index --color=always --src-prefix= --dst-prefix= \
"ga/readme.txt" "beta/readme.txt"
then
echo "INFO: readme.txt files are identical"
else
echo "INFO: readme.txt files differ (see above)"
fi
echo ""
echo "INFO: comparison complete!"