summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <archlinux@cryptocrack.de>2012-12-07 23:20:11 +0100
committerLukas Fleischer <archlinux@cryptocrack.de>2013-02-15 13:25:56 +0100
commit6dc61e7d9e87ad6821869dab61e5f005af2e0252 (patch)
tree1fc19a0bc0d67a695cd60b1a762e42295dd6667b
parent21e6c3f65ff4b0daeac75d6d66dcdd33fb98d646 (diff)
downloadaur-6dc61e7d9e87ad6821869dab61e5f005af2e0252.tar.gz
aur-6dc61e7d9e87ad6821869dab61e5f005af2e0252.tar.xz
Remove aurblup configuration file parser
Drop the (very bad) PHP parser and allow for passing all necessary configuration via command line parameters. Also, add a convenience wrapper written in PHP that parses the configuration file and subsequently calls aurblup with correct command line options. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
-rwxr-xr-xscripts/aurblup/aurblup-wrapper17
-rw-r--r--scripts/aurblup/aurblup.c108
-rw-r--r--scripts/aurblup/config.h.proto8
3 files changed, 58 insertions, 75 deletions
diff --git a/scripts/aurblup/aurblup-wrapper b/scripts/aurblup/aurblup-wrapper
new file mode 100755
index 00000000..b056030d
--- /dev/null
+++ b/scripts/aurblup/aurblup-wrapper
@@ -0,0 +1,17 @@
+#!/usr/bin/php
+<?php
+$dir = $argv[1];
+
+if (empty($dir)) {
+ echo "Please specify AUR directory.\n";
+ exit;
+}
+
+set_include_path(get_include_path() . PATH_SEPARATOR . "$dir/lib");
+include("config.inc.php");
+
+exec($dir . "/../scripts/aurblup/aurblup " .
+ "-S /var/run/mysqld/mysqld.sock " .
+ "-u " . escapeshellarg(AUR_db_user) . " " .
+ "-p " . escapeshellarg(AUR_db_pass) . " " .
+ "-D " . escapeshellarg(AUR_db_name));
diff --git a/scripts/aurblup/aurblup.c b/scripts/aurblup/aurblup.c
index 32365548..be398f8b 100644
--- a/scripts/aurblup/aurblup.c
+++ b/scripts/aurblup/aurblup.c
@@ -5,6 +5,7 @@
*/
#include <alpm.h>
+#include <getopt.h>
#include <mysql.h>
#include <stdio.h>
#include <string.h>
@@ -22,15 +23,15 @@ static void blacklist_remove(const char *);
static void blacklist_sync(alpm_list_t *, alpm_list_t *);
static alpm_list_t *dblist_get_pkglist(alpm_list_t *);
static alpm_list_t *dblist_create(void);
-static void read_config(const char *);
+static int parse_options(int, char **);
static void init(void);
static void cleanup(void);
-static char *mysql_host = NULL;
+static char *mysql_host = "localhost";
static char *mysql_socket = NULL;
-static char *mysql_user = NULL;
-static char *mysql_passwd = NULL;
-static char *mysql_db = NULL;
+static char *mysql_user = "aur";
+static char *mysql_passwd = "aur";
+static char *mysql_db = "AUR";
static MYSQL *c;
@@ -208,65 +209,42 @@ dblist_create(void)
return dblist;
}
-static void
-read_config(const char *fn)
+static int parse_options(int argc, char **argv)
{
- FILE *fp;
- char line[128];
- char **t, **u, *p, *q;
-
- if (!(fp = fopen(fn, "r")))
- die("failed to open AUR config file (\"%s\")\n", fn);
-
- while (fgets(line, sizeof(line), fp)) {
- u = NULL;
- if (strstr(line, CONFIG_KEY_HOST)) {
- t = &mysql_host;
- u = &mysql_socket;
- }
- else if (strstr(line, CONFIG_KEY_USER))
- t = &mysql_user;
- else if (strstr(line, CONFIG_KEY_PASSWD))
- t = &mysql_passwd;
- else if (strstr(line, CONFIG_KEY_DB))
- t = &mysql_db;
- else
- t = NULL;
-
- if (t) {
- strtok(line, "\"");
- strtok(NULL, "\"");
- strtok(NULL, "\"");
- p = strtok(NULL, "\"");
-
- if (u) {
- p = strtok(p, ":");
- q = strtok(NULL, ":");
- }
- else q = NULL;
-
- if (p && !*t) {
- *t = malloc(strlen(p) + 1);
- strncpy(*t, p, strlen(p) + 1);
- }
-
- if (q && !*u) {
- *u = malloc(strlen(q) + 1);
- strncpy(*u, q, strlen(q) + 1);
- }
+ int opt;
+
+ static const struct option opts[] = {
+ { "mysql-host", required_argument, 0, 'h' },
+ { "mysql-socket", required_argument, 0, 'S' },
+ { "mysql-user", required_argument, 0, 'u' },
+ { "mysql-passwd", required_argument, 0, 'p' },
+ { "mysql-db", required_argument, 0, 'D' },
+ { 0, 0, 0, 0 }
+ };
+
+ while((opt = getopt_long(argc, argv, "h:S:u:p:D:", opts, NULL)) != -1) {
+ switch(opt) {
+ case 'h':
+ mysql_host = optarg;
+ break;;
+ case 'S':
+ mysql_socket = optarg;
+ break;;
+ case 'u':
+ mysql_user = optarg;
+ break;;
+ case 'p':
+ mysql_passwd = optarg;
+ break;;
+ case 'D':
+ mysql_db = optarg;
+ break;;
+ default:
+ return 0;
}
}
- fclose(fp);
-
- if (!mysql_host)
- die("MySQL host setting not found in AUR config file\n");
- if (!mysql_user)
- die("MySQL user setting not found in AUR config file\n");
- if (!mysql_passwd)
- die("MySQL password setting not found in AUR config file\n");
- if (!mysql_db)
- die("MySQL database setting not found in AUR config file\n");
+ return 1;
}
static void
@@ -288,12 +266,6 @@ init(void)
static void
cleanup(void)
{
- free(mysql_host);
- free(mysql_socket);
- free(mysql_user);
- free(mysql_passwd);
- free(mysql_db);
-
alpm_release(handle);
mysql_close(c);
mysql_library_end();
@@ -303,7 +275,9 @@ int main(int argc, char *argv[])
{
alpm_list_t *pkgs_cur, *pkgs_new;
- read_config(AUR_CONFIG);
+ if (!parse_options(argc, argv))
+ return 1;
+
init();
pkgs_cur = blacklist_get_pkglist();
diff --git a/scripts/aurblup/config.h.proto b/scripts/aurblup/config.h.proto
index 1a19ef42..45acb877 100644
--- a/scripts/aurblup/config.h.proto
+++ b/scripts/aurblup/config.h.proto
@@ -1,11 +1,3 @@
-/* AUR configuration file */
-#define AUR_CONFIG "/srv/aur/web/lib/config.inc.php"
-
-#define CONFIG_KEY_HOST "AUR_db_host"
-#define CONFIG_KEY_USER "AUR_db_user"
-#define CONFIG_KEY_PASSWD "AUR_db_pass"
-#define CONFIG_KEY_DB "AUR_db_name"
-
/* libalpm options */
#define ALPM_DBPATH "/var/lib/aurblup/"
#define ALPM_MIRROR "ftp://mirrors.kernel.org/archlinux/%s/os/x86_64"