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}" \ |
| 25 | --request "POST" "${WIKIAPI}?action=login&format=txt") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame^] | 26 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 27 | CR2=($CR) |
| 28 | if [ "${CR2[9]}" = "[token]" ]; then |
| 29 | TOKEN=${CR2[11]} |
| 30 | else |
| 31 | exit |
| 32 | fi |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame^] | 33 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 34 | #Login part 2 |
| 35 | CR=$(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") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame^] | 48 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 49 | ############### |
| 50 | #Get edit token |
| 51 | CR=$(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") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame^] | 61 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 62 | CR2=($CR) |
| 63 | EDITTOKEN=${CR2[8]} |
| 64 | if [ ${#EDITTOKEN} != 34 ]; then |
| 65 | exit |
| 66 | fi |
| 67 | ######################### |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame^] | 68 | |
Patrick Georgi | 274c6c2 | 2013-12-05 18:11:33 +0100 | [diff] [blame] | 69 | CR=$(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&") |
Patrick Georgi | 466ea0c | 2014-08-10 19:06:45 +0200 | [diff] [blame^] | 82 | |