From 7cc82e6778589942608e0dc377204f96701143c0 Mon Sep 17 00:00:00 2001 From: Mark Rotteveel Date: Sat, 19 Jul 2025 09:55:23 +0200 Subject: [PATCH 1/3] Add Firebird 5.0.3, 4.0.6 and 3.0.13 --- assets.json | 104 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 15 deletions(-) diff --git a/assets.json b/assets.json index 7c71448..ff0dace 100644 --- a/assets.json +++ b/assets.json @@ -1,39 +1,70 @@ [ { - "version": "5.0.2", + "version": "5.0.3", "releases": [ { "arm64": { - "url": "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.2/Firebird-5.0.2.1613-0-linux-arm64.tar.gz", - "sha256": "216edb3594d3318690bd3f2ae9979a9a52efb512eb1bf799c0bace50106a0a69" + "url": "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-arm64.tar.gz", + "sha256": "e375341466e625bf17e4416723c1465a646d44903011ac4b89f84afe1df3633e" } }, { "amd64": { - "url": "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.2/Firebird-5.0.2.1613-0-linux-x64.tar.gz", - "sha256": "23d6e0522f32fb13c288f67c98105014c3186ecf3f930f96ca9af1897b9565bf" + "url": "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-x64.tar.gz", + "sha256": "ef281c53f85756288151a86831375c9ae668caaeccd1b18103d523ba8f444779" } } ], "tags": { "bookworm": [ "5", - "5.0.2", + "5.0.3", "latest" ], "bullseye": [ "bullseye", "5-bullseye", - "5.0.2-bullseye" + "5.0.3-bullseye" ], "jammy": [ "jammy", "5-jammy", - "5.0.2-jammy" + "5.0.3-jammy" ], "noble": [ "noble", "5-noble", + "5.0.3-noble" + ] + } + }, + { + "version": "5.0.2", + "releases": [ + { + "arm64": { + "url": "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.2/Firebird-5.0.2.1613-0-linux-arm64.tar.gz", + "sha256": "216edb3594d3318690bd3f2ae9979a9a52efb512eb1bf799c0bace50106a0a69" + } + }, + { + "amd64": { + "url": "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.2/Firebird-5.0.2.1613-0-linux-x64.tar.gz", + "sha256": "23d6e0522f32fb13c288f67c98105014c3186ecf3f930f96ca9af1897b9565bf" + } + } + ], + "tags": { + "bookworm": [ + "5.0.2" + ], + "bullseye": [ + "5.0.2-bullseye" + ], + "jammy": [ + "5.0.2-jammy" + ], + "noble": [ "5.0.2-noble" ] } @@ -100,6 +131,33 @@ ] } }, + { + "version": "4.0.6", + "releases": { + "amd64": { + "url": "https://github.com/FirebirdSQL/firebird/releases/download/v4.0.6/Firebird-4.0.6.3221-0.amd64.tar.gz", + "sha256": "6ff5f672e10ee38ec5fc5394012ac83fe19872543dd2fefa249c1ccf62bc0075" + } + }, + "tags": { + "bookworm": [ + "4", + "4.0.6" + ], + "bullseye": [ + "4-bullseye", + "4.0.6-bullseye" + ], + "jammy": [ + "4-jammy", + "4.0.6-jammy" + ], + "noble": [ + "4-noble", + "4.0.6-noble" + ] + } + }, { "version": "4.0.5", "releases": { @@ -110,19 +168,15 @@ }, "tags": { "bookworm": [ - "4", "4.0.5" ], "bullseye": [ - "4-bullseye", "4.0.5-bullseye" ], "jammy": [ - "4-jammy", "4.0.5-jammy" ], "noble": [ - "4-noble", "4.0.5-noble" ] } @@ -242,6 +296,29 @@ ] } }, + { + "version": "3.0.13", + "releases": { + "amd64": { + "url": "https://github.com/FirebirdSQL/firebird/releases/download/v3.0.13/Firebird-3.0.13.33818-0.amd64.tar.gz", + "sha256": "677e19d6308869d5dd0836a342157c7bd1e4b5a873aa385832da01d81db444dd" + } + }, + "tags": { + "bookworm": [ + "3", + "3.0.13" + ], + "bullseye": [ + "3-bullseye", + "3.0.13-bullseye" + ], + "jammy": [ + "3-jammy", + "3.0.13-jammy" + ] + } + }, { "version": "3.0.12", "releases": { @@ -252,15 +329,12 @@ }, "tags": { "bookworm": [ - "3", "3.0.12" ], "bullseye": [ - "3-bullseye", "3.0.12-bullseye" ], "jammy": [ - "3-jammy", "3.0.12-jammy" ] } From 3997f6515ce45f100c3e778fb202420fda497eb0 Mon Sep 17 00:00:00 2001 From: "F.D.Castel" Date: Sat, 19 Jul 2025 09:56:14 +0000 Subject: [PATCH 2/3] Updates README. --- README.md | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c8e03b6..00d6dec 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,14 @@ Docker images for Firebird Database. |`firebirdsql/firebird`|Dockerfile| |:-|:-:| -|`5`, `5.0.2`, `latest`|[Dockerfile](./generated/5.0.2/bookworm/Dockerfile)| - |`bullseye`, `5-bullseye`, `5.0.2-bullseye`|[Dockerfile](./generated/5.0.2/bullseye/Dockerfile)| - |`jammy`, `5-jammy`, `5.0.2-jammy`|[Dockerfile](./generated/5.0.2/jammy/Dockerfile)| - |`noble`, `5-noble`, `5.0.2-noble`|[Dockerfile](./generated/5.0.2/noble/Dockerfile)| +|`5`, `5.0.3`, `latest`|[Dockerfile](./generated/5.0.3/bookworm/Dockerfile)| + |`bullseye`, `5-bullseye`, `5.0.3-bullseye`|[Dockerfile](./generated/5.0.3/bullseye/Dockerfile)| + |`jammy`, `5-jammy`, `5.0.3-jammy`|[Dockerfile](./generated/5.0.3/jammy/Dockerfile)| + |`noble`, `5-noble`, `5.0.3-noble`|[Dockerfile](./generated/5.0.3/noble/Dockerfile)| + |`5.0.2`|[Dockerfile](./generated/5.0.2/bookworm/Dockerfile)| + |`5.0.2-bullseye`|[Dockerfile](./generated/5.0.2/bullseye/Dockerfile)| + |`5.0.2-jammy`|[Dockerfile](./generated/5.0.2/jammy/Dockerfile)| + |`5.0.2-noble`|[Dockerfile](./generated/5.0.2/noble/Dockerfile)| |`5.0.1`|[Dockerfile](./generated/5.0.1/bookworm/Dockerfile)| |`5.0.1-bullseye`|[Dockerfile](./generated/5.0.1/bullseye/Dockerfile)| |`5.0.1-jammy`|[Dockerfile](./generated/5.0.1/jammy/Dockerfile)| @@ -31,10 +35,14 @@ Docker images for Firebird Database. |`5.0.0-bullseye`|[Dockerfile](./generated/5.0.0/bullseye/Dockerfile)| |`5.0.0-jammy`|[Dockerfile](./generated/5.0.0/jammy/Dockerfile)| |`5.0.0-noble`|[Dockerfile](./generated/5.0.0/noble/Dockerfile)| - |`4`, `4.0.5`|[Dockerfile](./generated/4.0.5/bookworm/Dockerfile)| - |`4-bullseye`, `4.0.5-bullseye`|[Dockerfile](./generated/4.0.5/bullseye/Dockerfile)| - |`4-jammy`, `4.0.5-jammy`|[Dockerfile](./generated/4.0.5/jammy/Dockerfile)| - |`4-noble`, `4.0.5-noble`|[Dockerfile](./generated/4.0.5/noble/Dockerfile)| + |`4`, `4.0.6`|[Dockerfile](./generated/4.0.6/bookworm/Dockerfile)| + |`4-bullseye`, `4.0.6-bullseye`|[Dockerfile](./generated/4.0.6/bullseye/Dockerfile)| + |`4-jammy`, `4.0.6-jammy`|[Dockerfile](./generated/4.0.6/jammy/Dockerfile)| + |`4-noble`, `4.0.6-noble`|[Dockerfile](./generated/4.0.6/noble/Dockerfile)| + |`4.0.5`|[Dockerfile](./generated/4.0.5/bookworm/Dockerfile)| + |`4.0.5-bullseye`|[Dockerfile](./generated/4.0.5/bullseye/Dockerfile)| + |`4.0.5-jammy`|[Dockerfile](./generated/4.0.5/jammy/Dockerfile)| + |`4.0.5-noble`|[Dockerfile](./generated/4.0.5/noble/Dockerfile)| |`4.0.4`|[Dockerfile](./generated/4.0.4/bookworm/Dockerfile)| |`4.0.4-bullseye`|[Dockerfile](./generated/4.0.4/bullseye/Dockerfile)| |`4.0.4-jammy`|[Dockerfile](./generated/4.0.4/jammy/Dockerfile)| @@ -55,9 +63,12 @@ Docker images for Firebird Database. |`4.0.0-bullseye`|[Dockerfile](./generated/4.0.0/bullseye/Dockerfile)| |`4.0.0-jammy`|[Dockerfile](./generated/4.0.0/jammy/Dockerfile)| |`4.0.0-noble`|[Dockerfile](./generated/4.0.0/noble/Dockerfile)| - |`3`, `3.0.12`|[Dockerfile](./generated/3.0.12/bookworm/Dockerfile)| - |`3-bullseye`, `3.0.12-bullseye`|[Dockerfile](./generated/3.0.12/bullseye/Dockerfile)| - |`3-jammy`, `3.0.12-jammy`|[Dockerfile](./generated/3.0.12/jammy/Dockerfile)| + |`3`, `3.0.13`|[Dockerfile](./generated/3.0.13/bookworm/Dockerfile)| + |`3-bullseye`, `3.0.13-bullseye`|[Dockerfile](./generated/3.0.13/bullseye/Dockerfile)| + |`3-jammy`, `3.0.13-jammy`|[Dockerfile](./generated/3.0.13/jammy/Dockerfile)| + |`3.0.12`|[Dockerfile](./generated/3.0.12/bookworm/Dockerfile)| + |`3.0.12-bullseye`|[Dockerfile](./generated/3.0.12/bullseye/Dockerfile)| + |`3.0.12-jammy`|[Dockerfile](./generated/3.0.12/jammy/Dockerfile)| |`3.0.11`|[Dockerfile](./generated/3.0.11/bookworm/Dockerfile)| |`3.0.11-bullseye`|[Dockerfile](./generated/3.0.11/bullseye/Dockerfile)| |`3.0.11-jammy`|[Dockerfile](./generated/3.0.11/jammy/Dockerfile)| From fd67d57b668f41632cabe39a19e8d593802d4e4d Mon Sep 17 00:00:00 2001 From: "F.D.Castel" Date: Sat, 19 Jul 2025 10:03:08 +0000 Subject: [PATCH 3/3] Adds generated files. --- generated/3.0.13/bookworm/Dockerfile | 98 ++++++++ generated/3.0.13/bookworm/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/3.0.13/bullseye/Dockerfile | 98 ++++++++ generated/3.0.13/bullseye/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/3.0.13/jammy/Dockerfile | 99 ++++++++ generated/3.0.13/jammy/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/4.0.6/bookworm/Dockerfile | 98 ++++++++ generated/4.0.6/bookworm/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/4.0.6/bullseye/Dockerfile | 98 ++++++++ generated/4.0.6/bullseye/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/4.0.6/jammy/Dockerfile | 99 ++++++++ generated/4.0.6/jammy/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/4.0.6/noble/Dockerfile | 98 ++++++++ generated/4.0.6/noble/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/5.0.3/bookworm/Dockerfile | 98 ++++++++ generated/5.0.3/bookworm/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/5.0.3/bullseye/Dockerfile | 98 ++++++++ generated/5.0.3/bullseye/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/5.0.3/jammy/Dockerfile | 99 ++++++++ generated/5.0.3/jammy/entrypoint.sh | 291 ++++++++++++++++++++++++ generated/5.0.3/noble/Dockerfile | 98 ++++++++ generated/5.0.3/noble/entrypoint.sh | 291 ++++++++++++++++++++++++ 22 files changed, 4282 insertions(+) create mode 100644 generated/3.0.13/bookworm/Dockerfile create mode 100644 generated/3.0.13/bookworm/entrypoint.sh create mode 100644 generated/3.0.13/bullseye/Dockerfile create mode 100644 generated/3.0.13/bullseye/entrypoint.sh create mode 100644 generated/3.0.13/jammy/Dockerfile create mode 100644 generated/3.0.13/jammy/entrypoint.sh create mode 100644 generated/4.0.6/bookworm/Dockerfile create mode 100644 generated/4.0.6/bookworm/entrypoint.sh create mode 100644 generated/4.0.6/bullseye/Dockerfile create mode 100644 generated/4.0.6/bullseye/entrypoint.sh create mode 100644 generated/4.0.6/jammy/Dockerfile create mode 100644 generated/4.0.6/jammy/entrypoint.sh create mode 100644 generated/4.0.6/noble/Dockerfile create mode 100644 generated/4.0.6/noble/entrypoint.sh create mode 100644 generated/5.0.3/bookworm/Dockerfile create mode 100644 generated/5.0.3/bookworm/entrypoint.sh create mode 100644 generated/5.0.3/bullseye/Dockerfile create mode 100644 generated/5.0.3/bullseye/entrypoint.sh create mode 100644 generated/5.0.3/jammy/Dockerfile create mode 100644 generated/5.0.3/jammy/entrypoint.sh create mode 100644 generated/5.0.3/noble/Dockerfile create mode 100644 generated/5.0.3/noble/entrypoint.sh diff --git a/generated/3.0.13/bookworm/Dockerfile b/generated/3.0.13/bookworm/Dockerfile new file mode 100644 index 0000000..a8852ec --- /dev/null +++ b/generated/3.0.13/bookworm/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM debian:bookworm-slim + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v3.0.13/Firebird-3.0.13.33818-0.amd64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-677e19d6308869d5dd0836a342157c7bd1e4b5a873aa385832da01d81db444dd} + +ENV FIREBIRD_VERSION=3.0.13 +ENV FIREBIRD_MAJOR=3 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu72 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/3.0.13/bookworm/entrypoint.sh b/generated/3.0.13/bookworm/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/3.0.13/bookworm/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/3.0.13/bullseye/Dockerfile b/generated/3.0.13/bullseye/Dockerfile new file mode 100644 index 0000000..ef2d5e7 --- /dev/null +++ b/generated/3.0.13/bullseye/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM debian:bullseye-slim + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v3.0.13/Firebird-3.0.13.33818-0.amd64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-677e19d6308869d5dd0836a342157c7bd1e4b5a873aa385832da01d81db444dd} + +ENV FIREBIRD_VERSION=3.0.13 +ENV FIREBIRD_MAJOR=3 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu67 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/3.0.13/bullseye/entrypoint.sh b/generated/3.0.13/bullseye/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/3.0.13/bullseye/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/3.0.13/jammy/Dockerfile b/generated/3.0.13/jammy/Dockerfile new file mode 100644 index 0000000..66031f0 --- /dev/null +++ b/generated/3.0.13/jammy/Dockerfile @@ -0,0 +1,99 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM ubuntu:jammy + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v3.0.13/Firebird-3.0.13.33818-0.amd64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-677e19d6308869d5dd0836a342157c7bd1e4b5a873aa385832da01d81db444dd} + +ENV FIREBIRD_VERSION=3.0.13 +ENV FIREBIRD_MAJOR=3 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu70 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + tzdata \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/3.0.13/jammy/entrypoint.sh b/generated/3.0.13/jammy/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/3.0.13/jammy/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/4.0.6/bookworm/Dockerfile b/generated/4.0.6/bookworm/Dockerfile new file mode 100644 index 0000000..19d797e --- /dev/null +++ b/generated/4.0.6/bookworm/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM debian:bookworm-slim + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v4.0.6/Firebird-4.0.6.3221-0.amd64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-6ff5f672e10ee38ec5fc5394012ac83fe19872543dd2fefa249c1ccf62bc0075} + +ENV FIREBIRD_VERSION=4.0.6 +ENV FIREBIRD_MAJOR=4 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu72 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/4.0.6/bookworm/entrypoint.sh b/generated/4.0.6/bookworm/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/4.0.6/bookworm/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/4.0.6/bullseye/Dockerfile b/generated/4.0.6/bullseye/Dockerfile new file mode 100644 index 0000000..72eb9ed --- /dev/null +++ b/generated/4.0.6/bullseye/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM debian:bullseye-slim + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v4.0.6/Firebird-4.0.6.3221-0.amd64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-6ff5f672e10ee38ec5fc5394012ac83fe19872543dd2fefa249c1ccf62bc0075} + +ENV FIREBIRD_VERSION=4.0.6 +ENV FIREBIRD_MAJOR=4 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu67 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/4.0.6/bullseye/entrypoint.sh b/generated/4.0.6/bullseye/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/4.0.6/bullseye/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/4.0.6/jammy/Dockerfile b/generated/4.0.6/jammy/Dockerfile new file mode 100644 index 0000000..6586ea6 --- /dev/null +++ b/generated/4.0.6/jammy/Dockerfile @@ -0,0 +1,99 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM ubuntu:jammy + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v4.0.6/Firebird-4.0.6.3221-0.amd64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-6ff5f672e10ee38ec5fc5394012ac83fe19872543dd2fefa249c1ccf62bc0075} + +ENV FIREBIRD_VERSION=4.0.6 +ENV FIREBIRD_MAJOR=4 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu70 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + tzdata \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/4.0.6/jammy/entrypoint.sh b/generated/4.0.6/jammy/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/4.0.6/jammy/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/4.0.6/noble/Dockerfile b/generated/4.0.6/noble/Dockerfile new file mode 100644 index 0000000..afb4da5 --- /dev/null +++ b/generated/4.0.6/noble/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM ubuntu:noble + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v4.0.6/Firebird-4.0.6.3221-0.amd64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-6ff5f672e10ee38ec5fc5394012ac83fe19872543dd2fefa249c1ccf62bc0075} + +ENV FIREBIRD_VERSION=4.0.6 +ENV FIREBIRD_MAJOR=4 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu74 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/4.0.6/noble/entrypoint.sh b/generated/4.0.6/noble/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/4.0.6/noble/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/5.0.3/bookworm/Dockerfile b/generated/5.0.3/bookworm/Dockerfile new file mode 100644 index 0000000..428523e --- /dev/null +++ b/generated/5.0.3/bookworm/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM debian:bookworm-slim + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-arm64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+e375341466e625bf17e4416723c1465a646d44903011ac4b89f84afe1df3633e} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-x64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-ef281c53f85756288151a86831375c9ae668caaeccd1b18103d523ba8f444779} + +ENV FIREBIRD_VERSION=5.0.3 +ENV FIREBIRD_MAJOR=5 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu72 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/5.0.3/bookworm/entrypoint.sh b/generated/5.0.3/bookworm/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/5.0.3/bookworm/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/5.0.3/bullseye/Dockerfile b/generated/5.0.3/bullseye/Dockerfile new file mode 100644 index 0000000..bc2b8e8 --- /dev/null +++ b/generated/5.0.3/bullseye/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM debian:bullseye-slim + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-arm64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+e375341466e625bf17e4416723c1465a646d44903011ac4b89f84afe1df3633e} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-x64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-ef281c53f85756288151a86831375c9ae668caaeccd1b18103d523ba8f444779} + +ENV FIREBIRD_VERSION=5.0.3 +ENV FIREBIRD_MAJOR=5 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu67 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/5.0.3/bullseye/entrypoint.sh b/generated/5.0.3/bullseye/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/5.0.3/bullseye/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/5.0.3/jammy/Dockerfile b/generated/5.0.3/jammy/Dockerfile new file mode 100644 index 0000000..93bba77 --- /dev/null +++ b/generated/5.0.3/jammy/Dockerfile @@ -0,0 +1,99 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM ubuntu:jammy + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-arm64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+e375341466e625bf17e4416723c1465a646d44903011ac4b89f84afe1df3633e} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-x64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-ef281c53f85756288151a86831375c9ae668caaeccd1b18103d523ba8f444779} + +ENV FIREBIRD_VERSION=5.0.3 +ENV FIREBIRD_MAJOR=5 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu70 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + tzdata \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/5.0.3/jammy/entrypoint.sh b/generated/5.0.3/jammy/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/5.0.3/jammy/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi diff --git a/generated/5.0.3/noble/Dockerfile b/generated/5.0.3/noble/Dockerfile new file mode 100644 index 0000000..4de0462 --- /dev/null +++ b/generated/5.0.3/noble/Dockerfile @@ -0,0 +1,98 @@ +# +# This file was auto-generated. Do not edit. See /src. +# + +# Best practices for Dockerfile instructions +# https://docs.docker.com/develop/develop-images/instructions/ + +FROM ubuntu:noble + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +ARG ARCH_ARM64 + +# ARM64 arch +ENV FIREBIRD_RELEASE_URL=${ARCH_ARM64:+https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-arm64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${ARCH_ARM64:+e375341466e625bf17e4416723c1465a646d44903011ac4b89f84afe1df3633e} + +# AMD64 arch +ENV FIREBIRD_RELEASE_URL=${FIREBIRD_RELEASE_URL:-https://github.com/FirebirdSQL/firebird/releases/download/v5.0.3/Firebird-5.0.3.1683-0-linux-x64.tar.gz} +ENV FIREBIRD_RELEASE_SHA256=${FIREBIRD_RELEASE_SHA256:-ef281c53f85756288151a86831375c9ae668caaeccd1b18103d523ba8f444779} + +ENV FIREBIRD_VERSION=5.0.3 +ENV FIREBIRD_MAJOR=5 + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -x Print commands and their arguments as they are executed. + +# Prerequisites +# FB 3.0 uses libncurses5: https://github.com/FirebirdSQL/firebird/issues/6418#issuecomment-826245785 +RUN set -eux; \ + apt-get update; \ + # Install prerequisites + curl, ca-certificates for download + apt-get install -y --no-install-recommends \ + libatomic1 \ + libicu74 \ + $([ $FIREBIRD_MAJOR -eq 3 ] && echo 'libncurses5' || echo 'libncurses6') \ + libtomcrypt1 \ + libtommath1 \ + netbase \ + procps \ + ca-certificates \ + curl; \ + \ + # Download + mkdir -p /tmp/firebird_install; \ + echo "Downloading Firebird from $FIREBIRD_RELEASE_URL"; \ + curl -fSL "$FIREBIRD_RELEASE_URL" -o /tmp/firebird_install/firebird-bundle.tar.gz; \ + echo "Verifying checksum: $FIREBIRD_RELEASE_SHA256 for downloaded file"; \ + echo "$FIREBIRD_RELEASE_SHA256 /tmp/firebird_install/firebird-bundle.tar.gz" | sha256sum -c -; \ + \ + # Extract, install, clean + cd /tmp/firebird_install; \ + tar --extract --file=firebird-bundle.tar.gz --gunzip --verbose --strip-components=1; \ + ./install.sh -silent; \ + rm -rf /tmp/firebird_install; \ + # Remove unnecessary files + rm -rf /opt/firebird/doc \ + /opt/firebird/examples \ + /opt/firebird/help \ + /opt/firebird/include; \ + # Remove 'employee' sample database from 'databases.conf' + sed -i '/^employee/d' /opt/firebird/databases.conf; \ + \ + # Clean up temporary packages (curl, ca-certificates) and apt lists + apt-get purge -y --auto-remove curl ca-certificates; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# Fix libtommath for FB 3.0 -- https://github.com/FirebirdSQL/firebird/issues/5716#issuecomment-826239174 +RUN [ $FIREBIRD_MAJOR -eq 3 ] && ln -sf /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0 || true + +# System path +ENV PATH=/opt/firebird/bin:$PATH + +# Data directory +ENV FIREBIRD_DATA=/var/lib/firebird/data +RUN set -eux; \ + mkdir -p "$FIREBIRD_DATA"; \ + chown -R firebird:firebird "$FIREBIRD_DATA"; \ + chmod 644 "$FIREBIRD_DATA" +VOLUME $FIREBIRD_DATA + +# Entrypoint +COPY entrypoint.sh /usr/local/bin/ +RUN set -eux; \ + chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] + +EXPOSE 3050/tcp + +# Fix terminfo location +ENV TERMINFO=/lib/terminfo/ + +CMD ["firebird"] + diff --git a/generated/5.0.3/noble/entrypoint.sh b/generated/5.0.3/noble/entrypoint.sh new file mode 100644 index 0000000..e9fa133 --- /dev/null +++ b/generated/5.0.3/noble/entrypoint.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env bash + +# +# Docker entrypoint for firebird-docker images. +# +# Based on works of Jacob Alberty and The PostgreSQL Development Group. +# + +# +# About the [Tabs ahead] marker: +# Some sections of this file use tabs for better readability. +# When using bash here strings the - option suppresses leading tabs but not spaces. +# + + + +# https://linuxcommand.org/lc3_man_pages/seth.html +# -E If set, the ERR trap is inherited by shell functions. +# -e Exit immediately if a command exits with a non-zero status. +# -u Treat unset variables as an error when substituting +# -o Set the variable corresponding to option-name: +# pipefail the return value of a pipeline is the status of +# the last command to exit with a non-zero status, +# or zero if no command exited with a non-zero status +set -Eeuo pipefail + +# usage: read_from_file_or_env VAR [DEFAULT] +# ie: read_from_file_or_env 'DB_PASSWORD' 'example' +# If $(VAR)_FILE var is set, sets VAR value from file contents. Otherwise, uses DEFAULT value if VAR is not set. +read_from_file_or_env() { + local var="$1" + local fileVar="${var}_FILE" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: Both $var and $fileVar are set. + + Variables %s and %s are mutually exclusive. Remove either one. + ----- + EOL + exit 1 + fi + + local def="${2:-}" + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + + export "$var"="$val" + unset "$fileVar" +} + +# usage: firebird_config_set KEY VALUE +# ie: firebird_config_set 'WireCrypt' 'Enabled' +# Set configuration key KEY to VALUE in 'firebird.conf' +firebird_config_set() { + # Uncomment line + sed -i "s/^#${1}/${1}/g" /opt/firebird/firebird.conf + + # Set KEY to VALUE + sed -i "s~^\(${1}\s*=\s*\).*$~\1${2}~" /opt/firebird/firebird.conf +} + +# Indent multi-line string -- https://stackoverflow.com/a/29779745 +indent() { + sed 's/^/ /'; +} + +# Set Firebird configuration parameters from environment variables. +set_config() { + read_from_file_or_env 'FIREBIRD_USE_LEGACY_AUTH' + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + echo 'Using Legacy_Auth.' + + # Firebird 4+: Uses 'Srp256' before 'Srp'. + local srp256='' + [ "$FIREBIRD_MAJOR" -ge "4" ] && srp256='Srp256, ' + + # Adds Legacy_Auth and Legacy_UserManager as first options. + firebird_config_set AuthServer "Legacy_Auth, ${srp256}Srp" + firebird_config_set AuthClient "Legacy_Auth, ${srp256}Srp" + firebird_config_set UserManager 'Legacy_UserManager, Srp' + + # Default setting is 'Required'. Reduces it to 'Enabled'. + firebird_config_set WireCrypt 'Enabled' + fi + + # FIREBIRD_CONF_* variables: set key in 'firebird.conf' + local v + for v in $(compgen -A variable | grep 'FIREBIRD_CONF_'); do + local key=${v/FIREBIRD_CONF_/} + firebird_config_set "$key" "${!v}" + done + + # Output changed settings + local changed_settings=$(grep -o '^[^#]*' /opt/firebird/firebird.conf) + if [ -n "$changed_settings" ]; then + echo "Using settings:" + echo "$changed_settings" | indent + fi +} + +# Changes SYSDBA password if FIREBIRD_ROOT_PASSWORD variable is set. +set_sysdba() { + read_from_file_or_env 'FIREBIRD_ROOT_PASSWORD' + if [ -n "$FIREBIRD_ROOT_PASSWORD" ]; then + echo 'Changing SYSDBA password.' + + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Srp; + EXIT; + EOL + + if [ "$FIREBIRD_USE_LEGACY_AUTH" == 'true' ]; then + # [Tabs ahead] + /opt/firebird/bin/isql -b -user SYSDBA security.db <<-EOL + CREATE OR ALTER USER SYSDBA + PASSWORD '$FIREBIRD_ROOT_PASSWORD' + USING PLUGIN Legacy_UserManager; + EXIT; + EOL + fi + + rm -rf /opt/firebird/SYSDBA.password + fi +} + +# Requires FIREBIRD_PASSWORD if FIREBIRD_USER is set. +requires_user_password() { + if [ -n "$FIREBIRD_USER" ] && [ -z "$FIREBIRD_PASSWORD" ]; then + # [Tabs ahead] + cat >&2 <<-EOL + ----- + ERROR: FIREBIRD_PASSWORD variable is not set. + + When using FIREBIRD_USER you must also set FIREBIRD_PASSWORD variable. + ----- + EOL + exit 1 + fi +} + +# Create Firebird user. +create_user() { + read_from_file_or_env 'FIREBIRD_USER' + read_from_file_or_env 'FIREBIRD_PASSWORD' + + if [ -n "$FIREBIRD_USER" ]; then + requires_user_password + echo "Creating user '$FIREBIRD_USER'..." + + # [Tabs ahead] + /opt/firebird/bin/isql -b security.db <<-EOL + CREATE OR ALTER USER $FIREBIRD_USER + PASSWORD '$FIREBIRD_PASSWORD' + GRANT ADMIN ROLE; + EXIT; + EOL + fi +} + +# Run isql +process_sql() { + local isql_command=( /opt/firebird/bin/isql -b ) + + if [ -n "$FIREBIRD_USER" ]; then + isql_command+=( -u "$FIREBIRD_USER" -p "$FIREBIRD_PASSWORD" ) + fi + + if [ -n "$FIREBIRD_DATABASE" ]; then + isql_command+=( "$FIREBIRD_DATABASE" ) + fi + + ${isql_command[@]} "$@" +} + +# Execute database initialization scripts +init_db() { + local f + for f; do + case "$f" in + *.sh) + if [ -x "$f" ]; then + # Script is executable. Run it. + printf ' running %s\n' "$f" + "$f" + else + # Script is not executable. Source it. + printf ' sourcing %s\n' "$f" + . "$f" + fi + ;; + *.sql) printf ' running %s\n' "$f"; cat "$f" | process_sql; printf '\n' ;; + *.sql.gz) printf ' running %s\n' "$f"; gunzip -c "$f" | process_sql; printf '\n' ;; + *.sql.xz) printf ' running %s\n' "$f"; xzcat "$f" | process_sql; printf '\n' ;; + *.sql.zst) printf ' running %s\n' "$f"; zstd -dc "$f" | process_sql; printf '\n' ;; + *) printf ' ignoring %s\n' "$f" ;; + esac + printf '\n' + done + +} + +# Create user database. +create_db() { + read_from_file_or_env 'FIREBIRD_DATABASE' + if [ -n "$FIREBIRD_DATABASE" ]; then + # Expand FIREBIRD_DATABASE to full path + cd "$FIREBIRD_DATA" + export FIREBIRD_DATABASE=$(realpath --canonicalize-missing "$FIREBIRD_DATABASE") + + # Store it for other sessions of this instance + echo "export FIREBIRD_DATABASE='$FIREBIRD_DATABASE'" > ~/.bashrc + + # Create database only if not exists. + if [ ! -f "$FIREBIRD_DATABASE" ]; then + echo "Creating database '$FIREBIRD_DATABASE'..." + + read_from_file_or_env 'FIREBIRD_DATABASE_PAGE_SIZE' + read_from_file_or_env 'FIREBIRD_DATABASE_DEFAULT_CHARSET' + + local user_and_password='' + [ -n "$FIREBIRD_USER" ] && user_and_password=" USER '$FIREBIRD_USER' PASSWORD '$FIREBIRD_PASSWORD'" + + local page_size='' + [ -n "$FIREBIRD_DATABASE_PAGE_SIZE" ] && page_size="PAGE_SIZE $FIREBIRD_DATABASE_PAGE_SIZE" + + local default_charset='' + [ -n "$FIREBIRD_DATABASE_DEFAULT_CHARSET" ] && default_charset="DEFAULT CHARACTER SET $FIREBIRD_DATABASE_DEFAULT_CHARSET" + + # [Tabs ahead] + /opt/firebird/bin/isql -b -q <<-EOL + CREATE DATABASE '$FIREBIRD_DATABASE' + $user_and_password + $page_size + $default_charset; + EXIT; + EOL + + init_db /docker-entrypoint-initdb.d/* + fi + fi +} + +sigint_handler() { + echo "Stopping Firebird... [SIGINT received]" +} + +sigterm_handler() { + echo "Stopping Firebird... [SIGTERM received]" +} + +run_daemon_and_wait() { + # Traps SIGINT (handles Ctrl-C in interactive mode) + trap sigint_handler SIGINT + + # Traps SIGTERM (polite shutdown) + trap sigterm_handler SIGTERM + + # Firebird version + echo -n 'Starting ' + /opt/firebird/bin/firebird -z + + # Run fbguard and wait + /opt/firebird/bin/fbguard & + wait $! +} + + + +# +# main() +# +if [ "$1" = 'firebird' ]; then + set_config + set_sysdba + + create_user + create_db + + run_daemon_and_wait +else + exec "$@" +fi