1 #if defined(SUSE) || defined(FEDORA) || defined(MAGEIA)
7 #include <sys/utsname.h>
11 #include "repo_rpmdb.h"
14 #include "repoinfo_config_yum.h"
17 #if defined(FEDORA) || defined(MAGEIA)
18 # define REPOINFO_PATH "/etc/yum.repos.d"
21 # define REPOINFO_PATH "/etc/zypp/repos.d"
25 find_releaseevr(Pool *pool)
28 extern char *suse_find_baseproduct_evr(Pool *);
35 if ((releaseevr = suse_find_baseproduct_evr(pool)) != 0)
39 rpmstate = rpm_state_create(pool, pool_get_rootdir(pool));
40 rpm_installedrpmdbids(rpmstate, "Providename", "system-release", &q);
45 handle = rpm_byrpmdbid(rpmstate, q.elements[0]);
46 releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0;
47 if (releaseevr && (p = strchr(releaseevr, '-')) != 0)
50 rpm_state_free(rpmstate);
56 yum_substitute(Pool *pool, char *line)
59 static char *releaseevr;
60 static char *basearch;
64 solv_free(releaseevr);
71 while ((p2 = strchr(p, '$')) != 0)
73 if (!strncmp(p2, "$releasever", 11))
77 releaseevr = find_releaseevr(pool);
80 fprintf(stderr, "Cannot determine $releasever\n");
83 /* we only need the version */
84 if ((p = strchr(releaseevr, '-')) != 0)
88 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
91 p = p2 + strlen(releaseevr);
94 if (!strncmp(p2, "$basearch", 9))
104 basearch = strdup(un.machine);
105 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
109 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
110 p2 = p + (p2 - line);
112 p = p2 + strlen(basearch);
121 read_repoinfos_yum(Pool *pool, int *nrepoinfosp)
123 const char *reposdir = REPOINFO_PATH;
125 char buf2[4096], *kp, *vp, *kpe;
130 struct repoinfo *repoinfos = 0, *cinfo;
133 rdlen = strlen(reposdir);
134 dir = opendir(reposdir);
140 while ((ent = readdir(dir)) != 0)
142 if (ent->d_name[0] == '.')
144 l = strlen(ent->d_name);
145 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
147 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
148 if ((fp = fopen(buf, "r")) == 0)
154 while(fgets(buf2, sizeof(buf2), fp))
159 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
162 while (*kp == ' ' || *kp == '\t')
164 if (!*kp || *kp == '#')
167 kp = yum_substitute(pool, kp);
170 vp = strrchr(kp, ']');
174 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
175 cinfo = repoinfos + nrepoinfos++;
176 memset(cinfo, 0, sizeof(*cinfo));
177 cinfo->alias = strdup(kp + 1);
178 cinfo->type = TYPE_RPMMD;
179 cinfo->autorefresh = 1;
180 cinfo->priority = 99;
181 #if !defined(FEDORA) && !defined(MAGEIA)
182 cinfo->repo_gpgcheck = 1;
184 cinfo->metadata_expire = METADATA_EXPIRE;
189 vp = strchr(kp, '=');
192 for (kpe = vp - 1; kpe >= kp; kpe--)
193 if (*kpe != ' ' && *kpe != '\t')
198 while (*vp == ' ' || *vp == '\t')
201 if (!strcmp(kp, "name"))
202 cinfo->name = strdup(vp);
203 else if (!strcmp(kp, "enabled"))
204 cinfo->enabled = *vp == '0' ? 0 : 1;
205 else if (!strcmp(kp, "autorefresh"))
206 cinfo->autorefresh = *vp == '0' ? 0 : 1;
207 else if (!strcmp(kp, "gpgcheck"))
208 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
209 else if (!strcmp(kp, "repo_gpgcheck"))
210 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
211 else if (!strcmp(kp, "baseurl"))
212 cinfo->baseurl = strdup(vp);
213 else if (!strcmp(kp, "mirrorlist"))
215 if (strstr(vp, "metalink"))
216 cinfo->metalink = strdup(vp);
218 cinfo->mirrorlist = strdup(vp);
220 else if (!strcmp(kp, "path"))
222 if (vp && strcmp(vp, "/") != 0)
223 cinfo->path = strdup(vp);
225 else if (!strcmp(kp, "type"))
227 if (!strcmp(vp, "yast2"))
228 cinfo->type = TYPE_SUSETAGS;
229 else if (!strcmp(vp, "rpm-md"))
230 cinfo->type = TYPE_RPMMD;
231 else if (!strcmp(vp, "plaindir"))
232 cinfo->type = TYPE_PLAINDIR;
233 else if (!strcmp(vp, "mdk"))
234 cinfo->type = TYPE_MDK;
236 cinfo->type = TYPE_UNKNOWN;
238 else if (!strcmp(kp, "priority"))
239 cinfo->priority = atoi(vp);
240 else if (!strcmp(kp, "keeppackages"))
241 cinfo->keeppackages = *vp == '0' ? 0 : 1;
247 *nrepoinfosp = nrepoinfos;