update: fix formatting

This commit is contained in:
ngn 2024-05-05 23:26:01 +03:00
parent 88b948e186
commit c8bdc795a9
3 changed files with 39 additions and 39 deletions

View File

@ -185,7 +185,7 @@ bool config_load(config_t *config, char *path) {
void config_print(config_t *config) { void config_print(config_t *config) {
info(_("Configuration details:\n")); info(_("Configuration details:\n"));
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Name"), config->name); printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Name"), config->name);
if(NULL != config->desc) if (NULL != config->desc)
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Desc"), config->desc); printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Desc"), config->desc);
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Author"), config->author); printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Author"), config->author);

View File

@ -4,9 +4,9 @@
#include "error.h" #include "error.h"
#include "log.h" #include "log.h"
#include "paths.h" #include "paths.h"
#include "run.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>
@ -110,7 +110,7 @@ COPY:
info(_("Copying all the targets")); info(_("Copying all the targets"));
char **argv = NULL; char **argv = NULL;
int argc = 0, indx = 0; int argc = 0, indx = 0;
while (cur && ++counter > 0) { while (cur && ++counter > 0) {
target_print(cur); target_print(cur);
@ -127,35 +127,35 @@ COPY:
} }
argc += cur->require.s; argc += cur->require.s;
if(0 == argc) if (0 == argc)
goto NEXT; goto NEXT;
if(NULL == argv) if (NULL == argv)
argv = malloc(sizeof(char*)*argc); argv = malloc(sizeof(char *) * argc);
else else
argv = realloc(argv, sizeof(char*)*argc); argv = realloc(argv, sizeof(char *) * argc);
for(int i = 0; i < cur->require.s; i++){ for (int i = 0; i < cur->require.s; i++) {
argv[indx] = cur->require.c[i]; argv[indx] = cur->require.c[i];
indx++; indx++;
} }
NEXT: NEXT:
cur = cur->next; cur = cur->next;
} }
if(NULL == argv){ if (NULL == argv) {
ret = true; ret = true;
goto END; goto END;
} }
argc++; argc++;
argv = realloc(argv, sizeof(char*)*argc); argv = realloc(argv, sizeof(char *) * argc);
argv[indx] = NULL; argv[indx] = NULL;
ret = true; ret = true;
info(_("Installing all the requirements")); info(_("Installing all the requirements"));
if(!run_cmd_root("mp-install", argv)){ if (!run_cmd_root("mp-install", argv)) {
ret = false; ret = false;
error(_("Failed to run the mp-install command")); error(_("Failed to run the mp-install command"));
details(errch); details(errch);

View File

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