#!/bin/sh set -eu log() { printf '%s %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$*"; } # Determine the numeric UID:GID for the odoo user if present; otherwise # fall back to the UID:GID of the current user (likely root when the # wrapper runs as root inside the container). OG_UID="$(id -u odoo 2>/dev/null || true)" OG_GID="$(id -g odoo 2>/dev/null || true)" if [ -n "$OG_UID" ] && [ -n "$OG_GID" ]; then OG="$OG_UID:$OG_GID" else OG="$(id -u):$(id -g)" fi log "Fixing Odoo volumes to UID:GID=$OG" # Paths we expect to ensure ownership for. If a path is missing we create it # with sensible defaults so Odoo can write into it later. for d in /var/lib/odo /etc/odoo; do if [ -e "$d" ]; then log " -> chown $OG $d" if chown -R "$OG" "$d"; then log " chown succeeded for $d" else log " WARNING: chown failed for $d (continuing)" fi ls -ldn "$d" || true else log " -> path $d does not exist, creating" if mkdir -p "$d"; then log " created $d" chown -R "$OG" "$d" || log " WARNING: chown failed after creating $d" ls -ldn "$d" || true else log " ERROR: failed to create $d" fi fi done # Touch a marker so other tooling can detect that the one-shot ran. MARKER=/var/lib/odoo/.odoo-init-done log "Creating marker $MARKER" if touch "$MARKER"; then chown "$OG" "$MARKER" || true else log "WARNING: could not create marker $MARKER" fi # Ensure the init script exists and is readable. If not, fail early with # a clear exit code so upstream tooling can detect the problem. if [ ! -r /init-odoo.sh ]; then log "ERROR: /init-odoo.sh missing or not readable" exit 2 fi # Try to make it executable for the target user only if the file is writable. # This avoids noisy "Read-only file system" errors when /init-odoo.sh is mounted # read-only from the host. if [ -w /init-odoo.sh ]; then chmod +x /init-odoo.sh || log "WARNING: chmod /init-odoo.sh failed" else log "Skipping chmod: /init-odoo.sh is not writable (read-only mount)" fi log "Executing init script as 'odoo' user" # Run the init script as the odoo user while passing DB env vars inline so # they are visible even when using su which doesn't preserve the current # environment by default. exec su -s /bin/sh -c "DB_NAME=\"$DB_NAME\" HOST=\"$HOST\" USER=\"$USER\" PASSWORD=\"$PASSWORD\" /init-odoo.sh" odoo #!/bin/sh set -eu OG="$(id -u odoo 2>/dev/null || id -u):$(id -g odoo 2>/dev/null || id -g)" echo "Fixing Odoo volumes to UID:GID=$OG" for d in /var/lib/odo /etc/odoo; do echo " -> chown $OG $d" chown -R "$OG" "$d" || true ls -ldn "$d" || true done # Execute the original init script as the 'odoo' user (we run this wrapper as root). # When switching user with su, the target user's environment is reset; pass the # needed DB env vars inline so the init script sees them. exec su -s /bin/sh -c \ "DB_NAME=\"$DB_NAME\" HOST=\"$HOST\" USER=\"$USER\" PASSWORD=\"$PASSWORD\" /init-odoo.sh" \ odoo