14.0.20220510-debian-11-r0 release

This commit is contained in:
Bitnami Bot
2022-06-06 12:23:17 +00:00
committed by Bitnami Containers
parent 2babf36522
commit 5107b4471d
33 changed files with 3799 additions and 1 deletions

View File

@@ -0,0 +1,337 @@
#!/bin/bash
#
# Bitnami Odoo library
# shellcheck disable=SC1091
# Load generic libraries
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/libnet.sh
. /opt/bitnami/scripts/libfile.sh
. /opt/bitnami/scripts/libvalidations.sh
. /opt/bitnami/scripts/libpersistence.sh
. /opt/bitnami/scripts/libservice.sh
# Load database library
if [[ -f /opt/bitnami/scripts/libpostgresqlclient.sh ]]; then
. /opt/bitnami/scripts/libpostgresqlclient.sh
elif [[ -f /opt/bitnami/scripts/libpostgresql.sh ]]; then
. /opt/bitnami/scripts/libpostgresql.sh
fi
########################
# Validate settings in ODOO_* env vars
# Globals:
# ODOO_*
# Arguments:
# None
# Returns:
# 0 if the validation succeeded, 1 otherwise
#########################
odoo_validate() {
debug "Validating settings in ODOO_* environment variables..."
local error_code=0
# Auxiliary functions
print_validation_error() {
error "$1"
error_code=1
}
check_empty_value() {
if is_empty_value "${!1}"; then
print_validation_error "${1} must be set"
fi
}
check_yes_no_value() {
if ! is_yes_no_value "${!1}" && ! is_true_false_value "${!1}"; then
print_validation_error "The allowed values for ${1} are: yes no"
fi
}
check_multi_value() {
if [[ " ${2} " != *" ${!1} "* ]]; then
print_validation_error "The allowed values for ${1} are: ${2}"
fi
}
check_resolved_hostname() {
if ! is_hostname_resolved "$1"; then
warn "Hostname ${1} could not be resolved, this could lead to connection issues"
fi
}
check_valid_port() {
local port_var="${1:?missing port variable}"
local err
if ! err="$(validate_port "${!port_var}")"; then
print_validation_error "An invalid port was specified in the environment variable ${port_var}: ${err}."
fi
}
# Validate user inputs
check_yes_no_value "ODOO_SKIP_BOOTSTRAP"
check_yes_no_value "ODOO_SKIP_MODULES_UPDATE"
check_yes_no_value "ODOO_LOAD_DEMO_DATA"
check_valid_port "ODOO_PORT_NUMBER"
check_valid_port "ODOO_LONGPOLLING_PORT_NUMBER"
! is_empty_value "$ODOO_DATABASE_HOST" && check_resolved_hostname "$ODOO_DATABASE_HOST"
! is_empty_value "$ODOO_DATABASE_PORT_NUMBER" && check_valid_port "ODOO_DATABASE_PORT_NUMBER"
[[ -n "${WITHOUT_DEMO:-}" ]] && warn "The WITHOUT_DEMO environment variable has been deprecated in favor of ODOO_LOAD_DEMO_DATA=yes. Support for it may be removed in a future release."
# Validate credentials
if is_boolean_yes "${ALLOW_EMPTY_PASSWORD:-}"; then
warn "You set the environment variable ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD:-}. For safety reasons, do not use this flag in a production environment."
else
for empty_env_var in "ODOO_DATABASE_PASSWORD" "ODOO_PASSWORD"; do
is_empty_value "${!empty_env_var}" && print_validation_error "The ${empty_env_var} environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow a blank password. This is only recommended for development environments."
done
fi
# Validate SMTP credentials
if ! is_empty_value "$ODOO_SMTP_HOST"; then
for empty_env_var in "ODOO_SMTP_USER" "ODOO_SMTP_PASSWORD"; do
is_empty_value "${!empty_env_var}" && warn "The ${empty_env_var} environment variable is empty or not set."
done
is_empty_value "$ODOO_SMTP_PORT_NUMBER" && print_validation_error "The ODOO_SMTP_PORT_NUMBER environment variable is empty or not set."
! is_empty_value "$ODOO_SMTP_PORT_NUMBER" && check_valid_port "ODOO_SMTP_PORT_NUMBER"
! is_empty_value "$ODOO_SMTP_PROTOCOL" && check_multi_value "ODOO_SMTP_PROTOCOL" "ssl tls"
fi
return "$error_code"
}
########################
# Ensure Odoo is initialized
# Globals:
# ODOO_*
# Arguments:
# None
# Returns:
# None
#########################
odoo_initialize() {
# Check if Odoo has already been initialized and persisted in a previous run
local -r app_name="odoo"
if ! is_app_initialized "$app_name"; then
local -a db_execute_args=("$ODOO_DATABASE_HOST" "$ODOO_DATABASE_PORT_NUMBER" "$ODOO_DATABASE_NAME" "$ODOO_DATABASE_USER" "$ODOO_DATABASE_PASSWORD")
# Ensure Odoo persisted directories exist (i.e. when a volume has been mounted to /bitnami)
info "Ensuring Odoo directories exist"
ensure_dir_exists "$ODOO_VOLUME_DIR"
# Use daemon:root ownership for compatibility when running as a non-root user
am_i_root && configure_permissions_ownership "$ODOO_VOLUME_DIR" -d "775" -f "664" -u "$ODOO_DAEMON_USER" -g "root"
info "Trying to connect to the database server"
odoo_wait_for_postgresql_connection "${db_execute_args[@]}"
# Odoo requires the database to be owned by the same database user used by the application
# If not, the DB will simply not appear in the list of DBs and Odoo will force you to create a new one
# Refer to function 'list_dbs' in 'service/db.py'
info "Validating database owner"
local db_owner_result
db_owner_result="$(postgresql_remote_execute_print_output "${db_execute_args[@]}" <<< "SELECT u.usename FROM pg_database d JOIN pg_user u ON (d.datdba = u.usesysid) WHERE d.datname = '${ODOO_DATABASE_NAME}' AND u.usename = '${ODOO_DATABASE_USER}';")"
if [[ "$db_owner_result" = *"(0 rows)"* ]]; then
error "The database '${ODOO_DATABASE_NAME}' is not owned by database user '${ODOO_DATABASE_USER}'. This is required for the Odoo application to be able to use this database."
return 1
fi
info "Generating configuration file"
local template_dir="${BITNAMI_ROOT_DIR}/scripts/odoo/bitnami-templates"
render-template "${template_dir}/odoo.conf.tpl" > "$ODOO_CONF_FILE"
if ! is_empty_value "$ODOO_SMTP_HOST"; then
info "Configuring SMTP"
odoo_conf_set "smtp_server" "$ODOO_SMTP_HOST"
odoo_conf_set "smtp_port" "$ODOO_SMTP_PORT_NUMBER"
[[ "$ODOO_SMTP_PROTOCOL" = "ssl" || "$ODOO_SMTP_PROTOCOL" = "tls" ]] && odoo_conf_set "smtp_ssl" "True"
odoo_conf_set "smtp_user" "$ODOO_SMTP_USER"
odoo_conf_set "smtp_password" "$ODOO_SMTP_PASSWORD"
fi
if ! is_boolean_yes "$ODOO_SKIP_BOOTSTRAP"; then
info "Installing modules"
local -a init_args=("--init=all")
# Disable demo data import if specified by the user
if [[ -n "${WITHOUT_DEMO:-}" ]]; then
# Support for legacy WITHOUT_DEMO environment variable, this may be removed in the future
init_args+=("--without-demo=${WITHOUT_DEMO}")
elif ! is_boolean_yes "$ODOO_LOAD_DEMO_DATA"; then
init_args+=("--without-demo=all")
fi
odoo_execute "${init_args[@]}"
info "Updating admin user credentials"
postgresql_remote_execute "${db_execute_args[@]}" <<< "UPDATE res_users SET login = '${ODOO_EMAIL}', password = '${ODOO_PASSWORD}' WHERE login = 'admin'"
else
info "An already initialized Odoo database was provided, configuration will be skipped"
# Odoo stores a cache of the full path to cached .css/.js files in the filesystem
# However when reinstalling with ODOO_SKIP_BOOTSTRAP, no filesystem is mounted
# So we need to clear the assets or if none of the .css/.js will load properly
info "Clearing assets cache from the database"
postgresql_remote_execute "${db_execute_args[@]}" <<< "DELETE FROM ir_attachment WHERE url LIKE '/web/content/%';"
if ! is_boolean_yes "$ODOO_SKIP_MODULES_UPDATE"; then
info "Updating modules"
odoo_execute --update=all
fi
fi
info "Persisting Odoo installation"
persist_app "$app_name" "$ODOO_DATA_TO_PERSIST"
else
# Fix to make upgrades from old images work
# Before, we were persisting 'odoo-server.conf' dir instead of 'conf/odoo.conf', causing errors when restoring persisted data
# TODO: Remove this block in a future release
if [[ ! -e "${ODOO_VOLUME_DIR}/conf" && -e "${ODOO_VOLUME_DIR}/odoo-server.conf" ]]; then
warn "Detected legacy configuration file ${ODOO_VOLUME_DIR}/odoo-server.conf in volume"
warn "Creating ${ODOO_VOLUME_DIR}/conf/odoo.conf symlink pointing to ${ODOO_VOLUME_DIR}/odoo-server.conf"
mkdir -p "${ODOO_VOLUME_DIR}/conf"
ln -s "${ODOO_VOLUME_DIR}/odoo-server.conf" "${ODOO_VOLUME_DIR}/conf/odoo.conf"
fi
info "Restoring persisted Odoo installation"
restore_persisted_app "$app_name" "$ODOO_DATA_TO_PERSIST"
info "Trying to connect to the database server"
local db_host db_port db_name db_user db_pass
db_host="$(odoo_conf_get "db_host")"
db_port="$(odoo_conf_get "db_port")"
db_name="$(odoo_conf_get "db_name")"
db_user="$(odoo_conf_get "db_user")"
db_pass="$(odoo_conf_get "db_password")"
odoo_wait_for_postgresql_connection "$db_host" "$db_port" "$db_name" "$db_user" "$db_pass"
if ! is_boolean_yes "$ODOO_SKIP_MODULES_UPDATE"; then
info "Updating modules"
odoo_execute --update=all
fi
fi
# Avoid exit code of previous commands to affect the result of this function
true
}
########################
# Add or modify an entry in the Odoo configuration file
# Globals:
# ODOO_*
# Arguments:
# $1 - Variable name
# $2 - Value to assign to the variable
# Returns:
# None
#########################
odoo_conf_set() {
local -r key="${1:?key missing}"
local -r value="${2:?value missing}"
debug "Setting ${key} to '${value}' in Odoo configuration"
# Sanitize key (sed does not support fixed string substitutions)
local sanitized_pattern
sanitized_pattern="^\s*(;\s*)?$(sed 's/[]\[^$.*/]/\\&/g' <<< "$key")\s*=.*"
local entry="${key} = ${value}"
# Check if the configuration exists in the file
if grep -q -E "$sanitized_pattern" "$ODOO_CONF_FILE"; then
# It exists, so replace the line
replace_in_file "$ODOO_CONF_FILE" "$sanitized_pattern" "$entry"
else
# It doesn't exist, so append to the end of the file
cat >> "$ODOO_CONF_FILE" <<< "$entry"
fi
}
########################
# Get an entry from the Odoo configuration file
# Globals:
# ODOO_*
# Arguments:
# $1 - Variable name
# Returns:
# None
#########################
odoo_conf_get() {
local -r key="${1:?key missing}"
debug "Getting ${key} from Odoo configuration"
# Sanitize key (sed does not support fixed string substitutions)
local sanitized_pattern
sanitized_pattern="^\s*(;\s*)?$(sed 's/[]\[^$.*/]/\\&/g' <<< "$key")\s*=(.*)"
grep -E "$sanitized_pattern" "$ODOO_CONF_FILE" | sed -E "s|${sanitized_pattern}|\2|" | tr -d "\"' "
}
########################
# Wait until the database is accessible with the currently-known credentials
# Globals:
# *
# Arguments:
# $1 - database host
# $2 - database port
# $3 - database name
# $4 - database username
# $5 - database user password (optional)
# Returns:
# true if the database connection succeeded, false otherwise
#########################
odoo_wait_for_postgresql_connection() {
local -r db_host="${1:?missing database host}"
local -r db_port="${2:?missing database port}"
local -r db_name="${3:?missing database name}"
local -r db_user="${4:?missing database user}"
local -r db_pass="${5:-}"
check_postgresql_connection() {
echo "SELECT 1" | postgresql_remote_execute "$db_host" "$db_port" "$db_name" "$db_user" "$db_pass"
}
if ! retry_while "check_postgresql_connection"; then
error "Could not connect to the database"
return 1
fi
}
########################
# Execute a command using the 'odoo' CLI
# Globals:
# ODOO_*
# Arguments:
# $1 - log file
# Returns:
# None
#########################
odoo_execute() {
# Define 'odoo' cmdline arguments
local -a cmd=("${ODOO_BIN_DIR}/odoo")
am_i_root && cmd=("gosu" "$ODOO_DAEMON_USER" "${cmd[@]}")
# Ensure the logfile is not populated with init info and no service is left running
debug_execute "${cmd[@]}" --config="$ODOO_CONF_FILE" --logfile= --pidfile= --stop-after-init "$@"
}
########################
# Check if Odoo is running
# Arguments:
# None
# Returns:
# Boolean
#########################
is_odoo_running() {
pid="$(get_pid_from_file "$ODOO_PID_FILE")"
if [[ -n "$pid" ]]; then
is_service_running "$pid"
else
false
fi
}
########################
# Check if Odoo is not running
# Arguments:
# None
# Returns:
# Boolean
#########################
is_odoo_not_running() {
! is_odoo_running
}
########################
# Stop Odoo
# Arguments:
# None
# Returns:
# None
#########################
odoo_stop() {
! is_odoo_running && return
stop_service_using_pid "$ODOO_PID_FILE"
}

