]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - bin/functions
- finished
[projects/pld-ftp-admin.git] / bin / functions
CommitLineData
f87a6239 1
775933a1 2# Note: all functions expect to get N-V-R strings as pkg arguments (unless
9d6d692b
MM
3# it's obvious they shouldn't get them of course)
4
f87a6239
MM
5# Read config
6if [ ! -f ~/.ftpadmrc ]; then
7 echo "Config not found"
8 exit
9fi
10
11. ~/.ftpadmrc
12
13# For logging
14scriptname=`basename $0`
15
16# Log a message... useful for debugging
17log() {
18 echo `date "+%F %T"` "[$scriptname]" "--" "$@" >>~/pld-ftp-admin/log
19}
20
775933a1 21# Wrapper so that we can test stuff without actually doing (allmost) anything
9d6d692b
MM
22if [ "$DEBUG" == "yes" ]; then
23 rm()
24 {
25 echo "RM: $@" >&2
26 }
27 mv()
28 {
29 echo "MV: $@" >&2
30 }
31 cd()
32 {
33 command cd $1
34 echo "CD: $1" >&2
35 }
36fi
37
bb821c5a
MM
38errnum="0"
39pkglist=""
40# Fill $pkglist
41# Args: 1 - ftp tree to check against
42# 2 - list of args
43init_pkglist()
44{
45 for i in $2; do
46 pkg=`echo $i|sed -e 's,.src.rpm$,,'`
47 if [ ! -f "$FTP_DIR/$1/SRPMS/.metadata/$pkg.src.rpm.info" ]; then
48 errnum=$(($errnum+1))
49 echo "$pkg was not found in source tree"
50 else
51 pkglist="$pkglist $pkg"
52 fi
53 shift
54 done
55}
56
cebb3b04
MM
57# Check if all builders said they're finished with the package
58# Args: 1 - ftp tree
59# pkglist
60check_buildids()
61{
62 cd ~/tmp
63 rm -f queue.txt
64 wget -nv "http://ep09.pld-linux.org/~builderth/queue.txt"
65 echo "------------------------------------------"
66 cat queue.txt|grep '^group:\|builders:'| \
67 sed -e 's,^[ ]*,,' -e 's,^group.*id=\(.*\) pri=.*$,\1:,' |\
68 perl -e '$_=join("",<STDIN>);~s/\nbuilders://g;print;'>q.txt
69
70 cd "$FTP_DIR/$1/SRPMS/.metadata/"
71 for pkg in $pkglist; do
72 for buildid in `grep ^info:buildid: $pkg.src.rpm.info|cut -d: -f 3`; do
73 if [ -n "`grep ^$buildid: ~/tmp/q.txt|grep '?'`" ]; then
74 errnum=$(($errnum+1))
75 echo "Building of package $pkg (buildid $buildid) not finished"
76 fi
77 done
78 done
79}
80
81# Check if we won't remove some arch when moving
82# Args: pkglist, srctree, dsttree
83check_built_archs()
84{
85 cd "$FTP_DIR/$dsttree/SRPMS/.metadata/"
86 for pkg in $pkglist; do
87 olderpkgs=`find_other_pkgs "$dsttree" "$pkg"`
88 if [ -z "$olderpkgs" ]; then
89 continue
90 fi
91 # Archs that are already provided by the package that's in dest tree
92 availablearchs=""
93 for oldpkg in $olderpkgs; do
94 tmparchs="`cat $oldpkg.src.rpm.info|grep ^file:| \
95 cut -d: -f 2|sort|uniq`"
96 availablearchs="$tmparchs $availablearchs"
97 done
98 availablearchs="`echo \"$availablearchs\"|sort|uniq`"
99 grepstring=`echo $availablearchs| \
100 sed -e 's,^,^,' -e 's,$,$,' -e 's, ,$\\\|^,g'`
101 newarchs="`cat $FTP_DIR/$srctree/SRPMS/.metadata/$pkg.src.rpm.info| \
102 grep ^file:|cut -d: -f 2|sort|uniq`"
103 # Number of archs already provided by the package that's in dest tree
104 availablearchsnum="`echo \"$availablearchs\"|wc -l`"
105 # Number of archs supported by dst pkg that are supported by src pkg
106 diffnum="`echo \"$newarchs\"|grep $grepstring|wc -l`"
107
108 if [ $availablearchsnum != $diffnum ]; then
109 errnum=$(($errnum+1))
110 echo "$availablearchs">~/tmp/a.list
111 echo "$newarchs" > ~/tmp/n.list
112 missingarchs=`diff ~/tmp/{a,n}.list |grep '^<'|sed -e 's,^..,,'`
113 echo "Moving package $pkg would remove archs: $missingarchs"
114 fi
115 done
116}
117
bb821c5a 118
9d6d692b
MM
119# Return a list of packages that differ only by version than the one given
120# Args: $1 - the package we're intersted in (in N-V-R format)
121# Note1: we assume we're in .metadata dir
122# Note2: the list returned is newline, not space, separated
123# Note3: sets $glob_basename to basename (without V-R) if anybody need's it
124glob_packages()
125{
126 # Get just the name without the version tag
127 basename=`echo $1|sed -e 's,-[^-]*-[^-]*$,,'`
128 # Find packages beginning with that name
775933a1
MM
129 allpkgs=`echo $basename*`
130 if [ "$allpkgs" == "$basename*" ]; then
9d6d692b
MM
131 # No files found
132 return
133 fi
775933a1
MM
134 allpkgs=`echo "$allpkgs"|sed -e 's, ,\n,g' -e 's,.src.rpm.info,,g'`
135 # Filter out pkgs that just begin with basename, but ain't other
9d6d692b 136 # versions of that package
775933a1
MM
137 allpkgs=`echo "$allpkgs"|grep "$basename-[^-]*-[^-]*$"`
138 echo "$allpkgs"
9d6d692b
MM
139}
140
141# Generate a list of older packages
142# Args: $1 - ftp tree
143# $2 - packages we're interested in
144find_older_pkgs()
145{
146 cd "$FTP_DIR/$1/SRPMS/.metadata/"
147 list=""
775933a1
MM
148 for pkg in $2; do
149 # "Glob" for other pkgs
150 allpkgs=`glob_packages $pkg`
9d6d692b 151 # Get just the name without the version tag (we need it)
775933a1 152 basename=`echo $pkg|sed -e 's,-[^-]*-[^-]*$,,'`
9d6d692b 153 # Get only versions
775933a1 154 allpkgs=`echo "$allpkgs"|sed -e "s,^$basename-,,"`
9d6d692b 155 # Sort (note - this ain't perfect sorting)
775933a1 156 allpkgs=`echo "$allpkgs"|sort -n`
9d6d692b 157 # Readd names
775933a1 158 allpkgs=`echo "$allpkgs"|sed -e "s,^,$basename-,"`
9d6d692b 159 # Grep packages < current package
775933a1 160 allpkgs=`echo "$allpkgs"|grep -B 999 "$pkg"|grep -v "^$pkg$"`
9d6d692b 161 # Add to the list
775933a1
MM
162 allpkgs=`echo $allpkgs`
163 list="$list $allpkgs"
9d6d692b
MM
164 done
165 echo $list
166}
167
c9d648be 168# Generate a list of all packages (glob name-*) except the one given
9d6d692b
MM
169# Args: $1 - ftp tree
170# $2 - packages we're interested in
c9d648be 171find_other_pkgs()
9d6d692b
MM
172{
173 cd "$FTP_DIR/$1/SRPMS/.metadata/"
174 list=""
775933a1
MM
175 for pkg in $2; do
176 # "Glob" for other pkgs
177 allpkgs=`glob_packages $pkg`
c9d648be 178 # Cut out our own package
775933a1 179 allpkgs=`echo "$allpkgs"|grep -v "^$pkg$"`
9d6d692b 180 # Add to the list
775933a1
MM
181 allpkgs=`echo $allpkgs`
182 list="$list $allpkgs"
9d6d692b
MM
183 done
184 echo $list
185}
186
187# Remove packages in given tree
188# Args: $1 - ftp tree
775933a1 189# $2 - list of packages to remove
c9d648be 190# $3 - force option
9d6d692b
MM
191remove_pkgs() {
192 cd "$FTP_DIR/$1/SRPMS/.metadata/"
c9d648be
MM
193 rmopt=""
194 if [ "$3" == "force" ]; then
195 rmopt="-f"
196 fi
775933a1 197 for pkg in $2; do
9d6d692b
MM
198 # Remove all files connected to the old src.rpm
199 # (+ the src.rpm itself)
775933a1 200 for i in `grep '^file:' $pkg.src.rpm.info`; do
9d6d692b
MM
201 arch=`echo $i|cut -d: -f 2`
202 file=`echo $i|cut -d: -f 3`
c9d648be 203 rm $rmopt "$FTP_DIR/$1/$arch/RPMS/$file"
9d6d692b
MM
204 done
205 # And finally remove the .info file
775933a1 206 rm $rmopt $pkg.src.rpm.info
9d6d692b
MM
207 done
208}
209
f87a6239 210# vi: syntax=sh
This page took 0.053622 seconds and 4 git commands to generate.