Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement gui #5

Merged
merged 11 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions build-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

if [ ! -f "/.dockerenv" ]; then
docker pull golang:latest && docker run -ti --rm -v "${PWD}":"${PWD}" --workdir "${PWD}" golang:latest
fi;

apt-get update &&
apt-get install -yqq \
libx11-dev \
libxcursor-dev \
libxrandr-dev \
libxinerama-dev \
libxi-dev \
libglx-dev \
libgl-dev \
libxxf86vm-dev &&

go build -v -ldflags "-s -w -X 'main.version=0.0.0' -X 'main.commit=dev' -X 'main.date=$(date '+%Y-%m-%d %H:%M:%S')' -X 'main.builtBy=manual'" .

exit ${?}

# GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=amd64-linux-gnu-gcc CXX=amd64-linux-gnu-g++ HOST=amd64-linux-gnu go build -v
# x86_64-pc-linux-gcc
17 changes: 13 additions & 4 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import (
)

var (
app = kingpin.New("sdpud", "Updates GE-Proton on the Steam Deck in the background").Author("intrand")
cmd_version = app.Command("version", "Prints version and exits")
cmd_install = app.Command("install", "Installs the latest release of GE-Proton")
cmd_prune = app.Command("prune", "Removes versions older than latest from this machine")
app = kingpin.New("Steam Deck GE-Proton Updater", "Automatically updates GE-Proton on the Steam Deck in the background").Author("intrand")

cmd_gui = app.Command("gui", "opens the graphical user interface of this tool").Hidden().Default()

// tool commands
cmd_version = app.Command("version", "Prints version and exits")
cmd_install = app.Command("install", "Performs installation of sd-ge-proton-updater, and set it to run automatically on Steam Deck boot")
cmd_uninstall = app.Command("uninstall", "Removes sd-ge-proton-updater from your Steam Deck")
cmd_update = app.Command("update", "Updates sd-ge-proton-updater to the latest stable release on GitHub")

// ge-proton commands
cmd_get = app.Command("get", "Gets the latest release of GE-Proton")
cmd_prune = app.Command("prune", "Removes chosen GE-Proton versions from your Steam Deck")
)
161 changes: 161 additions & 0 deletions get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package main

import (
"context"
"errors"
"log"
"path/filepath"
"strings"

"github.com/google/go-github/v47/github"
)

// split [https://|http://|git://]github.com/owner/repo[.git]/... into owner, repo
func splitGithubUrl(url string) (owner string, repo string, err error) {
str := url
str = strings.TrimPrefix(str, "https://")
str = strings.TrimPrefix(str, "http://")
str = strings.TrimPrefix(str, "git://")

if strings.HasPrefix(str, "github.com/") {
str = strings.TrimPrefix(str, "github.com/")
} else {
err = errors.New("not a github url")
return
}

fields := strings.Split(str, "/")
if len(fields) < 2 {
err = errors.New("invalid format for github")
return
}

owner = fields[0]
repo = strings.TrimRight(fields[1], ".git")

return
}

func getGithubClient() (client *github.Client, org string, repo string, err error) {
client = github.NewClient(nil)

org, repo, err = splitGithubUrl(protonGeUrl)
if err != nil {
return client, org, repo, err
}

return client, org, repo, err
}

func getLatestReleases(ctx context.Context) (releases []*github.RepositoryRelease, err error) {
client := github.NewClient(nil)

org, repo, err := splitGithubUrl(protonGeUrl)
if err != nil {
return releases, err
}

allReleases, _, err := client.Repositories.ListReleases(ctx, org, repo, nil)
if err != nil {
return releases, err
}

if len(allReleases) < 1 {
return releases, errors.New("no releases found")
}

var stableReleases []*github.RepositoryRelease
for _, unfilteredRelease := range allReleases {
if *unfilteredRelease.Prerelease { // omit pre-releases
continue
}
if *unfilteredRelease.Draft { // omit drafts
continue
}
stableReleases = append(stableReleases, unfilteredRelease)
}

if len(stableReleases) < 2 {
return releases, errors.New("not enough stable releases found (possibly 0)")
}

releases = []*github.RepositoryRelease{
stableReleases[0],
stableReleases[1],
}

return releases, err
}

