diff --git a/bin/fex b/bin/fex index fe54eb9..028efe1 100755 Binary files a/bin/fex and b/bin/fex differ diff --git a/inc/config.h b/inc/config.h index d010035..1e3d58a 100644 --- a/inc/config.h +++ b/inc/config.h @@ -5,6 +5,14 @@ #ifndef 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 diff --git a/inc/fetch.h b/inc/fetch.h new file mode 100644 index 0000000..d548e77 --- /dev/null +++ b/inc/fetch.h @@ -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 diff --git a/inc/fex.h b/inc/fex.h index 87fa092..a95e203 100644 --- a/inc/fex.h +++ b/inc/fex.h @@ -7,15 +7,15 @@ enum Flags { FLAG_INSTALL = 1 << 0, - //FLAG_SOURCE = 1 << 1, - //FLAG_UNINSTALL = 1 << 1, - FLAG_LIST = 1 << 1, - FLAG_SEARCH = 1 << 2, - FLAG_FORCE = 1 << 3, - FLAG_UPGRADE = 1 << 4, + FLAG_SOURCE = 1 << 1, + FLAG_REMOVE = 1 << 2, + //FLAG_LIST = 1 << 1, + FLAG_SEARCH = 1 << 3, + FLAG_FORCE = 1 << 4, + FLAG_UPGRADE = 1 << 5, }; extern char* flagNames[]; -extern int flagSource, flagUninstall; +//extern int flagSource, flagUninstall; #endif //FEX_H diff --git a/inc/install.h b/inc/install.h index 75d05bf..610f786 100644 --- a/inc/install.h +++ b/inc/install.h @@ -5,6 +5,10 @@ #ifndef 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 diff --git a/inc/mirrors.h b/inc/mirrors.h new file mode 100644 index 0000000..64b0bfa --- /dev/null +++ b/inc/mirrors.h @@ -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 diff --git a/inc/nprint.c b/inc/nprint.c index ca563bc..a9b37b7 100644 --- a/inc/nprint.c +++ b/inc/nprint.c @@ -5,6 +5,7 @@ #include "nprint.h" #include +#ifndef silentOutput void nprint(const char *tag, const char *format, ...) { const char *color = ""; const char *bgcolor = ""; @@ -47,3 +48,8 @@ void nprint(const char *tag, const char *format, ...) { printf("\n"); } +#else + void nprint(const char *tag, const char *format, ...) { + do {} while (0); + } +#endif \ No newline at end of file diff --git a/obj/fetch.o b/obj/fetch.o new file mode 100644 index 0000000..eb7a6ef Binary files /dev/null and b/obj/fetch.o differ diff --git a/obj/fex.o b/obj/fex.o index da546d4..239537b 100644 Binary files a/obj/fex.o and b/obj/fex.o differ diff --git a/obj/install.o b/obj/install.o index 2928c6b..4baae2a 100644 Binary files a/obj/install.o and b/obj/install.o differ diff --git a/obj/nprint.o b/obj/nprint.o index 4880fa1..b40e565 100644 Binary files a/obj/nprint.o and b/obj/nprint.o differ diff --git a/obj/sanity.o b/obj/sanity.o index 0195859..1d6f8b9 100644 Binary files a/obj/sanity.o and b/obj/sanity.o differ diff --git a/src/fetch.c b/src/fetch.c new file mode 100644 index 0000000..027073b --- /dev/null +++ b/src/fetch.c @@ -0,0 +1,13 @@ +// +// Created by auric on 2/29/24. +// + +#include "../inc/mirrors.h" +#include "../inc/fetch.h" +#include "../inc/config.h" +#include + +int fetch(int type, char** input) { + + return OK; +}; diff --git a/src/fex.c b/src/fex.c index f4b1019..8bec797 100644 --- a/src/fex.c +++ b/src/fex.c @@ -2,9 +2,9 @@ // Created by auric on 2/21/24. // -#include +/*#include #include -#include +#include */ #include #include #include "sanity.h" @@ -12,22 +12,24 @@ #include "debug.h" #include "fex.h" #include "install.h" +#include "fetch.h" void help() { 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) { unsigned int flags = 0; char* packages[argc - 1]; int pkgCount = 0; - int flagSource, flagUninstall = 0; if (argc < 2) { help(); - return 1; + return ERROR; } for(int i = 1; i < argc; i++) { @@ -38,16 +40,18 @@ int main(int argc, char** argv) { flags |= FLAG_INSTALL; break; case 'S': // source, 1 - //flags |= FLAG_SOURCE; - flagSource = 1; + flags |= FLAG_SOURCE; + type = TYPE_SOURCE; + //flagSource = 1; break; case 'r': // remove, 2 - //flags |= FLAG_UNINSTALL; - flagUninstall = 1; + flags |= FLAG_REMOVE; + type = TYPE_GENERIC; // Reusing code. This is for fetch();, but is used here to define the type for `installPackage`. + //flagUninstall = 1; break; - case 'l': // list, 3 + /*case 'l': // list, 3 flags |= FLAG_LIST; - break; + break;*/ case 's': // search, 4 flags |= FLAG_SEARCH; break; @@ -59,7 +63,7 @@ int main(int argc, char** argv) { break; default: nprint("E", "Flag '%c' is unknown.", argv[i][j]); - return 1; + return ERROR; } } } else { @@ -69,12 +73,12 @@ int main(int argc, char** argv) { const int sysSanity = isSysSane(); if ((isSyntaxSane(flags, pkgCount))) { - return 1; + return ERROR; } #ifdef debugEnabled 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]); for(int i = 0; i < numFlags; i++) { if (flags & flagValues[i]) { @@ -91,18 +95,18 @@ int main(int argc, char** argv) { /* End Prelogic */ DEBUG_PRINT("[!] Break parselogic"); - if(flags & FLAG_LIST) { + /*if(flags & FLAG_LIST) { DEBUG_PRINT("HIT: List"); // list packages - } + }*/ if(flags & FLAG_SEARCH) { DEBUG_PRINT("HIT: Search"); // search packages } if(!(getuid())) { - if (flags & FLAG_INSTALL) { - DEBUG_PRINT("HIT: Install. Source: %d; Uninstall: %d", flagSource, flagUninstall); - installPackages(packages, pkgCount, flagSource, flagUninstall); + if ((flags & FLAG_INSTALL)) { + DEBUG_PRINT("HIT: Install"); + installBinaries(packages, pkgCount); } if(flags & FLAG_UPGRADE) { DEBUG_PRINT("HIT: Upgrade"); @@ -110,7 +114,7 @@ int main(int argc, char** argv) { } } else { nprint("E", "Superuser permissions required for this operation."); - return 1; + return ERROR; } - return 0; + return OK; } \ No newline at end of file diff --git a/src/install.c b/src/install.c index dbdde75..abd968e 100644 --- a/src/install.c +++ b/src/install.c @@ -3,10 +3,27 @@ */ #include "../inc/debug.h" +#include "../inc/fetch.h" -int installPackages(char** packages, int pkgCount, int source, int uninstall) { - for(int i = 0; i < pkgCount; i++) { +int installBinaries(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 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]); + } +} \ No newline at end of file diff --git a/src/sanity.c b/src/sanity.c index 685f400..9737b38 100644 --- a/src/sanity.c +++ b/src/sanity.c @@ -2,6 +2,7 @@ #include "../inc/sanity.h" #include "../inc/fex.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 @@ -32,25 +33,25 @@ int isSysSane() { } 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 - return 1; - }*/ + return ERROR; + } if((flags & FLAG_INSTALL) && (pkgCount == 0)) { nprint("E", "You must specify at least one package"); - return 1; + return ERROR; } if(flags == FLAG_FORCE) { 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"); - return 1; + return ERROR; } - return 0; + return OK; }