I don't know what to write here. I'm going to hate this commit in the future
This commit is contained in:
parent
72343ecc79
commit
f578366906
10
inc/config.h
10
inc/config.h
@ -5,6 +5,14 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
#define debugEnabled
|
/* Run `make clean` after changing this file, or it won't reflect in the binary */
|
||||||
|
|
||||||
|
#define debugEnabled // Uncomment to enable debug output
|
||||||
|
// #define silentOutput // Uncomment to remove output
|
||||||
|
|
||||||
|
enum status { // define status output for more readable code
|
||||||
|
OK,
|
||||||
|
ERROR
|
||||||
|
};
|
||||||
|
|
||||||
#endif //CONFIG_H
|
#endif //CONFIG_H
|
||||||
|
19
inc/fetch.h
Normal file
19
inc/fetch.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by auric on 2/29/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef FETCH_H
|
||||||
|
#define FETCH_H
|
||||||
|
|
||||||
|
int fetch(int type, char** input);
|
||||||
|
|
||||||
|
enum type {
|
||||||
|
TYPE_PRELIM,
|
||||||
|
TYPE_BINARY,
|
||||||
|
TYPE_SOURCE,
|
||||||
|
TYPE_GENERIC,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern int type;
|
||||||
|
|
||||||
|
#endif //FETCH_H
|
14
inc/fex.h
14
inc/fex.h
@ -7,15 +7,15 @@
|
|||||||
|
|
||||||
enum Flags {
|
enum Flags {
|
||||||
FLAG_INSTALL = 1 << 0,
|
FLAG_INSTALL = 1 << 0,
|
||||||
//FLAG_SOURCE = 1 << 1,
|
FLAG_SOURCE = 1 << 1,
|
||||||
//FLAG_UNINSTALL = 1 << 1,
|
FLAG_REMOVE = 1 << 2,
|
||||||
FLAG_LIST = 1 << 1,
|
//FLAG_LIST = 1 << 1,
|
||||||
FLAG_SEARCH = 1 << 2,
|
FLAG_SEARCH = 1 << 3,
|
||||||
FLAG_FORCE = 1 << 3,
|
FLAG_FORCE = 1 << 4,
|
||||||
FLAG_UPGRADE = 1 << 4,
|
FLAG_UPGRADE = 1 << 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char* flagNames[];
|
extern char* flagNames[];
|
||||||
extern int flagSource, flagUninstall;
|
//extern int flagSource, flagUninstall;
|
||||||
|
|
||||||
#endif //FEX_H
|
#endif //FEX_H
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
#ifndef INSTALL_H
|
#ifndef INSTALL_H
|
||||||
#define INSTALL_H
|
#define INSTALL_H
|
||||||
|
|
||||||
int installPackages(char** package, int pkgCount, int source, int uninstall);
|
//int installPackage(char** packages, int pkgCount, int type);
|
||||||
|
|
||||||
|
int installBinaries(char** packages, int pkgCount);
|
||||||
|
int installSources(char** packages, int pkgCount);
|
||||||
|
int removePackages(char** packges, int pkgCount);
|
||||||
|
|
||||||
#endif //INSTALL_H
|
#endif //INSTALL_H
|
||||||
|
15
inc/mirrors.h
Normal file
15
inc/mirrors.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// Created by auric on 2/29/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MIRRORS_H
|
||||||
|
#define MIRRORS_H
|
||||||
|
|
||||||
|
/* Define mirrors here */
|
||||||
|
const char* mirrors[] = {
|
||||||
|
"https://mirror.japegames.com/",
|
||||||
|
};
|
||||||
|
|
||||||
|
const int num_mirrors = sizeof(mirrors) / sizeof(mirrors[0]);
|
||||||
|
|
||||||
|
#endif //MIRRORS_H
|
@ -5,6 +5,7 @@
|
|||||||
#include "nprint.h"
|
#include "nprint.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef silentOutput
|
||||||
void nprint(const char *tag, const char *format, ...) {
|
void nprint(const char *tag, const char *format, ...) {
|
||||||
const char *color = "";
|
const char *color = "";
|
||||||
const char *bgcolor = "";
|
const char *bgcolor = "";
|
||||||
@ -47,3 +48,8 @@ void nprint(const char *tag, const char *format, ...) {
|
|||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void nprint(const char *tag, const char *format, ...) {
|
||||||
|
do {} while (0);
|
||||||
|
}
|
||||||
|
#endif
|
BIN
obj/fetch.o
Normal file
BIN
obj/fetch.o
Normal file
Binary file not shown.
BIN
obj/install.o
BIN
obj/install.o
Binary file not shown.
BIN
obj/nprint.o
BIN
obj/nprint.o
Binary file not shown.
BIN
obj/sanity.o
BIN
obj/sanity.o
Binary file not shown.
13
src/fetch.c
Normal file
13
src/fetch.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by auric on 2/29/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../inc/mirrors.h"
|
||||||
|
#include "../inc/fetch.h"
|
||||||
|
#include "../inc/config.h"
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
int fetch(int type, char** input) {
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
};
|
46
src/fex.c
46
src/fex.c
@ -2,9 +2,9 @@
|
|||||||
// Created by auric on 2/21/24.
|
// Created by auric on 2/21/24.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <stdlib.h>
|
/*#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>*/
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <nprint.h>
|
#include <nprint.h>
|
||||||
#include "sanity.h"
|
#include "sanity.h"
|
||||||
@ -12,22 +12,24 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "fex.h"
|
#include "fex.h"
|
||||||
#include "install.h"
|
#include "install.h"
|
||||||
|
#include "fetch.h"
|
||||||
|
|
||||||
void help() {
|
void help() {
|
||||||
nprint("E", "Usage: fex (OPT) (PACKAGES)");
|
nprint("E", "Usage: fex (OPT) (PACKAGES)");
|
||||||
}
|
}
|
||||||
|
|
||||||
char* flagNames[] = {"INSTALL","LIST", "SEARCH", "FORCE", "UPGRADE"};
|
char* flagNames[] = {"INSTALL", "SOURCE", "REMOVE", "SEARCH", "FORCE", "UPGRADE"};
|
||||||
|
/*int flagSource, flagUninstall = 0;*/
|
||||||
|
int type;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
char* packages[argc - 1];
|
char* packages[argc - 1];
|
||||||
int pkgCount = 0;
|
int pkgCount = 0;
|
||||||
int flagSource, flagUninstall = 0;
|
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
help();
|
help();
|
||||||
return 1;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 1; i < argc; i++) {
|
for(int i = 1; i < argc; i++) {
|
||||||
@ -38,16 +40,18 @@ int main(int argc, char** argv) {
|
|||||||
flags |= FLAG_INSTALL;
|
flags |= FLAG_INSTALL;
|
||||||
break;
|
break;
|
||||||
case 'S': // source, 1
|
case 'S': // source, 1
|
||||||
//flags |= FLAG_SOURCE;
|
flags |= FLAG_SOURCE;
|
||||||
flagSource = 1;
|
type = TYPE_SOURCE;
|
||||||
|
//flagSource = 1;
|
||||||
break;
|
break;
|
||||||
case 'r': // remove, 2
|
case 'r': // remove, 2
|
||||||
//flags |= FLAG_UNINSTALL;
|
flags |= FLAG_REMOVE;
|
||||||
flagUninstall = 1;
|
type = TYPE_GENERIC; // Reusing code. This is for fetch();, but is used here to define the type for `installPackage`.
|
||||||
|
//flagUninstall = 1;
|
||||||
break;
|
break;
|
||||||
case 'l': // list, 3
|
/*case 'l': // list, 3
|
||||||
flags |= FLAG_LIST;
|
flags |= FLAG_LIST;
|
||||||
break;
|
break;*/
|
||||||
case 's': // search, 4
|
case 's': // search, 4
|
||||||
flags |= FLAG_SEARCH;
|
flags |= FLAG_SEARCH;
|
||||||
break;
|
break;
|
||||||
@ -59,7 +63,7 @@ int main(int argc, char** argv) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nprint("E", "Flag '%c' is unknown.", argv[i][j]);
|
nprint("E", "Flag '%c' is unknown.", argv[i][j]);
|
||||||
return 1;
|
return ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -69,12 +73,12 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
const int sysSanity = isSysSane();
|
const int sysSanity = isSysSane();
|
||||||
if ((isSyntaxSane(flags, pkgCount))) {
|
if ((isSyntaxSane(flags, pkgCount))) {
|
||||||
return 1;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef debugEnabled
|
#ifdef debugEnabled
|
||||||
DEBUG_PRINT("sysSanity: %d", sysSanity);
|
DEBUG_PRINT("sysSanity: %d", sysSanity);
|
||||||
unsigned int flagValues[] = {0b00001, 0b00010, 0b00100, 0b01000, 0b10000};
|
unsigned int flagValues[] = {0b000001, 0b000010, 0b000100, 0b001000, 0b010000, 0b100000};
|
||||||
int numFlags = sizeof(flagValues) / sizeof(flagValues[0]);
|
int numFlags = sizeof(flagValues) / sizeof(flagValues[0]);
|
||||||
for(int i = 0; i < numFlags; i++) {
|
for(int i = 0; i < numFlags; i++) {
|
||||||
if (flags & flagValues[i]) {
|
if (flags & flagValues[i]) {
|
||||||
@ -91,18 +95,18 @@ int main(int argc, char** argv) {
|
|||||||
/* End Prelogic */
|
/* End Prelogic */
|
||||||
DEBUG_PRINT("[!] Break parselogic");
|
DEBUG_PRINT("[!] Break parselogic");
|
||||||
|
|
||||||
if(flags & FLAG_LIST) {
|
/*if(flags & FLAG_LIST) {
|
||||||
DEBUG_PRINT("HIT: List");
|
DEBUG_PRINT("HIT: List");
|
||||||
// list packages
|
// list packages
|
||||||
}
|
}*/
|
||||||
if(flags & FLAG_SEARCH) {
|
if(flags & FLAG_SEARCH) {
|
||||||
DEBUG_PRINT("HIT: Search");
|
DEBUG_PRINT("HIT: Search");
|
||||||
// search packages
|
// search packages
|
||||||
}
|
}
|
||||||
if(!(getuid())) {
|
if(!(getuid())) {
|
||||||
if (flags & FLAG_INSTALL) {
|
if ((flags & FLAG_INSTALL)) {
|
||||||
DEBUG_PRINT("HIT: Install. Source: %d; Uninstall: %d", flagSource, flagUninstall);
|
DEBUG_PRINT("HIT: Install");
|
||||||
installPackages(packages, pkgCount, flagSource, flagUninstall);
|
installBinaries(packages, pkgCount);
|
||||||
}
|
}
|
||||||
if(flags & FLAG_UPGRADE) {
|
if(flags & FLAG_UPGRADE) {
|
||||||
DEBUG_PRINT("HIT: Upgrade");
|
DEBUG_PRINT("HIT: Upgrade");
|
||||||
@ -110,7 +114,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nprint("E", "Superuser permissions required for this operation.");
|
nprint("E", "Superuser permissions required for this operation.");
|
||||||
return 1;
|
return ERROR;
|
||||||
}
|
}
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
@ -3,10 +3,27 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
#include "../inc/debug.h"
|
#include "../inc/debug.h"
|
||||||
|
#include "../inc/fetch.h"
|
||||||
|
|
||||||
int installPackages(char** packages, int pkgCount, int source, int uninstall) {
|
int installBinaries(char** packages, int pkgCount) {
|
||||||
for(int i = 0; i < pkgCount; i++) {
|
for (int i = 0; i < pkgCount; i++) {
|
||||||
DEBUG_PRINT("PACKAGE: %s", packages[i]);
|
DEBUG_PRINT("PACKAGE: %s", packages[i]);
|
||||||
DEBUG_PRINT("pkgCount ('i'): %d", i);
|
DEBUG_PRINT("pkgCount ('i'): %d", i);
|
||||||
|
fetch(type, &packages[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int installSources(char** packages, int pkgCount) {
|
||||||
|
for (int i = 0; i < pkgCount; i++) {
|
||||||
|
DEBUG_PRINT("PACKAGE: %s", packages[i]);
|
||||||
|
DEBUG_PRINT("pkgCount ('i'): %d", i);
|
||||||
|
fetch(type, &packages[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int removePackages(char** packages, int pkgCount) {
|
||||||
|
for (int i = 0; i < pkgCount; i++) {
|
||||||
|
DEBUG_PRINT("PACKAGE: %s", packages[i]);
|
||||||
|
DEBUG_PRINT("pkgCount ('i'): %d", i);
|
||||||
|
fetch(type, &packages[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
17
src/sanity.c
17
src/sanity.c
@ -2,6 +2,7 @@
|
|||||||
#include "../inc/sanity.h"
|
#include "../inc/sanity.h"
|
||||||
#include "../inc/fex.h"
|
#include "../inc/fex.h"
|
||||||
#include "../inc/nprint.h"
|
#include "../inc/nprint.h"
|
||||||
|
#include "../inc/config.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Uses bitwise operations to determine the sanity of the system's directory hierarchy. In particular, it checks if the directories of
|
* Uses bitwise operations to determine the sanity of the system's directory hierarchy. In particular, it checks if the directories of
|
||||||
@ -32,25 +33,25 @@ int isSysSane() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int isSyntaxSane(unsigned int flags, int pkgCount) {
|
int isSyntaxSane(unsigned int flags, int pkgCount) {
|
||||||
/*if((flags & FLAG_INSTALL)) {
|
if((flags & FLAG_INSTALL) && (flags & FLAG_REMOVE)) {
|
||||||
nprint("E", "You cannot install and uninstall at the same time"); // Sequential parsing of flags would leave so many ambiguous cases and expand these checks greatly. Not worth it without extensive research
|
nprint("E", "You cannot install and uninstall at the same time"); // Sequential parsing of flags would leave so many ambiguous cases and expand these checks greatly. Not worth it without extensive research
|
||||||
return 1;
|
return ERROR;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
if((flags & FLAG_INSTALL) && (pkgCount == 0)) {
|
if((flags & FLAG_INSTALL) && (pkgCount == 0)) {
|
||||||
nprint("E", "You must specify at least one package");
|
nprint("E", "You must specify at least one package");
|
||||||
return 1;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flags == FLAG_FORCE) {
|
if(flags == FLAG_FORCE) {
|
||||||
nprint("E", "Force may not be used alone");
|
nprint("E", "Force may not be used alone");
|
||||||
return 1;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((flags == FLAG_LIST) || (flags == FLAG_SEARCH)) {
|
if(/*(flags == FLAG_LIST) || */flags == FLAG_SEARCH) {
|
||||||
nprint("E", "List and search must be used alone");
|
nprint("E", "List and search must be used alone");
|
||||||
return 1;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user