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.

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