Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.6 #519

Merged
merged 18 commits into from
Sep 6, 2022
Merged

0.3.6 #519

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: goreleaser

on:
push:
tags:
- v*.*.*

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-22.04
steps:
-
name: Install dependencies for cross-compiling
run: |
sudo apt update
sudo apt-get --no-install-recommends --yes install \
libc6-dev-amd64-cross \
gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Fetch all tags
run: git fetch --force --tags
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
136 changes: 136 additions & 0 deletions build/scripts/migration/script.d/03-migrate-casaos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/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"
APP_NAME_FORMAL="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_LEGACY}/${APP_NAME} || which ${APP_NAME} || 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}
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
2 changes: 2 additions & 0 deletions build/scripts/migration/service.d/casaos/migration.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LEGACY_WITHOUT_VERSION v0.3.6-alpha2
v0.3.5 v0.3.6-alpha2
54 changes: 54 additions & 0 deletions build/scripts/setup/script.d/03-setup-casaos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

set -e

BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..

APP_NAME_SHORT=casaos

__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."
24 changes: 24 additions & 0 deletions build/scripts/setup/service.d/casaos/debian/setup-casaos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

APP_NAME="casaos"

# copy config files
CONF_PATH=/etc/casaos
CONF_FILE=${CONF_PATH}/${APP_NAME}.conf
CONF_FILE_SAMPLE=${CONF_PATH}/${APP_NAME}.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"
23 changes: 23 additions & 0 deletions build/sysroot/etc/casaos/casaos.conf.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[app]
PAGE_SIZE = 10
RuntimeRootPath = runtime/
LogPath = /var/log/casaos/
LogSaveName = log
LogFileExt = log
DateStrFormat = 20060102
DateTimeFormat = 2006-01-02 15:04:05
TimeFormat = 15:04:05
DateFormat = 2006-01-02
DBPath = /var/lib/casaos
ShellPath = /usr/share/casaos/shell
UserDataPath = /var/lib/casaos/conf
TempPath = /var/lib/casaos/temp

[server]
RunMode = release
ServerApi = https://api.casaos.io/casaos-api
Handshake = socket.casaos.io
Token =
USBAutoMount =

[system]
12 changes: 12 additions & 0 deletions build/sysroot/usr/lib/systemd/system/casaos.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
After=casaos-gateway.service
ConditionFileNotEmpty=/etc/casaos/casaos.conf
Description=CasaOS Service

[Service]
ExecStart=/usr/bin/casaos -c /etc/casaos/casaos.conf
PIDFile=/var/run/casaos/casaos.pid
Restart=always

[Install]
WantedBy=multi-user.target
21 changes: 21 additions & 0 deletions cmd/migration-tool/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/IceWhaleTech/CasaOS/types"
)

func main() {
versionFlag := flag.Bool("v", false, "version")
flag.Parse()

if *versionFlag {
fmt.Println(types.CURRENTVERSION)
os.Exit(0)
}

fmt.Println("This migration tool is not implemented yet.")
}