]> git.wh0rd.org Git - home.git/blob - .profile.d/gentoo.sh
add nacl settings
[home.git] / .profile.d / gentoo.sh
1 alias ebuild-sync='rsync -av ./ /usr/portage/${PWD#/usr/local/src/gentoo-x86/} --exclude ChangeLog --exclude CVS --exclude metadata.xml --delete'
2 alias ebuild-emerge='sudo emerge -1av $(echo ${PWD} | awk -F/ "{printf \"%s/%s\", \$(NF-1), \$(NF)}")'
3 alias ekeyword='ekeyword -v -q'
4
5 cvs_gentoo_url() {
6 _cvs_gentoo_url() {
7         if [[ -n $2 ]] ; then
8                 echo "Usage: cvs_gentoo_url <file>[:rev1[:rev2]]"
9                 return 1
10         fi
11
12         # spec has the form file:rev1[:rev2]
13         # rev2 defaults to rev1-1
14         export IFS=:
15         set -- $1
16         unset IFS
17
18         local file=$1
19         if [[ ! -e ${file} ]] ; then
20                 echo "file '${file}' does not exist"
21                 return 1
22         fi
23         local dir="."
24         [[ ${file} == */* ]] && dir=${file%/*}
25         file=${file##*/}
26
27         local rev2=$2
28         if [[ -z ${rev2} ]] ; then
29                 rev2=$(
30                         cd ${dir}
31                         export IFS=/
32                         set -- $(grep /${file}/ CVS/Entries)
33                         unset IFS
34                         echo $3
35                 )
36                 if [[ ${rev2} == "0" ]] ; then
37                         # new file
38                         rev2="1.1"
39                 else
40                         # existing file, bump rev automatically
41                         rev2="1.$((${rev2#1.}+1))"
42                 fi
43         fi
44         local rev2r=${rev2#1.}
45         local rev1=${3:-1.$((rev2r - 1))}
46
47         local cvsroot=$(<${dir}/CVS/Repository)
48         if [[ ${cvsroot} == gentoo-x86* ]] ; then
49                 cvsroot=${cvsroot#gentoo-x86}
50                 cvsroot=${cvsroot#/}
51         fi
52
53         local urirev
54         [[ ${rev2} == "1.1" || ${rev1} == "${rev2}" ]] \
55                 && urirev="?rev=${rev2}" \
56                 || urirev="?r1=${rev1}&r2=${rev2}"
57         echo "http://sources.gentoo.org/${cvsroot}/${file}${urirev}"
58 }
59         local f
60         for f in "$@" ; do
61                 _cvs_gentoo_url "${f}"
62         done
63         unset _cvs_gentoo_url
64 }
65 git_gentoo_url() {
66         local repo=$(git config remote.origin.url | sed 's:.*git.overlays.gentoo.org/::')
67         git log -n3 ${1:-HEAD} | \
68                 sed "s,^commit ,http://git.overlays.gentoo.org/gitweb/?p=${repo};a=commitdiff;h=,"
69 }
70 svn_gentoo_url() {
71         if [[ -z $* ]] ; then
72                 svn info | \
73                 awk '{
74                         if ($1 == "URL:") {
75                                 URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/,"\\1","");
76                         } else if ($1 == "Revision:") {
77                                 rev = $2
78                                 URL = URL "?rev=" (rev + 1) "&view=rev"
79                         }
80                 }
81                 END { print URL }'
82                 return 0
83         fi
84
85         local f
86         for f in "$@" ; do
87                 svn info "${f}" | \
88                 awk '{
89                         if ($1 == "URL:") {
90                                 sub(/.*svnroot/,"")
91                                 URL = "http://sources.gentoo.org" $1 "?"
92                         } else if ($1 == "Revision:") {
93                                 rev = $2
94                                 URL = URL "r1=" rev "&r2=" (rev + 1)
95                         }
96                 }
97                 END { print URL }'
98         done
99 }
100
101 _echangelog() {
102         [[ ! -e ChangeLog ]] \
103                 && echo "No ChangeLog" \
104                 && return 1
105         echangelog "$@" || return 1
106 }
107 er() {
108         repoman commit --echangelog=y "${@:1:$#-1}" -m "${@:$#}" || return 1
109 }
110 ec() {
111         (
112         _echangelog "$@" || exit 1
113         cvs commit -m "$@" || exit 1
114         )
115 }
116
117 att() {
118         while [[ $# -gt 0 ]] ; do
119                 declare url=$1 tmp=$(mktemp) filename || return 1
120                 [[ ${url} == */* ]] || url="http://bugs.gentoo.org/attachment.cgi?id=${url}"
121                 printf '%s -> ' "${url}"
122                 if eval $(wget -S -O"${tmp}" "${url}" 2>&1 |
123                         grep 'Content-disposition:' | sed 's/.* //') && \
124                         mv "${tmp}" "${filename}" && \
125                         chmod $(printf "%03o" "$((0666 & ~$(umask)))") "${filename}" ; then
126                         du -b "${filename}"
127                 else
128                         echo "FAIL"
129                         rm -f "${tmp}"
130                 fi
131                 shift
132         done
133 }
134 arch_emails() {
135         local ret
136         if [[ $@ == *.ebuild* ]] ; then
137                 local e keys
138                 for e in "$@" ; do
139                         keys=$(sed -n '/^[[:space:]]*KEYWORD/{s:.*=::;s:"::g;p}' ${e})
140                         for a in ${keys} ; do
141                                 [[ ${a} != ~* ]] && continue
142                                 ret="${ret} ${a}"
143                         done
144                 done
145         else
146                 ret="$*"
147         fi
148         printf '%s@gentoo.org ' ${ret//\~}
149         echo
150 }
151 stable_arch_emails() {
152         arch_emails "$@" | sed -r -e 's:([^ ]*-[^ ]*|mips)@[^ ]*::g'
153 }
154 eget_maintainer() {
155         local f=${1:-metadata.xml}
156         local maintainer=$(xml sel -t -v pkgmetadata/herd $f)
157         if [[ ${maintainer:-no-herd} == "no-herd" ]] ; then
158                 maintainer=$(xml sel -t -v pkgmetadata/maintainer/email $f)
159         elif [[ -n ${maintainer} ]] ; then
160                 maintainer="${maintainer}@gentoo.org"
161         fi
162         if [[ -z ${maintainer} ]] ; then
163                 echo "No maintainer found in $f"
164                 return 1
165         fi
166         echo ${maintainer}
167         return 0
168 }
169 submit_bug_stable() {
170         local msg="doit"
171         if [[ $1 == "-m" ]] ; then
172                 msg=$2
173                 shift 2
174         fi
175         if [[ -z $1 ]] || [[ -n $2 ]] ; then
176                 echo "Usage: submit_bug_stable <ebuilds>"
177                 return 1
178         fi
179         local maintainer
180         maintainer=$(eget_maintainer) || return 1
181         local cat=$(basename $(dirname $(pwd)))
182         local pkg=${1%.ebuild}
183         local ebuild=${pkg}.ebuild
184         local cc=$(stable_arch_emails ${ebuild})
185         if [[ -z ${cc} ]] ; then
186                 echo "Unable to read ebuild '${ebuild}'"
187                 return 1
188         fi
189         if [[ ${maintainer} == *" "* ]] ; then
190                 cc+=",${maintainer#* }"
191                 maintainer=${maintainer%% *}
192         fi
193         gbugz \
194                 post \
195                 --batch \
196                 -t "${cat}/${pkg}: stabilize" \
197                 -d "${msg}" \
198                 -a "${maintainer}" \
199                 --cc="${cc// /,}" \
200                 -k STABLEREQ \
201                 --product='Gentoo Linux' \
202                 --component=Ebuilds \
203                 --priority=Normal \
204                 --severity=enhancement
205 }
206
207 eskeys() {
208         local k cat
209         if [[ ! -e ChangeLog ]] ; then
210                 # running in a category rather than package
211                 cat="/"
212         fi
213         [[ -z $* ]] && set -- arm64 m68k s390 sh
214         for k in "$@" ; do
215                 ekeyword "${k}=x86" $(grep -l "KEYWORDS.*${k}" *${cat}*.ebuild)
216         done
217 }
218 _erit() {
219         local msg=$1 ; shift
220         [[ $1 == [[:digit:]]* ]] && msg="$msg #$1" && shift
221         echo repoman commit -m "$(echo $@ | sed 's: :/:g') $msg"
222         repoman commit -m "$(echo $@ | sed 's: :/:g') $msg"
223 }
224 erstable() { _erit stable "$@" ; }
225 erlove() { _erit love "$@" ; }
226
227 export PORTAGE_INST_UID=${UID}
228 export PORTAGE_INST_GID=`id -g`