new: install requirements after pull

This commit is contained in:
ngn 2024-05-04 22:34:48 +03:00
parent dbaf581335
commit c439f30820
5 changed files with 158 additions and 17 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-04 20:25+0300\n" "POT-Creation-Date: 2024-05-04 22:30+0300\n"
"PO-Revision-Date: 2024-05-01 13:34+0300\n" "PO-Revision-Date: 2024-05-01 13:34+0300\n"
"Last-Translator: <ngn@ngn.tf>\n" "Last-Translator: <ngn@ngn.tf>\n"
"Language-Team: Turkish <gnome-turk@gnome.org>\n" "Language-Team: Turkish <gnome-turk@gnome.org>\n"
@ -74,19 +74,19 @@ msgstr ""
msgid "Failed to change directory to the specified directory" msgid "Failed to change directory to the specified directory"
msgstr "" msgstr ""
#: src/gen.c:29 src/gen.c:36 src/pull.c:82 #: src/gen.c:29 src/gen.c:36 src/pull.c:83
msgid "Loaded repository configuration" msgid "Loaded repository configuration"
msgstr "" msgstr ""
#: src/gen.c:31 src/pull.c:77 #: src/gen.c:31 src/pull.c:78
msgid "Failed to load the configuration file (mc.cfg):" msgid "Failed to load the configuration file (mc.cfg):"
msgstr "" msgstr ""
#: src/gen.c:42 src/pull.c:109 #: src/gen.c:42 src/pull.c:110
msgid "Copying all the targets" msgid "Copying all the targets"
msgstr "" msgstr ""
#: src/gen.c:48 src/pull.c:121 #: src/gen.c:48 src/pull.c:124
msgid "Failed to copy the target:" msgid "Failed to copy the target:"
msgstr "" msgstr ""
@ -161,50 +161,58 @@ msgid ""
"information" "information"
msgstr "" msgstr ""
#: src/pull.c:27 #: src/pull.c:28
msgid "Please specify a config name or a URL" msgid "Please specify a config name or a URL"
msgstr "" msgstr ""
#: src/pull.c:56 #: src/pull.c:57
#, c-format #, c-format
msgid "Cloning %s" msgid "Cloning %s"
msgstr "" msgstr ""
#: src/pull.c:61 #: src/pull.c:62
#, c-format #, c-format
msgid "Failed to clone the %s:" msgid "Failed to clone the %s:"
msgstr "" msgstr ""
#: src/pull.c:72 #: src/pull.c:73
#, c-format #, c-format
msgid "Failed to chdir to %s" msgid "Failed to chdir to %s"
msgstr "" msgstr ""
#: src/pull.c:85 #: src/pull.c:86
msgid "Do you want to continue?" msgid "Do you want to continue?"
msgstr "" msgstr ""
#: src/pull.c:91 #: src/pull.c:92
msgid "Checking all the targets" msgid "Checking all the targets"
msgstr "" msgstr ""
#: src/pull.c:97 #: src/pull.c:98
#, c-format #, c-format
msgid "Failed to access the source for the target \"%s\"" msgid "Failed to access the source for the target \"%s\""
msgstr "" msgstr ""
#: src/pull.c:106 #: src/pull.c:107
msgid "All the target checks were successful" msgid "All the target checks were successful"
msgstr "" msgstr ""
#: src/pull.c:114 #: src/pull.c:118
msgid "Install the target?" msgid "Install the target?"
msgstr "" msgstr ""
#: src/pull.c:115 #: src/pull.c:119
msgid "Skipping target" msgid "Skipping target"
msgstr "" msgstr ""
#: src/pull.c:157
msgid "Installing all the requirements"
msgstr ""
#: src/pull.c:160
msgid "Failed to run the mp-install command"
msgstr ""
#: src/target.c:15 #: src/target.c:15
msgid "Configuration target is missing a name" msgid "Configuration target is missing a name"
msgstr "" msgstr ""

View File

@ -12,6 +12,10 @@ enum ErrorCodes {
OpendirFail = 948, OpendirFail = 948,
MkdirFail = 945, MkdirFail = 945,
OpenFail = 944, OpenFail = 944,
RunNoRoot = 943,
RunCmdNotFound = 942,
RunCmdFail = 941,
}; };
extern int errno; extern int errno;

