public
Last active

AUR upload helper script

  • Download Gist
aurupload.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
#!/bin/bash
 
set -u
set -e
 
declare -A categorys
categorys[daemons]=2
categorys[devel]=3
categorys[editors]=4
categorys[emulators]=5
categorys[games]=6
categorys[gnome]=7
categorys[i18n]=8
categorys[kde]=9
categorys[kernels]=19
categorys[lib]=10
categorys[modules]=11
categorys[multimedia]=12
categorys[network]=13
categorys[office]=14
categorys[science]=15
categorys[system]=16
categorys[x11]=17
categorys[xfce]=18
 
verbose=0
if [ "${1:-}" == "-v" ]; then
verbose=1
shift 1
fi
 
if [ $# -lt 3 ]; then
echo "Usage: aurupload <user> <pass> [<category>] <path to src-pkg>"
echo "Valid categorys are: ${!categorys[*]}"
echo "If pass is -, aurupload asks interactively."
exit 1
fi
 
username=$1
password=$2
 
if [ "$password" = "-" ]; then
stty -echo
read -p "Enter your password: " password
stty echo
echo
fi
 
if [ $# -lt 4 ]; then
category=1
filename=$3
else
category=${categorys[$3]:-errorerror}
filename=$4
fi
 
if [ $category = "errorerror" ]; then
echo "Invalid category"
exit 2
fi
 
echo "Logging in..."
 
response=`curl -sSi -F user=$username -F passwd=$password -H 'Expect: ' https://aur.archlinux.org/login/`
sessid=`echo "$response" | awk '/^Set-Cookie: / {print $2}' | tr -d ';'`
 
if [ $verbose -gt 0 ]; then
echo "$response"
fi
 
if [ -z "$sessid" ]; then
echo "Login failed. Wrong username/password?" >&2
exit 1
fi
 
echo "Done, sessionid is $sessid"
 
echo "Requesting upload token..."
 
response=`curl -sSi -H 'Expect: ' -b $sessid https://aur.archlinux.org/submit/`
token=`echo "$response" | grep 'input.type..hidden..name..token..value' | cut -d\" -f6`
 
if [ $verbose -gt 0 ]; then
echo "$response"
fi
 
if [ -z "$token" ]; then
echo "Could not get the token." >&2
exit 1
fi
 
echo "Done, token is $token"
 
echo "Uploading file..."
 
response=`curl -sSi -H 'Expect: ' -F token="$token" -F pkgsubmit=1 -F category=$category -F pfile=@$filename -b $sessid https://aur.archlinux.org/submit/`
error=`echo "$response" | grep 'class="pkgoutput"' | sed 's/\s*<[^>]*>//g'`
package=`echo "$response" | awk '/^Location: / {print $2}'`
 
if [ $verbose -gt 0 ]; then
echo "$response"
fi
 
if [ "$error" ]; then
echo "Error: $error" >&2
exit 1
else
echo "Done, (new) package is https://aur.archlinux.org$package"
fi

Thanks for your openspace pull request which was the reason to have a look at your website and thus at your AUR packages. My eclipse plugin packager (eclipse-artifacts) can make use of it :-)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.