diff options
author | kaa <kaa@disroot.org> | 2023-11-25 12:40:23 -0800 |
---|---|---|
committer | kaa <kaa@disroot.org> | 2023-11-25 12:40:23 -0800 |
commit | 06b553ab3f6355e643049dad0ccb570a0bc0d613 (patch) | |
tree | ef758a08c2dea66085f11c333984f5e96d4ab444 /old/dump.sh | |
parent | 3df21ef899aafd2461570687ef3b9b1c9f9a555e (diff) |
Diffstat (limited to 'old/dump.sh')
-rwxr-xr-x | old/dump.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/old/dump.sh b/old/dump.sh new file mode 100755 index 0000000..bc50cfb --- /dev/null +++ b/old/dump.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ -z $CANKEY ] +then + echo Provide an API key in the environment variable CANKEY. + return 1 +fi +if ! [ -d dump ] +then + mkdir dump +fi +cd dump +base=https://sdccd.instructure.com/api/v1/ +process_json() +{ + jq -M +} +get() +{ + url=$base$1 + curl -s -X GET "$url" -H "Authorization: Bearer $CANKEY" | jq -M +} + +get users/self/folders > folders +get users/self/files > files + +get_id() +{ + < folders sed -e 's/,.*//g' -e 's/.*://g' +} +get_name() +{ + < folders grep id.:$1 | sed -e 's/.*name":"//' -e 's/",.*//' +} + +# Recursively resolve directories and files. +# Empty response: [] +get_dir() +{ + id=$1 + name=$2 + echo $id + mkdir $id + cd $id + echo $name > name + get folders/$id/files > files + get folders/$id/folders > folders + for i in $(get_id) + do + get_dir $i "$(get_name $i)" + done + cd .. +} + +for i in $(get_id) +do + get_dir $i +done |