First commit of the BIJ1 WP installer

This commit is contained in:
Jelle Hermsen 2021-12-02 15:52:08 +01:00
commit 222382b68b
3 changed files with 118 additions and 0 deletions

13
README.md Normal file
View File

@ -0,0 +1,13 @@
BIJ1 Wordpress Installer
-------------------------
This script automates installing Wordpress with all specific BIJ1 plugins,
template and Advanced Custom Fields settings.
Steps:
- First you have to setup a database.
- Start the installer by running `./install.sh` in your web folder.
- Note down the bij1admin password that's generated during installation.
- Tweak the BIJ1 specific settings in wp-config.php.
If you use this primarily for testing you can run `./cleanup.sh` to remove the
Wordpress install (you'll have to wipe the db manually).

13
cleanup.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# Move working directory to path of this bash script
cd $(dirname "$0")
echo "Press 1 to delete this entire WP install:"
read input
if [ "$input" = "1" ]; then
find ./ -type f -not -name ".git" -not -name 'install.sh' -not -name 'cleanup.sh' -not -name '.' -not -name 'acf.zip' -not -name 'README.md' ! -path '*/.git/*' -delete
rm -rf wp-content/
rm -rf wp-includes/
else
echo "Stopped"
fi

92
install.sh Executable file
View File

@ -0,0 +1,92 @@
#!/bin/bash
# Helper function for easy sed usage
function sedeasy {
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
# Setup right DB settings
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 git@gitlab.com:bij1/site/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
echo -e "\n\n\n"
echo "Installing plugins"
./wp plugin install acf.zip --activate > /dev/null
./wp plugin install acf-options-for-polylang --activate > /dev/null
./wp plugin install admin-menu-editor --activate > /dev/null
./wp plugin install advanced-custom-fields-pro --activate > /dev/null
./wp plugin install ajax-load-more --activate > /dev/null
./wp plugin install gosign-gallery-box-block --activate > /dev/null
./wp plugin install polylang --activate > /dev/null
./wp plugin install simple-custom-post-order --activate > /dev/null
./wp plugin install wp-mail-smtp --activate > /dev/null
echo "Activate BIJ1 theme"
./wp theme activate BIJ1