Fix links

This commit is contained in:
Penguinehis
2026-09-29 10:18:56 -03:00
parent b4a8a70e54
commit 4673f8c58e
6 changed files with 88 additions and 33 deletions
+49 -25
View File
@@ -1,5 +1,5 @@
#!/bin/bash
# Update the DragonCoreSSH CLI from a local extracted release.
# Update the DragonCoreSSH CLI from its Git repository.
#
# Preserved:
# - /opt/sshpanel/.env
@@ -11,8 +11,8 @@
# sudo bash /opt/sshpanel/update.sh
# sudo bash update.sh
#
# Run from an extracted DragonCoreSSH-CLI source directory to apply that release.
# Installed /opt/sshpanel/update.sh rebuilds the cached CLI source.
# UPDATE_SOURCE=local sudo bash update.sh applies a checked-out/offline release.
# UPDATE_REF selects an optional remote branch; empty follows remote HEAD.
set -euo pipefail
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
@@ -25,13 +25,17 @@ INSTALL_DIR="${INSTALL_DIR:-/opt/sshpanel}"
SERVICE_NAME="${SERVICE_NAME:-sshpanel}"
LOG_TMPFS_SIZE="${LOG_TMPFS_SIZE:-15m}"
PANEL_LOG_MAX_BYTES="${PANEL_LOG_MAX_BYTES:-1048576}"
REPO_URL="local-cli-source"
REPO_URL="${REPO_URL:-https://git.dr2.site/penguinehis/DragonCoreNEWCLI}"
UPDATE_REF="${UPDATE_REF:-}"
UPDATE_SOURCE="${UPDATE_SOURCE:-git}"
export GIT_TERMINAL_PROMPT=0
export GIT_ASKPASS=/bin/false
SOURCE_CACHE_DIR="${SOURCE_CACHE_DIR:-${INSTALL_DIR}/source}"
MKDIR_BIN="$(command -v mkdir 2>/dev/null || true)"
[[ -n "$MKDIR_BIN" ]] || MKDIR_BIN="/bin/mkdir"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR=""
FETCH_DIR=""
RESTART_NEEDED=false
BUILD_COMMIT=""
BUILD_BRANCH=""
@@ -186,25 +190,35 @@ install_git_if_missing() {
pkg_install git ca-certificates
}
remote_default_branch() {
local branch
branch="$(git ls-remote --symref "$REPO_URL" HEAD 2>/dev/null | awk '/^ref:/ {sub("refs/heads/", "", $2); print $2; exit}')"
if [[ -n "$branch" ]]; then
printf '%s\n' "$branch"
prepare_source_from_git() {
if [[ "$UPDATE_SOURCE" == "local" ]]; then
SOURCE_DIR="${SOURCE_DIR:-$SCRIPT_DIR}"
if [[ ! -f "$SOURCE_DIR/go.mod" ]]; then
SOURCE_DIR="$SOURCE_CACHE_DIR"
fi
info "[1/7] Using local CLI source: $SOURCE_DIR"
elif [[ "$UPDATE_SOURCE" == "git" ]]; then
FETCH_DIR="$(mktemp -d "${TMPDIR:-/tmp}/dragoncore-update.XXXXXXXX")"
info "[1/7] Fetching CLI source from $REPO_URL..."
if [[ -n "$UPDATE_REF" ]]; then
git clone --depth 1 --branch "$UPDATE_REF" "$REPO_URL" "$FETCH_DIR" || error "Git fetch failed; service and installed files were not changed"
else
git clone --depth 1 "$REPO_URL" "$FETCH_DIR" || error "Git fetch failed; service and installed files were not changed"
fi
SOURCE_DIR="$FETCH_DIR"
else
printf 'main\n'
error "UPDATE_SOURCE must be git or local"
fi
[[ -f "$SOURCE_DIR/go.mod" && -f "$SOURCE_DIR/dragoncore_cli.py" && -f "$SOURCE_DIR/update.sh" ]] || \
error "Update source is missing go.mod, dragoncore_cli.py, or update.sh; service was not changed"
}
prepare_source_from_git() {
SOURCE_DIR="${SOURCE_DIR:-$SCRIPT_DIR}"
if [[ ! -f "$SOURCE_DIR/go.mod" ]]; then
SOURCE_DIR="$SOURCE_CACHE_DIR"
cleanup_fetch() {
if [[ -n "$FETCH_DIR" && -d "$FETCH_DIR" ]]; then
rm -rf -- "$FETCH_DIR"
fi
info "[1/7] Using local CLI source: $SOURCE_DIR"
[[ -f "$SOURCE_DIR/go.mod" ]] || error "go.mod not found; run update.sh from an extracted CLI release"
[[ -f "$SOURCE_DIR/dragoncore_cli.py" ]] || error "Source is missing dragoncore_cli.py"
}
trap cleanup_fetch EXIT
install_go_if_needed() {
local go_version machine goarch go_url current_go need_go
@@ -252,11 +266,16 @@ build_binary() {
export GOCACHE=/tmp/gocache_sshpanel
BUILD_COMMIT="$(git -C "$SOURCE_DIR" rev-parse HEAD 2>/dev/null || true)"
BUILD_BRANCH="${UPDATE_REF:-$(git -C "$SOURCE_DIR" rev-parse --abbrev-ref HEAD 2>/dev/null || true)}"
BUILD_BRANCH="$(git -C "$SOURCE_DIR" rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
BUILD_REPO_URL="DragonCoreSSH-CLI local release"
if [[ "$UPDATE_SOURCE" == "local" ]]; then
BUILD_REPO_URL="$(git -C "$SOURCE_DIR" config --get remote.origin.url 2>/dev/null || true)"
[[ -n "$BUILD_REPO_URL" ]] || BUILD_REPO_URL="DragonCoreSSH-CLI local release"
else
BUILD_REPO_URL="$REPO_URL"
fi
[[ -n "$BUILD_COMMIT" ]] || BUILD_COMMIT="unknown"
[[ -n "$BUILD_BRANCH" && "$BUILD_BRANCH" != "HEAD" ]] || BUILD_BRANCH="main"
[[ -n "$BUILD_BRANCH" && "$BUILD_BRANCH" != "HEAD" ]] || BUILD_BRANCH="${UPDATE_REF:-unknown}"
go mod download
go mod tidy
@@ -278,12 +297,13 @@ stop_service() {
}
copy_optional_script() {
local name mode
local name mode staged
name="$1"
mode="$2"
if [[ -f "$SOURCE_DIR/$name" ]]; then
cp "$SOURCE_DIR/$name" "$INSTALL_DIR/$name"
chmod "$mode" "$INSTALL_DIR/$name"
staged="$(mktemp "$INSTALL_DIR/.${name}.XXXXXX")"
install -m "$mode" "$SOURCE_DIR/$name" "$staged"
mv -f "$staged" "$INSTALL_DIR/$name"
info " Updated $name"
fi
}
@@ -549,7 +569,9 @@ restart_service() {
warn " $SERVICE_NAME was not running before update; starting it now."
fi
"$SYSTEMCTL_BIN" start "$SERVICE_NAME"
if ! "$SYSTEMCTL_BIN" start "$SERVICE_NAME"; then
error "$SERVICE_NAME could not start. Restore $INSTALL_DIR/sshpanel.bak and inspect journalctl -u $SERVICE_NAME"
fi
sleep 2
if "$SYSTEMCTL_BIN" is-active --quiet "$SERVICE_NAME"; then
info " $SERVICE_NAME is running."
@@ -560,6 +582,7 @@ restart_service() {
warn " Restore command:"
warn " cp $INSTALL_DIR/sshpanel.bak $INSTALL_DIR/sshpanel && systemctl start $SERVICE_NAME"
fi
error "$SERVICE_NAME is not running after the update"
exit 1
fi
}
@@ -578,6 +601,7 @@ need_cmd wget
info " Install dir : $INSTALL_DIR"
info " Cache dir : $SOURCE_CACHE_DIR"
info " Update source : $UPDATE_SOURCE"
info " Package manager : $PKG_MANAGER"
info " Service manager : systemd"
@@ -595,7 +619,7 @@ echo -e "${GREEN} Update complete! ${NC}"
echo -e "${GREEN}==========================================${NC}"
echo ""
echo -e " Updated from: ${YELLOW}${REPO_URL}${NC}"
echo -e " Source ref : ${YELLOW}${UPDATE_REF}${NC}"
echo -e " Source ref : ${YELLOW}${BUILD_BRANCH} (${BUILD_COMMIT})${NC}"
echo -e " Source cache: ${YELLOW}${SOURCE_CACHE_DIR}${NC}"
echo -e " Logs : ${YELLOW}journalctl -u ${SERVICE_NAME} -f${NC}"
echo -e " ${YELLOW}tail -f ${INSTALL_DIR}/logs/panel.log${NC}"