mpm

morphux package manager
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/mpm

commit c9fc84936e1a50b74e19c9cb76c2c997d2783b33
parent 45889c900067a9b6ac0b4f8f4b742c2461e75876
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 14 Dec 2015 02:18:32 +0000

Add(Basic Kernel interface):

We can now recompile kernel with mpm, and add CONFIG_* requirements in packages.

Diffstat:
Ainc/Developer.hpp | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainc/Kernel.hpp | 40++++++++++++++++++++++++++++++++++++++++
Minc/main.hpp | 1+
Asrc/Kernel.cpp | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/Makefile.am | 3++-
Msrc/Options.cpp | 2+-
Msrc/main.cpp | 4++++
7 files changed, 210 insertions(+), 2 deletions(-)

diff --git a/inc/Developer.hpp b/inc/Developer.hpp @@ -0,0 +1,54 @@ +/* + * Developer.cpp + * By: Louis Solofrizzo <louis@ne02ptzero.me> + * 2015-13-12 19:17 + */ + +#ifndef __DEVELOPER__ +# define __DEVELOPER__ + +# include <sys/types.h> +# include <sys/stat.h> +# include <archive.h> +# include <dirent.h> +# include <archive_entry.h> +# include <curl/curl.h> +# include <iostream> +# include <fstream> +# include <stdio.h> +# include <list> +# include "Error.hpp" + +# define BASIC_FILE "{\n\ + \"package\": {\n\ + \"name\": \"\",\n\ + \"version\": \"\",\n\ + \"description\": \"\",\n\ + },\n\ + \"compilation\": {\n\ + \"before\": [],\n\ + \"patches\": [],\n\ + \"configure\": [],\n\ + \"make\": \"\",\n\ + \"install\": \"install\",\n\ + \"uninstall\": \"uninstall\",\n\ + },\n\ + \"dependencies\": {\n\ + \"needed\": [],\n\ + \"recommended\": [],\n\ + \"optionnal\": []\n\ + }\n\ +}" + +class Developer { + public: + Developer(void); + ~Developer(void); + + void createPackage(std::list<std::string>); + std::string getArchive(std::string url); + std::string extract(std::string archive); + +}; + +#endif diff --git a/inc/Kernel.hpp b/inc/Kernel.hpp @@ -0,0 +1,40 @@ +/* + * Kernel.cpp + * By: Louis Solofrizzo <louis@ne02ptzero.me> + * 2015-13-12 23:38 + */ + +#ifndef __KERNEL__ +# define __KERNEL__ + +# include <sys/utsname.h> +# include <iostream> +# include <fstream> +# include <time.h> +# include "Error.hpp" +# include "Exec.hpp" +# include "functions.hpp" + +typedef struct s_kern { + std::string name; + std::string value; + int isComment; +} t_kern; + +class Kernel { + public: + Kernel(void); + ~Kernel(void); + + void setConfig(std::string name, std::string value); + void make(void); + + static int recompile; + + private: + void _readConfig(std::string s); + + std::list<t_kern *> _config; +}; + +#endif diff --git a/inc/main.hpp b/inc/main.hpp @@ -13,5 +13,6 @@ # include "Error.hpp" # include "Download.hpp" # include "Manager.hpp" +# include "Kernel.hpp" #endif diff --git a/src/Kernel.cpp b/src/Kernel.cpp @@ -0,0 +1,108 @@ +/* + * Kernel.cpp + * By: Louis Solofrizzo <louis@ne02ptzero.me> + * 2015-13-12 23:38 + */ + +#include "Kernel.hpp" + +Kernel::Kernel(void) { + std::stringstream buffer; + std::ifstream fd; + struct utsname s_uname; + + uname(&s_uname); + fd.open("/usr/src/linux-" + std::string(s_uname.release) + "/.config"); + if (!fd.is_open()) + Error::error("The Kernel configuration file can not be found"); + buffer << fd.rdbuf(); + this->_readConfig(buffer.str()); +} + +Kernel::~Kernel(void) { + return ; +} + +void Kernel::_readConfig(std::string s) { + std::list<std::string> lst = split(s, '\n'), line; + std::list<std::string>::iterator it; + t_kern *tmp; + std::vector<std::string> vLine; + + for (it = lst.begin(); it != lst.end(); it++) { + if ((*it).length() > 1) { + line = split(*it, '='); + vLine = { std::begin(line), std::end(line) }; + tmp = new t_kern(); + if (vLine.size() == 2) { + tmp->name = vLine[0]; + tmp->value = vLine[1]; + tmp->isComment = 0; + this->_config.push_back(tmp); + } else if (vLine.size() == 1) { + line = split(*it, ' '); + vLine = { std::begin(line), std::end(line) }; + if (vLine.size() > 1 && vLine[1].substr(0, 6) == "CONFIG") { + tmp->name = vLine[1]; + tmp->value = ""; + tmp->isComment = 1; + this->_config.push_back(tmp); + } + } + } + } +} + +void Kernel::setConfig(std::string name, std::string value) { + std::list<t_kern *>::iterator it; + + for (it = this->_config.begin(); it != this->_config.end(); it++) { + if ((*it)->name == name) { + if ((*it)->value != value) { + (*it)->value = value; + if (value == "") + (*it)->isComment = 1; + else + (*it)->isComment = 0; + Kernel::recompile = 1; + } + } + } +} + +void Kernel::make(void) { + std::ofstream fd; + struct utsname s_uname; + time_t tm =time(NULL); + struct tm *curtime = localtime (&tm); + Exec *e = new Exec(); + std::list<t_kern *>::iterator it; + + uname(&s_uname); + fd.open("/usr/src/linux-" + std::string(s_uname.release) + "/.config", std::fstream::trunc); + fd << "# Linux Kernel " << std::string(s_uname.release) << " config file" << std::endl; + fd << "# Generated by Morphux Package Manager" << std::endl; + fd << "# Date: " << asctime(curtime); + fd << "# DO NOT EDIT" << std::endl << std::endl; + for (it = this->_config.begin(); it != this->_config.end(); it++) { + if ((*it)->isComment == 1) { + fd << "# " << (*it)->name << " is not set" << std::endl; + } else { + fd << (*it)->name << "=" << (*it)->value << std::endl; + } + } + chdir(std::string("/usr/src/linux-" + std::string(s_uname.release)).c_str()); + Error::info("Compiling Kernel"); + e->execute({"make"}); + Error::info("Modules installation"); + e->execute({"make", "modules_install"}); + Error::info("Installation"); + e->execute({"cp", "-v", "arch/" + Options::config["arch"].asString() + "/boot/bzImage", + "/boot/vmlinuz-" + std::string(s_uname.release) + "-morphux"}); + e->execute({"cp", "-v", ".config", + "/boot/Config-" + std::string(s_uname.release)}); + e->execute({"cp", "-v", "System.map", + "/boot/System-map-" + std::string(s_uname.release)}); +} + +int Kernel::recompile = 0; diff --git a/src/Makefile.am b/src/Makefile.am @@ -8,6 +8,7 @@ mpm_SOURCES = Download.cpp \ Options.cpp \ Package.cpp \ jsoncpp.cpp \ - Developer.cpp + Developer.cpp \ + Kernel.cpp AM_CXXFLAGS = -Wall -Wextra -Werror -std=c++0x -g -I../inc/ mpm_LDADD = -lcurl -larchive diff --git a/src/Options.cpp b/src/Options.cpp @@ -31,7 +31,7 @@ std::string Options::getOptions(std::string s) { } void Options::getConfig(void) { -std::string file; + std::string file; std::stringstream buffer; std::ifstream fd; Json::Reader read; diff --git a/src/main.cpp b/src/main.cpp @@ -52,6 +52,10 @@ void execute(void) { if (Options::args.size() != 2) Error::error("Create usage <package> <url>"); d->createPackage(Options::args); + } else if (cmd == "kernel") { + Kernel *k = new Kernel(); + k->make(); + delete k; } else { Error::error("Unknown action: " + cmd); }