From 9eebe5b30140a3db2179881d39a27c120a565f34 Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Sat, 31 Aug 2024 01:17:14 -0400 Subject: [PATCH] first commit upgrades system, downloads package --- Makefile | 27 ++++++++++++++ caur | Bin 0 -> 17968 bytes readme.md | 14 ++++++++ src/main.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 Makefile create mode 100755 caur create mode 100644 readme.md create mode 100644 src/main.c 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 0000000000000000000000000000000000000000..707dfa620eee1f0df1a4374c9071cbc2b4a84e62 GIT binary patch literal 17968 zcmeHP4{#jSd4D=1EEDv{UA_z9Gzra7~|OCWLsjD%0~WIoT=&hbhmf9a=N?R z?qS)niKsBiMOEX3@TZM4m`p-unxTOvrH~pbFa@0Sk7!cjCeBnL!02j+7~%v2uCKrE z?fdTb*4kqx(`lwN_cV9E_x--_d++VH@9o~cw@;tx?CJ8=)Cf+~#K#3mO*3sKs1%QV zTx9@3u~O9I`$}DSjG|{AN>T3Y=%tf{|NDNPb>vVur0@ z6iv2FezlZUvKtLL5F|#{7whv&wGb{`J>BLRoqkm0Sc|P6TjN3%mvM#cMVIAMg6*|dW(4J(zl zgqcid;z=ti(pk$yYtWGJ?RvQXc0C%3C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;UZ*U%{cOj0C-gLj!!pm~Fz!_T9Aj?3qQxjObWYfx=aCqB9*OH` ze?I;Pl>b^)AkRxN@;ny#)7+KY|6y6K{m=lBc1vQ+p0DIJO9$JE~= zV62<=j14}AA literal 0 HcmV?d00001 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