mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-06-27 11:25:52 +07:00
add incrementation migration logic (#4)
This commit is contained in:
parent
2493e91ce8
commit
8b2af35f39
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@ -10,7 +10,7 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
goreleaser:
|
goreleaser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Install dependencies for cross-compiling
|
name: Install dependencies for cross-compiling
|
||||||
@ -18,8 +18,8 @@ jobs:
|
|||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt-get --no-install-recommends --yes install \
|
sudo apt-get --no-install-recommends --yes install \
|
||||||
libc6-dev-amd64-cross \
|
libc6-dev-amd64-cross \
|
||||||
gcc-10-aarch64-linux-gnu libc6-dev-arm64-cross \
|
gcc-11-aarch64-linux-gnu libc6-dev-arm64-cross \
|
||||||
gcc-10-arm-linux-gnueabihf libc6-dev-armhf-cross
|
gcc-11-arm-linux-gnueabihf libc6-dev-armhf-cross
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -7,28 +7,28 @@ before:
|
|||||||
- go mod tidy
|
- go mod tidy
|
||||||
builds:
|
builds:
|
||||||
- id: casaos-user-service-amd64
|
- id: casaos-user-service-amd64
|
||||||
binary: build/usr/bin/casaos-user-service
|
binary: build/sysroot/usr/bin/casaos-user-service
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=1
|
- CGO_ENABLED=1
|
||||||
- CC=x86_64-linux-gnu-gcc-10
|
- CC=x86_64-linux-gnu-gcc-11
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
- id: casaos-user-service-arm64
|
- id: casaos-user-service-arm64
|
||||||
binary: build/usr/bin/casaos-user-service
|
binary: build/sysroot/usr/bin/casaos-user-service
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=1
|
- CGO_ENABLED=1
|
||||||
- CC=aarch64-linux-gnu-gcc-10
|
- CC=aarch64-linux-gnu-gcc-11
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
- arm64
|
- arm64
|
||||||
- id: casaos-user-service-arm-7
|
- id: casaos-user-service-arm-7
|
||||||
binary: build/usr/bin/casaos-user-service
|
binary: build/sysroot/usr/bin/casaos-user-service
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=1
|
- CGO_ENABLED=1
|
||||||
- CC=arm-linux-gnueabihf-gcc-10
|
- CC=arm-linux-gnueabihf-gcc-11
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
@ -36,31 +36,31 @@ builds:
|
|||||||
goarm:
|
goarm:
|
||||||
- 7
|
- 7
|
||||||
- id: casaos-user-service-migration-tool-amd64
|
- id: casaos-user-service-migration-tool-amd64
|
||||||
binary: build/usr/bin/casaos-user-service-migration-tool
|
binary: build/sysroot/usr/bin/casaos-user-service-migration-tool
|
||||||
main: ./cmd/migration-tool
|
main: ./cmd/migration-tool
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=1
|
- CGO_ENABLED=1
|
||||||
- CC=x86_64-linux-gnu-gcc-10
|
- CC=x86_64-linux-gnu-gcc-11
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
- id: casaos-user-service-migration-tool-arm64
|
- id: casaos-user-service-migration-tool-arm64
|
||||||
binary: build/usr/bin/casaos-user-service-migration-tool
|
binary: build/sysroot/usr/bin/casaos-user-service-migration-tool
|
||||||
main: ./cmd/migration-tool
|
main: ./cmd/migration-tool
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=1
|
- CGO_ENABLED=1
|
||||||
- CC=aarch64-linux-gnu-gcc-10
|
- CC=aarch64-linux-gnu-gcc-11
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
- arm64
|
- arm64
|
||||||
- id: casaos-user-service-migration-tool-arm-7
|
- id: casaos-user-service-migration-tool-arm-7
|
||||||
binary: build/usr/bin/casaos-user-service-migration-tool
|
binary: build/sysroot/usr/bin/casaos-user-service-migration-tool
|
||||||
main: ./cmd/migration-tool
|
main: ./cmd/migration-tool
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=1
|
- CGO_ENABLED=1
|
||||||
- CC=arm-linux-gnueabihf-gcc-10
|
- CC=arm-linux-gnueabihf-gcc-11
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
@ -87,7 +87,7 @@ archives:
|
|||||||
replacements:
|
replacements:
|
||||||
arm: arm-7
|
arm: arm-7
|
||||||
files:
|
files:
|
||||||
- build/**/*
|
- build/sysroot/etc/**/*
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
snapshot:
|
snapshot:
|
||||||
|
31
Makefile
31
Makefile
@ -1,31 +0,0 @@
|
|||||||
APP_NAME = casaos-user-service
|
|
||||||
APP_NAME_SHORT = user-service
|
|
||||||
|
|
||||||
TARGET_DIR = target
|
|
||||||
BUILD_DIR = $(TARGET_DIR)/build
|
|
||||||
|
|
||||||
INSTALL_ROOT = /
|
|
||||||
|
|
||||||
all: $(TARGET_DIR)
|
|
||||||
|
|
||||||
$(BUILD_DIR): clean
|
|
||||||
mkdir -pv $(BUILD_DIR)/usr/bin
|
|
||||||
|
|
||||||
$(APP_NAME): $(BUILD_DIR)
|
|
||||||
go build -v -o $(BUILD_DIR)/usr/bin/$(APP_NAME)
|
|
||||||
|
|
||||||
$(TARGET_DIR): $(APP_NAME)
|
|
||||||
cp -rv build $(TARGET_DIR)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rfv $(TARGET_DIR)
|
|
||||||
|
|
||||||
install:
|
|
||||||
cp -rv $(BUILD_DIR)/* $(INSTALL_ROOT)
|
|
||||||
systemctl enable --now $(APP_NAME).service
|
|
||||||
|
|
||||||
uninstall:
|
|
||||||
systemctl disable --now $(APP_NAME).service
|
|
||||||
rm -v $(INSTALL_ROOT)/etc/casaos/$(APP_NAME_SHORT).conf
|
|
||||||
rm -v $(INSTALL_ROOT)/usr/bin/$(APP_NAME)
|
|
||||||
rm -v $(INSTALL_ROOT)/usr/lib/systemd/system/$(APP_NAME).service
|
|
138
build/scripts/migration/script.d/02-migrate-user-service.sh
Normal file
138
build/scripts/migration/script.d/02-migrate-user-service.sh
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# functions
|
||||||
|
__is_version_gt() {
|
||||||
|
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
__is_migration_needed() {
|
||||||
|
local version1
|
||||||
|
local version2
|
||||||
|
|
||||||
|
version1="${1}"
|
||||||
|
version2="${2}"
|
||||||
|
|
||||||
|
if [ "${version1}" = "${version2}" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "CURRENT_VERSION_NOT_FOUND" = "${version1}" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "LEGACY_WITHOUT_VERSION" = "${version1}" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
__is_version_gt "${version2}" "${version1}"
|
||||||
|
}
|
||||||
|
|
||||||
|
BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..
|
||||||
|
SOURCE_ROOT=${BUILD_PATH}/sysroot
|
||||||
|
|
||||||
|
APP_NAME="casaos-user-service"
|
||||||
|
APP_NAME_FORMAL="CasaOS-UserService"
|
||||||
|
APP_NAME_SHORT="user-service"
|
||||||
|
APP_NAME_LEGACY="casaos"
|
||||||
|
|
||||||
|
# check if migration is needed
|
||||||
|
SOURCE_BIN_PATH=${SOURCE_ROOT}/usr/bin
|
||||||
|
SOURCE_BIN_FILE=${SOURCE_BIN_PATH}/${APP_NAME}
|
||||||
|
|
||||||
|
CURRENT_BIN_PATH=/usr/bin
|
||||||
|
CURRENT_BIN_PATH_LEGACY=/usr/local/bin
|
||||||
|
CURRENT_BIN_FILE=${CURRENT_BIN_PATH}/${APP_NAME}
|
||||||
|
CURRENT_BIN_FILE_LEGACY=$(realpath -e ${CURRENT_BIN_PATH}/${APP_NAME_LEGACY} || realpath -e ${CURRENT_BIN_PATH_LEGACY}/${APP_NAME_LEGACY} || which ${APP_NAME_LEGACY} || echo CURRENT_BIN_FILE_LEGACY_NOT_FOUND)
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
|
NEED_MIGRATION=$(__is_migration_needed "${CURRENT_VERSION}" "${SOURCE_VERSION}" && echo "true" || echo "false")
|
||||||
|
|
||||||
|
if [ "${NEED_MIGRATION}" = "false" ]; then
|
||||||
|
echo "✅ Migration is not needed."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
MIGRATION_SERVICE_DIR=${BUILD_PATH}/scripts/migration/service.d/${APP_NAME_SHORT}
|
||||||
|
MIGRATION_LIST_FILE=${MIGRATION_SERVICE_DIR}/migration.list
|
||||||
|
MIGRATION_PATH=()
|
||||||
|
|
||||||
|
CURRENT_VERSION_FOUND="false"
|
||||||
|
|
||||||
|
while read -r VERSION_PAIR; do
|
||||||
|
if [ -z "${VERSION_PAIR}" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
VER1=$(echo "${VERSION_PAIR}" | cut -d' ' -f1)
|
||||||
|
VER2=$(echo "${VERSION_PAIR}" | cut -d' ' -f2)
|
||||||
|
|
||||||
|
if [ "v${CURRENT_VERSION}" = "${VER1// /}" ]; then
|
||||||
|
CURRENT_VERSION_FOUND="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${CURRENT_VERSION_FOUND}" = "true" ]; then
|
||||||
|
MIGRATION_PATH+=("${VER2// /}")
|
||||||
|
fi
|
||||||
|
done < "${MIGRATION_LIST_FILE}"
|
||||||
|
|
||||||
|
if [ ${#MIGRATION_PATH[@]} -eq 0 ]; then
|
||||||
|
echo "🟨 No migration path found from ${CURRENT_VERSION} to ${SOURCE_VERSION}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
ARCH="unknown"
|
||||||
|
|
||||||
|
case $(uname -m) in
|
||||||
|
x86_64)
|
||||||
|
ARCH="amd64"
|
||||||
|
;;
|
||||||
|
aarch64)
|
||||||
|
ARCH="arm64"
|
||||||
|
;;
|
||||||
|
armv7l)
|
||||||
|
ARCH="arm-7"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported architecture"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
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}..."
|
||||||
|
curl -sL -O "${MIGRATION_TOOL_URL}"
|
||||||
|
done
|
||||||
|
} || {
|
||||||
|
echo "🟥 Failed to download migration tools"
|
||||||
|
popd
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
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}"
|
||||||
|
|
||||||
|
MIGRATION_TOOL_PATH=build/sysroot/usr/bin/${APP_NAME}-migration-tool
|
||||||
|
echo "Running ${MIGRATION_TOOL_PATH}..."
|
||||||
|
${MIGRATION_TOOL_PATH}
|
||||||
|
done
|
||||||
|
} || {
|
||||||
|
echo "🟥 Failed to extract and run migration tools"
|
||||||
|
popd
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
popd
|
@ -0,0 +1,2 @@
|
|||||||
|
LEGACY_WITHOUT_VERSION v0.3.6-alpha1
|
||||||
|
v0.3.5 v0.3.6-alpha1
|
54
build/scripts/setup/script.d/02-setup-user-service.sh
Executable file
54
build/scripts/setup/script.d/02-setup-user-service.sh
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..
|
||||||
|
|
||||||
|
APP_NAME_SHORT=user-service
|
||||||
|
|
||||||
|
__get_setup_script_directory_by_os_release() {
|
||||||
|
pushd "$(dirname "${BASH_SOURCE[0]}")/../service.d/${APP_NAME_SHORT}" >/dev/null
|
||||||
|
|
||||||
|
{
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
{
|
||||||
|
source /etc/os-release
|
||||||
|
{
|
||||||
|
pushd "${ID}"/"${VERSION_CODENAME}" >/dev/null
|
||||||
|
} || {
|
||||||
|
pushd "${ID}" >/dev/null
|
||||||
|
} || {
|
||||||
|
pushd "${ID_LIKE}" >/dev/null
|
||||||
|
} || {
|
||||||
|
echo "Unsupported OS: ${ID} ${VERSION_CODENAME} (${ID_LIKE})"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
pwd
|
||||||
|
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
|
} || {
|
||||||
|
echo "Unsupported OS: unknown"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
popd >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
SETUP_SCRIPT_DIRECTORY=$(__get_setup_script_directory_by_os_release)
|
||||||
|
SETUP_SCRIPT_FILENAME="setup-${APP_NAME_SHORT}.sh"
|
||||||
|
|
||||||
|
SETUP_SCRIPT_FILEPATH="${SETUP_SCRIPT_DIRECTORY}/${SETUP_SCRIPT_FILENAME}"
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "🟩 Running ${SETUP_SCRIPT_FILENAME}..."
|
||||||
|
$SHELL "${SETUP_SCRIPT_FILEPATH}" "${BUILD_PATH}"
|
||||||
|
} || {
|
||||||
|
echo "🟥 ${SETUP_SCRIPT_FILENAME} failed."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "✅ ${SETUP_SCRIPT_FILENAME} finished."
|
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
APP_NAME="casaos-user-service"
|
||||||
|
APP_NAME_SHORT="user-service"
|
||||||
|
|
||||||
|
# copy config files
|
||||||
|
CONF_PATH=/etc/casaos
|
||||||
|
CONF_FILE=${CONF_PATH}/${APP_NAME_SHORT}.conf
|
||||||
|
CONF_FILE_SAMPLE=${CONF_PATH}/${APP_NAME_SHORT}.conf.sample
|
||||||
|
|
||||||
|
if [ ! -f "${CONF_FILE}" ]; then \
|
||||||
|
echo "Initializing config file..."
|
||||||
|
cp -v "${CONF_FILE_SAMPLE}" "${CONF_FILE}"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# enable and start service
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
echo "Enabling service..."
|
||||||
|
systemctl enable --force --no-ask-password "${APP_NAME}.service"
|
||||||
|
|
||||||
|
echo "Starting service..."
|
||||||
|
systemctl start --force --no-ask-password "${APP_NAME}.service"
|
@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
__get_existing_version() {
|
|
||||||
local version
|
|
||||||
|
|
||||||
echo "$version"
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
from-0.3.sh
|
|
@ -1,4 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user