2013-12-05 18:11:33 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# $1: file containing text
|
2014-08-10 19:06:45 +02:00
|
|
|
|
2013-12-05 18:11:33 +01:00
|
|
|
. ~/.wikiaccount
|
|
|
|
WIKIAPI="http://www.coreboot.org/api.php"
|
|
|
|
TITLE="Supported_Motherboards"
|
2016-02-19 10:19:39 +01:00
|
|
|
cookie_jar="$HOME/.wikicookiejar"
|
2013-12-05 18:11:33 +01:00
|
|
|
#Will store file in wikifile
|
2014-08-10 19:06:45 +02:00
|
|
|
|
2013-12-05 18:11:33 +01:00
|
|
|
#################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}" \
|
2015-03-01 21:25:59 +01:00
|
|
|
--request "POST" "${WIKIAPI}?action=login&format=json")
|
2014-08-10 19:06:45 +02:00
|
|
|
|
2015-03-01 21:25:59 +01:00
|
|
|
TOKEN=`echo $CR| sed -e 's,^.*"token":"\([^"]*\)".*$,\1,'`
|
|
|
|
if [ -z "$TOKEN" ]; then
|
2013-12-05 18:11:33 +01:00
|
|
|
exit
|
|
|
|
fi
|
2014-08-10 19:06:45 +02:00
|
|
|
|
2013-12-05 18:11:33 +01:00
|
|
|
#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}" \
|
2015-03-01 21:25:59 +01:00
|
|
|
--request "POST" "${WIKIAPI}?action=login&format=json")
|
2014-08-10 19:06:45 +02:00
|
|
|
|
2013-12-05 18:11:33 +01:00
|
|
|
###############
|
|
|
|
#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 \
|
2015-03-01 21:25:59 +01:00
|
|
|
--request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json")
|
2014-08-10 19:06:45 +02:00
|
|
|
|
2015-03-01 21:25:59 +01:00
|
|
|
EDITTOKEN=`echo $CR| sed -e 's,^.*"csrftoken":"\([^"]*\)".*$,\1,'`
|
|
|
|
EDITTOKEN=`printf "$EDITTOKEN"`
|
2013-12-05 18:11:33 +01:00
|
|
|
if [ ${#EDITTOKEN} != 34 ]; then
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
#########################
|
2014-08-10 19:06:45 +02:00
|
|
|
|
2013-12-05 18:11:33 +01:00
|
|
|
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&")
|