From 8124a4d09091c85efaaed88ba40c4660673148a1 Mon Sep 17 00:00:00 2001 From: Johan Date: Sat, 9 Jul 2022 22:21:35 +0200 Subject: [PATCH] Add Apache installation bash script --- BashScripts/install-apache.sh | 127 ++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 BashScripts/install-apache.sh diff --git a/BashScripts/install-apache.sh b/BashScripts/install-apache.sh new file mode 100644 index 0000000..e064d88 --- /dev/null +++ b/BashScripts/install-apache.sh @@ -0,0 +1,127 @@ +# Install using: sudo su -c "bash <(wget -qO- /url/to/install-apache.sh)" + +REALUSER=$(logname) +mkdir /home/$REALUSER/www 2>>install.log & + +#apt install docker.io + +# apt update 2>>install.log && +apt install apache2 -y 2>>install.log && +apt install samba -y 2>>install.log && + +# Setting up Samba shares +if ! grep -q "/home/$REALUSER/www" "/etc/samba/smb.conf"; then + cat <> "/etc/samba/smb.conf" +[$REALUSER-www] + comment = Samba File Server Share + path = /home/$REALUSER/www + browsable = yes + guest ok = yes + read only = no + create mask = 777 + force create mode = 777 + directory mask = 777 + force directory mode = 777 +[/$REALUSER-www] +EOT +fi +if ! grep -q "/var/www" "/etc/samba/smb.conf"; then + cat <> "/etc/samba/smb.conf" +[www] + comment = Samba File Server Share + path = /var/www + browsable = yes + guest ok = yes + read only = no + create mask = 777 + force create mode = 777 + directory mask = 777 + force directory mode = 777 + valid users = $REALUSER, root + force user = root + force group = root + writeable = yes + admin users = root +[/www] +EOT +fi +if ! grep -q "/etc/apache2" "/etc/samba/smb.conf"; then + cat <> "/etc/samba/smb.conf" +[apache2] + comment = Samba File Server Share + path = /etc/apache2 + browsable = yes + guest ok = yes + read only = no + create mask = 777 + force create mode = 777 + directory mask = 777 + force directory mode = 777 + valid users = $REALUSER, root + force user = root + force group = root + writeable = yes + admin users = root +[/apache2] +EOT +fi +sed -i -e 's/obey pam restrictions = yes/obey pam restrictions = no/g' /etc/samba/smb.conf +service smbd restart 2>>install.log && +ufw allow samba 2>>install.log + +if ! pdbedit "$REALUSER" &>/dev/null; then + sudo smbpasswd -a $REALUSER 2>>install.log +fi + +mkdir -p /var/www/cms/www 2>>install.log && +mkdir -p /var/www/cms/log 2>>install.log && +chmod -R uga+rwx /home/$REALUSER/www/ 2>>install.log && +chmod -R uga+rwx /var/www/ 2>>install.log && +# chmod -R 775 /var/www/ +# chown -R $REALUSER:$REALUSER /var/www/ +# chown -R $REALUSER:$REALUSER /etc/apache2/ + +service apache2 restart 2>>install.log && + +apt install libcgi-session-perl -y 2>>install.log && +apt install libapache2-mod-perl2 -y 2>>install.log && +apt install libarchive-zip-perl -y 2>>install.log && +apt install libdbd-sqlite2-perl -y 2>>install.log && +apt install libdbd-sqlite3-perl -y 2>>install.log && +apt install libdbd-mysql-perl -y 2>>install.log && +apt install libio-string-perl -y 2>>install.log && +apt install libjson-perl -y 2>>install.log && +apt install libmime-lite-perl -y 2>>install.log && +apt install libexcel-writer-xlsx-perl -y 2>>install.log && + +a2enmod rewrite 2>>install.log && +a2enmod headers 2>>install.log && +a2enmod expires 2>>install.log && +a2enmod cgi.load 2>>install.log && + +if [ ! -f "/etc/apache2/sites-enabled/cms.conf" ]; then + cat < "/etc/apache2/sites-enabled/cms.conf" +Listen 8090 + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/cms/www + ErrorLog /var/www/cms/log/error.log + CustomLog /var/www/cms/log/access.log combined + + + Options Indexes FollowSymLinks MultiViews + DirectoryIndex index.html index.pl + AllowOverride All + Require all granted + + + AddHandler cgi-script .pl + Options +ExecCGI + + +EOT +fi + +systemctl restart apache2 2>>install.log && + +echo 'Installation complete' \ No newline at end of file