Add new file
This commit is contained in:
		
							
								
								
									
										182
									
								
								wp-setup.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										182
									
								
								wp-setup.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,182 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
set -u
 | 
			
		||||
 | 
			
		||||
if [[ $# -eq 0 ]] ; then
 | 
			
		||||
    echo 'Site name required'
 | 
			
		||||
    exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Vars
 | 
			
		||||
#
 | 
			
		||||
domain="localhost"
 | 
			
		||||
admin_email="put-email-adress-here"
 | 
			
		||||
 | 
			
		||||
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=""
 | 
			
		||||
 | 
			
		||||
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 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 ....."
 | 
			
		||||
  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
 | 
			
		||||
  if [ -f /etc/release ]; then
 | 
			
		||||
    # Are we on Debian?
 | 
			
		||||
    mv wp-cli.phar wp; chmod +x ./$cmd
 | 
			
		||||
    cmd="./wp"
 | 
			
		||||
  elif [ -f /etc/redhat-release ]; then
 | 
			
		||||
    # Are we on RedHat / CentOS / Fedora?
 | 
			
		||||
    chmod +x wp-cli.phar
 | 
			
		||||
    cmd="./wp-cli.phar"
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
  if [ -n "$plugins" ]; then 
 | 
			
		||||
    echo "installing Plugins $plugins"
 | 
			
		||||
    $cmd plugin install $plugins --allow-root
 | 
			
		||||
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  if [ -n "$theme" ]; then 
 | 
			
		||||
    echo "installing Theme:  $theme"
 | 
			
		||||
    $cmd theme install $theme --allow-root
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
configure_nginx() {
 | 
			
		||||
  return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
configure_apache2() {
 | 
			
		||||
cat > /etc/apache2/sites-available/$1.conf << EOL 
 | 
			
		||||
<VirtualHost *:80>
 | 
			
		||||
  ServerName $1.$domain
 | 
			
		||||
  DocumentRoot /home/dany/local-dev/$1
 | 
			
		||||
  DirectoryIndex index.php index.html
 | 
			
		||||
  <Directory /home/dany/local-dev/$1/>
 | 
			
		||||
      AllowOverride None
 | 
			
		||||
      Order allow,deny
 | 
			
		||||
      Allow from all
 | 
			
		||||
      Options -Indexes
 | 
			
		||||
  </Directory>
 | 
			
		||||
</VirtualHost>
 | 
			
		||||
EOL
 | 
			
		||||
 | 
			
		||||
  systemctl a2ensite $1
 | 
			
		||||
  systemctl reload apache2
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
############################################
 | 
			
		||||
# script starts here:
 | 
			
		||||
#############################################
 | 
			
		||||
 | 
			
		||||
check_service mysql
 | 
			
		||||
ret_mysql=$?
 | 
			
		||||
 | 
			
		||||
check_service mariadb 
 | 
			
		||||
ret_maria=$?
 | 
			
		||||
 | 
			
		||||
n=$(($ret_maria + $ret_mysql))
 | 
			
		||||
if [ n == 2 ]; then
 | 
			
		||||
  echo "No SQL Database 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_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."
 | 
			
		||||
echo "you will have to configure your webserver manually"
 | 
			
		||||
echo
 | 
			
		||||
exit
 | 
			
		||||
		Reference in New Issue
	
	Block a user