#!/bin/bash
# Installeert Wordpress met wp-cli

# vraag om username als niet op commandline
if test "$1" = ""; then
  read -p "Linux username: " user
else
  user=$1
  echo "Linux username: $user"
fi
if test "$user" = ""; then
  echo geen username.
  exit
fi

# Database paswoord ophalen
dbpw=`cat /tmp/$user`
# Domeinnaam ophalen
domain=`cat /tmp/$user-domain`

# vraag om database password als niet gegeven
read -p "Database naam: " -ei "$user" db
read -p "Database username: " -ei "$user" dbuser
read -p "Database password: " -ei "$dbpw" dbpw
read -p "URL: " -ei "https://$domain" url
read -p "Titel site: " -ei "Brand new site" title
read -p "Admin name: " -ei "$user" admin
read -p "Admin password: " -ei `pwgen -sy 12` pw
read -p "Admin e-mail: " -ei "paul@vandervlis.nl" email
read -p "Path: " -ei "/home/$user/www/" path
read -p "Locale: " -ei "nl_NL" locale

if ! test -e "$path"; then echo "Path bestaat niet, ik stop"; exit; fi
if test -e "$path/index.html"; then rm "$path/index.html"; fi

wp core download --allow-root --path="$path" --locale="$locale"
wp config create --allow-root --dbname="$db" --dbuser="$dbuser" --dbpass="$dbpw" --path="$path"
wp core install --allow-root --url="$url" --title="$title" --admin_user="$admin" \
   --admin_email="$email" --admin_password="$pw" --path="$path"
#wp cli cache clear

chown -R $user:$user $path

echo "Done."
echo

