summaryrefslogtreecommitdiff
path: root/old/dump.sh
blob: bc50cfbdd09434e3f77df8fb45fab7c5986ad35a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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