Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
48d177965e | |||
b8243e3ee9 | |||
5ad1b09971 | |||
c8bdc795a9 | |||
88b948e186 | |||
fb9b7682e2 |
9
Makefile
9
Makefile
@ -6,7 +6,7 @@ PO_SRCS = $(wildcard locale/*/*/*.po)
|
||||
PO_OUTS = $(patsubst locale/%.po,locale/%.mo,$(PO_SRCS))
|
||||
PO_DIRS = $(wildcard locale/*/*)
|
||||
|
||||
VERSION = 24.22
|
||||
VERSION = 24.02
|
||||
prefix = /usr
|
||||
CC = gcc
|
||||
|
||||
@ -14,7 +14,7 @@ all: dist/mc $(PO_OUTS)
|
||||
|
||||
dist/mc: $(CSRCS) $(HEADERS)
|
||||
mkdir -p dist
|
||||
$(CC) $(CFLAGS) $(CSRCS) -o $@ -DVERSION=\"${VERSION}\" -linih -lgit2 -lcrypto
|
||||
$(CC) $(CFLAGS) $(CSRCS) -o $@ -DVERSION=\"${VERSION}\" -linih -lgit2 -lcurl -lcrypto
|
||||
|
||||
locale/%.mo: locale/%.po
|
||||
msgfmt $^ -o $@
|
||||
@ -34,8 +34,6 @@ locale/mc.pot: $(CSRCS)
|
||||
xgettext -k_ -c $^ -o $@
|
||||
|
||||
install:
|
||||
mkdir -pv $(DESTDIR)/etc/mc
|
||||
mkdir -pv $(DESTDIR)/var/lib/mc
|
||||
mkdir -pv $(DESTDIR)$(prefix)/bin
|
||||
install -v -m755 dist/mc $(DESTDIR)$(prefix)/bin/mc
|
||||
@for cmd in $(CMDS) ; do \
|
||||
@ -47,9 +45,6 @@ install:
|
||||
cp $$po/mc.mo $(DESTDIR)/usr/share/$$po ; \
|
||||
done
|
||||
|
||||
defcfg:
|
||||
cp -v install/cfg.default $(DESTDIR)/etc/mc/cfg
|
||||
|
||||
uninstall:
|
||||
rm -v $(DESTDIR)$(prefix)/bin/mc
|
||||
@for cmd in $(CMDS) ; do \
|
||||
|
@ -10,6 +10,7 @@ To compile `mc` and to use it, you will need the following:
|
||||
- make
|
||||
- gettext
|
||||
- libinih
|
||||
- curl
|
||||
- doas (or sudo)
|
||||
|
||||
After installing these dependencies, **download the latest
|
||||
|
@ -7,7 +7,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-05-05 20:10+0300\n"
|
||||
"POT-Creation-Date: 2024-05-09 23:28+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"
|
||||
@ -78,19 +78,19 @@ msgstr ""
|
||||
msgid "Failed to change directory to the specified directory"
|
||||
msgstr ""
|
||||
|
||||
#: src/gen.c:29 src/gen.c:36 src/pull.c:83
|
||||
#: src/gen.c:29 src/gen.c:36 src/pull.c:95
|
||||
msgid "Loaded repository configuration"
|
||||
msgstr ""
|
||||
|
||||
#: src/gen.c:31 src/pull.c:78
|
||||
#: src/gen.c:31 src/pull.c:90
|
||||
msgid "Failed to load the configuration file (mc.cfg):"
|
||||
msgstr ""
|
||||
|
||||
#: src/gen.c:42 src/pull.c:110
|
||||
#: src/gen.c:42 src/pull.c:122
|
||||
msgid "Copying all the targets"
|
||||
msgstr ""
|
||||
|
||||
#: src/gen.c:48 src/pull.c:124
|
||||
#: src/gen.c:48 src/pull.c:136
|
||||
msgid "Failed to copy the target:"
|
||||
msgstr ""
|
||||
|
||||
@ -173,51 +173,51 @@ msgstr ""
|
||||
msgid "Please specify a config name or a URL"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:57
|
||||
#: src/pull.c:69
|
||||
#, c-format
|
||||
msgid "Cloning %s"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:62
|
||||
#: src/pull.c:74
|
||||
#, c-format
|
||||
msgid "Failed to clone the %s:"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:73
|
||||
#: src/pull.c:85
|
||||
#, c-format
|
||||
msgid "Failed to chdir to %s"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:86
|
||||
#: src/pull.c:98
|
||||
msgid "Do you want to continue?"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:92
|
||||
#: src/pull.c:104
|
||||
msgid "Checking all the targets"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:98
|
||||
#: src/pull.c:110
|
||||
#, c-format
|
||||
msgid "Failed to access the source for the target \"%s\""
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:107
|
||||
#: src/pull.c:119
|
||||
msgid "All the target checks were successful"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:118
|
||||
#: src/pull.c:130
|
||||
msgid "Install the target?"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:119
|
||||
#: src/pull.c:131
|
||||
msgid "Skipping target"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:157
|
||||
#: src/pull.c:169
|
||||
msgid "Installing all the requirements"
|
||||
msgstr ""
|
||||
|
||||
#: src/pull.c:160
|
||||
#: src/pull.c:172
|
||||
msgid "Failed to run the mp-install command"
|
||||
msgstr ""
|
||||
|
||||
@ -253,6 +253,34 @@ msgstr ""
|
||||
msgid "Description"
|
||||
msgstr ""
|
||||
|
||||
#: src/url.c:44
|
||||
msgid "Failed to open /dev/null"
|
||||
msgstr ""
|
||||
|
||||
#: src/url.c:51
|
||||
msgid "Failed to init curl"
|
||||
msgstr ""
|
||||
|
||||
#: src/url.c:63
|
||||
msgid "Request failed"
|
||||
msgstr ""
|
||||
|
||||
#: src/url.c:70
|
||||
msgid "Failed to get the response code"
|
||||
msgstr ""
|
||||
|
||||
#: src/url.c:76
|
||||
msgid "Response is not a redirect"
|
||||
msgstr ""
|
||||
|
||||
#: src/url.c:83
|
||||
msgid "Failed to get the location header"
|
||||
msgstr ""
|
||||
|
||||
#: src/url.c:89
|
||||
msgid "Invalid location header"
|
||||
msgstr ""
|
||||
|
||||
#: src/util.c:115 src/util.c:126
|
||||
#, c-format
|
||||
msgid "Failed to create directory: %s"
|
||||
|
@ -185,7 +185,7 @@ bool config_load(config_t *config, char *path) {
|
||||
void config_print(config_t *config) {
|
||||
info(_("Configuration details:\n"));
|
||||
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", _("Author"), config->author);
|
||||
|
||||
|
10
src/error.h
10
src/error.h
@ -16,6 +16,16 @@ enum ErrorCodes {
|
||||
RunNoRoot = 943,
|
||||
RunCmdNotFound = 942,
|
||||
RunCmdFail = 941,
|
||||
|
||||
UrlCurlFail = 940,
|
||||
UrlReqFail = 939,
|
||||
UrlNullFail = 938,
|
||||
|
||||
UrlReqCodeFail = 937,
|
||||
UrlReqBadCode = 936,
|
||||
|
||||
UrlLocationFail = 935,
|
||||
UrlLocationBad = 934
|
||||
};
|
||||
|
||||
extern int errno;
|
||||
|
36
src/pull.c
36
src/pull.c
@ -4,9 +4,9 @@
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "paths.h"
|
||||
#include "run.h"
|
||||
#include "url.h"
|
||||
#include "util.h"
|
||||
#include "run.h"
|
||||
|
||||
#include <git2.h>
|
||||
#include <git2/global.h>
|
||||
@ -44,6 +44,18 @@ bool pull_cmd() {
|
||||
else
|
||||
repo_url = url_ensure_protocol(args.list[1]);
|
||||
|
||||
if (NULL == repo_url) {
|
||||
switch (errno) {
|
||||
case UrlReqBadCode:
|
||||
error("Specified configuration is not found");
|
||||
break;
|
||||
default:
|
||||
error("Failed to access the URL");
|
||||
details(errch);
|
||||
}
|
||||
goto END;
|
||||
}
|
||||
|
||||
rmrf(mc_tmp_path);
|
||||
repo_root = mc_tmp_path;
|
||||
|
||||
@ -110,7 +122,7 @@ COPY:
|
||||
info(_("Copying all the targets"));
|
||||
|
||||
char **argv = NULL;
|
||||
int argc = 0, indx = 0;
|
||||
int argc = 0, indx = 0;
|
||||
|
||||
while (cur && ++counter > 0) {
|
||||
target_print(cur);
|
||||
@ -127,35 +139,35 @@ COPY:
|
||||
}
|
||||
|
||||
argc += cur->require.s;
|
||||
if(0 == argc)
|
||||
if (0 == argc)
|
||||
goto NEXT;
|
||||
|
||||
if(NULL == argv)
|
||||
argv = malloc(sizeof(char*)*argc);
|
||||
if (NULL == argv)
|
||||
argv = malloc(sizeof(char *) * argc);
|
||||
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];
|
||||
indx++;
|
||||
}
|
||||
|
||||
NEXT:
|
||||
NEXT:
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
if(NULL == argv){
|
||||
if (NULL == argv) {
|
||||
ret = true;
|
||||
goto END;
|
||||
}
|
||||
|
||||
argc++;
|
||||
argv = realloc(argv, sizeof(char*)*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)){
|
||||
if (!run_cmd_root("mp-install", argv)) {
|
||||
ret = false;
|
||||
error(_("Failed to run the mp-install command"));
|
||||
details(errch);
|
||||
|
52
src/run.c
52
src/run.c
@ -1,33 +1,33 @@
|
||||
#include <sys/wait.h>
|
||||
#include <spawn.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "error.h"
|
||||
#include "util.h"
|
||||
#include "run.h"
|
||||
#include "util.h"
|
||||
|
||||
extern char **environ;
|
||||
|
||||
char *run_find_cmd(char *cmd){
|
||||
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];
|
||||
while ((el = strtok_r(path, ":", &save)) != NULL) {
|
||||
char fp[strlen(el) + strlen(cmd) + 2];
|
||||
join(fp, el, cmd);
|
||||
|
||||
if(exists(fp))
|
||||
if (exists(fp))
|
||||
return strdup(fp);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool run_cmd(char **all){
|
||||
bool run_cmd(char **all) {
|
||||
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;
|
||||
|
||||
int status;
|
||||
@ -35,20 +35,20 @@ bool run_cmd(char **all){
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
bool run_cmd_root(char *cmd, char **args){
|
||||
bool run_cmd_root(char *cmd, char **args) {
|
||||
char *rootcmd = NULL;
|
||||
|
||||
if(NULL == run_find_cmd(cmd)){
|
||||
if (NULL == run_find_cmd(cmd)) {
|
||||
error_set("Command not found");
|
||||
errno = RunCmdNotFound;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(getuid()==0)
|
||||
if (getuid() == 0)
|
||||
goto RUN;
|
||||
else if((rootcmd = run_find_cmd("doas")) != NULL)
|
||||
else if ((rootcmd = run_find_cmd("doas")) != NULL)
|
||||
goto RUN;
|
||||
else if((rootcmd = run_find_cmd("sudo" )) != NULL)
|
||||
else if ((rootcmd = run_find_cmd("sudo")) != NULL)
|
||||
goto RUN;
|
||||
|
||||
error_set("There is no doas or sudo installed");
|
||||
@ -57,32 +57,32 @@ bool run_cmd_root(char *cmd, char **args){
|
||||
|
||||
RUN:
|
||||
int arg_count = 0;
|
||||
while(args[arg_count] != NULL)
|
||||
while (args[arg_count] != NULL)
|
||||
arg_count++;
|
||||
arg_count += 2;
|
||||
|
||||
if(rootcmd != NULL)
|
||||
if (rootcmd != NULL)
|
||||
arg_count++;
|
||||
|
||||
char **all = malloc(arg_count*sizeof(char*));
|
||||
int indx = 0;
|
||||
char **all = malloc(arg_count * sizeof(char *));
|
||||
int indx = 0;
|
||||
|
||||
if(rootcmd != NULL){
|
||||
all[indx] = rootcmd;
|
||||
if (rootcmd != NULL) {
|
||||
all[indx] = rootcmd;
|
||||
all[++indx] = cmd;
|
||||
}else
|
||||
} else
|
||||
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] = NULL;
|
||||
|
||||
bool ret = true;
|
||||
|
||||
if(!run_cmd(all)){
|
||||
if (!run_cmd(all)) {
|
||||
error_set("Command failed");
|
||||
errno = RunCmdFail;
|
||||
ret = false;
|
||||
ret = false;
|
||||
}
|
||||
|
||||
free(all);
|
||||
|
72
src/url.c
72
src/url.c
@ -1,4 +1,7 @@
|
||||
#include "error.h"
|
||||
#include "intl.h"
|
||||
#include "util.h"
|
||||
#include <curl/curl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@ -6,7 +9,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define HUB_URL "https://matterlinux.xyz/hub/"
|
||||
#define HUB_URL "https://matterlinux.xyz/hub"
|
||||
|
||||
bool url_is_name(char *name) {
|
||||
for (char *c = name; *c != '\0'; c++) {
|
||||
@ -30,10 +33,71 @@ bool url_is_local(char *url) {
|
||||
}
|
||||
|
||||
char *url_complete(char *name) {
|
||||
char *url = malloc(strlen(name) + strlen(HUB_URL) + 1);
|
||||
|
||||
char url[strlen(name) + strlen(HUB_URL) + 1];
|
||||
sprintf(url, "%s/%s", HUB_URL, name);
|
||||
return url;
|
||||
|
||||
FILE *devnull = fopen("/dev/null", "w");
|
||||
char *location = NULL;
|
||||
long code = 0;
|
||||
|
||||
if (NULL == devnull) {
|
||||
error_set(_("Failed to open /dev/null"));
|
||||
errno = UrlNullFail;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CURL *curl = curl_easy_init();
|
||||
if (NULL == curl) {
|
||||
error_set(_("Failed to init curl"));
|
||||
errno = UrlCurlFail;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl/mp");
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, devnull);
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
error_set(_("Request failed"));
|
||||
errno = UrlReqFail;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
|
||||
if (res != CURLE_OK) {
|
||||
error_set(_("Failed to get the response code"));
|
||||
errno = UrlReqCodeFail;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
if ((code / 100) != 3) {
|
||||
error_set(_("Response is not a redirect"));
|
||||
errno = UrlReqBadCode;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
res = curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &location);
|
||||
if (res != CURLE_OK) {
|
||||
error_set(_("Failed to get the location header"));
|
||||
errno = UrlLocationFail;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
if (NULL == location) {
|
||||
error_set(_("Invalid location header"));
|
||||
errno = UrlLocationBad;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
location = strdup(location);
|
||||
|
||||
CLEANUP:
|
||||
fclose(devnull);
|
||||
if (NULL != curl)
|
||||
curl_easy_cleanup(curl);
|
||||
return location;
|
||||
}
|
||||
|
||||
char *url_ensure_protocol(char *url) {
|
||||
|
Reference in New Issue
Block a user