48 lines
1.4 KiB
Bash
48 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
REPO_URL="${REPO_URL:-https://git.dr2.site/penguinehis/DragonCore-Modules.git}"
|
|
BRANCH="${BRANCH:-main}"
|
|
CONFIG_DIR="/etc/dragoncore-bridge"
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
echo "Run as root."
|
|
exit 1
|
|
fi
|
|
|
|
need_cmd() { command -v "$1" >/dev/null 2>&1; }
|
|
|
|
# If this updater is executed from an extracted repository, use the local files.
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || true)"
|
|
if [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/install_bridge.sh" ] && [ -f "$SCRIPT_DIR/main.go" ]; then
|
|
echo "Updating DragonCore Bridge from local source..."
|
|
bash "$SCRIPT_DIR/install_bridge.sh" "$@"
|
|
exit $?
|
|
fi
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
if need_cmd apt-get; then
|
|
apt-get update -y
|
|
apt-get install -y ca-certificates curl git
|
|
elif need_cmd yum; then
|
|
yum install -y ca-certificates curl git
|
|
elif need_cmd dnf; then
|
|
dnf install -y ca-certificates curl git
|
|
fi
|
|
|
|
TMP_DIR="$(mktemp -d)"
|
|
cleanup() { rm -rf "$TMP_DIR"; }
|
|
trap cleanup EXIT
|
|
|
|
echo "Updating DragonCore Bridge from ${REPO_URL} (${BRANCH})..."
|
|
git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$TMP_DIR/src"
|
|
|
|
# install_bridge.sh preserves existing username/password/token and existing port
|
|
# unless --port is explicitly supplied. It also migrates accounts.json to SQLite.
|
|
bash "$TMP_DIR/src/install_bridge.sh" "$@"
|
|
|
|
if [ -f "$CONFIG_DIR/config.json" ]; then
|
|
echo
|
|
echo "Updated config: $CONFIG_DIR/config.json"
|
|
fi
|