fordon_greeman / sfetch

Branch: 096ab11
Switch branches/tags
main
theidioticdev i forgot to add the license... 096ab11 2026-10-03
70 lines · 1.3 KB Raw Blame History
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #define PROG_NAME "sfetch"
6 #define COMPILE_CMD "gcc -Wall -Wextra -O3 src/main.c -o " PROG_NAME
7 #define DEST "/usr/local/bin"
8 #define INSTALL_CMD "cp " PROG_NAME " " DEST "/" PROG_NAME
9 #define UNINSTALL_CMD "rm " DEST "/" PROG_NAME
10
11 int
12 build(void)
13 {
14 printf("[BUILD]: %s\n", COMPILE_CMD);
15 if (system(COMPILE_CMD) != 0)
16 {
17 fprintf(stderr, "[ERROR]: compilation failed\n");
18 return 0;
19 }
20 printf("[SUCCESS]: compiled successfully\n");
21 return 1;
22 }
23
24 int
25 install(void)
26 {
27 if (!build()) return 0;
28 printf("[INSTALL]: %s\n", INSTALL_CMD);
29 if (system(INSTALL_CMD) != 0)
30 {
31 fprintf(stderr, "[ERROR]: install failed\n");
32 return 0;
33 }
34 printf("[SUCCESS]: installed successfully\n");
35 return 1;
36 }
37
38
39 int
40 uninstall(void)
41 {
42 if (system(UNINSTALL_CMD) != 0)
43 {
44 fprintf(stderr, "[ERROR]: uninstall failed.\n");
45 return 0;
46 }
47 printf("[SUCCESS]: uninstalled successfully\n");
48 return 1;
49 }
50
51 int
52 main(int argc, char **argv)
53 {
54 if (argc < 2 || strcmp(argv[1], "--build-only") == 0)
55 {
56 return build() ? 0 : 1;
57 }
58
59 if (strcmp(argv[1], "--install") == 0)
60 {
61 return install() ? 0 : 1;
62 }
63
64 if (strcmp(argv[1], "--uninstall") == 0)
65 {
66 return uninstall() ? 0 : 1;
67 }
68 fprintf(stderr, "Unknown argument: %s\n", argv[1]);
69 return 1;
70 }