set -e
ODOO_VERSION="16.0"
WKHTML_VERSION="0.12.6.1-2"
#curl  http://nightly.odoo.com/${ODOO_VERSION}/nightly/rpm/odoo_${ODOO_VERSION}.latest.rpm -o odoo_${ODOO_VERSION}.latest.rpm
#OPT=$(dnf_opt_base "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP")
#dnf --assumeyes $OPT localinstall odoo_${ODOO_VERSION}.latest.rpm
#rm -f odoo_${ODOO_VERSION}.latest.rpm
mv $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/etc/resolv.conf /tmp
echo "nameserver 9.9.9.9" > $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/etc/resolv.conf

WKHTML_PKG=wkhtmltox_$WKHTML_VERSION.bullseye_amd64.deb

curl https://nightly.odoo.com/odoo.key -o "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/odoo.key"
curl -L "https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTML_VERSION/$WKHTML_PKG" -o "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/$WKHTML_PKG"
echo """#!/bin/bash -xe
cat /odoo.key | apt-key add -
rm /odoo.key
echo "deb http://nightly.odoo.com/$ODOO_VERSION/nightly/deb/ ./" >> /etc/apt/sources.list 
apt update
apt install --no-install-recommends -y odoo
dpkg -i /"$WKHTML_PKG" || true
rm -f /"$WKHTML_PKG"
apt -f install -y
""" > $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/install.sh
chmod 755 $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/install.sh
chroot $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP /install.sh



sed -i "s/'postgres'/odoo.tools.config['db_name']/g" $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/usr/lib/python3/dist-packages/odoo/service/server.py
sed -i "s/'postgres'/odoo.tools.config['db_name']/g" $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/usr/lib/python3/dist-packages/odoo/service/db.py 
sed -i "s/'postgres'/odoo.tools.config['db_name']/g" $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/usr/lib/python3/dist-packages/odoo/addons/bus/models/bus.py
sed -i "s/'postgres'/odoo.tools.config['db_name']/g" $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_cron.py
sed -i "s@ldap://@ldaps://@g" $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/usr/lib/python3/dist-packages/odoo/addons/auth_ldap/models/res_company_ldap.py
mv -f /tmp/resolv.conf $IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP/etc/resolv.conf
set +e
