From 27d04c92dc3ee54fe867decc0fa542d757e369d9 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Fri, 15 Apr 2022 14:03:57 -0500 Subject: [PATCH 1/3] Added SquashfsReader() --- src/goappimage/appimage.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/goappimage/appimage.go b/src/goappimage/appimage.go index e497be9c..6344ce83 100644 --- a/src/goappimage/appimage.go +++ b/src/goappimage/appimage.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/CalebQ42/squashfs" "github.com/probonopd/go-appimage/internal/helpers" "gopkg.in/ini.v1" ) @@ -146,6 +147,24 @@ func (ai AppImage) determineImageType() int { return -1 } +//SquashfsReader allows direct access to an AppImage's squashfs. +func (ai AppImage) SquashfsReader() (*squashfs.Reader, error) { + if ai.imageType != 2 { + return nil, errors.New("not a type 2 appimage") + } + aiFil, err := os.Open(ai.Path) + if err != nil { + return nil, err + } + stat, _ := aiFil.Stat() + aiRdr := io.NewSectionReader(aiFil, ai.offset, stat.Size()-ai.offset) + squashRdr, err := squashfs.NewSquashfsReader(aiRdr) + if err != nil { + return nil, err + } + return squashRdr, nil +} + //Type is the type of the AppImage. Should be either 1 or 2. func (ai AppImage) Type() int { return ai.imageType From 559780debbe0c9d3c9373c480c880e8e159be52d Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Sun, 17 Apr 2022 01:29:08 -0500 Subject: [PATCH 2/3] Fixed #195 and #125 --- src/appimaged/desktop.go | 2 +- src/appimaged/prerequisites.go | 18 +++++++++--------- src/goappimage/appimage.go | 2 -- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/appimaged/desktop.go b/src/appimaged/desktop.go index bab03879..1b199ed4 100644 --- a/src/appimaged/desktop.go +++ b/src/appimaged/desktop.go @@ -95,7 +95,7 @@ func writeDesktopFile(ai AppImage) { time.Sleep(1 * time.Second) add := "" args, err := ai.Args() - if err == nil { + if err == nil && len(args) > 0 { add = " " + strings.Join(args, " ") } cfg.Section("Desktop Entry").Key("Exec").SetValue(arg0abs + " wrap \"" + ai.Path + "\"" + add) // Resolve to a full path diff --git a/src/appimaged/prerequisites.go b/src/appimaged/prerequisites.go index 761ff2b4..050991eb 100644 --- a/src/appimaged/prerequisites.go +++ b/src/appimaged/prerequisites.go @@ -207,16 +207,16 @@ func stopSystemdService(servicename string) { */ func exitIfBinfmtExists(path string) { - cmd := exec.Command("/bin/sh", "-c", "echo -1 | sudo tee "+path) - cmd.Run() - // if err != nil { - // helpers.PrintError("prerequisites: exitIfBinfmtExists", err) - // If these binfmts are not there, that is actually not an error and should not be reported as that - // } if _, err := os.Stat(path); err == nil { - log.Println("ERROR:", path, "exists. Please remove it by running") - println("echo -1 | sudo tee", path) - os.Exit(1) + //If path exists, try to get sudo and remove it. + cmd := exec.Command("/bin/sh", "-c", "echo -1 | sudo tee "+path) + cmd.Run() + if _, err := os.Stat(path); err == nil { + //It still exists, so we panic and quit. + log.Println("ERROR:", path, "exists. Please remove it by running") + println("echo -1 | sudo tee", path) + os.Exit(1) + } } } diff --git a/src/goappimage/appimage.go b/src/goappimage/appimage.go index 6344ce83..2677b7e9 100644 --- a/src/goappimage/appimage.go +++ b/src/goappimage/appimage.go @@ -4,7 +4,6 @@ import ( "bufio" "bytes" "errors" - "fmt" "io" "os" "os/exec" @@ -232,7 +231,6 @@ func (ai AppImage) Args() ([]string, error) { return nil, errors.New("desktop file wasn't parsed") } var exec = ai.Desktop.Section("Desktop Entry").Key("Exec").Value() - fmt.Println("exec:", exec) if exec == "" { return nil, errors.New("exec key not present") } From 7e0d206b7fdeaf711b093854fde6afc48bc06fa2 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Sun, 17 Apr 2022 01:31:28 -0500 Subject: [PATCH 3/3] Added more comments to SquashfsReader --- src/goappimage/appimage.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/goappimage/appimage.go b/src/goappimage/appimage.go index 2677b7e9..f2d8be82 100644 --- a/src/goappimage/appimage.go +++ b/src/goappimage/appimage.go @@ -147,6 +147,7 @@ func (ai AppImage) determineImageType() int { } //SquashfsReader allows direct access to an AppImage's squashfs. +//Only works on type 2 AppImages func (ai AppImage) SquashfsReader() (*squashfs.Reader, error) { if ai.imageType != 2 { return nil, errors.New("not a type 2 appimage")