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
DB_PATH="./backend/data/pocket-id.db"
@@ -27,16 +25,24 @@ fi
USER_IDENTIFIER="$1"
# Check if sqlite3 is installed, if not install it via apk
if ! command -v sqlite3 &>/dev/null; then
# 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 "sqlite3 not found. Installing..."
apk add sqlite3 --no-cache
echo "$cmd not found. Installing..."
apk add "$pkg" --no-cache
else
echo "sqlite3 is not installed, please install it manually."
echo "$cmd is not installed, please install it manually."
exit 1
fi
fi
}
check_and_install sqlite3 sqlite
check_and_install uuidgen uuidgen
# Generate a 16-character alphanumeric secret token
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
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
echo "Error creating access token."
exit 1