From 494000bf5b23862160c9c1cd2a64e49031e8079e Mon Sep 17 00:00:00 2001 From: aurelien Date: Fri, 30 May 2014 18:51:42 +0200 Subject: aurvote --- pcr/aurvote/PKGBUILD | 10 ++++------ pcr/aurvote/aurvote | 46 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 17 deletions(-) mode change 100644 => 100755 pcr/aurvote/aurvote (limited to 'pcr') diff --git a/pcr/aurvote/PKGBUILD b/pcr/aurvote/PKGBUILD index 712e5d2c4..25dd1887d 100644 --- a/pcr/aurvote/PKGBUILD +++ b/pcr/aurvote/PKGBUILD @@ -1,8 +1,8 @@ -# Maintainer (Arch): tuxce -# Maintainer: Parabola GNU / Linux-libre Aurelien Desbrieres +# Contributor: tuxce +# Maintainer : Parabola Aurélien DESBRIÈRES pkgname=aurvote -pkgver=1.4 +pkgver=1.6 pkgrel=1 pkgdesc="Tool to vote for favorite AUR packages" url="http://git.archlinux.fr/aurvote.git/" @@ -11,8 +11,6 @@ arch=('any') depends=('curl') source=($pkgname) -build() { +package() { install -D -m 755 "$srcdir/$pkgname" "$pkgdir/usr/bin/$pkgname" } - -md5sums=('57f2f0822b833f6c858526eb7c8bb85f') diff --git a/pcr/aurvote/aurvote b/pcr/aurvote/aurvote old mode 100644 new mode 100755 index 1b9c8f1bf..833267f10 --- a/pcr/aurvote/aurvote +++ b/pcr/aurvote/aurvote @@ -20,12 +20,12 @@ # NAME='aurvote' -VERSION=1.4 +VERSION=1.6 TMPDIR=${TMPDIR:-/tmp} AV_TMP="$TMPDIR/aurvote-$USER" -CONFIGFILE=${XDG_HOME_CONFIG:-~/.config}/aurvote +CONFIGFILE=${XDG_CONFIG_HOME:-~/.config}/aurvote AUR_URL="https://aur.archlinux.org" AUR_URL_LOGIN="$AUR_URL/login/" @@ -35,7 +35,7 @@ AUR_DOMAIN="aur.archlinux.org" AUR_COOKIE="AURSID" AUR_COOKIE_VALUE="" AUR_SETLANG="?setlang=en" - +AUR_TOKEN="" version() { echo "$NAME $VERSION" @@ -87,13 +87,24 @@ aur_login() { [[ $err ]] && error "$err" } +aur_get_pkg_page() { + local pkg=$1 + 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" +} + +aur_set_token() { + aur_get_pkg_page "$1" + AUR_TOKEN=$(sed -n -e '//q' "$AV_TMP/$pkg.$PID" | grep -q /unvote/; then echo "already voted" elif sed '/
/q' "$AV_TMP/$pkg.$PID" | grep -q /vote/; then @@ -106,11 +117,21 @@ aur_check_vote() { aur_vote() { - local pkg - (($1)) && vote="/vote/" || vote="/unvote/" + local pkg vote action + if (($1)); then + vote="/vote/" + action=do_Vote + else + vote="/unvote/" + action=do_UnVote + fi for pkg in "${pkgnames[@]}"; do + [[ ! $AUR_TOKEN ]] && aur_set_token "$pkg" curl $CURL_OPT -fs -b "$COOKIE_FILE" \ - "${AUR_URL_PKG_PAGE}${pkg}${vote}" -o /dev/null + "${AUR_URL_PKG_PAGE}${pkg}${vote}" \ + -d token="$AUR_TOKEN" \ + -d "$action"="(Un)Vote" \ + -o /dev/null if (($?)); then echo "Error: Can't (un)vote for $pkg" else @@ -120,7 +141,10 @@ aur_vote() { } create_config_file() { - local ans + local ans configdir=${CONFIGFILE%/*} + if [[ ! -d $configdir ]]; then + mkdir -p "$configdir" || error "Unable to create $configdir" + fi if [[ -f "$CONFIGFILE" ]]; then read -p "$CONFIGFILE exists. Replace ? [y/N] " ans [[ $ans != 'Y' && $ans != 'y' ]] && return 0 -- cgit v1.2.3