second commit
This commit is contained in:
Executable
+180
@@ -0,0 +1,180 @@
|
||||
#!/bin/bash
|
||||
|
||||
function check_database_exists() {
|
||||
db-psql list | grep -q "$longname"
|
||||
}
|
||||
|
||||
function check_port_used() {
|
||||
# shellcheck disable=SC2034
|
||||
usedport=$(lxc exec "$container" -- bash -c "grep xmlrpc_port /etc/odoo12/$shortname.conf | cut -d' ' -f3")
|
||||
[[ "$usedport" == "$port" ]]
|
||||
}
|
||||
|
||||
function check_service_running() {
|
||||
lxc exec "$container" -- bash -c "systemctl is-active --quiet ${longname}.service"
|
||||
}
|
||||
|
||||
function _read() {
|
||||
disable_trace
|
||||
check_database_exists
|
||||
check_container "$container"
|
||||
check_port_used
|
||||
check_service_running
|
||||
enable_trace
|
||||
return 0
|
||||
}
|
||||
|
||||
function _create() {
|
||||
|
||||
echo "creating templates ... "
|
||||
mkdir -p "$MIAOU_CONFIGDIR/apps/odoo12"
|
||||
|
||||
longport=$((port + 1000))
|
||||
APP_PORT=$port LONG_PORT=$longport APP_NAME=$shortname tera -e -t "$MIAOU_DIR/templates/apps/odoo12/odoo.conf.j2" -o "$MIAOU_CONFIGDIR/apps/odoo12/$shortname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null
|
||||
APP_NAME=$shortname tera -t "$MIAOU_DIR/templates/apps/odoo12/odoo.service.j2" --env-only -o "$MIAOU_CONFIGDIR/apps/odoo12/$longname.service" >/dev/null
|
||||
echo "creating templates ... OK"
|
||||
|
||||
echo "copying files over container <$container> ... "
|
||||
lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/odoo12/$shortname.conf" "$container/etc/odoo12/$shortname.conf"
|
||||
lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/odoo12/$longname.service" "$container/etc/systemd/system/$longname.service"
|
||||
echo "copying files over container <$container> ... OK"
|
||||
|
||||
if ! (db-psql list | grep -q "$longname"); then
|
||||
echo "create empty database <$longname> ... "
|
||||
db-psql create "$longname"
|
||||
echo "create empty database <$longname> ... OK"
|
||||
|
||||
credential_username=$(load_yaml_from_expanded credential.username)
|
||||
credential_password=$(load_yaml_from_expanded credential.password)
|
||||
cat <<EOF | lxc_exec "$container"
|
||||
set -Eeuo pipefail
|
||||
echo reloading systemd
|
||||
systemctl daemon-reload
|
||||
systemctl stop $longname
|
||||
|
||||
echo initialize database...
|
||||
su odoo -c "/home/odoo/venv/bin/python3 /home/odoo/odoo12/odoo-bin -c /etc/odoo12/$shortname.conf -i base --without-demo=all --stop-after-init"
|
||||
echo initialize database OK
|
||||
|
||||
echo install default modules ...
|
||||
su odoo -c "/home/odoo/venv/bin/python3 /home/odoo/odoo12/odoo-bin -c /etc/odoo12/$shortname.conf -i account,contacts,l10n_fr,account,sale,point_of_sale -d $longname --worker=0 --stop-after-init"
|
||||
echo default modules OK
|
||||
|
||||
chmod u+w -R "/home/odoo/data-$shortname"
|
||||
|
||||
echo "TODO: change administrator password, default credential applied!"
|
||||
echo "UPDATE res_users SET login='$credential_username', password='$credential_password' WHERE id=2" | PGPASSWORD=$longname psql -U $longname -h ct1.lxd
|
||||
EOF
|
||||
else
|
||||
echo "database already exists!"
|
||||
fi
|
||||
|
||||
echo "initialize odoo $shortname $longname ..."
|
||||
cat <<EOF | lxc_exec "$container"
|
||||
set -Eeuo pipefail
|
||||
echo reloading systemd
|
||||
systemctl daemon-reload
|
||||
|
||||
if ! systemctl is-active --quiet $longname; then
|
||||
echo start service $longname
|
||||
systemctl start $longname
|
||||
systemctl is-active --quiet $longname
|
||||
systemctl enable $longname
|
||||
else
|
||||
echo service $longname already started!
|
||||
fi
|
||||
EOF
|
||||
echo "initialize odoo $shortname $longname ... OK"
|
||||
}
|
||||
|
||||
function _update() {
|
||||
echo "TODO: update"
|
||||
}
|
||||
|
||||
function _delete() {
|
||||
echo "TODO: delete"
|
||||
}
|
||||
|
||||
function usage() {
|
||||
echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME"
|
||||
exit 2
|
||||
}
|
||||
|
||||
### MAIN
|
||||
|
||||
# init_strict
|
||||
|
||||
COMMAND_NAME=$(basename "$0")
|
||||
|
||||
# read the options
|
||||
|
||||
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
|
||||
# shellcheck disable=SC2181
|
||||
[[ "$?" -eq 0 ]] || usage
|
||||
eval set -- "$TEMP"
|
||||
|
||||
action="unset"
|
||||
port="unset"
|
||||
container="unset"
|
||||
shortname="unset"
|
||||
longname="unset"
|
||||
|
||||
# extract options and their arguments into variables.
|
||||
while true; do
|
||||
case "$1" in
|
||||
--port)
|
||||
port=$2
|
||||
shift 2
|
||||
;;
|
||||
--fqdn)
|
||||
shift 2
|
||||
;;
|
||||
--container)
|
||||
container=$2
|
||||
shift 2
|
||||
;;
|
||||
--name)
|
||||
shortname=$2
|
||||
longname="odoo12-$shortname"
|
||||
shift 2
|
||||
;;
|
||||
-c)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_create"
|
||||
shift 1
|
||||
;;
|
||||
-r)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_read"
|
||||
shift 1
|
||||
;;
|
||||
-u)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_update"
|
||||
shift 1
|
||||
;;
|
||||
-d)
|
||||
[[ "$action" == "unset" ]] || usage
|
||||
action="_delete"
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Internal error!"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[
|
||||
"$action" != unset &&
|
||||
"$port" != unset &&
|
||||
"$container" != unset &&
|
||||
"$shortname" != unset ]] || usage
|
||||
|
||||
. "$MIAOU_BASEDIR/lib/init.sh"
|
||||
|
||||
$action
|
||||
Executable
+158
@@ -0,0 +1,158 @@
|
||||
#!/bin/bash
|
||||
|
||||
readonly EXPANDED_CONF="$MIAOU_CONFIGDIR/miaou.expanded.yaml"
|
||||
readonly WKHTML_VERSION="0.12.6-1"
|
||||
readonly WKHTML_RELEASE="$WKHTML_VERSION.buster_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" /home/odoo/odoo12/addons/web/static/src/scss/primary_variables.scss) || return 13
|
||||
return 0
|
||||
}
|
||||
|
||||
function check_wkhtmltox() {
|
||||
(lxc exec "$CONTAINER" -- dpkg -l | grep -s wkhtmltox | grep -qs $WKHTML_VERSION) || return 1
|
||||
}
|
||||
|
||||
function check_python() {
|
||||
(lxc exec "$CONTAINER" -- test -d /opt/Python-3.7.13) || return 1
|
||||
}
|
||||
|
||||
function check_venv() {
|
||||
(lxc exec "$CONTAINER" -- test -d /home/odoo/venv) || return 1
|
||||
}
|
||||
|
||||
function check_favicon() {
|
||||
lxc exec "$CONTAINER" -- test -L /home/odoo/odoo12/addons/web/static/src/img/favicon.ico
|
||||
}
|
||||
|
||||
function check_file_odoo-addon-install() {
|
||||
(lxc exec "$CONTAINER" -- test -f /home/odoo/odoo12/odoo12-addon-install) || return 23
|
||||
}
|
||||
|
||||
function check() {
|
||||
PREFIX="recipe:odoo12:check"
|
||||
check_wkhtmltox || return 10
|
||||
check_python || return 11
|
||||
check_user_odoo || return 12
|
||||
check_target_bgcolor || return 13
|
||||
check_venv || return 14
|
||||
check_favicon || return 15
|
||||
check_file_odoo-addon-install || return 23
|
||||
|
||||
echo "container <$CONTAINER> approved successfully!"
|
||||
return 0
|
||||
}
|
||||
|
||||
function install() {
|
||||
PREFIX="recipe:odoo12:install"
|
||||
: $PREFIX
|
||||
|
||||
launch_container "$CONTAINER"
|
||||
echo "initializing Odoo12 ... "
|
||||
|
||||
lxc exec "$CONTAINER" -- bash <<EOF
|
||||
set -Eeuo pipefail
|
||||
echo "installing odoo12..."
|
||||
apt-get update && apt-get dist-upgrade -y
|
||||
|
||||
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 [[ ! -d /opt/Python-3.7.13 ]]; then
|
||||
echo "installing Python-3.7.13..."
|
||||
apt-get install -y zlib1g-dev python3-pip python3-venv xz-utils build-essential libssl-dev python3-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libpq-dev libffi-dev postgresql-client
|
||||
wget -O- https://www.python.org/ftp/python/3.7.13/Python-3.7.13.tar.xz | tar -xJ -C /opt
|
||||
chown -R root:root /opt/Python-3.7.13
|
||||
cd /opt/Python-3.7.13
|
||||
./configure --enable-optimizations --enable-shared
|
||||
make -j8 altinstall
|
||||
ldconfig /opt/Python3.7.13
|
||||
echo "Python-3.7.13...OK"
|
||||
else
|
||||
echo "Python-3.7.13 already installed!"
|
||||
fi
|
||||
|
||||
if ! id -u odoo &>/dev/null; then
|
||||
echo "creating system user <odoo>"
|
||||
useradd -rms /bin/bash odoo
|
||||
else
|
||||
echo "user <odoo> already exists!"
|
||||
fi
|
||||
|
||||
cat <<EOT | su - odoo
|
||||
if [[ ! -d odoo12 ]]; then
|
||||
echo "git odoo12 from remote"
|
||||
git clone https://github.com/odoo/odoo.git --depth 1 --branch 12.0 odoo12
|
||||
else
|
||||
echo "git odoo12 already downloaded!"
|
||||
fi
|
||||
if [[ ! -d venv ]]; then
|
||||
echo "installing Python-3.7 virtual env (venv)"
|
||||
python3.7 -m venv venv
|
||||
source venv/bin/activate
|
||||
python -m pip install --upgrade pip
|
||||
pip install wheel
|
||||
pip install -r odoo12/requirements.txt
|
||||
else
|
||||
echo "venv (Python-3.7) already installed!"
|
||||
fi
|
||||
|
||||
echo "community-color change to $BACKGROUND_COLOR"
|
||||
/opt/debian-bash/tools/append_or_replace "^.*o-community-color:.*" "\\\\\\\$o-community-color: $BACKGROUND_COLOR;" /home/odoo/odoo12/addons/web/static/src/scss/primary_variables.scss
|
||||
|
||||
EOT
|
||||
mkdir -p /etc/odoo12
|
||||
EOF
|
||||
|
||||
lxc file push "$MIAOU_BASEDIR/templates/apps/odoo12/odoo12-addon-install" "$CONTAINER/home/odoo/odoo12/odoo12-addon-install"
|
||||
lxc exec "$CONTAINER" -- bash <<EOF
|
||||
chown odoo:odoo /home/odoo/odoo12/odoo12-addon-install
|
||||
chmod 740 /home/odoo/odoo12/odoo12-addon-install
|
||||
echo "new script <odoo12-addon-install> added!"
|
||||
EOF
|
||||
|
||||
echo "push various target-related favicons..."
|
||||
for favicon in "$MIAOU_BASEDIR"/templates/apps/odoo12/favicon/*.ico; do
|
||||
lxc file push --uid 0 --gid 0 "$favicon" "$CONTAINER/home/odoo/odoo12/addons/web/static/src/img/"
|
||||
done
|
||||
echo "OK"
|
||||
|
||||
echo "adjust symbolic link according to target=<$TARGET>"
|
||||
lxc exec "$CONTAINER" -- rm -f /home/odoo/odoo12/addons/web/static/src/img/favicon.ico
|
||||
lxc exec "$CONTAINER" -- ln -s /home/odoo/odoo12/addons/web/static/src/img/favicon-"$TARGET".ico /home/odoo/odoo12/addons/web/static/src/img/favicon.ico
|
||||
echo "OK"
|
||||
}
|
||||
|
||||
function compute_bgcolor_target() {
|
||||
case "$TARGET" in
|
||||
dev) echo "#17a2b8" ;;
|
||||
beta) echo "#79A70A" ;;
|
||||
prod) echo "#7C7BAD" ;;
|
||||
*) echoerr "unknown target <$TARGET>" && exit 10 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
### MAIN
|
||||
|
||||
. "$MIAOU_BASEDIR/lib/init.sh"
|
||||
arg1_required "$@"
|
||||
readonly CONTAINER="$1"
|
||||
TARGET=$(yq '.target' "$EXPANDED_CONF")
|
||||
readonly TARGET
|
||||
BACKGROUND_COLOR=$(compute_bgcolor_target)
|
||||
readonly BACKGROUND_COLOR
|
||||
|
||||
check || (
|
||||
install
|
||||
check
|
||||
)
|
||||
Reference in New Issue
Block a user