summaryrefslogtreecommitdiff
path: root/util/board_status/to-wiki/push-to-wiki.sh
blob: ad339931e5556e36cd0732cb9de6e538f3d1e7e9 (plain)
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
77
78
79
80
81
82
#!/bin/bash
# $1: file containing text

. ~/.wikiaccount
WIKIAPI="http://www.coreboot.org/api.php"
TITLE="Supported_Motherboards"
cookie_jar="/tmp/wikicookiejar"
#Will store file in wikifile

#################login
#Login part 1
CR=$(curl -sS \
        --location \
        --retry 2 \
        --retry-delay 5\
        --cookie $cookie_jar \
        --cookie-jar $cookie_jar \
        --user-agent "Curl Shell Script" \
        --keepalive-time 60 \
        --header "Accept-Language: en-us" \
        --header "Connection: keep-alive" \
        --compressed \
        --data-urlencode "lgname=${USERNAME}" \
        --data-urlencode "lgpassword=${USERPASS}" \
        --request "POST" "${WIKIAPI}?action=login&format=txt")

CR2=($CR)
if [ "${CR2[9]}" = "[token]" ]; then
        TOKEN=${CR2[11]}
else
        exit
fi

#Login part 2
CR=$(curl -sS \
        --location \
        --cookie $cookie_jar \
    --cookie-jar $cookie_jar \
        --user-agent "Curl Shell Script" \
        --keepalive-time 60 \
        --header "Accept-Language: en-us" \
        --header "Connection: keep-alive" \
        --compressed \
        --data-urlencode "lgname=${USERNAME}" \
        --data-urlencode "lgpassword=${USERPASS}" \
        --data-urlencode "lgtoken=${TOKEN}" \
        --request "POST" "${WIKIAPI}?action=login&format=txt")

###############
#Get edit token
CR=$(curl -sS \
        --location \
        --cookie $cookie_jar \
        --cookie-jar $cookie_jar \
        --user-agent "Curl Shell Script" \
        --keepalive-time 60 \
        --header "Accept-Language: en-us" \
        --header "Connection: keep-alive" \
        --compressed \
        --request "POST" "${WIKIAPI}?action=tokens&format=txt")

CR2=($CR)
EDITTOKEN=${CR2[8]}
if [ ${#EDITTOKEN} != 34 ]; then
        exit
fi
#########################

CR=$(curl -sS \
        --location \
        --cookie $cookie_jar \
        --cookie-jar $cookie_jar \
        --user-agent "Curl Shell Script" \
        --keepalive-time 60 \
        --header "Accept-Language: en-us" \
        --header "Connection: keep-alive" \
        --header "Expect:" \
        --form "token=${EDITTOKEN}" \
        --form "title=${TITLE}" \
        --form "text=<$1" \
        --request "POST" "${WIKIAPI}?action=edit&")