Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
- Added LICENSE file
- Added more test coverage
- Fixed failing tests
- Various other improvements
- Added Go Report Badge
  • Loading branch information
Phillip Miller committed Oct 20, 2021
1 parent 532a4de commit 7e0effe
Show file tree
Hide file tree
Showing 19 changed files with 1,210 additions and 46 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Donate with Bitcoin](https://en.cryptobadges.io/badge/micro/3Cd54T1EB6WHRcechq1dRCGF6vY2HHhkdk)](https://en.cryptobadges.io/donate/3Cd54T1EB6WHRcechq1dRCGF6vY2HHhkdk)
[![Donate with Ethereum](https://en.cryptobadges.io/badge/micro/0x064AA753EF36e5641E2Ee3C9BbC117F6aFe35F62)](https://en.cryptobadges.io/donate/0x064AA753EF36e5641E2Ee3C9BbC117F6aFe35F62)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cffe102aadbd4f4394754f0c259cc527)](https://www.codacy.com/gh/mr-pmillz/pimp-my-shell/dashboard?utm_source=github.com&utm_medium=referral&utm_content=mr-pmillz/pimp-my-shell&utm_campaign=Badge_Grade)
[![Go Report Card](https://goreportcard.com/badge/github.com/mr-pmillz/pimp-my-shell)](https://goreportcard.com/report/github.com/mr-pmillz/pimp-my-shell)
![GitHub all releases](https://img.shields.io/github/downloads/mr-pmillz/pimp-my-shell/total?style=social)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/mr-pmillz/pimp-my-shell/CI?style=plastic)
![GitHub repo size](https://img.shields.io/github/repo-size/mr-pmillz/pimp-my-shell?style=plastic)
Expand Down
12 changes: 6 additions & 6 deletions extra/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func InstallExtraPackages(osType string, dirs *localio.Directories, packages *lo
if err := localio.BrewInstallProgram("gnu-sed", "gsed", packages); err != nil {
return err
}
// brew tap cjbassi/gotop
if err := localio.BrewTap("cjbassi/gotop", packages); err != nil {
return err
}
// install gotop
if err := localio.BrewInstallProgram("gotop", "gotop", packages); err != nil {
return err
Expand Down Expand Up @@ -98,12 +94,16 @@ func InstallExtraPackages(osType string, dirs *localio.Directories, packages *lo
}
// install gotop
if _, exists := localio.CommandExists("go"); exists {
if _, exists := localio.CommandExists("gotop"); !exists {
if err := localio.RunCommandPipeOutput("go get github.com/cjbassi/gotop"); err != nil {
if _, exists = localio.CommandExists("gotop"); !exists {
if err := localio.RunCommandPipeOutput("go install github.com/xxxserxxx/gotop/v4/cmd/gotop@latest"); err != nil {
return err
}
}
}
// ensure apt-transport-https is installed. Prevents apt-get error exit code 100
if err := localio.AptInstall(packages, "apt-transport-https"); err != nil {
return err
}
// install cowsay
if err := localio.AptInstall(packages, "cowsay", "bat"); err != nil {
return err
Expand Down
44 changes: 41 additions & 3 deletions extra/extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extra

import (
"pimp-my-shell/localio"
"runtime"
"testing"
)

Expand All @@ -10,6 +11,19 @@ func TestInstallExtraPackages(t *testing.T) {
if err != nil {
t.Errorf("failed to create Directories type: %v", err)
}
osType := runtime.GOOS
switch osType {
case "linux":
if err = localio.DownloadAndInstallLatestVersionOfGolang(dirs.HomeDir); err != nil {
t.Errorf("couldn't download and install golang: %v", err)
}
if err = localio.RunCommandPipeOutput("go version"); err != nil {
t.Errorf("couldn't get go version: %v", err)
}
default:
//DoNothing
}

type args struct {
osType string
dirs *localio.Directories
Expand All @@ -26,14 +40,38 @@ func TestInstallExtraPackages(t *testing.T) {
packages: &localio.InstalledPackages{
AptInstalledPackages: nil,
BrewInstalledPackages: &localio.BrewInstalled{
Names: []string{"bat", "lsd", "gnu-sed", "gotop", "yamllint", "git-delta"}, CaskFullNames: []string{"bat"}, Taps: []string{"homebrew/core", "cjbassi/gotop"},
Names: []string{"bat", "lsd", "gnu-sed", "gotop", "yamllint", "git-delta"}, CaskFullNames: []string{"gotop"}, Taps: []string{"homebrew/core", "cjbassi/gotop"},
},
}}, false},
{"Test InstallExtraPackages darwin lots of packages already installed 2", args{
osType: "darwin",
dirs: dirs,
packages: &localio.InstalledPackages{
AptInstalledPackages: nil,
BrewInstalledPackages: &localio.BrewInstalled{
Names: []string{"aom", "apr", "apr-util", "argon2", "aspell", "assimp", "autoconf", "bdw-gc", "binwalk", "boost", "brotli", "c-ares", "ca-certificates",
"cairo", "cheat", "cmake", "cointop", "coreutils", "cscope", "curl", "dbus", "deployer", "docbook", "docbook-xsl", "double-conversion", "exiftool",
"fontconfig", "freetds", "freetype", "fribidi", "gcc", "gd", "gdbm", "gdk-pixbuf", "gettext", "ghostscript", "git-quick-stats",
"github-markdown-toc", "glib", "gmp", "gnu-getopt", "gnu-sed", "gnupg", "gnutls", "gobject-introspection", "graphite2", "graphviz", "gts", "guile", "gulp-cli",
"harfbuzz", "helm", "htop", "hunspell", "icu4c", "ilmbase", "imagemagick", "imath", "iproute2mac", "ipython", "isl", "jansson", "jasper", "jbig2dec", "jemalloc",
"jpeg", "jq", "kind", "krb5", "lastpass-cli", "libarchive", "libassuan", "libb2", "libde265", "libev", "libevent", "libffi", "libgcrypt", "libgpg-error", "libheif",
"libidn", "libidn2", "libimagequant", "libksba", "liblqr", "libmaxminddb", "libmetalink", "libmpc", "libnghttp2", "libomp", "libpng", "libpq", "libproxy", "libpthread-stubs",
"libraqm", "librsvg", "libsmi", "libsodium", "libssh", "libssh2", "libtasn1", "libtiff", "libtool", "libunistring", "libusb", "libuv", "libx11", "libxau", "libxcb", "libxdmcp",
"libxext", "libxrender", "libyaml", "libzip", "little-cms2", "lnav", "lsd", "lua", "lz4", "lzo", "m4", "macvim", "md4c", "mpdecimal", "mpfr", "msodbcsql17", "mssql-tools", "mysql",
"ncurses", "neofetch", "netpbm", "nettle", "nghttp2", "nmap", "node", "npth", "nspr", "nss", "numpy", "oniguruma", "openblas", "openexr", "openjdk", "openjpeg", "openldap", "[email protected]",
"p11-kit", "p7zip", "packer", "pango", "pcre", "pcre2", "php", "[email protected]", "pillow", "pinentry", "pixman", "pkg-config", "poppler", "popt", "protobuf", "putty", "pyenv", "pyenv-virtualenv",
"[email protected]", "[email protected]", "[email protected]", "qt", "qt@5", "readline", "reattach-to-user-namespace", "rsync", "rtmpdump", "ruby", "screenresolution", "shared-mime-info", "shellcheck", "six",
"sqlite", "ssdeep", "swaks", "tcl-tk", "telnet", "terraform", "tidy-html5", "tmux", "tree", "unbound", "unixodbc", "unrar", "unzip", "utf8proc", "watch", "webp", "wget", "x265", "xmlto",
"xorgproto", "xxhash", "xz", "yamllint", "zeromq", "zstd"},
CaskFullNames: []string{"font-meslo-lg-nerd-font", "wireshark"},
Taps: []string{"hashicorp/tap", "homebrew/core", "microsoft/mssql-release"},
},
}}, false},
{"Test InstallExtraPackages Linux 2", args{
{"Test InstallExtraPackages Linux 3", args{
osType: "linux",
dirs: dirs,
packages: &localio.InstalledPackages{
AptInstalledPackages: &localio.AptInstalled{Name: []string{"bat", "lsd", "gotop", "delta"}},
AptInstalledPackages: &localio.AptInstalled{Name: []string{"bat", "lsd", "delta"}},
BrewInstalledPackages: nil,
}}, false},
}
Expand Down
12 changes: 1 addition & 11 deletions githubapi/githubapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/google/go-github/v39/github"
"github.com/klauspost/cpuid/v2"
)

// ReleaseAssets ...
Expand Down Expand Up @@ -68,16 +67,7 @@ func DownloadLatestRelease(osType string, dirs *localio.Directories, owner, repo
return "", err
}

var cpuType string
cpuid.Detect()
if cpuid.CPU.VendorID.String() == "AMD" || cpuid.CPU.VendorID.String() == "Intel" && cpuid.CPU.CacheLine == 64 {
cpuType = "AMD64"
} else if cpuid.CPU.VendorID.String() == "ARM" && cpuid.CPU.CacheLine == 64 {
cpuType = "ARM64"
} else {
cpuType = ""
}

cpuType := localio.GetCPUType()
switch osType {
case "darwin":
switch cpuType {
Expand Down
68 changes: 66 additions & 2 deletions localio/localio.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/klauspost/cpuid/v2"
"github.com/schollz/progressbar/v3"
"github.com/tidwall/gjson"
"io"
Expand All @@ -14,6 +15,7 @@ import (
"os"
"os/exec"
"os/user"
"path"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -128,6 +130,68 @@ func DownloadFile(dest, url string) error {
return err
}

// GetCPUType Returns the CPU type for the current runtime environment
func GetCPUType() string {
cpuid.Detect()
if cpuid.CPU.VendorID.String() == "AMD" || cpuid.CPU.VendorID.String() == "Intel" && cpuid.CPU.CacheLine == 64 {
return "AMD64"
} else if cpuid.CPU.VendorID.String() == "ARM" && cpuid.CPU.CacheLine == 64 {
return "ARM64"
} else {
return ""
}
}

// DownloadAndInstallLatestVersionOfGolang Only for linux x86_64. Mac uses homebrew
func DownloadAndInstallLatestVersionOfGolang(homeDir string) error {
if !CorrectOS("linux") {
return nil
}
req, err := http.NewRequest("GET", "https://golang.org/VERSION?m=text", nil)
if err != nil {
return err
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
goversion, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
latestGoVersion := string(goversion)

switch GetCPUType() {
case "AMD64":
armGoURL := fmt.Sprintf("https://dl.google.com/go/%s.linux-arm64.tar.gz", latestGoVersion)
dest := fmt.Sprintf("%s/%s", homeDir, path.Base(armGoURL))
if err = DownloadFile(dest, armGoURL); err != nil {
return err
}
// // Now extract the go binary. pimp-my-shell ensures that ~/.zshrc will already have the path setup for you
if err = RunCommandPipeOutput(fmt.Sprintf("sudo rm -rf /usr/local/go && tar -C /usr/local -xzf %s || true", dest)); err != nil {
return err
}

case "ARM64":
amdGoURL := fmt.Sprintf("https://dl.google.com/go/%s.linux-amd64.tar.gz", latestGoVersion)
dest := fmt.Sprintf("%s/%s", homeDir, path.Base(amdGoURL))
if err = DownloadFile(dest, amdGoURL); err != nil {
return err
}

if err = RunCommandPipeOutput(fmt.Sprintf("sudo rm -rf /usr/local/go && tar -C /usr/local -xzf %s || true", dest)); err != nil {
return err
}
default:
fmt.Println("[-] Couldn't download and install golang Unsupported CPU... Pimp-My-Shell only supports 64 bit")
}

return nil
}

// RunCommands ...
func RunCommands(cmds []string) error {
for _, c := range cmds {
Expand Down Expand Up @@ -194,7 +258,7 @@ func EmbedFileCopy(dst string, src fs.File) error {
return nil
}

// EmbedFileStringAppendToDest ...
// EmbedFileStringAppendToDest takes a slice of bytes and writes it as a string to dest file path
func EmbedFileStringAppendToDest(data []byte, dest string) error {
fmt.Printf("[+] Appending: \n%s\n -> %s\n", string(data), dest)
fileDest, err := ResolveAbsPath(dest)
Expand Down Expand Up @@ -324,7 +388,7 @@ func Contains(s []string, str string) bool {
return false
}

// CorrectOS ...
// CorrectOS ... Useful for go tests
func CorrectOS(osType string) bool {
operatingSystem := runtime.GOOS
if operatingSystem == osType {
Expand Down
Loading

0 comments on commit 7e0effe

Please sign in to comment.