second commit
This commit is contained in:
Executable
+202
@@ -0,0 +1,202 @@
|
||||
#!/bin/bash
|
||||
|
||||
function check_database_exists() {
|
||||
db-maria list | grep -q "$longname"
|
||||
}
|
||||
|
||||
function check_port_used() {
|
||||
# shellcheck disable=SC2034
|
||||
usedport=$(lxc exec "$container" -- bash -c "grep listen /etc/nginx/sites-enabled/$longname.conf | cut -d' ' -f6")
|
||||
[[ "$usedport" == "$port" ]]
|
||||
}
|
||||
|
||||
function check_service_running() {
|
||||
lxc exec "$container" -- bash -c "systemctl is-active --quiet nginx.service"
|
||||
}
|
||||
|
||||
function _read() {
|
||||
disable_trace
|
||||
check_database_exists
|
||||
check_container "$container"
|
||||
check_port_used
|
||||
check_service_running
|
||||
enable_trace
|
||||
return 0
|
||||
}
|
||||
|
||||
function _create() {
|
||||
|
||||
echo "creating wordpress instance for <$shortname> ... "
|
||||
|
||||
mkdir -p "$MIAOU_CONFIGDIR/apps/wordpress"
|
||||
APP_PORT=$port APP_NAME=$shortname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/wordpress/wp-host.j2" -o "$MIAOU_CONFIGDIR/apps/wordpress/$longname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml"
|
||||
echo "creating templates ... OK"
|
||||
|
||||
echo "copying files over container <$container> ... "
|
||||
lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/wordpress/$longname.conf" "$container/etc/nginx/sites-available/$longname.conf"
|
||||
echo "copying files over container <$container> ... OK"
|
||||
|
||||
if ! (db-maria list | grep -q "$longname"); then
|
||||
echo "create empty database <$longname> ... "
|
||||
db-maria create "$longname"
|
||||
echo "create empty database <$longname> ... OK"
|
||||
else
|
||||
echo "database already exists!"
|
||||
fi
|
||||
|
||||
echo "initialize wordpress $shortname $longname ..."
|
||||
lxc exec "$container" -- bash <<EOF
|
||||
set -Eeuo pipefail
|
||||
if [[ ! -d /var/www/wordpress/$shortname ]]; then
|
||||
echo "installing new instance of wordpress into /var/www/wordpress/$shortname"
|
||||
mkdir -p /tmp/$shortname
|
||||
tar -xzf /var/www/wordpress-latest.tgz -C /tmp/$shortname
|
||||
mv /tmp/$shortname/wordpress /var/www/wordpress/$shortname
|
||||
else
|
||||
echo "instance of wordpress /var/www/wordpress/$shortname already defined!"
|
||||
fi
|
||||
|
||||
if [[ ! -f /var/www/wordpress/$shortname/wp-config.php ]]; then
|
||||
echo "create wp-config.php"
|
||||
cat << 'EOT2' > /var/www/wordpress/$shortname/wp-config.php
|
||||
<?php
|
||||
|
||||
define( 'DB_NAME', '$longname' );
|
||||
define( 'DB_USER', '$longname' );
|
||||
define( 'DB_PASSWORD', '$longname' );
|
||||
define( 'DB_HOST', 'ct1.lxd' );
|
||||
|
||||
define( 'DB_CHARSET', 'utf8' );
|
||||
define( 'DB_COLLATE', '' );
|
||||
|
||||
define( 'AUTH_KEY', '$(genpasswd 20)' );
|
||||
define( 'SECURE_AUTH_KEY', '$(genpasswd 20)' );
|
||||
define( 'LOGGED_IN_KEY', '$(genpasswd 20)' );
|
||||
define( 'NONCE_KEY', '$(genpasswd 20)' );
|
||||
define( 'AUTH_SALT', '$(genpasswd 20)' );
|
||||
define( 'SECURE_AUTH_SALT', '$(genpasswd 20)' );
|
||||
define( 'LOGGED_IN_SALT', '$(genpasswd 20)' );
|
||||
define( 'NONCE_SALT', '$(genpasswd 20)' );
|
||||
|
||||
\$table_prefix = 'wp_';
|
||||
define( 'WP_DEBUG', false );
|
||||
|
||||
/* Add any custom values between this line and the "stop editing" line. */
|
||||
\$_SERVER['HTTPS'] = 'on';
|
||||
|
||||
/* That's all, stop editing! Happy publishing. */
|
||||
|
||||
/** Absolute path to the WordPress directory. */
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
define( 'ABSPATH', __DIR__ . '/' );
|
||||
}
|
||||
|
||||
/** Sets up WordPress vars and included files. */
|
||||
require_once ABSPATH . 'wp-settings.php';
|
||||
EOT2
|
||||
|
||||
else
|
||||
echo "wp-config.php already defined!"
|
||||
fi
|
||||
|
||||
chown -R www-data:www-data /var/www/wordpress/$shortname
|
||||
|
||||
echo "enabling wordpress host into nginx"
|
||||
mkdir -p /var/log/nginx/$shortname
|
||||
ln -sf "/etc/nginx/sites-available/$longname.conf" "/etc/nginx/sites-enabled/$longname.conf"
|
||||
|
||||
echo "reloading nginx"
|
||||
nginx -tq && systemctl reload nginx
|
||||
EOF
|
||||
echo "initialize wordpress $shortname $longname ... OK"
|
||||
}
|
||||
|
||||
function _update() {
|
||||
echo "update"
|
||||
}
|
||||
|
||||
function _delete() {
|
||||
echo "delete"
|
||||
}
|
||||
|
||||
function usage() {
|
||||
echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME"
|
||||
exit 2
|
||||
}
|
||||
|
||||
### MAIN
|
||||
|
||||
# init_strict
|
||||
|
||||
COMMAND_NAME=$(basename "$0")
|
||||
|
||||
# read the options
|
||||
|
||||
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
|
||||
# shellcheck disable=SC2181
|
||||
[[ "$?" -eq 0 ]] || usage
|
||||
eval set -- "$TEMP"
|
||||
|
||||
action="unset"
|
||||
port="unset"
|
||||
container="unset"
|
||||
shortname="unset"
|
||||
longname="unset"
|
||||
|
||||
# extract options and their arguments into variables.
|
||||
while true; do
|
||||
case "$1" in
|
||||
--port)
|
||||
port=$2
|
||||
shift 2
|
||||
;;
|
||||
--fqdn)
|
||||
shift 2
|
||||
;;
|
||||
--container)
|
||||
container=$2
|
||||
shift 2
|
||||
;;
|
||||
--name)
|
||||
shortname=$2
|
||||
longname="wp-$shortname"
|
||||
shift 2
|
||||
;;
|
||||
-c)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_create"
|
||||
shift 1
|
||||
;;
|
||||
-r)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_read"
|
||||
shift 1
|
||||
;;
|
||||
-u)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_update"
|
||||
shift 1
|
||||
;;
|
||||
-d)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_delete"
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Internal error!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
. "$MIAOU_BASEDIR/lib/init.sh"
|
||||
[[
|
||||
"$action" != unset &&
|
||||
"$port" != unset &&
|
||||
"$container" != unset &&
|
||||
"$shortname" != unset ]] || usage
|
||||
$action
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/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
|
||||
)
|
||||
Reference in New Issue
Block a user