2019-07-25 12:11:09 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -u
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
# THis script is a basic wordpress setup. It does
|
|
|
|
# - download wordpress latest
|
|
|
|
# - download wp-cli.phar
|
|
|
|
# - install wordpress with plugins / themes
|
|
|
|
# - create a mysql database and user
|
|
|
|
# - create apache2 config ( nginx still needs implementation )
|
|
|
|
# - restarts apache2
|
|
|
|
#
|
|
|
|
# The Wordpress Site is then available at localhost/YOUR_SITENAME
|
|
|
|
# user: admin pw: admin ( change !! )
|
|
|
|
|
2019-12-13 21:07:39 +01:00
|
|
|
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "This script must be run as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-07-25 12:11:09 +02:00
|
|
|
if [[ $# -eq 0 ]] ; then
|
2019-12-13 21:05:21 +01:00
|
|
|
echo 'Site name required. Exiting ......'
|
2019-07-25 12:11:09 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
|
2019-07-25 12:11:09 +02:00
|
|
|
#
|
|
|
|
# Vars
|
2019-12-13 21:05:21 +01:00
|
|
|
# Edit according to your needs
|
2019-07-25 12:11:09 +02:00
|
|
|
#
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
# apache2 document root
|
|
|
|
document_root="/var/www/html/"
|
|
|
|
domain="localhost"
|
|
|
|
admin_email="mail@schubertdaniel.de"
|
|
|
|
site_name=$1
|
2019-07-25 12:11:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
plugins="login-lockdown cachify"
|
|
|
|
themes=""
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
|
|
|
|
db_new_host="localhost"
|
|
|
|
db_new_name="wp_$site_name"
|
|
|
|
db_new_user=$db_new_name
|
|
|
|
db_new_pw=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w8 | head -n1)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Functions
|
|
|
|
#
|
2019-07-25 12:11:09 +02:00
|
|
|
check_service() {
|
|
|
|
echo "Checking if $1 is running."
|
|
|
|
systemctl is-active --quiet $1
|
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "++ $1 is running. Good."
|
|
|
|
echo
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echo "-- $1 is not running."
|
|
|
|
echo
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function install_wp {
|
|
|
|
echo "Download wp-cli ....."
|
|
|
|
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
|
|
|
|
|
|
|
|
# bug when renaming wp-cli.phar on CentOs
|
|
|
|
# https://github.com/wp-cli/config-command/issues/31
|
2019-12-13 21:05:21 +01:00
|
|
|
|
|
|
|
# Are we on Debian?
|
2019-07-25 12:11:09 +02:00
|
|
|
if [ -f /etc/release ]; then
|
|
|
|
mv wp-cli.phar wp; chmod +x ./$cmd
|
|
|
|
cmd="./wp"
|
2019-12-13 21:05:21 +01:00
|
|
|
|
|
|
|
# Are we on RedHat / CentOS / Fedora?
|
2019-07-25 12:11:09 +02:00
|
|
|
elif [ -f /etc/redhat-release ]; then
|
|
|
|
chmod +x wp-cli.phar
|
|
|
|
cmd="./wp-cli.phar"
|
2019-12-13 21:05:21 +01:00
|
|
|
|
|
|
|
# dunno ....
|
2019-07-25 12:11:09 +02:00
|
|
|
else
|
|
|
|
chmod +x wp-cli.phar
|
|
|
|
cmd="./wp-cli.phar"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Installing Wordpress with \"$cmd\" "
|
|
|
|
$cmd core download --locale=de_DE --allow-root
|
|
|
|
$cmd config create --dbname=$db_new_name --dbuser=$db_new_user --dbhost=$db_new_host --dbpass=$db_new_pw --skip-check --allow-root
|
|
|
|
|
|
|
|
$cmd core install --url=$domain/$1 --title=$1 --admin_user=admin --admin_password=admin --admin_email=$admin_email --skip-email --allow-root
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
if [ -n "${plugins+x}" ]; then
|
2019-07-25 12:11:09 +02:00
|
|
|
echo "installing Plugins $plugins"
|
|
|
|
$cmd plugin install $plugins --allow-root
|
|
|
|
fi
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
if [ -n "${theme+x}" ]; then
|
2019-07-25 12:11:09 +02:00
|
|
|
echo "installing Theme: $theme"
|
|
|
|
$cmd theme install $theme --allow-root
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
configure_nginx() {
|
2019-12-13 21:05:21 +01:00
|
|
|
# TODO : not implemented yet
|
2019-07-25 12:11:09 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
configure_apache2() {
|
2019-12-13 21:05:21 +01:00
|
|
|
chown -R www-data. $document_root$site_name
|
|
|
|
|
|
|
|
cat > /etc/apache2/sites-available/$site_name.conf << EOL
|
2019-07-25 12:11:09 +02:00
|
|
|
<VirtualHost *:80>
|
2019-12-13 21:05:21 +01:00
|
|
|
DocumentRoot $document_root
|
|
|
|
ServerName localhost
|
|
|
|
Alias /$site_name $document_root$site_name
|
2019-07-25 12:11:09 +02:00
|
|
|
DirectoryIndex index.php index.html
|
2019-12-13 21:05:21 +01:00
|
|
|
<Directory $document_root$site_name/>
|
|
|
|
AllowOverride All
|
|
|
|
Require all granted
|
2019-07-25 12:11:09 +02:00
|
|
|
Options -Indexes
|
|
|
|
</Directory>
|
|
|
|
</VirtualHost>
|
|
|
|
EOL
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
a2ensite $site_name.conf
|
2019-07-25 12:11:09 +02:00
|
|
|
systemctl reload apache2
|
2019-12-13 21:05:21 +01:00
|
|
|
}
|
2019-07-25 12:11:09 +02:00
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
setup_db(){
|
|
|
|
echo "Creating new database $db_new_name"
|
|
|
|
mysqladmin create $db_new_name
|
|
|
|
|
|
|
|
mysql -e "CREATE USER '$db_new_user'@'localhost' IDENTIFIED BY '$db_new_pw';"
|
|
|
|
mysql -e "GRANT ALL PRIVILEGES ON $db_new_name . * TO '$db_new_user'@'localhost';"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
run(){
|
|
|
|
mkdir $document_root$1
|
|
|
|
cd $document_root$1
|
|
|
|
|
|
|
|
echo "We have $2 running; Configuring it "
|
|
|
|
|
|
|
|
setup_db
|
|
|
|
install_wp $1
|
|
|
|
configure_$2
|
|
|
|
|
|
|
|
echo "Finished. Exitinig now."
|
|
|
|
exit
|
2019-07-25 12:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
############################################
|
|
|
|
# script starts here:
|
|
|
|
#############################################
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
|
|
|
|
# Check for running database
|
2019-07-25 12:11:09 +02:00
|
|
|
check_service mysql
|
|
|
|
ret_mysql=$?
|
|
|
|
|
|
|
|
check_service mariadb
|
|
|
|
ret_maria=$?
|
|
|
|
|
|
|
|
n=$(($ret_maria + $ret_mysql))
|
|
|
|
if [ n == 2 ]; then
|
2019-12-13 21:05:21 +01:00
|
|
|
echo "No MySQL or MariaDB running. Exiting .."
|
2019-07-25 12:11:09 +02:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2019-12-13 21:05:21 +01:00
|
|
|
# check for running webserver
|
2019-07-25 12:11:09 +02:00
|
|
|
check_service nginx
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
run $1 nginx
|
|
|
|
fi
|
|
|
|
|
|
|
|
check_service apache2
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
run $1 apache2
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Neither nginx nor apache2 found running."
|
2019-12-13 21:05:21 +01:00
|
|
|
echo "Continuing anyway, but you will have to configure your webserver manually to make this work."
|
2019-07-25 12:11:09 +02:00
|
|
|
exit
|