Cleanup: Add man workaround and remove termux releaser
This commit adds one workaround for an annoying issue with helpers/man
taking precedence over man(1).
And it removes the Termux postrel helper since termux-packages seems
to have automation in place that's faster than we need to be.
package main
import (
+ "fmt"
+ "io/fs"
"io/ioutil"
"os"
+ "os/exec"
+ "path/filepath"
"sort"
"strings"
"text/template"
@@ -22,6 +26,26 @@ import (
)
func main() {
+ // this is a workaround for the man helper getting accidentially
+ // installed into my $GOBIN dir and me not being able to figure out
+ // why. So instead of being greeted with an ugly panic message
+ // every now and then when I need to open a man page I decided
+ // to rather have a little bit of code to automate this away.
+ if len(os.Args) > 0 && os.Args[0] == "man" {
+ manPath, err := lookPath("man")
+ if err != nil {
+ panic(err)
+ }
+ cmd := exec.Command(manPath, os.Args[1:]...)
+ cmd.Stderr = os.Stderr
+ cmd.Stdin = os.Stdin
+ cmd.Stdout = os.Stdout
+ if err := cmd.Run(); err != nil {
+ os.Exit(cmd.ProcessState.ExitCode())
+ }
+ return
+ }
+
vs, err := ioutil.ReadFile("VERSION")
if err != nil {
panic(err)
@@ -97,6 +121,41 @@ type payload struct {
Flags []flag
}
+// from https://cs.opensource.google/go/go/+/refs/tags/go1.17.3:src/os/exec/lp_unix.go
+func lookPath(file string) (string, error) {
+ curPath, err := os.Executable()
+ if err != nil {
+ return "", err
+ }
+ path := os.Getenv("PATH")
+ for _, dir := range filepath.SplitList(path) {
+ if dir == "" {
+ // Unix shell semantics: path element "" means "."
+ dir = "."
+ }
+ path := filepath.Join(dir, file)
+ // do not call ourselves
+ if path == curPath {
+ continue
+ }
+ if err := findExecutable(path); err == nil {
+ return path, nil
+ }
+ }
+ return "", fmt.Errorf("%s: executable file not found in $PATH", file)
+}
+
+func findExecutable(file string) error {
+ d, err := os.Stat(file)
+ if err != nil {
+ return err
+ }
+ if m := d.Mode(); !m.IsDir() && m&0111 != 0 {
+ return nil
+ }
+ return fs.ErrPermission
+}
+
var manTpl = `
.TH GOPASS "{{ .SectionNumber }}" "{{ .DatePretty }}" "gopass (github.com/gopasspw/gopass) {{ .Version }}" "{{ .SectionName }}"
.SH NAME
