changed to incubator
added new install script updated security updated ETA
This commit is contained in:
+29
-6
@@ -4,11 +4,14 @@ set -eu
|
||||
SERVICE_NAME="incus-backup-agent"
|
||||
DEFAULT_REPO_URL="https://forgejo.digital-droplets.de/philschlo/incus-backup-ui.git"
|
||||
|
||||
INSTALL_DIR="${INSTALL_DIR:-/opt/incus-backup-ui}"
|
||||
INSTALL_DIR="${INSTALL_DIR:-/opt/incubator}"
|
||||
LEGACY_INSTALL_DIR="${LEGACY_INSTALL_DIR:-/opt/incus-backup-ui}"
|
||||
REPO_URL="${INCUS_BACKUP_REPO_URL:-$DEFAULT_REPO_URL}"
|
||||
BRANCH="${INCUS_BACKUP_BRANCH:-main}"
|
||||
AGENT_DIR="$INSTALL_DIR/agent"
|
||||
OLD_AGENT_DIR="$INSTALL_DIR/backend"
|
||||
LEGACY_AGENT_DIR="$LEGACY_INSTALL_DIR/agent"
|
||||
LEGACY_BACKEND_DIR="$LEGACY_INSTALL_DIR/backend"
|
||||
STATE_DIR="${STATE_DIR:-/var/lib/incus-backup-agent}"
|
||||
CONFIG_DIR="${CONFIG_DIR:-/etc/incus-backup-agent}"
|
||||
ENV_FILE="$AGENT_DIR/.env"
|
||||
@@ -58,21 +61,25 @@ copy_repo_from_script_location() {
|
||||
fi
|
||||
command -v rsync >/dev/null 2>&1 || return 1
|
||||
rsync -a --delete \
|
||||
--exclude '.git' \
|
||||
--exclude 'agent/.env' \
|
||||
--exclude 'agent/node_modules' \
|
||||
--exclude 'management/node_modules' \
|
||||
--exclude 'frontend/node_modules' \
|
||||
"$repo_dir/" "$INSTALL_DIR/"
|
||||
"$repo_dir/agent" "$repo_dir/deploy" "$INSTALL_DIR/"
|
||||
}
|
||||
|
||||
ensure_sparse_checkout() {
|
||||
git -C "$INSTALL_DIR" sparse-checkout init --cone
|
||||
git -C "$INSTALL_DIR" sparse-checkout set agent deploy
|
||||
}
|
||||
|
||||
checkout_or_update_repo() {
|
||||
need_cmd git
|
||||
if [ -d "$INSTALL_DIR/.git" ]; then
|
||||
log "Updating $INSTALL_DIR from Git..."
|
||||
ensure_sparse_checkout
|
||||
git -C "$INSTALL_DIR" fetch --prune origin "$BRANCH"
|
||||
git -C "$INSTALL_DIR" checkout "$BRANCH"
|
||||
git -C "$INSTALL_DIR" pull --ff-only origin "$BRANCH"
|
||||
ensure_sparse_checkout
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -83,7 +90,8 @@ checkout_or_update_repo() {
|
||||
|
||||
log "Cloning $REPO_URL to $INSTALL_DIR..."
|
||||
mkdir -p "$(dirname "$INSTALL_DIR")"
|
||||
git clone --branch "$BRANCH" "$REPO_URL" "$INSTALL_DIR"
|
||||
git clone --filter=blob:none --sparse --branch "$BRANCH" "$REPO_URL" "$INSTALL_DIR"
|
||||
ensure_sparse_checkout
|
||||
}
|
||||
|
||||
move_old_agent_dir() {
|
||||
@@ -96,6 +104,18 @@ move_old_agent_dir() {
|
||||
log "Moving existing backend .env to agent .env..."
|
||||
mv "$OLD_AGENT_DIR/.env" "$ENV_FILE"
|
||||
fi
|
||||
|
||||
if [ "$INSTALL_DIR" != "$LEGACY_INSTALL_DIR" ] && [ ! -f "$ENV_FILE" ]; then
|
||||
if [ -f "$LEGACY_AGENT_DIR/.env" ]; then
|
||||
log "Migrating legacy agent .env from $LEGACY_AGENT_DIR..."
|
||||
cp "$LEGACY_AGENT_DIR/.env" "$ENV_FILE"
|
||||
chmod 600 "$ENV_FILE"
|
||||
elif [ -f "$LEGACY_BACKEND_DIR/.env" ]; then
|
||||
log "Migrating legacy backend .env from $LEGACY_BACKEND_DIR..."
|
||||
cp "$LEGACY_BACKEND_DIR/.env" "$ENV_FILE"
|
||||
chmod 600 "$ENV_FILE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_env_file() {
|
||||
@@ -201,6 +221,8 @@ install_dependencies() {
|
||||
install_systemd_service() {
|
||||
install -d -m 700 "$STATE_DIR"
|
||||
install -d -m 700 "$CONFIG_DIR"
|
||||
install -m 755 "$INSTALL_DIR/deploy/incubator.sh" /usr/local/bin/incubator
|
||||
rm -f /usr/local/bin/incus-backup-agentctl
|
||||
tmp_service="$SERVICE_FILE.tmp"
|
||||
awk -v agent_dir="$AGENT_DIR" '
|
||||
/^WorkingDirectory=/ {
|
||||
@@ -232,6 +254,7 @@ main() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
exec sudo \
|
||||
INSTALL_DIR="$INSTALL_DIR" \
|
||||
LEGACY_INSTALL_DIR="$LEGACY_INSTALL_DIR" \
|
||||
INCUS_BACKUP_REPO_URL="$REPO_URL" \
|
||||
INCUS_BACKUP_BRANCH="$BRANCH" \
|
||||
STATE_DIR="$STATE_DIR" \
|
||||
|
||||
@@ -5,7 +5,7 @@ Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/opt/incus-backup-ui/agent
|
||||
WorkingDirectory=/opt/incubator/agent
|
||||
Environment=NODE_ENV=production
|
||||
ExecStart=/usr/bin/npm start
|
||||
Restart=on-failure
|
||||
|
||||
Reference in New Issue
Block a user