From ee9a7df69bc39d95f68c6f4c47622d045286b09e Mon Sep 17 00:00:00 2001 From: Ahmed alaa Date: Fri, 21 Mar 2025 01:24:42 +0200 Subject: [PATCH] feat: fix find token script --- scripts/find-token.sh | 45 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/scripts/find-token.sh b/scripts/find-token.sh index 3b162def9e..ded75b85f4 100644 --- a/scripts/find-token.sh +++ b/scripts/find-token.sh @@ -1,14 +1,27 @@ #!/bin/sh # Searches for app token within source files. +JSON_APP_TOKEN=$( + grep "app_token" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=instabug.json ./ | + sed 's/[[:space:]]//g' | + grep -o ":[\"\'][0-9a-zA-Z]*[\"\']" | + cut -d ":" -f 2 | + cut -d "\"" -f 2 | + cut -d "'" -f 2 +) + +if [ ! -z "${JSON_APP_TOKEN}" ]; then + echo $JSON_APP_TOKEN + exit 0 +fi INIT_APP_TOKEN=$( grep "Instabug.init({" -r -A 6 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.{js,ts,jsx,tsx} ./ | - grep "token:[[:space:]]*[\"\'][0-9a-zA-Z]*[\"\']" | + grep "token[[:space:]]*:[[:space:]]*[\"\'][0-9a-zA-Z]*[\"\']" | grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2 -) +) if [ ! -z "${INIT_APP_TOKEN}" ]; then echo $INIT_APP_TOKEN @@ -20,12 +33,38 @@ START_APP_TOKEN=$( grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2 -) +) if [ ! -z "${START_APP_TOKEN}" ]; then echo $START_APP_TOKEN exit 0 fi +ENV_APP_TOKEN=$( + grep "INSTABUG_APP_TOKEN" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.env ./ | + sed 's/[[:space:]]//g' | + grep -o "INSTABUG_APP_TOKEN=.*" | + cut -d "=" -f 2 +) + +if [ ! -z "${ENV_APP_TOKEN}" ]; then + echo $ENV_APP_TOKEN + exit 0 +fi + +CONSTANTS_APP_TOKEN=$( + grep "INSTABUG_APP_TOKEN" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.{js,ts,jsx,tsx} ./ | + sed 's/[[:space:]]//g' | + grep -o "=[\"\'][0-9a-zA-Z]*[\"\']" | + cut -d "=" -f 2 | + cut -d "\"" -f 2 | + cut -d "'" -f 2 +) + +if [ ! -z "${CONSTANTS_APP_TOKEN}" ]; then + echo $CONSTANTS_APP_TOKEN + exit 0 +fi + echo "Couldn't find Instabug's app token" exit 1