Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
1.3 is out!
Browse files Browse the repository at this point in the history
1.3
  • Loading branch information
xplshn committed Feb 26, 2024
2 parents dd16e56 + 3dcb2d1 commit 9c1d7a1
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 78 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Unlike BDL which required either wget or curl, BigDL is suited for embedded syst
- `remove`: Say goodbye to programs you no longer need.
- `update`: Get new features. Update all, or a select list of programs in an instant.
- `run`: Execute programs instantly, without the hassle of installing.
- `info|fast_info`: Get detailed information about a specific program.
- `info`: Get detailed information about a specific program.
- `search`: Find the perfect program to suit your needs.
- `tldr`: Show a <abbr title="Details: its just an alias to 'bigdl run tlrc'">tldr</abbr> page (without installing any 'TLDR' client)


#### Usage:

```
$ Usage: bigdl [-vh] {list|install|remove|update|run|info|fast_info|search|tldr} [args...]
$ Usage: bigdl [-vh] {list|install|remove|update|run|info|search|tldr} [args...]
```

#### BDL Compatibility:
Expand Down
Binary file modified bigdl
Binary file not shown.
2 changes: 1 addition & 1 deletion findURL.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
)

// findURLCommand returns the URL for the specified binary.
// findURLCommand returns the URL for the specified binary. We do not use info.go for this because unmarshalling such big files is slower than pinging to see which exists
func findURLCommand(binaryName string) {
url, err := findURL(binaryName)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion fsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// fSearch searches for binaries based on the given search term.
func fSearch(searchTerm string, desiredArch string) {
func fSearch(searchTerm string) {
// Fetch metadata
response, err := http.Get(RMetadataURL)
if err != nil {
Expand Down
148 changes: 93 additions & 55 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
)

// BinaryInfo represents the structure of binary information.
// BinaryInfo represents the structure of binary information including description.
type BinaryInfo struct {
Name string `json:"Name"`
Description string `json:"Description"`
Expand All @@ -20,71 +20,109 @@ type BinaryInfo struct {
Source string `json:"Source"`
}

// BinaryMetadata represents the structure of the metadata for a binary.
type BinaryMetadata struct {
Binaries []BinaryInfo `json:"binaries"`
}

// getBinaryInfo fetches binary information from MetadataURLs and returns it as a BinaryInfo struct.
// getBinaryInfo fetches a binary's information from RNMetadataURL and RMetadataURL and returns it as a BinaryInfo struct.
func getBinaryInfo(binaryName string) (*BinaryInfo, error) {
for i, metadataURL := range MetadataURLs {
if i >= 2 { // TODO: Correctly unmarshal Github's REST API's "contents" endpoint. In order not to do this ugly thing.
break
}
response, err := http.Get(metadataURL)
if err != nil {
return nil, fmt.Errorf("error fetching metadata from %s: %v", metadataURL, err)
}
defer response.Body.Close()

body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("error reading metadata from %s: %v", metadataURL, err)
}

var metadata []BinaryInfo
if err := json.Unmarshal(body, &metadata); err != nil {
return nil, fmt.Errorf("error decoding metadata from %s: %v", metadataURL, err)
}
// Fetch a binary's details from RNMetadataURL
response, err := http.Get(RNMetadataURL)
if err != nil {
return nil, fmt.Errorf("error fetching metadata from %s: %v", RNMetadataURL, err)
}
defer response.Body.Close()

for _, bin := range metadata {
if bin.Name == binaryName {
// Fetch the description from RMetadataURL
response, err = http.Get(RMetadataURL)
if err != nil {
return nil, fmt.Errorf("error fetching description from %s: %v", RMetadataURL, err)
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("error reading metadata from %s: %v", RNMetadataURL, err)
}

body, err = ioutil.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("error reading description from %s: %v", RMetadataURL, err)
}
var metadata [][]map[string]interface{}
if err := json.Unmarshal(body, &metadata); err != nil {
return nil, fmt.Errorf("error decoding metadata from %s: %v", RNMetadataURL, err)
}

// Unmarshal the description as a map with a slice of BinaryInfo objects
var descriptionMetadata map[string][]BinaryInfo
if err := json.Unmarshal(body, &descriptionMetadata); err != nil {
return nil, fmt.Errorf("error decoding description from %s: %v", RMetadataURL, err)
}
var binInfo BinaryInfo
var found bool

// TODO: Once Github repos are supported, optionally detect METADATA.json files in the repos.
binaries, exists := descriptionMetadata["packages"]
if !exists {
return nil, fmt.Errorf("invalid description metadata format. No 'packages' field found.")
for _, hostInfoArray := range metadata {
for _, hostInfo := range hostInfoArray {
if hostInfo["host"].(string) == validatedArch[2] {
mainBins, ok := hostInfo["Main"].([]interface{})
if !ok {
return nil, fmt.Errorf("error decoding Main field from %s: %v", RNMetadataURL, err)
}

// Find the binary with the matching name and set its description
for _, binInfo := range binaries {
if binInfo.Name == binaryName {
bin.Description = binInfo.Description
for _, bin := range mainBins {
binMap, ok := bin.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("error decoding binary details from %s: %v", RNMetadataURL, err)
}
if binMap["Name"].(string) == binaryName {
binInfo = BinaryInfo{
Name: binMap["Name"].(string),
Size: binMap["Size"].(string),
ModTime: binMap["ModTime"].(string),
Source: binMap["Source"].(string),
B3SUM: binMap["B3SUM"].(string),
SHA256: binMap["SHA256"].(string),
Repo: binMap["Repo"].(string),
}
found = true
break
}
}

return &bin, nil
if found {
break
}
}
}
if found {
break
}
}

if !found {
return nil, fmt.Errorf("info for the requested binary ('%s') not found in the metadata.json file for architecture '%s'", binaryName, validatedArch[2])
}

// Fetch binary description from RMetadataURL
response, err = http.Get(RMetadataURL)
if err != nil {
return nil, fmt.Errorf("error fetching description from %s: %v", RMetadataURL, err)
}
defer response.Body.Close()

body, err = ioutil.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("error reading description from %s: %v", RMetadataURL, err)
}

var descriptionMetadata map[string][]BinaryInfo
if err := json.Unmarshal(body, &descriptionMetadata); err != nil {
return nil, fmt.Errorf("error decoding description from %s: %v", RMetadataURL, err)
}

binaries, exists := descriptionMetadata["packages"]
if !exists {
return nil, fmt.Errorf("invalid description metadata format. No 'packages' field found.")
}

var description string
for _, binInfo := range binaries {
if binInfo.Name == binaryName {
description = binInfo.Description
break
}
}

// Combine the technical details and description into a single BinaryInfo struct
combinedInfo := BinaryInfo{
Name: binInfo.Name,
Description: description,
Repo: binInfo.Repo,
ModTime: binInfo.ModTime,
Size: binInfo.Size,
SHA256: binInfo.SHA256,
B3SUM: binInfo.B3SUM,
Source: binInfo.Source,
}

return nil, fmt.Errorf("info for the requested binary ('%s') not found in the metadata.json files", binaryName)
return &combinedInfo, nil
}
25 changes: 9 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Repositories []string
var MetadataURLs []string

// Array for storing a variable that fsearch and info use.
var validatedArch = [2]string{}
var validatedArch = [3]string{}

func init() {
switch runtime.GOARCH {
Expand All @@ -25,23 +25,24 @@ func init() {
MetadataURLs = append(MetadataURLs, "https://bin.ajam.dev/x86_64_Linux/METADATA.json")
MetadataURLs = append(MetadataURLs, "https://bin.ajam.dev/x86_64_Linux/Baseutils/METADATA.json")
MetadataURLs = append(MetadataURLs, "https://api.github.com/repos/xplshn/Handyscripts/contents")
validatedArch = [2]string{"x86_64_Linux", "x86_64"}
validatedArch = [3]string{"x86_64_Linux", "x86_64", "x86_64-Linux"}
case "arm64":
Repositories = append(Repositories, "https://bin.ajam.dev/aarch64_arm64_Linux/")
Repositories = append(Repositories, "https://raw.githubusercontent.com/xplshn/Handyscripts/master/")
Repositories = append(Repositories, "https://bin.ajam.dev/aarch64_arm64_Linux/Baseutils/")
MetadataURLs = append(MetadataURLs, "https://bin.ajam.dev/aarch64_arm64_Linux/METADATA.json")
MetadataURLs = append(MetadataURLs, "https://bin.ajam.dev/aarch64_arm64_Linux/Baseutils/METADATA.json")
MetadataURLs = append(MetadataURLs, "https://api.github.com/repos/xplshn/Handyscripts/contents")
validatedArch = [2]string{"aarch64_arm64_Linux", "aarch64_arm64"}
validatedArch = [3]string{"aarch64_arm64_Linux", "aarch64_arm64", "aarch64-Linux"}
default:
fmt.Println("Unsupported architecture:", runtime.GOARCH)
os.Exit(1)
}
}

const RMetadataURL = "https://raw.githubusercontent.com/Azathothas/Toolpacks/main/metadata.json"
const VERSION = "1.2"
const RNMetadataURL = "https://bin.ajam.dev/METADATA.json"
const VERSION = "1.3"

///// YOU MAY CHANGE THESE TO POINT TO ANOTHER PLACE.

Expand All @@ -50,11 +51,11 @@ const (
MaxCacheSize = 10
BinariesToDelete = 5
// TMPDIR is the directory for storing temporary files.
TEMP_DIR = "/tmp/bigdl_cached"
TEMP_DIR = "/tmp/bigdl_cached" // TODO: Don't hardcode this value.
)

func printHelp() {
fmt.Println("Usage: bigdl [-vh] {list|install|remove|update|run|info|fast_info|search|tldr} [args...]")
fmt.Println("Usage: bigdl [-vh] {list|install|remove|update|run|info|search|tldr} [args...]")
fmt.Println("\nOptions:")
fmt.Println(" -h, --help Show this help message")
fmt.Println(" -v, --version Show the version number")
Expand All @@ -65,7 +66,6 @@ func printHelp() {
fmt.Println(" update Update binaries, by checking their SHA against the repo's SHA.")
fmt.Println(" run Run a binary")
fmt.Println(" info Show information about a specific binary")
fmt.Println(" fast_info Show information about a specific binary - Using a single metadata file")
fmt.Println(" search Search for a binary - (not all binaries have metadata. Use list to see all binaries)")
fmt.Println(" tldr Show a brief description & usage examples for a given program/command")
fmt.Println("\nExamples:")
Expand Down Expand Up @@ -95,7 +95,7 @@ func main() {

// If no arguments are received, show the usage text
if len(os.Args) < 2 {
fmt.Println("Usage: bigdl [-vh] {list|install|remove|update|run|info|fast_info|search|tldr} [args...]")
fmt.Println("Usage: bigdl [-vh] {list|install|remove|update|run|info|search|tldr} [args...]")
os.Exit(1)
}

Expand Down Expand Up @@ -185,20 +185,13 @@ func main() {
if binaryInfo.Source != "" {
fmt.Printf("Source: %s\n", binaryInfo.Source)
}
case "fast_info":
if len(os.Args) != 3 {
fmt.Println("Usage: bigdl fast_info <binary>")
os.Exit(1)
}
binaryName := os.Args[2]
fast_showBinaryInfo(binaryName, validatedArch[1])
case "search":
if len(os.Args) != 3 {
fmt.Println("Usage: bigdl search <search-term>")
os.Exit(1)
}
searchTerm := os.Args[2]
fSearch(searchTerm, validatedArch[1])
fSearch(searchTerm)
case "update":
if len(os.Args) > 2 {
// Bulk update with list of programs to update
Expand Down
6 changes: 3 additions & 3 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func update(programsToUpdate []string) error {
localFilePath := filepath.Join(installDir, program)
_, err := os.Stat(localFilePath)
if os.IsNotExist(err) {
truncatePrintf("\033[2K\rWarning: Tried to update a non-existent program %s. %s\n", program, leftToGoStr)
truncatePrintf("\033[2K\rWarning: Tried to update a non-existent program %s. %s", program, leftToGoStr)
fmt.Printf("\n")
skipped++
continue
} else if err != nil {
Expand Down Expand Up @@ -117,8 +118,7 @@ func update(programsToUpdate []string) error {
}

// Print final counts
truncatePrintf("\033[2K\rSkipped: %d\tUpdated: %d\tChecked: %d\n", skipped, updated, checked)

fmt.Printf("\033[2K\rSkipped: %d\tUpdated: %d\tChecked: %d\n", skipped, updated, checked)
return nil
}

Expand Down

0 comments on commit 9c1d7a1

Please sign in to comment.