Skip to content

Commit

Permalink
Merge pull request nightscout#3 from tzachi-dar/vps-1
Browse files Browse the repository at this point in the history
Allow to clone repositories that are protected by tokens.
  • Loading branch information
jamorham authored Sep 20, 2022
2 parents 732e8bf + 9bfc1c8 commit 89f568b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions clone_nightscout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
clone_collection() {
REST_ENDPOINT=$1
collection_name=$2
read_token=$3
echo $REST_ENDPOINT
if [[ $collection_name == entries ]]; then
wget $REST_ENDPOINT/api/v1/$collection_name'.json?find[date][$gte]=1662845659&count=1000000' -O /tmp/$collection_name.json
wget $REST_ENDPOINT/api/v1/$collection_name'.json?find[date][$gte]=1662845659&count=1000000'$read_token -O /tmp/$collection_name.json
else
wget $REST_ENDPOINT/api/v1/$collection_name'.json?find[created_at][$gte]=1662845659&count=1000000' -O /tmp/$collection_name.json
wget $REST_ENDPOINT/api/v1/$collection_name'.json?find[created_at][$gte]=1662845659&count=1000000'$read_token -O /tmp/$collection_name.json
fi
jq '.[]' /tmp/$collection_name.json > /tmp/$collection_name.jq.json
mongoimport --uri "mongodb://username:password@localhost:27017/Nightscout" --mode=upsert --collection=$collection_name --file=/tmp/$collection_name.jq.json
Expand All @@ -16,9 +17,10 @@ clone_collection() {

clone_collections() {
REST_ENDPOINT=$1
read_token=$2
for collection in entries activity devicestatus food profile treatments;
do echo cloning "<$collection>";
clone_collection $1 $collection
clone_collection $REST_ENDPOINT $collection $read_token
done
}

Expand All @@ -36,17 +38,24 @@ do
echo "yes"
rest_endpoint=${rest_endpoint::-1}
fi


read -rep "If you have a read token, enter it now. For example: read-c9b67850b67acf82"$'\n'"If you don't know use a token press enter."$'\n'"read_token:" read_token
if [[ ! -z "$read_token" ]]
then
echo "Token exists"
read_token="&token="$read_token
fi

# do a sanity check before actually starting to copy.
wget $rest_endpoint/api/v1/entries'.json?find[date][$gte]=1662845659&count=1' -O /tmp/entries.json
wget $rest_endpoint/api/v1/entries'.json?find[date][$gte]=1662845659&count=1'$read_token -O /tmp/entries.json
ret_code=$?
if [ ! $ret_code = 0 ]; then
echo "Accesseing site " $rest_endpoint "failed, please try again, enter to skip."
continue;
fi

echo Startint to copy $rest_endpoint
clone_collections $rest_endpoint
clone_collections $rest_endpoint $read_token
exit 0

done
Expand Down

0 comments on commit 89f568b

Please sign in to comment.