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.

158 lines
5.4 KiB

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