优化权限

This commit is contained in:
CN-JS-HuiBai
2026-04-05 15:27:12 +08:00
parent 035ebd8d40
commit a9fe0f219a

View File

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