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 yum_substitute(Pool *pool, char *line)
28 static char *releaseevr;
29 static char *basearch;
33 solv_free(releaseevr);
40 while ((p2 = strchr(p, '$')) != 0)
42 if (!strncmp(p2, "$releasever", 11))
50 rpmstate = rpm_state_create(pool, pool_get_rootdir(pool));
51 rpm_installedrpmdbids(rpmstate, "Providename", "system-release", &q);
56 handle = rpm_byrpmdbid(rpmstate, q.elements[0]);
57 releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0;
58 if (releaseevr && (p = strchr(releaseevr, '-')) != 0)
61 rpm_state_free(rpmstate);
65 fprintf(stderr, "no installed package provides 'system-release', cannot determine $releasever\n");
70 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
73 p = p2 + strlen(releaseevr);
76 if (!strncmp(p2, "$basearch", 9))
86 basearch = strdup(un.machine);
87 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
91 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
94 p = p2 + strlen(basearch);
103 read_repoinfos_yum(Pool *pool, int *nrepoinfosp)
105 const char *reposdir = REPOINFO_PATH;
107 char buf2[4096], *kp, *vp, *kpe;
112 struct repoinfo *repoinfos = 0, *cinfo;
115 rdlen = strlen(reposdir);
116 dir = opendir(reposdir);
122 while ((ent = readdir(dir)) != 0)
124 if (ent->d_name[0] == '.')
126 l = strlen(ent->d_name);
127 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
129 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
130 if ((fp = fopen(buf, "r")) == 0)
136 while(fgets(buf2, sizeof(buf2), fp))
141 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
144 while (*kp == ' ' || *kp == '\t')
146 if (!*kp || *kp == '#')
149 kp = yum_substitute(pool, kp);
152 vp = strrchr(kp, ']');
156 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
157 cinfo = repoinfos + nrepoinfos++;
158 memset(cinfo, 0, sizeof(*cinfo));
159 cinfo->alias = strdup(kp + 1);
160 cinfo->type = TYPE_RPMMD;
161 cinfo->autorefresh = 1;
162 cinfo->priority = 99;
163 #if !defined(FEDORA) && !defined(MAGEIA)
164 cinfo->repo_gpgcheck = 1;
166 cinfo->metadata_expire = METADATA_EXPIRE;
171 vp = strchr(kp, '=');
174 for (kpe = vp - 1; kpe >= kp; kpe--)
175 if (*kpe != ' ' && *kpe != '\t')
180 while (*vp == ' ' || *vp == '\t')
183 if (!strcmp(kp, "name"))
184 cinfo->name = strdup(vp);
185 else if (!strcmp(kp, "enabled"))
186 cinfo->enabled = *vp == '0' ? 0 : 1;
187 else if (!strcmp(kp, "autorefresh"))
188 cinfo->autorefresh = *vp == '0' ? 0 : 1;
189 else if (!strcmp(kp, "gpgcheck"))
190 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
191 else if (!strcmp(kp, "repo_gpgcheck"))
192 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
193 else if (!strcmp(kp, "baseurl"))
194 cinfo->baseurl = strdup(vp);
195 else if (!strcmp(kp, "mirrorlist"))
197 if (strstr(vp, "metalink"))
198 cinfo->metalink = strdup(vp);
200 cinfo->mirrorlist = strdup(vp);
202 else if (!strcmp(kp, "path"))
204 if (vp && strcmp(vp, "/") != 0)
205 cinfo->path = strdup(vp);
207 else if (!strcmp(kp, "type"))
209 if (!strcmp(vp, "yast2"))
210 cinfo->type = TYPE_SUSETAGS;
211 else if (!strcmp(vp, "rpm-md"))
212 cinfo->type = TYPE_RPMMD;
213 else if (!strcmp(vp, "plaindir"))
214 cinfo->type = TYPE_PLAINDIR;
215 else if (!strcmp(vp, "mdk"))
216 cinfo->type = TYPE_MDK;
218 cinfo->type = TYPE_UNKNOWN;
220 else if (!strcmp(kp, "priority"))
221 cinfo->priority = atoi(vp);
222 else if (!strcmp(kp, "keeppackages"))
223 cinfo->keeppackages = *vp == '0' ? 0 : 1;
229 *nrepoinfosp = nrepoinfos;