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
|
||||
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
|
||||
echo 'Site name required'
|
||||
echo 'Site name required. Exiting ......'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Vars
|
||||
# Edit according to your needs
|
||||
#
|
||||
|
||||
# apache2 document root
|
||||
document_root="/var/www/html/"
|
||||
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"
|
||||
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() {
|
||||
echo "Checking if $1 is running."
|
||||
systemctl is-active --quiet $1
|
||||
@ -44,29 +57,6 @@ check_service() {
|
||||
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 {
|
||||
echo "Download wp-cli ....."
|
||||
@ -74,14 +64,18 @@ function install_wp {
|
||||
|
||||
# bug when renaming wp-cli.phar on CentOs
|
||||
# https://github.com/wp-cli/config-command/issues/31
|
||||
if [ -f /etc/release ]; then
|
||||
|
||||
# Are we on Debian?
|
||||
if [ -f /etc/release ]; then
|
||||
mv wp-cli.phar wp; chmod +x ./$cmd
|
||||
cmd="./wp"
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
|
||||
# Are we on RedHat / CentOS / Fedora?
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
chmod +x wp-cli.phar
|
||||
cmd="./wp-cli.phar"
|
||||
|
||||
# dunno ....
|
||||
else
|
||||
chmod +x 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
|
||||
|
||||
if [ -n "$plugins" ]; then
|
||||
if [ -n "${plugins+x}" ]; then
|
||||
echo "installing Plugins $plugins"
|
||||
$cmd plugin install $plugins --allow-root
|
||||
|
||||
fi
|
||||
|
||||
if [ -n "$theme" ]; then
|
||||
if [ -n "${theme+x}" ]; then
|
||||
echo "installing Theme: $theme"
|
||||
$cmd theme install $theme --allow-root
|
||||
fi
|
||||
}
|
||||
|
||||
configure_nginx() {
|
||||
# TODO : not implemented yet
|
||||
return 0
|
||||
}
|
||||
|
||||
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>
|
||||
ServerName $1.$domain
|
||||
DocumentRoot /home/dany/local-dev/$1
|
||||
DocumentRoot $document_root
|
||||
ServerName localhost
|
||||
Alias /$site_name $document_root$site_name
|
||||
DirectoryIndex index.php index.html
|
||||
<Directory /home/dany/local-dev/$1/>
|
||||
AllowOverride None
|
||||
Order allow,deny
|
||||
Allow from all
|
||||
<Directory $document_root$site_name/>
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
Options -Indexes
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
EOL
|
||||
|
||||
systemctl a2ensite $1
|
||||
a2ensite $site_name.conf
|
||||
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:
|
||||
#############################################
|
||||
|
||||
|
||||
# Check for running database
|
||||
check_service mysql
|
||||
ret_mysql=$?
|
||||
|
||||
@ -141,31 +161,11 @@ ret_maria=$?
|
||||
|
||||
n=$(($ret_maria + $ret_mysql))
|
||||
if [ n == 2 ]; then
|
||||
echo "No SQL Database running. Exiting .."
|
||||
echo "No MySQL or MariaDB running. Exiting .."
|
||||
exit
|
||||
fi
|
||||
|
||||
setup_db(){
|
||||
# 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 for running webserver
|
||||
check_service nginx
|
||||
if [ $? -eq 0 ]; then
|
||||
run $1 nginx
|
||||
@ -177,6 +177,5 @@ if [ $? -eq 0 ]; then
|
||||
fi
|
||||
|
||||
echo "Neither nginx nor apache2 found running."
|
||||
echo "you will have to configure your webserver manually"
|
||||
echo
|
||||
echo "Continuing anyway, but you will have to configure your webserver manually to make this work."
|
||||
exit
|
||||
|
Loading…
Reference in New Issue
Block a user