mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-03-15 23:25:35 +07:00
fix migration not working for LEGACY_WITHOUT_VERSION (#6)
This commit is contained in:
parent
210aa979f5
commit
8d9c3f987d
@ -3,6 +3,23 @@
|
||||
set -e
|
||||
|
||||
# functions
|
||||
__info() {
|
||||
echo -e "🟩 ${1}"
|
||||
}
|
||||
|
||||
__info_done() {
|
||||
echo -e "✅ ${1}"
|
||||
}
|
||||
|
||||
__warning() {
|
||||
echo -e "🟨 ${1}"
|
||||
}
|
||||
|
||||
__error() {
|
||||
echo "🟥 ${1}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
__is_version_gt() {
|
||||
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"
|
||||
}
|
||||
@ -49,13 +66,13 @@ CURRENT_BIN_FILE_LEGACY=$(realpath -e ${CURRENT_BIN_PATH}/${APP_NAME_LEGACY} ||
|
||||
SOURCE_VERSION="$(${SOURCE_BIN_FILE} -v)"
|
||||
CURRENT_VERSION="$(${CURRENT_BIN_FILE} -v || ${CURRENT_BIN_FILE_LEGACY} -v || (stat "${CURRENT_BIN_FILE_LEGACY}" > /dev/null && echo LEGACY_WITHOUT_VERSION) || echo CURRENT_VERSION_NOT_FOUND)"
|
||||
|
||||
echo "CURRENT_VERSION: ${CURRENT_VERSION}"
|
||||
echo "SOURCE_VERSION: ${SOURCE_VERSION}"
|
||||
__info_done "CURRENT_VERSION: ${CURRENT_VERSION}"
|
||||
__info_done "SOURCE_VERSION: ${SOURCE_VERSION}"
|
||||
|
||||
NEED_MIGRATION=$(__is_migration_needed "${CURRENT_VERSION}" "${SOURCE_VERSION}" && echo "true" || echo "false")
|
||||
|
||||
if [ "${NEED_MIGRATION}" = "false" ]; then
|
||||
echo "✅ Migration is not needed."
|
||||
__info_done "Migration is not needed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@ -65,15 +82,22 @@ MIGRATION_PATH=()
|
||||
|
||||
CURRENT_VERSION_FOUND="false"
|
||||
|
||||
# a VERSION_PAIR looks like "v0.3.5 v0.3.6-alpha2"
|
||||
#
|
||||
# - "v0.3.5" is the current version installed on this host
|
||||
# - "v0.3.6-alpha2" is the version of the migration tool from GitHub
|
||||
while read -r VERSION_PAIR; do
|
||||
if [ -z "${VERSION_PAIR}" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# obtain "v0.3.5" from "v0.3.5 v0.3.6-alpha2"
|
||||
VER1=$(echo "${VERSION_PAIR}" | cut -d' ' -f1)
|
||||
|
||||
# obtain "v0.3.6-alpha2" from "v0.3.5 v0.3.6-alpha2"
|
||||
VER2=$(echo "${VERSION_PAIR}" | cut -d' ' -f2)
|
||||
|
||||
if [ "v${CURRENT_VERSION}" = "${VER1// /}" ]; then
|
||||
if [ "v${CURRENT_VERSION}" = "${VER1// /}" ] || [ "${CURRENT_VERSION}" = "LEGACY_WITHOUT_VERSION" ]; then
|
||||
CURRENT_VERSION_FOUND="true"
|
||||
fi
|
||||
|
||||
@ -83,7 +107,7 @@ while read -r VERSION_PAIR; do
|
||||
done < "${MIGRATION_LIST_FILE}"
|
||||
|
||||
if [ ${#MIGRATION_PATH[@]} -eq 0 ]; then
|
||||
echo "🟨 No migration path found from ${CURRENT_VERSION} to ${SOURCE_VERSION}"
|
||||
__warning "No migration path found from ${CURRENT_VERSION} to ${SOURCE_VERSION}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@ -100,8 +124,7 @@ case $(uname -m) in
|
||||
ARCH="arm-7"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture"
|
||||
exit 1
|
||||
__error "Unsupported architecture"
|
||||
;;
|
||||
esac
|
||||
|
||||
@ -110,29 +133,30 @@ pushd "${MIGRATION_SERVICE_DIR}"
|
||||
{
|
||||
for VER2 in "${MIGRATION_PATH[@]}"; do
|
||||
MIGRATION_TOOL_URL=https://github.com/IceWhaleTech/"${APP_NAME_FORMAL}"/releases/download/"${VER2}"/linux-"${ARCH}"-"${APP_NAME}"-migration-tool-"${VER2}".tar.gz
|
||||
echo "Dowloading ${MIGRATION_TOOL_URL}..."
|
||||
__info "Dowloading ${MIGRATION_TOOL_URL}..."
|
||||
curl -sL -O "${MIGRATION_TOOL_URL}"
|
||||
done
|
||||
} || {
|
||||
echo "🟥 Failed to download migration tools"
|
||||
popd
|
||||
exit 1
|
||||
__error "Failed to download migration tools"
|
||||
}
|
||||
|
||||
{
|
||||
for VER2 in "${MIGRATION_PATH[@]}"; do
|
||||
MIGRATION_TOOL_FILE=linux-"${ARCH}"-"${APP_NAME}"-migration-tool-"${VER2}".tar.gz
|
||||
echo "Extracting ${MIGRATION_TOOL_FILE}..."
|
||||
tar zxvf "${MIGRATION_TOOL_FILE}"
|
||||
__info "Extracting ${MIGRATION_TOOL_FILE}..."
|
||||
tar zxvf "${MIGRATION_TOOL_FILE}" || __error "Failed to extract ${MIGRATION_TOOL_FILE}"
|
||||
|
||||
MIGRATION_SYSROOT_DIR=$(realpath -e "${MIGRATION_SERVICE_DIR}"/build/sysroot || __error "Failed to find sysroot directory for migration")
|
||||
cp -rv "${MIGRATION_SYSROOT_DIR}"/* / || __error "Failed to copy sysroot directory for migration"
|
||||
|
||||
MIGRATION_TOOL_PATH=build/sysroot/usr/bin/${APP_NAME}-migration-tool
|
||||
echo "Running ${MIGRATION_TOOL_PATH}..."
|
||||
__info "Running ${MIGRATION_TOOL_PATH}..."
|
||||
${MIGRATION_TOOL_PATH}
|
||||
done
|
||||
} || {
|
||||
echo "🟥 Failed to extract and run migration tools"
|
||||
popd
|
||||
exit 1
|
||||
__error "Failed to extract and run migration tools"
|
||||
}
|
||||
|
||||
popd
|
||||
|
@ -1,2 +1,2 @@
|
||||
LEGACY_WITHOUT_VERSION v0.3.6-alpha2
|
||||
v0.3.5 v0.3.6-alpha2
|
||||
v0.3.5 v0.3.6-alpha2
|
||||
|
Loading…
Reference in New Issue
Block a user