diff --git a/bin/fex b/bin/fex index c40c485..968664c 100755 Binary files a/bin/fex and b/bin/fex differ diff --git a/bin/install b/bin/install deleted file mode 100755 index 2df8112..0000000 Binary files a/bin/install and /dev/null differ diff --git a/inc/debug.h b/inc/debug.h index 92c125c..564ba28 100644 --- a/inc/debug.h +++ b/inc/debug.h @@ -6,11 +6,12 @@ #define DEBUG_H #include "nprint.h" +#include "config.h" #ifdef debugEnabled #define DEBUG_PRINT(fmt, ...) nprint("D", fmt, ##__VA_ARGS__) #else - #define DEBUG_PRINT(fmg, ...) void(0) + #define DEBUG_PRINT(fmt, ...) do {} while (0) #endif #endif //DEBUG_H diff --git a/inc/fex.h b/inc/fex.h index a54731b..87fa092 100644 --- a/inc/fex.h +++ b/inc/fex.h @@ -7,14 +7,15 @@ enum Flags { FLAG_INSTALL = 1 << 0, - FLAG_SOURCE = 1 << 1, - FLAG_UNINSTALL = 1 << 2, - FLAG_LIST = 1 << 3, - FLAG_SEARCH = 1 << 4, - FLAG_FORCE = 1 << 5, - FLAG_UPGRADE = 1 << 6, + //FLAG_SOURCE = 1 << 1, + //FLAG_UNINSTALL = 1 << 1, + FLAG_LIST = 1 << 1, + FLAG_SEARCH = 1 << 2, + FLAG_FORCE = 1 << 3, + FLAG_UPGRADE = 1 << 4, }; extern char* flagNames[]; +extern int flagSource, flagUninstall; #endif //FEX_H diff --git a/inc/install.h b/inc/install.h new file mode 100644 index 0000000..75d05bf --- /dev/null +++ b/inc/install.h @@ -0,0 +1,10 @@ +// +// Created by auric on 2/28/24. +// + +#ifndef INSTALL_H +#define INSTALL_H + +int installPackages(char** package, int pkgCount, int source, int uninstall); + +#endif //INSTALL_H diff --git a/obj/fex.o b/obj/fex.o index 0109459..da546d4 100644 Binary files a/obj/fex.o and b/obj/fex.o differ diff --git a/obj/install.o b/obj/install.o index cb51599..4c86b54 100644 Binary files a/obj/install.o and b/obj/install.o differ diff --git a/obj/sanity.o b/obj/sanity.o index c05da53..0195859 100644 Binary files a/obj/sanity.o and b/obj/sanity.o differ diff --git a/src/fex.c b/src/fex.c index 83723c3..f4b1019 100644 --- a/src/fex.c +++ b/src/fex.c @@ -5,22 +5,25 @@ #include #include #include +#include #include -#include +#include "sanity.h" #include "config.h" #include "debug.h" #include "fex.h" +#include "install.h" void help() { nprint("E", "Usage: fex (OPT) (PACKAGES)"); } -char* flagNames[] = {"INSTALL", "SOURCE", "UNINSTALL", "LIST", "SEARCH", "FORCE", "UPGRADE"}; +char* flagNames[] = {"INSTALL","LIST", "SEARCH", "FORCE", "UPGRADE"}; 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(); @@ -35,10 +38,12 @@ int main(int argc, char** argv) { flags |= FLAG_INSTALL; break; case 'S': // source, 1 - flags |= FLAG_SOURCE; + //flags |= FLAG_SOURCE; + flagSource = 1; break; case 'r': // remove, 2 - flags |= FLAG_UNINSTALL; + //flags |= FLAG_UNINSTALL; + flagUninstall = 1; break; case 'l': // list, 3 flags |= FLAG_LIST; @@ -69,7 +74,7 @@ int main(int argc, char** argv) { #ifdef debugEnabled DEBUG_PRINT("sysSanity: %d", sysSanity); - unsigned int flagValues[] = {0b0000001, 0b0000010, 0b0000100, 0b0001000, 0b0010000, 0b0100000, 0b1000000}; + unsigned int flagValues[] = {0b00001, 0b00010, 0b00100, 0b01000, 0b10000}; int numFlags = sizeof(flagValues) / sizeof(flagValues[0]); for(int i = 0; i < numFlags; i++) { if (flags & flagValues[i]) { @@ -86,9 +91,26 @@ int main(int argc, char** argv) { /* End Prelogic */ DEBUG_PRINT("[!] Break parselogic"); - for(int i = 0; i < numFlags; i++) { - DEBUG_PRINT("Iterating over %s", flagNames[i]); - + 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_UPGRADE) { + DEBUG_PRINT("HIT: Upgrade"); + //upgrade + } + } else { + nprint("E", "Superuser permissions required for this operation."); + return 1; } return 0; } \ No newline at end of file diff --git a/src/install.c b/src/install.c index c13d784..dbdde75 100644 --- a/src/install.c +++ b/src/install.c @@ -2,14 +2,11 @@ Created by auric on 2/21/24. */ +#include "../inc/debug.h" -#include -#include -#include -#include -/* Prototype main for suite instead of a unified manager. Obviously never developed -int main() { - nprint("I", "Information"); +int installPackages(char** packages, int pkgCount, int source, int uninstall) { + for(int i = 0; i < pkgCount; i++) { + DEBUG_PRINT("PACKAGE: %s", packages[i]); + DEBUG_PRINT("pkgCount ('i'): %d", i); + } } - */ - diff --git a/src/sanity.c b/src/sanity.c index ba82188..685f400 100644 --- a/src/sanity.c +++ b/src/sanity.c @@ -13,8 +13,6 @@ * exist, and if the owner can write to them. This notably does not check if the program is run as superuser. */ -/* For a root check - simply use conditional checking for a zero value in some way, such as !(getuid()) */ - int isSysSane() { struct stat conStat, exeStat, utiStat, libStat, hdrStat; int result = 0; @@ -34,12 +32,12 @@ int isSysSane() { } int isSyntaxSane(unsigned int flags, int pkgCount) { - if((flags & FLAG_INSTALL) && (flags & FLAG_UNINSTALL)) { - nprint("E", "You cannot install and uninstall at the same time"); // TODO: allow for this to happen by parsing the flags in order. e.g fex -i japes -u japes2 should install japes and uninstall japes2 + /*if((flags & FLAG_INSTALL)) { + 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; - } + }*/ - if(((flags & FLAG_INSTALL) || (flags & FLAG_UNINSTALL)) && (pkgCount == 0)) { + if((flags & FLAG_INSTALL) && (pkgCount == 0)) { nprint("E", "You must specify at least one package"); return 1; }