DB_PATH="./backend/data/pocket-id.db" DB_PROVIDER="${DB_PROVIDER:=sqlite}" USER_IDENTIFIER="$1" # Parse command-line arguments for the -d flag (database path) while getopts ":d:" opt; do case $opt in d) DB_PATH="$OPTARG" ;; \?) echo "Invalid option -$OPTARG" >&2 exit 1 ;; esac done shift $((OPTIND - 1)) # Ensure username or email is provided as a parameter if [ -z "$1" ]; then echo "Usage: $0 [-d ] " if [ "$DB_PROVIDER" == "sqlite" ]; then echo "-d (optional): Path to the SQLite database file. Default: $DB_PATH" fi exit 1 fi # Check and try to install the required commands check_and_install() { local cmd=$1 local pkg=$2 if ! command -v "$cmd" &>/dev/null; then if command -v apk &>/dev/null; then echo "$cmd not found. Installing..." apk add "$pkg" --no-cache else echo "$cmd is not installed, please install it manually." exit 1 fi fi } check_and_install uuidgen uuidgen if [ "$DB_PROVIDER" == "postgres" ]; then check_and_install psql postgresql-client elif [ "$DB_PROVIDER" == "sqlite" ]; then check_and_install sqlite3 sqlite fi # Generate a 16-character alphanumeric secret token SECRET_TOKEN=$(LC_ALL=C tr -dc 'A-Za-z0-9' }/login/$SECRET_TOKEN" else echo "Error creating access token." exit 1 fi echo "================================================="