diff --git a/update.sh b/update.sh index 8b90cb9..cc2e7b5 100644 --- a/update.sh +++ b/update.sh @@ -6,10 +6,10 @@ set -e # Config -APP_DIR="/opt/promdata-panel" SERVICE_NAME="promdatapanel" +DEFAULT_APP_DIR="/opt/promdata-panel" -# 1. Colors for logs +# 1. Colors & Banner GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' @@ -17,16 +17,34 @@ NC='\033[0m' # No Color echo -e "${BLUE}=== Starting PromdataPanel Update ===${NC}" -# Detect if we're in the app directory -if [ ! -d ".git" ]; then - if [ -d "$APP_DIR/.git" ]; then - cd "$APP_DIR" - else - echo -e "${RED}Error: Not in a git repository or $APP_DIR. Please run this from the app root.${NC}" - exit 1 +# 2. Detect APP_DIR automatically from systemd service +if systemctl list-unit-files | grep -q "^$SERVICE_NAME.service"; then + echo "Detecting application directory from systemd service..." + # Get WorkingDirectory from systemd (using env to handle it safely) + SERVICE_DIR=$(systemctl show -p WorkingDirectory "$SERVICE_NAME" | cut -d= -f2-) + if [ -n "$SERVICE_DIR" ] && [ -d "$SERVICE_DIR" ]; then + APP_DIR="$SERVICE_DIR" fi fi +# Fallback 1: Current directory if it contains package.json +if [ -z "$APP_DIR" ]; then + if [ -f "package.json" ]; then + APP_DIR=$(pwd) + else + APP_DIR="$DEFAULT_APP_DIR" + fi +fi + +echo -e "${BLUE}Application directory: $APP_DIR${NC}" + +if [ ! -d "$APP_DIR" ]; then + echo -e "${RED}Error: Could not find application directory at $APP_DIR. Check if you installed it correctly.${NC}" + exit 1 +fi + +cd "$APP_DIR" + # 2. Update logic if [ -d ".git" ]; then echo -e "${BLUE}Git repository detected. Pulling latest code...${NC}"