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.

155 lines
5.3 KiB

10 months ago
10 months ago
  1. #!/bin/bash
  2. readonly EXPANDED_CONF="$MIAOU_CONFIGDIR/miaou.expanded.yaml"
  3. readonly WKHTML_VERSION="0.12.6-1"
  4. readonly WKHTML_RELEASE="$WKHTML_VERSION.buster_amd64"
  5. function check_user_odoo() {
  6. (lxc exec "$CONTAINER" -- id odoo &>/dev/null) || return 12
  7. return 0
  8. }
  9. function check_target_bgcolor() {
  10. (lxc exec "$CONTAINER" -- grep -Pq "^\\\$o-community-color: $BACKGROUND_COLOR" /home/odoo/odoo12/addons/web/static/src/scss/primary_variables.scss) || return 13
  11. return 0
  12. }
  13. function check_wkhtmltox() {
  14. (lxc exec "$CONTAINER" -- dpkg -l | grep -s wkhtmltox | grep -qs $WKHTML_VERSION) || return 1
  15. }
  16. function check_python() {
  17. (lxc exec "$CONTAINER" -- test -d /opt/Python-3.7.13) || return 1
  18. }
  19. function check_venv() {
  20. (lxc exec "$CONTAINER" -- test -d /home/odoo/venv) || return 1
  21. }
  22. function check_favicon() {
  23. lxc exec "$CONTAINER" -- test -L /home/odoo/odoo12/addons/web/static/src/img/favicon.ico
  24. }
  25. function check_file_odoo-addon-install() {
  26. (lxc exec "$CONTAINER" -- test -f /home/odoo/odoo12/odoo12-addon-install) || return 23
  27. }
  28. function check() {
  29. PREFIX="recipe:odoo12:check"
  30. check_wkhtmltox || return 10
  31. check_python || return 11
  32. check_user_odoo || return 12
  33. check_target_bgcolor || return 13
  34. check_venv || return 14
  35. check_favicon || return 15
  36. check_file_odoo-addon-install || return 23
  37. }
  38. function install() {
  39. PREFIX="recipe:odoo12:install"
  40. : $PREFIX
  41. launch_container "$CONTAINER"
  42. echo "initializing Odoo12 ... "
  43. lxc exec "$CONTAINER" -- bash <<EOF
  44. set -Eeuo pipefail
  45. echo "installing odoo12..."
  46. apt-get update && apt-get dist-upgrade -y
  47. if dpkg -l | grep -s wkhtmltox | grep -qs $WKHTML_VERSION; then
  48. echo package=wkhtmltox version=$WKHTML_RELEASE already found!
  49. else
  50. echo "wkhtmltox version=$WKHTML_RELEASE has to be installed!"
  51. wget https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTML_VERSION/wkhtmltox_$WKHTML_RELEASE.deb
  52. dpkg -i wkhtmltox_$WKHTML_RELEASE.deb || (apt -fy install && rm wkhtmltox_$WKHTML_RELEASE.deb)
  53. fi
  54. if [[ ! -d /opt/Python-3.7.13 ]]; then
  55. echo "installing Python-3.7.13..."
  56. apt-get install -y zlib1g-dev python3-pip python3-venv xz-utils build-essential libssl-dev python3-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libpq-dev libffi-dev postgresql-client
  57. wget -O- https://www.python.org/ftp/python/3.7.13/Python-3.7.13.tar.xz | tar -xJ -C /opt
  58. chown -R root:root /opt/Python-3.7.13
  59. cd /opt/Python-3.7.13
  60. ./configure --enable-optimizations --enable-shared
  61. make -j8 altinstall
  62. ldconfig /opt/Python3.7.13
  63. echo "Python-3.7.13...OK"
  64. else
  65. echo "Python-3.7.13 already installed!"
  66. fi
  67. if ! id -u odoo &>/dev/null; then
  68. echo "creating system user <odoo>"
  69. useradd -rms /bin/bash odoo
  70. else
  71. echo "user <odoo> already exists!"
  72. fi
  73. cat <<EOT | su - odoo
  74. if [[ ! -d odoo12 ]]; then
  75. echo "git odoo12 from remote"
  76. git clone https://github.com/odoo/odoo.git --depth 1 --branch 12.0 odoo12
  77. else
  78. echo "git odoo12 already downloaded!"
  79. fi
  80. if [[ ! -d venv ]]; then
  81. echo "installing Python-3.7 virtual env (venv)"
  82. python3.7 -m venv venv
  83. source venv/bin/activate
  84. python -m pip install --upgrade pip
  85. pip install wheel
  86. pip install -r odoo12/requirements.txt
  87. else
  88. echo "venv (Python-3.7) already installed!"
  89. fi
  90. echo "community-color change to $BACKGROUND_COLOR"
  91. /opt/miaou-bash/tools/append_or_replace "^.*o-community-color:.*" "\\\\\\\$o-community-color: $BACKGROUND_COLOR;" /home/odoo/odoo12/addons/web/static/src/scss/primary_variables.scss
  92. EOT
  93. mkdir -p /etc/odoo12
  94. EOF
  95. lxc file push "$MIAOU_BASEDIR/templates/apps/odoo12/odoo12-addon-install" "$CONTAINER/home/odoo/odoo12/odoo12-addon-install"
  96. lxc exec "$CONTAINER" -- bash <<EOF
  97. chown odoo:odoo /home/odoo/odoo12/odoo12-addon-install
  98. chmod 740 /home/odoo/odoo12/odoo12-addon-install
  99. echo "new script <odoo12-addon-install> added!"
  100. EOF
  101. echo "push various target-related favicons..."
  102. for favicon in "$MIAOU_BASEDIR"/templates/apps/odoo12/favicon/*.ico; do
  103. lxc file push --uid 0 --gid 0 "$favicon" "$CONTAINER/home/odoo/odoo12/addons/web/static/src/img/"
  104. done
  105. echo "OK"
  106. echo "adjust symbolic link according to target=<$TARGET>"
  107. lxc exec "$CONTAINER" -- rm -f /home/odoo/odoo12/addons/web/static/src/img/favicon.ico
  108. lxc exec "$CONTAINER" -- ln -s /home/odoo/odoo12/addons/web/static/src/img/favicon-"$TARGET".ico /home/odoo/odoo12/addons/web/static/src/img/favicon.ico
  109. echo "OK"
  110. }
  111. function compute_bgcolor_target() {
  112. case "$TARGET" in
  113. dev) echo "#17a2b8" ;;
  114. beta) echo "#79A70A" ;;
  115. prod) echo "#7C7BAD" ;;
  116. *) echoerr "unknown target <$TARGET>" && exit 10 ;;
  117. esac
  118. }
  119. ### MAIN
  120. . "$MIAOU_BASEDIR/lib/init.sh"
  121. arg1_required "$@"
  122. readonly CONTAINER="$1"
  123. TARGET=$(yq '.target' "$EXPANDED_CONF")
  124. readonly TARGET
  125. BACKGROUND_COLOR=$(compute_bgcolor_target)
  126. readonly BACKGROUND_COLOR
  127. check || (
  128. install
  129. check
  130. )