View File

@@ -0,0 +1,417 @@
#!/bin/bash
#
# Bitnami PostgreSQL Client library
# shellcheck disable=SC1091
# Load Generic Libraries
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/libvalidations.sh
########################
# Validate settings in POSTGRESQL_CLIENT_* environment variables
# Globals:
# POSTGRESQL_CLIENT_*
# Arguments:
# None
# Returns:
# None
#########################
postgresql_client_validate() {
info "Validating settings in POSTGRESQL_CLIENT_* env vars"
local error_code=0
# Auxiliary functions
print_validation_error() {
error "$1"
error_code=1
}
empty_password_enabled_warn() {
warn "You set the environment variable ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD}. For safety reasons, do not use this flag in a production environment."
}
empty_password_error() {
print_validation_error "The $1 environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development."
}
# Only validate environment variables if any action needs to be performed
local -a database_names
read -r -a database_names <<< "$(tr ',;' ' ' <<< "$POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES")"
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" || "${#database_names[@]}" -gt 0 ]]; then
if is_boolean_yes "$ALLOW_EMPTY_PASSWORD"; then
empty_password_enabled_warn
else
if [[ -z "$POSTGRESQL_CLIENT_POSTGRES_PASSWORD" ]]; then
empty_password_error "POSTGRESQL_CLIENT_POSTGRES_PASSWORD"
fi
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" ]] && [[ -z "$POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD" ]]; then
empty_password_error "POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD"
fi
fi
fi
# When enabling extensions, the DB name must be provided
local -a extensions
read -r -a extensions <<< "$(tr ',;' ' ' <<< "$POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS")"
if [[ "${#database_names[@]}" -le 0 && "${#extensions[@]}" -gt 0 ]]; then
print_validation_error "POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS requires POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES to be set."
fi
return "$error_code"
}
########################
# Perform actions to a database
# Globals:
# POSTGRESQL_CLIENT_*
# Arguments:
# None
# Returns:
# None
#########################
postgresql_client_initialize() {
local -a database_names
read -r -a database_names <<< "$(tr ',;' ' ' <<< "$POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES")"
# Wait for the database to be accessible if any action needs to be performed
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" || "${#database_names[@]}" -gt 0 ]]; then
info "Trying to connect to the database server"
check_postgresql_connection() {
echo "SELECT 1" | postgresql_remote_execute "$POSTGRESQL_CLIENT_DATABASE_HOST" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER" "postgres" "$POSTGRESQL_CLIENT_POSTGRES_USER" "$POSTGRESQL_CLIENT_POSTGRES_PASSWORD"
}
if ! retry_while "check_postgresql_connection"; then
error "Could not connect to the database server"
return 1
fi
fi
# Ensure a database user exists in the server
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" ]]; then
info "Creating database user ${POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME}"
local -a args=("$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" "--host" "$POSTGRESQL_CLIENT_DATABASE_HOST" "--port" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER")
[[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD" ]] && args+=("-p" "$POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD")
postgresql_ensure_user_exists "${args[@]}"
fi
# Ensure a database exists in the server (and that the user has write privileges, if specified)
if [[ "${#database_names[@]}" -gt 0 ]]; then
local -a createdb_args extensions
read -r -a extensions <<< "$(tr ',;' ' ' <<< "$POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS")"
for database_name in "${database_names[@]}"; do
info "Creating database ${database_name}"
createdb_args=("$database_name" "--host" "$POSTGRESQL_CLIENT_DATABASE_HOST" "--port" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER")
[[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" ]] && createdb_args+=("-u" "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME")
postgresql_ensure_database_exists "${createdb_args[@]}"
# Ensure the list of extensions are enabled in the specified database
if [[ "${#extensions[@]}" -gt 0 ]]; then
for extension_to_create in "${extensions[@]}"; do
echo "CREATE EXTENSION IF NOT EXISTS ${extension_to_create}" | postgresql_remote_execute "$POSTGRESQL_CLIENT_DATABASE_HOST" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER" "$database_name" "$POSTGRESQL_CLIENT_POSTGRES_USER" "$POSTGRESQL_CLIENT_POSTGRES_PASSWORD"
done
fi
done
fi
# Execute a custom SQL script
if [[ -n "$POSTGRESQL_CLIENT_EXECUTE_SQL" ]]; then
info "Executing custom SQL script"
echo "$POSTGRESQL_CLIENT_EXECUTE_SQL" | postgresql_remote_execute "$POSTGRESQL_CLIENT_DATABASE_HOST" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER" "postgres" "$POSTGRESQL_CLIENT_POSTGRES_USER" "$POSTGRESQL_CLIENT_POSTGRES_PASSWORD"
fi
# Avoid exit code of previous commands to affect the result of this function
true
}
########################
# Return PostgreSQL major version
# Globals:
# POSTGRESQL_*
# Arguments:
# None
# Returns:
# String
#########################
postgresql_get_major_version() {
psql --version | grep -oE "[0-9]+\.[0-9]+" | grep -oE "^[0-9]+"
}
########################
# Gets an environment variable name based on the suffix
# Arguments:
# $1 - environment variable suffix
# Returns:
# environment variable name
#########################
get_env_var_value() {
local env_var_suffix="${1:?missing suffix}"
local env_var_name
for env_var_prefix in POSTGRESQL POSTGRESQL_CLIENT; do
env_var_name="${env_var_prefix}_${env_var_suffix}"
if [[ -n "${!env_var_name:-}" ]]; then
echo "${!env_var_name}"
break
fi
done
}
########################
# Execute an arbitrary query/queries against the running PostgreSQL service and print the output
# Stdin:
# Query/queries to execute
# Globals:
# BITNAMI_DEBUG
# POSTGRESQL_*
# Arguments:
# $1 - Database where to run the queries
# $2 - User to run queries
# $3 - Password
# $4 - Extra options (eg. -tA)
# Returns:
# None
#########################
postgresql_execute_print_output() {
local -r db="${1:-}"
local -r user="${2:-postgres}"
local -r pass="${3:-}"
local opts
read -r -a opts <<<"${@:4}"
local args=("-U" "$user" "-p" "${POSTGRESQL_PORT_NUMBER:-5432}")
[[ -n "$db" ]] && args+=("-d" "$db")
[[ "${#opts[@]}" -gt 0 ]] && args+=("${opts[@]}")
# Execute the Query/queries from stdin
PGPASSWORD=$pass psql "${args[@]}"
}
########################
# Execute an arbitrary query/queries against the running PostgreSQL service
# Stdin:
# Query/queries to execute
# Globals:
# BITNAMI_DEBUG
# POSTGRESQL_*
# Arguments:
# $1 - Database where to run the queries
# $2 - User to run queries
# $3 - Password
# $4 - Extra options (eg. -tA)
# Returns:
# None
#########################
postgresql_execute() {
if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then
"postgresql_execute_print_output" "$@"
elif [[ "${NO_ERRORS:-false}" = true ]]; then
"postgresql_execute_print_output" "$@" 2>/dev/null
else
"postgresql_execute_print_output" "$@" >/dev/null 2>&1
fi
}
########################
# Execute an arbitrary query/queries against a remote PostgreSQL service and print to stdout
# Stdin:
# Query/queries to execute
# Globals:
# BITNAMI_DEBUG
# DB_*
# Arguments:
# $1 - Remote PostgreSQL service hostname
# $2 - Remote PostgreSQL service port
# $3 - Database where to run the queries
# $4 - User to run queries
# $5 - Password
# $6 - Extra options (eg. -tA)
# Returns:
# None
postgresql_remote_execute_print_output() {
local -r hostname="${1:?hostname is required}"
local -r port="${2:?port is required}"
local -a args=("-h" "$hostname" "-p" "$port")
shift 2
"postgresql_execute_print_output" "$@" "${args[@]}"
}
########################
# Execute an arbitrary query/queries against a remote PostgreSQL service
# Stdin:
# Query/queries to execute
# Globals:
# BITNAMI_DEBUG
# DB_*
# Arguments:
# $1 - Remote PostgreSQL service hostname
# $2 - Remote PostgreSQL service port
# $3 - Database where to run the queries
# $4 - User to run queries
# $5 - Password
# $6 - Extra options (eg. -tA)
# Returns:
# None
postgresql_remote_execute() {
if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then
"postgresql_remote_execute_print_output" "$@"
elif [[ "${NO_ERRORS:-false}" = true ]]; then
"postgresql_remote_execute_print_output" "$@" 2>/dev/null
else
"postgresql_remote_execute_print_output" "$@" >/dev/null 2>&1
fi
}
########################
# Optionally create the given database user
# Flags:
# -p|--password - database password
# --host - database host
# --port - database port
# Arguments:
# $1 - user
# Returns:
# None
#########################
postgresql_ensure_user_exists() {
local -r user="${1:?user is missing}"
local password=""
# For accessing an external database
local db_host=""
local db_port=""
# Validate arguments
shift 1
while [ "$#" -gt 0 ]; do
case "$1" in
-p | --password)
shift
password="${1:?missing password}"
;;
--host)
shift
db_host="${1:?missing database host}"
;;
--port)
shift
db_port="${1:?missing database port}"
;;
*)
echo "Invalid command line flag $1" >&2
return 1
;;
esac
shift
done
local -a postgresql_execute_cmd=("postgresql_execute")
[[ -n "$db_host" && -n "$db_port" ]] && postgresql_execute_cmd=("postgresql_remote_execute" "$db_host" "$db_port")
local -a postgresql_execute_flags=("postgres" "$(get_env_var_value POSTGRES_USER)" "$(get_env_var_value POSTGRES_PASSWORD)")
"${postgresql_execute_cmd[@]}" "${postgresql_execute_flags[@]}" <<EOF
DO
\$do\$
BEGIN
IF NOT EXISTS (
SELECT FROM pg_catalog.pg_roles WHERE rolname = '${user}'
) THEN
CREATE ROLE "${user}" LOGIN PASSWORD '${password}';
END IF;
END
\$do\$;
EOF
}
########################
# Ensure a user has all privileges to access a database
# Arguments:
# $1 - database name
# $2 - database user
# $3 - database host (optional)
# $4 - database port (optional)
# Returns:
# None
#########################
postgresql_ensure_user_has_database_privileges() {
local -r user="${1:?user is required}"
local -r database="${2:?db is required}"
local -r db_host="${3:-}"
local -r db_port="${4:-}"
local -a postgresql_execute_cmd=("postgresql_execute")
[[ -n "$db_host" && -n "$db_port" ]] && postgresql_execute_cmd=("postgresql_remote_execute" "$db_host" "$db_port")
local -a postgresql_execute_flags=("postgres" "$(get_env_var_value POSTGRES_USER)" "$(get_env_var_value POSTGRES_PASSWORD)")
debug "Providing privileges to username ${user} on database ${database}"
"${postgresql_execute_cmd[@]}" "${postgresql_execute_flags[@]}" <<EOF
GRANT ALL PRIVILEGES ON DATABASE "${database}" TO "${user}";
ALTER DATABASE "${database}" OWNER TO "${user}";
EOF
}
########################
# Optionally create the given database, and then optionally give a user
# full privileges on the database.
# Flags:
# -u|--user - database user
# --host - database host
# --port - database port
# Arguments:
# $1 - database name
# Returns:
# None
#########################
postgresql_ensure_database_exists() {
local -r database="${1:?database is missing}"
local user=""
# For accessing an external database
local db_host=""
local db_port=""
# Validate arguments
shift 1
while [ "$#" -gt 0 ]; do
case "$1" in
-u | --user)
shift
user="${1:?missing database user}"
;;
--host)
shift
db_host="${1:?missing database host}"
;;
--port)
shift
db_port="${1:?missing database port}"
;;
*)
echo "Invalid command line flag $1" >&2
return 1
;;
esac
shift
done
local -a postgresql_execute_cmd=("postgresql_execute")
[[ -n "$db_host" && -n "$db_port" ]] && postgresql_execute_cmd=("postgresql_remote_execute" "$db_host" "$db_port")
local -a postgresql_execute_flags=("postgres" "$(get_env_var_value POSTGRES_USER)" "$(get_env_var_value POSTGRES_PASSWORD)")
"${postgresql_execute_cmd[@]}" "${postgresql_execute_flags[@]}" <<EOF
SELECT 'CREATE DATABASE "${database}"'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${database}')\gexec
EOF
if [[ -n "$user" ]]; then
local -a grant_flags=("$user" "$database")
[[ -n "$db_host" ]] && grant_flags+=("$db_host")
[[ -n "$db_port" ]] && grant_flags+=("$db_port")
postgresql_ensure_user_has_database_privileges "${grant_flags[@]}"
fi
}
########################
# Retrieves the WAL directory in use by PostgreSQL / to use if not initialized yet
# Globals:
# REPMGR_*
# Arguments:
# None
# Returns:
# the path to the WAL directory, or empty if not set
#########################
postgresql_get_waldir() {
if [[ -L "${POSTGRESQL_DATA_DIR}/pg_wal" && -d "${POSTGRESQL_DATA_DIR}/pg_wal" ]]; then
readlink -f "${POSTGRESQL_DATA_DIR}/pg_wal"
else
# Uninitialized - using value from $POSTGRESQL_INITDB_WAL_DIR if set
echo "$POSTGRESQL_INITDB_WAL_DIR"
fi
}

