Skip to content

Commit

Permalink
Bugfix: RHEL 7 Compatibility (#108)
Browse files Browse the repository at this point in the history
* Updated OS Check to validate for RHEL 7 and remove command non-existent in older packages

* Updated arrays to work on older bash versions
  • Loading branch information
Michael-Burke authored Feb 16, 2024
1 parent ae0c2d0 commit d9cd53c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
11 changes: 11 additions & 0 deletions src/_cli_common_utilities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,14 @@ function _load_static() {
export SYSTEM_REQUIREMENTS=`cat "$staticFilesDir/system-requirements.json"`
fi
}

function os_check() {
OS_NAME=$(grep '^NAME' /etc/os-release | cut -d '=' -f2)
OS_VERSION=$(grep '^VERSION_ID' /etc/os-release | cut -d '=' -f2)
color_always="--color=always"
if echo "$OS_NAME" | grep -q "Red"; then
if echo "$OS_VERSION" | grep -q "7"; then
color_always=""
fi
fi
}
3 changes: 2 additions & 1 deletion src/_configure_plextrac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ PLEXTRAC_BACKUP_PATH="${PLEXTRAC_BACKUP_PATH:-$PLEXTRAC_HOME/backups}"
if [ $(echo "$mergedEnv" | md5sum | awk '{print $1}') = $(md5sum "${PLEXTRAC_HOME}/.env" | awk '{print $1}') ]; then
log "No change required";
else
envDiff="`diff -Nurb --color=always "${PLEXTRAC_HOME}/.env" <(echo "$mergedEnv") || true`"
os_check
envDiff="`diff -Nurb "$color_always" "${PLEXTRAC_HOME}/.env" <(echo "$mergedEnv") || true`"
info "Detected pending changes to ${PLEXTRAC_HOME}/.env:"
log "${envDiff}"
if get_user_approval; then
Expand Down
3 changes: 2 additions & 1 deletion src/_migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ function checkExistingConfigForOverrides() {

decodedComposeFile=$(base64 -d <<<$DOCKER_COMPOSE_ENCODED)
#diff -N --unified=2 --color=always --label existing --label "updated" $targetComposeFile <(echo "$decodedComposeFile") || return 0
diff --unified --color=always --show-function-line='^\s\{2\}\w\+' \
os_check
diff --unified "$color_always" --show-function-line='^\s\{2\}\w\+' \
<($dcCMD config --no-interpolate) \
<(docker compose -f - <<< "${decodedComposeFile}" -f ${composeOverrideFile} config --no-interpolate) || return 0
return 1
Expand Down
11 changes: 8 additions & 3 deletions src/_setup_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ function system_packages__refresh_package_lists() {
function system_packages__do_system_upgrade() {
info "Updating OS packages, this make take some time!"
nobest="--nobest"
if [ "$(grep '^NAME' /etc/os-release | cut -d '=' -f2 | grep CentOS)" ]; then
os_check
if echo "$OS_NAME" | grep -q 'CentOS'; then
nobest=""
elif [ "$(grep '^NAME' /etc/os-release | cut -d '=' -f2 | grep Hat)" ]; then
nobest="--nobest"
elif echo "$OS_NAME" | grep -q 'Hat'; then
if echo "$OS_VERSION" | grep -v '7'; then
nobest="--nobest"
else
nobest=""
fi
fi
debug "$(grep '^NAME' /etc/os-release | cut -d '=' -f2 | tr -d '"')"
system_packages__refresh_package_lists
Expand Down
27 changes: 17 additions & 10 deletions src/_version_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,18 @@ function version_check() {
debug "Looking for Running version $running_ver or Breaking version $breaking_ver"
while [ $page -lt 600 ]
do
upstream_tags+=(`wget --header="Authorization: JWT "${JWT_TOKEN} -O - "https://hub.docker.com/v2/repositories/plextrac/plextracapi/tags/?page=$page&page_size=1000" -q | jq -r .results[].name | grep -E '(^[0-9]\.[0-9]*$)' || true`)
# Get the available versions from DockerHub and save to array
if [[ $(echo "${upstream_tags[@]}" | grep "$running_ver" || true) ]]
then
debug "Found running version $running_backend_version"; break;
elif [[ $(echo "${upstream_tags[@]}" | grep "$breaking_ver" || true) ]]
then
debug "Found breaking version $breaking_ver"; break;
else
upstream_tags+=(`wget --header="Authorization: JWT "${JWT_TOKEN} -O - "https://hub.docker.com/v2/repositories/plextrac/plextracapi/tags/?page=$page&page_size=1000" -q | jq -r .results[].name | grep -E '(^[0-9]\.[0-9]*$)' || true`)
fi
page=$[$page+1]
done

# Remove the running version from the Upgrade path
for i in "${!upstream_tags[@]}"
do
Expand All @@ -125,11 +124,16 @@ function version_check() {
unset 'upstream_tags[i]'
fi
done
new_array=()
for i in "${!upstream_tags[@]}"; do
new_array+=( "${upstream_tags[i]}" )
done
upstream_tags=("${new_array[@]}")
unset new_array
if "${#new_array[@]}" > 0; then
upstream_tags=("${new_array[@]}")
unset new_array
else
upstream_tags=("")
fi
# This grabs the first element in the version sorted list which should always be the highest version available on DockerHub; this should match stable's version"
if [[ -n "${upstream_tags[*]}" ]]; then
debug "Setting latest upstream version var to array first index"
Expand All @@ -140,11 +144,14 @@ function version_check() {
# Set Contiguous updates to false here to ensure that since the app is on latest version, it still attempts to pull patch version updates
contiguous_update=false
fi
# Sort the upstream tags weve chosen as the upgrade path
IFS=$'\n' upgrade_path=($(sort -V <<<"${upstream_tags[*]}"))
# Reset IFS to default value
IFS=$' \t\n'

if "${upstream_tags[@]}" != ""; then
# Sort the upstream tags weve chosen as the upgrade path
IFS=$'\n' upgrade_path=($(sort -V <<<"${upstream_tags[*]}"))
# Reset IFS to default value
IFS=$' \t\n'
else
upgrade_path=("")
fi

debug "------------"
debug "Listing version information"
Expand Down

0 comments on commit d9cd53c

Please sign in to comment.