I don't know what to write here. I'm going to hate this commit in the future

This commit is contained in:
John Barns 2024-02-29 13:42:06 -06:00
parent 72343ecc79
commit f578366906
16 changed files with 127 additions and 40 deletions

BIN
bin/fex

Binary file not shown.

View File

@ -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

19
inc/fetch.h Normal file
View 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

View File

@ -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

View File

@ -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

15
inc/mirrors.h Normal file
View 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

View File

@ -5,6 +5,7 @@
#include "nprint.h"
#include <stdio.h>
#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

BIN
obj/fetch.o Normal file

Binary file not shown.

BIN
obj/fex.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

13
src/fetch.c Normal file
View 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;
};

View File

@ -2,9 +2,9 @@
// Created by auric on 2/21/24.
//
#include <stdlib.h>
/*#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string.h>*/
#include <unistd.h>
#include <nprint.h>
#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;
}

View File

@ -3,10 +3,27 @@
*/
#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++) {
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]);
}
}

View File

@ -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;
}