View File

@@ -0,0 +1,127 @@
#!/bin/bash
#
# Environment configuration for odoo
# The values for all environment variables will be set in the below order of precedence
# 1. Custom environment variables defined below after Bitnami defaults
# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR
# 3. Environment variables overridden via external files using *_FILE variables (see below)
# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata)
# Load logging library
# shellcheck disable=SC1090,SC1091
. /opt/bitnami/scripts/liblog.sh
export BITNAMI_ROOT_DIR="/opt/bitnami"
export BITNAMI_VOLUME_DIR="/bitnami"
# Logging configuration
export MODULE="${MODULE:-odoo}"
export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}"
# By setting an environment variable matching *_FILE to a file path, the prefixed environment
# variable will be overridden with the value specified in that file
odoo_env_vars=(
ODOO_DATA_TO_PERSIST
ODOO_PORT_NUMBER
ODOO_LONGPOLLING_PORT_NUMBER
ODOO_SKIP_BOOTSTRAP
ODOO_SKIP_MODULES_UPDATE
ODOO_LOAD_DEMO_DATA
ODOO_EMAIL
ODOO_PASSWORD
ODOO_SMTP_HOST
ODOO_SMTP_PORT_NUMBER
ODOO_SMTP_USER
ODOO_SMTP_PASSWORD
ODOO_SMTP_PROTOCOL
ODOO_DATABASE_HOST
ODOO_DATABASE_PORT_NUMBER
ODOO_DATABASE_NAME
ODOO_DATABASE_USER
ODOO_DATABASE_PASSWORD
SMTP_HOST
SMTP_PORT
ODOO_SMTP_PORT
SMTP_USER
SMTP_PASSWORD
SMTP_PROTOCOL
POSTGRESQL_HOST
POSTGRESQL_PORT_NUMBER
POSTGRESQL_DATABASE_NAME
POSTGRESQL_DATABASE_USER
POSTGRESQL_DATABASE_USERNAME
POSTGRESQL_DATABASE_PASSWORD
)
for env_var in "${odoo_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
if [[ -n "${!file_env_var:-}" ]]; then
if [[ -r "${!file_env_var:-}" ]]; then
export "${env_var}=$(< "${!file_env_var}")"
unset "${file_env_var}"
else
warn "Skipping export of '${env_var}'. '${!file_env_var:-}' is not readable."
fi
fi
done
unset odoo_env_vars
# Paths
export ODOO_BASE_DIR="${BITNAMI_ROOT_DIR}/odoo"
export ODOO_BIN_DIR="${ODOO_BASE_DIR}/bin"
export ODOO_CONF_DIR="${ODOO_BASE_DIR}/conf"
export ODOO_CONF_FILE="${ODOO_CONF_DIR}/odoo.conf"
export ODOO_DATA_DIR="${ODOO_BASE_DIR}/data"
export ODOO_ADDONS_DIR="${ODOO_BASE_DIR}/addons"
export ODOO_TMP_DIR="${ODOO_BASE_DIR}/tmp"
export ODOO_PID_FILE="${ODOO_TMP_DIR}/odoo.pid"
export ODOO_LOGS_DIR="${ODOO_BASE_DIR}/log"
export ODOO_LOG_FILE="${ODOO_LOGS_DIR}/odoo-server.log"
# Odoo persistence configuration
export ODOO_VOLUME_DIR="${BITNAMI_VOLUME_DIR}/odoo"
export ODOO_DATA_TO_PERSIST="${ODOO_DATA_TO_PERSIST:-${ODOO_ADDONS_DIR} ${ODOO_CONF_DIR} ${ODOO_DATA_DIR}}"
# System users (when running with a privileged user)
export ODOO_DAEMON_USER="odoo"
export ODOO_DAEMON_GROUP="odoo"
# Odoo configuration
export ODOO_PORT_NUMBER="${ODOO_PORT_NUMBER:-8069}" # only used during the first initialization
export ODOO_LONGPOLLING_PORT_NUMBER="${ODOO_LONGPOLLING_PORT_NUMBER:-8072}" # only used during the first initialization
export ODOO_SKIP_BOOTSTRAP="${ODOO_SKIP_BOOTSTRAP:-no}" # only used during the first initialization
export ODOO_SKIP_MODULES_UPDATE="${ODOO_SKIP_MODULES_UPDATE:-no}" # only used during the first initialization
export ODOO_LOAD_DEMO_DATA="${ODOO_LOAD_DEMO_DATA:-no}" # only used during the first initialization
# Odoo credentials
export ODOO_EMAIL="${ODOO_EMAIL:-user@example.com}" # only used during the first initialization
export ODOO_PASSWORD="${ODOO_PASSWORD:-bitnami}" # only used during the first initialization
# Odoo SMTP credentials
ODOO_SMTP_HOST="${ODOO_SMTP_HOST:-"${SMTP_HOST:-}"}"
export ODOO_SMTP_HOST="${ODOO_SMTP_HOST:-}" # only used during the first initialization
ODOO_SMTP_PORT_NUMBER="${ODOO_SMTP_PORT_NUMBER:-"${SMTP_PORT:-}"}"
ODOO_SMTP_PORT_NUMBER="${ODOO_SMTP_PORT_NUMBER:-"${ODOO_SMTP_PORT:-}"}"
export ODOO_SMTP_PORT_NUMBER="${ODOO_SMTP_PORT_NUMBER:-}" # only used during the first initialization
ODOO_SMTP_USER="${ODOO_SMTP_USER:-"${SMTP_USER:-}"}"
export ODOO_SMTP_USER="${ODOO_SMTP_USER:-}" # only used during the first initialization
ODOO_SMTP_PASSWORD="${ODOO_SMTP_PASSWORD:-"${SMTP_PASSWORD:-}"}"
export ODOO_SMTP_PASSWORD="${ODOO_SMTP_PASSWORD:-}" # only used during the first initialization
ODOO_SMTP_PROTOCOL="${ODOO_SMTP_PROTOCOL:-"${SMTP_PROTOCOL:-}"}"
export ODOO_SMTP_PROTOCOL="${ODOO_SMTP_PROTOCOL:-}" # only used during the first initialization
# Database configuration
export ODOO_DEFAULT_DATABASE_HOST="postgresql" # only used at build time
ODOO_DATABASE_HOST="${ODOO_DATABASE_HOST:-"${POSTGRESQL_HOST:-}"}"
export ODOO_DATABASE_HOST="${ODOO_DATABASE_HOST:-$ODOO_DEFAULT_DATABASE_HOST}" # only used during the first initialization
ODOO_DATABASE_PORT_NUMBER="${ODOO_DATABASE_PORT_NUMBER:-"${POSTGRESQL_PORT_NUMBER:-}"}"
export ODOO_DATABASE_PORT_NUMBER="${ODOO_DATABASE_PORT_NUMBER:-5432}" # only used during the first initialization
ODOO_DATABASE_NAME="${ODOO_DATABASE_NAME:-"${POSTGRESQL_DATABASE_NAME:-}"}"
export ODOO_DATABASE_NAME="${ODOO_DATABASE_NAME:-bitnami_odoo}" # only used during the first initialization
ODOO_DATABASE_USER="${ODOO_DATABASE_USER:-"${POSTGRESQL_DATABASE_USER:-}"}"
ODOO_DATABASE_USER="${ODOO_DATABASE_USER:-"${POSTGRESQL_DATABASE_USERNAME:-}"}"
export ODOO_DATABASE_USER="${ODOO_DATABASE_USER:-bn_odoo}" # only used during the first initialization
ODOO_DATABASE_PASSWORD="${ODOO_DATABASE_PASSWORD:-"${POSTGRESQL_DATABASE_PASSWORD:-}"}"
export ODOO_DATABASE_PASSWORD="${ODOO_DATABASE_PASSWORD:-}" # only used during the first initialization
# Custom environment variables may be defined below

