add possibility to https

This commit is contained in:
rnsrk 2021-09-28 10:18:27 +02:00
parent abba49a635
commit bd02b48507
2 changed files with 238 additions and 96 deletions

37
example-ssl.conf Normal file
View file

@ -0,0 +1,37 @@
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin <your email>
ServerName www.<your website>
ServerAlias <your website>
DocumentRoot /var/www/html/<your website>/web
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile <path to SSLCertificateFile.pem>
SSLCertificateKeyFile <path to SSLCertificateKeyFile.key>
# Depending on your provider, you may not need a SSLCertificateChainFile
# SSLCertificateChainFile <path to SSLCertificateChainFile.crt>
# Rewrite rule to redirect www.<your website> to <your website>
# RewriteEngine on
# RewriteCond %{SERVER_NAME} =<your website>
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
# OR
# Rewrite rule to redirect <your website> to www.<your website>
# RewriteEngine on
# RewriteCond %{SERVER_NAME} =example.com
# RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent
<Directory /var/www/html/<your website>/web>
Options FollowSymlinks
AllowOverride All
Require all granted
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q= [L,QSA]
</Directory>
</VirtualHost>
</IfModule>

View file

@ -7,38 +7,38 @@ RED='\033[0;31m'
NC='\033[0m' NC='\033[0m'
# Check if executer is root # Check if executer is root
if [ "$EUID" -ne 0 ] if [ "$EUID" -ne 0 ]; then
then echo -e"${RED} Please run as root: \"sudo ./install_drupal-wisski.bash\"${NC}" echo -e "${RED}Please run as root: \"sudo ./install_drupal-wisski.bash\""
exit exit
fi fi
echo -e "${GREEN}Hi, this script installs a LAMP-Stack with the latest Drupal-WissKI for you!${NC}" echo -e "${GREEN}Hi, this script installs a LAMP-Stack with the latest Drupal-WissKI for you!"
echo echo
sleep 3 sleep 3
# Check if installation is for local develepment or production # Check if installation is for local develepment or production
# If yes: add website name to /etc/hosts/, see section "add website to /etc/hosts" # If yes: add website name to /etc/hosts/, see section "add website to /etc/hosts"
echo -e "${YELLOW}Do you use this script to install WissKI on a local development system" echo -e "${YELLOW}Do you use this script to install WissKI on a local development system"
echo -e "or on a server for production?${NC}" echo -e "or on a server for production?"
echo -e "${YELLOW}(Selecting \"for local development\" adds your domain to /etc/hosts) in a later step.${NC}" echo -e "(Selecting \"for local development\" adds your domain to /etc/hosts) in a later step."
echo -e "${YELLOW}(Selecting \"for production\" opens the possibility to use ssl.)${NC}" echo -e "(Selecting \"for production\" opens the possibility to use ssl.)${NC}"
echo echo
PS3="I am installing WissKI... " PS3="I am installing option... "
options=("for local development." "for production." "I don't know, please quit.") options=("for local development." "for production." "I don't know, please quit.")
select opt in "${options[@]}" select opt in "${options[@]}"
do do
case $opt in case $opt in
"for local development.") "for local development.")
LOCALHOST=true LOCALHOST=true
echo -e "${GREEN} Okay, will add website name to /etc/hosts later.${NC}" echo -e "${GREEN} Okay, will add website name to /etc/hosts later."
break break
;; ;;
"for production.") "for production.")
echo "${GREEN}Okay fine.${NC}" echo -e "${GREEN}Okay fine."
break break
;; ;;
"I don't know, please quit.") "I don't know, please quit.")
echo -e "${GREEN}Okay bye.${NC}" echo -e "${GREEN}Okay bye."
exit 0 exit 0
;; ;;
*) echo "invalid option $REPLY";; *) echo "invalid option $REPLY";;
@ -46,7 +46,7 @@ do
done done
echo echo
echo -e "${GREEN}I want to check if required LAMP-Stack is installed. You need:${NC}" echo -e "${GREEN}I want to check if required LAMP-Stack is installed. You need:"
echo echo
APTS=() APTS=()
@ -58,7 +58,7 @@ else
APACHE='not installed' APACHE='not installed'
APTS+=( "apache2" "libapache2-mod-php" ) APTS+=( "apache2" "libapache2-mod-php" )
fi fi
echo -e "${GREEN}Apache2: ${APACHE}${NC}" echo -e "${GREEN}Apache2: ${APACHE}"
# Mariadb # Mariadb
if command -v mysql &> /dev/null if command -v mysql &> /dev/null
@ -68,7 +68,7 @@ else
MYSQL="not installed" MYSQL="not installed"
APTS+=( "mariadb-server" ) APTS+=( "mariadb-server" )
fi fi
echo -e "${GREEN}MariaDB/MySQL: ${MYSQL}${NC}" echo -e "${GREEN}MariaDB/MySQL: ${MYSQL}"
# PHP # PHP
if command -v php &> /dev/null if command -v php &> /dev/null
@ -85,20 +85,20 @@ else
PHP='not installed' PHP='not installed'
fi fi
echo -e "${GREEN}PHP: ${PHP}${NC}" echo -e "${GREEN}PHP: ${PHP}"
if [[ $OLDPHPVERSION ]] if [[ $OLDPHPVERSION ]]
then then
while true; do while true; do
echo echo
echo -e "${RED}Your php version is lower than 8.0, to you want to install php version 8.0 (this is optional)?${NC}" echo -e "${RED}Your php version is lower than 8.0, to you want to install php version 8.0 (this is optional)?"
echo -e "${YELLOW}Please note that if you confirm the app-repo \"ppa:ondrej/php\" will be added to your sources.${NC}" echo -e "${YELLOW}Please note that if you confirm the app-repo \"ppa:ondrej/php\" will be added to your sources.${NC}"
read -p "(y/n): " CURRENTPHPVERSION read -p "(y/n): " CURRENTPHPVERSION
case $CURRENTPHPVERSION in case $CURRENTPHPVERSION in
[Yy]* ) [Yy]* )
sudo a2dismod php${PHPVERSION}
PHPVERSION="8.0"; PHPVERSION="8.0";
APTS+=( "php8.0" ); APTS+=( "php8.0" );
sudo a2dismod php${PHPVERSION}
add-apt-repository ppa:ondrej/php -y; break;; add-apt-repository ppa:ondrej/php -y; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer y[es] or n[o].";; * ) echo "Please answer y[es] or n[o].";;
@ -110,8 +110,9 @@ if [[ ${PHP} == "not installed" ]]
then then
echo echo
echo -e "${YELLOW}Since php is missing on your system, would you like to install version 8.0?" echo -e "${YELLOW}Since php is missing on your system, would you like to install version 8.0?"
echo -e "${RED}The app-repo \"ppa:ondrej/php\" must be added to your sources." echo -e "${RED}The app-repo \"ppa:ondrej/php\" must be added to your sources for this."
echo -e "If you do not like to add an external repo, you can stay with php 7.4.${NC}" echo -e "If you do not like to add an external repo, you can stay with php 7.4.${NC}"
echo
PS3="I would like to use option... " PS3="I would like to use option... "
options=("8.0 from ppa:ondrej/php" "7.4 from default sources" "I don't know, please quit.") options=("8.0 from ppa:ondrej/php" "7.4 from default sources" "I don't know, please quit.")
select opt in "${options[@]}" select opt in "${options[@]}"
@ -120,18 +121,18 @@ then
"8.0 from ppa:ondrej/php") "8.0 from ppa:ondrej/php")
APTS+=( "php8.0" ) APTS+=( "php8.0" )
PHPVERSION="8.0" PHPVERSION="8.0"
echo -e "${GREEN}Add app-repo \"ppa:ondrej/php\" to your sources.${NC}" echo -e "${GREEN}Add app-repo \"ppa:ondrej/php\" to your sources."
add-apt-repository ppa:ondrej/php -y; add-apt-repository ppa:ondrej/php -y;
break break
;; ;;
"7.4 from default sources") "7.4 from default sources")
APTS+=( "php7.4" ) APTS+=( "php7.4" )
PHPVERSION="7.4" PHPVERSION="7.4"
echo -e "${GREEN}Will take php7.4 from default sources. ${NC}" echo -e "${GREEN}Will take php7.4 from default sources. "
break break
;; ;;
"I don't know, please quit.") "I don't know, please quit.")
echo -e "${GREEN}Okay bye.${NC}" echo -e "${GREEN}Okay bye."
exit 0 exit 0
;; ;;
*) echo "invalid option $REPLY";; *) echo "invalid option $REPLY";;
@ -147,33 +148,38 @@ then
read -p "(y/n): " INSTALLPACKAGES read -p "(y/n): " INSTALLPACKAGES
case $INSTALLPACKAGES in case $INSTALLPACKAGES in
[Yy]* ) apt update && apt install ${APTS[*]} -y; break;; [Yy]* ) apt update && apt install ${APTS[*]} -y; break;;
[Nn]* ) echo -e "${RED}I need ${APTS[*]} to process, abort${NC}"; exit;; [Nn]* ) echo -e "${RED}I need ${APTS[*]} to process, abort"; exit;;
* ) echo "Please answer y[es] or n[o].";; * ) echo "Please answer y[es] or n[o].";;
esac esac
done done
else else
echo -e "${GREEN}Good, your LAMP-Stack is complete.${NC}" echo -e "${GREEN}Good, your LAMP-Stack is complete."
fi fi
# check if dependencies are fulfilled # check if dependencies are fulfilled
echo echo
echo -e "${GREEN}Checking if dependencies are fulfilled...${NC}" echo -e "${GREEN}Checking if dependencies are fulfilled..."
echo echo
DEPENDENCIES=("libapache2-mod-php"\ DEPENDENCIES=("libapache2-mod-php"\
"php${PHPVERSION}-apcu"\
"php${PHPVERSION}-curl"\ "php${PHPVERSION}-curl"\
"php${PHPVERSION}-gd"\ "php${PHPVERSION}-gd"\
"php${PHPVERSION}-json"\
"php${PHPVERSION}-mbstring"\ "php${PHPVERSION}-mbstring"\
"php${PHPVERSION}-mysqli"\ "php${PHPVERSION}-mysql"\
"php${PHPVERSION}-xml"\ "php${PHPVERSION}-xml"
"php${PHPVERSION}-zip") "php${PHPVERSION}-zip")
if [[ ! $PHPVERSION == 8* ]]; then
DEPENDENCIES+=("php${PHPVERSION}-json")
fi
for REQUIREDPKG in "${DEPENDENCIES[@]}" for REQUIREDPKG in "${DEPENDENCIES[@]}"
do do
if dpkg-query -W --showformat='${Status}\n' $REQUIREDPKG &> /dev/null if [[ "$(dpkg-query -W --showformat='${Status}\n' $REQUIREDPKG)" == "install ok installed" ]]; then
then echo -e "${GREEN}${REQUIREDPKG} is installed."
echo -e "${GREEN}${REQUIREDPKG} is installed.${NC}"
delete=(${REQUIREDPKG}) delete=(${REQUIREDPKG})
for target in "${delete[@]}"; do for target in "${delete[@]}"; do
for i in "${!DEPENDENCIES[@]}"; do for i in "${!DEPENDENCIES[@]}"; do
@ -183,7 +189,7 @@ do
done done
done done
else else
echo -e "${RED}${REQUIREDPKG} is missing.${NC}" echo -e "${RED}${REQUIREDPKG} is missing."
fi fi
done done
@ -195,13 +201,13 @@ then
read -p "(y/n): " INSTALLDEPENDENCIES read -p "(y/n): " INSTALLDEPENDENCIES
case $INSTALLDEPENDENCIES in case $INSTALLDEPENDENCIES in
[Yy]* ) apt update && apt install ${DEPENDENCIES[*]} -y; break;; [Yy]* ) apt update && apt install ${DEPENDENCIES[*]} -y; break;;
[Nn]* ) echo -e "${RED}I need ${DEPENDENCIES[*]} to process, abort.${NC}"; exit;; [Nn]* ) echo -e "${RED}I need ${DEPENDENCIES[*]} to process, abort."; exit;;
* ) echo "Please answer y[es] or n[o].";; * ) echo "Please answer y[es] or n[o].";;
esac esac
done done
else else
echo echo
echo -e "${GREEN}Good, all dependencies are fulfilled.${NC}" echo -e "${GREEN}Good, all dependencies are fulfilled."
fi fi
unset REQUIREDPKG unset REQUIREDPKG
@ -214,11 +220,9 @@ HELPERS=(\
"unzip" \ "unzip" \
) )
for REQUIREDPKG in "${HELPERS[@]}" for REQUIREDPKG in "${HELPERS[@]}"; do
do if [[ "$(dpkg-query -W --showformat='${Status}\n' $REQUIREDPKG)" == "install ok installed" ]]; then
if dpkg-query -W --showformat='${Status}\n' $REQUIREDPKG &> /dev/null echo -e "${GREEN}${REQUIREDPKG} is installed."
then
echo -e "${GREEN}${REQUIREDPKG} is installed.${NC}"
delete=(${REQUIREDPKG}) delete=(${REQUIREDPKG})
for target in "${delete[@]}"; do for target in "${delete[@]}"; do
for i in "${!HELPERS[@]}"; do for i in "${!HELPERS[@]}"; do
@ -228,7 +232,7 @@ do
done done
done done
else else
echo -e "${RED}${REQUIREDPKG} is missing.${NC}" echo -e "${RED}${REQUIREDPKG} is missing."
fi fi
done done
@ -240,13 +244,13 @@ then
read -p "(y/n): " INSTALLHELPERS read -p "(y/n): " INSTALLHELPERS
case $INSTALLHELPERS in case $INSTALLHELPERS in
[Yy]* ) apt update && apt install ${HELPERS[*]} -y; break;; [Yy]* ) apt update && apt install ${HELPERS[*]} -y; break;;
[Nn]* ) echo -e "${RED}I need ${HELPERS[*]} to process, abort${NC}"; exit;; [Nn]* ) echo -e "${RED}I need ${HELPERS[*]} to process, abort"; exit;;
* ) echo "Please answer y[es] or n[o].";; * ) echo "Please answer y[es] or n[o].";;
esac esac
done done
else else
echo echo
echo -e "${GREEN}Good, all helpers are installed.${NC}" echo -e "${GREEN}Good, all helpers are installed."
fi fi
# add php configuration via wisski.ini # add php configuration via wisski.ini
@ -261,17 +265,26 @@ date.timezone = Europe/Berlin
max_input_nesting_level = 640' max_input_nesting_level = 640'
echo echo
echo -e "${YELLOW}Do you like to tweak your php?${NC}" echo -e "${YELLOW}Do you like to tweak your php?"
echo -e "${YELLOW}(This will add${NC}" echo -e "${YELLOW}This will add"
echo echo
echo -e "${RED}${TWEAKPHP}${NC}" echo -e "${RED}${TWEAKPHP}"
echo
echo -e "${YELLOW}to"
echo
echo -e "${RED}/etc/php/${PHPVERSION}/mods-available/wisski.ini$"
echo
echo -e "${YELLOW}and activate it.${NC}"
echo echo
echo -e "${YELLOW}to ${RED}/etc/php/${PHPVERSION}/apache2/conf.d/wisski.ini${YELLOW})${NC}"
while true; do while true; do
read -p "(y/n): " TWEAK read -p "(y/n): " TWEAK
case $TWEAK in case $TWEAK in
[Yy]* ) echo "$TWEAKPHP" > /etc/php/${PHPVERSION}/apache2/conf.d/wisski.ini; break;; [Yy]* )
echo "$TWEAKPHP" > /etc/php/${PHPVERSION}/mods-available/wisski.ini
echo -e "${GREEN}Activate wisski.ini.${NC}"
phpenmod -v ${PHPVERSION} wisski
break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -280,28 +293,27 @@ done
# enable mod-rewrite # enable mod-rewrite
echo echo
echo -e "${GREEN}Enable mod_rewrite for apache2.${NC}" echo -e "${GREEN}Enable mod_rewrite for apache2.${NC}"
sleep 1 echo
a2enmod rewrite; a2enmod rewrite;
# restart apache # restart apache
echo echo
echo -e "${GREEN}Restart apache server${NC}" echo -e "${GREEN}Restart apache server${NC}"
sleep 1
systemctl restart apache2 systemctl restart apache2
echo echo
# configure site
# configure site
FINISHED=false FINISHED=false
while [ $FINISHED == false ] while [ $FINISHED == false ]
do do
echo -e "${YELLOW}What is the name of your Website (WITHOUT \"https://www.\" etc. like \"example.com\")?${NC}" echo -e "${YELLOW}What is the name of your Website (WITHOUT \"https://www.\" etc. like \"example.com\")?"
echo -e "${YELLOW}It will be used as webroot dir at /var/www/html/ and as your servername.${NC}" echo -e "${YELLOW}It will be used as webroot dir at /var/www/html/ and as your servername.${NC}"
while [[ -z $WEBSITENAME ]] while [[ -z $WEBSITENAME ]]
do do
read WEBSITENAME read WEBSITENAME
if [[ -z $WEBSITENAME ]] if [[ -z $WEBSITENAME ]]
then then
echo -e "${RED}Websitename can not be emtpy! Please enter a websitename!${NC}" echo -e "${RED}Websitename can not be emtpy! Please enter a websitename!"
fi fi
done done
echo -e "${YELLOW}Enter your server admin email adress:${NC}" echo -e "${YELLOW}Enter your server admin email adress:${NC}"
@ -310,11 +322,11 @@ do
read SERVERADMINEMAIL read SERVERADMINEMAIL
if [[ -z $SERVERADMINEMAIL ]] if [[ -z $SERVERADMINEMAIL ]]
then then
echo -e "${RED}Server admin mail adress can not be emtpy! Please enter an amdin mail adress!${NC}" echo -e "${RED}Server admin mail adress can not be emtpy! Please enter an amdin mail adress!"
fi fi
done done
echo -e "${GREEN}Websitename: ${WEBSITENAME}${NC}" echo -e "${GREEN}Websitename: ${WEBSITENAME}"
echo -e "${GREEN}Server admin mail: ${SERVERADMINEMAIL}${NC}" echo -e "${GREEN}Server admin mail: ${SERVERADMINEMAIL}"
echo -e "${YELLOW}Is that correct?${NC}" echo -e "${YELLOW}Is that correct?${NC}"
while true; do while true; do
@ -326,7 +338,7 @@ do
FINISHED=true; FINISHED=true;
break;; break;;
[Nn]* ) [Nn]* )
echo -e "${GREEN}Okay then...${NC}"; echo -e "${GREEN}Okay then...";
break;; break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -338,29 +350,29 @@ done
if [[ $LOCALHOST ]] if [[ $LOCALHOST ]]
then then
echo echo
echo -e "${GREEN}Since, you are on localhost, I try to add \"127.0.0.1 ${WEBSITENAME}\" to /etc/hosts.${NC}" echo -e "${GREEN}Since, you are on localhost, I try to add \"127.0.0.1 ${WEBSITENAME}\" to /etc/hosts."
if grep -q "${WEBSITENAME}" "/etc/hosts"; if grep -q "${WEBSITENAME}" "/etc/hosts";
then then
echo echo
echo -e "${RED}Entry \"127.0.0.1 ${WEBSITENAME}\" already in /etc/hosts${NC}" echo -e "${RED}Entry \"127.0.0.1 ${WEBSITENAME}\" already in /etc/hosts"
else else
echo echo
echo -e "${YELLOW}ADD $WEBSITENAME to /etc/hosts, because you are on a localhost!${NC}" echo -e "${YELLOW}ADD $WEBSITENAME to /etc/hosts, because you are on a localhost!"
echo "127.0.0.1 ${WEBSITENAME}" >> /etc/hosts echo "127.0.0.1 ${WEBSITENAME}" >> /etc/hosts
fi fi
fi fi
echo echo
echo -e "${YELLOW}Do you like to add your site to your apache config?${NC}" echo -e "${YELLOW}Do you like to add your site to your apache config?"
echo -e "${YELLOW}This will create \"/etc/apache2/sites-available/${WEBSITENAME}.conf\".${NC}" echo -e "This will create \"/etc/apache2/sites-available/${WEBSITENAME}.conf\".${NC}"
SITECONFIG=$'<VirtualHost *:80> SITECONFIG=$'<VirtualHost *:80>
ServerAdmin ${SERVERADMINEMAIL} ServerAdmin ${SERVERADMINEMAIL}
DocumentRoot \"/var/www/html/${WEBSITENAME}/web\" DocumentRoot \"/var/www/html/${WEBSITENAME}/web\"
ServerName www.${WEBSITENAME} ServerName www.${WEBSITENAME}
ServerAlias ${WEBSITENAME} ServerAlias ${WEBSITENAME}
ErrorLog \"/var/log/apache2/drupal.local-error_log\" ErrorLog \"/var/log/apache2/${WEBSITENAME}-error_log\"
CustomLog \"/var/log/apache2/drupal.local-access_log\" common CustomLog \"/var/log/apache2/${WEBSITENAME}-access_log\" common
<Directory /var/www/html/$WEBSITENAME/web> <Directory /var/www/html/$WEBSITENAME/web>
Options FollowSymlinks Options FollowSymlinks
AllowOverride All AllowOverride All
@ -401,7 +413,7 @@ then
read -p "(y/n): " SECUREMARIADB read -p "(y/n): " SECUREMARIADB
case $SECUREMARIADB in case $SECUREMARIADB in
[Yy]* ) [Yy]* )
echo -e "${GREEN}Please note your credentials!${NC}"; echo -e "${GREEN}Please note your credentials!";
mysql_secure_installation; mysql_secure_installation;
break;; break;;
[Nn]* ) [Nn]* )
@ -411,10 +423,9 @@ then
done done
fi fi
echo "hello"
# create database user and database # create database user and database
echo echo
echo -e "${YELLOW}Create database and user for Drupal. Please note your inputs, they will be needed in a moment.${NC}" echo -e "${YELLOW}Create database and user for Drupal. Please note your inputs, they will be needed in a moment."
CORRECTDATABASE=false CORRECTDATABASE=false
CORRECTUSER=false CORRECTUSER=false
FINISHED=false FINISHED=false
@ -424,33 +435,33 @@ while [[ $CORRECTDATABASE == false ]] && [[ $CORRECTUSER == false ]]; do
read DB read DB
if [[ ! -z "`mysql -qfsBe "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='${DB}'" 2>&1`" ]]; then if [[ ! -z "`mysql -qfsBe "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='${DB}'" 2>&1`" ]]; then
echo echo
echo -e "${RED}Database already exists!${NC}" echo -e "${RED}Database already exists!"
echo -e "${RED}Should I drop it and recreate? Attention: All data will be lost and can not be recovered!${NC}" echo -e "Should I drop it and recreate? Attention: All data will be lost and can not be recovered!${NC}"
while true; do while true; do
read -p "(y/n/rename/abort): " SURE read -p "(recreate/keep/rename/abort): " SURE
case $SURE in case $SURE in
[Yy]* ) [recreate]* )
mysql -e "DROP DATABASE ${DB};" mysql -e "DROP DATABASE ${DB};"
mysql -e "CREATE DATABASE ${DB} ;" mysql -e "CREATE DATABASE ${DB} ;"
echo -e "${GREEN}Recreated database ${DB}.${NC}" echo -e "${GREEN}Recreated database ${DB}."
FINISHED=true FINISHED=true
break;; break;;
[Nn]* ) [keep]* )
echo -e "${GREEN}Okay keep old database...${NC}" echo -e "${GREEN}Okay keep old database..."
FINISHED=true FINISHED=true
break;; break;;
[retry]* ) [retry]* )
echo -e "${GREEN}Okay, then...${NC}" echo -e "${GREEN}Okay, then..."
break;; break;;
[abort]* ) [abort]* )
echo -e "${GREEN}Okay, bye${NC}" echo -e "${GREEN}Okay, bye"
exit;; exit;;
* ) echo "Please answer y[es], n[o], rename or abort!";; * ) echo "Please answer y[es], n[o], rename or abort!";;
esac esac
done done
else else
mysql -e "CREATE DATABASE ${DB} ;" mysql -e "CREATE DATABASE ${DB} ;"
echo -e "${GREEN}Created database ${DB}.${NC}" echo -e "${GREEN}Created database ${DB}."
FINISHED=true FINISHED=true
CORRECTDATABASE=true CORRECTDATABASE=true
fi fi
@ -463,8 +474,8 @@ while [[ $CORRECTDATABASE == false ]] && [[ $CORRECTUSER == false ]]; do
echo -e "${YELLOW}Enter passwort of that user:${NC}" echo -e "${YELLOW}Enter passwort of that user:${NC}"
read USERPW read USERPW
echo echo
echo -e "${GREEN}Database username: ${USER}${NC}" echo -e "${GREEN}Database username: ${USER}"
echo -e "${GREEN}Database user password: ${USERPW}${NC}" echo -e "Database user password: ${USERPW}"
echo -e "${YELLOW}Is that correct?${NC}" echo -e "${YELLOW}Is that correct?${NC}"
while true; do while true; do
read -p "(y/n): " SURE read -p "(y/n): " SURE
@ -473,22 +484,48 @@ while [[ $CORRECTDATABASE == false ]] && [[ $CORRECTUSER == false ]]; do
if [[ ! -z "`mysql -qfsBe "SELECT User FROM mysql.user WHERE User = '${USER}'" 2>&1`" ]]; if [[ ! -z "`mysql -qfsBe "SELECT User FROM mysql.user WHERE User = '${USER}'" 2>&1`" ]];
then then
echo echo
echo -e "${RED}User already exists!${NC}" echo -e "${RED}User already exists!"
echo -e "${RED}Should I drop it and recreate or keep existing user?${NC}" echo -e "Should I drop it and recreate or keep existing user?${NC}"
while true; do while true; do
read -p "(y/keep): " SURE read -p "(recreate/keep): " SURE
case $SURE in case $SURE in
[Yy]* ) [recreate]* )
mysql -e "DROP USER ${DB}@'localhost';" mysql -e "DROP USER ${DB}@'localhost';"
mysql -e "CREATE USER ${DB}@localhost IDENTIFIED BY '${USERPW}';" mysql -e "CREATE USER ${DB}@localhost IDENTIFIED BY '${USERPW}';"
mysql -e "GRANT ALL PRIVILEGES ON ${DB}.* TO '${USER}'@'localhost';" mysql -e "GRANT ALL PRIVILEGES ON ${DB}.* TO '${USER}'@'localhost';"
mysql -e "FLUSH PRIVILEGES;" mysql -e "FLUSH PRIVILEGES;"
echo -e "${GREEN}Recreated User ${USER}.${NC}" echo -e "${GREEN}Recreated User ${USER}."
FINISHED=true FINISHED=true
CORRECTUSER=true CORRECTUSER=true
break;; break;;
[keep]* ) [keep]* )
echo -e "${GREEN}Okay keep user.${NC}" unset USERPW
echo
echo -e "${GREEN}Okay keep existing user."
while [[ -z ${USERPW} ]]; do
echo -e "${YELLOW}What is the password of this user?"
echo -e "${RED}Be sure that the password is correct!${NC}"
read USERPW
while true; do
echo
echo -e "${GREEN}User password is: ${USERPW}"
echo -e "${YELLOW}Is this correct?${NC}"
read -p "(y/n): " SURE
case $SURE in
[Yy]* )
CORRECTUSER=true
break;;
[Nn]* )
unset USERPW
break;;
[abort]* )
echo -e "${GREEN}Okay, bye"
exit;;
* ) echo "Please answer y[es], n[o] or abort!";;
esac
done
done
FINISHED=true
break;; break;;
* ) echo "Please answer y[es] or keep.";; * ) echo "Please answer y[es] or keep.";;
esac esac
@ -498,27 +535,27 @@ while [[ $CORRECTDATABASE == false ]] && [[ $CORRECTUSER == false ]]; do
mysql -e "GRANT ALL PRIVILEGES ON ${DB}.* TO '${USER}'@'localhost';" mysql -e "GRANT ALL PRIVILEGES ON ${DB}.* TO '${USER}'@'localhost';"
mysql -e "FLUSH PRIVILEGES;" mysql -e "FLUSH PRIVILEGES;"
echo echo
echo -e "${GREEN}Created User ${USER}.${NC}" echo -e "${GREEN}Created User ${USER}."
FINISHED=true FINISHED=true
CORRECTUSER=true CORRECTUSER=true
fi fi
break;; break;;
[Nn]* ) [Nn]* )
echo -e "${GREEN}Okay then...${NC}" echo -e "${GREEN}Okay then..."
break;; break;;
* ) echo "Please answer y[es] or n[o].";; * ) echo -e "${RED}Please answer y[es] or n[o].";;
esac esac
done done
done done
done done
echo echo
echo -e "${GREEN}Created ${DB} database with ${USER} identified by ${USERPW} ${NC}" echo -e "${GREEN}Created ${DB} database with ${USER}@localhost identified by ${USERPW}."
sleep 1 sleep 1
# install drupal with drush # install drupal with drush
echo echo
echo -e "${GREEN}You are ready to install Drupal! It will be installed under /var/www/html/$WEBSITENAME.${NC}" echo -e "${GREEN}You are ready to install Drupal! It will be installed under /var/www/html/$WEBSITENAME."
echo -e "${YELLOW}Should I start?${NC}" echo -e "${YELLOW}Should I start?${NC}"
while true; do while true; do
read -p "(y/n): " INSTALLDRUPAL read -p "(y/n): " INSTALLDRUPAL
@ -543,9 +580,9 @@ then
echo -e "${RED}Seems that composer is not installed, do you like to install it?${NC}" echo -e "${RED}Seems that composer is not installed, do you like to install it?${NC}"
while true; do while true; do
read -p "(y/n): " INSTALLCOMPOSER read -p "(y/n): " INSTALLCOMPOSER
case INSTALLCOMPOSER in case ${INSTALLCOMPOSER} in
[Yy]* ) [Yy]* )
echo -e "${YELLOW}I will install composer at \"/usr/local/bin/composer\n${NC}" echo -e "${RED}I will install composer at \"/usr/local/bin/composer\"${NC}"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --filename=composer --install-dir=/usr/local/bin php composer-setup.php --filename=composer --install-dir=/usr/local/bin
@ -558,38 +595,106 @@ then
fi fi
echo echo
echo -e "${YELLOW}Composer will scold you for being root, do not worry, we take care of this later - answer always \"y\". " echo -e "${RED}Composer will scold you for being root, do not worry, we take care of this later - answer always \"y\".${NC}"
echo
composer create-project drupal/recommended-project $WEBSITENAME composer create-project drupal/recommended-project $WEBSITENAME
chown -R www-data:www-data $WEBSITENAME chown -R www-data:www-data $WEBSITENAME
chmod 775 -R $WEBSITENAME chmod 775 -R $WEBSITENAME
echo echo
echo -e "${GREEN}Installing WissKI with some modules (you have to activate them later).${NC}" echo -e "${GREEN}Installing WissKI with some modules (you have to activate them later).${NC}"
sleep 1 echo
cd /var/www/html/$WEBSITENAME cd /var/www/html/$WEBSITENAME
composer require drupal/colorbox drupal/devel drush/drush drupal/imagemagick drupal/inline_entity_form:^1.0@RC drupal/wisski:^3.0@RC composer require drupal/colorbox drupal/devel drush/drush drupal/imagemagick 'drupal/inline_entity_form:1.x-dev@dev' 'drupal/wisski:^3.0@RC'
cd web/modules/contrib/wisski cd web/modules/contrib/wisski
echo echo
echo -e "${GREEN}Autoload WissKI dependencies.${NC}" echo -e "${GREEN}Autoload WissKI dependencies.${NC}"
echo
composer update composer update
cd /var/www/html/$WEBSITENAME cd /var/www/html/$WEBSITENAME
## get mirador
echo echo
echo -e "${GREEN}Get necessary libraries.${NC}" echo -e "${GREEN}Get necessary libraries.${NC}"
sleep 1 echo
mkdir -p web/libraries mkdir -p web/libraries
## get colorbox
wget https://github.com/jackmoore/colorbox/archive/refs/heads/master.zip -P web/libraries/ wget https://github.com/jackmoore/colorbox/archive/refs/heads/master.zip -P web/libraries/
unzip web/libraries/master.zip -d web/libraries/ unzip web/libraries/master.zip -d web/libraries/
mv web/libraries/colorbox-master web/libraries/colorbox mv web/libraries/colorbox-master web/libraries/colorbox
#wget http://wisskieu.nasarek.org/sites/default/files/assets/mirador.zip -P web/libraries/ ## get mirador
#unzip web/libraries/mirador.zip -d web/libraries/
wget http://wisskieu.nasarek.org/sites/default/files/assets/mirador.zip -P web/libraries/
unzip web/libraries/mirador.zip -d web/libraries/
#echo change permissions for webroot to www-data #echo change permissions for webroot to www-data
echo
echo -e "${GREEN}Change permissions to www-data at \"/var/www/html/$WEBSITENAME\".${NC}"
echo
chown -R www-data:www-data ../$WEBSITENAME chown -R www-data:www-data ../$WEBSITENAME
chmod 775 -R ../$WEBSITENAME chmod 775 -R ../$WEBSITENAME
if [[ ! ${LOCALHOST} ]]; then
echo
echo -e "${YELLOW}You are installing WissKI for production, do you like to add https support?"
echo -e "You can use certbot and letsencrypt for an automaticaly installation and configuration"
echo -e "of all certificates and Apache config files or"
echo -e "use your own certificates and configure Apache manually.${NC}"
echo
PS3="I would like to... "
options=("use certbots automode." "configure Apache manually." "I don't know, please skip this.")
select opt in "${options[@]}"
do
case $opt in
"use certbots automode.")
echo -e "${GREEN}Okay, installing certbot which obtaining letsencrypt certificates!"
echo -e "Please note, that you need a correct DNS configuration with"
echo -e "${WEBSITENAME} or www.${WEBSITENAME} pointing with a \"A\" record to your ServerIP"
echo -e "${YELLOW}Can we start?${NC}"
while true; do
read -p "(y/n): " INSTALLCERTBOT
case $INSTALLCERTBOT in
[Yy]* )
apt remove certbot -y
snap install core
snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --apache
break;;
[Nn]* )
echo -e "${GREEN}Okay skipping.";
for (( i=0; i<${#options[@]}; i++)); do
printf '%d) %s\n' $((i+1)) "${options[$i]}"
done
continue 2;;
* ) echo "Please answer y[es] or n[o].";;
esac
done;
break
;;
"configure Apache manually.")
echo
echo -e "${GREEN}You can use \"example-ssl.conf\" as a template. Please alter <your email>,"
echo -e "<your website>, the paths to your certificate files and rewrite rules."
echo -e "Copy it to /etc/apache2/sites-available/${WEBSITENAME}-ssl.conf"
echo -e "and enable it with \"sudo a2ensite ${WEBSITENAME}-ssl\""
break
;;
"I don't know, please skip this.")
echo -e "${GREEN}Okay skipping.${NC}"
break
;;
*) echo "invalid option $REPLY";;
esac
done
fi
echo echo
echo -e "${GREEN}Thats it! You can now visit http://${WEBSITENAME} and install Drupal!${NC}" echo -e "${GREEN}Thats it! You can now visit http://${WEBSITENAME} and install Drupal!${NC}"
exit 0;