package manager repository? or other form of updator tool
Merith-TK opened this issue · comments
If you could provide a repo for us to use (even on aur for the archwsl users such as myself) that would be great. i could try and write an simple updater in go that checks the hash of the current kernel and the hash of the latest git release if that would be helpful
Unfortunately, I do not really have the time to do something like this but if you would like to do it yourself, by all means :)
The GitHub releases make doing something like this very programmatic, I wrote a small updater function for my laptop:
https://github.com/nathanchance/scripts/blob/36f999e86d98aaddb4972c663cdc703aa1507467/env/wsl#L258
https://github.com/nathanchance/scripts/blob/36f999e86d98aaddb4972c663cdc703aa1507467/common#L213
Made one that works for windows
only requirement is you have to have your .wslconfig
file look here for the image C:\\users\\<you>\\.vmlinux
package main
import (
"crypto/md5"
"encoding/json"
"io"
"log"
"net/http"
"os"
"os/user"
"time"
"github.com/gen2brain/dlgs"
)
var (
rel = release{}
)
// Please go to line 93 for main fuction
type release struct {
URL string `json:"url"`
AssetsURL string `json:"assets_url"`
UploadURL string `json:"upload_url"`
HTMLURL string `json:"html_url"`
ID int `json:"id"`
NodeID string `json:"node_id"`
TagName string `json:"tag_name"`
TargetCommitish string `json:"target_commitish"`
Name string `json:"name"`
Draft bool `json:"draft"`
Author struct {
Login string `json:"login"`
ID int `json:"id"`
NodeID string `json:"node_id"`
AvatarURL string `json:"avatar_url"`
GravatarID string `json:"gravatar_id"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
FollowersURL string `json:"followers_url"`
FollowingURL string `json:"following_url"`
GistsURL string `json:"gists_url"`
StarredURL string `json:"starred_url"`
SubscriptionsURL string `json:"subscriptions_url"`
OrganizationsURL string `json:"organizations_url"`
ReposURL string `json:"repos_url"`
EventsURL string `json:"events_url"`
ReceivedEventsURL string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"author"`
Prerelease bool `json:"prerelease"`
CreatedAt time.Time `json:"created_at"`
PublishedAt time.Time `json:"published_at"`
Assets []struct {
URL string `json:"url"`
ID int `json:"id"`
NodeID string `json:"node_id"`
Name string `json:"name"`
Label string `json:"label"`
Uploader struct {
Login string `json:"login"`
ID int `json:"id"`
NodeID string `json:"node_id"`
AvatarURL string `json:"avatar_url"`
GravatarID string `json:"gravatar_id"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
FollowersURL string `json:"followers_url"`
FollowingURL string `json:"following_url"`
GistsURL string `json:"gists_url"`
StarredURL string `json:"starred_url"`
SubscriptionsURL string `json:"subscriptions_url"`
OrganizationsURL string `json:"organizations_url"`
ReposURL string `json:"repos_url"`
EventsURL string `json:"events_url"`
ReceivedEventsURL string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"uploader"`
ContentType string `json:"content_type"`
State string `json:"state"`
Size int `json:"size"`
DownloadCount int `json:"download_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
BrowserDownloadURL string `json:"browser_download_url"`
} `json:"assets"`
TarballURL string `json:"tarball_url"`
ZipballURL string `json:"zipball_url"`
Body string `json:"body"`
}
func main() {
r, err := http.Get("https://api.github.com/repos/nathanchance/WSL2-Linux-Kernel/releases/latest")
ifErr(err, 1, "Failed to GET json")
defer r.Body.Close()
err = json.NewDecoder(r.Body).Decode(&rel)
ifErr(err, 1, "Error decoding JSON")
for i := 0; i < len(rel.Assets); i++ {
blep := rel.Assets[i].Name
if blep == "bzImage" {
downloadFile(rel.Assets[i].BrowserDownloadURL, "bzimage")
}
}
check()
}
func downloadFile(url string, filename string) {
resp, err := http.Get(url)
ifErr(err, 2, "Failed to download File")
defer resp.Body.Close()
out, err := os.Create(os.TempDir() + "\\" + filename)
ifErr(err, 2, "Failed to create File")
defer out.Close()
_, err = io.Copy(out, resp.Body)
ifErr(err, 2, "Failed to write File")
}
func check() {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
local := checkFile(usr.HomeDir + "\\.vmlinux")
remote := checkFile(os.TempDir() + "\\bzImage")
if local != remote {
confirm, err := dlgs.Question("Update?", "You are not on the latest kernel update, would you like to update?", false)
ifErr(err, 5, "Failed to Install new Kernel")
if confirm == true {
err := os.Rename(os.TempDir()+"\\bzImage", usr.HomeDir+"\\.vmlinux")
ifErr(err, 5, "Failed to Install new Kernel")
dlgs.Warning("HEADS UP!", "Please put this in your .wslconfig file, \n ------ \n [wsl2] \n kernel=C:\\users\\<YOUR USERNAME>\\.vmlinux \n ------ \n And the run \"Restart-Service LxssManager\" in powershell as administrator to finnish installation")
}
} else {
dlgs.Info("SUCCESS", "You are at the latest release")
}
}
func checkFile(filename string) string {
if _, err := os.Stat(filename); os.IsNotExist(err) {
file, err := os.Create(filename)
ifErr(err, 5, "Failed to Create empty file")
file.Close()
}
f, err := os.Open(filename)
ifErr(err, 5, "Failed to open File")
defer f.Close()
h := md5.New()
_, err = io.Copy(h, f)
ifErr(err, 5, "Failed to Check md5sum")
return string(h.Sum(nil))
}
// How i am handling errors
func ifErr(err error, code int, msg string) {
if err != nil {
dlgs.Error("ERROR CODE"+string(code), msg)
os.Exit(code)
}
}
/*
Error codes
1: Related to json requests
2: Related to file requests
3:
4: Unknown
5: Related to local file system errors
*/
kernel-updater.zip
Now when you run it, it will seem like its doing nothing, what it is actually doing is downloading the latest release into your temp folder, and then it will give different popups, what one would expect is that "You are on the latest release", but if you are not, it will ask you if you want to install the latest release,
and then it will tell you what to do now, (set your config, restart LxssManager)
it checks if your on the latest release by comparing your local vmlinux md5sum. with the freshly downloaded md5sum
wow... thats alot of comits that reference this,
I am just seeing this now, but I wrote this for my own personal use a while ago. It is far from perfect, but maybe it will be helpful to someone.
I'm using Scoop. It's due to the custom Repo feature.
i use scoop as well,
Looks like there are plenty of solutions available, closing this up.