blob: 58e2cbb064256e60fccd726eafa8c46fc6403121 [file] [log] [blame]
Patrick Georgi274c6c22013-12-05 18:11:33 +01001#!/bin/bash
2# $1: file containing text
Patrick Georgi2d5d552f2016-02-19 10:24:07 +01003# $2: wiki page to update
Patrick Georgi466ea0c2014-08-10 19:06:45 +02004
Patrick Georgi274c6c22013-12-05 18:11:33 +01005. ~/.wikiaccount
6WIKIAPI="http://www.coreboot.org/api.php"
Patrick Georgi2d5d552f2016-02-19 10:24:07 +01007TITLE="$2"
Patrick Georgi8a0dae62016-02-19 10:19:39 +01008cookie_jar="$HOME/.wikicookiejar"
Patrick Georgi274c6c22013-12-05 18:11:33 +01009#Will store file in wikifile
Patrick Georgi466ea0c2014-08-10 19:06:45 +020010
Patrick Georgi274c6c22013-12-05 18:11:33 +010011#################login
12#Login part 1
13CR=$(curl -sS \
14 --location \
15 --retry 2 \
16 --retry-delay 5\
17 --cookie $cookie_jar \
18 --cookie-jar $cookie_jar \
19 --user-agent "Curl Shell Script" \
20 --keepalive-time 60 \
21 --header "Accept-Language: en-us" \
22 --header "Connection: keep-alive" \
23 --compressed \
24 --data-urlencode "lgname=${USERNAME}" \
25 --data-urlencode "lgpassword=${USERPASS}" \
Patrick Georgi48e78cf2015-03-01 21:25:59 +010026 --request "POST" "${WIKIAPI}?action=login&format=json")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020027
Patrick Georgi48e78cf2015-03-01 21:25:59 +010028TOKEN=`echo $CR| sed -e 's,^.*"token":"\([^"]*\)".*$,\1,'`
29if [ -z "$TOKEN" ]; then
Patrick Georgi274c6c22013-12-05 18:11:33 +010030 exit
31fi
Patrick Georgi466ea0c2014-08-10 19:06:45 +020032
Patrick Georgi274c6c22013-12-05 18:11:33 +010033#Login part 2
34CR=$(curl -sS \
35 --location \
36 --cookie $cookie_jar \
37 --cookie-jar $cookie_jar \
38 --user-agent "Curl Shell Script" \
39 --keepalive-time 60 \
40 --header "Accept-Language: en-us" \
41 --header "Connection: keep-alive" \
42 --compressed \
43 --data-urlencode "lgname=${USERNAME}" \
44 --data-urlencode "lgpassword=${USERPASS}" \
45 --data-urlencode "lgtoken=${TOKEN}" \
Patrick Georgi48e78cf2015-03-01 21:25:59 +010046 --request "POST" "${WIKIAPI}?action=login&format=json")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020047
Patrick Georgi274c6c22013-12-05 18:11:33 +010048###############
49#Get edit token
50CR=$(curl -sS \
51 --location \
52 --cookie $cookie_jar \
53 --cookie-jar $cookie_jar \
54 --user-agent "Curl Shell Script" \
55 --keepalive-time 60 \
56 --header "Accept-Language: en-us" \
57 --header "Connection: keep-alive" \
58 --compressed \
Patrick Georgi48e78cf2015-03-01 21:25:59 +010059 --request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020060
Patrick Georgi48e78cf2015-03-01 21:25:59 +010061EDITTOKEN=`echo $CR| sed -e 's,^.*"csrftoken":"\([^"]*\)".*$,\1,'`
62EDITTOKEN=`printf "$EDITTOKEN"`
Patrick Georgi274c6c22013-12-05 18:11:33 +010063if [ ${#EDITTOKEN} != 34 ]; then
64 exit
65fi
66#########################
Patrick Georgi466ea0c2014-08-10 19:06:45 +020067
Patrick Georgi274c6c22013-12-05 18:11:33 +010068CR=$(curl -sS \
69 --location \
70 --cookie $cookie_jar \
71 --cookie-jar $cookie_jar \
72 --user-agent "Curl Shell Script" \
73 --keepalive-time 60 \
74 --header "Accept-Language: en-us" \
75 --header "Connection: keep-alive" \
76 --header "Expect:" \
77 --form "token=${EDITTOKEN}" \
78 --form "title=${TITLE}" \
79 --form "text=<$1" \
80 --request "POST" "${WIKIAPI}?action=edit&")