View File

@@ -0,0 +1,45 @@
[options]
addons_path = {{ODOO_ADDONS_DIR}}
admin_passwd = {{ODOO_PASSWORD}}
; csv_internal_sep = ,
data_dir = {{ODOO_DATA_DIR}}
db_host = {{ODOO_DATABASE_HOST}}
; db_maxconn = 64
db_name = {{ODOO_DATABASE_NAME}}
db_password = {{ODOO_DATABASE_PASSWORD}}
db_port = {{ODOO_DATABASE_PORT_NUMBER}}
; db_sslmode = prefer
; https://www.postgresql.org/docs/current/manage-ag-templatedbs.html
db_template = template1
db_user = {{ODOO_DATABASE_USER}}
dbfilter = .*
debug_mode = False
email_from = {{ODOO_EMAIL}}
http_port = {{ODOO_PORT_NUMBER}}
; limit_memory_hard = 2684354560
; limit_memory_soft = 2147483648
; limit_request = 8192
; https://www.odoo.com/forum/help-1/question/cpu-time-limit-exceeded-how-to-solve-it-87922
limit_time_cpu = 90
limit_time_real = 150
; list_db = True
; log_db = False
; log_handler = [':INFO']
; log_level = info
; logfile = {{ODOO_LOG_FILE}}
longpolling_port = {{ODOO_LONGPOLLING_PORT_NUMBER}}
; https://www.odoo.com/es_ES/forum/ayuda-1/could-not-obtain-lock-on-row-in-relation-ir-cron-74519
max_cron_threads = 1
pidfile = {{ODOO_PID_FILE}}
; Odoo will always be running behind a proxy (e.g. Docker or Apache)
proxy_mode = True
; osv_memory_age_limit = 1.0
; osv_memory_count_limit = False
; pg_path =
; smtp_password = False
; smtp_port = 25
; smtp_server = localhost
; smtp_ssl = False
; smtp_user = False
; without_demo = False
; workers = 0

