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.
 
 

129 lines
4.3 KiB

#!/bin/bash
readonly EXPANDED_CONF="$MIAOU_CONFIGDIR/miaou.expanded.yaml"
readonly ODOO15_DIR="/home/odoo/odoo15"
readonly WKHTML_VERSION="0.12.6.1-3"
readonly WKHTML_RELEASE="$WKHTML_VERSION.bookworm_amd64"
function check_user_odoo() {
(lxc exec "$CONTAINER" -- id odoo &>/dev/null) || return 12
return 0
}
function check_target_bgcolor() {
(lxc exec "$CONTAINER" -- grep -Pq "^\\\$o-community-color: $BACKGROUND_COLOR" "$ODOO15_DIR/addons/web/static/src/legacy/scss/primary_variables.scss") || return 13
return 0
}
function check_file_odoo-addon-install() {
(lxc exec "$CONTAINER" -- test -f /home/odoo/odoo15/odoo-addon-install) || return 23
return 0
}
function check() {
PREFIX="recipe:odoo15:check"
check_user_odoo || return 21
check_target_bgcolor || return 22
check_file_odoo-addon-install || return 23
echo "container <$CONTAINER> approved successfully!"
return 0
}
function install() {
PREFIX="recipe:odoo15:install"
: $PREFIX
launch_container "$CONTAINER"
echo "initializing Odoo15 ... "
lxc exec "$CONTAINER" -- bash <<EOF
set -Eeuo pipefail
cloud-init status --wait > /dev/null
echo "installing odoo15..."
apt update && apt dist-upgrade -y
echo "required packages"
apt install -y postgresql-client build-essential zlib1g-dev libssl-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libpq-dev libffi-dev
if [[ ! -d /usr/local/share/python3.9 ]]; then
echo "install python-3.9.18"
cd /tmp
wget https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz
tar -xf Python-3.9.18.tgz
mv Python-3.9.18 /usr/local/share/python3.9
cd /usr/local/share/python3.9
./configure --enable-optimizations --enable-shared
make -j \$(nproc)
make altinstall
ldconfig /usr/local/share/python3.9
else
echo "python-3.9.18 already installed!"
fi
if dpkg -l | grep -s wkhtmltox | grep -qs $WKHTML_VERSION; then
echo package=wkhtmltox version=$WKHTML_RELEASE already found!
else
echo "wkhtmltox version=$WKHTML_RELEASE has to be installed!"
wget https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTML_VERSION/wkhtmltox_$WKHTML_RELEASE.deb
dpkg -i wkhtmltox_$WKHTML_RELEASE.deb || (apt -fy install && rm wkhtmltox_$WKHTML_RELEASE.deb)
fi
if ! grep -q odoo /etc/passwd; then
echo "add user <odoo>"
useradd -ms /bin/bash odoo
else
echo "user <odoo> already set!"
fi
echo "install odoo15 in odoo userspace"
cat <<EOT | su - odoo
set -Eeuo pipefail
if [[ ! -d odoo15 ]]; then
echo "git odoo15 from remote"
git clone https://github.com/odoo/odoo.git --depth 1 --branch 15.0 odoo15
export MAKEFLAGS="-j\$(nproc)"
pip3.9 install --upgrade pip
pip3.9 install wheel pypdf2 slugify
pip3.9 install -r odoo15/requirements.txt
else
echo "git odoo15 already downloaded!"
fi
echo "community-color change to $BACKGROUND_COLOR"
/opt/miaou-bash/tools/append_or_replace "^.*o-community-color:.*" "\\\\\\\$o-community-color: $BACKGROUND_COLOR !default;" /home/odoo/odoo15/addons/web/static/src/legacy/scss/primary_variables.scss
EOT
mkdir -p /etc/odoo15
EOF
lxc file push "$MIAOU_BASEDIR/templates/apps/odoo15/odoo-addon-install" "$CONTAINER/home/odoo/odoo15/odoo-addon-install"
lxc exec "$CONTAINER" -- bash <<EOF
chown odoo:odoo /home/odoo/odoo15/odoo-addon-install
chmod 740 /home/odoo/odoo15/odoo-addon-install
echo "new script <odoo-addon-install> added!"
EOF
}
function compute_bgcolor_target() {
target=$(yq '.target' "$EXPANDED_CONF")
case "$target" in
dev) builtin echo "#17a2b8" ;;
beta) builtin echo "#79A70A" ;;
prod) builtin echo "#7C7BAD" ;;
*) echoerr "unknown target <$target>" && exit 10 ;;
esac
}
### MAIN
. "$MIAOU_BASEDIR/lib/init.sh"
arg1_required "$@"
readonly CONTAINER="$1"
BACKGROUND_COLOR=$(compute_bgcolor_target)
readonly BACKGROUND_COLOR
check || (
install
check
)