#!/bin/bash ############################################################################### # Setup a Debian 13x64 VM with Watch My Domains SED # # Copyright (C) 2018-2026 CodePunch Solutions - All Rights Reserved # https://codepunch.com/ # # Author: Anil Kumar # Last revised by Syam Kumar on 09 January 2026 # # This will install Apache, PHP 8.4, LetsEncrypt, fail2ban, MariaDB etc. # A user 'wmdsed' will be created (password saved to /root/required.txt) # MariaDB root password is also saved to /root/required.txt. Please # delete this file after saving the passwords. # ############################################################################### # # if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1 fi # # DEFAULTEMAIL="example@example.com" REGEMAIL=${1:-$DEFAULTEMAIL} if [[ "$REGEMAIL" == "example@example.com" ]]; then read -p "Enter the Email to Use for Registering Let's Encrypt: " REGEMAIL fi # # Email validation if [[ ! $REGEMAIL =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then echo "Invalid email format!" exit 1 fi if [ -z "$2" ]; then read -p "Enter the server hostname where Watch My Domains SED will be installed.: " boxname else boxname=${2} fi # Hostname validation if [[ ! $boxname =~ ^[a-zA-Z0-9][-a-zA-Z0-9]*\.[a-zA-Z0-9.-]+$ ]]; then echo "Invalid hostname format!" exit 1 fi # # export DEBIAN_FRONTEND=noninteractive export DEBIAN_PRIORITY=critical # # sudo mkdir -p /etc/apt/keyrings curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg # NODE_MAJOR=20 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list # # sudo -E apt-get -qy update sudo -E apt-get -qy -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" upgrade sudo -E apt-get -qy autoclean apt-get -y install logwatch unzip fail2ban curl apt-get -y install perl-modules # # RNDAPPPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) theapppas=${SEDAPPPASS:-$RNDAPPPASS} # RNDSEDPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) password=${WMDSEDPASS:-$RNDSEDPASS} username=wmdsed echo "User wmdsed: $password" >> "/root/required.txt" echo "User sedapp: $theapppas" >> "/root/required.txt" grep -E "^$username" /etc/passwd >/dev/null if [ $? -eq 0 ]; then echo "$username exists!" else pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) useradd -m -p $pass $username retVal=$? if [ $retVal -ne 0 ]; then echo "Failed to add a user!" else echo "User has been added to system!" if [ -f /root/.ssh/authorized_keys ]; then cd /home/wmdsed/ || exit mkdir .ssh chown wmdsed:wmdsed .ssh chmod 700 .ssh cd .ssh || exit cp /root/.ssh/authorized_keys . chown wmdsed:wmdsed authorized_keys chmod 600 authorized_keys fi usermod --shell /bin/bash wmdsed fi fi # # apt-get -y install apache2 php mariadb-server libapache2-mod-php php-mysql php-gd php8.4-opcache php-curl php-mbstring php-xml php-zip php-soap php-bcmath php-intl # # RNDROOTPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) rootpass=${MSQLROOTPASS:-$RNDROOTPASS} echo "MySQL Root: $rootpass" >> "/root/required.txt" mysql -u root <<-EOF ALTER USER 'root'@'localhost' IDENTIFIED BY '$rootpass'; FLUSH PRIVILEGES; EOF # # MAINDB=wmdsed6 mysql -uroot -p${rootpass} -e "CREATE DATABASE ${MAINDB} /*\!40100 DEFAULT CHARACTER SET utf8 */;" mysql -uroot -p${rootpass} -e "GRANT ALL PRIVILEGES ON ${MAINDB}.* TO '${MAINDB}'@'localhost' IDENTIFIED BY '${password}';" mysql -uroot -p${rootpass} -e "FLUSH PRIVILEGES;" # # # Download and install ionCube in an isolated temporary directory. # Do not follow redirects or reuse an archive from an earlier attempt. if ! ( loader_dir=$(mktemp -d) || exit 1 trap 'rm -rf -- "$loader_dir"' EXIT cd "$loader_dir" || exit 1 wget --no-config --https-only --max-redirect=0 https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz -O loader.tar.gz || exit 1 test -s loader.tar.gz || exit 1 tar -xzf loader.tar.gz -- ioncube/ioncube_loader_lin_8.4.so || exit 1 test -f ioncube/ioncube_loader_lin_8.4.so && test ! -L ioncube/ioncube_loader_lin_8.4.so && test -s ioncube/ioncube_loader_lin_8.4.so || exit 1 mkdir -p /usr/local/ioncube || exit 1 cp ioncube/ioncube_loader_lin_8.4.so /usr/local/ioncube/ || exit 1 ); then echo "ionCube loader download or installation failed." >&2 exit 1 fi # # cd /etc/apache2/sites-enabled || exit mv 000-default.conf zzz.conf a2enmod rewrite a2enmod ssl a2enmod cgi a2enmod authz_groupfile # # apt-get -y install certbot python3-certbot-apache # # su wmdsed -c 'mkdir /home/wmdsed/logs/' su wmdsed -c 'mkdir /home/wmdsed/logs/www' su wmdsed -c 'mkdir /home/wmdsed/logs/wmdsed' su wmdsed -c 'mkdir /home/wmdsed/sites/' su wmdsed -c 'mkdir /home/wmdsed/backup/' su wmdsed -c 'wget --content-disposition -P /home/wmdsed/sites/ https://domainpunch.com/sed/wmdsed60_trial.zip.php' su wmdsed -c 'unzip /home/wmdsed/sites/wmdsed60_trial.zip -d /home/wmdsed/sites/' su wmdsed -c 'rm /home/wmdsed/sites/wmdsed60_trial.zip' su wmdsed -c 'cp /home/wmdsed/sites/wmdsed60/config-sample.php /home/wmdsed/sites/wmdsed60/config.php' # # chmod u+w,g+w,o+w /home/wmdsed/logs/wmdsed # # su wmdsed -c 'sed -i -e ''s/dbname_here/wmdsed6/g'' /home/wmdsed/sites/wmdsed60/config.php' su wmdsed -c 'sed -i -e ''s/dbuser_here/wmdsed6/g'' /home/wmdsed/sites/wmdsed60/config.php' su wmdsed -c "sed -i -e 's/secret_here/${password}/g' /home/wmdsed/sites/wmdsed60/config.php" su wmdsed -c "sed -i -e 's/secret/${theapppas}/g' /home/wmdsed/sites/wmdsed60/config.php" su wmdsed -c "sed -i -e 's/\/path\/to\/logs\//\/home\/wmdsed\/logs\/wmdsed\//g' /home/wmdsed/sites/wmdsed60/config.php" # # hostname=`uname -n` cat > /home/wmdsed/backup/backup.sh << 'EOF' mysqldump -u wmdsed6 -pthepassword --skip-lock-tables wmdsed6 > /home/wmdsed/backup/wmdsed6_thehostname_`date +%Y%m%d`.sql rm /home/wmdsed/backup/wmdsed6_thehostname_`date -d "15 days ago" +%Y%m%d`.sql EOF # # su wmdsed -c "sed -i -e 's/thepassword/${password}/g' /home/wmdsed/backup/backup.sh" su wmdsed -c "sed -i -e 's/thehostname/${hostname}/g' /home/wmdsed/backup/backup.sh" # # chown wmdsed:wmdsed /home/wmdsed/backup/backup.sh chmod u+x,g+x,o+x /home/wmdsed/backup/backup.sh # # cat > /etc/apache2/sites-enabled/wmdsed.conf << EOF ############################################################### Order allow,deny Deny from all ############################################################### Options +FollowSymLinks -Indexes -MultiViews AllowOverride All Order allow,deny allow from all Require all granted ErrorDocument 404 /404.php ############################################################### AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all ############################################################### ServerAdmin webmaster@localhost ServerName $boxname DocumentRoot /home/wmdsed/sites/wmdsed60/ ErrorLog /home/wmdsed/logs/www/error_default.log CustomLog /home/wmdsed/logs/www/access_default.log combined LogLevel warn ############################################################### EOF # # echo "zend_extension = /usr/local/ioncube/ioncube_loader_lin_8.4.so" >> "/etc/php/8.4/apache2/php.ini" echo "zend_extension = /usr/local/ioncube/ioncube_loader_lin_8.4.so" >> "/etc/php/8.4/cli/php.ini" # # service apache2 restart # # # create the tables for the first time. su wmdsed -c 'php /home/wmdsed/sites/wmdsed60/sed.php list=tables' # # debconf-set-selections <<< "postfix postfix/mailname string $boxname" debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'" apt-get install -y postfix # # randomtext=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) cat > /home/wmdsed/sites/wmdsed60/${randomtext}.txt << EOF found EOF # # chown wmdsed:wmdsed /home/wmdsed/sites/wmdsed60/${randomtext}.txt chmod +x /home/wmdsed/ # # # Do not proceed from here until the host name resolves to the local droplet # # url="http://${boxname}/${randomtext}.txt" status=`curl -s https://codepunch.com/tools/checkif.php?url=${url}` echo $status while [[ ${status} != 1 ]]; do sleep 5 status=`curl -s https://codepunch.com/tools/checkif.php?url=${url}` echo "waiting for $boxname to resolve (${status})" done # # rm /home/wmdsed/sites/wmdsed60/${randomtext}.txt # # su wmdsed -c "echo '* * * * * php /home/wmdsed/sites/wmdsed60/cron.php >/dev/null 2>&1' >> /home/wmdsed/mycron.txt" su wmdsed -c "echo '30 22 * * * /home/wmdsed/backup/backup.sh >/dev/null 2>&1' >> /home/wmdsed/mycron.txt" su wmdsed -c 'crontab /home/wmdsed/mycron.txt' su wmdsed -c 'rm /home/wmdsed/mycron.txt' # # apt-get -y install nodejs libnss3-tools libgbm-dev libasound2t64 libatk1.0-0t64 libatk-bridge2.0-0t64 libcups2t64 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libxkbcommon0 libpango-1.0-0 libpangocairo-1.0-0 # # su wmdsed -c "echo 'mkdir /home/wmdsed/webdata' >> /home/wmdsed/ws.sh" su wmdsed -c "echo 'cd /home/wmdsed/webdata/' >> /home/wmdsed/ws.sh" su wmdsed -c "echo 'npm install puppeteer' >> /home/wmdsed/ws.sh" su wmdsed -c "echo 'npm install minimist' >> /home/wmdsed/ws.sh" su wmdsed -c "echo 'npm install timers-promises' >> /home/wmdsed/ws.sh" su wmdsed -c "echo 'ln -s /home/wmdsed/webdata /home/wmdsed/logs/wmdsed/websites' >> /home/wmdsed/ws.sh" su wmdsed -c "echo 'cp /home/wmdsed/sites/wmdsed60/lib/js/websites.js /home/wmdsed/webdata' >> /home/wmdsed/ws.sh" su wmdsed -c "chmod u+x /home/wmdsed/ws.sh" su wmdsed -c "/home/wmdsed/ws.sh" su wmdsed -c "rm /home/wmdsed/ws.sh" # # certbot -m $REGEMAIL --agree-tos register --noninteractive certbot --authenticator webroot --webroot-path /home/wmdsed/sites/wmdsed60/ certonly -d $boxname #wget https://raw.githubusercontent.com/certbot/certbot/master/certbot-apache/certbot_apache/options-ssl-apache.conf -P /etc/letsencrypt/ # # cat > /etc/apache2/sites-enabled/wmdsed.conf << EOF ############################################################### Order allow,deny Deny from all ############################################################### Options +FollowSymLinks -Indexes -MultiViews AllowOverride All Order allow,deny allow from all Require all granted ErrorDocument 404 /404.php ############################################################### AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all ############################################################### ServerName $boxname Redirect Permanent / https://$boxname/ ############################################################### SSLCertificateFile /etc/letsencrypt/live/${boxname}/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/${boxname}/privkey.pem #Include /etc/letsencrypt/options-ssl-apache.conf ServerAdmin webmaster@localhost ServerName $boxname DocumentRoot /home/wmdsed/sites/wmdsed60/ ErrorLog /home/wmdsed/logs/www/error_default.log CustomLog /home/wmdsed/logs/www/access_default.log combined ############################################################### EOF # # service apache2 restart # # crontab -l > /root/mycron echo "0 0 1 * * certbot renew >/dev/null 2>&1" >> /root/mycron crontab /root/mycron rm /root/mycron # #