1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <libgen.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <alpm.h>
#include <list.h>
#include <util.h>
int main(int argc, char* argv[])
{
FILE* db = NULL;
FILE* fp = NULL;
char* ptr = NULL;
char name[256];
char ver[256];
char line[PATH_MAX+1];
char topdir[PATH_MAX+1];
char path[PATH_MAX+1];
mode_t oldumask;
struct stat buf;
char dbdir[PATH_MAX];
sprintf(dbdir, "/%s", PM_DBPATH);
if(argc < 2) {
printf("converts a pacman 1.x database to a pacman 2.0 format\n");
printf("usage: %s <target_dir>\n\n", basename(argv[0]));
printf("convertdb will convert all package data from /var/lib/pacman/pacman.db\n");
printf("to a 2.0 format and place it in target_dir.\n\n");
return(0);
}
db = fopen(dbdir, "r");
if(db == NULL) {
perror(dbdir);
return(1);
}
oldumask = umask(0000);
while(fgets(name, 255, db)) {
PMList *backup = NULL;
PMList *lp;
if(!fgets(ver, 255, db)) {
perror(dbdir);
return(1);
}
_alpm_strtrim(name);
_alpm_strtrim(ver);
fprintf(stderr, "converting %s\n", name);
snprintf(topdir, PATH_MAX, "%s/%s-%s", argv[1], name, ver);
mkdir(topdir, 0755);
snprintf(path, PATH_MAX, "%s/desc", topdir);
if(!(fp = fopen(path, "w"))) {
perror(path);
return(1);
}
fputs("%NAME%\n", fp);
fprintf(fp, "%s\n\n", name);
fputs("%VERSION%\n", fp);
fprintf(fp, "%s\n\n", ver);
fputs("%DESC%\n\n", fp);
fclose(fp);
snprintf(path, PATH_MAX, "%s/depends", topdir);
if(!(fp = fopen(path, "w"))) {
perror(path);
return(1);
}
fputs("%DEPENDS%\n\n", fp);
fputs("%REQUIREDBY%\n\n", fp);
fputs("%CONFLICTS%\n\n", fp);
fclose(fp);
snprintf(path, PATH_MAX, "%s/files", topdir);
if(!(fp = fopen(path, "w"))) {
perror(path);
return(1);
}
fputs("%FILES%\n", fp);
while(fgets(line, 255, db) && strcmp(_alpm_strtrim(line), "")) {
ptr = line;
if(line[0] == '*') ptr++;
if(*ptr == '/') ptr++;
if(line[0] == '*') backup = _alpm_list_add(backup, strdup(ptr));
fprintf(fp, "%s\n", ptr);
}
fprintf(fp, "\n");
fputs("%BACKUP%\n", fp);
for(lp = backup; lp; lp = lp->next) {
fprintf(fp, "%s\tffffffffffffffffffffffffffffffff\n", (char*)lp->data);
}
fputs("\n", fp);
fclose(fp);
snprintf(path, PATH_MAX, "/var/lib/pacman/scripts/%s", name);
if(!stat(path, &buf)) {
snprintf(line, PATH_MAX, "/bin/cp %s %s/install", path, topdir);
system(line);
}
_alpm_list_free(backup, free);
}
umask(oldumask);
return(0);
}
|