View File

@@ -0,0 +1,27 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purpose
# Load Odoo environment
. /opt/bitnami/scripts/odoo-env.sh
# Load libraries
. /opt/bitnami/scripts/libbitnami.sh
. /opt/bitnami/scripts/liblog.sh
print_welcome_page
if [[ "$1" = "/opt/bitnami/scripts/odoo/run.sh" ]]; then
/opt/bitnami/scripts/postgresql-client/setup.sh
/opt/bitnami/scripts/odoo/setup.sh
/post-init.sh
info "** Odoo setup finished! **"
fi
echo ""
exec "$@"

View File

@@ -0,0 +1,41 @@
#!/bin/bash
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purpose
# Load Odoo environment
. /opt/bitnami/scripts/odoo-env.sh
# Load libraries
. /opt/bitnami/scripts/libodoo.sh
. /opt/bitnami/scripts/libfile.sh
. /opt/bitnami/scripts/libfs.sh
. /opt/bitnami/scripts/liblog.sh
# The 'odoo-bin' tool is really the same as 'odoo', but due to the way it was installed, it appears in the latter form
# Official Odoo docs refer to 'odoo-bin' so we add a symlink for users to be able to use any form
ln -s "${ODOO_BIN_DIR}/odoo" "${ODOO_BIN_DIR}/odoo-bin"
# Ensure the Odoo base directory exists and has proper permissions
info "Configuring file permissions for Odoo"
ensure_user_exists "$ODOO_DAEMON_USER" --group "$ODOO_DAEMON_GROUP" --system
for dir in "$ODOO_ADDONS_DIR" "$ODOO_CONF_DIR" "$ODOO_DATA_DIR" "$ODOO_LOGS_DIR" "$ODOO_TMP_DIR" "$ODOO_VOLUME_DIR"; do
ensure_dir_exists "$dir"
# Use daemon:root ownership for compatibility when running as a non-root user
configure_permissions_ownership "$dir" -d "775" -f "664" -u "$ODOO_DAEMON_USER" -g "root"
done
# Use daemon user ownership for compatibility when running as a non-root user
chown "$ODOO_DAEMON_USER" "$ODOO_BASE_DIR"
# Create folders that existed in previous versions of this image with proper permissions/ownership
# TODO: Remove this block in a future release
ensure_dir_exists "${ODOO_BASE_DIR}/odoo"
ln -s "$ODOO_BASE_DIR"/lib/odoo-*.egg/odoo/addons "${ODOO_BASE_DIR}/odoo/addons"
# Intentionally avoid symlink since it would point to the parent folder, with potential to cause problems
ensure_dir_exists "${ODOO_TMP_DIR}/pids"
configure_permissions_ownership "${ODOO_TMP_DIR}/pids" -d "775" -f "664" -u "$ODOO_DAEMON_USER" -g "root"

