blob: 1f907457025163a5ba26a535f6900bf56861edf4 [file] [log] [blame]
Patrick Georgi274c6c22013-12-05 18:11:33 +01001#!/bin/bash
2# $1: file containing text
3
4. ~/.wikiaccount
5WIKIAPI="http://www.coreboot.org/api.php"
6TITLE="Supported_Motherboards"
7cookie_jar="/tmp/wikicookiejar"
8#Will store file in wikifile
9
10#################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")
26
27CR2=($CR)
28if [ "${CR2[9]}" = "[token]" ]; then
29 TOKEN=${CR2[11]}
30else
31 exit
32fi
33
34#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")
48
49###############
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")
61
62CR2=($CR)
63EDITTOKEN=${CR2[8]}
64if [ ${#EDITTOKEN} != 34 ]; then
65 exit
66fi
67#########################
68
69CR=$(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&")
82