mpm

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

commit c72a149f6b57281bcc0fdfa804873d330ef2dbc7
parent cb49d7b9be5406ca2dd41c6b0516652fcd6a7ce9
Author: Louis Solofrizzo <louis@ne02ptzero.me>
Date:   Sun,  4 Jan 2015 16:57:15 +0100

feat(install) New install process:

Binding 3 functions in one, Generating config files for uninstall.
Also, Add a test for an already installed package.

Diffstat:
Dsrc/.deps/download.Po | 1-
Dsrc/.deps/functions.Po | 1-
Dsrc/.deps/help.Po | 1-
Dsrc/.deps/install.Po | 1-
Dsrc/.deps/main.Po | 1-
Dsrc/.deps/options.Po | 1-
Dsrc/.deps/package.Po | 1-
Dsrc/.deps/parse.Po | 1-
Dsrc/.deps/resume.Po | 1-
Dsrc/.deps/unpack.Po | 1-
Msrc/download.c | 5++---
Msrc/install.c | 14+++++++++++++-
Msrc/parse.c | 22++++++++++++++++++----
Msrc/unpack.c | 105++++++++++++++++++++++++++++++++++++++++++-------------------------------------
14 files changed, 89 insertions(+), 67 deletions(-)

diff --git a/src/.deps/download.Po b/src/.deps/download.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/functions.Po b/src/.deps/functions.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/help.Po b/src/.deps/help.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/install.Po b/src/.deps/install.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/main.Po b/src/.deps/main.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/options.Po b/src/.deps/options.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/package.Po b/src/.deps/package.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/parse.Po b/src/.deps/parse.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/resume.Po b/src/.deps/resume.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/.deps/unpack.Po b/src/.deps/unpack.Po @@ -1 +0,0 @@ -# dummy diff --git a/src/download.c b/src/download.c @@ -68,9 +68,8 @@ void download(mpm_pinfo *p) { } curl_easy_cleanup(curl); fflush(stdout); - printf("\n"); - success("Done !"); - unpacking(getTarName(p->url), p); + printf("\nDone!\n"); + unpack_install(getTarName(p->url), p); p = p->next; } curl_global_cleanup(); diff --git a/src/install.c b/src/install.c @@ -42,6 +42,7 @@ static char *get_web_page(char *name) { } } + mpm_pinfo *get_info(char *name, mpm_pinfo *packages) { char *conf; @@ -51,6 +52,13 @@ mpm_pinfo *get_info(char *name, mpm_pinfo *packages) { return packages; } +int package_len(mpm_pinfo *p) { + int i; + + for (i = 0; p; p = p->next, i++); + return i; +} + void install(mpm_package *p) { mpm_pinfo *packages; @@ -61,7 +69,11 @@ void install(mpm_package *p) { packages = get_info(p->package, packages); p = p->next; } -/* print_packages(packages);*/ + /*print_packages(packages);*/ + if (!package_len(packages)) { + info("No package need to be installed."); + _exit(0); + } resume(packages); download(packages); } diff --git a/src/parse.c b/src/parse.c @@ -10,6 +10,15 @@ static char *return_string(char *str) { return NULL; } +int is_install(mpm_pinfo *p) { + DIR *dir; + + dir = opendir(strjoin("/etc/mpm/", p->name)); + if (!dir) + return 0; + return 1; +} + mpm_pinfo *parse(char *str, mpm_pinfo *packages) { char **conf = ft_strsplit(str, '\n'), **tmp; int i; @@ -46,11 +55,8 @@ mpm_pinfo *parse(char *str, mpm_pinfo *packages) { } if (i == 0) error("Config file error"); - if (packages) - pack_tmp->next = packages; else - pack_tmp->next = NULL; - success("Configuration file: done. Looking for dependencies..."); + success("Configuration file: done. Looking for dependencies..."); if (pack_tmp->dependencies) { conf = ft_strsplit(pack_tmp->dependencies, ','); for (i = 0; conf[i]; i++) { @@ -58,6 +64,14 @@ mpm_pinfo *parse(char *str, mpm_pinfo *packages) { pack_tmp = get_info(conf[i], pack_tmp); } } + if (is_install(pack_tmp)) { + info(strjoin("The package ", strjoin(pack_tmp->name, " is already installed !"))); + return packages; + } else if (packages) { + pack_tmp->next = packages; + } else { + pack_tmp->next = NULL; + } return pack_tmp; } diff --git a/src/unpack.c b/src/unpack.c @@ -8,82 +8,89 @@ static char *get_extract_directory(void) { read(fd, buffer, 50); result = ft_strsplit(buffer, '/'); close(fd); - remove("/tmp/mpm.log"); return strjoin("/tmp/", result[0]); } extern char **environ; -void configure(char *path, mpm_pinfo *p) { - info("Running configure.."); - char **configure = ft_strsplit(p->configure, ' '); - int pid, status; +void exec(char *cmd, int type, char *prefix) { + char **command = ft_strsplit(cmd, ' '); + int pid, status, fd; - configure[0] = strjoin(path, configure[0]); + if (type == 0) + info("Running configure..."); + else if (type == 1) + info("Running make..."); + else if (type == 2) + info("Running make install..."); + command[0] = strjoin(prefix, command[0]); if (!(pid = fork())) { - int fd = open("/dev/null", O_WRONLY); + fd = open("/var/log/mpm.log", O_WRONLY | O_APPEND | O_CREAT, 0777); dup2(fd, 1); - execve(configure[0], configure, environ); + dup2(fd, 2); + execve(command[0], command, environ); } waitpid(pid, &status, 0); + close(fd); if (status > 0) - error("Configure return an error"); - info("Done."); + error("An error append, see /var/log/mpm.log for more information"); + printf("Done.\n"); } -void make(mpm_pinfo *p) { - info("Running make..."); - char **make = ft_strsplit(p->make, ' '); - int pid, status; +static void do_extract(char *path) { + int pid, fd; - make[0] = strjoin("/usr/bin/", make[0]); - if (!(pid = fork())) { - int fd = open("/dev/null", O_WRONLY); + info("Unpacking..."); + if (!(pid = fork())){ + fd = open("/tmp/mpm.log", O_WRONLY | O_CREAT | O_TRUNC, 0777); dup2(fd, 1); - execve(make[0], make, environ); + execl("/bin/tar", "/bin/tar", "xvf", path, "-C", "/tmp/", NULL); } - waitpid(pid, &status, 0); - if (status > 0) - error("Make return an error"); - info("Done."); + waitpid(pid, &pid, 0); + close(fd); + success("Done."); } -void make_install(mpm_pinfo *p) { - info("Install the package..."); - char **install = ft_strsplit(p->install, ' '); - int pid, status; +static void package_config(mpm_pinfo *p) { + int fd, fd2; + char buffer[1]; - install[0] = strjoin("/usr/bin/", install[0]); - if (!(pid = fork())) { - int fd = open("/dev/null", O_WRONLY); - dup2(fd, 1); - execve(install[0], install, environ); - } - waitpid(pid, &status, 0); - if (status > 0) - error("Installation return an error"); - info("Done."); + info("Making local configuration"); + mkdir(strjoin("/etc/mpm/", p->name), 0777); + fd = open("/tmp/build/Makefile", O_RDONLY); + fd2 = open(strjoin("/etc/mpm/", strjoin(p->name, "/Makefile")), O_CREAT | O_WRONLY , 0777); + if ((fd == -1)) { + info("Can't find /tmp/build/Makefile, trying to find /tmp/build/makefile"); + close(fd); + fd = open("/tmp/build/makefile", O_RDONLY); + if (fd == -1) + error("Failed. No makefile found. (The Package is installed but can't be uninstall). Please mail to packages[at]lists.morphux.org about this situation"); + } else if (fd2 == -1) + error("Can't open the config directory. Is the chmod of /etc/mpm good (777)?"); + while (read(fd, buffer, 1)) + write(fd2, buffer, 1); + printf("Done.\n"); +} + +static void clean(mpm_pinfo *p, char *extract) { + info("Cleaning..."); + exec(strjoin("rm -rf /tmp/build ", extract), 3, "/bin/"); + remove("/tmp/mpm.log"); } -void unpacking(char *path, mpm_pinfo *p) { +void unpack_install(char *path, mpm_pinfo *p) { char *extract_dir; - int pid; - info("Unpacking ..."); - if (!(pid = fork())){ - int fd = open("/tmp/mpm.log", O_WRONLY | O_CREAT, 0777); - dup2(fd, 1); - execl("/bin/tar", "/bin/tar", "xvf", path, "-C", "/tmp/", NULL); - } - waitpid(pid, &pid, 0); - success("Done."); + do_extract(path); extract_dir = get_extract_directory(); info("Making build directory"); mkdir("/tmp/build", 0777); info("Changing directory"); chdir("/tmp/build"); - configure(extract_dir, p); - make(p); - make_install(p); + exec(p->configure, 0, extract_dir); + exec(p->make, 1, "/usr/bin/"); + exec(p->install, 2, "/usr/bin/"); + package_config(p); + clean(p, extract_dir); success("Package installed !"); }