updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / aurup / aurup
blobec9c8927b3cbba66af67f66525aaf96bad3cc5c5
1 #!/bin/sh
2 ver=0.7.10
4 # AurUp, a tool to upload packages to AUR
5 # provided by Pierluigi, mOLOk and Dundee
7 # This is free software. You may redistribute
8 # copies of it under the terms of the GNU
9 # General Public License <https://www.gnu.org/licenses/gpl.html>.
10 # There is NO WARRANTY, to the extent permitted by law.
13 tmpdir=~/
14 use_color=Y
15 auto_unflag=Y
16 auto_vote=N
17 auto_notify=Y
19 if [ ! -r ~/.config/aurup ]; then
20 echo "You should create ~/.config/aurup with inside:"
21 echo "user=YOUR_AUR_USERNAME"
22 echo "pass=YOUR_AUR_PASS"
23 echo "to avoid manual input of these data."
24 echo
25 echo -n "Your AUR username: "
26 read user
27 echo
28 echo -n "Your AUR password: "
29 read -s pass
30 echo
31 else
32 source ~/.config/aurup
35 msg() {
36 if [ "$use_color" = "Y" -o "$use_color" = "y" ]; then
37 echo -e "\033[1;32m${1}\033[1;0m" >&2
38 else
39 echo "$1" >&2
41 } #end of msg()
43 error() {
44 if [ "$use_color" = "Y" -o "$use_color" = "y" ]; then
45 echo -e "\033[1;31mERROR: ${1}\033[1;0m" >&2
46 else
47 echo "ERROR: $1" >&2
49 } #end of error()
51 usage() {
52 echo "aurup - version $ver"
53 echo
54 echo "usage: $0 pkgfile.tar.gz category"
55 echo
56 echo "pkgfile.tar.gz == tar.gz with PKGBUILD inside to send"
57 echo " (autarchy or makepkg --source can be used)"
58 echo "category == category of the package"
59 echo
60 echo "$0 -h shows this help"
61 echo "$0 -l list available category"
62 echo "$0 -c check for out-of-date packages"
63 echo
64 } # end of usage()
66 list_cat() {
67 echo "Category List:"
68 echo
69 echo "daemons"
70 echo "devel"
71 echo "editors"
72 echo "emulators"
73 echo "games"
74 echo "gnome"
75 echo "i18n"
76 echo "kde"
77 echo "lib"
78 echo "modules"
79 echo "multimedia"
80 echo "network"
81 echo "office"
82 echo "science"
83 echo "system"
84 echo "x11"
85 echo "xfce"
86 echo "kernels"
87 echo
88 } # end of list_cat()
90 aur_login(){
91 curl -c $tmpdir/.aurup.cookies -d "user=${user}&passwd=${pass}" https://aur.archlinux.org/index.php &>/dev/null
92 login=`curl -s -b $tmpdir/.aurup.cookies -d "user=${user}&passwd=${pass}" https://aur.archlinux.org/index.php | grep -c "Bad username or password"`
93 [ $login = "1" ] && echo "Bad username or password" && exit
97 aur_action(){
98 # do_Notify / do_UnNotify
99 # do_Flag / do_UnFlag
100 # do_Adopt / do_Disown
101 # do_Vote / do_UnVote
102 # do_Delete
103 # do_MyPackages
104 action=$1
105 pkgid=$2
106 aur_login
107 if [[ $action == "do_MyPackages" ]]; then
108 curl -b $tmpdir/.aurup.cookies "https://aur.archlinux.org/packages.php?SeB=m&K=${user}&PP=100" 2>/dev/null
109 else
110 curl -b $tmpdir/.aurup.cookies -d "IDs[${pkgid}]=1&ID=${pkgid}&${action}=1" https://aur.archlinux.org/packages.php 2>/dev/null
112 } # end of aur_action()
115 id_finder(){
116 pkgname=$1
117 #curl -F K=${pkgname} -F PP=100 https://aur.archlinux.org/packages.php 2>/dev/null > $tmpdir/.aurup1.tmp
118 curl https://aur.archlinux.org/packages.php?K=${pkgname} 2>/dev/null > $tmpdir/.aurup1.tmp
119 for id in `cat $tmpdir/.aurup1.tmp | grep href | grep packages\.php | grep ID | cut -d\' -f 6 | cut -d\= -f2`; do
120 url="https://aur.archlinux.org/packages.php?do_Details=1&ID=${id}"
121 links -dump $url > $tmpdir/.aurup2.tmp
122 name=`cat $tmpdir/.aurup2.tmp | awk '/Package Details/,/Maintainer: /' | head -3 | tail -1 | awk '{ print $1 }'`
123 if [[ $name == ${pkgname} ]]; then
124 echo $id
125 break
127 done
131 check_ood(){
132 aur_login
133 aur_action do_MyPackages >$tmpdir/.aurup4.tmp
134 out_ood(){
135 for idood in `grep "outofdate" $tmpdir/.aurup4.tmp | egrep -o "\[[0-9]{1,}\]" | egrep -o "[0-9]{1,}"`; do
136 name=`grep ID=${idood} $tmpdir/.aurup4.tmp | html2text | cut -d\ -f1`
137 echo -e "$name \t\t\t it's flagged out-of-date"
138 done
140 out=`out_ood`
141 if [[ "$out" == "" ]]; then
142 echo "No package is flagged out-of-date"
143 else
144 echo "$out"
146 exit 0
149 aur_cat_finder() {
150 #curl -F K=${pkgname} -F PP=100 https://aur.archlinux.org/packages.php 2>/dev/null > $tmpdir/.aurup1.tmp
151 curl https://aur.archlinux.org/packages.php?K=${pkgname} 2>/dev/null > $tmpdir/.aurup1.tmp
152 for id in `cat $tmpdir/.aurup1.tmp | grep href | grep packages\.php | grep ID | cut -d\' -f 6 | cut -d\= -f2`; do
153 url="https://aur.archlinux.org/packages.php?do_Details=1&ID=${id}"
154 links -dump $url > $tmpdir/.aurup2.tmp
155 name=`cat $tmpdir/.aurup2.tmp | awk '/Package Details/,/Maintainer: /' | head -3 \
156 | tail -1 | awk '{ print $1 }'`
157 if [[ $name == ${pkgname} ]]; then
158 # category=`cat $tmpdir/.aurup2.tmp | awk '/Package Details/,/Maintainer: /' \
159 # | tail -2 | head -1 | awk '{ print $3 }'`
160 category=`cat $tmpdir/.aurup2.tmp | awk '/Package Details/,/Maintainer: /' | tail -2 | head -1 | awk '{ print $3 }'`
161 echo "$category"
162 break
164 done
165 rm -f $tmpdir/.aurup{1,2}.tmp
166 } #end of aur_cat_finder()
168 send(){
169 aur_login
170 curl -H "Expect:" -b $tmpdir/.aurup.cookies -F pkgsubmit=1 -F MAX_FILE_SIZE=2097152 -F category="${num_category}" -F pfile="@${pkgfile}" https://aur.archlinux.org/pkgsubmit.php 2>/dev/null > $tmpdir/.aurup3.tmp
171 rm -f $tmpdir/.aurup.cookies
172 } #end of send()
174 print_message(){
175 if [[ `grep error $tmpdir/.aurup3.tmp` ]]; then
176 message="`grep error $tmpdir/.aurup3.tmp | html2text`"
177 error "$message"
178 else
179 message="`grep \/center $tmpdir/.aurup3.tmp |html2text`"
180 pkgid=`id_finder ${pkgname}`
181 if [[ $auto_unflag == "Y" || $auto_unflag == "y" ]]; then
182 aur_action do_UnFlag $pkgid &>/dev/null
183 message="$message (unflagged out of date)"
185 if [[ $auto_vote == "Y" || $auto_vote == "y" ]]; then
186 aur_action do_Vote $pkgid &>/dev/null
187 message="$message (voted)"
189 if [[ $auto_notify == "Y" || $auto_notify == "y" ]]; then
190 aur_action do_Notify $pkgid &>/dev/null
191 message="$message (added to notify list)"
193 msg "${message}"
195 #echo $message
196 #rm -f $tmpdir/.aurup3.tmp
197 } # end of print_message()
199 if [[ $1 == "-h" || $1 == "--help" ]]; then usage; exit 0; fi
200 if [[ $1 == "-l" || $1 == "--list" ]]; then list_cat; exit 0; fi
201 if [[ $1 == "-c" || $1 == "--check-out-of-date" ]]; then check_ood; fi
202 if [[ $# != 2 ]]; then error "wrong number of parameters" 1>&2 ; usage; exit -1; fi
203 if [[ ! -f $1 ]]; then error "$1 does not exist" 1>&2; exit -4; fi
205 pkgfile="$1"
206 category="$2"
207 pkgname=`basename $1 .tar.gz`
208 pkgname=`echo $pkgname | sed -re 's|^(.*)-[^-]+-[^-]+\.src\$|\1|'`
209 echo -n "$pkgname: "
211 #pkgname_len=`echo $pkgname | wc -c`
212 #if [[ $pkgname_len -gt 32 ]]; then error "pkgname is longer than 32 characters, and this is not allowed in AUR"; exit -6; fi
214 num_category=0
216 for categ in daemons devel editors emulators games gnome i18n kde \
217 lib modules multimedia network office science system x11 xfce kernels; do
218 if [[ $category == $categ ]]; then num_category=$i; fi
219 let i++
220 done
222 if [[ $num_category == 0 ]]; then
223 error "insert a valid category name" 1>&2
224 else
225 send
226 print_message