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.

126 lines
4.2 KiB

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