You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.4 KiB

#!/usr/bin/env miaou-recipe
# CONSTANTS
UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE-256M} #TODO: allow passing environment variables from `miaou-recipe`
FORCE=false
WP_NAME=
# FUNCTIONS
function usage {
echo "$RECIPE_NAME {WP_NAME} [--force|-f]"
echo "install a wordpress"
}
function parse_options {
while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
usage && exit 0
;;
--force | -f)
FORCE=true
;;
-*)
echo >&2 "ERROR: unknown option <$1>" && usage && exit 3
;;
*)
if [[ -z $WP_NAME ]]; then
WP_NAME=$1
else
echo >&2 "ERROR: unknown argument <$1>" && usage && exit 2
fi
;;
esac
shift 1 # Move to the next argument
done
[[ -z $WP_NAME ]] && echo >&2 "ERROR: expecting mandatory argument {WP_NAME}" && usage && exit 2 || true
}
function install_mariadb {
if $FORCE || ! systemctl is-active mariadb.service --quiet; then
DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server
echo mariadb installed successfully!
else
echo mariadb already installed!
fi
}
function install_php {
local php_version=php --version | head -n1 | cut -d' ' -f2 | grep -o '^[[:digit:]]*\.[[:digit:]]*'
local php_service="php$php_version-fpm"
if $FORCE || ! systemctl is-active "$php_service" --quiet; then
apt-get install -y php-fpm php-mysql php-curl php-dom php-imagick php-mbstring php-zip php-gd php-intl
php_version=php --version | head -n1 | cut -d' ' -f2 | grep -o '^[[:digit:]]*\.[[:digit:]]*'
sed -i "s/^post_max_size = 8M/post_max_size = $UPLOAD_MAX_SIZE/g" /etc/php/$php_version/fpm/php.ini
sed -i "s/^upload_max_filesize = 2M/upload_max_filesize = $UPLOAD_MAX_SIZE/g" /etc/php/$php_version/fpm/php.ini
systemctl enable "$php_service" --now
echo "$php_service installed successfully!"
else
echo "$php_service already installed!"
fi
}
function install_nginx_host {
if $FORCE || [[ ! -f /etc/nginx/sites-available/sympa.conf ]]; then
cat << EOF > /etc/nginx/sites-available/sympa.conf
server {
listen {{ env.APP_PORT }} default_server;
access_log /var/log/nginx/{{ env.APP_NAME }}/wp-access.log;
error_log /var/log/nginx/{{ env.APP_NAME }}/wp-error.log;
client_max_body_size 50M;
root /var/www/wordpress/{{ env.APP_NAME }};
index index.php index.html index.htm;
charset UTF-8;
location / {
try_files $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~* \.(js|css|png|jpg|jpeg|svg|gif|ico|eot|otf|ttf|woff|woff2|mp3|wav|ogg)$ {
add_header Access-Control-Allow-Origin *;
access_log off; log_not_found off; expires 30d;
}
# Mailpoet - tinyMCE quick fix
location ~ /wp-content/plugins/wysija-newsletters/js/tinymce/.*\.(htm|html)$ {
add_header Access-Control-Allow-Origin *;
access_log off; log_not_found off; expires 30d;
}
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
}
EOF
cd /etc/nginx/sites-enabled && rm -f default && ln -sf ../sites-available/sympa.conf && cd
systemctl reload nginx
echo host for nginx installed successfully!
else
echo host for nginx already installed!
fi
}
# MAIN
set -Eue -o pipefail
parse_options "$@"
exit 0
install_mariadb
install_php
# install_wordpress
# install_nginx_host