]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - bin/functions
- cosmetics
[projects/pld-ftp-admin.git] / bin / functions
1
2 # Note: all functions expect to get N-V-R strings as pkg arguments (unless
3 # it's obvious they shouldn't get them of course)
4
5 # Read config
6 if [ ! -f ~/.ftpadmrc ]; then
7         echo "Config not found"
8         exit
9 fi
10
11 . ~/.ftpadmrc
12
13 # For logging
14 scriptname=`basename $0`
15
16 # Log a message... useful for debugging
17 log() {
18         echo `date "+%F %T"` "[$scriptname]" "--" "$@" >>~/pld-ftp-admin/log
19 }
20
21 # Wrapper so that we can test stuff without actually doing (allmost) anything
22 if [ "$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         }
36 fi
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
43 glob_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
48         allpkgs=`echo $basename*`
49         if [ "$allpkgs" == "$basename*" ]; then
50                 # No files found
51                 return
52         fi
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
55         # versions of that package
56         allpkgs=`echo "$allpkgs"|grep "$basename-[^-]*-[^-]*$"`
57         echo "$allpkgs"
58 }
59
60 # Generate a list of older packages
61 # Args: $1 - ftp tree
62 #       $2 - packages we're interested in
63 find_older_pkgs()
64 {
65         cd "$FTP_DIR/$1/SRPMS/.metadata/"
66         list=""
67         for pkg in $2; do
68                 # "Glob" for other pkgs
69                 allpkgs=`glob_packages $pkg`
70                 # Get just the name without the version tag (we need it)
71                 basename=`echo $pkg|sed -e 's,-[^-]*-[^-]*$,,'`
72                 # Get only versions
73                 allpkgs=`echo "$allpkgs"|sed -e "s,^$basename-,,"`
74                 # Sort (note - this ain't perfect sorting)
75                 allpkgs=`echo "$allpkgs"|sort -n`
76                 # Readd names
77                 allpkgs=`echo "$allpkgs"|sed -e "s,^,$basename-,"`
78                 # Grep packages < current package
79                 allpkgs=`echo "$allpkgs"|grep -B 999 "$pkg"|grep -v "^$pkg$"`
80                 # Add to the list
81                 allpkgs=`echo $allpkgs`
82                 list="$list $allpkgs"
83         done
84         echo $list
85 }
86
87 # Generate a list of all packages (glob name-*) except the one given
88 # Args: $1 - ftp tree
89 #       $2 - packages we're interested in
90 find_other_pkgs()
91 {
92         cd "$FTP_DIR/$1/SRPMS/.metadata/"
93         list=""
94         for pkg in $2; do
95                 # "Glob" for other pkgs
96                 allpkgs=`glob_packages $pkg`
97                 # Cut out our own package
98                 allpkgs=`echo "$allpkgs"|grep -v "^$pkg$"`
99                 # Add to the list
100                 allpkgs=`echo $allpkgs`
101                 list="$list $allpkgs"
102         done
103         echo $list
104 }
105
106 # Remove packages in given tree
107 # Args: $1 - ftp tree
108 #       $2 - list of packages to remove
109 #       $3 - force option
110 remove_pkgs() {
111         cd "$FTP_DIR/$1/SRPMS/.metadata/"
112         rmopt=""
113         if [ "$3" == "force" ]; then
114                 rmopt="-f"
115         fi
116         for pkg in $2; do
117                 # Remove all files connected to the old src.rpm
118                 # (+ the src.rpm itself)
119                 for i in `grep '^file:' $pkg.src.rpm.info`; do
120                         arch=`echo $i|cut -d: -f 2`
121                         file=`echo $i|cut -d: -f 3`
122                         rm $rmopt "$FTP_DIR/$1/$arch/RPMS/$file"
123                 done
124                 # And finally remove the .info file
125                 rm $rmopt $pkg.src.rpm.info
126         done
127 }
128
129 # vi: syntax=sh
This page took 0.040602 seconds and 3 git commands to generate.