Update wp-setup.sh
This commit is contained in:
parent
ba196d22e6
commit
c618e9c5aa
149
wp-setup.sh
149
wp-setup.sh
@ -1,34 +1,47 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
|
# 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 !! )
|
||||||
|
|
||||||
if [[ $# -eq 0 ]] ; then
|
if [[ $# -eq 0 ]] ; then
|
||||||
echo 'Site name required'
|
echo 'Site name required. Exiting ......'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Vars
|
# Vars
|
||||||
|
# Edit according to your needs
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# apache2 document root
|
||||||
|
document_root="/var/www/html/"
|
||||||
domain="localhost"
|
domain="localhost"
|
||||||
admin_email="put-email-adress-here"
|
admin_email="mail@schubertdaniel.de"
|
||||||
|
site_name=$1
|
||||||
|
|
||||||
db_file="db.sql"
|
|
||||||
|
|
||||||
# source DB
|
|
||||||
db_host="hostname.example"
|
|
||||||
db_user="username"
|
|
||||||
db_pass="SeCrEt"
|
|
||||||
db_name="DB-NAME"
|
|
||||||
|
|
||||||
# New DB
|
|
||||||
db_new_name="wordpress"
|
|
||||||
db_new_host="localhost"
|
|
||||||
db_new_user="wordpress"
|
|
||||||
db_new_pw="wordpress"
|
|
||||||
|
|
||||||
plugins="login-lockdown cachify"
|
plugins="login-lockdown cachify"
|
||||||
themes=""
|
themes=""
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
#
|
||||||
check_service() {
|
check_service() {
|
||||||
echo "Checking if $1 is running."
|
echo "Checking if $1 is running."
|
||||||
systemctl is-active --quiet $1
|
systemctl is-active --quiet $1
|
||||||
@ -44,29 +57,6 @@ check_service() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function dump_db {
|
|
||||||
mysqldump --opt --add-drop-table -h$db_host -u$db_user -p$db_pass $db_name > $db_file
|
|
||||||
}
|
|
||||||
|
|
||||||
function change_url_in_db {
|
|
||||||
echo "Changing URL in DB......"
|
|
||||||
cat $db_file | sed "s+www.amv-verlag.de+$1.$domain+g" > db_file_edited.sql
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_db {
|
|
||||||
echo "Creating new database $db_new_name"
|
|
||||||
mysqladmin create $db_new_name
|
|
||||||
}
|
|
||||||
|
|
||||||
function copy_db {
|
|
||||||
if [ -f 'db_file_edited.sql' ]; then
|
|
||||||
echo "Copying databasefile db_file_edited.sql into Database..."
|
|
||||||
mysql -D $db_new_name < db_file_edited.sql
|
|
||||||
else
|
|
||||||
echo "Copying databasefile $db_file into Database..."
|
|
||||||
mysql -D $db_new_name < $db_file
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function install_wp {
|
function install_wp {
|
||||||
echo "Download wp-cli ....."
|
echo "Download wp-cli ....."
|
||||||
@ -74,14 +64,18 @@ function install_wp {
|
|||||||
|
|
||||||
# bug when renaming wp-cli.phar on CentOs
|
# bug when renaming wp-cli.phar on CentOs
|
||||||
# https://github.com/wp-cli/config-command/issues/31
|
# https://github.com/wp-cli/config-command/issues/31
|
||||||
|
|
||||||
|
# Are we on Debian?
|
||||||
if [ -f /etc/release ]; then
|
if [ -f /etc/release ]; then
|
||||||
# Are we on Debian?
|
|
||||||
mv wp-cli.phar wp; chmod +x ./$cmd
|
mv wp-cli.phar wp; chmod +x ./$cmd
|
||||||
cmd="./wp"
|
cmd="./wp"
|
||||||
|
|
||||||
|
# Are we on RedHat / CentOS / Fedora?
|
||||||
elif [ -f /etc/redhat-release ]; then
|
elif [ -f /etc/redhat-release ]; then
|
||||||
# Are we on RedHat / CentOS / Fedora?
|
|
||||||
chmod +x wp-cli.phar
|
chmod +x wp-cli.phar
|
||||||
cmd="./wp-cli.phar"
|
cmd="./wp-cli.phar"
|
||||||
|
|
||||||
|
# dunno ....
|
||||||
else
|
else
|
||||||
chmod +x wp-cli.phar
|
chmod +x wp-cli.phar
|
||||||
cmd="./wp-cli.phar"
|
cmd="./wp-cli.phar"
|
||||||
@ -93,46 +87,72 @@ function install_wp {
|
|||||||
|
|
||||||
$cmd core install --url=$domain/$1 --title=$1 --admin_user=admin --admin_password=admin --admin_email=$admin_email --skip-email --allow-root
|
$cmd core install --url=$domain/$1 --title=$1 --admin_user=admin --admin_password=admin --admin_email=$admin_email --skip-email --allow-root
|
||||||
|
|
||||||
if [ -n "$plugins" ]; then
|
if [ -n "${plugins+x}" ]; then
|
||||||
echo "installing Plugins $plugins"
|
echo "installing Plugins $plugins"
|
||||||
$cmd plugin install $plugins --allow-root
|
$cmd plugin install $plugins --allow-root
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$theme" ]; then
|
if [ -n "${theme+x}" ]; then
|
||||||
echo "installing Theme: $theme"
|
echo "installing Theme: $theme"
|
||||||
$cmd theme install $theme --allow-root
|
$cmd theme install $theme --allow-root
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_nginx() {
|
configure_nginx() {
|
||||||
|
# TODO : not implemented yet
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_apache2() {
|
configure_apache2() {
|
||||||
cat > /etc/apache2/sites-available/$1.conf << EOL
|
chown -R www-data. $document_root$site_name
|
||||||
|
|
||||||
|
cat > /etc/apache2/sites-available/$site_name.conf << EOL
|
||||||
<VirtualHost *:80>
|
<VirtualHost *:80>
|
||||||
ServerName $1.$domain
|
DocumentRoot $document_root
|
||||||
DocumentRoot /home/dany/local-dev/$1
|
ServerName localhost
|
||||||
|
Alias /$site_name $document_root$site_name
|
||||||
DirectoryIndex index.php index.html
|
DirectoryIndex index.php index.html
|
||||||
<Directory /home/dany/local-dev/$1/>
|
<Directory $document_root$site_name/>
|
||||||
AllowOverride None
|
AllowOverride All
|
||||||
Order allow,deny
|
Require all granted
|
||||||
Allow from all
|
|
||||||
Options -Indexes
|
Options -Indexes
|
||||||
</Directory>
|
</Directory>
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
systemctl a2ensite $1
|
a2ensite $site_name.conf
|
||||||
systemctl reload apache2
|
systemctl reload apache2
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# script starts here:
|
# script starts here:
|
||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
|
|
||||||
|
# Check for running database
|
||||||
check_service mysql
|
check_service mysql
|
||||||
ret_mysql=$?
|
ret_mysql=$?
|
||||||
|
|
||||||
@ -141,31 +161,11 @@ ret_maria=$?
|
|||||||
|
|
||||||
n=$(($ret_maria + $ret_mysql))
|
n=$(($ret_maria + $ret_mysql))
|
||||||
if [ n == 2 ]; then
|
if [ n == 2 ]; then
|
||||||
echo "No SQL Database running. Exiting .."
|
echo "No MySQL or MariaDB running. Exiting .."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setup_db(){
|
# check for running webserver
|
||||||
# TODO: nutzer anlegen
|
|
||||||
change_url_in_db $1; create_db; copy_db
|
|
||||||
}
|
|
||||||
|
|
||||||
run(){
|
|
||||||
mkdir /home/dany/local-dev/$1
|
|
||||||
cd /home/dany/local-dev/$1
|
|
||||||
|
|
||||||
echo "We have $2 running; Configuring it "
|
|
||||||
|
|
||||||
#setup_db
|
|
||||||
install_wp $1
|
|
||||||
chown -R $2. /home/dany/local-dev/$1
|
|
||||||
configure_$2
|
|
||||||
|
|
||||||
echo "Finished. Exitinig now."
|
|
||||||
exit
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
check_service nginx
|
check_service nginx
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
run $1 nginx
|
run $1 nginx
|
||||||
@ -177,6 +177,5 @@ if [ $? -eq 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Neither nginx nor apache2 found running."
|
echo "Neither nginx nor apache2 found running."
|
||||||
echo "you will have to configure your webserver manually"
|
echo "Continuing anyway, but you will have to configure your webserver manually to make this work."
|
||||||
echo
|
|
||||||
exit
|
exit
|
||||||
|
Loading…
Reference in New Issue
Block a user