feat: implement license platform business flows and delivery tooling
Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation. Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
22
scripts/restore-delivery.sh
Normal file
22
scripts/restore-delivery.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Restore only into an explicitly empty isolated database/private directory. Never restores signing keys.
|
||||
: "${MYSQL_HOST:?set MYSQL_HOST}"; : "${MYSQL_USER:?set MYSQL_USER}"; : "${MYSQL_PASSWORD_FILE:?set protected MYSQL_PASSWORD_FILE}"; : "${MYSQL_DATABASE:?set MYSQL_DATABASE}"
|
||||
: "${PACKAGE_STORAGE_ROOT:?set PACKAGE_STORAGE_ROOT for the empty private target directory}"; : "${BACKUP_DIR:?set BACKUP_DIR containing delivery-*/mysql.sql and packages.tar}"
|
||||
: "${CONFIRM_EMPTY_RESTORE:?set CONFIRM_EMPTY_RESTORE=YES after independently verifying isolation}"
|
||||
[ "$CONFIRM_EMPTY_RESTORE" = YES ] || { echo 'CONFIRM_EMPTY_RESTORE must be YES' >&2; exit 1; }
|
||||
case "$PACKAGE_STORAGE_ROOT" in /*) ;; *) echo 'PACKAGE_STORAGE_ROOT must be absolute' >&2; exit 1;; esac
|
||||
[ -d "$PACKAGE_STORAGE_ROOT" ] || { echo 'target package directory must exist' >&2; exit 1; }
|
||||
[ -z "$(find "$PACKAGE_STORAGE_ROOT" -mindepth 1 -print -quit)" ] || { echo 'target package directory must be empty' >&2; exit 1; }
|
||||
backup=$(find "$BACKUP_DIR" -mindepth 1 -maxdepth 1 -type d -name 'delivery-*' -exec test -f '{}/mysql.sql' \; -print | sort | tail -1)
|
||||
[ -n "$backup" ] || { echo 'no backup found' >&2; exit 1; }
|
||||
(cd "$backup" && sha256sum -c SHA256SUMS)
|
||||
case "$MYSQL_DATABASE" in ''|*[!a-zA-Z0-9_]*) echo 'MYSQL_DATABASE must be an ASCII identifier' >&2; exit 1;; esac
|
||||
export MYSQL_PWD=$(cat "$MYSQL_PASSWORD_FILE")
|
||||
trap 'unset MYSQL_PWD' EXIT HUP INT TERM
|
||||
count=$(mysql --host="$MYSQL_HOST" --port="${MYSQL_PORT:-3306}" --user="$MYSQL_USER" --batch --skip-column-names "$MYSQL_DATABASE" -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '$MYSQL_DATABASE'")
|
||||
[ "$count" = 0 ] || { echo 'target database must exist and be empty' >&2; exit 1; }
|
||||
mysql --host="$MYSQL_HOST" --port="${MYSQL_PORT:-3306}" --user="$MYSQL_USER" "$MYSQL_DATABASE" < "$backup/mysql.sql"
|
||||
unset MYSQL_PWD
|
||||
tar -C "$PACKAGE_STORAGE_ROOT" -xf "$backup/packages.tar"
|
||||
printf '%s\n' 'Restore completed without restoring signing keys. Run explicit migrations/version checks and release/object checksum verification before traffic.'
|
||||
Reference in New Issue
Block a user