-
Notifications
You must be signed in to change notification settings - Fork 9
/
e5.sh
78 lines (61 loc) · 3.78 KB
/
e5.sh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# this script is called by cron job to renew the microsoft e5 automatically
#get accessToken
echo "1.start to get accessToken"
accessToken=`curl -s -XPOST -H 'Content-Type: application/x-www-form-urlencoded' -T ~/body.txt 'https://login.microsoftonline.com/common/oauth2/v2.0/token'|awk -F',' '{print $5}'|awk -F'"' '{print $4}'`
echo "1.accessToken got "$accessToken
#use the token to get the email subject and count all of emails
echo "2.start to get email subject"
curl -XGET -H "Authorization: Bearer $accessToken" 'https://graph.microsoft.com/v1.0/me/messages?$select=subject&$count=true'
echo "2.end to get email subject"
#get drive id
echo "3.start to get driveId"
driveId=`curl -s -XGET -H "Authorization: Bearer $accessToken" 'https://graph.microsoft.com/v1.0/me/drive?$select=id'|awk -F',' '{print $2}'|awk -F'"' '{print $4}'`
echo "3.driveId is"$driveId
#get top 5 items in vps folder and only get their name item
echo "4.start to get top 5 items in vps folder"
curl -XGET -H "Authorization: Bearer $accessToken" 'https://graph.microsoft.com/v1.0/me/drive/root:/vps:/children?$top=5&$select=name'
echo "4.end to get top 5 items in vps folder"
#search items - be careful with the escape character
echo "5.start to search keyword ap-700"
curl -XGET -H "Authorization: Bearer $accessToken" 'https://graph.microsoft.com/v1.0/me/drive/root/search(q='\'ap-700\'')?$select=id,name,size,file'
echo "5.end to search keyword ap-700"
#This url is to upload file
#curl -XPUT -H "Authorization: Bearer $accessToken" -T body.txt 'https://graph.microsoft.com/v1.0/me/drive/root:/body.txt:/content'
#upload file body.txt to / and get the item id
echo "6.start to upload file body.txt to od"
itemId=`curl -s -XPUT -H "Authorization: Bearer $accessToken" -T ~/body.txt 'https://graph.microsoft.com/v1.0/me/drive/root:/body.txt:/content'|awk -F',' '{print $6}'|awk -F'"' '{print $4}'`
echo "6.end to upload, the itemId is "$itemId
#get item info by itemId
echo "7.1 start to get the item info by itemId"
curl -XGET -H "Authorization: Bearer $accessToken" "https://graph.microsoft.com/v1.0/me/drive/items/$itemId"
echo "7.1 end to get the item info by itemId"
#get item info by driveId and itemId
echo "7.2 start to get the item info by itemId"
curl -XGET -H "Authorization: Bearer $accessToken" "https://graph.microsoft.com/v1.0/me/drives/$driveId/items/$itemId"
echo "7.2 end to get the item info by itemId"
#delete file body.txt from /
echo "8.start to delete the file body.txt"
curl -XDELETE -H "Authorization: Bearer $accessToken" "https://graph.microsoft.com/v1.0/me/drive/items/$itemId"
echo "8.end to delete the file body.txt"
##########################################
# OneNote API
##########################################
#get the onenote sections
echo "9.start to get the onenote sections"
curl -XGET -H "Authorization: Bearer $accessToken" 'https://graph.microsoft.com/v1.0/me/onenote/sections?$select=id,displayName'
echo "9.end to get the onenote sections"
#get the onenote pages
echo "10.start to get the onenote pages"
curl -XGET -H "Authorization: Bearer $accessToken" 'https://graph.microsoft.com/v1.0/me/onenote/pages?$select=id,title'
echo "10.end to get the onenote pages"
#Create onenote page
echo "11.start to create onenoete page"
pageId=`curl -s -XPOST -H 'Content-Type: text/html' -H "Authorization: Bearer $accessToken" -T ~/body.txt 'https://graph.microsoft.com/v1.0/me/onenote/sections/1-59113c3c-2e93-4951-be71-bac8add02ac0/pages'|awk -F',' '{print $2}'|awk -F'"' '{print $4}'`
echo "11.New Page id is "$pageId
#delete onenote page
echo "12.start to delete the page by id"
curl -XDELETE -H "Authorization: Bearer $accessToken" "https://graph.microsoft.com//v1.0/me/onenote/pages/$pageId"
echo "12.end to delete the page by id"