libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 32d7ec6730fb4998681a677e28292e619e1c745a
parent 06eb67f4b0ec398cdec141ea65ec6b6f13f4485c
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 13 Feb 2017 23:07:33 +0100

Merge branch 'unstable'

Diffstat:
MMakefile | 3++-
Ainc/config.h | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Minc/libmpm.h | 1+
Asrc/config.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/Makefile | 3++-
Mtests/base.conf | 47++++++++++++++++++++++++++++++++++++++++++-----
Mtests/main.c | 1+
Mtests/test.h | 1+
Atests/test_config.c | 15+++++++++++++++
9 files changed, 193 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile @@ -24,7 +24,8 @@ IFLAGS = -I inc/ \ -I lib/libmorphux/inc/ \ -I lib/curl/lib/ \ -I lib/json-c/ \ - -I lib/sqlite + -I lib/sqlite \ + -I lib/libconfuse/src/ # Optimisation Flags OFLAGS = -std=c99 -g -O3 diff --git a/inc/config.h b/inc/config.h @@ -0,0 +1,57 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + +#ifndef CONFIG_H +# define CONFIG_H + +# include <confuse.h> +# include <morphux.h> + +# define CONFIG_DEF_PATH "/etc/mpm/mpm.conf" + +# define CONFIG_MAIN_SEC "main" +# define CONFIG_MAIN_INST_MODE "install-mode" +# define CONFIG_MAIN_THREAD_INST "thread-install" + +# define CONFIG_LOG_SEC "log" +# define CONFIG_LOG_VERBOSE_LVL "verbose-level" +# define CONFIG_LOG_DIR "directory" + +# define CONFIG_DL_SEC "download" +# define CONFIG_DL_MAIN_SITE "main-site" +# define CONFIG_DL_THREAD_DL "thread-downloading" +# define CONFIG_DL_DIR "directory" +# define CONFIG_DL_MIRROR_LIST "mirror-list" + +# define CONFIG_COMP_SEC "compile" +# define CONFIG_COMP_SBU "sbu" +# define CONFIG_COMP_CONF_DEF "configure-def" +# define CONFIG_COMP_MAKE_DEF "make-def" + +# define CONFIG_PKG_SEC "packages" +# define CONFIG_PKG_DB "database" +# define CONFIG_PKG_TREE "tree" + +# define CONFIG_KERN_SEC "kernel" +# define CONFIG_KERN_SRC "sources" + +# define CONFIG_BOOT_SEC "boot" +# define CONFIG_BOOT_MNT_WHEN_NEEDED "mount-when-needed" +# define CONFIG_BOOT_GRUB_DIR "grub-dir" + +u8_t parse_config(const char *path, cfg_t **config); + +#endif /* CONFIG_H */ diff --git a/inc/libmpm.h b/inc/libmpm.h @@ -20,5 +20,6 @@ # include <morphux.h> # include <flags.h> # include <database.h> +# include <config.h> #endif /* LIBMPM_H */ diff --git a/src/config.c b/src/config.c @@ -0,0 +1,72 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + +#include "config.h" + +u8_t parse_config(const char *path, cfg_t **config) { + cfg_opt_t opts_main[] = { + CFG_INT(CONFIG_MAIN_THREAD_INST,0, CFGF_NONE), + CFG_STR(CONFIG_MAIN_INST_MODE, "binary", CFGF_NONE), + CFG_END() + }; + cfg_opt_t opts_log[] = { + CFG_INT(CONFIG_LOG_VERBOSE_LVL, 1, CFGF_NONE), + CFG_STR(CONFIG_LOG_DIR, "/var/log/mpm", CFGF_NONE), + CFG_END() + }; + cfg_opt_t opts_dl[] = { + CFG_STR(CONFIG_DL_MAIN_SITE, "pkgs.morphux.org", CFGF_NONE), + CFG_INT(CONFIG_DL_THREAD_DL, 0, CFGF_NONE), + CFG_STR(CONFIG_DL_DIR, "/var/cache/mpm/pkgs/", CFGF_NONE), + CFG_STR(CONFIG_DL_MIRROR_LIST, "/var/lib/mpm/mirrors", CFGF_NONE), + CFG_END() + }; + cfg_opt_t opts_comp[] = { + CFG_INT(CONFIG_COMP_SBU, 0, CFGF_NONE), + CFG_STR_LIST(CONFIG_COMP_CONF_DEF,"{\"--prefix=/usr\"}", CFGF_NONE), + CFG_STR_LIST(CONFIG_COMP_MAKE_DEF,"{-j2}", CFGF_NONE), + CFG_END() + }; + cfg_opt_t opts_pkg[] = { + CFG_STR(CONFIG_PKG_DB, "/var/lib/mpm/package.db", CFGF_NONE), + CFG_STR(CONFIG_PKG_TREE, "/var/cache/mpm/tree", CFGF_NONE), + CFG_END() + }; + cfg_opt_t opts_kern[] = { + CFG_STR(CONFIG_KERN_SRC, "/usr/src/linux-current", CFGF_NONE), + CFG_END() + }; + cfg_opt_t opts_boot[] = { + CFG_INT(CONFIG_BOOT_MNT_WHEN_NEEDED, 0, CFGF_NONE), + CFG_STR(CONFIG_BOOT_GRUB_DIR, "/boot/grub", CFGF_NONE), + CFG_END() + }; + cfg_opt_t opts[] = { + CFG_SEC(CONFIG_MAIN_SEC, opts_main, CFGF_NONE), + CFG_SEC(CONFIG_LOG_SEC, opts_log, CFGF_NONE), + CFG_SEC(CONFIG_DL_SEC, opts_dl, CFGF_NONE), + CFG_SEC(CONFIG_COMP_SEC, opts_comp, CFGF_NONE), + CFG_SEC(CONFIG_PKG_SEC, opts_pkg, CFGF_NONE), + CFG_SEC(CONFIG_KERN_SEC, opts_kern, CFGF_NONE), + CFG_SEC(CONFIG_BOOT_SEC, opts_boot, CFGF_NONE), + CFG_END() + }; + u8_t ret; + + *config = cfg_init(opts, CFGF_NONE); + ret = cfg_parse(*config, path != NULL ? path : CONFIG_DEF_PATH); + return ret; +} diff --git a/tests/Makefile b/tests/Makefile @@ -6,7 +6,8 @@ IFLAGS = -I ../inc/ \ -I ../lib/libmorphux/inc/ \ -I ../lib/curl/lib/ \ -I ../lib/json-c/ \ - -I ../lib/sqlite + -I ../lib/sqlite \ + -I ../lib/libconfuse/src/ # Optimisation Flags OFLAGS = -std=c99 -g -O3 diff --git a/tests/base.conf b/tests/base.conf @@ -1,7 +1,8 @@ # MPM Basic config # Main section -section main { +main { + # Installation mode (sources | binary) install-mode = sources # Threading install: # If possible, the package manager will execute concurrent installation @@ -9,19 +10,55 @@ section main { } # Log section -section log { +log { # Verbose level: # 0: None # 1: Basic # 2: Informative # 3: Debug verbose-level = 2 - file = "/var/log/mpm.log" + # Log directory + directory = "/var/log/mpm/" } # Download section -section download { - main-site = pkgs.morphux.org +download { + # Packages main site + main-site = "pkgs.morphux.org" # Download multiple archives at the same time thread-downloading = 0 + # Temporay directory of the downloaded archives + directory = "/var/cache/mpm/pkgs/" + # Mirror lists + mirror-list = "/var/lib/mpm/mirrors" +} + +# Compile section +compile { + sbu = 60 + configure-def = {"--prefix=/usr"} + make-def = {"-j2"} +} + +# Packages section +packages { + # Database file path + database = "/var/lib/mpm/package.db" + # Binary tree file path + tree = "/var/cache/mpm/tree" +} + +# Kernel section +kernel { + # Kernel source directory + sources = "/usr/src/linux-current" +} + +# Boot section +boot { + # Only mount /boot when needed + # (Grub reconfiguration | Kernel recompilation) + mount-when-needed = 0 + # Grub config directory + grub-dir = "/boot/grub" } diff --git a/tests/main.c b/tests/main.c @@ -7,6 +7,7 @@ int main(void) { register_test_database(); register_test_files(); register_test_category(); + register_test_config(); ret = test_all(); test_free(); return ret; diff --git a/tests/test.h b/tests/test.h @@ -14,6 +14,7 @@ void register_flags_test(void); void register_test_database(void); void register_test_files(void); void register_test_category(void); +void register_test_config(void); void clean_db(const char *name); int free_sql_results(void *ptr); diff --git a/tests/test_config.c b/tests/test_config.c @@ -0,0 +1,15 @@ +# include "test.h" + +TEST(config_basic) { + u8_t ret; + cfg_t *conf = NULL; + + ret = parse_config("base.conf", &conf); + TEST_ASSERT((ret == 0), "Can't open configuration file"); + cfg_free(conf); + return TEST_SUCCESS; +} + +void register_test_config(void) { + reg_test("config", config_basic); +}