mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
This commit is contained in:
parent
21e6c3f65f
commit
6dc61e7d9e
3 changed files with 56 additions and 73 deletions
17
scripts/aurblup/aurblup-wrapper
Executable file
17
scripts/aurblup/aurblup-wrapper
Executable file
|
@ -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));
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <alpm.h>
|
#include <alpm.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <mysql.h>
|
#include <mysql.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.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 void blacklist_sync(alpm_list_t *, alpm_list_t *);
|
||||||
static alpm_list_t *dblist_get_pkglist(alpm_list_t *);
|
static alpm_list_t *dblist_get_pkglist(alpm_list_t *);
|
||||||
static alpm_list_t *dblist_create(void);
|
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 init(void);
|
||||||
static void cleanup(void);
|
static void cleanup(void);
|
||||||
|
|
||||||
static char *mysql_host = NULL;
|
static char *mysql_host = "localhost";
|
||||||
static char *mysql_socket = NULL;
|
static char *mysql_socket = NULL;
|
||||||
static char *mysql_user = NULL;
|
static char *mysql_user = "aur";
|
||||||
static char *mysql_passwd = NULL;
|
static char *mysql_passwd = "aur";
|
||||||
static char *mysql_db = NULL;
|
static char *mysql_db = "AUR";
|
||||||
|
|
||||||
static MYSQL *c;
|
static MYSQL *c;
|
||||||
|
|
||||||
|
@ -208,65 +209,42 @@ dblist_create(void)
|
||||||
return dblist;
|
return dblist;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int parse_options(int argc, char **argv)
|
||||||
read_config(const char *fn)
|
|
||||||
{
|
{
|
||||||
FILE *fp;
|
int opt;
|
||||||
char line[128];
|
|
||||||
char **t, **u, *p, *q;
|
|
||||||
|
|
||||||
if (!(fp = fopen(fn, "r")))
|
static const struct option opts[] = {
|
||||||
die("failed to open AUR config file (\"%s\")\n", fn);
|
{ "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 (fgets(line, sizeof(line), fp)) {
|
while((opt = getopt_long(argc, argv, "h:S:u:p:D:", opts, NULL)) != -1) {
|
||||||
u = NULL;
|
switch(opt) {
|
||||||
if (strstr(line, CONFIG_KEY_HOST)) {
|
case 'h':
|
||||||
t = &mysql_host;
|
mysql_host = optarg;
|
||||||
u = &mysql_socket;
|
break;;
|
||||||
}
|
case 'S':
|
||||||
else if (strstr(line, CONFIG_KEY_USER))
|
mysql_socket = optarg;
|
||||||
t = &mysql_user;
|
break;;
|
||||||
else if (strstr(line, CONFIG_KEY_PASSWD))
|
case 'u':
|
||||||
t = &mysql_passwd;
|
mysql_user = optarg;
|
||||||
else if (strstr(line, CONFIG_KEY_DB))
|
break;;
|
||||||
t = &mysql_db;
|
case 'p':
|
||||||
else
|
mysql_passwd = optarg;
|
||||||
t = NULL;
|
break;;
|
||||||
|
case 'D':
|
||||||
if (t) {
|
mysql_db = optarg;
|
||||||
strtok(line, "\"");
|
break;;
|
||||||
strtok(NULL, "\"");
|
default:
|
||||||
strtok(NULL, "\"");
|
return 0;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
return 1;
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -288,12 +266,6 @@ init(void)
|
||||||
static void
|
static void
|
||||||
cleanup(void)
|
cleanup(void)
|
||||||
{
|
{
|
||||||
free(mysql_host);
|
|
||||||
free(mysql_socket);
|
|
||||||
free(mysql_user);
|
|
||||||
free(mysql_passwd);
|
|
||||||
free(mysql_db);
|
|
||||||
|
|
||||||
alpm_release(handle);
|
alpm_release(handle);
|
||||||
mysql_close(c);
|
mysql_close(c);
|
||||||
mysql_library_end();
|
mysql_library_end();
|
||||||
|
@ -303,7 +275,9 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
alpm_list_t *pkgs_cur, *pkgs_new;
|
alpm_list_t *pkgs_cur, *pkgs_new;
|
||||||
|
|
||||||
read_config(AUR_CONFIG);
|
if (!parse_options(argc, argv))
|
||||||
|
return 1;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
pkgs_cur = blacklist_get_pkglist();
|
pkgs_cur = blacklist_get_pkglist();
|
||||||
|
|
|
@ -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 */
|
/* libalpm options */
|
||||||
#define ALPM_DBPATH "/var/lib/aurblup/"
|
#define ALPM_DBPATH "/var/lib/aurblup/"
|
||||||
#define ALPM_MIRROR "ftp://mirrors.kernel.org/archlinux/%s/os/x86_64"
|
#define ALPM_MIRROR "ftp://mirrors.kernel.org/archlinux/%s/os/x86_64"
|
||||||
|
|
Loading…
Add table
Reference in a new issue