2019-03-31 17:14:17 +02:00
#!/usr/bin/env bash
2019-02-25 12:27:23 +01:00
# -------------------------------------------------------------------------
# WordOps install and update script
# -------------------------------------------------------------------------
2019-03-29 12:17:17 +01:00
# Website: https://wordops.net
2019-02-25 12:27:23 +01:00
# GitHub: https://github.com/WordOps/WordOps
# Copyright (c) 2019 - WordOps
# This script is licensed under M.I.T
# -------------------------------------------------------------------------
2019-08-17 14:01:16 +02:00
# wget -qO wo wops.cc && sudo bash wo
# -------------------------------------------------------------------------
2019-10-11 13:01:00 +02:00
# Version 3.9.9.3 - 2019-10-11
2019-02-25 12:27:23 +01:00
# -------------------------------------------------------------------------
2019-08-17 14:05:40 +02:00
2019-02-25 12:27:23 +01:00
# CONTENTS
# ---
# 1. VARIABLES AND DECLARATIONS
# 2. PREPARE FOR INSTALLATION
# 3. INSTALLATION
# 4.
2018-11-30 17:04:15 +01:00
###
# 1 - Set the CLI output colors
###
2018-11-13 21:55:59 +01:00
2019-03-05 13:19:47 +01:00
TPUT_RESET=$(tput sgr0)
TPUT_FAIL=$(tput setaf 1)
2019-03-07 18:02:46 +01:00
TPUT_INFO=$(tput setaf 7)
TPUT_ECHO=$(tput setaf 4)
2019-03-05 13:19:47 +01:00
2019-03-22 23:55:04 +01:00
wo_lib_echo() {
2019-03-20 21:59:56 +01:00
echo "${TPUT_ECHO}${*}${TPUT_RESET}"
2019-03-05 13:19:47 +01:00
}
2019-03-22 23:55:04 +01:00
wo_lib_echo_info() {
2019-03-20 21:59:56 +01:00
2019-03-05 13:19:47 +01:00
echo "${TPUT_INFO}${*}${TPUT_RESET}"
2018-11-13 21:55:59 +01:00
}
2018-11-30 17:04:15 +01:00
2019-03-22 23:55:04 +01:00
wo_lib_echo_fail() {
2019-03-20 21:59:56 +01:00
2019-03-05 13:19:47 +01:00
echo "${TPUT_FAIL}${*}${TPUT_RESET}"
2018-11-13 21:55:59 +01:00
}
2018-11-30 17:04:15 +01:00
2019-03-05 13:19:47 +01:00
###
# 1 - Capture errors
###
2019-03-22 23:55:04 +01:00
wo_lib_error() {
2019-03-05 13:19:47 +01:00
echo "[ $(date) ] ${TPUT_FAIL}${*}${TPUT_RESET}"
exit "$2"
2018-11-13 21:55:59 +01:00
}
2019-04-17 12:55:07 +02:00
###
# 1 - script argument parsing
###
while [ "$#" -gt 0 ]; do
case "$1" in
-b | --branch)
wo_branch="$2"
shift
;;
--force)
wo_force_install="y"
;;
--travis)
wo_travis="y"
2019-09-27 14:25:31 +02:00
wo_force_install="y"
2019-04-17 12:55:07 +02:00
;;
2019-06-16 21:13:58 +02:00
-s | --silent)
2019-06-18 14:35:05 +02:00
wo_force_install="y"
2019-06-16 21:13:58 +02:00
;;
2019-07-29 11:23:23 +02:00
--purge | --uninstall)
wo_purge="y"
;;
2019-04-17 12:55:07 +02:00
*) # positional args
;;
esac
shift
done
2018-11-30 17:04:15 +01:00
###
# 1 - Check whether the installation is called with elevated rights
###
2018-11-13 21:55:59 +01:00
if [[ $EUID -ne 0 ]]; then
wo_lib_echo_fail "Sudo privilege required..."
2019-08-17 14:01:16 +02:00
wo_lib_echo_fail "Use: wget -qO wo wops.cc && sudo bash wo "
2018-11-13 21:55:59 +01:00
exit 100
fi
2019-08-17 14:05:40 +02:00
export DEBIAN_FRONTEND=noninteractive
2019-09-01 23:29:23 +02:00
unset LANG
2019-09-01 20:39:12 +02:00
export LANG='en_US.UTF-8'
2019-09-01 23:29:23 +02:00
export LC_ALL='C.UTF-8'
2019-09-01 20:39:12 +02:00
2019-10-08 17:14:22 +02:00
###
# 1- Main functions
###
2019-09-18 11:20:23 +02:00
# check if a command exist
2019-08-29 23:04:46 +02:00
command_exists() {
command -v "$@" > /dev/null 2>&1
}
2019-09-18 11:20:23 +02:00
# run functions and exit on failure
_run() {
if [ -n "$2" ]; then
wo_lib_echo "$2"
fi
if ! { "$1" >> "$wo_install_log" 2>&1; }; then
exit 1
fi
}
2019-10-08 17:14:22 +02:00
###
# 1- Update the apt sewers with fresh info
###
2019-10-09 11:43:09 +02:00
2019-09-03 04:00:40 +02:00
if [ -z "$wo_travis" ]; then
2019-10-09 11:43:09 +02:00
if ! {
apt-get update --allow-releaseinfo-change -qq > /dev/null 2>&1
}; then
apt-get update -qq > /dev/null 2>&1
fi
if ! command_exists curl; then
2019-10-11 13:01:00 +02:00
apt-get -y install curl -qq > /dev/null 2>&1
2019-09-02 19:50:01 +02:00
fi
2019-08-17 14:01:16 +02:00
fi
2019-08-17 14:07:59 +02:00
2019-08-17 14:24:11 +02:00
if [ -f ./setup.py ]; then
readonly wo_version_new=$(grep "version='" setup.py | awk -F "'" '{print$2}' 2>&1)
else
readonly wo_version_new=$(curl -sL https://wops.cc/setup.py 2>&1 | grep "version='" | awk -F "'" '{print$2}' 2>&1)
fi
2019-08-17 14:01:16 +02:00
echo ""
2019-08-21 17:44:42 +02:00
wo_lib_echo "Welcome to WordOps install/update script v${wo_version_new}"
2019-08-17 14:01:16 +02:00
echo ""
2018-11-30 17:04:15 +01:00
###
# 1- Check whether lsb_release is installed, and if not, install it
###
2019-09-19 23:41:44 +02:00
2019-08-29 23:04:46 +02:00
if ! command_exists lsb_release; then
apt-get install lsb-release -qq
2018-11-13 21:55:59 +01:00
fi
2018-11-30 17:04:15 +01:00
###
# 1 - Define variables for later use
###
2019-04-15 21:31:13 +02:00
if [ -z "$wo_branch" ]; then
2019-04-11 13:04:30 +02:00
wo_branch=master
fi
2018-11-13 21:55:59 +01:00
readonly wo_log_dir=/var/log/wo/
2019-03-25 10:09:53 +01:00
readonly wo_backup_dir=/var/lib/wo-backup/
2019-05-01 12:06:39 +02:00
readonly wo_tmp_dir=/var/lib/wo/tmp
2018-11-13 21:55:59 +01:00
readonly wo_install_log=/var/log/wo/install.log
2019-03-14 12:40:52 +01:00
readonly wo_linux_distro=$(lsb_release -is)
2018-11-13 21:55:59 +01:00
readonly wo_distro_version=$(lsb_release -sc)
2019-08-15 17:19:52 +02:00
readonly TIME_FORMAT='%d-%b-%Y-%H%M%S'
readonly TIME=$(date +"$TIME_FORMAT")
readonly NGINX_BACKUP_FILE="/var/lib/wo-backup/nginx-backup.$TIME.tar.gz"
readonly EE_BACKUP_FILE="/var/lib/wo-backup/ee-backup.$TIME.tar.gz"
readonly WO_BACKUP_FILE="/var/lib/wo-backup/wo-backup.$TIME.tar.gz"
2019-08-31 17:15:38 +02:00
readonly wo_lxc=$(grep "container=lxc" /proc/1/environ)
readonly wo_wsl=$(grep "wsl" /proc/1/environ)
2019-05-02 14:38:18 +02:00
WO_ARCH="$(uname -m)"
2019-03-14 12:40:52 +01:00
2019-03-20 21:59:56 +01:00
if [ -x /usr/local/bin/ee ]; then
2019-04-10 21:18:09 +02:00
ee_migration=1
elif [ -x /usr/local/bin/wo ]; then
wo_upgrade=1
2019-08-20 00:26:12 +02:00
fi
2018-11-30 17:04:15 +01:00
###
# 1 - Checking linux distro
###
2019-04-15 21:31:13 +02:00
if [ -z "$wo_force_install" ]; then
2019-04-30 18:44:35 +02:00
if [ "$wo_linux_distro" != "Ubuntu" ] && [ "$wo_linux_distro" != "Debian" ] && [ "$wo_linux_distro" != "Raspbian" ]; then
wo_lib_echo_fail "WordOps (wo) only supports Ubuntu, Debian & Raspbian at the moment."
2019-04-17 12:55:07 +02:00
wo_lib_echo_fail "If you are feeling adventurous, you are free to fork WordOps to support"
wo_lib_echo_fail "other Linux distributions and perhaps even Unix deratives."
2019-03-05 17:03:23 +01:00
exit 100
2019-04-17 12:55:07 +02:00
else
2019-08-05 04:27:27 +02:00
check_wo_linux_distro=$(lsb_release -sc | grep -E "xenial|bionic|disco|jessie|stretch|buster")
2019-04-17 12:55:07 +02:00
if [ -z "$check_wo_linux_distro" ]; then
2019-09-03 04:00:40 +02:00
wo_lib_echo_fail "WordOps (wo) only supports Ubuntu 16.04/18.04/19.04 LTS, Debian 9.x/10.x and Raspbian 9.x/10x"
2019-04-17 12:55:07 +02:00
exit 100
fi
2019-03-05 17:03:23 +01:00
fi
2018-11-13 21:55:59 +01:00
fi
2018-11-30 17:04:15 +01:00
###
# 1 - To prevent errors or unexpected behaviour, create the log and ACL it
###
2019-05-01 13:21:25 +02:00
if [ ! -d "$wo_log_dir" ] || [ ! -d "$wo_backup_dir" ] || [ ! -d "$wo_tmp_dir" ]; then
2019-03-20 21:59:56 +01:00
2019-05-01 13:21:25 +02:00
mkdir -p "$wo_backup_dir" "$wo_log_dir" "$wo_tmp_dir" || wo_lib_error "Whoops - seems we are unable to create the log directory $wo_log_dir, exit status " $?
2019-03-20 21:59:56 +01:00
2019-03-23 18:05:30 +01:00
# create wordops log files
2018-11-13 21:55:59 +01:00
touch /var/log/wo/{wordops.log,install.log}
2019-03-20 21:59:56 +01:00
2019-05-01 13:21:25 +02:00
chmod -R 700 "$wo_log_dir" "$wo_backup_dir" "$wo_tmp_dir" || wo_lib_error "Whoops, there was an error setting the permissions on the WordOps log folder, exit status " $?
2019-03-25 10:09:53 +01:00
fi
2018-11-30 17:04:15 +01:00
###
# 2 - Setup the dependencies for installation
####
2019-08-21 17:12:13 +02:00
wo_dist_upgrade() {
2019-09-18 11:20:23 +02:00
# perform server packages upgrade
2019-08-29 23:04:46 +02:00
apt-get dist-upgrade --option=Dpkg::options::=--force-confmiss --option=Dpkg::options::=--force-confold --option=Dpkg::options::=--force-unsafe-io --assume-yes --quiet
2019-09-18 11:20:23 +02:00
}
2019-08-21 17:12:13 +02:00
2019-03-22 23:55:04 +01:00
wo_install_dep() {
2019-03-20 21:59:56 +01:00
2019-09-18 11:20:23 +02:00
if [ "$wo_linux_distro" == "Ubuntu" ]; then
# install dependencies
apt-get -option=Dpkg::options::=--force-confmiss --option=Dpkg::options::=--force-confold --assume-yes install \
2019-10-09 18:50:43 +02:00
build-essential curl gzip python3-pip python3-wheel python3-apt python3-setuptools python3-dev sqlite3 git tar software-properties-common pigz \
2019-10-08 17:14:22 +02:00
gnupg2 cron ccze rsync apt-transport-https tree haveged ufw unattended-upgrades tzdata ntp > /dev/null 2>&1
2019-09-18 11:20:23 +02:00
add-apt-repository ppa:wordops/nginx-wo -yn
else
# install dependencies
apt-get -option=Dpkg::options::=--force-confmiss --option=Dpkg::options::=--force-confold --assume-yes install \
2019-10-09 18:50:43 +02:00
build-essential curl gzip dirmngr sudo python3-pip python3-wheel python3-apt python3-setuptools python3-dev ca-certificates sqlite3 git tar \
2019-09-18 11:20:23 +02:00
software-properties-common pigz apt-transport-https gnupg2 cron ccze rsync tree haveged ufw unattended-upgrades tzdata ntp > /dev/null 2>&1
# add php repository gpg key
[ -d /etc/apt/trusted.gpg.d ] && { wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg; }
# add nginx repository gpg key
curl -sL https://download.opensuse.org/repositories/home:virtubox:WordOps/Debian_10/Release.key | apt-key add -
fi
2019-03-20 21:59:56 +01:00
2019-09-18 11:20:23 +02:00
locale-gen en
# enable unattended upgades
if [ ! -f /etc/apt/apt.conf.d/20auto-upgrades ]; then
cp /usr/share/unattended-upgrades/20auto-upgrades /etc/apt/apt.conf.d/20auto-upgrades
fi
2019-06-16 21:13:58 +02:00
2018-11-13 21:55:59 +01:00
}
2019-08-29 23:04:46 +02:00
wo_timesync() {
# set default ntp pools
2019-09-18 11:20:23 +02:00
if [ -f /etc/systemd/timesyncd.conf ]; then
if ! grep -q "time.cloudflare.com" /etc/systemd/timesyncd.conf; then
sed -e 's/^#NTP=/NTP=time.cloudflare.com 0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org 2.ubuntu.pool.ntp.org 3.ubuntu.pool.ntp.org/' -i /etc/systemd/timesyncd.conf
# enable ntp
timedatectl set-ntp 1
fi
2019-08-29 23:04:46 +02:00
fi
2019-09-18 11:20:23 +02:00
}
2019-08-29 23:04:46 +02:00
2018-11-30 17:04:15 +01:00
###
# 3 - Create/migrate the essentials
###
2019-03-22 23:55:04 +01:00
wo_sync_db() {
2018-11-30 17:04:15 +01:00
###
# Switching from EE -> WO
###
2019-03-22 05:20:06 +01:00
if [ ! -f /var/lib/wo/dbase.db ]; then
2018-11-30 17:04:15 +01:00
# Create the WordOps folder
mkdir -p /var/lib/wo
2019-03-20 21:59:56 +01:00
2019-03-22 05:20:06 +01:00
if [ -f /var/lib/ee/ee.db ]; then
2019-09-20 01:13:01 +02:00
# Make a backup of the EasyEngine database
2019-03-22 05:20:06 +01:00
cp /var/lib/ee/ee.db /var/lib/wo/dbase-ee.db
2019-03-20 21:59:56 +01:00
2019-09-20 01:13:01 +02:00
# Copy ee database
2019-03-22 05:20:06 +01:00
cp /var/lib/ee/ee.db /var/lib/wo/dbase.db
else
2019-09-20 01:13:01 +02:00
if [ -d /etc/nginx/sites-available ]; then
2019-03-20 21:59:56 +01:00
2019-09-20 01:13:01 +02:00
# Create an empty database for WordOps
echo "CREATE TABLE sites (
2018-11-13 21:55:59 +01:00
id INTEGER PRIMARY KEY AUTOINCREMENT,
sitename UNIQUE,
site_type CHAR,
cache_type CHAR,
site_path CHAR,
created_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_enabled INT,
is_ssl INT,
storage_fs CHAR,
storage_db CHAR,
db_name VARCHAR,
db_user VARCHAR,
db_password VARCHAR,
db_host VARCHAR,
is_hhvm INT INT DEFAULT '0',
php_version VARCHAR
2019-03-22 05:20:06 +01:00
);" | sqlite3 /var/lib/wo/dbase.db
2019-09-20 01:13:01 +02:00
# Check site is enable/live or disable
AV_SITES="$(basename -a /etc/nginx/sites-available/* | grep -v default)"
for site in $AV_SITES; do
if [ -h "/etc/nginx/sites-enabled/$site" ]; then
wo_site_status='1'
else
wo_site_status='0'
fi
2019-03-22 05:20:06 +01:00
2019-09-20 01:13:01 +02:00
# Acquire information about the current nginx configuration
2019-03-22 05:20:06 +01:00
2019-09-20 01:13:01 +02:00
wo_site_current_type=$(grep "common/" "/etc/nginx/sites-available/$site" | awk -F "/" '{print $2}')
2019-03-22 05:20:06 +01:00
2019-09-20 01:13:01 +02:00
if echo "$wo_site_current_type" | grep -q "redis"; then
wo_site_current_cache="wpredis"
elif echo "$wo_site_current_type" | grep -q wpsc; then
wo_site_current_cache="wpsc"
elif echo "$wo_site_current_type" | grep -q wpfc; then
wo_site_current_cache="wpfc"
2019-03-22 05:20:06 +01:00
else
2019-09-20 01:13:01 +02:00
wo_site_current_cache="basic"
2019-03-22 05:20:06 +01:00
fi
2019-09-20 01:13:01 +02:00
if echo "$wo_site_current_type" | grep -q wp; then
if echo "$wo_site_current_type" | grep -q wpsubdir; then
wo_site_current="wpsubdir"
elif echo "$wo_site_current_type" | grep -q wpsudomain; then
wo_site_current="wpsubdomain"
else
wo_site_current="wp"
fi
2019-03-22 05:20:06 +01:00
else
2019-09-20 01:13:01 +02:00
if echo "$wo_site_current_type" | grep -q location; then
wo_site_current="proxy"
elif echo "$wo_site_current_type" | grep -q php; then
wo_site_current="html"
2019-03-22 05:20:06 +01:00
else
2019-09-20 01:13:01 +02:00
if [ -f "/var/www/${site}/ee-config.php" ] || [ -f "/var/www/${site}/wo-config.php" ]; then
wo_site_current="mysql"
else
wo_site_current="php"
fi
2019-03-22 05:20:06 +01:00
fi
fi
2019-09-20 01:13:01 +02:00
wo_webroot="/var/www/$site"
2019-03-20 21:59:56 +01:00
2019-09-20 01:13:01 +02:00
# Import the configuration into the WordOps SQLite database
echo "INSERT INTO sites (sitename, site_type, cache_type, site_path, is_enabled, is_ssl, storage_fs, storage_db)
2018-12-11 01:37:36 +01:00
VALUES (\"$site\", \"$wo_site_current\", \"$wo_site_current_cache\", \"$wo_webroot\", \"$wo_site_status\", 0, 'ext4', 'mysql');" | sqlite3 /var/lib/wo/dbase.db
2019-03-20 21:59:56 +01:00
2019-09-20 01:13:01 +02:00
done
fi
2019-03-22 05:20:06 +01:00
fi
2019-03-22 06:01:02 +01:00
# echo "UPDATE sites SET php_version = REPLACE(php_version, '5.6', '7.2');" | sqlite3 /var/lib/wo/dbase.db
# echo "UPDATE sites SET php_version = REPLACE(php_version, '7.0', '7.3');" | sqlite3 /var/lib/wo/dbase.db
2019-03-22 05:20:06 +01:00
fi
2018-11-13 21:55:59 +01:00
}
# Once again, set the proper ACL on the WordOps configuration directory
2019-03-22 23:55:04 +01:00
secure_wo_db() {
2019-03-20 21:59:56 +01:00
2018-11-13 21:55:59 +01:00
# The owner is root
2019-04-26 21:30:46 +02:00
chown -R root:root /var/lib/wo
2018-11-13 21:55:59 +01:00
# Only allow access by root, block others
2019-04-26 21:30:46 +02:00
chmod -R 600 /var/lib/wo
2019-03-20 21:59:56 +01:00
2018-11-13 21:55:59 +01:00
}
# Update the WP-CLI version
2019-03-22 23:55:04 +01:00
wo_update_wp_cli() {
2019-09-18 11:20:23 +02:00
WP_CLI_PATH=$(command -v wp)
if [ -n "$WP_CLI_PATH" ]; then
rm -rf "$WP_CLI_PATH"
fi
# Update WP-CLI to the most recent version
wget -qO /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x /usr/local/bin/wp
[ ! -h /usr/bin/wp ] && {
ln -s /usr/local/bin/wp /usr/bin/
}
[ -d /etc/bash_completion.d ] && {
wget -qO /etc/bash_completion.d/wp-completion.bash https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
}
2018-11-13 21:55:59 +01:00
}
2019-03-14 12:40:52 +01:00
wo_install_acme_sh() {
# check if acme.sh is already installed
2019-09-18 11:20:23 +02:00
if [ ! -x /etc/letsencrypt/acme.sh ]; then
# clone the git repository
if [ -d /opt/acme.sh/.git ]; then
git -C /opt/acme.sh pull origin master
else
git clone --depth=50 https://github.com/Neilpang/acme.sh.git /opt/acme.sh -q
fi
cd /opt/acme.sh || exit 1
# create conf directories
mkdir -p /etc/letsencrypt/{config,live,renewal}
# install acme.sh
./acme.sh --install \
--home /etc/letsencrypt \
--config-home /etc/letsencrypt/config \
--cert-home /etc/letsencrypt/renewal
# enable auto-upgrade
/etc/letsencrypt/acme.sh --config-home '/etc/letsencrypt/config' --upgrade --auto-upgrade
2019-03-23 18:05:30 +01:00
fi
2019-09-18 11:20:23 +02:00
2019-04-30 18:44:35 +02:00
if [ -x "$HOME/.acme.sh/acme.sh" ]; then
2019-09-18 11:20:23 +02:00
# backup acme.sh folder
/bin/tar -I pigz -cf /var/lib/wo-backup/acme.sh.tar.gz "$HOME/.acme.sh"
# rsync previous certificates to new acme.sh location
/usr/bin/rsync -rltgoDpz --exclude="account.conf" \
--exclude="acme.sh" \
--exclude="acme.sh.env" \
--exclude="deploy" \
--exclude="dnsapi" \
--exclude="http.header" \
--exclude="ca" \
"$HOME/.acme.sh/" \
/etc/letsencrypt/renewal/
# remove previous acme.sh folder
rm -rf "$HOME/.acme.sh"
mkdir "$HOME/.acme.sh"
touch "$HOME/.acme.sh/acme.sh.env"
# removing previous cronjob
crontab -l | sed '/41 0 \* \* \* "\/root\/\.acme\.sh"\/acme.sh --cron --home "\/root\/\.acme\.sh" > \/dev\/null/d' | crontab -
2019-03-14 12:40:52 +01:00
fi
2019-04-25 11:01:26 +02:00
# Let's Encrypt .well-known folder setup
if [ ! -d /var/www/html/.well-known/acme-challenge ]; then
mkdir -p /var/www/html/.well-known/acme-challenge
chown -R www-data:www-data /var/www/html /var/www/html/.well-known
chmod 750 /var/www/html /var/www/html/.well-known
else
2019-09-27 01:19:45 +02:00
chown -R www-data:www-data /var/www/html /var/www/html/.well-known
2019-04-25 11:01:26 +02:00
chmod 750 /var/www/html /var/www/html/.well-known
fi
2019-03-14 12:40:52 +01:00
}
2019-09-17 03:20:12 +02:00
wo_git_config() {
2019-06-18 14:35:05 +02:00
2019-07-24 14:22:27 +02:00
if [ "$wo_force_install" = "y" ]; then
2019-07-25 08:24:02 +02:00
[ ! -f "$HOME/.gitconfig" ] && { bash -c 'echo -e "[user]\n\tname = $USER\n\temail = root@$HOSTNAME.local" > $HOME/.gitconfig'; }
2019-07-24 14:22:27 +02:00
fi
2019-09-17 03:20:12 +02:00
# .gitconfig inital setup
2019-10-11 12:39:00 +02:00
cd /var/lib/wo/tmp/WordOps-install || exit 1
python3 gitconfig.py
2019-09-17 03:20:12 +02:00
}
2019-10-11 12:19:32 +02:00
# Download WordOps
wo_download() {
rm -f /etc/bash_completion.d/wo_auto.rc
rm -rf /var/lib/wo/tmp/WordOps-*
if [ -z "$wo_version" ]; then
curl -sL https://github.com/WordOps/WordOps/archive/${wo_branch}.tar.gz | tar -I pigz -xf - -C /var/lib/wo/tmp
mv "/var/lib/wo/tmp/WordOps-$wo_branch" /var/lib/wo/tmp/WordOps-install
else
curl -sL https://github.com/WordOps/WordOps/archive/v${wo_version}.tar.gz | tar -I pigz -xf - -C /var/lib/wo/tmp
mv "/var/lib/wo/tmp/WordOps-$wo_version" /var/lib/wo/tmp/WordOps-install
fi
}
2019-09-17 03:20:12 +02:00
# WordOps install
wo_install() {
2019-10-11 12:19:32 +02:00
cd /var/lib/wo/tmp/WordOps-install || exit 1
python3 setup.py install
2019-07-31 13:08:01 +02:00
}
2019-10-11 12:19:32 +02:00
# Clone Github repository if it doesn't exist
wo_install_travis() {
2019-10-08 02:36:14 +02:00
2019-10-11 12:19:32 +02:00
if [ "$wo_force_install" = "y" ]; then
[ ! -f "$HOME/.gitconfig" ] && { bash -c 'echo -e "[user]\n\tname = $USER\n\temail = root@$HOSTNAME.local" > $HOME/.gitconfig'; }
fi
if [ -f "$HOME/.gitconfig" ]; then
# install and redirect log to not print python package install
python3 setup.py install
fi
2019-10-08 02:36:14 +02:00
}
2019-03-22 23:55:04 +01:00
wo_upgrade_nginx() {
2019-03-20 21:59:56 +01:00
2019-09-18 11:20:23 +02:00
if [ -d /var/lib/wo-backup/nginx ]; then
/bin/tar -I pigz "$NGINX_BACKUP_FILE" /var/lib/wo-backup/nginx
rm -rf /var/lib/wo-backup/nginx
fi
# backup nginx conf
if [ -d /etc/nginx ]; then
/usr/bin/rsync -a --noatime /etc/nginx/ /var/lib/wo-backup/nginx/
fi
if [ -d /etc/php ]; then
/usr/bin/rsync -a --noatime /etc/php/ /var/lib/wo-backup/php/
fi
# chec if the package nginx-ee is installed
CHECK_NGINX_EE=$(dpkg --list | grep nginx-ee)
CHECK_PHP72=$(command -v php-fpm7.2)
# add new Nginx repository
if [ "$wo_distro_version" == "jessie" ]; then
# import the respository key for updates
curl -sL https://download.opensuse.org/repositories/home:virtubox:WordOps/Debian_8.0/Release.key | apt-key add -
else
curl -sL https://download.opensuse.org/repositories/home:virtubox:WordOps/Debian_9.0/Release.key | apt-key add -
fi
2019-03-20 21:59:56 +01:00
2019-09-18 11:20:23 +02:00
# install new nginx package
if [ -n "$CHECK_NGINX_EE" ]; then
if [ -x /usr/local/bin/wo ]; then
[ -f /etc/apt/preferences.d/nginx-block ] && { mv /etc/apt/preferences.d/nginx-block /var/lib/wo/tmp/nginx-block; }
# stop nginx
service nginx stop
# remove previous package
apt-mark unhold nginx-ee nginx-common nginx-custom
apt-get autoremove nginx-ee nginx-common nginx-custom --allow-change-held-packages --purge -qq
# remove previous php-fpm pool configuration
if [ -n "$CHECK_PHP72" ]; then
apt-get purge php7.2-fpm -y -qq
rm -f /etc/php/7.2/fpm/pool.d/{www.conf,www-two.conf,debug.conf}
2019-06-18 14:35:05 +02:00
fi
2019-09-18 11:20:23 +02:00
if [ -d /etc/nginx ]; then
rm -rf /etc/nginx
fi
/usr/local/bin/wo stack install --nginx --php
rm -f /etc/nginx/common/acl.conf /etc/nginx/htpasswd-wo
/usr/bin/rsync -au --noatime /var/lib/wo-backup/nginx/ /etc/nginx/
/usr/local/bin/wo stack upgrade --nginx --force
2019-06-18 14:35:05 +02:00
fi
2019-09-18 11:20:23 +02:00
fi
# restore sites and configuration
[ -f /etc/nginx/htpasswd-ee ] && { cp -f /etc/nginx/htpasswd-ee /etc/nginx/htpasswd-wo; }
sed -i "s/locations.conf/locations-wo.conf/" /etc/nginx/sites-available/*
sed -i "s/locations-php7.conf/locations-wo.conf/" /etc/nginx/sites-available/*
sed -i "s/locations-php71.conf/locations-wo.conf/" /etc/nginx/sites-available/*
sed -i "s/locations-php72.conf/locations-wo.conf/" /etc/nginx/sites-available/*
sed -i "s/locations-php73.conf/locations-wo.conf/" /etc/nginx/sites-available/*
sed -i "s/htpasswd-ee/htpasswd-wo/" /etc/nginx/common/acl.conf
sed -i 's/ssl on;/#ssl on;/' /var/www/*/conf/nginx/ssl.conf
# update redis.conf headers
if [ -f /etc/nginx/common/redis.conf ]; then
sed -i "s/X-Cache /X-SRCache-Fetch-Status /g" /etc/nginx/common/redis.conf
sed -i "s/X-Cache-2 /X-SRCache-Store-Status /g" /etc/nginx/common/redis.conf
2019-03-22 23:55:04 +01:00
2019-09-18 11:20:23 +02:00
fi
2019-03-22 23:55:04 +01:00
2019-09-18 11:20:23 +02:00
VERIFY_NGINX_CONFIG=$(nginx -t 2>&1 | grep failed)
# check if nginx -t do not return errors
if [ -z "$VERIFY_NGINX_CONFIG" ]; then
systemctl stop nginx
systemctl start nginx
else
VERIFY_NGINX_BUCKET=$(nginx -t 2>&1 | grep "server_names_hash_bucket_size")
if [ -n "$VERIFY_NGINX_BUCKET" ]; then
sed -i "s/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size 128;/g" /etc/nginx/nginx.conf
2019-03-25 10:17:51 +01:00
fi
2019-09-18 11:20:23 +02:00
systemctl stop nginx
systemctl start nginx
fi
[ -f /var/lib/wo/tmp/nginx-block ] && { mv /var/lib/wo/tmp/nginx-block /etc/apt/preferences.d/nginx-block; }
2019-03-20 21:59:56 +01:00
2018-11-13 21:55:59 +01:00
}
2019-03-22 23:55:04 +01:00
wo_update_latest() {
2019-03-20 21:59:56 +01:00
2019-03-05 17:03:23 +01:00
# Move ~/.my.cnf to /etc/mysql/conf.d/my.cnf
2019-03-20 21:59:56 +01:00
if [ ! -f /etc/mysql/conf.d/my.cnf ]; then
2019-03-05 17:03:23 +01:00
# create conf.d folder if not exist
2019-03-20 21:59:56 +01:00
[ ! -d /etc/mysql/conf.d ] && {
2018-11-13 21:55:59 +01:00
mkdir -p /etc/mysql/conf.d
chmod 755 /etc/mysql/conf.d
2019-03-20 21:59:56 +01:00
}
2019-07-18 20:49:42 +02:00
if [ -f "$HOME/.my.cnf" ]; then
cp -f "$HOME/.my.cnf" /etc/mysql/conf.d/my.cnf
2019-03-20 21:59:56 +01:00
chmod 600 /etc/mysql/conf.d/my.cnf
2019-03-22 23:55:04 +01:00
elif [ -f /root/.my.cnf ]; then
2019-03-22 06:01:02 +01:00
cp -f /root/.my.cnf /etc/mysql/conf.d/my.cnf
2019-03-20 21:59:56 +01:00
chmod 600 /etc/mysql/conf.d/my.cnf
2019-03-22 06:01:02 +01:00
fi
else
if [ ! -f /root/.my.cnf ]; then
cp /etc/mysql/conf.d/my.cnf /root/.my.cnf
2019-03-22 23:55:04 +01:00
chmod 600 /root/.my.cnf
2018-11-13 21:55:59 +01:00
fi
fi
}
2019-03-23 18:05:30 +01:00
wo_backup_ee() {
2019-09-23 14:24:16 +02:00
local BACKUP_EE=""
[ -d /etc/nginx ] && { BACKUP_EE="$BACKUP_EE /etc/nginx"; }
[ -d /etc/letsencrypt ] && { BACKUP_EE="$BACKUP_EE /etc/letsencrypt"; }
2019-10-05 12:29:49 +02:00
/bin/tar -I pigz -cf "$EE_BACKUP_FILE" /usr/local/bin/ee /usr/lib/ee/templates /etc/ee /var/lib/ee "$BACKUP_EE"
2019-09-23 14:24:16 +02:00
return 0
2019-09-18 11:20:23 +02:00
}
2019-03-23 18:05:30 +01:00
wo_backup_wo() {
2019-10-08 17:14:22 +02:00
if [ -d /etc/nginx ] && [ -d /etc/wo ] && [ -d /var/lib/wo ]; then
/bin/tar -I pigz -cf "$WO_BACKUP_FILE" /etc/nginx /etc/wo /var/lib/wo
fi
2019-09-20 01:07:19 +02:00
return 0
2019-09-18 11:20:23 +02:00
}
2019-03-23 18:05:30 +01:00
wo_clean_ee() {
2019-09-22 17:00:35 +02:00
rm -rf /usr/local/bin/ee /etc/bash_completion.d/ee_auto.rc /usr/lib/ee/templates /usr/local/lib/python3.*/dist-packages/ee-*.egg /etc/ee /var/lib/ee
2019-09-20 01:07:19 +02:00
return 0
2019-09-18 11:20:23 +02:00
}
2019-03-23 18:05:30 +01:00
2019-05-02 14:38:18 +02:00
wo_remove_ee_cron() {
2019-04-26 21:30:46 +02:00
2019-05-02 14:38:18 +02:00
crontab -l | sed '/ee site update --le=renew --all 2> \/dev\/null/d' | crontab -
2019-09-18 11:20:23 +02:00
}
2019-05-02 14:38:18 +02:00
wo_tweak_kernel() {
2019-08-31 17:15:38 +02:00
if [ "$WO_ARCH" = "x86_64" ] && [ -z "$wo_lxc" ] && [ -z "$wo_wsl" ]; then
2019-08-15 00:42:49 +02:00
rm -f /etc/sysctl.d/60-ubuntu-nginx-web-server.conf
wget -qO /etc/sysctl.d/60-wo-tweaks.conf https://raw.githubusercontent.com/WordOps/WordOps/"$wo_branch"/wo/cli/templates/sysctl.mustache
if [ "$wo_distro_version" = "bionic" ] || [ "$wo_distro_version" = "disco" ] || [ "$wo_distro_version" = "buster" ]; then
modprobe tcp_bbr && echo 'tcp_bbr' >> /etc/modules-load.d/bbr.conf
echo -e '\nnet.ipv4.tcp_congestion_control = bbr\nnet.ipv4.tcp_notsent_lowat = 16384' >> /etc/sysctl.d/60-wo-tweaks.conf
else
modprobe tcp_htcp && echo 'tcp_htcp' >> /etc/modules-load.d/htcp.conf
echo 'net.ipv4.tcp_congestion_control = htcp' >> /etc/sysctl.d/60-wo-tweaks.conf
2019-05-02 14:38:18 +02:00
fi
2019-08-15 00:42:49 +02:00
# apply sysctl tweaks
sysctl -eq -p /etc/sysctl.d/60-wo-tweaks.conf
2019-08-02 12:10:44 +02:00
fi
2019-09-18 11:20:23 +02:00
}
2019-08-21 17:12:13 +02:00
wo_systemd_tweak() {
2019-08-02 12:13:31 +02:00
if [ ! -x /opt/wo-kernel.sh ]; then
2019-09-18 11:20:23 +02:00
# download and setup wo-kernel systemd service to apply kernel tweaks for netdata and redis on server startup
wget -qO /opt/wo-kernel.sh https://raw.githubusercontent.com/WordOps/WordOps/updating-configuration/wo/cli/templates/wo-kernel-script.mustache
chmod +x /opt/wo-kernel.sh
wget -qO /lib/systemd/system/wo-kernel.service https://raw.githubusercontent.com/WordOps/WordOps/updating-configuration/wo/cli/templates/wo-kernel-service.mustache
systemctl enable wo-kernel.service
systemctl start wo-kernel.service
2019-08-02 12:13:31 +02:00
fi
2019-08-02 12:10:44 +02:00
LIMIT_CHECK=$(grep "500000" /etc/security/limits.conf)
if [ -z "$LIMIT_CHECK" ]; then
echo -e "* hard nofile 500000\n* soft nofile 500000\nroot hard nofile 500000\nroot soft nofile 500000\n" >> /etc/security/limits.conf
2019-05-02 14:38:18 +02:00
fi
2019-09-18 11:20:23 +02:00
}
2019-04-26 21:30:46 +02:00
2019-08-26 18:05:26 +02:00
wo_domain_suffix() {
2019-10-05 12:29:49 +02:00
curl -m 10 --retry 3 -sL https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat | sed '/^\/\//d' | sed '/^$/d' | sed 's/^\s+//g' > /var/lib/wo/public_suffix_list.dat
2019-09-18 11:20:23 +02:00
}
2019-08-26 18:05:26 +02:00
wo_mariadb_tweak() {
# increase mariadb open_files_limit
2019-09-18 11:20:23 +02:00
if [ -d /etc/systemd/system/mariadb.service.d ] && [ ! -f /etc/systemd/system/mariadb.service.d/limits.conf ]; then
echo -e '[Service]\nLimitNOFILE=500000' > /etc/systemd/system/mariadb.service.d/limits.conf
systemctl daemon-reload
service mysql restart
fi
2019-08-26 18:05:26 +02:00
}
wo_nginx_tweak() {
# increase nginx open_files_limit
2019-09-18 11:20:23 +02:00
if [ ! -d /etc/systemd/system/nginx.service.d ]; then
mkdir -p /etc/systemd/system/nginx.service.d
if [ ! -f /etc/systemd/system/nginx.service.d/limits.conf ]; then
echo -e '[Service]\nLimitNOFILE=500000' > /etc/systemd/system/nginx.service.d/limits.conf
systemctl daemon-reload
nginx -t && service nginx restart
2019-08-29 23:04:46 +02:00
fi
2019-09-18 11:20:23 +02:00
fi
2019-08-26 18:05:26 +02:00
}
2019-08-04 12:24:10 +02:00
wo_clean() {
rm -rf /usr/local/lib/python3.*/dist-packages/wo-*
2019-09-18 11:20:23 +02:00
}
2019-08-04 12:24:10 +02:00
2019-07-29 11:23:23 +02:00
wo_uninstall() {
2019-10-05 13:31:16 +02:00
python3 -m pip uninstall wordops -y
2019-09-17 03:20:12 +02:00
rm -rf /usr/local/lib/python3.*/dist-packages/{pystache-*,cement-2.*,wo-*} /usr/local/bin/wo /etc/bash_completion.d/wo_auto.rc /var/lib/wo /etc/wo /usr/lib/wo/templates
2019-09-18 11:20:23 +02:00
}
2019-07-29 11:23:23 +02:00
2019-08-30 21:09:10 +02:00
wo_cheat_install() {
curl -sL https://cht.sh/:cht.sh > /usr/local/bin/cht.sh
2019-09-03 06:27:43 -05:00
chmod +x /usr/local/bin/cht.sh
2019-09-06 02:23:40 +02:00
[ ! -h /usr/local/bin/cheat ] && {
2019-09-19 14:07:34 +02:00
rm -f /usr/local/bin/cheat
2019-09-06 02:23:40 +02:00
ln -s /usr/local/bin/cht.sh /usr/local/bin/cheat
2019-09-04 00:04:58 +02:00
}
2019-08-30 21:09:10 +02:00
curl -sL https://cheat.sh/:bash_completion > /etc/bash_completion.d/cht.sh
2019-09-18 11:20:23 +02:00
}
2019-08-30 21:09:10 +02:00
2019-03-05 17:03:23 +01:00
###
# 4 - WO MAIN SETUP
###
2019-09-18 11:20:23 +02:00
# wo uninstall script
2019-07-29 11:29:45 +02:00
if [ "$wo_purge" = "y" ]; then
2019-09-18 11:20:23 +02:00
_run wo_backup_wo "Backing-up WO install"
_run wo_uninstall "Uninstalling WordOps"
2019-07-29 11:23:23 +02:00
wo_lib_echo "The WordOps backup files can be found in $WO_BACKUP_FILE"
2019-09-02 18:56:34 +02:00
exit 0
2019-07-29 11:23:23 +02:00
else
# 1 - WO already installed
if [ -x /usr/local/bin/wo ]; then
2019-08-31 02:42:46 +02:00
if [ -z "$wo_force_install" ]; then
if { wo -v 2>&1 | grep -q "$wo_version_new"; }; then
2019-08-31 17:15:38 +02:00
wo_lib_error "You already have WordOps $wo_version_new" 1
2019-08-31 02:42:46 +02:00
fi
2019-08-29 23:17:18 +02:00
fi
2019-09-18 11:20:23 +02:00
_run wo_backup_wo "Backing-up WO install"
_run wo_clean
# 2 - Migration from EEv3
elif [ -x /usr/local/bin/ee ]; then
if [ -z "$wo_force_install" ]; then
echo -e "Migrate from EasyEngine to WordOps (y/n): " && read -r WO_ANSWER
if [ "$WO_ANSWER" != "y" ] && [ "$WO_ANSWER" != "Y" ]; then
wo_lib_error "Not installing WordOps" 1
2019-08-21 17:12:13 +02:00
fi
2019-03-05 17:03:23 +01:00
fi
2019-09-18 11:20:23 +02:00
_run wo_backup_ee "Backing-up EE install"
_run wo_remove_ee_cron "Removing EasyEngine cronjob"
_run wo_sync_db "Syncing WO database"
fi
_run wo_install_dep "Installing wo dependencies"
_run wo_timesync
# skip steps if travis
if [ -z "$wo_travis" ]; then
_run wo_dist_upgrade
2019-10-11 12:19:32 +02:00
_run wo_download "Downloading WordOps"
2019-09-20 18:22:22 +02:00
wo_git_config
2019-10-08 02:36:14 +02:00
_run wo_install "Installing WordOps"
else
_run wo_travis_install "Installing WordOps"
2019-09-18 11:20:23 +02:00
fi
if [ -x /usr/local/bin/ee ]; then
_run wo_upgrade_nginx "Upgrading Nginx"
_run wo_clean_ee "Cleaning previous EasyEngine install"
fi
_run wo_install_acme_sh
_run wo_tweak_kernel "Applying Kernel tweaks"
if [ ! -f /opt/wo-kernel.sh ]; then
_run wo_systemd_tweak "Adding systemd service tweak"
fi
if [ -x /usr/sbin/nginx ]; then
2019-09-18 15:07:48 +02:00
_run wo_nginx_tweak
2019-09-18 11:20:23 +02:00
fi
if [ -d /etc/systemd/system/mariadb.service.d ]; then
2019-09-18 15:07:48 +02:00
_run wo_mariadb_tweak
2019-03-05 17:03:23 +01:00
fi
2019-09-18 11:20:23 +02:00
_run wo_cheat_install "Running post-install steps"
_run wo_domain_suffix
_run wo_update_wp_cli
_run wo_update_latest
_run secure_wo_db
2018-12-03 20:17:22 +01:00
2019-08-22 14:52:05 +02:00
wo sync >> $wo_install_log 2>&1
2018-11-13 21:55:59 +01:00
2019-07-29 11:23:23 +02:00
if [ "$ee_migration" = "1" ]; then
echo
wo_lib_echo "The migration from EasyEngine to WordOps was succesfull!"
wo_lib_echo "The EasyEngine backup files can be found in /var/lib/wo-backup/ee-backup.tgz"
echo
elif [ "$wo_upgrade" = "1" ]; then
wo_lib_echo "WordOps (wo) upgrade to $wo_version_new was succesfull!"
2019-08-22 14:46:39 +02:00
echo
2019-09-15 14:47:58 +02:00
wo_lib_echo "To upgrade WordOps stacks use the command:"
wo_lib_echo_info "wo stack upgrade --all"
2019-08-22 14:46:39 +02:00
echo
2019-09-15 14:47:58 +02:00
wo_lib_echo "To update all other server packages use the command:"
2019-08-31 02:30:14 +02:00
wo_lib_echo_info "wo maintenance"
2019-07-29 11:23:23 +02:00
else
wo_lib_echo "WordOps (wo) installed successfully"
2019-08-22 14:46:39 +02:00
echo
2019-09-03 11:33:10 +02:00
wo_lib_echo "To enable bash-completion, just use the command:"
2019-09-21 19:12:46 +02:00
wo_lib_echo_info "bash -l"
2019-09-03 05:37:53 +02:00
echo
2019-09-03 11:33:10 +02:00
wo_lib_echo "To install WordOps recommended stacks, you can use the command:"
2019-08-22 15:01:35 +02:00
wo_lib_echo_info "wo stack install"
2019-09-02 19:41:46 +02:00
echo
2019-09-03 11:33:10 +02:00
wo_lib_echo "To create a first WordPress site, you can use the command:"
2019-09-02 19:41:46 +02:00
wo_lib_echo_info "wo site create site.tld --wp"
2019-07-29 11:23:23 +02:00
fi
2018-12-03 20:17:22 +01:00
echo
2019-07-29 11:23:23 +02:00
wo_lib_echo "WordOps Documentation : https://docs.wordops.net"
wo_lib_echo "WordOps Community Forum : https://community.wordops.net"
echo
2019-08-13 09:46:21 +02:00
wo_lib_echo "Give WordOps a GitHub star : https://github.com/WordOps/WordOps/"
echo
2019-02-21 21:17:54 +01:00
fi