From 09af0b7366dd8b1aabafb28629365b0fe01992e2 Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Sat, 31 Aug 2024 02:32:45 -0400 Subject: [PATCH] refactor for modularity --- Makefile | 14 ++++------ caur | Bin 17968 -> 23616 bytes download.o | Bin 0 -> 6976 bytes main.o | Bin 0 -> 5528 bytes src/caur.h | 16 +++++++++++ src/download.c | 47 ++++++++++++++++++++++++++++++++ src/download.o | Bin 0 -> 6976 bytes src/main.c | 72 ++++--------------------------------------------- src/main.o | Bin 0 -> 5528 bytes src/upgrade.c | 19 +++++++++++++ src/upgrade.o | Bin 0 -> 5680 bytes upgrade.o | Bin 0 -> 5680 bytes 12 files changed, 92 insertions(+), 76 deletions(-) create mode 100644 download.o create mode 100644 main.o create mode 100644 src/caur.h create mode 100644 src/download.c create mode 100644 src/download.o create mode 100644 src/main.o create mode 100644 src/upgrade.c create mode 100644 src/upgrade.o create mode 100644 upgrade.o diff --git a/Makefile b/Makefile index 2cbe37f..86a7721 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Define the compiler and flags CC = gcc -CFLAGS = -Wall -Wextra -Werror +CFLAGS = -Wall -Wextra -std=c99 # Define the target executable and the source files TARGET = caur @@ -12,16 +12,12 @@ all: $(TARGET) # Link the object files into the target executable $(TARGET): $(OBJS) - $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) -lcurl # Compile the .c files into .o files -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ +src/%.o: src/%.c + $(CC) $(CFLAGS) -c $< -o $@ # Clean up the build artifacts clean: - rm -f $(TARGET) $(OBJS) - -# Run the program -run: $(TARGET) - ./$(TARGET) + rm -f $(TARGET) $(OBJS) diff --git a/caur b/caur index 707dfa620eee1f0df1a4374c9071cbc2b4a84e62..a17548415ceff681c243ae6a697613457210ab18 100755 GIT binary patch literal 23616 zcmeHP3vg6bnm!4FjS2|}14`6JVTjJsJd7-07{ViX8N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yA8v;t{V}F|_JGun^g(%3j9;!FZqrNoJM{luF$Ob4`u`48tN~{L literal 0 HcmV?d00001 diff --git a/main.o b/main.o new file mode 100644 index 0000000000000000000000000000000000000000..95ee78be33b89bf9abc189600dcb484bfb63f6d7 GIT binary patch literal 5528 zcmdUyPiP%Q9LMJ+wT-ncu_zW2b=B5?=#rLNsuX=~n)V5$)M`N`vf20Eyw_*F;i0ehqI)>DD`?OCt-VOU1s@^vEKV7un{cZs*ao z{_Q>QjN`x>Vq*6Fb#+WfwJ>TnT6HI$h>dPKopwF)tJ-y4?7}g>a>}o3XGiQ*!!xZQ z1gYx8ok~T=ajg>s6C2S?9r7Ci2qs)MbK1+UU~+hP_!Z~b!$(g%=j`0=?s9iJyM}h{ z9@;zfQsS=GLFT}PlK@t#M-{rrI2EYQYvUmj3LhL-h4KEvz@`m-mq8o^ju)o&c-z0F z|69 zpSS2s7JaZMouJ(DTl7(jK55ZsEc%>9pSS2s7JabSGJcCbYSAYx`iw=Nv*`1rU&3MV z_uF$Z{eaV7o$7*kKdXhldZ(zR_+Q)T=Dfy-#zXiNMA^*Jn zk;6B@VZ56Cwj8dSexv19lvn9Qfv5d=!i%*D+s4yTqka%q;?paT0;lbIL9DaEhmjZ!?jGBji$EQ#6cssk>L}^kGxsRKB2Bnqg4x&<-Br9 zW>vY^vsyLmlmngDZZf(R-OBnW7AA;eSRQdBY+;wyY^|cBq~B{Ar3-RRlk^M4k6g7o zCRXkAKf+6YB0TzuQ2fu}(a(Tt!^dl2bN_+19oSyg6L2lvP16nHu&pF#G4o$Ce0#=z zF~fIc_(nK)Fmd~XX;nQ!9NT{yE^hxBVSkY9cjwqUq+|PdaVk=Q`Fg643C?lEl;9jk z%nHtNL|1T*BNhb5IZ9GyT-Ya$BOJjwjwlMwam1M597jwEet;f3D>%myUBNkySP-1! z2%cP?PmUuT1dy1IB{ijrf^!@(COF3tQ-X6GF)KL75naJKj#v=<0`&(DDu1m}1`x$#8P_+`jVl;$V76zRZsjUG43 zO-=x}9LLIy!n9Hen@!yUtrZ&W!ax0saNNR~oYw2Djtl1+Y#U|*e6S^b(yK*&Q_~3k zTjqc}E-C*0xV0h`UZeHKTvXKn2)IWS*?{uJ&1s=a^#>qF-#)7IcZz!pa++3Bl{zOM zM2f^O0LM1}t^ZE&#Wr!xWz!TrsGfyT=KeE&84761`vUXd$)ERA=7bX;WC!44#x|Ju z$_|kzZI1)r0GBlHBOv=F`~N=pVw=)`FM&ldvC y?b+xzL<{nBdOn^5Pp;yRZHg`eQR-(DAU%$q%Op8}4}!Lu|11iSOqwmQL literal 0 HcmV?d00001 diff --git a/src/caur.h b/src/caur.h new file mode 100644 index 0000000..150fb08 --- /dev/null +++ b/src/caur.h @@ -0,0 +1,16 @@ +#ifndef CAUR_H +#define CAUR_H + +#include +#include + +// Function to write data to file +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream); + +// Function to download a package from the AUR +int download_package(const char *package_name); + +// Function to perform a system upgrade +int perform_system_upgrade(); + +#endif // CAUR_H diff --git a/src/download.c b/src/download.c new file mode 100644 index 0000000..77c1224 --- /dev/null +++ b/src/download.c @@ -0,0 +1,47 @@ +#include "caur.h" +#include + +#define AUR_PACKAGE_URL "https://aur.archlinux.org/cgit/aur.git/snapshot/" +#define AUR_PACKAGE_URL_END ".tar.gz" + +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t written = fwrite(ptr, size, nmemb, stream); + return written; +} + +int download_package(const char *package_name) { + CURL *curl; + FILE *fp; + CURLcode res; + char url[256]; + char outfilename[256]; + + 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; +} \ No newline at end of file diff --git a/src/download.o b/src/download.o new file mode 100644 index 0000000000000000000000000000000000000000..284bca6a86b6c9d65dd2e9a20cc0a01dd3c7b079 GIT binary patch literal 6976 zcmdU!UuYcF8o*D|*8kO7>OTy!RdY>^ZqiUiLzQi7+Yzf^HE_8`HnY34n>CZ2b!N6r zHEN`dur7hV#0Lpj#0zpCeDa}`R&rISB1kV>q-Y-UBGf;KJ}7;N*6%y>eY?l6JsH6# zzi{T9^ZWkHIcLt9`L=y!_r5*dU0sT$OFgVQJ*G-6-qdO5bTg-}RqNG=)BO6`kN$pF z=kWJ~PV=R6PP4J>G)K-l&BxC;EiBM(0c-6B-RW~URj0Z8JoL|hs^{sv`hBh&;i*r4 zy>OxAwAS|ak9$xSgK;Kj`|OP^vYDEwZ9fU1WR~Os>bst$7?= zYYxGsBXcBrKF!&sj%jsjWFwm#c{t{ zYfNQ>urg4rRAY^?j%sc_8V}+D)f?fTuGGPT+T&Jzuat>{Oi=e~nKJY;z0p;w*a-c+ z=SGL}buTOj;bh;IOj+9wYkkMBTC2txG`~uzy}Nb|XZrR&F|sAIbz62QyEQX3IJ9l> zfx-Lqpy9F>N(KsU7qC;^s%sG$OBeNVWl(ULP`X~&uezo-blrN*)y5gvK?RmUDRzy4r0@fCTgpGIz_*bqCc6UUrN!hr09ESk!mQ}jzI`jr%Y54=86tn*LNkEZCSQ}hcd`jaX8r4;>2ioRz}%KTIGqbd676#YVq z{$z@NiS)xb4L-k(&iP#-{X@78tY7m$cVdyuU0!j^tW`f?`+`pq z4+Y0Fit(oeKSlgy!M`MaMDX*(@p+=~d^f=!#rQ`P+~z~X-w^z1;tPV$5Pw_ne-nRK z@K1=pCpdQ3=&vg&sQMP{H^MmIr@lUO(Eb_thCiC>9-ck4|ABP+3_^Q7e5@~Jf1`!> zT6n*O4_WxIg+FHD&sun3;Rh_dY2m6A9IW|)TgnzyzLP9PUL4fpycdRfKd4nKDs3N> z%lX)15XE8D>U}V*#$LYY`hLMJPFNy@UKIETyf7a@q8O)JyQO@wV2M=?im`83M?rA{ zCvEk|%o2^fRcz{EP=PT=_9!K<(5TqeQ3OMbr|bsBpmxBnjXZC{t}PbwB{z00>jO_a z2=j$Tx$K1&lRb~_+ig+RgD5UnJ--xL4D@cnJRb~KGnuSTdTBP1U$q9=HL`!-Q;vCu ziWgUF@FIX>8~wfKZ;;`MAe{%Ls~Uj(F^ssS2apD zLW zS_Uclo?C0wRk`Q~k!L92ap-NQ@_53Fuy@BN^7sRd-q*`i!|O}k0cGVvA{qD&qrm4( zZHB`9Zo$zHWt-sqLv9aowCjb!ah?(O%ss(5|2SxgGi~sH81df{advFMi8~h%F zzhm%w4SvGlS%ZH}94m7jJ~KG3!zdJ#uZ%e6I(%c;n{j?MIL4XQQQ&tz}BEK*6!6G2I^O8jV$C?@P&yFfe%LV#`ERSoy1?Re_b*V0=F8UOOBYM zMnA0sbJ~{NRkuP5-x0YsNg7A5PwL~iP#{-BLEkH|1H$JQzY)mAZPbJW=ma9~kMCBD zDb4?^|5l1g!-QTUbqYAofNCB;;|HOEW8(J(^L4l=AU#RdzVi6F-U%9Rw~e5&nfy(L zZE3q7*yT{<`1{CTj!TaJIf^O$|4IHgi*ZPQ+=Xb8gJO!aiF&k-`24Sg!v6gHaX#|i u=vgPj8M;4yA8v;t{V}F|_JGun^g(%3j9;!FZqrNoJM{luF$Ob4`u`48tN~{L literal 0 HcmV?d00001 diff --git a/src/main.c b/src/main.c index cdb2c0e..75e8a44 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,7 @@ // Version: 0.1 -// caur - a simple command line utility for managing aur packages written in C hence the name lol +// date created 8-31-24 + +#include "caur.h" #include // For standard input/output operations #include // For memory allocation, process control, and conversions @@ -9,75 +11,11 @@ // #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; + return perform_system_upgrade(); } // The package name is the first argument after the program name diff --git a/src/main.o b/src/main.o new file mode 100644 index 0000000000000000000000000000000000000000..95ee78be33b89bf9abc189600dcb484bfb63f6d7 GIT binary patch literal 5528 zcmdUyPiP%Q9LMJ+wT-ncu_zW2b=B5?=#rLNsuX=~n)V5$)M`N`vf20Eyw_*F;i0ehqI)>DD`?OCt-VOU1s@^vEKV7un{cZs*ao z{_Q>QjN`x>Vq*6Fb#+WfwJ>TnT6HI$h>dPKopwF)tJ-y4?7}g>a>}o3XGiQ*!!xZQ z1gYx8ok~T=ajg>s6C2S?9r7Ci2qs)MbK1+UU~+hP_!Z~b!$(g%=j`0=?s9iJyM}h{ z9@;zfQsS=GLFT}PlK@t#M-{rrI2EYQYvUmj3LhL-h4KEvz@`m-mq8o^ju)o&c-z0F z|69 zpSS2s7JaZMouJ(DTl7(jK55ZsEc%>9pSS2s7JabSGJcCbYSAYx`iw=Nv*`1rU&3MV z_uF$Z{eaV7o$7*kKdXhldZ(zR_+Q)T=Dfy-#zXiNMA^*Jn zk;6B@VZ56Cwj8dSexv19lvn9Qfv5d=!i%*D+s4yTqka%q;?paT0;lbIL9DaEhmjZ!?jGBji$EQ#6cssk>L}^kGxsRKB2Bnqg4x&<-Br9 zW>vY^vsyLmlmngDZZf(R-OBnW7AA;eSRQdBY+;wyY^|cBq~B{Ar3-RRlk^M4k6g7o zCRXkAKf+6YB0TzuQ2fu}(a(Tt!^dl2bN_+19oSyg6L2lvP16nHu&pF#G4o$Ce0#=z zF~fIc_(nK)Fmd~XX;nQ!9NT{yE^hxBVSkY9cjwqUq+|PdaVk=Q`Fg643C?lEl;9jk z%nHtNL|1T*BNhb5IZ9GyT-Ya$BOJjwjwlMwam1M597jwEet;f3D>%myUBNkySP-1! z2%cP?PmUuT1dy1IB{ijrf^!@(COF3tQ-X6GF)KL75naJKj#v=<0`&(DDu1m}1`x$#8P_+`jVl;$V76zRZsjUG43 zO-=x}9LLIy!n9Hen@!yUtrZ&W!ax0saNNR~oYw2Djtl1+Y#U|*e6S^b(yK*&Q_~3k zTjqc}E-C*0xV0h`UZeHKTvXKn2)IWS*?{uJ&1s=a^#>qF-#)7IcZz!pa++3Bl{zOM zM2f^O0LM1}t^ZE&#Wr!xWz!TrsGfyT=KeE&84761`vUXd$)ERA=7bX;WC!44#x|Ju z$_|kzZI1)r0GBlHBOv=F`~N=pVw=)`FM&ldvC y?b+xzL<{nBdOn^5Pp;yRZHg`eQR-(DAU%$q%Op8}4}!Lu|11iSOqwmQL literal 0 HcmV?d00001 diff --git a/src/upgrade.c b/src/upgrade.c new file mode 100644 index 0000000..3ef0795 --- /dev/null +++ b/src/upgrade.c @@ -0,0 +1,19 @@ +#include "caur.h" + +#include +#include + +int perform_system_upgrade() { + 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; +} \ No newline at end of file diff --git a/src/upgrade.o b/src/upgrade.o new file mode 100644 index 0000000000000000000000000000000000000000..0543c57da4c0ede6aa30ca99c84c2ef6f5bc3ac1 GIT binary patch literal 5680 zcmdUzU2GIp6vyut1VktmAt9lf0r^lOYm2Brh*@X~YeYgQBt&brv$J>GmD!!m%pGV+ zl_r2mB_uql2~BJW4?Y?kGjooNr=3osPu^sD z@BRJHIrq+;J9E$WZ1151ZMmG{l2b3K2R)`reX{yNyAU-Cs$H#A$BW}XzH#&a_qTZN z=Z@l~hwx5{ENe?ycGT;kM#M;y1qB0Q@Ul4`F*9+1(Qt!DZ&`g;ux+TAS5< zr7pBg9@;nVEnD^3cO2-_O0b4;zJ;N#V>22rj`&D=Pz!F#p+l1lFluQ<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