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.

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