]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - bin/functions
- cosmetics
[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
38# Return a list of packages that differ only by version than the one given
39# Args: $1 - the package we're intersted in (in N-V-R format)
40# Note1: we assume we're in .metadata dir
41# Note2: the list returned is newline, not space, separated
42# Note3: sets $glob_basename to basename (without V-R) if anybody need's it
43glob_packages()
44{
45 # Get just the name without the version tag
46 basename=`echo $1|sed -e 's,-[^-]*-[^-]*$,,'`
47 # Find packages beginning with that name
775933a1
MM
48 allpkgs=`echo $basename*`
49 if [ "$allpkgs" == "$basename*" ]; then
9d6d692b
MM
50 # No files found
51 return
52 fi
775933a1
MM
53 allpkgs=`echo "$allpkgs"|sed -e 's, ,\n,g' -e 's,.src.rpm.info,,g'`
54 # Filter out pkgs that just begin with basename, but ain't other
9d6d692b 55 # versions of that package
775933a1
MM
56 allpkgs=`echo "$allpkgs"|grep "$basename-[^-]*-[^-]*$"`
57 echo "$allpkgs"
9d6d692b
MM
58}
59
60# Generate a list of older packages
61# Args: $1 - ftp tree
62# $2 - packages we're interested in
63find_older_pkgs()
64{
65 cd "$FTP_DIR/$1/SRPMS/.metadata/"
66 list=""
775933a1
MM
67 for pkg in $2; do
68 # "Glob" for other pkgs
69 allpkgs=`glob_packages $pkg`
9d6d692b 70 # Get just the name without the version tag (we need it)
775933a1 71 basename=`echo $pkg|sed -e 's,-[^-]*-[^-]*$,,'`
9d6d692b 72 # Get only versions
775933a1 73 allpkgs=`echo "$allpkgs"|sed -e "s,^$basename-,,"`
9d6d692b 74 # Sort (note - this ain't perfect sorting)
775933a1 75 allpkgs=`echo "$allpkgs"|sort -n`
9d6d692b 76 # Readd names
775933a1 77 allpkgs=`echo "$allpkgs"|sed -e "s,^,$basename-,"`
9d6d692b 78 # Grep packages < current package
775933a1 79 allpkgs=`echo "$allpkgs"|grep -B 999 "$pkg"|grep -v "^$pkg$"`
9d6d692b 80 # Add to the list
775933a1
MM
81 allpkgs=`echo $allpkgs`
82 list="$list $allpkgs"
9d6d692b
MM
83 done
84 echo $list
85}
86
c9d648be 87# Generate a list of all packages (glob name-*) except the one given
9d6d692b
MM
88# Args: $1 - ftp tree
89# $2 - packages we're interested in
c9d648be 90find_other_pkgs()
9d6d692b
MM
91{
92 cd "$FTP_DIR/$1/SRPMS/.metadata/"
93 list=""
775933a1
MM
94 for pkg in $2; do
95 # "Glob" for other pkgs
96 allpkgs=`glob_packages $pkg`
c9d648be 97 # Cut out our own package
775933a1 98 allpkgs=`echo "$allpkgs"|grep -v "^$pkg$"`
9d6d692b 99 # Add to the list
775933a1
MM
100 allpkgs=`echo $allpkgs`
101 list="$list $allpkgs"
9d6d692b
MM
102 done
103 echo $list
104}
105
106# Remove packages in given tree
107# Args: $1 - ftp tree
775933a1 108# $2 - list of packages to remove
c9d648be 109# $3 - force option
9d6d692b
MM
110remove_pkgs() {
111 cd "$FTP_DIR/$1/SRPMS/.metadata/"
c9d648be
MM
112 rmopt=""
113 if [ "$3" == "force" ]; then
114 rmopt="-f"
115 fi
775933a1 116 for pkg in $2; do
9d6d692b
MM
117 # Remove all files connected to the old src.rpm
118 # (+ the src.rpm itself)
775933a1 119 for i in `grep '^file:' $pkg.src.rpm.info`; do
9d6d692b
MM
120 arch=`echo $i|cut -d: -f 2`
121 file=`echo $i|cut -d: -f 3`
c9d648be 122 rm $rmopt "$FTP_DIR/$1/$arch/RPMS/$file"
9d6d692b
MM
123 done
124 # And finally remove the .info file
775933a1 125 rm $rmopt $pkg.src.rpm.info
9d6d692b
MM
126 done
127}
128
f87a6239 129# vi: syntax=sh
This page took 0.425791 seconds and 4 git commands to generate.