chore: improve check of required tools in one time access token script

This commit is contained in:
Elias Schneider
2024-10-23 10:50:49 +02:00
parent 824c5cb4f3
commit 0aff6181c9

View File

@@ -1,5 +1,3 @@
#!/bin/bash
# Default database path # Default database path
DB_PATH="./backend/data/pocket-id.db" DB_PATH="./backend/data/pocket-id.db"
@@ -27,16 +25,24 @@ fi
USER_IDENTIFIER="$1" USER_IDENTIFIER="$1"
# Check if sqlite3 is installed, if not install it via apk # Check and try to install the required commands
if ! command -v sqlite3 &>/dev/null; then check_and_install() {
if command -v apk &>/dev/null; then local cmd=$1
echo "sqlite3 not found. Installing..." local pkg=$2
apk add sqlite3 --no-cache
else if ! command -v "$cmd" &>/dev/null; then
echo "sqlite3 is not installed, please install it manually." if command -v apk &>/dev/null; then
exit 1 echo "$cmd not found. Installing..."
apk add "$pkg" --no-cache
else
echo "$cmd is not installed, please install it manually."
exit 1
fi
fi fi
fi }
check_and_install sqlite3 sqlite
check_and_install uuidgen uuidgen
# Generate a 16-character alphanumeric secret token # Generate a 16-character alphanumeric secret token
SECRET_TOKEN=$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 16) SECRET_TOKEN=$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 16)
@@ -62,7 +68,7 @@ EOF
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "A one-time access token valid for 1 hour has been created for \"$USER_IDENTIFIER\"." echo "A one-time access token valid for 1 hour has been created for \"$USER_IDENTIFIER\"."
echo "Use the following URL to sign in once: https://<your-pocket-id-domain>/login/$SECRET_TOKEN" echo "Use the following URL to sign in once: ${PUBLIC_APP_URL:=https://<your-pocket-id-domain>}/login/$SECRET_TOKEN"
else else
echo "Error creating access token." echo "Error creating access token."
exit 1 exit 1