diff --git a/install.sh b/install.sh index fd01471..cad14ab 100644 --- a/install.sh +++ b/install.sh @@ -12,15 +12,16 @@ NC='\033[0m' # No Color echo -e "${BLUE}=== Data Visualization Display Wall Installer ===${NC}" -# 1. Check permissions -if [ "$EUID" -ne 0 ]; then - echo -e "${RED}Please run as root (sudo ./Install.sh)${NC}" - exit 1 +# 1. Permission check (no longer mandatory) +if [ "$EUID" -eq 0 ]; then + # If run as sudo, get the real user that called it + REAL_USER=${SUDO_USER:-$USER} +else + REAL_USER=$USER fi # 2. Get current directory and user PROJECT_DIR=$(pwd) -REAL_USER=${SUDO_USER:-$USER} USER_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6) echo -e "Project Directory: ${GREEN}$PROJECT_DIR${NC}" @@ -49,7 +50,6 @@ if [ ! -f ".env" ]; then if [ -f ".env.example" ]; then echo -e "Creating .env from .env.example..." cp .env.example .env - chown "$REAL_USER":"$REAL_USER" .env echo -e "${GREEN}Created .env file. Please ensure values are correct.${NC}" else echo -e "${RED}Error: .env.example not found. Configuration missing.${NC}" @@ -58,8 +58,7 @@ fi # 6. Install NPM dependencies echo -e "${BLUE}Installing dependencies...${NC}" -# Run npm install as the real user to avoid permission issues in node_modules -sudo -u "$REAL_USER" npm install +npm install if [ $? -ne 0 ]; then echo -e "${RED}NPM install failed.${NC}" @@ -70,9 +69,8 @@ fi SERVICE_FILE="/etc/systemd/system/data-wall.service" NODE_PATH=$(command -v node) -echo -e "${BLUE}Creating systemd service at $SERVICE_FILE...${NC}" - -cat < "$SERVICE_FILE" +echo -e "${BLUE}Creating systemd service at $SERVICE_FILE... (May require password)${NC}" +sudo bash -c "cat < '$SERVICE_FILE' [Unit] Description=Data Visualization Display Wall After=network.target mysql.service redis-server.service valkey-server.service @@ -99,18 +97,18 @@ LimitNOFILE=65535 [Install] WantedBy=multi-user.target -EOF +EOF" # 8. Reload Systemd and Start -echo -e "${BLUE}Reloading systemd and restarting service...${NC}" -systemctl daemon-reload -systemctl enable data-wall -systemctl restart data-wall +echo -e "${BLUE}Reloading systemd and restarting service... (May require password)${NC}" +sudo systemctl daemon-reload +sudo systemctl enable data-wall +sudo systemctl restart data-wall # 9. Check Status echo -e "${BLUE}Checking service status...${NC}" sleep 2 -if systemctl is-active --quiet data-wall; then +if sudo systemctl is-active --quiet data-wall; then echo -e "${GREEN}SUCCESS: Service is now running.${NC}" PORT=$(grep "^PORT=" .env | cut -d'=' -f2) PORT=${PORT:-3000} @@ -166,7 +164,6 @@ http://$DOMAIN { } EOF fi - chown "$REAL_USER":"$REAL_USER" "$CADDY_FILE" echo -e "${GREEN}Caddyfile generated at $PROJECT_DIR/$CADDY_FILE${NC}" echo -e "${YELLOW}Tip: Ensure Caddy is installed and pointing to this file.${NC}" @@ -229,7 +226,6 @@ server { } EOF fi - chown "$REAL_USER":"$REAL_USER" "$NGINX_PATH" echo -e "${GREEN}Nginx config generated at $NGINX_PATH${NC}" echo -e "${YELLOW}Tip: You can symlink this to /etc/nginx/sites-enabled/ to activate.${NC}" else