View File

@@ -0,0 +1,26 @@
#!/bin/bash
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purpose
# Load Odoo environment
. /opt/bitnami/scripts/odoo-env.sh
# Load libraries
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libodoo.sh
declare cmd="${ODOO_BASE_DIR}/bin/odoo"
declare -a args=("--config" "$ODOO_CONF_FILE" "$@")
info "** Starting Odoo **"
if am_i_root; then
exec gosu "$ODOO_DAEMON_USER" "$cmd" "${args[@]}"
else
exec "$cmd" "${args[@]}"
fi

View File

@@ -0,0 +1,27 @@
#!/bin/bash
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purpose
# Load Odoo environment
. /opt/bitnami/scripts/odoo-env.sh
# Load PostgreSQL Client environment for 'postgresql_remote_execute' (after 'odoo-env.sh' so that MODULE is not set to a wrong value)
if [[ -f /opt/bitnami/scripts/postgresql-client-env.sh ]]; then
. /opt/bitnami/scripts/postgresql-client-env.sh
elif [[ -f /opt/bitnami/scripts/postgresql-env.sh ]]; then
. /opt/bitnami/scripts/postgresql-env.sh
fi
# Load libraries
. /opt/bitnami/scripts/libodoo.sh
# Ensure Odoo environment variables are valid
odoo_validate
# Ensure Odoo is initialized
odoo_initialize

