desktop/ccr/ccr-submit
2012-04-06 14:38:30 +00:00

179 lines
4.1 KiB
Bash

#!/bin/bash
ver=0.1
tempdir=$(mktemp -d)
configrc=$HOME/.config/ccr-toolsrc
ccrbaseurl="http://chakra-linux.org/ccr/"
submiturl="${ccrbaseurl}pkgsubmit.php"
# Defining some functions needed by main program
getcat() {
declare -A categories
categories=(
["daemons"]="2"
["devel"]="3"
["editors"]="4"
["educational"]="15"
["emulators"]="5"
["games"]="6"
["gnome"]="7"
["i18n"]="8"
["kde"]="9"
["lib"]="10"
["lib32"]="19"
["modules"]="11"
["multimedia"]="12"
["network"]="13"
["office"]="14"
["system"]="16"
["utils"]="18"
["x11"]="17"
)
catvalue=${categories[$1]}
if [[ "${catvalue}" == "" ]]; then
echo "'$1' is not a valid category."
die 1
fi
}
die() {
if [ -d "$tempdir" ]; then
rm -rf "$tempdir"
fi
exit $1
}
version() {
echo "ccr-submit - version $ver"
echo
echo " https://github.com/Ram-Z/ccr-tools"
die 0
}
use() {
echo "ccr-submit - version $ver"
echo
echo "usage: ccr-submit -c <category> <pkgsrc>"
echo
echo "ccr-submit --version, -V shows version"
echo "ccr-submit --help, -h shows this help"
echo
echo " example: ccr-submit -c devel ccr-submit-$ver.src.tar.gz"
echo
echo "You can create ~/.config/ccr-toolsrc containing:"
echo "user=YOUR_CCR_USERNAME"
echo "pass=YOUR_CCR_PASS"
echo
echo "To create a new account just go to:"
echo "http://chakra-linux.org/ccr/account.php"
echo
echo "Fork of ccr-vote"
echo "written by Ram-Z <samir.benmendil[at]gmail[dot]com>"
echo " https://github.com/Ram-Z/ccr-tools"
}
urlencode(){
echo $@ | LANG=C awk '
BEGIN {
split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ")
hextab [0] = 0
for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0
}
{
encoded = ""
for ( i=1; i<=length ($0); ++i ) {
c = substr ($0, i, 1)
if ( c ~ /[a-zA-Z0-9.-]/ ) {
encoded = encoded c # safe character
} else if ( c == " " ) {
encoded = encoded "+" # special handling
} else {
# unsafe character, encode it as a two-digit hex-number
lo = ord [c] % 16
hi = int (ord [c] / 16);
encoded = encoded "%" hextab [hi] hextab [lo]
}
}
print encoded
}
END {
}
'
}
### MAIN PROGRAM ###
while [ "$#" -ne "0" ]; do
case $1 in
--help|-h)
use
die 0
;;
--version|-V) version;;
--category|-c) shift; category=$1;;
--*|-*)
use
die 0
;;
*)
pkgsrc=$1
;;
esac
shift
done
if [[ $pkgsrc == "" ]]; then
use
die 0
fi
# we don't even want to submit something different than source files
if [[ ! -f $pkgsrc || $pkgsrc != *.src.tar.gz ]]; then
echo "`basename ${pkgsrc}` is not a source package!"
die 1
fi
# check for category
if [[ $category == "" ]]; then
echo "You must provide a category."
die 1
fi
getcat $category
# Check config file
if [ -r ~/.ccr-toolsrc ] && [ ! -r "$configrc" ]; then
echo "Moving ~/.ccr-toolsrc to $configrc"
mv ~/.ccr-toolsrc $configrc
fi
[ -r "$configrc" ] && source $configrc
[[ -z $user ]] && read -p "please enter your CCR username: " user
[[ -z $pass ]] && read -p "please enter your CCR password: " -s pass && echo
#logins to ccr and keeps sesion alive
umask 077
curl -Ss --cookie-jar "$tempdir/cjar" --output /dev/null ${ccrbaseurl}
curl -Ss --cookie "$tempdir/cjar" --cookie-jar "$tempdir/cjar" \
--data "user=$user" --data "passwd=$(urlencode $pass)" \
--location --output "$tempdir/ccrvote.login" \
${ccrbaseurl}
if grep --quiet "'error'>Bad username or password" "$tempdir/ccrvote.login"; then
echo "incorrect password: check $configrc file"
die 1
fi
# submit file
echo "`basename ${pkgsrc}`"
curl -Ss --cookie "$tempdir/cjar" --cookie-jar "$tempdir/cjar" \
--form "pkgsubmit=1" \
--form "pfile=@${pkgsrc}" \
--form "category=${catvalue}" \
--output /dev/null \
"${submiturl}"
die 0
# vim: sts=4 ts=4 sw=4 et