Update sas4-install.sh

updated port and apache file in seperated file
This commit is contained in:
Abanoub Hany 2025-06-09 17:34:02 +00:00
parent beefd0eebc
commit 93c369dd02

View File

@ -1,51 +1,58 @@
#!/bin/bash #!/bin/bash
# Define variables # Variables
REPO_URL="https://github.com/h4775346/l2tp-manager.git" REPO_URL="https://github.com/h4775346/l2tp-manager.git"
TARGET_DIR="/opt/sas4/site/l2tp-manager/" TARGET_DIR="/opt/sas4/site/l2tp-manager/"
APACHE_CONF="/etc/apache2/sites-enabled/sas4.conf"
CHAP_SECRETS="/etc/ppp/chap-secrets" CHAP_SECRETS="/etc/ppp/chap-secrets"
APACHE_CONF="/etc/apache2/sites-available/l2tp-manager.conf"
PORTS_CONF="/etc/apache2/ports.conf"
# Update package list and install necessary packages # Update and install packages
apt-get update apt update
apt-get install -y git unzip curl apache2 apt install -y git unzip curl apache2 libapache2-mod-php
# Clone the GitHub repository # Clone the repo
if [ ! -d "$TARGET_DIR" ]; then if [ ! -d "$TARGET_DIR" ]; then
git clone $REPO_URL $TARGET_DIR git clone $REPO_URL $TARGET_DIR
else else
echo "Directory $TARGET_DIR already exists. Stashing local changes and pulling the latest changes." echo "Directory $TARGET_DIR already exists. Pulling latest changes..."
git config --global --add safe.directory $TARGET_DIR git config --global --add safe.directory $TARGET_DIR
cd $TARGET_DIR cd $TARGET_DIR
git stash git stash
git pull git pull
fi fi
# Ensure /etc/ppp/chap-secrets is writable # Set permissions
chmod 666 $CHAP_SECRETS chmod 666 $CHAP_SECRETS
# Ensure the target directory is writable by the web server
chown -R www-data:www-data $TARGET_DIR chown -R www-data:www-data $TARGET_DIR
chmod -R 755 $TARGET_DIR chmod -R 755 $TARGET_DIR
# Define the Alias and Directory block # Ensure Apache listens on port 8090
ALIAS_BLOCK=$(cat <<EOT if ! grep -q "Listen 8090" $PORTS_CONF; then
Alias /l2tp-manager $TARGET_DIR echo "Listen 8090" >> $PORTS_CONF
fi
# Create Apache VirtualHost config
if [ ! -f "$APACHE_CONF" ]; then
cat <<EOL > $APACHE_CONF
<VirtualHost *:8090>
ServerAdmin admin@localhost
DocumentRoot $TARGET_DIR
<Directory $TARGET_DIR> <Directory $TARGET_DIR>
Order allow,deny Options Indexes FollowSymLinks
Allow from all
AllowOverride All AllowOverride All
Require all granted Require all granted
</Directory> </Directory>
EOT
)
# Add the new Alias and Directory block above the existing Alias /user/api block ErrorLog \${APACHE_LOG_DIR}/l2tp-error.log
if ! grep -q "/l2tp-manager/" $APACHE_CONF; then CustomLog \${APACHE_LOG_DIR}/l2tp-access.log combined
awk -v insert="$ALIAS_BLOCK" '/Alias \/user\/api \/opt\/sas4\/site\/user\/backend\/public\// {print insert; print} !/Alias \/user\/api \/opt\/sas4\/site\/user\/backend\/public\// {print}' $APACHE_CONF > /tmp/sas4.conf && mv /tmp/sas4.conf $APACHE_CONF </VirtualHost>
EOL
a2ensite l2tp-manager.conf
fi fi
# Restart Apache to apply the changes # Restart Apache
systemctl restart apache2 systemctl reload apache2
echo "l2tp-manager installed and Apache configuration updated." echo "✅ Apache is now serving /l2tp-manager on http://your-server-ip:8090/"