Use more secure HTTPS URLs for coreboot sites
[coreboot.git] / util / board_status / to-wiki / push-to-wiki.sh
blob6ad3c4a3f82e71ed013615cb5733d367cceaa798
1 #!/bin/bash
2 # $1: file containing text
3 # $2: wiki page to update
5 . ~/.wikiaccount
6 WIKIAPI="https://www.coreboot.org/api.php"
7 TITLE="$2"
8 cookie_jar="$HOME/.wikicookiejar"
9 #Will store file in wikifile
11 #################login
12 #Login part 1
13 CR=$(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}" \
26 --request "POST" "${WIKIAPI}?action=login&format=json")
28 TOKEN=`echo $CR| sed -e 's,^.*"token":"\([^"]*\)".*$,\1,'`
29 if [ -z "$TOKEN" ]; then
30 exit
33 #Login part 2
34 CR=$(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}" \
46 --request "POST" "${WIKIAPI}?action=login&format=json")
48 ###############
49 #Get edit token
50 CR=$(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 \
59 --request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json")
61 EDITTOKEN=`echo $CR| sed -e 's,^.*"csrftoken":"\([^"]*\)".*$,\1,'`
62 EDITTOKEN=`printf "$EDITTOKEN"`
63 if [ ${#EDITTOKEN} != 34 ]; then
64 exit
66 #########################
68 CR=$(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&")