| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # Colors for output |
| 5 | RED='\033[0;31m' |
| 6 | GREEN='\033[0;32m' |
| 7 | YELLOW='\033[1;33m' |
| 8 | GRAY='\033[0;90m' |
| 9 | NC='\033[0m' # No Color |
| 10 | |
| 11 | # Execute command with visibility |
| 12 | run() { |
| 13 | # Print the command being executed |
| 14 | printf >&2 "${GRAY}$(pwd) >${NC} " |
| 15 | printf >&2 "${YELLOW}" |
| 16 | printf >&2 "%q " "$@" |
| 17 | printf >&2 "${NC}\n" |
| 18 | |
| 19 | # Execute the command |
| 20 | if ! "$@"; then |
| 21 | local exit_code=$? |
| 22 | echo -e >&2 "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 23 | echo -e >&2 "${RED}[ERROR]${NC} Command failed with exit code ${exit_code}: ${YELLOW}$1${NC}" |
| 24 | echo -e >&2 "${RED} Full command:${NC} $*" |
| 25 | echo -e >&2 "${RED} Working dir:${NC} $(pwd)" |
| 26 | echo -e >&2 "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 27 | return $exit_code |
| 28 | fi |
| 29 | } |
| 30 | |
| 31 | if [ -x /opt/mssql-tools18/bin/sqlcmd ]; then |
| 32 | run /opt/mssql-tools18/bin/sqlcmd -C -S mssql -U sa -P "${MSSQL_SA_PASSWORD}" -i /seed/init.sql |
| 33 | else |
| 34 | run /opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P "${MSSQL_SA_PASSWORD}" -i /seed/init.sql |
| 35 | fi |