-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: sougata-progress <[email protected]>
- Loading branch information
1 parent
0607b01
commit 3f64307
Showing
2 changed files
with
17 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,52 @@ | ||
set -eou pipefail | ||
|
||
CHANNEL="LTS-2024" | ||
install_minio() { | ||
|
||
sudo hab pkg install core/minio -c $CHANNEL | ||
echo "MinIO installation completed." | ||
} | ||
|
||
check_and_install_minio() { | ||
if ! hab pkg path core/minio >/dev/null 2>&1; then | ||
echo "MinIO is not installed. Installing MinIO..." | ||
install_minio | ||
else | ||
echo "MinIO is already installed." | ||
fi | ||
} | ||
LATEST_MINIO_VERSION="2023-11-01T01-57-10Z" | ||
|
||
get_installed_minio_version() { | ||
installed_version=$(hab pkg path core/minio | cut -d '/' -f6) | ||
echo "$installed_version" | ||
} | ||
|
||
get_latest_minio_version() { | ||
latest_version=$(curl --silent "https://bldr.habitat.sh/v1/depot/channels/core/$CHANNEL/pkgs/minio/latest" | jq -r '.ident.version') | ||
if [[ -z "$latest_version" ]]; then | ||
echo "Failed to fetch the latest MinIO version." | ||
exit 1 | ||
fi | ||
echo "$latest_version" | ||
} | ||
|
||
compare_versions() { | ||
local v1=$1 | ||
local v2=$2 | ||
echo "Comparing versions..." | ||
echo "Installed version: $v1" | ||
echo "Latest version: $v2" | ||
echo "Latest version threshold: $v2" | ||
|
||
if [ "$v1" = "$v2" ]; then | ||
return 1 | ||
return 0 | ||
elif [[ "$v1" < "$v2" ]]; then | ||
echo "Installed version is older." | ||
return 0 | ||
echo "Installed version is older or equal." | ||
return 0 | ||
else | ||
echo "Installed version is newer or equal." | ||
return 1 | ||
fi | ||
} | ||
|
||
trigger_migration() { | ||
echo "Triggering MinIO data migration..." | ||
y | bash ./minio-update.sh upgrade | ||
} | ||
|
||
detect_migration() { | ||
installed_version=$(get_installed_minio_version) | ||
latest_version=$(get_latest_minio_version) | ||
|
||
compare_versions "$installed_version" "$latest_version" | ||
compare_versions "$installed_version" "$LATEST_MINIO_VERSION" | ||
compare_result=$? | ||
|
||
if [[ $compare_result -eq 0 ]]; then | ||
echo "Older version of MinIO detected. Migration required." | ||
return 0 | ||
elif [[ $compare_result -eq 1 ]]; then | ||
echo "MinIO is up to date. No migration required." | ||
return 1 | ||
echo "Migration required for MinIO version < $LATEST_MINIO_VERSION." | ||
trigger_migration | ||
else | ||
echo "Unexpected result from version comparison." | ||
exit 1 | ||
echo "No migration needed. Exiting." | ||
exit 0 | ||
fi | ||
} | ||
|
||
check_and_install_minio | ||
|
||
installed_version=$(get_installed_minio_version) | ||
echo "Installed MinIO version: $installed_version" | ||
|
||
detect_migration | ||
detect_migration_result=$? | ||
|
||
case "$detect_migration_result" in | ||
0) | ||
echo "Migrating MinIO" | ||
install_minio | ||
;; | ||
1) | ||
echo "No migration needed." | ||
;; | ||
*) | ||
echo "An unexpected error occurred during MinIO version check." | ||
exit 1 | ||
;; | ||
esac | ||
detect_migration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters