bij1-wp-installer/install.sh

108 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# Helper function for easy sed usage
function sedeasy {
# Use sed -i '' for BSD systems
sed -i "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" $3
}
# Move working directory to path of this bash script
cd $(dirname "$0")
# Download wordpress to /tmp/ folder
echo "Download latest nl_NL wordpress"
curl -s https://nl.wordpress.org/latest-nl_NL.tar.gz > /tmp/wordpress-latest.tar.gz
# Extract Wordpress here
tar -xvzf /tmp/wordpress-latest.tar.gz wordpress
# Move wordpress files to current working root
mv wordpress/* .
rm -rf wordpress
# Install WP Cli
curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp
chmod +x wp
# Setup wp-config
mv wp-config-sample.php wp-config.php
echo 'Domain name:'
read domain_name
echo 'Site title:'
read site_title
echo 'Database name:'
read db_name
echo 'Database username:'
read db_user
echo 'Database password:'
read -s db_pass
echo 'Database host:'
read db_host
# Setup right DB settings
sedeasy localhost $db_host wp-config.php
sedeasy database_name_here $db_name wp-config.php
sedeasy username_here $db_user wp-config.php
sedeasy password_here $db_pass wp-config.php
# Setup Wordpress secret keys
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
STRING='put your unique phrase here'
printf '%s\n' "g/$STRING/d" a "$SALT" . w | ed -s wp-config.php
# Convert Windows line endings to *nix style
sed -i '' 's/\r//g' wp-config.php
export BIJ1_SETTINGS="
define( 'LOGO_BIG_PATH', '/wp-content/themes/BIJ1/img/afdelingen/arnhem-nijmegen-breed.svg' );
define( 'LOGO_SMALL_PATH', '/wp-content/themes/BIJ1/img/afdelingen/arnhem-nijmegen.svg' );
define( 'IS_MAIN_SITE', false);
"
# Add custom BIJ1 settings to wp-config in the "custom values" block
perl -0777 -pe 's/(.*custom values[^\n]*)/$1\n$ENV{BIJ1_SETTINGS}/s' wp-config.php > wp-config-new.php
rm wp-config.php
mv wp-config-new.php wp-config.php
# Setup template
git clone https://code.bij1.org/bij1/bij1-wp-theme.git tmp
rm -rf wp-content/themes/twenty*
mv tmp/src wp-content/themes/BIJ1
rm -rf tmp/
echo "Installing Wordpress, please note down the password"
./wp core install --url=$domain_name --title=$site_title --admin_name=bij1admin --admin_email=ict@bij1.org --allow-root
echo -e "\n\n\n"
echo "Installing plugins"
./wp plugin install acf.zip --activate --allow-root > /dev/null
./wp plugin install acf-options-for-polylang --activate --allow-root > /dev/null
./wp plugin install admin-menu-editor --activate --allow-root > /dev/null
./wp plugin install advanced-custom-fields-pro --activate --allow-root > /dev/null
./wp plugin install ajax-load-more --activate --allow-root > /dev/null
./wp plugin install gosign-gallery-box-block --activate --allow-root > /dev/null
./wp plugin install polylang --activate --allow-root > /dev/null
./wp plugin install simple-custom-post-order --activate --allow-root > /dev/null
./wp plugin install ics-calendar --activate --allow-root > /dev/null
./wp plugin install easy-wp-smtp --activate --allow-root
./wp plugin install opengraph --activate --allow-root
echo "Activate BIJ1 theme"
./wp theme activate BIJ1 --allow-root
echo "Create menus"
./wp menu create "Header menu" --allow-root
./wp menu create "Informatie" --allow-root
./wp menu create "Kom in actie" --allow-root
./wp menu create "Language" --allow-root
./wp menu create "Main" --allow-root
./wp menu create "Secondary" --allow-root