Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # $1: file containing text |
Patrick Georgi | 2d5d552f | 2016-02-19 10:24:07 +0100 | [diff] [blame] | 3 | # $2: wiki page to update |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 4 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 5 | . ~/.wikiaccount |
| 6 | WIKIAPI="http://www.coreboot.org/api.php" |
Patrick Georgi | 2d5d552f | 2016-02-19 10:24:07 +0100 | [diff] [blame] | 7 | TITLE="$2" |
Patrick Georgi | 8a0dae6 | 2016-02-19 10:19:39 +0100 | [diff] [blame] | 8 | cookie_jar="$HOME/.wikicookiejar" |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 9 | #Will store file in wikifile |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 10 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 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}" \ |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 26 | --request "POST" "${WIKIAPI}?action=login&format=json") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 27 | |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 28 | TOKEN=`echo $CR| sed -e 's,^.*"token":"\([^"]*\)".*$,\1,'` |
| 29 | if [ -z "$TOKEN" ]; then |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 30 | exit |
| 31 | fi |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 32 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 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}" \ |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 46 | --request "POST" "${WIKIAPI}?action=login&format=json") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 47 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 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 \ |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 59 | --request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 60 | |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 61 | EDITTOKEN=`echo $CR| sed -e 's,^.*"csrftoken":"\([^"]*\)".*$,\1,'` |
| 62 | EDITTOKEN=`printf "$EDITTOKEN"` |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 63 | if [ ${#EDITTOKEN} != 34 ]; then |
| 64 | exit |
| 65 | fi |
| 66 | ######################### |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 67 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 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&") |