mirror of
https://github.com/go-i2p/go-i2pbrowser.git
synced 2025-06-17 06:35:40 -04:00
initialize
This commit is contained in:
14
embed.go
Normal file
14
embed.go
Normal file
@ -0,0 +1,14 @@
|
||||
//go:build !generate
|
||||
// +build !generate
|
||||
|
||||
package goi2pbrowser
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed i2p.firefox.base.profile.zip
|
||||
var baseProfile []byte
|
||||
|
||||
//go:embed i2p.firefox.usability.profile.zip
|
||||
var usabilityProfile []byte
|
||||
|
||||
//go:generate go run --tags=generate generate.go
|
80
generate.go
Normal file
80
generate.go
Normal file
@ -0,0 +1,80 @@
|
||||
//go:build generate
|
||||
// +build generate
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
var owner = "eyedeekay"
|
||||
var repo = "i2p.plugins.firefox"
|
||||
|
||||
func profileVersion() string {
|
||||
client := github.NewClient(nil)
|
||||
tags, _, err := client.Repositories.ListTags(context.Background(), owner, repo, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return "0.0.34"
|
||||
}
|
||||
if len(tags) > 0 {
|
||||
latestTag := tags[0]
|
||||
fmt.Printf("Latest tag '%s', (SHA-1: %s)\n", *latestTag.Name, *latestTag.Commit.SHA)
|
||||
return *latestTag.Name
|
||||
} else {
|
||||
fmt.Printf("No tags yet\n")
|
||||
}
|
||||
return "0.0.36"
|
||||
}
|
||||
|
||||
func DownloadURL(version, mode string) string {
|
||||
return "https://github.com/" + owner + "/" + repo + "/releases/download/" + version + "/i2p.firefox." + mode + ".profile.zip"
|
||||
}
|
||||
|
||||
// Downloads a file from a URL to path output. Outputs absolute path to download or an error
|
||||
func DownloadFile(URL, output string) (string, error) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
filePath := filepath.Join(wd, output)
|
||||
log.Println("Downloading:", URL, "to", filePath)
|
||||
resp, err := http.Get(URL)
|
||||
if err != nil {
|
||||
return filePath, err
|
||||
}
|
||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return filePath, err
|
||||
}
|
||||
err = ioutil.WriteFile(filePath, bodyBytes, 0644)
|
||||
if err != nil {
|
||||
return filePath, err
|
||||
}
|
||||
return filePath, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("Downloading profiles from upstream bundles")
|
||||
version := profileVersion()
|
||||
log.Println("Version is:", version)
|
||||
basePath, err := DownloadFile(DownloadURL(version, "base"), "i2p.firefox.base.profile.zip")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println("Downloaded:", basePath)
|
||||
usabilityPath, err := DownloadFile(DownloadURL(version, "usability"), "i2p.firefox.usability.profile.zip")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println("Downloaded:", usabilityPath)
|
||||
|
||||
}
|
12
go.mod
Normal file
12
go.mod
Normal file
@ -0,0 +1,12 @@
|
||||
module github.com/eyedeekay/go-i2pbrowser
|
||||
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/artdarek/go-unzip v1.0.0
|
||||
github.com/google/go-github v17.0.0+incompatible
|
||||
)
|
||||
|
||||
require github.com/google/go-querystring v1.1.0 // indirect
|
||||
|
||||
replace github.com/artdarek/go-unzip v1.0.0 => github.com/eyedeekay/go-unzip v0.0.0-20220914222511-f2936bba53c2
|
9
go.sum
Normal file
9
go.sum
Normal file
@ -0,0 +1,9 @@
|
||||
github.com/eyedeekay/go-unzip v0.0.0-20220914222511-f2936bba53c2 h1:2ugjFSEUAduRk1lp5dSw19771HTZL8e37QSXjiiC7P4=
|
||||
github.com/eyedeekay/go-unzip v0.0.0-20220914222511-f2936bba53c2/go.mod h1:LRwT8AnFFHRm/oj++niZMHsi3o4rNDr1lN61xwHgFgI=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
|
||||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
58
unembed.go
Normal file
58
unembed.go
Normal file
@ -0,0 +1,58 @@
|
||||
//go:build !generate
|
||||
// +build !generate
|
||||
|
||||
package goi2pbrowser
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/artdarek/go-unzip/pkg/unzip"
|
||||
)
|
||||
|
||||
func existsAlready(profileDir string) bool {
|
||||
if _, err := os.Stat(filepath.Join(profileDir, "user.js")); err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func UnpackBase(profileDir string) error {
|
||||
if existsAlready(profileDir) {
|
||||
log.Println(profileDir, "exists already")
|
||||
return nil
|
||||
}
|
||||
os.MkdirAll(filepath.Dir(profileDir), 0755)
|
||||
zipFile := filepath.Join(filepath.Dir(profileDir), "i2p.firefox.base.profile.zip")
|
||||
err := ioutil.WriteFile(zipFile, baseProfile, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uz := unzip.New()
|
||||
_, err = uz.Extract(zipFile, profileDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UnpackUsability(profileDir string) error {
|
||||
if existsAlready(profileDir) {
|
||||
log.Println(profileDir, "exists already")
|
||||
return nil
|
||||
}
|
||||
os.MkdirAll(filepath.Dir(profileDir), 0755)
|
||||
zipFile := filepath.Join(filepath.Dir(profileDir), "i2p.firefox.usability.profile.zip")
|
||||
err := ioutil.WriteFile(zipFile, usabilityProfile, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uz := unzip.New()
|
||||
_, err = uz.Extract(zipFile, profileDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
13
unembed_test.go
Normal file
13
unembed_test.go
Normal file
@ -0,0 +1,13 @@
|
||||
package goi2pbrowser
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUnEmbded(t *testing.T) {
|
||||
t.Log("testing base")
|
||||
UnpackBase("testing/Base")
|
||||
t.Log("testing usability")
|
||||
UnpackUsability("testing/Usability")
|
||||
|
||||
}
|
Reference in New Issue
Block a user