aboutsummaryrefslogtreecommitdiff
path: root/snag
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2026-07-20 19:07:43 -0400
committerJack Jamison <jackqjamison@gmail.com>2026-07-20 19:07:43 -0400
commitd598be66eddc0e925eee96e23d9f95c88cf1f6ed (patch)
tree4edf80f0bdd7fab19e5f3a227da43ea0f3a8d0e1 /snag
parente057a21962fe9e81b47cfd6b97fc4c6c2cb156b9 (diff)
split into separate file, readme clarifications
Diffstat (limited to 'snag')
-rw-r--r--snag/main.c92
-rw-r--r--snag/makefile4
-rw-r--r--snag/pkg_db.c81
-rw-r--r--snag/pkg_db.h19
-rw-r--r--snag/readme.txt40
5 files changed, 128 insertions, 108 deletions
diff --git a/snag/main.c b/snag/main.c
index 0b5f442..9f9fd44 100644
--- a/snag/main.c
+++ b/snag/main.c
@@ -1,21 +1,8 @@
#include <stdio.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#define PKG_DB "../packages"
-#define PKG_INFO_CMD "./get_pkg_attrs.sh"
-
-typedef struct {
- char* id;
- char* name;
- char* desc;
- char* script_path;
-} package_info_t;
+#include "pkg_db.h"
void subcmd_install(char* pkgs[], size_t count);
-bool load_package_info(package_info_t* info, char* pkgid);
int main(int argc, char* argv[]) {
@@ -35,82 +22,7 @@ void subcmd_install(char* pkgs[], size_t count) {
// load package description
package_info_t info;
if (load_package_info(&info, pkgid)) {
- printf("Installing '%s'\n", info.name);
+ printf("Installing '%s'\n", info.id);
}
}
}
-
-// loads and allocates package attributes for the info struct. does not do
-// excessive validation, so this should be fine when loading package data in
-// bulk.
-bool load_package_info(package_info_t* info, char* pkgid) {
-
- // construct package description directory path and ensure it exists
- size_t pkg_dir_len = strlen(PKG_DB) + strlen(pkgid) + 1;
- char* pkg_dir = malloc(pkg_dir_len + 1);
- snprintf(pkg_dir, pkg_dir_len + 1, "%s/%s", PKG_DB, pkgid);
- if (access(pkg_dir, F_OK) != 0) {
- fprintf(stderr, "Package '%s' not found in database\n", pkgid);
- free(pkg_dir);
- return false;
- }
-
- // construct package description script path and ensure it exists
- size_t script_path_len = pkg_dir_len + strlen(pkgid) + 4;
- info->script_path = malloc(script_path_len + 1);
- snprintf(info->script_path, script_path_len + 1, "%s/%s.sh", pkg_dir, pkgid);
- free(pkg_dir);
- if (access(info->script_path, F_OK) != 0) {
- fprintf(stderr, "Package '%s' broken, doesn't have description script\n", pkgid);
- free(info->script_path);
- return false;
- }
-
- // run get_pkg_attrs script that outputs package attributes
- size_t cmd_len = strlen(PKG_INFO_CMD) + script_path_len + 3;
- char* cmd = malloc(cmd_len + 1);
- snprintf(cmd, cmd_len + 1, "%s '%s'", PKG_INFO_CMD, info->script_path);
- FILE* getinfo_fp = popen(cmd, "r");
- free(cmd);
- if (getinfo_fp == NULL) {
- perror("failed to popen get_pkg_attrs");
- exit(1); // fatal error
- }
-
- // go through each NULL delimited section of the output
- size_t n = 0;
- char* line = NULL;
- ssize_t read;
- while ((read = getdelim(&line, &n, '\0', getinfo_fp)) != -1) {
- // read in property based on first attribute type character
- char atype = line[0];
- char* avalue = line+1;
- switch (atype) {
- case 'i':
- // id
- info->id = strdup(avalue);
- break;
- case 'n':
- // name
- info->name = strdup(avalue);
- break;
- case 'd':
- // description
- info->desc = strdup(avalue);
- break;
- }
- }
- free(line);
-
- // close the get_pkg_attrs process
- int close_err = pclose(getinfo_fp);
- if (close_err == -1) {
- perror("failed to pclose get_pkg_attrs");
- exit(1); // fatal error
- } else if (close_err != 0) {
- fprintf(stderr, "failed to execute get_pkg_attrs: %d\n", close_err);
- exit(1); // fatal error
- }
-
- return true;
-}
diff --git a/snag/makefile b/snag/makefile
index 8fa032c..b44020f 100644
--- a/snag/makefile
+++ b/snag/makefile
@@ -3,7 +3,7 @@ CFLAGS = -Wall -g
TARGET = snag
-SRCS = main.c
+SRCS = main.c pkg_db.c
OBJS = $(SRCS:.c=.o)
.SILENT: $(OBJS) $(TARGET)
@@ -15,7 +15,7 @@ clean:
$(TARGET): $(OBJS)
printf " LD %s\n" $@
- $(CC) $(CFLAGS) -o $@ $<
+ $(CC) $(CFLAGS) -o $@ $^
%.o: %.c
printf " CC %s\n" $<
diff --git a/snag/pkg_db.c b/snag/pkg_db.c
new file mode 100644
index 0000000..26e972d
--- /dev/null
+++ b/snag/pkg_db.c
@@ -0,0 +1,81 @@
+#include "pkg_db.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define PKG_DB "../packages"
+#define PKG_INFO_CMD "./get_pkg_attrs.sh"
+
+bool load_package_info(package_info_t* info, char* pkgid) {
+
+ // construct package description directory path and ensure it exists
+ size_t pkg_dir_len = strlen(PKG_DB) + strlen(pkgid) + 1;
+ char* pkg_dir = malloc(pkg_dir_len + 1);
+ snprintf(pkg_dir, pkg_dir_len + 1, "%s/%s", PKG_DB, pkgid);
+ if (access(pkg_dir, F_OK) != 0) {
+ fprintf(stderr, "Package '%s' not found in database\n", pkgid);
+ free(pkg_dir);
+ return false;
+ }
+
+ // construct package description script path and ensure it exists
+ size_t script_path_len = pkg_dir_len + strlen(pkgid) + 4;
+ info->script_path = malloc(script_path_len + 1);
+ snprintf(info->script_path, script_path_len + 1, "%s/%s.sh", pkg_dir, pkgid);
+ free(pkg_dir);
+ if (access(info->script_path, F_OK) != 0) {
+ fprintf(stderr, "Package '%s' broken, doesn't have description script\n", pkgid);
+ free(info->script_path);
+ return false;
+ }
+
+ // construct get_pkg_attrs script cmd and invoke it
+ size_t cmd_len = strlen(PKG_INFO_CMD) + script_path_len + 3;
+ char* cmd = malloc(cmd_len + 1);
+ snprintf(cmd, cmd_len + 1, "%s '%s'", PKG_INFO_CMD, info->script_path);
+ FILE* getinfo_fp = popen(cmd, "r");
+ free(cmd);
+ if (getinfo_fp == NULL) {
+ perror("failed to popen get_pkg_attrs");
+ exit(1); // fatal error
+ }
+
+ // go through each NULL delimited section of the output (attributes)
+ size_t n = 0;
+ char* line = NULL;
+ ssize_t read;
+ while ((read = getdelim(&line, &n, '\0', getinfo_fp)) != -1) {
+ // read in property based on first attribute type character
+ char atype = line[0];
+ char* avalue = line+1;
+ switch (atype) {
+ case 'i':
+ // id
+ info->id = strdup(avalue);
+ break;
+ case 'n':
+ // name
+ info->name = strdup(avalue);
+ break;
+ case 'd':
+ // description
+ info->desc = strdup(avalue);
+ break;
+ }
+ }
+ free(line);
+
+ // close the get_pkg_attrs process
+ int close_err = pclose(getinfo_fp);
+ if (close_err == -1) {
+ perror("failed to pclose get_pkg_attrs");
+ exit(1); // fatal error
+ } else if (close_err != 0) {
+ fprintf(stderr, "failed to execute get_pkg_attrs: %d\n", close_err);
+ exit(1); // fatal error
+ }
+
+ return true;
+}
diff --git a/snag/pkg_db.h b/snag/pkg_db.h
new file mode 100644
index 0000000..e0f9a30
--- /dev/null
+++ b/snag/pkg_db.h
@@ -0,0 +1,19 @@
+#ifndef PKG_DB_H
+#define PKG_DB_H
+
+#include <stdbool.h>
+
+// loads and allocates package attributes for the info struct. does not do
+// excessive validation, so this should be fine when loading package data in
+// bulk.
+
+typedef struct {
+ char* id;
+ char* name;
+ char* desc;
+ char* script_path;
+} package_info_t;
+
+bool load_package_info(package_info_t* info, char* pkgid);
+
+#endif
diff --git a/snag/readme.txt b/snag/readme.txt
index ca358b6..ffc6041 100644
--- a/snag/readme.txt
+++ b/snag/readme.txt
@@ -1,15 +1,15 @@
# SNAGGLE Package Manager (snag)
## Useful Subcommands
-`install`/`inst` - install the specified package(s) (default)
-`remove` - uninstall the specified package(s)
-`upgrade/'up` - upgrade the package database
-`find`/`search` - list packages whose metadata matches specified search string (flag to limit to installed)
-`info`/`desc` - describe the metadata (and install data) of the specified package(s)
-`log` - open your pager to the build log of the specified package
+install/inst - install the specified package(s) (default)
+remove - uninstall the specified package(s)
+upgrade/up - upgrade the package database
+find/search - list packages whose metadata matches specified search string (flag to limit to installed)
+info/desc - describe the metadata (and install data) of the specified package(s)
+log - open your pager to the build log of the specified package
-`files` - list the installed files of the specified package(s)
-`why` - list why this package is installed (manually installed, as a dependency, from a group)
+files - list the installed files of the specified package(s)
+why - list why this package is installed (manually installed, as a dependency, from a group)
## Important Directories
Package Database - /var/snag/pkgs/
@@ -18,24 +18,32 @@ Logs/In Progress Builds - /var/snag/logs/
SNAG Configuration - /etc/snag/
## Terminology
-"Package Database" - the directory containing package descriptions
-"Install Database" - the directory containing information on installed package
-"Package Description" - the directory and script containing build instructions for a package
-"Package Info/Metadata" - the metadata encoded in the package description
-"Package Attribute" - a single key value property of the package info
-
-## Package Format
+Package Database - the directory containing package descriptions
+Package Description - the directory and script containing build instructions for a package
+Package Info/Metadata - the metadata encoded in the package description
+Package Attribute - a single key value property of the package info
+Install Database - the directory containing information on installed package
+Install Description - the data stored about a package in the install database
+
+## Package Description Format
Each package has a directory in the package database, named by its `id`.
Inside each package directory is the description script named `{id}.sh`
The description script should have functions for `configure`, `build`, and `install`
The description script should define variables for attributes with the name `pkg_{attr}`
+## Install Description Format
+TBD. Will contain at least:
+- date installed
+- flists
+- install reason
+
+
## Interesting Features
- switch between cli and tui mode mid run
- build packages that aren't in the database
Packages have the following attributes:
-`id` - the identifier name of the package. everything uses this
+`id` - the identifier name of the package. everything uses this
`name` - the display name of package
`desc` - the short description of the package