blob: ad339931e5556e36cd0732cb9de6e538f3d1e7e9 [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}" \
25 --request "POST" "${WIKIAPI}?action=login&format=txt")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020026
Patrick Georgi274c6c22013-12-05 18:11:33 +010027CR2=($CR)
28if [ "${CR2[9]}" = "[token]" ]; then
29 TOKEN=${CR2[11]}
30else
31 exit
32fi
Patrick Georgi466ea0c2014-08-10 19:06:45 +020033
Patrick Georgi274c6c22013-12-05 18:11:33 +010034#Login part 2
35CR=$(curl -sS \
36 --location \
37 --cookie $cookie_jar \
38 --cookie-jar $cookie_jar \
39 --user-agent "Curl Shell Script" \
40 --keepalive-time 60 \
41 --header "Accept-Language: en-us" \
42 --header "Connection: keep-alive" \
43 --compressed \
44 --data-urlencode "lgname=${USERNAME}" \
45 --data-urlencode "lgpassword=${USERPASS}" \
46 --data-urlencode "lgtoken=${TOKEN}" \
47 --request "POST" "${WIKIAPI}?action=login&format=txt")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020048
Patrick Georgi274c6c22013-12-05 18:11:33 +010049###############
50#Get edit token
51CR=$(curl -sS \
52 --location \
53 --cookie $cookie_jar \
54 --cookie-jar $cookie_jar \
55 --user-agent "Curl Shell Script" \
56 --keepalive-time 60 \
57 --header "Accept-Language: en-us" \
58 --header "Connection: keep-alive" \
59 --compressed \
60 --request "POST" "${WIKIAPI}?action=tokens&format=txt")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020061
Patrick Georgi274c6c22013-12-05 18:11:33 +010062CR2=($CR)
63EDITTOKEN=${CR2[8]}
64if [ ${#EDITTOKEN} != 34 ]; then
65 exit
66fi
67#########################
Patrick Georgi466ea0c2014-08-10 19:06:45 +020068
Patrick Georgi274c6c22013-12-05 18:11:33 +010069CR=$(curl -sS \
70 --location \
71 --cookie $cookie_jar \
72 --cookie-jar $cookie_jar \
73 --user-agent "Curl Shell Script" \
74 --keepalive-time 60 \
75 --header "Accept-Language: en-us" \
76 --header "Connection: keep-alive" \
77 --header "Expect:" \
78 --form "token=${EDITTOKEN}" \
79 --form "title=${TITLE}" \
80 --form "text=<$1" \
81 --request "POST" "${WIKIAPI}?action=edit&")
Patrick Georgi466ea0c2014-08-10 19:06:45 +020082