|
|
@@ -5,6 +5,9 @@ SERVICE_NAME="vmess-domain-rotator"
|
|
|
APP_DIR="/opt/vmess-domain-rotator"
|
|
|
RUN_USER="vmessrotator"
|
|
|
RUN_GROUP="vmessrotator"
|
|
|
+APP_DIR_SET="0"
|
|
|
+RUN_USER_SET="0"
|
|
|
+RUN_GROUP_SET="0"
|
|
|
INTERVAL="12h"
|
|
|
INSTALL_DEPS="1"
|
|
|
OVERWRITE_CONFIG="0"
|
|
|
@@ -13,6 +16,11 @@ usage() {
|
|
|
cat <<'EOF'
|
|
|
Usage: sudo bash scripts/install_debian.sh [options]
|
|
|
|
|
|
+Default behavior:
|
|
|
+ - If current source dir is a git repo and --app-dir is not set, install in-place
|
|
|
+ (service runs directly from this repo so auto-commit works on your real git repo).
|
|
|
+ - If --app-dir is set, files are copied into that directory.
|
|
|
+
|
|
|
Options:
|
|
|
--app-dir <path> Install directory (default: /opt/vmess-domain-rotator)
|
|
|
--user <name> Service user (default: vmessrotator)
|
|
|
@@ -24,6 +32,7 @@ Options:
|
|
|
|
|
|
Examples:
|
|
|
sudo bash scripts/install_debian.sh
|
|
|
+ sudo bash scripts/install_debian.sh --app-dir /opt/vmess-domain-rotator
|
|
|
sudo bash scripts/install_debian.sh --user root --group root --interval 10min
|
|
|
EOF
|
|
|
}
|
|
|
@@ -32,14 +41,17 @@ while [[ $# -gt 0 ]]; do
|
|
|
case "$1" in
|
|
|
--app-dir)
|
|
|
APP_DIR="$2"
|
|
|
+ APP_DIR_SET="1"
|
|
|
shift 2
|
|
|
;;
|
|
|
--user)
|
|
|
RUN_USER="$2"
|
|
|
+ RUN_USER_SET="1"
|
|
|
shift 2
|
|
|
;;
|
|
|
--group)
|
|
|
RUN_GROUP="$2"
|
|
|
+ RUN_GROUP_SET="1"
|
|
|
shift 2
|
|
|
;;
|
|
|
--interval)
|
|
|
@@ -72,6 +84,20 @@ if [[ "$(id -u)" -ne 0 ]]; then
|
|
|
fi
|
|
|
|
|
|
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
+DEPLOY_MODE="copy"
|
|
|
+
|
|
|
+if [[ "$APP_DIR_SET" != "1" ]] && git -C "$SOURCE_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
|
+ APP_DIR="$SOURCE_DIR"
|
|
|
+ DEPLOY_MODE="in-place"
|
|
|
+
|
|
|
+ if [[ -n "${SUDO_USER:-}" ]] && [[ "$RUN_USER_SET" != "1" ]]; then
|
|
|
+ RUN_USER="$SUDO_USER"
|
|
|
+ fi
|
|
|
+
|
|
|
+ if [[ -n "${SUDO_USER:-}" ]] && [[ "$RUN_GROUP_SET" != "1" ]]; then
|
|
|
+ RUN_GROUP="$(id -gn "$SUDO_USER")"
|
|
|
+ fi
|
|
|
+fi
|
|
|
|
|
|
if [[ "$INSTALL_DEPS" == "1" ]]; then
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
@@ -90,31 +116,37 @@ fi
|
|
|
|
|
|
mkdir -p "$APP_DIR"
|
|
|
|
|
|
-CONFIG_BACKUP=""
|
|
|
-if [[ "$OVERWRITE_CONFIG" != "1" && -f "$APP_DIR/config.json" ]]; then
|
|
|
- CONFIG_BACKUP="$(mktemp)"
|
|
|
- cp "$APP_DIR/config.json" "$CONFIG_BACKUP"
|
|
|
-fi
|
|
|
+if [[ "$DEPLOY_MODE" == "copy" ]]; then
|
|
|
+ CONFIG_BACKUP=""
|
|
|
+ if [[ "$OVERWRITE_CONFIG" != "1" && -f "$APP_DIR/config.json" ]]; then
|
|
|
+ CONFIG_BACKUP="$(mktemp)"
|
|
|
+ cp "$APP_DIR/config.json" "$CONFIG_BACKUP"
|
|
|
+ fi
|
|
|
|
|
|
-tar -C "$SOURCE_DIR" \
|
|
|
- --exclude='.git' \
|
|
|
- --exclude='.DS_Store' \
|
|
|
- --exclude='__pycache__' \
|
|
|
- -cf - . | tar -C "$APP_DIR" -xf -
|
|
|
+ tar -C "$SOURCE_DIR" \
|
|
|
+ --exclude='.git' \
|
|
|
+ --exclude='.DS_Store' \
|
|
|
+ --exclude='__pycache__' \
|
|
|
+ -cf - . | tar -C "$APP_DIR" -xf -
|
|
|
|
|
|
-if [[ -n "$CONFIG_BACKUP" ]]; then
|
|
|
- cp "$CONFIG_BACKUP" "$APP_DIR/config.json"
|
|
|
- rm -f "$CONFIG_BACKUP"
|
|
|
+ if [[ -n "$CONFIG_BACKUP" ]]; then
|
|
|
+ cp "$CONFIG_BACKUP" "$APP_DIR/config.json"
|
|
|
+ rm -f "$CONFIG_BACKUP"
|
|
|
+ fi
|
|
|
fi
|
|
|
|
|
|
mkdir -p "$APP_DIR/runtime"
|
|
|
chmod +x "$APP_DIR/scripts/run_update_and_commit.sh" "$APP_DIR/scripts/install_debian.sh" "$APP_DIR/scripts/uninstall_debian.sh" || true
|
|
|
|
|
|
if [[ "$RUN_USER" != "root" ]]; then
|
|
|
- chown -R "$RUN_USER:$RUN_GROUP" "$APP_DIR"
|
|
|
+ if [[ "$DEPLOY_MODE" == "in-place" ]]; then
|
|
|
+ chown -R "$RUN_USER:$RUN_GROUP" "$APP_DIR/runtime"
|
|
|
+ else
|
|
|
+ chown -R "$RUN_USER:$RUN_GROUP" "$APP_DIR"
|
|
|
+ fi
|
|
|
fi
|
|
|
|
|
|
-if ! git -C "$APP_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
|
+if [[ "$DEPLOY_MODE" == "copy" ]] && ! git -C "$APP_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
|
git -C "$APP_DIR" init
|
|
|
fi
|
|
|
|
|
|
@@ -152,6 +184,7 @@ systemctl enable --now "${SERVICE_NAME}.timer"
|
|
|
systemctl start "${SERVICE_NAME}.service"
|
|
|
|
|
|
echo "Installed successfully."
|
|
|
+echo "Deploy mode: ${DEPLOY_MODE}"
|
|
|
echo "App dir: ${APP_DIR}"
|
|
|
echo "Service: ${SERVICE_NAME}.service"
|
|
|
echo "Timer: ${SERVICE_NAME}.timer"
|