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.

269 lines
6.4 KiB

  1. #!/bin/bash
  2. set -ex # -x for verbose logging to juju debug-log
  3. ##
  4. ## Options (changeable thanks to ``/etc/charm/openerp.conf``)
  5. ##
  6. OPENERP_PASSWORD=${OPENERP_PASSWORD:-openerp_password}
  7. ## 0k git remote path
  8. GIT_0K_BASE=${GIT_0K_BASE:-"git.0k.io:/var/git"}
  9. ## 0k git remote options
  10. GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""}
  11. ## 0k git-sub setup options
  12. GIT_0K_SUB_CLONE_OPTIONS=${GIT_0K_SUB_CLONE_OPTIONS:-""}
  13. ## 0k git default checkout reference (for 0k-oe root package)
  14. GIT_0K_CHECKOUT_REF=${GIT_0K_CHECKOUT_REF:-"8.0/0k/dev/master"}
  15. RELEASE=${RELEASE:-}
  16. test -z "$RELEASE" && RELEASE=$(lsb_release -c -s)
  17. ##
  18. ## Code
  19. ##
  20. if [ -z "$NO_VIRTUALENV" ]; then
  21. set +ex
  22. source /srv/virtualenv/default/bin/activate
  23. set -ex
  24. fi
  25. if [ "$NO_VIRTUALENV" ]; then
  26. apt-get install -y --no-install-recommends python-geoip python-gevent \
  27. python-ldap python-lxml python-markupsafe python-pil python-pip \
  28. python-psutil python-psycopg2 python-pychart python-pydot python-pil \
  29. python-reportlab python-simplejson python-yaml wget wkhtmltopdf \
  30. python-mysqldb
  31. else
  32. ##
  33. ## Installing PIL
  34. ##
  35. ## install deps for PIL compilations
  36. ## from http://www.sandersnewmedia.com/why/2012/04/16/installing-pil-virtualenv-ubuntu-1204
  37. DEV="libxml2-dev libxslt-dev libpq-dev libyaml-dev
  38. zlib1g-dev libfreetype6-dev
  39. libsasl2-dev libjpeg-dev libmysqlclient-dev"
  40. LIB="libxslt1.1 libpq5 libjpeg8 libtiff5 libmysqlclient18"
  41. apt-get install $DEV $LIB \
  42. -y --force-yes --no-install-recommends
  43. if ! [ -e "/usr/lib/libjpeg.so" ]; then
  44. if [ "$RELEASE" == "trusty" ]; then
  45. ## for some reason /etc/apt/sources.list can be WITHOUT deb-src lines
  46. apt-cache policy python-imaging | tail -n 1 | \
  47. while read code url distrib arch type; do
  48. echo deb-src $url $(echo "$distrib" | tr "/" " ");
  49. done >> /etc/apt/sources.list &&
  50. apt-get update
  51. fi
  52. if ! [ -d "/usr/include/freetype2/freetype" ]; then
  53. (cd /usr/include/freetype2 &&
  54. ln -sf . freetype)
  55. fi
  56. apt-get build-dep python-imaging -y --force-yes &&
  57. ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/ &&
  58. ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/ &&
  59. ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/
  60. fi
  61. ## Installing PIL with our archive is safer.
  62. #pip install pil
  63. (
  64. cd /tmp &&
  65. scp "$GIT_0K_BASE"/archives/PIL-1.1.7.tar.gz . &&
  66. tar xvzf PIL-1.1.7.tar.gz &&
  67. cd PIL-1.1.7 &&
  68. python setup.py install
  69. cd /tmp
  70. rm -rf /tmp/PIL-1.1.7
  71. )
  72. ## Install pychart... from our repo as :
  73. ## download link in PyPi is dead,
  74. ## and gna.org was down recently
  75. (
  76. scp "$GIT_0K_BASE/archives/PyChart-1.39.tar.gz" /tmp &&
  77. cd /tmp && tar xvzf PyChart*.tar.gz &&
  78. cd PyChart* &&
  79. python setup.py install &&
  80. cd /tmp &&
  81. rm -rf /tmp/PyChart*
  82. )
  83. ## should be in connectors requirements.
  84. pip install mysql-python
  85. fi
  86. pip install sact.epoch shyaml
  87. ## Install OOOP... from our git repo as:
  88. ## we have some bug correction and custom features
  89. PYTHON_LIB_DEST=/usr/lib/python2.7
  90. if [ -z "$NO_VIRTUALENV" ]; then
  91. PYTHON_LIB_DEST=/srv/virtualenv/default/lib/python2.7
  92. fi
  93. mkdir -p /opt/apps
  94. if ! [ -d "/opt/apps/ooop" ]; then
  95. (
  96. cd /opt/apps &&
  97. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/ooop.git" &&
  98. cd /opt/apps/ooop &&
  99. git checkout 0k/prod/master &&
  100. ## beurk
  101. ln -sf /opt/apps/ooop/ooop.py $PYTHON_LIB_DEST/ooop.py
  102. )
  103. fi
  104. ## Install aerolib... from our git repo as:
  105. if ! [ -d "/opt/apps/aeroolib" ]; then
  106. (
  107. cd /opt/apps &&
  108. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/aeroolib.git" &&
  109. cd /opt/apps/aeroolib &&
  110. git checkout master &&
  111. ## beurk
  112. ln -sf /opt/apps/aeroolib/aeroolib/aeroolib $PYTHON_LIB_DEST/aeroolib
  113. )
  114. fi
  115. ## Install werkzeug from github last version
  116. ## because last PyPi version is 8.4 and we need the 9.0+
  117. (
  118. cd /tmp &&
  119. git clone https://github.com/mitsuhiko/werkzeug.git &&
  120. cd werkzeug &&
  121. python setup.py install &&
  122. cd /tmp &&
  123. rm -rf werkzeug
  124. )
  125. ##
  126. ## Install 0k-oe
  127. ##
  128. AVOID_INSTALL=
  129. if [ "$NO_VIRTUALENV" ]; then
  130. ## These are provided in the system already
  131. AVOID_INSTALL="psycopg2 pil lxml gevent python-ldap MarkupSafe
  132. psutil http://download.gna.org/pychart/PyChart-1.39.tar.gz
  133. pydot reportlab simplejson PyYAML"
  134. fi
  135. (
  136. cd /opt/apps || exit 1
  137. if [ "$ODOO_CP_FROM_DIR" ]; then
  138. cp -a "$ODOO_CP_FROM_DIR" "/opt/apps/0k-oe"
  139. else
  140. git sub clone $GIT_0K_CLONE_OPTIONS $GIT_0K_SUB_CLONE_OPTIONS -b "$GIT_0K_CHECKOUT_REF" \
  141. "$GIT_0K_BASE"/0k/0k-oe
  142. fi &&
  143. cd 0k-oe &&
  144. (
  145. [ -e odoo/requirements.txt ] && cat odoo/requirements.txt
  146. for req in addons/*/requirements.txt; do
  147. if [ -r "$req" ]; then
  148. cat "$req"
  149. fi
  150. done
  151. ) | sort -u > /tmp/requirements.txt
  152. for pack in $AVOID_INSTALL; do
  153. sed -ri "s%^($pack.*)$%#\1%g" /tmp/requirements.txt
  154. done
  155. pip install -r /tmp/requirements.txt || exit 1
  156. rm /tmp/requirements.txt
  157. ) || exit 1
  158. ## System user
  159. adduser --system --home=/var/lib/openerp --group openerp
  160. ## /etc/init.d
  161. if [ -z "$DOCKER" ]; then
  162. cp -i etc/init.d/openerp-server /etc/init.d/
  163. chown openerp /etc/init.d/openerp-server
  164. update-rc.d openerp-server defaults
  165. fi
  166. ## /etc/openerp-server.conf
  167. cp -i etc/openerp-server.conf /etc/
  168. sed -ri "s/%%PASSWORD%%/$OPENERP_PASSWORD/g" /etc/openerp-server.conf
  169. chown openerp /etc/openerp-server.conf
  170. chmod 600 /etc/openerp-server.conf
  171. ## Log dir
  172. mkdir -p /var/log/openerp
  173. touch /var/log/openerp/openerp-server.log
  174. chown openerp /var/log/openerp -R
  175. cp -i etc/default/openerp-server /etc/default/openerp-server
  176. ##
  177. ## Linking with external filestore !
  178. ##
  179. (
  180. ## keeping for compatibility with older version
  181. cd /opt/apps/0k-oe/odoo/openerp &&
  182. mkdir -p /var/openerp-filestore &&
  183. ln -sf /var/openerp-filestore filestore &&
  184. cd /var/openerp-filestore &&
  185. chown openerp .
  186. )
  187. ln -sf "/opt/apps/0k-oe/bin/oe" "/usr/local/bin/oe"
  188. ##
  189. ## Remove all unwanted libs
  190. ##
  191. if [ -z "$NO_VIRTUALENV" ]; then
  192. apt-get autoremove -y --force-yes $(apt-cache showsrc python-imaging |
  193. sed -e '/Build-Depends/!d;s/Build-Depends: \|,\|([^)]*),*\|\[[^]]*\]//g')
  194. fi
  195. apt-get autoremove $DEV -y --force-yes