Skip to content

Commit ba742ea

Browse files
committed
♻️ Synced dbin 📦 <-- config.go: hooks: change env var values ⌚
1 parent 9f9d9a2 commit ba742ea

File tree

13 files changed

+772
-538
lines changed

13 files changed

+772
-538
lines changed

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/xplshn/dbin?include_prereleases)](https://github.com/xplshn/dbin/releases/latest)
55
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/xplshn/dbin)
66

7-
<p align="center"><img src="https://github.com/user-attachments/assets/3c2dd460-6590-4e69-9c08-69bcccf77d9d" alt="dbin logo, made by a professional (my brother)" width="150" /></p>
7+
<p align="center"><img src="https://raw.githubusercontent.com/xplshn/dbin/master/misc/assets/pin.svg" alt="dbin logo, made with love, by @peacefulwilliam <github.com/contrarybaton60>" width="150" /></p>
88

99
<!--[Makes my repo look bad because these usually show "Failing"]-------------------------------------------------------------------------------------------
1010
[![AMD64 repo status](https://github.com/Azathothas/Toolpacks/actions/workflows/build_x86_64_Linux.yaml/badge.svg)](https://github.com/Azathothas/Toolpacks)
@@ -17,7 +17,7 @@ dbin can also work on systems other than Linux, but given that we don't have rep
1717

1818
> Why?
1919
20-
"I tend to think the drawbacks of dynamic linking outweigh the advantages for many (most?) applications." – John Carmack. If you are looking for more in-depth arguments, see: [dynlib - drewdevault.com](https://drewdevault.com/dynlib.html), [cat-v.ORG - Dynamic Linking](https://harmful.cat-v.org/software/dynamic-linking)
20+
"I tend to think the drawbacks of dynamic linking outweigh the advantages for many (most?) applications." – John Carmack. If you are looking for more in-depth arguments, see: [dynlib - drewdevault.com](https://drewdevault.com/dynlib.html), [cat-v.ORG - Dynamic Linking](https://harmful.cat-v.org/software/dynamic-linking)
2121

2222
> I've seen lots of package manager projects without "packages". What is different about this one?
2323
@@ -70,7 +70,7 @@ $ dbin --help
7070
dbin info
7171
dbin info | grep a-utils | xargs dbin add # install the entire a-utils suite
7272
dbin info jq
73-
dbin list --described
73+
dbin list --detailed
7474
dbin tldr gum
7575
dbin --verbose run curl -qsfSL "https://raw.githubusercontent.com/xplshn/dbin/master/stubdl" | sh -
7676
dbin --silent run --transparent micro ~/.profile
@@ -117,7 +117,7 @@ Rank: 1102
117117
Snapshots: HEAD-9b3f7ff-250119T130748-x86_64-linux [2.0.14]
118118
```
119119
##### Arguments of `list`
120-
`list` can receive the optional argument `--described`/`-d`. It will display all binaries + their description
120+
`list` can receive the optional argument `--detailed`/`-d`. It will display all binaries + their description
121121
##### Arguments of `search`
122122
`search` can only receive various search terms, if the name of a binary or a description of a binary contains the term, it is shown as a search result.
123123
`search` can optionally receive a `--limit` argument, which changes the limit on how many search results can be displayed (default is 90) (you can also put this in your config)
@@ -144,10 +144,9 @@ system_info=$(wget -qO- "https://raw.githubusercontent.com/xplshn/dbin/master/st
144144
![image](https://github.com/user-attachments/assets/949465ab-9572-404f-b02d-319eb3bc2fe0)
145145
![image](https://github.com/user-attachments/assets/64700072-a087-4206-8b52-212ecfea668d)
146146

147-
### Where do these binaries come from? ![pin](https://raw.githubusercontent.com/xplshn/dbin/master/misc/assets/pin.svg)
148-
- [AppBundleHub](https://github.com/xplshn/AppBundleHUB)
149-
- [PkgForge's repos](https://docs.pkgforge.dev/repositories)
150-
- Note however that pkgforge also has dynamic (unportable) programs/packages (that only run on Debian & derivatives), `dbin` filters these out, leaving behind only the static/portable programs.
147+
###### dbin uses a format for defining the repository index file that is derived from the endpoints provided by Pkgforge. During this step, we remove unportable programs and re-order variants based on their ID (smaller binaries are prioritized)
148+
149+
`dbin` is a package manager, which can use any repos. But it comes with a strong default selection by default.
151150

152151
> Hmm, can I add my own repos?
153152
@@ -195,9 +194,31 @@ NOTE: Not all fields are essential :)
195194

196195
A schema of the metadata format can be found here [/misc/cmd/dbinRepoIndexGenerators/*/generator.go](https://github.com/xplshn/dbin/tree/master/misc/cmd/dbinRepoIndexGenerators)
197196

198-
## Repositories you can optionally enable/add to your config ![pin](https://raw.githubusercontent.com/xplshn/dbin/master/misc/assets/pin.svg)
199-
- `https://github.com/xplshn/dbin-metadata/raw/refs/heads/master/misc/cmd/1.5/AM_amd64_linux.lite.cbor.zst`
200-
- The binaries in this repository come from the AM package manager, they aren't guaranteed to work everywhere, unlike the binaries in the official repos. But a lot of these are useful and do work. I recommend you check it out
197+
# Acknowledgements
198+
199+
### Default repos ![pin](https://raw.githubusercontent.com/xplshn/dbin/master/misc/assets/pin.svg)
200+
- [PkgForge's repos](https://docs.pkgforge.dev/repositories): Portable programs that are truly static, or otherwise self-contained using a wrapper format
201+
![pkgforge_repo](https://raw.githubusercontent.com/xplshn/dbin/master/misc/assets/pkgforge.svg)
202+
- <!-- PKGFORGE_COUNT -->
203+
- Note however that pkgforge also has dynamic (unportable) programs/packages (that only run on Debian & derivatives), `dbin` filters these out, leaving behind only the static/portable programs.
204+
- [AppBundleHub](https://github.com/xplshn/AppBundleHUB): Portable programs in .AppBundle format
205+
- <!-- APPBUNDLEHUB_COUNT -->
206+
207+
## Optional repos
208+
- [AM repo](https://github.com/ivan-hc/am): `https://github.com/xplshn/dbin-metadata/raw/refs/heads/master/misc/cmd/1.5/AM_amd64_linux.lite.cbor.zst`
209+
- Note that the binaries in this repository come from the AM package manager, they aren't guaranteed to work everywhere, unlike the binaries in the default repos. But a lot of these are useful and do work even on Musl systems. I recommend you check it out
210+
- <!-- AM_COUNT -->
211+
- URL: `https://d.xplshn.com.ar/misc/cmd/1.5/AM_amd64_linux.lite.cbor.zst`
212+
213+
- [PkgForge Go repo](https://github.com/ivan-hc/am): `https://github.com/xplshn/dbin-metadata/raw/refs/heads/master/misc/cmd/1.5/pkgforge-go_amd64_linux.lite.cbor.zst`
214+
- The binaries in this repo are Go projects that have been fetched, filtered and built automagically
215+
- <!-- GO_COUNT -->
216+
- URL: `https://d.xplshn.com.ar/misc/cmd/1.5/pkgforge-go_amd64_linux.lite.cbor.zst`
217+
218+
- [PkgForge Cargo repo](https://github.com/ivan-hc/am): `https://github.com/xplshn/dbin-metadata/raw/refs/heads/master/misc/cmd/1.5/pkgforge-cargo_amd64_linux.lite.cbor.zst`
219+
- The binaries in this repo are Rust projects that have been fetched, filtered and built automagically
220+
- <!-- CARGO_COUNT -->
221+
- URL: `https://d.xplshn.com.ar/misc/cmd/1.5/pkgforge-cargo_amd64_linux.lite.cbor.zst`
201222

202223
### Libraries
203224
I am using these libraries for `dbin`:

config.go

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
errConfigFileAccess = errs.Class("config file access error")
2424
errCommandExecution = errs.Class("command execution error")
2525
errSplitArgs = errs.Class("split args error")
26+
arch = runtime.GOARCH + "_" + runtime.GOOS
2627
)
2728

2829
type repository struct {
@@ -36,6 +37,8 @@ type config struct {
3637
Repositories []repository `yaml:"Repositories" env:"DBIN_REPO_URLS" description:"List of repositories to fetch binaries from."`
3738
InstallDir string `yaml:"InstallDir" env:"DBIN_INSTALL_DIR XDG_BIN_HOME" description:"Directory where binaries will be installed."`
3839
CacheDir string `yaml:"CacheDir" env:"DBIN_CACHE_DIR" description:"Directory where cached binaries will be stored."`
40+
LicenseDir string `yaml:"LicenseDir" env:"DBIN_LICENSE_DIR" description:"Directory where license files will be stored."`
41+
CreateLicenses bool `yaml:"CreateLicenses" env:"DBIN_CREATE_LICENSES" description:"Enable saving of license files from OCI downloads."`
3942
Limit uint `yaml:"SearchResultsLimit" description:"Limit the number of search results displayed."`
4043
ProgressbarStyle int `yaml:"PbarStyle,omitempty" description:"Style of the progress bar."`
4144
DisableTruncation bool `yaml:"Truncation" env:"DBIN_NOTRUNCATION" description:"Disable truncation of output."`
@@ -75,13 +78,20 @@ func configCommand() *cli.Command {
7578
},
7679
Action: func(_ context.Context, c *cli.Command) error {
7780
if c.Bool("new") {
78-
return createDefaultConfig()
81+
configFilePath := os.Getenv("DBIN_CONFIG_FILE")
82+
if configFilePath == "" {
83+
userConfigDir, err := os.UserConfigDir()
84+
if err != nil {
85+
return errConfigFileAccess.Wrap(err)
86+
}
87+
configFilePath = filepath.Join(userConfigDir, "dbin", "dbin.yaml")
88+
}
89+
return createDefaultConfigAt(configFilePath)
7990
} else if c.Bool("show") {
8091
config, err := loadConfig()
8192
if err != nil {
8293
return errConfigLoad.Wrap(err)
8394
}
84-
8595
printConfig(config)
8696
return nil
8797
}
@@ -95,7 +105,7 @@ func printConfig(config *config) {
95105
v := reflect.ValueOf(config).Elem()
96106
t := v.Type()
97107

98-
for i := range v.NumField() {
108+
for i := 0; i < v.NumField(); i++ {
99109
field := v.Field(i)
100110
fieldType := t.Field(i)
101111
description := fieldType.Tag.Get("description")
@@ -145,18 +155,12 @@ func splitArgs(cmd string) ([]string, error) {
145155
return args, nil
146156
}
147157

148-
func executeHookCommand(config *config, cmdTemplate, bEntryPath, extension string, isIntegration bool) error {
149-
hookCommands, exists := config.Hooks.Commands[extension]
150-
if !exists {
151-
return errCommandExecution.New("no commands found for extension: %s", extension)
152-
}
153-
158+
func executeHookCommand(config *config, hookCommands *hookCommands, ext, bEntryPath string, isIntegration bool) error {
154159
if hookCommands.NoOp {
155160
return nil
156161
}
157162

158-
cmd := strings.ReplaceAll(cmdTemplate, "{{binary}}", bEntryPath)
159-
commandParts, err := splitArgs(cmd)
163+
commandParts, err := splitArgs(hookCommands.IntegrationCommand)
160164
if err != nil {
161165
return errCommandExecution.Wrap(err)
162166
}
@@ -172,10 +176,11 @@ func executeHookCommand(config *config, cmdTemplate, bEntryPath, extension strin
172176
env = append(env, fmt.Sprintf("DBIN_CACHE_DIR=%s", config.CacheDir))
173177
env = append(env, fmt.Sprintf("DBIN=%s", os.Args[0]))
174178
env = append(env, fmt.Sprintf("DBIN_HOOK_BINARY=%s", bEntryPath))
179+
env = append(env, fmt.Sprintf("DBIN_HOOK_BINARY_EXT=%s", ext))
175180
if isIntegration {
176-
env = append(env, "DBIN_HOOK_TYPE=integration")
181+
env = append(env, "DBIN_HOOK_TYPE=install")
177182
} else {
178-
env = append(env, "DBIN_HOOK_TYPE=deintegration")
183+
env = append(env, "DBIN_HOOK_TYPE=remove")
179184
}
180185

181186
if hookCommands.Silent {
@@ -212,7 +217,7 @@ func loadConfig() (*config, error) {
212217
if err != nil {
213218
return nil, errConfigFileAccess.Wrap(err)
214219
}
215-
configFilePath = filepath.Join(userConfigDir, "dbin.yaml")
220+
configFilePath = filepath.Join(userConfigDir, "dbin", "dbin.yaml")
216221
}
217222

218223
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
@@ -225,7 +230,6 @@ func loadConfig() (*config, error) {
225230
return nil, errConfigLoad.Wrap(err)
226231
}
227232

228-
arch := runtime.GOARCH + "_" + runtime.GOOS
229233
for v := version - 0.1; v >= version-0.3; v -= 0.1 {
230234
url := fmt.Sprintf("https://github.com/xplshn/dbin-metadata/raw/refs/heads/master/misc/cmd/%.1f/%s%s", v, arch, ".lite.cbor.zst")
231235
for _, repo := range cfg.Repositories {
@@ -260,7 +264,6 @@ func overrideWithEnv(cfg *config) {
260264
case reflect.String:
261265
field.SetString(value)
262266
case reflect.Slice:
263-
// Special handling for []Repository
264267
if field.Type() == reflect.TypeOf([]repository{}) {
265268
urls := strings.Split(value, ",")
266269
var repos []repository
@@ -292,7 +295,7 @@ func overrideWithEnv(cfg *config) {
292295
return false
293296
}
294297

295-
for i := range v.NumField() {
298+
for i := 0; i < v.NumField(); i++ {
296299
field := v.Field(i)
297300
envTags := strings.Fields(t.Field(i).Tag.Get("env"))
298301

@@ -315,7 +318,14 @@ func setDefaultValues(config *config) {
315318
return
316319
}
317320
config.CacheDir = filepath.Join(tempDir, "dbin_cache")
318-
arch := runtime.GOARCH + "_" + runtime.GOOS
321+
322+
userConfigDir, err := os.UserConfigDir()
323+
if err != nil {
324+
fmt.Printf("failed to get user's Config directory: %v\n", err)
325+
return
326+
}
327+
config.LicenseDir = filepath.Join(userConfigDir, "dbin", "licenses")
328+
config.CreateLicenses = true
319329

320330
config.Repositories = []repository{
321331
{
@@ -329,34 +339,22 @@ func setDefaultValues(config *config) {
329339
}
330340

331341
config.DisableTruncation = false
332-
config.Limit = 90
342+
config.Limit = 9999
333343
config.UseIntegrationHooks = true
334344
config.RetakeOwnership = false
335345
config.ProgressbarStyle = 1
336346
config.DisableProgressbar = false
337347
config.NoConfig = false
338348
}
339349

340-
func createDefaultConfig() error {
341-
configFilePath := os.Getenv("DBIN_CONFIG_FILE")
342-
if configFilePath == "" {
343-
userConfigDir, err := os.UserConfigDir()
344-
if err != nil {
345-
return errConfigFileAccess.Wrap(err)
346-
}
347-
configFilePath = filepath.Join(userConfigDir, "dbin.yaml")
348-
}
349-
return createDefaultConfigAt(configFilePath)
350-
}
351-
352350
func createDefaultConfigAt(configFilePath string) error {
353351
cfg := config{}
354352
setDefaultValues(&cfg)
355353
overrideWithEnv(&cfg)
356354

357355
cfg.Hooks = hooks{
358356
Commands: map[string]hookCommands{
359-
"": {
357+
"*": {
360358
IntegrationCommand: "sh -c \"$DBIN info > ${DBIN_CACHE_DIR}/.info\"",
361359
DeintegrationCommand: "sh -c \"$DBIN info > ${DBIN_CACHE_DIR}/.info\"",
362360
UseRunFromCache: true,

0 commit comments

Comments
 (0)