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.

129 lines
4.3 KiB

10 months ago
  1. #!/bin/bash
  2. readonly EXPANDED_CONF="$MIAOU_CONFIGDIR/miaou.expanded.yaml"
  3. readonly ODOO15_DIR="/home/odoo/odoo15"
  4. readonly WKHTML_VERSION="0.12.6.1-3"
  5. readonly WKHTML_RELEASE="$WKHTML_VERSION.bookworm_amd64"
  6. function check_user_odoo() {
  7. (lxc exec "$CONTAINER" -- id odoo &>/dev/null) || return 12
  8. return 0
  9. }
  10. function check_target_bgcolor() {
  11. (lxc exec "$CONTAINER" -- grep -Pq "^\\\$o-community-color: $BACKGROUND_COLOR" "$ODOO15_DIR/addons/web/static/src/legacy/scss/primary_variables.scss") || return 13
  12. return 0
  13. }
  14. function check_file_odoo-addon-install() {
  15. (lxc exec "$CONTAINER" -- test -f /home/odoo/odoo15/odoo-addon-install) || return 23
  16. return 0
  17. }
  18. function check() {
  19. PREFIX="recipe:odoo15:check"
  20. check_user_odoo || return 21
  21. check_target_bgcolor || return 22
  22. check_file_odoo-addon-install || return 23
  23. echo "container <$CONTAINER> approved successfully!"
  24. return 0
  25. }
  26. function install() {
  27. PREFIX="recipe:odoo15:install"
  28. : $PREFIX
  29. launch_container "$CONTAINER"
  30. echo "initializing Odoo15 ... "
  31. lxc exec "$CONTAINER" -- bash <<EOF
  32. set -Eeuo pipefail
  33. cloud-init status --wait > /dev/null
  34. echo "installing odoo15..."
  35. apt update && apt dist-upgrade -y
  36. echo "required packages"
  37. apt install -y postgresql-client build-essential zlib1g-dev libssl-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libpq-dev libffi-dev
  38. if [[ ! -d /usr/local/share/python3.9 ]]; then
  39. echo "install python-3.9.18"
  40. cd /tmp
  41. wget https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz
  42. tar -xf Python-3.9.18.tgz
  43. mv Python-3.9.18 /usr/local/share/python3.9
  44. cd /usr/local/share/python3.9
  45. ./configure --enable-optimizations --enable-shared
  46. make -j \$(nproc)
  47. make altinstall
  48. ldconfig /usr/local/share/python3.9
  49. else
  50. echo "python-3.9.18 already installed!"
  51. fi
  52. if dpkg -l | grep -s wkhtmltox | grep -qs $WKHTML_VERSION; then
  53. echo package=wkhtmltox version=$WKHTML_RELEASE already found!
  54. else
  55. echo "wkhtmltox version=$WKHTML_RELEASE has to be installed!"
  56. wget https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTML_VERSION/wkhtmltox_$WKHTML_RELEASE.deb
  57. dpkg -i wkhtmltox_$WKHTML_RELEASE.deb || (apt -fy install && rm wkhtmltox_$WKHTML_RELEASE.deb)
  58. fi
  59. if ! grep -q odoo /etc/passwd; then
  60. echo "add user <odoo>"
  61. useradd -ms /bin/bash odoo
  62. else
  63. echo "user <odoo> already set!"
  64. fi
  65. echo "install odoo15 in odoo userspace"
  66. cat <<EOT | su - odoo
  67. set -Eeuo pipefail
  68. if [[ ! -d odoo15 ]]; then
  69. echo "git odoo15 from remote"
  70. git clone https://github.com/odoo/odoo.git --depth 1 --branch 15.0 odoo15
  71. export MAKEFLAGS="-j\$(nproc)"
  72. pip3.9 install --upgrade pip
  73. pip3.9 install wheel pypdf2 slugify
  74. pip3.9 install -r odoo15/requirements.txt
  75. else
  76. echo "git odoo15 already downloaded!"
  77. fi
  78. echo "community-color change to $BACKGROUND_COLOR"
  79. /opt/debian-bash/tools/append_or_replace "^.*o-community-color:.*" "\\\\\\\$o-community-color: $BACKGROUND_COLOR !default;" /home/odoo/odoo15/addons/web/static/src/legacy/scss/primary_variables.scss
  80. EOT
  81. mkdir -p /etc/odoo15
  82. EOF
  83. lxc file push "$MIAOU_BASEDIR/templates/apps/odoo15/odoo-addon-install" "$CONTAINER/home/odoo/odoo15/odoo-addon-install"
  84. lxc exec "$CONTAINER" -- bash <<EOF
  85. chown odoo:odoo /home/odoo/odoo15/odoo-addon-install
  86. chmod 740 /home/odoo/odoo15/odoo-addon-install
  87. echo "new script <odoo-addon-install> added!"
  88. EOF
  89. }
  90. function compute_bgcolor_target() {
  91. target=$(yq '.target' "$EXPANDED_CONF")
  92. case "$target" in
  93. dev) builtin echo "#17a2b8" ;;
  94. beta) builtin echo "#79A70A" ;;
  95. prod) builtin echo "#7C7BAD" ;;
  96. *) echoerr "unknown target <$target>" && exit 10 ;;
  97. esac
  98. }
  99. ### MAIN
  100. . "$MIAOU_BASEDIR/lib/init.sh"
  101. arg1_required "$@"
  102. readonly CONTAINER="$1"
  103. BACKGROUND_COLOR=$(compute_bgcolor_target)
  104. readonly BACKGROUND_COLOR
  105. check || (
  106. install
  107. check
  108. )