From 86af4e8487f27dd69863b1380fe17e841605214f Mon Sep 17 00:00:00 2001 From: Jack Jamison Date: Mon, 20 Jul 2026 15:56:56 -0400 Subject: improvements and fixes --- snag/get_pkg_attrs.sh | 19 +++++++++++++++++++ snag/main.c | 20 ++++++++++++++------ snag/readme.txt | 15 ++++++++++----- snag/run_pkg_install.sh | 16 ++++++++++++++++ snag/snagpkginfo.sh | 19 ------------------- 5 files changed, 59 insertions(+), 30 deletions(-) create mode 100755 snag/get_pkg_attrs.sh create mode 100755 snag/run_pkg_install.sh delete mode 100755 snag/snagpkginfo.sh (limited to 'snag') diff --git a/snag/get_pkg_attrs.sh b/snag/get_pkg_attrs.sh new file mode 100755 index 0000000..bb80418 --- /dev/null +++ b/snag/get_pkg_attrs.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# reads a package description script and outputs the attributes in a format easy +# for the snag program to read. it does not do any other validation, and should +# not be used by other programs + +if [ -z "$1" ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +# load the description script +. $1 + +# output package attributes (type char, value, null delimiter) +echoatt() { [ -n "$2" ] && printf "$1$2\0"; } +echoatt i "$pkg_id" +echoatt n "$pkg_name" +echoatt d "$pkg_desc" diff --git a/snag/main.c b/snag/main.c index 10a5f86..c80ec65 100644 --- a/snag/main.c +++ b/snag/main.c @@ -5,7 +5,7 @@ #include #define PKG_DB "../snaggies" -#define PKG_INFO_CMD "./snagpkginfo.sh" +#define PKG_INFO_CMD "./get_pkg_attrs.sh" typedef struct { char* id; @@ -40,6 +40,9 @@ void subcmd_install(char* pkgs[], size_t count) { } } +// 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 @@ -63,13 +66,14 @@ bool load_package_info(package_info_t* info, char* pkgid) { return false; } - // run getpkginfo script that outputs package attributes + // 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 getpkginfo"); + perror("failed to popen get_pkg_attrs"); exit(1); // fatal error } @@ -98,9 +102,13 @@ bool load_package_info(package_info_t* info, char* pkgid) { } free(line); - // close the getpkginfo process - if (pclose(getinfo_fp) != 0) { - perror("failed to pclose getpkginfo"); + // 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 } diff --git a/snag/readme.txt b/snag/readme.txt index d93431d..6062924 100644 --- a/snag/readme.txt +++ b/snag/readme.txt @@ -11,6 +11,12 @@ `log` - open your pager to the build log of the specified package `why` - list why this package is installed (manually installed, as a dependency, from a group) +## Important Directories +Package Database - /var/snag/pkgs/ +Install Database - /var/snag/install/ +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 @@ -23,16 +29,15 @@ 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}` -> We're still deciding if we want the metadata to be split from the instruction in separate file(s). + +## 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 `name` - the display name of package `desc` - the short description of the package -## Interesting Features -- switch between cli and tui mode mid run -- build packages that aren't in the database - ## Developer Subcommands `validate` - check a package description and check for format errors or warnings diff --git a/snag/run_pkg_install.sh b/snag/run_pkg_install.sh new file mode 100755 index 0000000..d48d831 --- /dev/null +++ b/snag/run_pkg_install.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# reads a package description script and runs the configure, build, and install +# steps. intended only for use by snag program +if [ -z "$1" ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +# load the description script +. $1 + +# run all install steps for package +configure +build +install diff --git a/snag/snagpkginfo.sh b/snag/snagpkginfo.sh deleted file mode 100755 index bb80418..0000000 --- a/snag/snagpkginfo.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -# reads a package description script and outputs the attributes in a format easy -# for the snag program to read. it does not do any other validation, and should -# not be used by other programs - -if [ -z "$1" ]; then - echo "Usage: $0 " >&2 - exit 1 -fi - -# load the description script -. $1 - -# output package attributes (type char, value, null delimiter) -echoatt() { [ -n "$2" ] && printf "$1$2\0"; } -echoatt i "$pkg_id" -echoatt n "$pkg_name" -echoatt d "$pkg_desc" -- cgit v1.2.3