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.

81 lines
2.2 KiB

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