fordon_greeman / pkger

added gnuit pkg, implemented basic dependencies res, added preview img, TODO Browse files
theidioticdev committed 1d ago parent b68a1f4 commit 0170f11420200d7d206be0b410e9b51dd8a7fb95
Showing 7 changed files with 83 additions and 46 deletions. UnifiedSplit
+6 −6 Makefile
@@ -1,17 +1,17 @@
1 -CC = cc 1 +CC = tcc
2 # CFLAGS = -Wall -Wextra -pendanic 2 # CFLAGS = -Wall -Wextra -pendanic
3 TARGET = pkger 3 TARGET = pkger
4 all: $(TARGET) 4 all: $(TARGET)
5 5
6 $(TARGET): pkger.c 6 $(TARGET): pkger.c
7 -# $(CC) $(CFLAGS) -o $(TARGET) pkger.c 7 + $(CC) $(CFLAGS) -o $(TARGET) pkger.c
8 - $(CC) -o $(TARGET) pkger.c 8 +# $(CC) -o $(TARGET) pkger.c
9 9
10 install: $(TARGET) 10 install: $(TARGET)
11 - mkdir -p /usr/local/bin 11 + mkdir -p $(HOME)/local/bin
12 - cp $(TARGET) /usr/local/bin/$(TARGET) 12 + cp $(TARGET) $(HOME)/.local/bin/$(TARGET)
13 13
14 uninstall: 14 uninstall:
15 - rm -f /usr/local/bin/$(TARGET) 15 + rm -f $(HOME)/.local/bin/$(TARGET)
16 16
17 .PHONY: all clean install uninstall 17 .PHONY: all clean install uninstall
+6 −0 TODO.org new file mode 100644
@@ -0,0 +1,6 @@
1 +* refactors
2 + - add dependencies as .dep files
3 +
4 +
5 +* cleanup
6 + - rem
+0 −0 assets/prev.png new file mode 100644, Binary files /dev/null and b/assets/prev.png differ
+0 −0 pkger Binary files a/pkger and b/pkger differ
+54 −40 pkger.c
@@ -1,6 +1,5 @@
1 -/* this project is licensed under GNU Public License Version 3 */
2 -
3 #include <stdio.h> 1 #include <stdio.h>
2 +#include <errno.h>
4 #include <unistd.h> 3 #include <unistd.h>
5 #include <sys/wait.h> 4 #include <sys/wait.h>
6 #include <stdlib.h> 5 #include <stdlib.h>
@@ -19,7 +18,7 @@ char bin_dir[512];
19 char recipe_dir[512]; 18 char recipe_dir[512];
20 char usr_dir[512]; 19 char usr_dir[512];
21 char etc_dir[512]; 20 char etc_dir[512];
22 - 21 +char tmp_dir[512];
23 /* make the fakeroot fs */ 22 /* make the fakeroot fs */
24 int 23 int
25 init_fakeroot (void) 24 init_fakeroot (void)
@@ -32,6 +31,7 @@ init_fakeroot (void)
32 snprintf (bin_dir, sizeof (bin_dir), "%s/usr/bin", root_dir); 31 snprintf (bin_dir, sizeof (bin_dir), "%s/usr/bin", root_dir);
33 snprintf (usr_dir, sizeof (usr_dir), "%s/usr", root_dir); 32 snprintf (usr_dir, sizeof (usr_dir), "%s/usr", root_dir);
34 snprintf (etc_dir, sizeof (etc_dir), "%s/etc", root_dir); 33 snprintf (etc_dir, sizeof (etc_dir), "%s/etc", root_dir);
34 + snprintf (tmp_dir, sizeof (tmp_dir), "%s/tmp", root_dir);
35 snprintf (recipe_dir, sizeof (recipe_dir), "%s/etc/recipes", root_dir); 35 snprintf (recipe_dir, sizeof (recipe_dir), "%s/etc/recipes", root_dir);
36 36
37 struct stat st; 37 struct stat st;
@@ -41,6 +41,7 @@ init_fakeroot (void)
41 mkdir (root_dir, 0755); 41 mkdir (root_dir, 0755);
42 mkdir (usr_dir, 0755); 42 mkdir (usr_dir, 0755);
43 mkdir (bin_dir, 0755); 43 mkdir (bin_dir, 0755);
44 + mkdir (tmp_dir, 0755);
44 mkdir (etc_dir, 0755); 45 mkdir (etc_dir, 0755);
45 mkdir (recipe_dir, 0755); 46 mkdir (recipe_dir, 0755);
46 47
@@ -48,6 +49,37 @@ init_fakeroot (void)
48 return 0; 49 return 0;
49 } 50 }
50 51
52 +
53 +/* helper 1 */
54 +int
55 +run_cmd (char *const argv[])
56 +{
57 + pid_t pid = fork();
58 + if (pid == 0)
59 + {
60 + execvp(argv[0], argv);
61 + perror("execvp failed");
62 + _exit(1);
63 + } else if (pid > 0)
64 + {
65 + int status;
66 + waitpid(pid, &status, 0);
67 + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) return 0;
68 + }
69 + return -1;
70 +}
71 +
72 +/* helper 2 */
73 +int
74 +exec_str (const char *cmd)
75 +{
76 + if (cmd == NULL || cmd[0] == '\0') return 0;
77 + char *const argv[] = { "/bin/sh", "-c", (char *)cmd, NULL };
78 + printf("[EXEC] %s\n", cmd);
79 + return run_cmd (argv);
80 +}
81 +
82 +
51 /* recipes parsing */ 83 /* recipes parsing */
52 84
53 int 85 int
@@ -112,35 +144,6 @@ list_recipes (void)
112 closedir (d); 144 closedir (d);
113 } 145 }
114 146
115 -/* helper 1 */
116 -int
117 -run_cmd (char *const argv[])
118 -{
119 - pid_t pid = fork();
120 - if (pid == 0)
121 - {
122 - execvp(argv[0], argv);
123 - perror("execvp failed");
124 - _exit(1);
125 - } else if (pid > 0)
126 - {
127 - int status;
128 - waitpid(pid, &status, 0);
129 - if (WIFEXITED(status) && WEXITSTATUS(status) == 0) return 0;
130 - }
131 - return -1;
132 -}
133 -
134 -/* helper 2 */
135 -int
136 -exec_str (const char *cmd)
137 -{
138 - if (cmd == NULL || cmd[0] == '\0') return 0;
139 - char *const argv[] = { "/bin/sh", "-c", (char *)cmd, NULL };
140 - printf("[EXEC] %s\n", cmd);
141 - return run_cmd (argv);
142 -}
143 -
144 /* TODO: add simple dependency res */ 147 /* TODO: add simple dependency res */
145 148
146 /* dependencies, finally. */ 149 /* dependencies, finally. */
@@ -156,7 +159,7 @@ get_deps (const char *pkg_name)
156 return 0; 159 return 0;
157 } 160 }
158 161
159 - printf ("[DEPS] Loading dependencies for %s\n", pkg_name); 162 + printf ("[DEPS] dependencies for %s\n", pkg_name);
160 char line[1024]; 163 char line[1024];
161 while (fgets (line, sizeof (line), file)) 164 while (fgets (line, sizeof (line), file))
162 { 165 {
@@ -199,15 +202,16 @@ pkg_get (const char *pkg_name)
199 snprintf (build_root, sizeof (build_root), "%s/tmp/build", root_dir); 202 snprintf (build_root, sizeof (build_root), "%s/tmp/build", root_dir);
200 snprintf (build_dir, sizeof (build_dir), "%s/%s", build_root, pkg_name); 203 snprintf (build_dir, sizeof (build_dir), "%s/%s", build_root, pkg_name);
201 204
202 - if (mkdir (build_root, 0755) != 0) 205 +
206 + if (mkdir (build_root, 0755) != 0 && errno != EEXIST)
203 { 207 {
204 - perror("Failed to make directory"); 208 + perror("Failed to make build root directory");
205 return -1; 209 return -1;
206 } 210 }
207 211
208 - if (mkdir (build_dir, 0755) != 0) 212 + if (mkdir (build_dir, 0755) != 0 && errno != EEXIST)
209 { 213 {
210 - perror("Failed to make directory"); 214 + perror("Failed to make package build directory");
211 return -1; 215 return -1;
212 } 216 }
213 217
@@ -216,7 +220,13 @@ pkg_get (const char *pkg_name)
216 perror("Failed to change directory"); 220 perror("Failed to change directory");
217 return -1; 221 return -1;
218 } 222 }
219 - 223 +
224 + if (chdir (build_dir) != 0)
225 + {
226 + perror("Failed to change directory");
227 + return -1;
228 + }
229 + if (get_deps (pkg_name) != 0) return -1;
220 if (exec_str (r.pkg_fetch) != 0) return -1; 230 if (exec_str (r.pkg_fetch) != 0) return -1;
221 if (exec_str (r.pkg_build) != 0) return -1; 231 if (exec_str (r.pkg_build) != 0) return -1;
222 if (exec_str (r.pkg_install) != 0) return -1; 232 if (exec_str (r.pkg_install) != 0) return -1;
@@ -253,12 +263,12 @@ main (int argc, char **argv)
253 263
254 if (argc < 2) 264 if (argc < 2)
255 { 265 {
256 - fprintf (stderr, "Usage: %s [list|get|rm|help] <pkg>\n", argv[0]); 266 + fprintf (stderr, "%s: no subcommand provided.\nrun `pkger help` for info.\n", argv[0]);
257 return EXIT_FAILURE; 267 return EXIT_FAILURE;
258 } 268 }
259 if (strcmp (argv[1], "help") == 0) 269 if (strcmp (argv[1], "help") == 0)
260 { 270 {
261 - printf ("Usage: %s [list|get|rm|help] <pkg>\n", argv[0]); 271 + printf ("Usage: %s [list|get|rm|help|init] <pkg>\n", argv[0]);
262 } 272 }
263 else if (strcmp (argv[1], "list") == 0) 273 else if (strcmp (argv[1], "list") == 0)
264 { 274 {
@@ -268,6 +278,10 @@ main (int argc, char **argv)
268 { 278 {
269 pkg_get (argv[2]); 279 pkg_get (argv[2]);
270 } 280 }
281 + else if (strcmp (argv[1], "init") == 0 && argc > 2)
282 + {
283 + if (init_fakeroot () != 0) return EXIT_FAILURE;
284 + }
271 else if (strcmp (argv[1], "rm") == 0 && argc > 2) 285 else if (strcmp (argv[1], "rm") == 0 && argc > 2)
272 { 286 {
273 pkg_rm (argv[2]); 287 pkg_rm (argv[2]);
+11 −0 readme.org
@@ -1,6 +1,8 @@
1 #+TITLE: pkger 1 #+TITLE: pkger
2 #+AUTHOR: theidioticdev 2 #+AUTHOR: theidioticdev
3 3
4 +[[./assets/prev.png]]
5 +
4 [WIP] 6 [WIP]
5 pkger is a really unconventional and bad pkg manager written in C 7 pkger is a really unconventional and bad pkg manager written in C
6 8
@@ -15,3 +17,12 @@ to add recipes, you write for example =foo.build=:
15 pkg_install = "<command_to_install>" 17 pkg_install = "<command_to_install>"
16 pkg_uninstall = "<command_to_unins>" 18 pkg_uninstall = "<command_to_unins>"
17 #+END_SRC 19 #+END_SRC
20 +
21 +and to add dependencies, you write for example foo.deps:
22 +#+BEGIN_SRC text
23 + # dep1
24 + ! <command_to_get>
25 + ! <command_to_build>
26 + ! <command_to_install>
27 + # and so on for other deps...
28 +#+END_SRC
+6 −0 recipes/gnuit.build new file mode 100644
@@ -0,0 +1,6 @@
1 +pkg_name = "gnuit"
2 +pkg_ver = "4.9.2"
3 +pkg_fetch = "wget https://ftp.gnu.org/gnu/gnuit/gnuit-4.9.2.tar.gz -P $HOME/pkger_root/tmp/build/gnuit && tar xf gnuit-4.9.2.tar.gz"
4 +pkg_build = "cd gnuit-4.9.2 && ./configure && ./make"
5 +pkg_install = "cd gnuit-4.9.2 && make prefix=$HOME/pkger_root/usr/bin install"
6 +pkg_uninstall = "cd gnuit-4.9.2 && make prefix=$HOME/pkger_root/usr/bin uninstall"
\ No newline at end of file \ No newline at end of file