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

10 months ago
  1. #!/bin/bash
  2. 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"
  3. ### CHECK
  4. function check() {
  5. PREFIX="recipe:wordpress:check"
  6. check_mandatory_packages || return 21
  7. check_wordpress_tgz || return 22
  8. check_wp-tool || return 23
  9. check_wp-backup || return 24
  10. echo "container <$CONTAINER> approved successfully!"
  11. return 0
  12. }
  13. function check_mandatory_packages() {
  14. lxc exec "$CONTAINER" -- bash <<EOF
  15. set -Eeuo pipefail
  16. mapfile -t PACKAGES <<< "$MANDATORY_PACKAGES_STRING"
  17. for package in \${PACKAGES[@]}; do
  18. dpkg -l "\$package" 2>/dev/null | grep -q ^ii
  19. done
  20. EOF
  21. }
  22. function check_wp-tool() {
  23. lxc exec "$CONTAINER" -- test -f /usr/local/sbin/wp-tool
  24. }
  25. function check_wp-backup() {
  26. lxc exec "$CONTAINER" -- test -f /usr/local/sbin/wp-backup
  27. }
  28. function check_wordpress_tgz() {
  29. lxc exec "$CONTAINER" -- test -f /var/www/wordpress-latest.tgz
  30. }
  31. ### INSTALL
  32. function install() {
  33. PREFIX="recipe:wordpress:install"
  34. : $PREFIX
  35. launch_container "$CONTAINER"
  36. echo "initializing Wordpress ... "
  37. lxc exec "$CONTAINER" -- bash <<EOF
  38. set -Eeuo pipefail
  39. echo installing wordpress...
  40. apt-get install -y $MANDATORY_PACKAGES_STRING
  41. rm -f /etc/nginx/sites-enabled/default
  42. rm -f /etc/nginx/sites-available/default
  43. systemctl reload nginx
  44. /TOOLBOX/wget https://wordpress.org/latest.tar.gz -O /var/www/wordpress-latest.tgz
  45. mkdir -p /var/www/wordpress
  46. chown www-data:www-data /var/www/wordpress
  47. EOF
  48. echo "OK"
  49. echo -n "copying wp-tool to /usr/local/sbin/..."
  50. lxc file push --uid 0 --gid 0 "$MIAOU_BASEDIR/templates/apps/wordpress/wp-tool" "$CONTAINER/usr/local/sbin/wp-tool"
  51. lxc exec "$CONTAINER" -- chmod +x /usr/local/sbin/wp-tool
  52. PREFIX="" echo "OK"
  53. echo -n "copying wp-backup to /usr/local/sbin/..."
  54. lxc file push --uid 0 --gid 0 "$MIAOU_BASEDIR/templates/apps/wordpress/wp-backup" "$CONTAINER/usr/local/sbin/wp-backup"
  55. lxc exec "$CONTAINER" -- chmod +x /usr/local/sbin/wp-backup
  56. PREFIX="" echo "OK"
  57. }
  58. ### MAIN
  59. . "$MIAOU_BASEDIR/lib/init.sh"
  60. arg1_required "$@"
  61. readonly CONTAINER="$1"
  62. check || (
  63. install
  64. check
  65. )