View File

@@ -0,0 +1,86 @@
#!/bin/bash
#
# Environment configuration for postgresql-client
# The values for all environment variables will be set in the below order of precedence
# 1. Custom environment variables defined below after Bitnami defaults
# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR
# 3. Environment variables overridden via external files using *_FILE variables (see below)
# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata)
# Load logging library
# shellcheck disable=SC1090,SC1091
. /opt/bitnami/scripts/liblog.sh
export BITNAMI_ROOT_DIR="/opt/bitnami"
export BITNAMI_VOLUME_DIR="/bitnami"
# Logging configuration
export MODULE="${MODULE:-postgresql-client}"
export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}"
# By setting an environment variable matching *_FILE to a file path, the prefixed environment
# variable will be overridden with the value specified in that file
postgresql_client_env_vars=(
ALLOW_EMPTY_PASSWORD
POSTGRESQL_CLIENT_DATABASE_HOST
POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER
POSTGRESQL_CLIENT_POSTGRES_USER
POSTGRESQL_CLIENT_POSTGRES_PASSWORD
POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES
POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME
POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD
POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS
POSTGRESQL_CLIENT_EXECUTE_SQL
POSTGRESQL_HOST
POSTGRESQL_PORT_NUMBER
POSTGRESQL_CLIENT_ROOT_USER
POSTGRESQL_POSTGRES_USER
POSTGRESQL_ROOT_USER
POSTGRESQL_CLIENT_ROOT_PASSWORD
POSTGRESQL_POSTGRES_PASSWORD
POSTGRESQL_ROOT_PASSWORD
POSTGRESQL_CLIENT_CREATE_DATABASE_NAME
POSTGRESQL_CLIENT_CREATE_DATABASE_USER
)
for env_var in "${postgresql_client_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
if [[ -n "${!file_env_var:-}" ]]; then
if [[ -r "${!file_env_var:-}" ]]; then
export "${env_var}=$(< "${!file_env_var}")"
unset "${file_env_var}"
else
warn "Skipping export of '${env_var}'. '${!file_env_var:-}' is not readable."
fi
fi
done
unset postgresql_client_env_vars
# Paths
export POSTGRESQL_BASE_DIR="/opt/bitnami/postgresql"
export POSTGRESQL_BIN_DIR="$POSTGRESQL_BASE_DIR/bin"
export PATH="${POSTGRESQL_BIN_DIR}:${PATH}"
# PostgreSQL settings
export ALLOW_EMPTY_PASSWORD="${ALLOW_EMPTY_PASSWORD:-no}"
POSTGRESQL_CLIENT_DATABASE_HOST="${POSTGRESQL_CLIENT_DATABASE_HOST:-"${POSTGRESQL_HOST:-}"}"
export POSTGRESQL_CLIENT_DATABASE_HOST="${POSTGRESQL_CLIENT_DATABASE_HOST:-postgresql}"
POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER="${POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER:-"${POSTGRESQL_PORT_NUMBER:-}"}"
export POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER="${POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER:-5432}"
POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-"${POSTGRESQL_CLIENT_ROOT_USER:-}"}"
POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-"${POSTGRESQL_POSTGRES_USER:-}"}"
POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-"${POSTGRESQL_ROOT_USER:-}"}"
export POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-postgres}" # only used during the first initialization
POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-"${POSTGRESQL_CLIENT_ROOT_PASSWORD:-}"}"
POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-"${POSTGRESQL_POSTGRES_PASSWORD:-}"}"
POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-"${POSTGRESQL_ROOT_PASSWORD:-}"}"
export POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-}" # only used during the first initialization
POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES="${POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES:-"${POSTGRESQL_CLIENT_CREATE_DATABASE_NAME:-}"}"
export POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES="${POSTGRESQL_CLIENT_CREATE_DATABASE_NAMES:-}" # only used during the first initialization
POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME="${POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME:-"${POSTGRESQL_CLIENT_CREATE_DATABASE_USER:-}"}"
export POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME="${POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME:-}" # only used during the first initialization
export POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD="${POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD:-}" # only used during the first initialization
export POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS="${POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS:-}" # only used during the first initialization
export POSTGRESQL_CLIENT_EXECUTE_SQL="${POSTGRESQL_CLIENT_EXECUTE_SQL:-}" # only used during the first initialization
# Custom environment variables may be defined below

