provisioning tool for building opinionated architecture
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.
 
 

83 lines
2.3 KiB

#!/bin/bash
MANDATORY_PACKAGES_STRING="nginx php-cli php-fpm php-mysql php-curl php-xml php-imagick php-zip php-gd php-intl composer mariadb-client"
### CHECK
function check() {
PREFIX="recipe:wordpress:check"
check_mandatory_packages || return 21
check_wordpress_tgz || return 22
check_wp-tool || return 23
check_wp-backup || return 24
echo "container <$CONTAINER> approved successfully!"
return 0
}
function check_mandatory_packages() {
lxc exec "$CONTAINER" -- bash <<EOF
set -Eeuo pipefail
mapfile -t PACKAGES <<< "$MANDATORY_PACKAGES_STRING"
for package in \${PACKAGES[@]}; do
dpkg -l "\$package" 2>/dev/null | grep -q ^ii
done
EOF
}
function check_wp-tool() {
lxc exec "$CONTAINER" -- test -f /usr/local/sbin/wp-tool
}
function check_wp-backup() {
lxc exec "$CONTAINER" -- test -f /usr/local/sbin/wp-backup
}
function check_wordpress_tgz() {
lxc exec "$CONTAINER" -- test -f /var/www/wordpress-latest.tgz
}
### INSTALL
function install() {
PREFIX="recipe:wordpress:install"
: $PREFIX
launch_container "$CONTAINER"
echo "initializing Wordpress ... "
lxc exec "$CONTAINER" -- bash <<EOF
set -Eeuo pipefail
echo installing wordpress...
apt-get install -y $MANDATORY_PACKAGES_STRING
rm -f /etc/nginx/sites-enabled/default
rm -f /etc/nginx/sites-available/default
systemctl reload nginx
/TOOLBOX/wget https://wordpress.org/latest.tar.gz -O /var/www/wordpress-latest.tgz
mkdir -p /var/www/wordpress
chown www-data:www-data /var/www/wordpress
EOF
echo "OK"
echo -n "copying wp-tool to /usr/local/sbin/..."
lxc file push --uid 0 --gid 0 "$MIAOU_BASEDIR/templates/apps/wordpress/wp-tool" "$CONTAINER/usr/local/sbin/wp-tool"
lxc exec "$CONTAINER" -- chmod +x /usr/local/sbin/wp-tool
PREFIX="" echo "OK"
echo -n "copying wp-backup to /usr/local/sbin/..."
lxc file push --uid 0 --gid 0 "$MIAOU_BASEDIR/templates/apps/wordpress/wp-backup" "$CONTAINER/usr/local/sbin/wp-backup"
lxc exec "$CONTAINER" -- chmod +x /usr/local/sbin/wp-backup
PREFIX="" echo "OK"
}
### MAIN
. "$MIAOU_BASEDIR/lib/init.sh"
arg1_required "$@"
readonly CONTAINER="$1"
check || (
install
check
)