View File

@ -6,6 +6,7 @@
#include "paths.h" #include "paths.h"
#include "url.h" #include "url.h"
#include "util.h" #include "util.h"
#include "run.h"
#include <git2.h> #include <git2.h>
#include <git2/global.h> #include <git2/global.h>
@ -108,13 +109,15 @@ COPY:
cur = repo_cfg.t_first; cur = repo_cfg.t_first;
info(_("Copying all the targets")); info(_("Copying all the targets"));
char **argv = NULL;
int argc = 0, indx = 0;
while (cur && ++counter > 0) { while (cur && ++counter > 0) {
target_print(cur); target_print(cur);
if (!yesno(_("Install the target?"))) { if (!yesno(_("Install the target?"))) {
info(_("Skipping target")); info(_("Skipping target"));
cur = cur->next; goto NEXT;
continue;
} }
if (!target_copy(cur, false)) { if (!target_copy(cur, false)) {
@ -123,11 +126,43 @@ COPY:
goto END; goto END;
} }
argc += cur->require.s;
if(0 == argc)
goto NEXT;
if(NULL == argv)
argv = malloc(sizeof(char*)*argc);
else
argv = realloc(argv, sizeof(char*)*argc);
for(int i = 0; i < cur->require.s; i++){
argv[indx] = cur->require.c[i];
indx++;
}
NEXT:
cur = cur->next; cur = cur->next;
} }
if(NULL == argv){
ret = true;
goto END;
}
argc++;
argv = realloc(argv, sizeof(char*)*argc);
argv[indx] = NULL;
ret = true; ret = true;
info(_("Installing all the requirements"));
if(!run_cmd_root("mp-install", argv)){
ret = false;
error(_("Failed to run the mp-install command"));
details(errch);
}
free(argv);
END: END:
if (repo_cfg.name != NULL) if (repo_cfg.name != NULL)
config_free(&repo_cfg); config_free(&repo_cfg);

90
src/run.c Normal file
View File

@ -0,0 +1,90 @@
#include <sys/wait.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <spawn.h>
#include <stdio.h>
#include "error.h"
#include "util.h"
#include "run.h"
extern char **environ;
char *run_find_cmd(char *cmd){
char *path = getenv("PATH"), *save, *el;
while((el = strtok_r(path, ":", &save)) != NULL){
char fp[strlen(el)+strlen(cmd)+2];
join(fp, el, cmd);
if(exists(fp))
return strdup(fp);
}
return NULL;
}
bool run_cmd(char **all){
pid_t pid;
if(posix_spawn(&pid, all[0], NULL, NULL, all, environ) != 0)
return false;
int status;
waitpid(pid, &status, 0);
return status == 0;
}
bool run_cmd_root(char *cmd, char **args){
char *rootcmd = NULL;
if(NULL == run_find_cmd(cmd)){
error_set("Command not found");
errno = RunCmdNotFound;
return false;
}
if(getuid()==0)
goto RUN;
else if((rootcmd = run_find_cmd("doas")) != NULL)
goto RUN;
else if((rootcmd = run_find_cmd("sudo" )) != NULL)
goto RUN;
error_set("There is no doas or sudo installed");
errno = RunNoRoot;
return false;
RUN:
int arg_count = 0;
while(args[arg_count] != NULL)
arg_count++;
arg_count += 2;
if(rootcmd != NULL)
arg_count++;
char **all = malloc(arg_count*sizeof(char*));
int indx = 0;
if(rootcmd != NULL){
all[indx] = rootcmd;
all[++indx] = cmd;
}else
all[indx] = rootcmd;
for(int i = 0; i < arg_count; i++)
all[++indx] = args[i];
all[++indx] = NULL;
bool ret = true;
if(!run_cmd(all)){
error_set("Command failed");
errno = RunCmdFail;
ret = false;
}
free(all);
return ret;
}

4
src/run.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
#include <stdbool.h>
bool run_cmd_root(char *, char **);