Last active
January 3, 2019 20:42
-
-
Save calendee/6a923b6da511c79f7435 to your computer and use it in GitHub Desktop.
Easily Firebase user accounts without the Forge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See : https://calendee.com/2015/02/04/retrieving-all-firebase-registrations/ | |
USAGE="USAGE: collect-firebase-user-accounts.sh {file-name-prefix} {firebase-name} {forge-token}" | |
# Start at 0 | |
start=0 | |
# Firebase restricts you to 1000 | |
limit=1000 | |
# Continue until this changes to 0 | |
i=1 | |
# Use the Date and Time in the File Name | |
now=$(date +"%Y-%m-%d_%H%M") | |
# While i is not 0, loop through accounts | |
while [ $i -gt 0 ] | |
do | |
# Prefix the output file name and increment it | |
file=$1"_"$now"_"$i".json" | |
# The firebase url to download users | |
url="https://auth.firebase.com/v2/"$2"/users?token="$3"&limit="$limit"&offset="$start | |
echo "" | |
echo "Outputting $url to $file" | |
# Dump the results of the request to the file | |
curl "$url" > $file | |
# Increment the counter and starting point | |
let start=$limit*$i | |
(( i++ )) | |
# If the file has an empty users array, then we're done : "users":[] | |
result=$(grep -i "\[\]" $file) | |
if [ ! -z $result ]; then | |
echo "No more users to download" | |
echo "" | |
# Stop the while loop | |
i=0 | |
fi | |
continue | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment