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 ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: <ngn@ngn.tf>\n"
"Language-Team: Turkish <gnome-turk@gnome.org>\n"
@ -74,19 +74,19 @@ msgstr ""
msgid "Failed to change directory to the specified directory"
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"
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):"
msgstr ""
#: src/gen.c:42 src/pull.c:109
#: src/gen.c:42 src/pull.c:110
msgid "Copying all the targets"
msgstr ""
#: src/gen.c:48 src/pull.c:121
#: src/gen.c:48 src/pull.c:124
msgid "Failed to copy the target:"
msgstr ""
@ -161,50 +161,58 @@ msgid ""
"information"
msgstr ""
#: src/pull.c:27
#: src/pull.c:28
msgid "Please specify a config name or a URL"
msgstr ""
#: src/pull.c:56
#: src/pull.c:57
#, c-format
msgid "Cloning %s"
msgstr ""
#: src/pull.c:61
#: src/pull.c:62
#, c-format
msgid "Failed to clone the %s:"
msgstr ""
#: src/pull.c:72
#: src/pull.c:73
#, c-format
msgid "Failed to chdir to %s"
msgstr ""
#: src/pull.c:85
#: src/pull.c:86
msgid "Do you want to continue?"
msgstr ""
#: src/pull.c:91
#: src/pull.c:92
msgid "Checking all the targets"
msgstr ""
#: src/pull.c:97
#: src/pull.c:98
#, c-format
msgid "Failed to access the source for the target \"%s\""
msgstr ""
#: src/pull.c:106
#: src/pull.c:107
msgid "All the target checks were successful"
msgstr ""
#: src/pull.c:114
#: src/pull.c:118
msgid "Install the target?"
msgstr ""
#: src/pull.c:115
#: src/pull.c:119
msgid "Skipping target"
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
msgid "Configuration target is missing a name"
msgstr ""

View File

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

View File

@ -6,6 +6,7 @@
#include "paths.h"
#include "url.h"
#include "util.h"
#include "run.h"
#include <git2.h>
#include <git2/global.h>
@ -108,13 +109,15 @@ COPY:
cur = repo_cfg.t_first;
info(_("Copying all the targets"));
char **argv = NULL;
int argc = 0, indx = 0;
while (cur && ++counter > 0) {
target_print(cur);
if (!yesno(_("Install the target?"))) {
info(_("Skipping target"));
cur = cur->next;
continue;
goto NEXT;
}
if (!target_copy(cur, false)) {
@ -123,11 +126,43 @@ COPY:
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;
}
if(NULL == argv){
ret = true;
goto END;
}
argc++;
argv = realloc(argv, sizeof(char*)*argc);
argv[indx] = NULL;
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:
if (repo_cfg.name != NULL)
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 **);