func get() (err error) {
ctx := context.Background() // create context
releases, err := getLatestReleases(ctx) // get latest stable releases
if err != nil {
return err
}

latestRelease := releases[0]
// latestMinusOneRelease := releases[1]

latestPath := filepath.Join(protonPath, *latestRelease.TagName)

exist, err := exists(latestPath)
if err != nil {
return err
}

if exist {
log.Println("Release " + *latestRelease.TagName + " already exists on this console. Nothing to do. Exiting.")
return err
} // end exists

var shaAsset *github.ReleaseAsset
var tarballAsset *github.ReleaseAsset
for _, asset := range latestRelease.Assets {
if strings.Contains(*asset.Name, ".sha512sum") {
shaAsset = asset
}
if strings.Contains(*asset.Name, ".tar.gz") {
tarballAsset = asset
}
} // end list of assets

var naked *github.ReleaseAsset
if shaAsset == naked || tarballAsset == naked { // check we got data for both
return errors.New("couldn't get enough info about releases. Did something change?")
}

dir, err := mkTempDir(*latestRelease.TagName)
if err != nil {
return err
}

var shaPath string = filepath.Join(dir, *shaAsset.Name)
var tarballPath string = filepath.Join(dir, *tarballAsset.Name)

// download SHA-512 checksum
err = downloadAsset(ctx, shaAsset, shaPath)
if err != nil {
return err
}

// download GE-Proton tarball distribution
err = downloadAsset(ctx, tarballAsset, tarballPath)
if err != nil {
return err
}

// verify SHA of tarball against SHA-512 checksum file (which is not signed!)
err = verifySha(shaPath, tarballPath)
if err != nil {
return err
}

err = installTarGzAsset(tarballPath, protonPath)
if err != nil {
return err
}

log.Println("Successfully installed: " + *latestRelease.TagName)
return err
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/AllenDang/giu v0.6.2
github.com/blang/semver v3.5.1+incompatible
github.com/google/go-github/v47 v47.0.0
github.com/google/go-github/v47 v47.1.0
github.com/rhysd/go-github-selfupdate v1.2.3
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
Expand All @@ -27,11 +27,11 @@ require (
github.com/stretchr/testify v1.8.0 // indirect
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/net v0.0.0-20220921203646-d300de134e69 // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/eapache/queue.v1 v1.1.0 // indirect
Expand Down
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG16L+Oo=
github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8=
github.com/google/go-github/v47 v47.0.0 h1:eQap5bIRZibukP0VhngWgpuM0zhY4xntqOzn6DhdkE4=
github.com/google/go-github/v47 v47.0.0/go.mod h1:DRjdvizXE876j0YOZwInB1ESpOcU/xFBClNiQLSdorE=
github.com/google/go-github/v47 v47.1.0 h1:Cacm/WxQBOa9lF0FT0EMjZ2BWMetQ1TQfyurn4yF1z8=
github.com/google/go-github/v47 v47.1.0/go.mod h1:VPZBXNbFSJGjyjFRUKo9vZGawTajnWzC/YjGw/oFKi0=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
Expand Down Expand Up @@ -69,17 +69,17 @@ github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 h1:a5Yg6ylndHHYJqIPrdq0AhvR6KTvDTAvgBtaidhEevY=
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY=
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220921203646-d300de134e69 h1:hUJpGDpnfwdJW8iNypFjmSY0sCBEL+spFTZ2eO+Sfps=
golang.org/x/net v0.0.0-20220921203646-d300de134e69/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 h1:lxqLZaMad/dJHMFZH0NiNpiEZI/nhgWhe4wgzpE+MuA=
Expand All @@ -89,8 +89,8 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down
Loading