From 738c765d84f30b3a15bc15a9c6571ede71966e62 Mon Sep 17 00:00:00 2001 From: robojerk Date: Wed, 25 Jun 2025 15:22:05 -0700 Subject: [PATCH] Fix install script for same-directory installation and improve test script robustness --- install.sh | 32 ++++++++++++++++++++++++-------- test-install.sh | 17 ++++++++++++++--- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/install.sh b/install.sh index ed846c7..2c1974b 100644 --- a/install.sh +++ b/install.sh @@ -94,12 +94,20 @@ mkdir -p "$INSTALL_DIR" chown $USERNAME:docker "$INSTALL_DIR" # Copy files to installation directory -cp update-agent.sh "$INSTALL_DIR/" -cp config-parser.sh "$INSTALL_DIR/" -chmod +x "$INSTALL_DIR/update-agent.sh" -chmod +x "$INSTALL_DIR/config-parser.sh" -chown $USERNAME:docker "$INSTALL_DIR/update-agent.sh" -chown $USERNAME:docker "$INSTALL_DIR/config-parser.sh" +if [ "$SCRIPT_DIR" != "$INSTALL_DIR" ]; then + cp update-agent.sh "$INSTALL_DIR/" + cp config-parser.sh "$INSTALL_DIR/" + chmod +x "$INSTALL_DIR/update-agent.sh" + chmod +x "$INSTALL_DIR/config-parser.sh" + chown $USERNAME:docker "$INSTALL_DIR/update-agent.sh" + chown $USERNAME:docker "$INSTALL_DIR/config-parser.sh" +else + # Files are already in the target directory, just ensure permissions + chmod +x "$INSTALL_DIR/update-agent.sh" + chmod +x "$INSTALL_DIR/config-parser.sh" + chown $USERNAME:docker "$INSTALL_DIR/update-agent.sh" + chown $USERNAME:docker "$INSTALL_DIR/config-parser.sh" +fi # Create default .env file if it doesn't exist if [ ! -f "$INSTALL_DIR/.env" ]; then @@ -123,8 +131,16 @@ EOF fi # Copy example configuration files -cp config.toml.example "$INSTALL_DIR/config.toml" -chown $USERNAME:docker "$INSTALL_DIR/config.toml" +if [ "$SCRIPT_DIR" != "$INSTALL_DIR" ]; then + cp config.toml.example "$INSTALL_DIR/config.toml" + chown $USERNAME:docker "$INSTALL_DIR/config.toml" +else + # File is already in the target directory, just ensure it exists and has proper permissions + if [ ! -f "$INSTALL_DIR/config.toml" ]; then + cp config.toml.example "$INSTALL_DIR/config.toml" + fi + chown $USERNAME:docker "$INSTALL_DIR/config.toml" +fi # Update service file with username and installation directory sed "s|YOUR_USERNAME|$USERNAME|g; s|/opt/composesync|$INSTALL_DIR|g" composesync.service > /etc/systemd/system/composesync.service diff --git a/test-install.sh b/test-install.sh index a908588..0fe293d 100644 --- a/test-install.sh +++ b/test-install.sh @@ -6,11 +6,22 @@ set -e # Get the installation directory from the service file -INSTALL_DIR=$(systemctl show composesync --property=ExecStart | sed 's/.*ExecStart=//' | sed 's|/update-agent.sh.*||') +INSTALL_DIR="" +if systemctl list-unit-files | grep -q composesync; then + INSTALL_DIR=$(systemctl show composesync --property=ExecStart 2>/dev/null | sed 's/.*ExecStart=//' | sed 's|/update-agent.sh.*||' || echo "") +fi +# If we can't get it from the service, try to determine from current directory if [ -z "$INSTALL_DIR" ]; then - echo "❌ Could not determine installation directory from service" - exit 1 + # Check if we're in a ComposeSync installation directory + if [ -f "update-agent.sh" ] && [ -f "config-parser.sh" ]; then + INSTALL_DIR="$(pwd)" + echo "⚠️ Service not found, testing current directory: $INSTALL_DIR" + else + echo "❌ Could not determine installation directory from service or current location" + echo " Make sure you're running this from the ComposeSync installation directory" + exit 1 + fi fi echo "🧪 Testing ComposeSync installation in: $INSTALL_DIR"