Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # $1: file containing text |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 3 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 4 | . ~/.wikiaccount |
| 5 | WIKIAPI="http://www.coreboot.org/api.php" |
| 6 | TITLE="Supported_Motherboards" |
| 7 | cookie_jar="/tmp/wikicookiejar" |
| 8 | #Will store file in wikifile |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 9 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 10 | #################login |
| 11 | #Login part 1 |
| 12 | CR=$(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}" \ |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 25 | --request "POST" "${WIKIAPI}?action=login&format=json") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 26 | |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 27 | TOKEN=`echo $CR| sed -e 's,^.*"token":"\([^"]*\)".*$,\1,'` |
| 28 | if [ -z "$TOKEN" ]; then |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 29 | exit |
| 30 | fi |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 31 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 32 | #Login part 2 |
| 33 | CR=$(curl -sS \ |
| 34 | --location \ |
| 35 | --cookie $cookie_jar \ |
| 36 | --cookie-jar $cookie_jar \ |
| 37 | --user-agent "Curl Shell Script" \ |
| 38 | --keepalive-time 60 \ |
| 39 | --header "Accept-Language: en-us" \ |
| 40 | --header "Connection: keep-alive" \ |
| 41 | --compressed \ |
| 42 | --data-urlencode "lgname=${USERNAME}" \ |
| 43 | --data-urlencode "lgpassword=${USERPASS}" \ |
| 44 | --data-urlencode "lgtoken=${TOKEN}" \ |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 45 | --request "POST" "${WIKIAPI}?action=login&format=json") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 46 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 47 | ############### |
| 48 | #Get edit token |
| 49 | CR=$(curl -sS \ |
| 50 | --location \ |
| 51 | --cookie $cookie_jar \ |
| 52 | --cookie-jar $cookie_jar \ |
| 53 | --user-agent "Curl Shell Script" \ |
| 54 | --keepalive-time 60 \ |
| 55 | --header "Accept-Language: en-us" \ |
| 56 | --header "Connection: keep-alive" \ |
| 57 | --compressed \ |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 58 | --request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 59 | |
Patrick Georgi | 48e78cf | 2015-03-01 21:25:59 +0100 | [diff] [blame] | 60 | EDITTOKEN=`echo $CR| sed -e 's,^.*"csrftoken":"\([^"]*\)".*$,\1,'` |
| 61 | EDITTOKEN=`printf "$EDITTOKEN"` |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 62 | if [ ${#EDITTOKEN} != 34 ]; then |
| 63 | exit |
| 64 | fi |
| 65 | ######################### |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 66 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 67 | CR=$(curl -sS \ |
| 68 | --location \ |
| 69 | --cookie $cookie_jar \ |
| 70 | --cookie-jar $cookie_jar \ |
| 71 | --user-agent "Curl Shell Script" \ |
| 72 | --keepalive-time 60 \ |
| 73 | --header "Accept-Language: en-us" \ |
| 74 | --header "Connection: keep-alive" \ |
| 75 | --header "Expect:" \ |
| 76 | --form "token=${EDITTOKEN}" \ |
| 77 | --form "title=${TITLE}" \ |
| 78 | --form "text=<$1" \ |
| 79 | --request "POST" "${WIKIAPI}?action=edit&") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame] | 80 | |