View File

@@ -0,0 +1,19 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries
. /opt/bitnami/scripts/libpostgresqlclient.sh
# Load PostgreSQL Client environment variables
. /opt/bitnami/scripts/postgresql-client-env.sh
# Ensure PostgreSQL Client environment variables settings are valid
postgresql_client_validate
# Ensure PostgreSQL Client is initialized
postgresql_client_initialize

View File

@@ -0,0 +1,31 @@
#!/bin/bash
#
# Executes custom Python init scripts
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries with logging functions
if [[ -f /opt/bitnami/base/functions ]]; then
. /opt/bitnami/base/functions
else
. /opt/bitnami/scripts/liblog.sh
fi
# Loop through all input files passed via stdin
read -r -a custom_init_scripts <<< "$@"
failure=0
if [[ "${#custom_init_scripts[@]}" -gt 0 ]]; then
for custom_init_script in "${custom_init_scripts[@]}"; do
[[ "$custom_init_script" != *".py" ]] && continue
info "Executing ${custom_init_script} with Python interpreter"
python "$custom_init_script" || failure=1
[[ "$failure" -ne 0 ]] && error "Failed to execute ${custom_init_script}"
done
fi
exit "$failure"

View File

@@ -0,0 +1,36 @@
#!/bin/bash
#
# Executes custom Bash init scripts
# shellcheck disable=SC1090,SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries with logging functions
if [[ -f /opt/bitnami/base/functions ]]; then
. /opt/bitnami/base/functions
else
. /opt/bitnami/scripts/liblog.sh
fi
# Loop through all input files passed via stdin
read -r -a custom_init_scripts <<< "$@"
failure=0
if [[ "${#custom_init_scripts[@]}" -gt 0 ]]; then
for custom_init_script in "${custom_init_scripts[@]}"; do
[[ "$custom_init_script" != *".sh" ]] && continue
if [[ -x "$custom_init_script" ]]; then
info "Executing ${custom_init_script}"
"$custom_init_script" || failure="1"
else
info "Sourcing ${custom_init_script} as it is not executable by the current user, any error may cause initialization to fail"
. "$custom_init_script"
fi
[[ "$failure" -ne 0 ]] && error "Failed to execute ${custom_init_script}"
done
fi
exit "$failure"

View File

@@ -0,0 +1,50 @@
#!/bin/bash
#
# Executes custom PostgreSQL (.sql or .sql.gz) init scripts
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Load libraries with logging functions
if [[ -f /opt/bitnami/base/functions ]]; then
. /opt/bitnami/base/functions
else
. /opt/bitnami/scripts/liblog.sh
fi
postgresql_execute() {
local -r sql_file="${1:?missing file}"
if [[ -n "$POSTGRESQL_PASSWORD" ]]; then
export PGPASSWORD=$POSTGRESQL_PASSWORD
fi
local -a psql=("psql")
if [[ -n "${POSTGRESQL_USER:-}" ]]; then
psql+=("-U" "$POSTGRESQL_USER")
else
psql+=("-U" "$POSTGRESQL_USERNAME")
fi
if [[ "$sql_file" == *".sql" ]]; then
"${psql[@]}" -f "$sql_file" || failure=$?
elif [[ "$sql_file" == *".sql.gz" ]]; then
gunzip -c "$sql_file" | "${psql[@]}" || failure=$?
fi
return "$failure"
}
# Loop through all input files passed via stdin
read -r -a custom_init_scripts <<< "$@"
failure=0
if [[ "${#custom_init_scripts[@]}" -gt 0 ]]; then
for custom_init_script in "${custom_init_scripts[@]}"; do
[[ ! "$custom_init_script" =~ ^.*(\.sql|\.sql\.gz)$ ]] && continue
info "Executing ${custom_init_script}"
postgresql_execute "$custom_init_script" || failure=1
[[ "$failure" -ne 0 ]] && error "Failed to execute ${custom_init_script}"
done
fi
exit "$failure"

View File

@@ -0,0 +1,23 @@
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes
# Only execute init scripts once
if [[ ! -f "/bitnami/odoo/.user_scripts_initialized" && -d "/docker-entrypoint-init.d" ]]; then
read -r -a init_scripts <<< "$(find "/docker-entrypoint-init.d" -type f -print0 | sort -z | xargs -0)"
if [[ "${#init_scripts[@]}" -gt 0 ]] && [[ ! -f "/bitnami/odoo/.user_scripts_initialized" ]]; then
mkdir -p "/bitnami/odoo"
for init_script in "${init_scripts[@]}"; do
for init_script_type_handler in /post-init.d/*.sh; do
"$init_script_type_handler" "$init_script"
done
done
fi
touch "/bitnami/odoo/.user_scripts_initialized"
fi