From bea1b8e6a823ff3b032f4b0efc5d2cf4ed65b1b5 Mon Sep 17 00:00:00 2001 From: Tiago Ilieve Date: Sat, 27 Nov 2021 10:07:37 -0300 Subject: [PATCH] Add 'upx' --- README.md | 2 +- main.go | 9 +++++++++ tables/arch.go | 6 ++++++ tables/os.go | 6 ++++++ tables/tables_test.go | 4 ++++ tables/tools.go | 1 + tables/url.go | 1 + tools/asset_test.go | 33 +++++++++++++++++++++++++++++++++ tools/tools.go | 6 ++++++ 9 files changed, 67 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fe83af..818715a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ staticd ======= -Download statically linked Go/Rust binaries from GitHub. +Download statically linked binaries from GitHub. diff --git a/main.go b/main.go index db818fd..de0f1d8 100644 --- a/main.go +++ b/main.go @@ -117,6 +117,14 @@ func main() { }, } + upxCmd := &cobra.Command{ + Use: tools.UPX, + Short: "The Ultimate Packer for eXecutables", + Run: func(cmd *cobra.Command, args []string) { + run(tools.UPX) + }, + } + xhCmd := &cobra.Command{ Use: tools.Xh, Short: "Friendly and fast tool for sending HTTP requests", @@ -138,6 +146,7 @@ func main() { rootCmd.AddCommand(cloudflaredCmd) rootCmd.AddCommand(dockerComposeCmd) rootCmd.AddCommand(k9sCmd) + rootCmd.AddCommand(upxCmd) rootCmd.AddCommand(xhCmd) rootCmd.AddCommand(versionCmd) diff --git a/tables/arch.go b/tables/arch.go index b44beae..f7dbf7d 100644 --- a/tables/arch.go +++ b/tables/arch.go @@ -43,6 +43,12 @@ var Arch = map[string]map[string]map[string]string{ "arm": "arm", }, }, + UPX: { + "linux": { + "amd64": "amd64", + "arm": "arm", + }, + }, Xh: { "darwin": { "amd64": "x86_64", diff --git a/tables/os.go b/tables/os.go index bc2fdd7..4233347 100644 --- a/tables/os.go +++ b/tables/os.go @@ -43,6 +43,12 @@ var OS = map[string]map[string]map[string]string{ "arm": "Linux", }, }, + UPX: { + "linux": { + "amd64": "linux", + "arm": "linux", + }, + }, Xh: { "darwin": { "amd64": "apple-darwin", diff --git a/tables/tables_test.go b/tables/tables_test.go index 1190f27..b7ae08c 100644 --- a/tables/tables_test.go +++ b/tables/tables_test.go @@ -42,6 +42,10 @@ func (s *TablesTestSuite) TestToolsNames() { local: tables.K9s, remote: tools.K9s, }, + { + local: tables.UPX, + remote: tools.UPX, + }, { local: tables.Xh, remote: tools.Xh, diff --git a/tables/tools.go b/tables/tools.go index afa1b51..875fc83 100644 --- a/tables/tools.go +++ b/tables/tools.go @@ -6,5 +6,6 @@ const ( Cloudflared = "cloudflared" DockerCompose = "docker-compose" K9s = "k9s" + UPX = "upx" Xh = "xh" ) diff --git a/tables/url.go b/tables/url.go index f694eac..2bd28f0 100644 --- a/tables/url.go +++ b/tables/url.go @@ -6,5 +6,6 @@ var URL = map[string]string{ Cloudflared: "https://github.com/cloudflare/cloudflared/releases", DockerCompose: "https://github.com/docker/compose/releases", K9s: "https://github.com/derailed/k9s/releases", + UPX: "https://github.com/upx/upx/releases", Xh: "https://github.com/ducaale/xh/releases", } diff --git a/tools/asset_test.go b/tools/asset_test.go index fdcfdd9..c9aff89 100644 --- a/tools/asset_test.go +++ b/tools/asset_test.go @@ -49,6 +49,12 @@ func (s *AssetTestSuite) TestDestination() { }, dest: "/usr/local/bin/k9s", }, + { + tool: &Tool{ + Name: UPX, + }, + dest: "/usr/local/bin/upx", + }, { tool: &Tool{ Name: Xh, @@ -124,6 +130,15 @@ func (s *AssetTestSuite) TestIsBinary() { os: "linux", binary: false, }, + { + tool: &Tool{ + Name: UPX, + Version: "v3.96", + }, + arch: "amd64", + os: "linux", + binary: false, + }, { tool: &Tool{ Name: Xh, @@ -194,6 +209,15 @@ func (s *AssetTestSuite) TestName() { os: "linux", name: "k9s_Linux_x86_64.tar.gz", }, + { + tool: &Tool{ + Name: UPX, + Version: "v3.96", + }, + arch: "amd64", + os: "linux", + name: "upx-3.96-amd64_linux.tar.xz", + }, { tool: &Tool{ Name: Xh, @@ -264,6 +288,15 @@ func (s *AssetTestSuite) TestWithinArchive() { os: "linux", withinArchive: "k9s", }, + { + tool: &Tool{ + Name: UPX, + Version: "v3.96", + }, + arch: "amd64", + os: "linux", + withinArchive: "upx-3.96-amd64_linux/upx", + }, { tool: &Tool{ Name: Xh, diff --git a/tools/tools.go b/tools/tools.go index 98e3024..d30b9ff 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -19,6 +19,7 @@ const ( Cloudflared = "cloudflared" DockerCompose = "docker-compose" K9s = "k9s" + UPX = "upx" Xh = "xh" ) @@ -150,6 +151,11 @@ func (t *Tool) SetAsset() error { t.Asset.IsBinary = true case K9s: t.Asset.Name = fmt.Sprintf("k9s_%v_%v.tar.gz", t.OS, t.Arch) + case UPX: + version := strings.TrimPrefix(t.Version, "v") + baseName := fmt.Sprintf("upx-%v-%v_%v", version, t.Arch, t.OS) + t.Asset.Name = baseName + ".tar.xz" + t.Asset.WithinArchive = path.Join(baseName, t.Name) case Xh: baseName := fmt.Sprintf("xh-%v-%v-%v", t.Version, t.Arch, t.OS) t.Asset.Name = baseName + ".tar.gz"