wordpress-tools/update.sh

109 lines
3.7 KiB
Bash
Raw Permalink Normal View History

2021-04-14 12:23:00 -07:00
#!/bin/bash
# update repo
git pull
2021-04-15 12:50:06 -07:00
# update wp-cli
if [ -f /usr/local/bin/wp ]; then
/usr/local/bin/wp cli update --yes --quiet --allow-root
else
# wp-cli not found, download & install
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
chmod +x /usr/local/bin/wp
2022-01-04 17:06:45 -08:00
fi
2021-04-15 12:50:06 -07:00
2021-04-14 12:23:00 -07:00
# update scripts in bin
chmod 755 local/bin/*
readarray -t bin_script_array < <(ls -1 local/bin/)
2021-04-14 12:23:00 -07:00
for bin_script in "${bin_script_array[@]}"; do
if [ -f /usr/local/bin/$bin_script ]; then
if ! diff -q local/bin/$bin_script /usr/local/bin/$bin_script ; then
2021-04-14 12:23:00 -07:00
echo "Updating /usr/local/bin/$bin_script"
cp local/bin/$bin_script /usr/local/bin/$bin_script
2021-04-14 12:23:00 -07:00
echo
fi
else
echo "Adding new script /usr/local/bin/$bin_script"
cp local/bin/$bin_script /usr/local/bin/$bin_script
2021-04-14 12:23:00 -07:00
echo
fi
done
2021-04-15 12:50:06 -07:00
# check wp-cron.sh for update
if ! diff -q local/sbin/wp-cron.sh /usr/local/sbin/wp-cron.sh ; then
cp local/sbin/wp-cron.sh /usr/local/sbin/wp-cron.sh
2022-01-04 17:30:57 -08:00
chmod 755 /usr/local/sbin/wp-cron.sh
2022-11-16 14:08:21 -08:00
echo "wp-cron.sh updated"
2021-04-15 12:50:06 -07:00
echo
fi
# check systemd timer for update
if ! diff -q local/systemd/wp-cron.service /usr/local/lib/systemd/system/wp-cron.service ; then
cp local/systemd/wp-cron.service /usr/local/lib/systemd/system/wp-cron.service
chmod 644 /usr/local/lib/systemd/system/wp-cron.service
2022-11-16 14:08:21 -08:00
echo "wp-cron.service updated"
2021-04-15 12:50:06 -07:00
echo
fi
if ! diff -q local/systemd/wp-cron.timer /usr/local/lib/systemd/system/wp-cron.timer ; then
cp local/systemd/wp-cron.timer /usr/local/lib/systemd/system/wp-cron.timer
chmod 644 /usr/local/lib/systemd/system/wp-cron.timer
2022-11-16 14:08:21 -08:00
echo "wp-cron.timer updated"
2021-04-14 12:23:00 -07:00
echo
fi
2022-11-16 14:25:10 -08:00
# check apache wp-security config for update
if ! diff -q etc/apache2/conf-available/wp-security.conf /etc/apache2/conf-available/wp-security.conf ; then
cp etc/apache2/conf-available/wp-security.conf /etc/apache2/conf-available/wp-security.conf
chmod 644 /etc/apache2/conf-available/wp-security.conf
systemctl restart apache2
echo "wp-security updated"
echo
fi
# check bash completion config for update
if ! diff -q etc/bash_completion.d/wp-cli /etc/bash_completion.d/wp-cli ; then
cp etc/bash_completion.d/wp-cli /etc/bash_completion.d/wp-cli
chmod 644 /etc/bash_completion.d/wp-cli
echo "bash completion config updated"
echo
fi
2022-11-16 14:25:10 -08:00
# check fail2ban wordpress configs
if [[ -d /etc/fail2ban/ ]]; then
RESTARTF2B=false
if ! diff -q etc/fail2ban/filter.d/wp-auth.conf /etc/fail2ban/filter.d/wp-auth.conf ; then
cp etc/fail2ban/filter.d/wp-auth.conf /etc/fail2ban/filter.d/wp-auth.conf
2022-11-16 14:25:10 -08:00
chmod 644 /etc/fail2ban/filter.d/wp-auth.conf
echo "fail2ban/filter.d/wp-auth.conf updated"
echo
RESTARTF2B=true
fi
if ! diff -q etc/fail2ban/filter.d/xmlrpc.conf /etc/fail2ban/filter.d/xmlrpc.conf ; then
cp etc/fail2ban/filter.d/xmlrpc.conf /etc/fail2ban/filter.d/xmlrpc.conf
2022-11-16 14:25:10 -08:00
chmod 644 /etc/fail2ban/filter.d/xmlrpc.conf
echo "fail2ban/filter.d/xmlrpc.conf updated"
echo
RESTARTF2B=true
fi
if ! diff -q etc/fail2ban/jail.d/wp-auth.conf /etc/fail2ban/jail.d/wp-auth.conf ; then
cp etc/fail2ban/jail.d/wp-auth.conf /etc/fail2ban/jail.d/wp-auth.conf
2022-11-16 14:25:10 -08:00
chmod 644 /etc/fail2ban/jail.d/wp-auth.conf
echo "fail2ban/jail.d/wp-auth.conf updated"
echo
RESTARTF2B=true
fi
if ! diff -q etc/fail2ban/jail.d/xmlrpc.conf /etc/fail2ban/jail.d/xmlrpc.conf ; then
cp etc/fail2ban/jail.d/xmlrpc.conf /etc/fail2ban/jail.d/xmlrpc.conf
2022-11-16 14:25:10 -08:00
chmod 644 /etc/fail2ban/jail.d/xmlrpc.conf
echo "fail2ban/jail.d/xmlrpc.conf updated"
echo
RESTARTF2B=true
fi
if [[ $RESTARTF2B = true ]]; then
systemctl restart fail2ban
fi
else
echo "Fail2ban not installed, skipping fail2ban wordpress configs."
fi