support plaindir repos (at least some)
[platform/upstream/libsolv.git] / tools / repo2solv.sh
1 #! /bin/sh
2 # repo2solv
3 #
4 # give it a directory of a local mirror of a repo and this
5 # tries to detect the repo type and generate one SOLV file on stdout
6
7 # this should signal an error if there is a problem
8 set -e 
9
10 LANG=C
11 parser_options=${PARSER_OPTIONS:-}
12
13
14 dir="$1"
15 cd "$dir" || exit 1
16 if test -d repodata; then
17   cd repodata || exit 2
18
19   # This contains a primary.xml* and maybe patches
20   for i in primary.xml*; do
21     case $i in
22       *.gz) cmd="gzip -dc" ;;
23       *.bz2) cmd="bzip2 -dc" ;;
24       *) cmd="cat" ;;
25     esac
26     # only check the first primary.xml*, in case there are more
27     break
28   done
29   primfile="/nonexist"
30   if test -n "$cmd"; then
31     # we have some primary.xml*
32     primfile=`mktemp` || exit 3
33     $cmd $i | rpmmd2solv $parser_options > $primfile || exit 4
34   fi
35
36   patchfile="/nonexist"
37   if test -f patches.xml; then
38     patchfile=`mktemp` || exit 3
39     (
40      echo '<patches>'
41      for i in patch-*.xml*; do
42        case $i in
43          *.gz) gzip -dc "$i" ;;
44          *.bz2) bzip2 -dc "$i" ;;
45          *) cat "$i" ;;
46        esac
47      done
48      echo '</patches>'
49     ) | grep -v '\?xml' | patchxml2solv $parser_options > $patchfile || exit 4
50   fi
51
52   # Now merge primary and patches
53   if test -s $primfile && test -s $patchfile; then
54     mergesolv $primfile $patchfile
55   elif test -s $primfile; then
56     cat $primfile
57   elif test -s $patchfile; then
58     cat $patchfile
59   fi
60   rm -f $primfile $patchfile
61 elif test -d suse/setup/descr && test -s content; then
62   olddir=`pwd`
63   cd suse/setup/descr || exit 2
64   (
65     # First packages
66     if test -s packages.gz; then
67       gzip -dc packages.gz
68     elif test -s packages.bz2; then
69       bzip2 -dc packages.bz2
70     elif test -s packages; then
71       cat packages
72     fi
73
74     # First packages
75     if test -s packages.en.gz; then
76       gzip -dc packages.en.gz
77     elif test -s packages.en.bz2; then
78       bzip2 -dc packages.en.bz2
79     elif test -s packages.en; then
80       cat packages.en
81     fi
82
83     # XXX need to do something with packages.DU and packages.{lang}
84
85     # Now patterns.  Not simply those files matching *.pat{,.gz,bz2},
86     # but only those mentioned in the file 'patterns'
87     if test -f patterns; then
88       for i in `cat patterns`; do
89         test -s "$i" || continue
90         case $i in
91           *.gz) gzip -dc "$i" ;;
92           *.bz2) bzip2 -dc "$i" ;;
93           *) cat "$i" ;;
94         esac
95       done
96     fi
97   ) | susetags2solv -c "${olddir}/content" $parser_options || exit 4
98   cd "$olddir"
99 else
100   rpms=`ls -1 *.rpm`
101   if test -n "$rpms"; then
102       rpms2solv $rpms
103   else
104       exit 1
105   fi
106 fi