diff options
author | Nicolás Reynolds <apoyosis@correo.inta.gob.ar> | 2012-11-13 13:34:54 -0300 |
---|---|---|
committer | Nicolás Reynolds <apoyosis@correo.inta.gob.ar> | 2012-11-13 13:34:54 -0300 |
commit | 359b99f193cb2c3b0ea7cad66080c1e81125afb1 (patch) | |
tree | e03f36b1af48bbcdcfe662695cd60d905253786a /pcr/aurvote | |
parent | b669c4d23e5797b4bfdd78908fa162caf202ad6f (diff) | |
parent | cf319581703bfe2836e7df909dd5f9c0ab0d54e5 (diff) | |
download | abslibre-359b99f193cb2c3b0ea7cad66080c1e81125afb1.tar.gz abslibre-359b99f193cb2c3b0ea7cad66080c1e81125afb1.tar.bz2 abslibre-359b99f193cb2c3b0ea7cad66080c1e81125afb1.zip |
Merge branch 'master' of ssh://gparabola/srv/git/abslibre
Diffstat (limited to 'pcr/aurvote')
-rw-r--r-- | pcr/aurvote/PKGBUILD | 18 | ||||
-rwxr-xr-x | pcr/aurvote/aurvote | 193 |
2 files changed, 211 insertions, 0 deletions
diff --git a/pcr/aurvote/PKGBUILD b/pcr/aurvote/PKGBUILD new file mode 100644 index 000000000..4dcf8d3d2 --- /dev/null +++ b/pcr/aurvote/PKGBUILD @@ -0,0 +1,18 @@ +# Maintainer: tuxce <tuxce.net@gmail.com> +# Maintainer: Parabola GNU / Linux-libre Aurelien Desbrieres <aurelien@cwb.io> + +pkgname=aurvote +pkgver=1.4 +pkgrel=1 +pkgdesc="Tool to vote for favorite AUR packages" +url="http://git.archlinux.fr/aurvote.git/" +license="GPL" +arch=('any') +depends=('curl') +source=($pkgname) + +build() { + install -D -m 755 "$srcdir/$pkgname" "$pkgdir/usr/bin/$pkgname" +} + +md5sums=('57f2f0822b833f6c858526eb7c8bb85f') diff --git a/pcr/aurvote/aurvote b/pcr/aurvote/aurvote new file mode 100755 index 000000000..1b9c8f1bf --- /dev/null +++ b/pcr/aurvote/aurvote @@ -0,0 +1,193 @@ +#!/bin/bash +# +# aurvote : Tool to vote for favorite AUR packages +# +# Copyright (c) 2007-2010 Julien MISCHKOWITZ <wain@archlinux.fr> +# Copyright (c) 2011 tuxce <tuxce.net@gmail.com> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Library General Public License as published +# by the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +NAME='aurvote' +VERSION=1.4 + +TMPDIR=${TMPDIR:-/tmp} +AV_TMP="$TMPDIR/aurvote-$USER" + +CONFIGFILE=${XDG_HOME_CONFIG:-~/.config}/aurvote + +AUR_URL="https://aur.archlinux.org" +AUR_URL_LOGIN="$AUR_URL/login/" +AUR_URL_PKG_INFO="$AUR_URL/rpc.php" +AUR_URL_PKG_PAGE="$AUR_URL/packages/" +AUR_DOMAIN="aur.archlinux.org" +AUR_COOKIE="AURSID" +AUR_COOKIE_VALUE="" +AUR_SETLANG="?setlang=en" + + +version() { + echo "$NAME $VERSION" +} + +usage() { + echo "$NAME $VERSION" + echo + echo "usage: $0 <option> <pkgname1> <pkgname2> ..." + echo + echo " --version, -V shows version" + echo " --help, -h shows this help" + echo " --check, -c check for voted packages" + echo " --vote, -v vote for packages" + echo " --unvote, -u unvote packages" + echo + echo " --configure create $CONFIGFILE" + echo +} + +error() { + echo -e "Error: $*" + exit 1 +} + +is_cookie_valid() { + [[ -r $COOKIE_FILE ]] || return 1 + local expire + expire=$(sed -ne '/^\(#HttpOnly_\|[^#]\)/ { s/#HttpOnly_//;p }' "$COOKIE_FILE" | + awk "{ if (\$1==\"$AUR_DOMAIN\" && \$6==\"$AUR_COOKIE\") print \$5\" \"\$7; }") + AUR_COOKIE_VALUE=${expire##* } + expire=${expire%% *} + [[ $expire ]] && { ((expire==0)) || ((expire>$(date +%s))); } +} + +aur_login() { + local args=() + if ((PERSIST)); then + is_cookie_valid && return 0 + args=(-d "remember_me=on") + fi + if [[ ! $user || ! $pass ]]; then + error "$CONFIGFILE must have user name and password. Run:\n$NAME --configure" + fi + curl $CURL_OPT -L -fs -c "$COOKIE_FILE" "${args[@]}" -d "user=$user" \ + --data-urlencode "passwd=$pass" "$AUR_URL_LOGIN" \ + -o "$AV_TMP/login" || error "Unable to access $AUR_URL_LOGIN" + err=$(sed -ne 's/.*ul class="errorlist"><li>\([^<]*\)<.*/\1/p' "$AV_TMP/login") + [[ $err ]] && error "$err" +} + +aur_check_vote() { + local pkg + for pkg in "${pkgnames[@]}"; do + curl $CURL_OPT -fs -b "$COOKIE_FILE" \ + "${AUR_URL_PKG_PAGE}${pkg}${AUR_SETLANG}" \ + -o "$AV_TMP/$pkg.$PID" || + error "Unable to get $pkg page" + if sed '/<div id="news">/q' "$AV_TMP/$pkg.$PID" | grep -q /unvote/; then + echo "already voted" + elif sed '/<div id="news">/q' "$AV_TMP/$pkg.$PID" | grep -q /vote/; then + echo "not voted" + else + echo "voted status not found" + fi + done +} + + +aur_vote() { + local pkg + (($1)) && vote="/vote/" || vote="/unvote/" + for pkg in "${pkgnames[@]}"; do + curl $CURL_OPT -fs -b "$COOKIE_FILE" \ + "${AUR_URL_PKG_PAGE}${pkg}${vote}" -o /dev/null + if (($?)); then + echo "Error: Can't (un)vote for $pkg" + else + echo "$pkg : vote changed" + fi + done +} + +create_config_file() { + local ans + if [[ -f "$CONFIGFILE" ]]; then + read -p "$CONFIGFILE exists. Replace ? [y/N] " ans + [[ $ans != 'Y' && $ans != 'y' ]] && return 0 + fi + echo -n > "$CONFIGFILE" + if [[ ! -r "$CONFIGFILE" ]]; then + error "Unable to create $CONFIGFILE" + fi + echo "Creation of $CONFIGFILE" + read -p "AUR User : " ans + printf "user=%q\n" "$ans" >> "$CONFIGFILE" + read -p "AUR Password : " ans + printf "pass=%q\n" "$ans" >> "$CONFIGFILE" + read -p "Persistent login ? [Y/n] " ans + [[ $ans = 'n' || $ans = 'N' ]] && return 0 + read -p "Path to the cookie file : [/var/tmp/aurvote-$USER.cookie] ? " ans + printf "COOKIE_FILE=%q\n" "${ans:-/var/tmp/aurvote-$USER.cookie}" >> "$CONFIGFILE" + echo + echo "Creation complete." +} + +### MAIN PROGRAM ### +umask 077 +[[ -d "$AV_TMP" ]] || mkdir -p "$AV_TMP" +[[ -d "$AV_TMP" && -w "$AV_TMP" ]] || error "Cannot access to $AV_TMP" +PID=$$ +ACTION="vote" +pkgnames=() +CURL_OPT="" +PERSIST=0 + +[[ -r "$CONFIGFILE" ]] && source "$CONFIGFILE" + +[[ $COOKIE_FILE ]] && PERSIST=1 + +while [[ $1 ]]; do + case $1 in + --help|-h) usage; exit 0;; + --version|-V) version; exit 0;; + --check|-c) ACTION="check";; + --configure) ACTION="configure";; + --vote|-v) ACTION="vote";; + --unvote|-u) ACTION="unvote";; + --id) ;; # deprecated + --insecure) CURL_OPT+=" --insecure";; + -k) PERSIST=1; shift; COOKIE_FILE="$1";; + --*|-*) usage; exit 1;; + *) pkgnames+=("$1");; + esac + shift +done + +if [[ $ACTION = "configure" ]]; then + create_config_file + exit 0 +fi + +COOKIE_FILE=${COOKIE_FILE:-"$AV_TMP/cookies"} +pkgnames=("${pkgnames[@]%/*}") # compatibility with yaourt <= 1.2.1 +[[ ! $pkgnames ]] && usage && exit 1 + +aur_login + +case "$ACTION" in + check) aur_check_vote;; + vote) aur_vote 1;; + unvote) aur_vote 0;; +esac + +# vim: set ts=4 sw=4 et: |