commit 9eebe5b30140a3db2179881d39a27c120a565f34 Author: Tristan Smith Date: Sat Aug 31 01:17:14 2024 -0400 first commit upgrades system, downloads package diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2cbe37f --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +# Define the compiler and flags +CC = gcc +CFLAGS = -Wall -Wextra -Werror + +# Define the target executable and the source files +TARGET = caur +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:.c=.o) + +# The default rule: build the target +all: $(TARGET) + +# Link the object files into the target executable +$(TARGET): $(OBJS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) + +# Compile the .c files into .o files +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +# Clean up the build artifacts +clean: + rm -f $(TARGET) $(OBJS) + +# Run the program +run: $(TARGET) + ./$(TARGET) diff --git a/caur b/caur new file mode 100755 index 0000000..707dfa6 Binary files /dev/null and b/caur differ diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a775f99 --- /dev/null +++ b/readme.md @@ -0,0 +1,14 @@ +## caur + +A simple command line utility for managing AUR packages written in C hence the name + +Of course, Arch Linux needs another AUR helper, right? No, of course not. But that's not why I'm building mine. I'm building mine because I suck at programming and want to learn. If you use it, great. If not, also great. I'll probably keep using yay. + +It currently has a Makefile, but I stole it. Dunno if it'll be needed yet. Ignore it for now. + +### Depends: +curl + +### 8-31-24 + +Version 0.1 - compiles with ```gcc -o caur src/main.c```, currently will run ```sudo pacman -Syu``` just running, ```./caur```. Currently will *only* download the archive of the package when you specify a package name. \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..cdb2c0e --- /dev/null +++ b/src/main.c @@ -0,0 +1,101 @@ +// Version: 0.1 +// caur - a simple command line utility for managing aur packages written in C hence the name lol + +#include // For standard input/output operations +#include // For memory allocation, process control, and conversions +#include // For handling strings and memory blocks +#include // This is for handling HTTP requests, which you’ll need to fetch data from the AUR + +// #include // For access to POSIX operating system API, useful for things like file operations and process management +// #include // Parsing packing information from the AUR packages + +// #define AUR_URL "https://aur.archlinux.org/rpc/?v=5&type=info&arg[]=" +// #define AUR_SEARCH_URL "https://aur.archlinux.org/rpc/?v=5&type=search&arg=" +#define AUR_PACKAGE_URL "https://aur.archlinux.org/cgit/aur.git/snapshot/" +#define AUR_PACKAGE_URL_END ".tar.gz" + +// Function to write data to file +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t written = fwrite(ptr, size, nmemb, stream); + return written; +} + +// Function to download a package from the AUR +int download_package(const char *package_name) { + CURL *curl; + FILE *fp; + CURLcode res; + char url[256]; + char outfilename[256]; + + // Construct the URL and output the file name + snprintf(url, sizeof(url), "%s%s%s", AUR_PACKAGE_URL, package_name, AUR_PACKAGE_URL_END); + snprintf(outfilename, sizeof(outfilename), "%s%s", package_name, AUR_PACKAGE_URL_END); + + curl = curl_easy_init(); + if (curl) { + fp = fopen(outfilename, "wb"); + if (fp == NULL) { + fprintf(stderr, "Failed to open file %s\n", outfilename); + return 1; + } + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); + res = curl_easy_perform(curl); + curl_easy_cleanup(curl); + fclose(fp); + + if (res != CURLE_OK) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + return 1; + } + } else { + fprintf(stderr, "Failed to init curl\n"); + return 1; + } + + return 0; + +} + +int main(int argc, char *argv[]) { + // Check if the user provided a package name as an argument, otherwise, run the system upgrade command + if (argc < 2) { + printf("Performing system upgrade...\n"); + + // System upgrade command + int result = system("sudo pacman -Syu"); + + if (result == -1) { + fprintf(stderr, "Failed to execute system upgrade\n"); + return 1; + } else if (WIFEXITED(result) && WEXITSTATUS(result) != 0) { + fprintf(stderr, "System upgrade failed with exit status %d.\n", WEXITSTATUS(result)); + return 1; + } + + printf("System upgrade completed successfully.\n"); + return 0; + } + + // The package name is the first argument after the program name + const char *package_name = argv[1]; + + // Call download function with provided package name + if (download_package(package_name) == 0) { + printf("Package %s downloaded successfully\n", package_name); + } else { + printf("Failed to download package %s\n", package_name); + } + + return 0; + + /* const char *package_name = "neofetch"; + if (download_package(package_name) == 0) { + printf("Package downloaded successfully\n"); + } else { + printf("Failed to download package"); + } */ +} \ No newline at end of file