summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorJudd Vinet <judd@archlinux.org>2005-03-15 01:51:43 +0000
committerJudd Vinet <judd@archlinux.org>2005-03-15 01:51:43 +0000
commitd04baabafa2ebbad92741d1f87e6ff32999f894a (patch)
tree5a2280176812b80c28ca77bfa8e0655c16f4db7e /src/util
Initial revision
Diffstat (limited to 'src/util')
-rw-r--r--src/util/convertdb.c146
-rw-r--r--src/util/vercmp.c45
2 files changed, 191 insertions, 0 deletions
diff --git a/src/util/convertdb.c b/src/util/convertdb.c
new file mode 100644
index 00000000..6fbebb23
--- /dev/null
+++ b/src/util/convertdb.c
@@ -0,0 +1,146 @@
+/*
+ * convertdb.c
+ *
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#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 "pacconf.h"
+#include "list.h"
+#include "util.h"
+
+unsigned short pmo_verbose = 0;
+
+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", PACDBDIR);
+
+ 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);
+ }
+ trim(name);
+ trim(ver);
+ fprintf(stderr, "converting %s\n", name);
+ /* package directory */
+ snprintf(topdir, PATH_MAX, "%s/%s-%s", argv[1], name, ver);
+ mkdir(topdir, 0755);
+
+ /* DESC */
+ 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);
+
+ /* DEPENDS */
+ 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);
+
+ /* FILES */
+ 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(trim(line), "")) {
+ trim(line);
+ ptr = line;
+
+ /* check for backup designation and frontslashes that shouldn't be there */
+ if(line[0] == '*') ptr++;
+ if(*ptr == '/') ptr++;
+ if(line[0] == '*') backup = list_add(backup, strdup(ptr));
+
+ fprintf(fp, "%s\n", ptr);
+ }
+ fprintf(fp, "\n");
+ fputs("%BACKUP%\n", fp);
+ for(lp = backup; lp; lp = lp->next) {
+ /* print the filename and a bad md5 hash. we just use 32 f's cuz we can't
+ * md5 the original file since we don't have it
+ */
+ 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);
+ }
+ list_free(backup);
+ }
+ umask(oldumask);
+ return(0);
+}
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/src/util/vercmp.c b/src/util/vercmp.c
new file mode 100644
index 00000000..0ed3da2e
--- /dev/null
+++ b/src/util/vercmp.c
@@ -0,0 +1,45 @@
+/*
+ * vercmp.c
+ *
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "rpmvercmp.h"
+
+int main(int argc, char *argv[])
+{
+ char s1[255] = "";
+ char s2[255] = "";
+ int ret;
+
+ if(argc > 1) {
+ strncpy(s1, argv[1], 255);
+ }
+ if(argc > 2) {
+ strncpy(s2, argv[2], 255);
+ } else {
+ printf("0\n");
+ return(0);
+ }
+
+ ret = rpmvercmp(s1, s2);
+ printf("%d\n", ret);
+ return(ret);
+}