summaryrefslogtreecommitdiff
path: root/dump.sh
blob: 18ed1f4f9903cf97512a4294c3516db7a04f7d48 (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
#!/bin/sh

cd dump
base=https://sdccd.instructure.com/api/v1/
get()
{
	url=$base$1
	curl -s -X GET "$url" -H "Authorization: Bearer $CANKEY"  | tr '}' '\n' | sed -e 's/{//g' -e's/\[//g' -e 's/\]//g' -e 's/^,//g'
}

get users/self/folders > folders
get users/self/files > files
fi

get_id()
{
	< folders sed -e 's/,.*//g' -e 's/.*://g'
}

# Recursively resolve directories and files.
# Empty response: []
get_dir()
{
	id=$1
	echo $id
	mkdir $id
	cd $id
	get folders/$id/files > files
	get folders/$id/folders > folders
	for i in $(get_id)
	do
		get_dir $i
	done
	cd ..
}

for i in $(get_id)
do
	get_dir $i
done