diff --git a/install.sh b/install.sh index 9d0725d..d36f576 100644 --- a/install.sh +++ b/install.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -USER=${SUDO_USER:-$(whoami)} - # Function to prompt for a Yes/no answer yes_no_prompt() { local prompt="$1" @@ -121,7 +119,7 @@ if yes_no_prompt "šŸ› ļø Do you want the script to run apt update and apt upgra apt-get update && apt-get upgrade fi -# Clone repository +# Clone repository & set permissions if [ ! -d "/opt" ]; then mkdir -p /opt echo "šŸ“‚ '/opt' has been created" @@ -133,18 +131,20 @@ cd /opt || { echo "āŒ Failed to change directory to '/opt'. Exiting..."; exit 1 if [ ! -d "UFW-AbuseIPDB-Reporter" ]; then echo "šŸ“„ Cloning the UFW-AbuseIPDB-Reporter repository..." - git clone https://github.com/sefinek/UFW-AbuseIPDB-Reporter.git --branch node.js || { echo "āŒ Failed to clone the repository. Exiting..."; exit 1; } + sudo git clone https://github.com/sefinek/UFW-AbuseIPDB-Reporter.git --branch node.js || { echo "āŒ Failed to clone the repository. Exiting..."; exit 1; } else echo "✨ The UFW-AbuseIPDB-Reporter repository already exists!" fi +sudo chown "$USER":"$USER" /opt/UFW-AbuseIPDB-Reporter -R + echo "šŸ“„ Pulling latest changes..." cd UFW-AbuseIPDB-Reporter || { echo "āŒ Failed to change directory to 'UFW-AbuseIPDB-Reporter'. Exiting..."; exit 1; } git pull || { echo "āŒ Failed to pull the latest changes. Exiting..."; exit 1; } # Install npm dependencies echo "šŸ“¦ Installing npm dependencies..." -npm install --silent +npm install # Copy configuration file echo "šŸ“‘ Copying default.config.js to config.js..." @@ -168,32 +168,32 @@ chmod 644 "$ufw_log_path" # Uninstall corepack echo "šŸ—‘ļø Uninstalling corepack..." -npm uninstall corepack -g --silent +sudo npm uninstall corepack -g # Install pm2 echo "šŸ“¦ Installing PM2..." -npm install pm2 -g --silent +sudo npm install pm2 -g # Create logs directory echo "šŸ“‚ Creating /var/log/ufw-abuseipdb directory..." -mkdir -p /var/log/ufw-abuseipdb -chown "$USER":"$USER" /var/log/ufw-abuseipdb -R +sudo mkdir -p /var/log/ufw-abuseipdb +sudo chown "$USER":"$USER" /var/log/ufw-abuseipdb -R # Configure pm2 echo "āš™ļø Configuring PM2..." -sudo -u "$USER" pm2 start -sudo -u "$USER" pm2 startup +pm2 start +pm2 startup # Execute the command generated by pm2 startup echo "šŸ”§ Complete pm2 startup configuration (for $USER):" sudo env PATH="$PATH":/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u "$USER" --hp /opt/"$USER" -sudo -u "$USER" pm2 save +pm2 save # Final echo -e "\n\n🌌 Checking PM2 status..." -sudo -u "$USER" pm2 status +pm2 status echo -e "\nšŸŽ‰ Installation and configuration completed! Use the 'pm2 logs' command to monitor logs in real time."