blob: 7c677269b1b1e001861b906bca840e0edd7a0931 [file] [log] [blame]
Patrick Georgi274c6c22013-12-05 18:11:33 +01001#!/bin/bash
2# $1: file containing text
Patrick Georgi466ea0c2014-08-10 19:06:45 +02003
Patrick Georgi274c6c22013-12-05 18:11:33 +01004. ~/.wikiaccount
5WIKIAPI="http://www.coreboot.org/api.php"
6TITLE="Supported_Motherboards"
7cookie_jar="/tmp/wikicookiejar"
8#Will store file in wikifile
Patrick Georgi466ea0c2014-08-10 19:06:45 +02009
Patrick Georgi274c6c22013-12-05 18:11:33 +010010#################login
11#Login part 1
12CR=$(curl -sS \
13 --location \
14 --retry 2 \
15 --retry-delay 5\
16 --cookie $cookie_jar \
17 --cookie-jar $cookie_jar \
18 --user-agent "Curl Shell Script" \
19 --keepalive-time 60 \
20 --header "Accept-Language: en-us" \
21 --header "Connection: keep-alive" \
22 --compressed \
23 --data-urlencode "lgname=${USERNAME}" \
24 --data-urlencode "lgpassword=${USERPASS}" \
Patrick Georgi48e78cf2015-03-01 21:25:59 +010025 --request "POST" "${WIKIAPI}?action=login&format=json")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020026
Patrick Georgi48e78cf2015-03-01 21:25:59 +010027TOKEN=`echo $CR| sed -e 's,^.*"token":"\([^"]*\)".*$,\1,'`
28if [ -z "$TOKEN" ]; then
Patrick Georgi274c6c22013-12-05 18:11:33 +010029 exit
30fi
Patrick Georgi466ea0c2014-08-10 19:06:45 +020031
Patrick Georgi274c6c22013-12-05 18:11:33 +010032#Login part 2
33CR=$(curl -sS \
34 --location \
35 --cookie $cookie_jar \
36 --cookie-jar $cookie_jar \
37 --user-agent "Curl Shell Script" \
38 --keepalive-time 60 \
39 --header "Accept-Language: en-us" \
40 --header "Connection: keep-alive" \
41 --compressed \
42 --data-urlencode "lgname=${USERNAME}" \
43 --data-urlencode "lgpassword=${USERPASS}" \
44 --data-urlencode "lgtoken=${TOKEN}" \
Patrick Georgi48e78cf2015-03-01 21:25:59 +010045 --request "POST" "${WIKIAPI}?action=login&format=json")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020046
Patrick Georgi274c6c22013-12-05 18:11:33 +010047###############
48#Get edit token
49CR=$(curl -sS \
50 --location \
51 --cookie $cookie_jar \
52 --cookie-jar $cookie_jar \
53 --user-agent "Curl Shell Script" \
54 --keepalive-time 60 \
55 --header "Accept-Language: en-us" \
56 --header "Connection: keep-alive" \
57 --compressed \
Patrick Georgi48e78cf2015-03-01 21:25:59 +010058 --request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020059
Patrick Georgi48e78cf2015-03-01 21:25:59 +010060EDITTOKEN=`echo $CR| sed -e 's,^.*"csrftoken":"\([^"]*\)".*$,\1,'`
61EDITTOKEN=`printf "$EDITTOKEN"`
Patrick Georgi274c6c22013-12-05 18:11:33 +010062if [ ${#EDITTOKEN} != 34 ]; then
63 exit
64fi
65#########################
Patrick Georgi466ea0c2014-08-10 19:06:45 +020066
Patrick Georgi274c6c22013-12-05 18:11:33 +010067CR=$(curl -sS \
68 --location \
69 --cookie $cookie_jar \
70 --cookie-jar $cookie_jar \
71 --user-agent "Curl Shell Script" \
72 --keepalive-time 60 \
73 --header "Accept-Language: en-us" \
74 --header "Connection: keep-alive" \
75 --header "Expect:" \
76 --form "token=${EDITTOKEN}" \
77 --form "title=${TITLE}" \
78 --form "text=<$1" \
79 --request "POST" "${WIKIAPI}?action=edit&")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020080