mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-11-06 22:59:44 +00:00
fix migration not working for LEGACY_WITHOUT_VERSION (#479)
* wip * wip
This commit is contained in:
parent
db8880547a
commit
03d6f8721c
1
UI
Submodule
1
UI
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit bca27426e1f398c31fb6c5c23885482326514f6e
|
||||
@ -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"
|
||||
}
|
||||
@ -47,13 +64,13 @@ CURRENT_BIN_FILE_LEGACY=$(realpath -e ${CURRENT_BIN_PATH_LEGACY}/${APP_NAME} ||
|
||||
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
|
||||
|
||||
@ -63,15 +80,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
|
||||
|
||||
@ -81,7 +105,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
|
||||
|
||||
@ -98,8 +122,7 @@ case $(uname -m) in
|
||||
ARCH="arm-7"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture"
|
||||
exit 1
|
||||
__error "Unsupported architecture"
|
||||
;;
|
||||
esac
|
||||
|
||||
@ -112,25 +135,26 @@ pushd "${MIGRATION_SERVICE_DIR}"
|
||||
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}..."
|
||||
__info "Extracting ${MIGRATION_TOOL_FILE}..."
|
||||
tar zxvf "${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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user