Make it launch I2P profiles too because why shouldn't it be cool like that
This commit is contained in:
168
get/get.go
168
get/get.go
@ -22,7 +22,7 @@ import (
|
||||
|
||||
var wd, _ = os.Getwd()
|
||||
|
||||
var UNPACK_URL = filepath.Join(wd, "unpack")
|
||||
var UNPACK_PATH = filepath.Join(wd, "unpack")
|
||||
var DOWNLOAD_PATH = filepath.Join(wd, "tor-browser")
|
||||
|
||||
const TOR_UPDATES_URL string = "https://aus1.torproject.org/torbrowser/update_3/release/downloads.json"
|
||||
@ -31,89 +31,103 @@ var (
|
||||
DefaultIETFLang, _ = jibber_jabber.DetectIETF()
|
||||
)
|
||||
|
||||
var OS, ARCH string
|
||||
type TBDownloader struct {
|
||||
UnpackPath string
|
||||
DownloadPath string
|
||||
Lang string
|
||||
OS, ARCH string
|
||||
}
|
||||
|
||||
func GetRuntimePair() string {
|
||||
if OS != "" && ARCH != "" {
|
||||
return fmt.Sprintf("%s%s", OS, ARCH)
|
||||
var OS = "linux"
|
||||
var ARCH = "64"
|
||||
|
||||
func NewTBDownloader(lang string, os, arch string) *TBDownloader {
|
||||
return &TBDownloader{
|
||||
Lang: lang,
|
||||
DownloadPath: DOWNLOAD_PATH,
|
||||
UnpackPath: UNPACK_PATH,
|
||||
OS: os,
|
||||
ARCH: arch,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TBDownloader) GetRuntimePair() string {
|
||||
if t.OS != "" && t.ARCH != "" {
|
||||
return fmt.Sprintf("%s%s", t.OS, t.ARCH)
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
OS = "osx"
|
||||
t.OS = "osx"
|
||||
case "linux":
|
||||
OS = "linux"
|
||||
t.OS = "linux"
|
||||
case "windows":
|
||||
OS = "win"
|
||||
t.OS = "win"
|
||||
default:
|
||||
OS = "unknown"
|
||||
t.OS = "unknown"
|
||||
}
|
||||
switch runtime.GOARCH {
|
||||
case "amd64":
|
||||
ARCH = "64"
|
||||
t.ARCH = "64"
|
||||
case "386":
|
||||
ARCH = "32"
|
||||
t.ARCH = "32"
|
||||
default:
|
||||
ARCH = "unknown"
|
||||
t.ARCH = "unknown"
|
||||
}
|
||||
return fmt.Sprintf("%s%s", OS, ARCH)
|
||||
return fmt.Sprintf("%s%s", t.OS, t.ARCH)
|
||||
}
|
||||
|
||||
func GetUpdater() (string, string, error) {
|
||||
return GetUpdaterForLang(DefaultIETFLang)
|
||||
func (t *TBDownloader) GetUpdater() (string, string, error) {
|
||||
return t.GetUpdaterForLang(t.Lang)
|
||||
}
|
||||
|
||||
func GetUpdaterForLang(ietf string) (string, string, error) {
|
||||
func (t *TBDownloader) GetUpdaterForLang(ietf string) (string, string, error) {
|
||||
jsonText, err := http.Get(TOR_UPDATES_URL)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("GetUpdaterForLang: %s", err)
|
||||
return "", "", fmt.Errorf("t.GetUpdaterForLang: %s", err)
|
||||
}
|
||||
defer jsonText.Body.Close()
|
||||
return GetUpdaterForLangFromJson(jsonText.Body, ietf)
|
||||
return t.GetUpdaterForLangFromJson(jsonText.Body, ietf)
|
||||
}
|
||||
|
||||
func GetUpdaterForLangFromJson(body io.ReadCloser, ietf string) (string, string, error) {
|
||||
func (t *TBDownloader) GetUpdaterForLangFromJson(body io.ReadCloser, ietf string) (string, string, error) {
|
||||
jsonBytes, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("GetUpdaterForLangFromJson: %s", err)
|
||||
return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err)
|
||||
}
|
||||
if err = ioutil.WriteFile(filepath.Join(DOWNLOAD_PATH, "downloads.json"), jsonBytes, 0644); err != nil {
|
||||
return "", "", fmt.Errorf("GetUpdaterForLangFromJson: %s", err)
|
||||
if err = ioutil.WriteFile(filepath.Join(t.DownloadPath, "downloads.json"), jsonBytes, 0644); err != nil {
|
||||
return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err)
|
||||
}
|
||||
return GetUpdaterForLangFromJsonBytes(jsonBytes, ietf)
|
||||
return t.GetUpdaterForLangFromJsonBytes(jsonBytes, ietf)
|
||||
}
|
||||
|
||||
func GetUpdaterForLangFromJsonBytes(jsonBytes []byte, ietf string) (string, string, error) {
|
||||
func (t *TBDownloader) GetUpdaterForLangFromJsonBytes(jsonBytes []byte, ietf string) (string, string, error) {
|
||||
var dat map[string]interface{}
|
||||
if err := json.Unmarshal(jsonBytes, &dat); err != nil {
|
||||
return "", "", fmt.Errorf("FuncName: %s", err)
|
||||
return "", "", fmt.Errorf("func (t *TBDownloader)Name: %s", err)
|
||||
}
|
||||
if platform, ok := dat["downloads"]; ok {
|
||||
rtp := GetRuntimePair()
|
||||
rtp := t.GetRuntimePair()
|
||||
if updater, ok := platform.(map[string]interface{})[rtp]; ok {
|
||||
if langUpdater, ok := updater.(map[string]interface{})[ietf]; ok {
|
||||
return langUpdater.(map[string]interface{})["binary"].(string), langUpdater.(map[string]interface{})["sig"].(string), nil
|
||||
} else {
|
||||
return "", "", fmt.Errorf("GetUpdaterForLangFromJsonBytes: no updater for language: %s", ietf)
|
||||
}
|
||||
// If we didn't find the language, try splitting at the hyphen
|
||||
lang := strings.Split(ietf, "-")[0]
|
||||
if langUpdater, ok := updater.(map[string]interface{})[lang]; ok {
|
||||
return langUpdater.(map[string]interface{})["binary"].(string), langUpdater.(map[string]interface{})["sig"].(string), nil
|
||||
} else {
|
||||
return "", "", fmt.Errorf("GetUpdaterForLangFromJsonBytes: no updater for fallback language %s", ietf)
|
||||
}
|
||||
// If we didn't find the language after splitting at the hyphen, try the default
|
||||
return GetUpdaterForLangFromJsonBytes(jsonBytes, DefaultIETFLang)
|
||||
return t.GetUpdaterForLangFromJsonBytes(jsonBytes, t.Lang)
|
||||
} else {
|
||||
return "", "", fmt.Errorf("GetUpdaterForLangFromJsonBytes: no updater for platform %s", rtp)
|
||||
return "", "", fmt.Errorf("t.GetUpdaterForLangFromJsonBytes: no updater for platform %s", rtp)
|
||||
}
|
||||
}
|
||||
return "", "", fmt.Errorf("GetUpdaterForLangFromJsonBytes: %s", ietf)
|
||||
return "", "", fmt.Errorf("t.GetUpdaterForLangFromJsonBytes: %s", ietf)
|
||||
}
|
||||
|
||||
func SingleFileDownload(url, name string) (string, error) {
|
||||
path := filepath.Join(DOWNLOAD_PATH, name)
|
||||
if !BotherToDownload(url, name) {
|
||||
func (t *TBDownloader) SingleFileDownload(url, name string) (string, error) {
|
||||
path := filepath.Join(t.DownloadPath, name)
|
||||
if !t.BotherToDownload(url, name) {
|
||||
fmt.Printf("No updates required, skipping download of %s\n", name)
|
||||
return path, nil
|
||||
}
|
||||
@ -136,13 +150,13 @@ func FileExists(path string) bool {
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
func BotherToDownload(url, name string) bool {
|
||||
path := filepath.Join(DOWNLOAD_PATH, name)
|
||||
func (t *TBDownloader) BotherToDownload(url, name string) bool {
|
||||
path := filepath.Join(t.DownloadPath, name)
|
||||
if !FileExists(path) {
|
||||
return true
|
||||
}
|
||||
defer ioutil.WriteFile(filepath.Join(DOWNLOAD_PATH, name+".last-url"), []byte(url), 0644)
|
||||
lastUrl, err := ioutil.ReadFile(filepath.Join(DOWNLOAD_PATH, name+".last-url"))
|
||||
defer ioutil.WriteFile(filepath.Join(t.DownloadPath, name+".last-url"), []byte(url), 0644)
|
||||
lastUrl, err := ioutil.ReadFile(filepath.Join(t.DownloadPath, name+".last-url"))
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
@ -152,7 +166,7 @@ func BotherToDownload(url, name string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func NamePerPlatform(ietf string) string {
|
||||
func (t *TBDownloader) NamePerPlatform(ietf string) string {
|
||||
extension := "tar.xz"
|
||||
windowsonly := ""
|
||||
switch runtime.GOOS {
|
||||
@ -162,78 +176,78 @@ func NamePerPlatform(ietf string) string {
|
||||
windowsonly = "-installer-"
|
||||
extension = "exe"
|
||||
}
|
||||
return fmt.Sprintf("torbrowser%s-%s-%s.%s", windowsonly, GetRuntimePair(), ietf, extension)
|
||||
return fmt.Sprintf("torbrowser%s-%s-%s.%s", windowsonly, t.GetRuntimePair(), ietf, extension)
|
||||
}
|
||||
|
||||
func DownloadUpdater() (string, string, error) {
|
||||
binary, sig, err := GetUpdater()
|
||||
func (t *TBDownloader) DownloadUpdater() (string, string, error) {
|
||||
binary, sig, err := t.GetUpdater()
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("DownloadUpdater: %s", err)
|
||||
}
|
||||
sigpath, err := SingleFileDownload(sig, NamePerPlatform(DefaultIETFLang)+".asc")
|
||||
sigpath, err := t.SingleFileDownload(sig, t.NamePerPlatform(t.Lang)+".asc")
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("DownloadUpdater: %s", err)
|
||||
}
|
||||
binpath, err := SingleFileDownload(binary, NamePerPlatform(DefaultIETFLang))
|
||||
binpath, err := t.SingleFileDownload(binary, t.NamePerPlatform(t.Lang))
|
||||
if err != nil {
|
||||
return "", sigpath, fmt.Errorf("DownloadUpdater: %s", err)
|
||||
}
|
||||
return binpath, sigpath, nil
|
||||
}
|
||||
|
||||
func DownloadUpdaterForLang(ietf string) (string, string, error) {
|
||||
binary, sig, err := GetUpdaterForLang(ietf)
|
||||
func (t *TBDownloader) DownloadUpdaterForLang(ietf string) (string, string, error) {
|
||||
binary, sig, err := t.GetUpdaterForLang(ietf)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("DownloadUpdaterForLang: %s", err)
|
||||
}
|
||||
|
||||
sigpath, err := SingleFileDownload(sig, NamePerPlatform(ietf)+".asc")
|
||||
sigpath, err := t.SingleFileDownload(sig, t.NamePerPlatform(ietf)+".asc")
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("DownloadUpdaterForLang: %s", err)
|
||||
}
|
||||
binpath, err := SingleFileDownload(binary, NamePerPlatform(ietf))
|
||||
binpath, err := t.SingleFileDownload(binary, t.NamePerPlatform(ietf))
|
||||
if err != nil {
|
||||
return "", sigpath, fmt.Errorf("DownloadUpdaterForLang: %s", err)
|
||||
}
|
||||
return binpath, sigpath, nil
|
||||
}
|
||||
|
||||
func UnpackUpdater(binpath string) error {
|
||||
if OS == "win" {
|
||||
cmd := exec.Command("cmd", "/c", "start", "\""+UNPACK_URL+"\"", "\""+binpath+" /SD /D="+UNPACK_URL+"\"")
|
||||
func (t *TBDownloader) UnpackUpdater(binpath string) (string, error) {
|
||||
if t.OS == "win" {
|
||||
cmd := exec.Command("cmd", "/c", "start", "\""+t.UnpackPath+"\"", "\""+binpath+" /SD /D="+t.UnpackPath+"\"")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("UnpackUpdater: windows exec fail %s", err)
|
||||
return "", fmt.Errorf("UnpackUpdater: windows exec fail %s", err)
|
||||
}
|
||||
}
|
||||
if OS == "osx" {
|
||||
cmd := exec.Command("open", "-W", "-n", "-a", "\""+UNPACK_URL+"\"", "\""+binpath+"\"")
|
||||
if t.OS == "osx" {
|
||||
cmd := exec.Command("open", "-W", "-n", "-a", "\""+t.UnpackPath+"\"", "\""+binpath+"\"")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("UnpackUpdater: osx open/mount fail %s", err)
|
||||
return "", fmt.Errorf("UnpackUpdater: osx open/mount fail %s", err)
|
||||
}
|
||||
}
|
||||
if FileExists(UNPACK_URL) {
|
||||
return nil
|
||||
if FileExists(t.UnpackPath) {
|
||||
return filepath.Join(t.UnpackPath, "tor-browser_"+t.Lang), nil
|
||||
}
|
||||
os.MkdirAll(UNPACK_URL, 0755)
|
||||
UNPACK_DIRECTORY, err := os.Open(UNPACK_URL)
|
||||
os.MkdirAll(t.UnpackPath, 0755)
|
||||
UNPACK_DIRECTORY, err := os.Open(t.UnpackPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UnpackUpdater: %s", err)
|
||||
return "", fmt.Errorf("UnpackUpdater: %s", err)
|
||||
}
|
||||
defer UNPACK_DIRECTORY.Close()
|
||||
xzfile, err := os.Open(binpath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UnpackUpdater: %s", err)
|
||||
return "", fmt.Errorf("UnpackUpdater: %s", err)
|
||||
}
|
||||
defer xzfile.Close()
|
||||
xzReader, err := xz.NewReader(xzfile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UnpackUpdater: %s", err)
|
||||
return "", fmt.Errorf("UnpackUpdater: %s", err)
|
||||
}
|
||||
tarReader := tar.NewReader(xzReader)
|
||||
for {
|
||||
@ -242,7 +256,7 @@ func UnpackUpdater(binpath string) error {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("UnpackUpdater: %s", err)
|
||||
return "", fmt.Errorf("UnpackUpdater: %s", err)
|
||||
}
|
||||
if header.Typeflag == tar.TypeDir {
|
||||
os.MkdirAll(filepath.Join(UNPACK_DIRECTORY.Name(), header.Name), 0755)
|
||||
@ -251,7 +265,7 @@ func UnpackUpdater(binpath string) error {
|
||||
filename := filepath.Join(UNPACK_DIRECTORY.Name(), header.Name)
|
||||
file, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UnpackUpdater: %s", err)
|
||||
return "", fmt.Errorf("UnpackUpdater: %s", err)
|
||||
}
|
||||
defer file.Close()
|
||||
io.Copy(file, tarReader)
|
||||
@ -259,37 +273,37 @@ func UnpackUpdater(binpath string) error {
|
||||
//remember to chmod the file afterwards
|
||||
file.Chmod(mode)
|
||||
}
|
||||
return nil
|
||||
return t.UnpackPath, nil
|
||||
|
||||
}
|
||||
|
||||
func CheckSignature(binpath, sigpath string) error {
|
||||
func (t *TBDownloader) CheckSignature(binpath, sigpath string) (string, error) {
|
||||
var pkBytes []byte
|
||||
var pk *openpgp.Entity
|
||||
var sig []byte
|
||||
var bin []byte
|
||||
var err error
|
||||
if pkBytes, err = ioutil.ReadFile(filepath.Join(DOWNLOAD_PATH, "TPO-signing-key.pub")); err != nil {
|
||||
return fmt.Errorf("CheckSignature pkBytes: %s", err)
|
||||
if pkBytes, err = ioutil.ReadFile(filepath.Join(t.DownloadPath, "TPO-signing-key.pub")); err != nil {
|
||||
return "", fmt.Errorf("CheckSignature pkBytes: %s", err)
|
||||
}
|
||||
if pk, err = pgp.GetEntity(pkBytes, nil); err != nil {
|
||||
return fmt.Errorf("CheckSignature pk: %s", err)
|
||||
return "", fmt.Errorf("CheckSignature pk: %s", err)
|
||||
}
|
||||
if bin, err = ioutil.ReadFile(binpath); err != nil {
|
||||
return fmt.Errorf("CheckSignature bin: %s", err)
|
||||
return "", fmt.Errorf("CheckSignature bin: %s", err)
|
||||
}
|
||||
if sig, err = ioutil.ReadFile(sigpath); err != nil {
|
||||
return fmt.Errorf("CheckSignature sig: %s", err)
|
||||
return "", fmt.Errorf("CheckSignature sig: %s", err)
|
||||
}
|
||||
if err = pgp.Verify(pk, sig, bin); err != nil {
|
||||
return UnpackUpdater(binpath)
|
||||
return t.UnpackUpdater(binpath)
|
||||
//return nil
|
||||
}
|
||||
err = fmt.Errorf("signature check failed")
|
||||
return fmt.Errorf("CheckSignature: %s", err)
|
||||
return "", fmt.Errorf("CheckSignature: %s", err)
|
||||
}
|
||||
|
||||
func BoolCheckSignature(binpath, sigpath string) bool {
|
||||
err := CheckSignature(binpath, sigpath)
|
||||
func (t *TBDownloader) BoolCheckSignature(binpath, sigpath string) bool {
|
||||
_, err := t.CheckSignature(binpath, sigpath)
|
||||
return err == nil
|
||||
}
|
||||
|
25
main.go
25
main.go
@ -5,24 +5,22 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/cloudfoundry/jibber_jabber"
|
||||
tbget "i2pgit.org/idk/i2p.plugins.tor-manager/get"
|
||||
tbsupervise "i2pgit.org/idk/i2p.plugins.tor-manager/supervise"
|
||||
tbserve "i2pgit.org/idk/i2p.plugins.tor-manager/serve"
|
||||
)
|
||||
|
||||
var runtimePair = tbget.GetRuntimePair()
|
||||
//var runtimePair = tbget.GetRuntimePair()
|
||||
|
||||
var (
|
||||
lang = flag.String("lang", "", "Language to download")
|
||||
os = flag.String("os", tbget.OS, "OS/arch to download")
|
||||
arch = flag.String("arch", tbget.ARCH, "OS/arch to download")
|
||||
os = flag.String("os", "linux", "OS/arch to download")
|
||||
arch = flag.String("arch", "64", "OS/arch to download")
|
||||
browse = flag.Bool("browse", false, "Open the browser")
|
||||
/*mirror = flag.String("mirror", "", "Mirror to use")*/
|
||||
bemirror = flag.Bool("bemirror", false, "Act as an in-I2P mirror when you're done downloading")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
tbget.OS = *os
|
||||
tbget.ARCH = *arch
|
||||
if *lang == "" {
|
||||
var err error
|
||||
*lang, err = jibber_jabber.DetectIETF()
|
||||
@ -31,18 +29,11 @@ func main() {
|
||||
}
|
||||
log.Println("Using auto-detected language", *lang)
|
||||
}
|
||||
bin, sig, err := tbget.DownloadUpdaterForLang(*lang)
|
||||
client, err := tbserve.NewClient("", *lang, *os, *arch)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("Couldn't create client", err)
|
||||
}
|
||||
if err := tbget.CheckSignature(bin, sig); err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
log.Printf("Signature check passed")
|
||||
}
|
||||
log.Println("Running Tor Browser", *lang, runtimePair, bin)
|
||||
supervisor := tbsupervise.NewSupervisor(bin, *lang)
|
||||
if err := supervisor.RunTBWithLang(); err != nil {
|
||||
if err := client.TBS.RunI2PBWithLang(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -4,29 +4,55 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
tbget "i2pgit.org/idk/i2p.plugins.tor-manager/get"
|
||||
TBSupervise "i2pgit.org/idk/i2p.plugins.tor-manager/supervise"
|
||||
)
|
||||
|
||||
func generateMirrorJSON(hostname string) (map[string]interface{}, error) {
|
||||
if !strings.HasSuffix(hostname, "/") {
|
||||
hostname += "/"
|
||||
type Client struct {
|
||||
hostname string
|
||||
TBD *tbget.TBDownloader
|
||||
TBS *TBSupervise.Supervisor
|
||||
}
|
||||
|
||||
func NewClient(hostname string, lang string, os string, arch string) (*Client, error) {
|
||||
m := &Client{
|
||||
TBD: tbget.NewTBDownloader(lang, os, arch),
|
||||
}
|
||||
tgz, sig, err := m.TBD.DownloadUpdaterForLang(lang)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var home string
|
||||
if home, err = m.TBD.CheckSignature(tgz, sig); err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
log.Printf("Signature check passed: %s %s", tgz, sig)
|
||||
}
|
||||
m.TBS = TBSupervise.NewSupervisor(home, lang)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *Client) generateMirrorJSON() (map[string]interface{}, error) {
|
||||
if !strings.HasSuffix(m.hostname, "/") {
|
||||
m.hostname += "/"
|
||||
}
|
||||
path := filepath.Join(tbget.DOWNLOAD_PATH, "downloads.json")
|
||||
preBytes, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GenerateMirrorJSON: %s", err)
|
||||
}
|
||||
binpath, _, err := tbget.GetUpdaterForLangFromJsonBytes(preBytes, "en-US")
|
||||
binpath, _, err := m.TBD.GetUpdaterForLangFromJsonBytes(preBytes, "en-US")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GenerateMirrorJSON: %s", err)
|
||||
}
|
||||
urlparts := strings.Split(binpath, "/")
|
||||
replaceString := GenerateReplaceString(urlparts[:len(urlparts)-1])
|
||||
fmt.Printf("Replacing: %s with %s\n", replaceString, hostname)
|
||||
jsonBytes := []byte(strings.Replace(string(preBytes), replaceString, hostname, -1))
|
||||
fmt.Printf("Replacing: %s with %s\n", replaceString, m.hostname)
|
||||
jsonBytes := []byte(strings.Replace(string(preBytes), replaceString, m.hostname, -1))
|
||||
var JSON map[string]interface{}
|
||||
if err := json.Unmarshal(jsonBytes, &JSON); err != nil {
|
||||
panic(err)
|
||||
@ -34,8 +60,8 @@ func generateMirrorJSON(hostname string) (map[string]interface{}, error) {
|
||||
return JSON, nil
|
||||
}
|
||||
|
||||
func GenerateMirrorJSON(hostname, lang string) (string, error) {
|
||||
JSON, err := generateMirrorJSON(hostname)
|
||||
func (m *Client) GenerateMirrorJSON(lang string) (string, error) {
|
||||
JSON, err := m.generateMirrorJSON()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -44,7 +70,7 @@ func GenerateMirrorJSON(hostname, lang string) (string, error) {
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("GenerateMirrorJSONBytes: %s", err)
|
||||
}
|
||||
binpath, _, err := tbget.GetUpdaterForLangFromJsonBytes(preBytes, "en-US")
|
||||
binpath, _, err := m.TBD.GetUpdaterForLangFromJsonBytes(preBytes, "en-US")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("GenerateMirrorJSONBytes: %s", err)
|
||||
}
|
||||
@ -52,7 +78,7 @@ func GenerateMirrorJSON(hostname, lang string) (string, error) {
|
||||
replaceString := GenerateReplaceString(urlparts[:len(urlparts)-1])
|
||||
|
||||
if platform, ok := JSON["downloads"]; ok {
|
||||
rtp := tbget.GetRuntimePair()
|
||||
rtp := m.TBD.GetRuntimePair()
|
||||
for k, v := range platform.(map[string]interface{}) {
|
||||
if k != rtp {
|
||||
delete(platform.(map[string]interface{}), k)
|
||||
@ -68,7 +94,7 @@ func GenerateMirrorJSON(hostname, lang string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.Replace(string(bytes), replaceString, hostname, -1), nil
|
||||
return strings.Replace(string(bytes), replaceString, m.hostname, -1), nil
|
||||
}
|
||||
return "", fmt.Errorf("GenerateMirrorJSONBytes: %s", "No downloads found")
|
||||
}
|
||||
|
@ -10,13 +10,8 @@ import (
|
||||
tbget "i2pgit.org/idk/i2p.plugins.tor-manager/get"
|
||||
)
|
||||
|
||||
var wd, _ = os.Getwd()
|
||||
|
||||
var UNPACK_URL = tbget.UNPACK_URL
|
||||
|
||||
//var DEFAULT_TB_LANG = tbget.DefaultIETFLang
|
||||
//var DEFAULT_TB_DIRECTORY = filepath.Join(UNPACK_URL, "tor-browser"+"_"+DEFAULT_TB_LANG)
|
||||
//var DEFAULT_TB_PATH = filepath.Join(DEFAULT_TB_DIRECTORY, "Browser", "start-tor-browser")
|
||||
var UNPACK_URL = tbget.UNPACK_PATH
|
||||
var DEFAULT_TB_LANG = tbget.DefaultIETFLang
|
||||
|
||||
var (
|
||||
OS = tbget.OS
|
||||
@ -33,21 +28,35 @@ func (s *Supervisor) TBPath() string {
|
||||
return filepath.Join(s.UnpackPath, "Browser", "start-tor-browser")
|
||||
}
|
||||
|
||||
func (s *Supervisor) FirefoxPath() string {
|
||||
return filepath.Join(s.UnpackPath, "Browser", "firefox.real")
|
||||
}
|
||||
|
||||
func (s *Supervisor) TBDirectory() string {
|
||||
return filepath.Join(s.UnpackPath, "Browser")
|
||||
}
|
||||
|
||||
func (s *Supervisor) TorPath() string {
|
||||
return filepath.Join(s.UnpackPath, "Browser", "TorBrowser", "tor")
|
||||
return filepath.Join(s.UnpackPath, "Browser", "TorBrowser", "Tor", "tor")
|
||||
}
|
||||
|
||||
func (s *Supervisor) TorDataPath() string {
|
||||
return filepath.Join(s.UnpackPath, "Browser", "TorBrowser", "Data")
|
||||
}
|
||||
|
||||
func (s *Supervisor) I2PDataPath() string {
|
||||
//if tbget.FileExists(filepath.Join(s.UnpackPath, "i2p.firefox")) {
|
||||
return filepath.Join(filepath.Dir(s.UnpackPath), "i2p.firefox")
|
||||
//}
|
||||
}
|
||||
|
||||
func (s *Supervisor) RunTBWithLang() error {
|
||||
tbget.ARCH = ARCH
|
||||
if s.Lang == "" {
|
||||
s.Lang = DEFAULT_TB_LANG
|
||||
}
|
||||
if s.UnpackPath == "" {
|
||||
s.UnpackPath = DEFAULT_TB_PATH
|
||||
s.UnpackPath = UNPACK_URL
|
||||
}
|
||||
|
||||
log.Println("running tor browser with lang", s.Lang, s.UnpackPath)
|
||||
@ -55,21 +64,93 @@ func (s *Supervisor) RunTBWithLang() error {
|
||||
case "linux":
|
||||
if tbget.FileExists(s.UnpackPath) {
|
||||
log.Println("running tor browser with lang", s.Lang, s.UnpackPath)
|
||||
s.cmd = exec.Command(s.UnpackPath)
|
||||
s.cmd = exec.Command(s.TBPath())
|
||||
s.cmd.Stdout = os.Stdout
|
||||
s.cmd.Stderr = os.Stderr
|
||||
return s.cmd.Run()
|
||||
} else {
|
||||
log.Println("tor browser not found at", s.UnpackPath)
|
||||
return fmt.Errorf("tor browser not found at %s", s.UnpackPath)
|
||||
log.Println("tor browser not found at", s.TBPath())
|
||||
return fmt.Errorf("tor browser not found at %s", s.TBPath())
|
||||
}
|
||||
case "darwin":
|
||||
cmd := exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"")
|
||||
cmd.Dir = DEFAULT_TB_DIRECTORY
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
case "windows":
|
||||
cmd := exec.Command("cmd", "/c", "start", "\""+s.UnpackPath+"\"", "\"Tor Browser.exe\"")
|
||||
cmd.Dir = DEFAULT_TB_DIRECTORY
|
||||
cmd := exec.Command("cmd", "/c", "start", "\""+s.TBDirectory()+"\"", "\"Tor Browser.exe\"")
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
default:
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Supervisor) RunI2PBWithLang() error {
|
||||
tbget.ARCH = ARCH
|
||||
if s.Lang == "" {
|
||||
s.Lang = DEFAULT_TB_LANG
|
||||
}
|
||||
if s.UnpackPath == "" {
|
||||
s.UnpackPath = UNPACK_URL
|
||||
}
|
||||
|
||||
log.Println("running tor browser with lang", s.Lang, s.UnpackPath)
|
||||
switch OS {
|
||||
case "linux":
|
||||
if tbget.FileExists(s.UnpackPath) {
|
||||
log.Println("running Tor browser with lang and I2P Profile", s.Lang, s.UnpackPath, s.FirefoxPath(), "--profile", s.I2PDataPath())
|
||||
s.cmd = exec.Command(s.FirefoxPath(), "--profile", s.I2PDataPath())
|
||||
s.cmd.Stdout = os.Stdout
|
||||
s.cmd.Stderr = os.Stderr
|
||||
return s.cmd.Run()
|
||||
} else {
|
||||
log.Println("tor browser not found at", s.FirefoxPath())
|
||||
return fmt.Errorf("tor browser not found at %s", s.FirefoxPath())
|
||||
}
|
||||
case "darwin":
|
||||
cmd := exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"")
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
case "windows":
|
||||
cmd := exec.Command("cmd", "/c", "start", "\""+s.TBDirectory()+"\"", "\"Tor Browser.exe\"")
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
default:
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Supervisor) RunTorWithLang() error {
|
||||
tbget.ARCH = ARCH
|
||||
if s.Lang == "" {
|
||||
s.Lang = DEFAULT_TB_LANG
|
||||
}
|
||||
if s.UnpackPath == "" {
|
||||
s.UnpackPath = UNPACK_URL
|
||||
}
|
||||
|
||||
log.Println("running tor with lang", s.Lang, s.UnpackPath)
|
||||
switch OS {
|
||||
case "linux":
|
||||
if tbget.FileExists(s.UnpackPath) {
|
||||
log.Println("running tor with lang", s.Lang, s.UnpackPath)
|
||||
s.cmd = exec.Command(s.TorPath())
|
||||
s.cmd.Stdout = os.Stdout
|
||||
s.cmd.Stderr = os.Stderr
|
||||
return s.cmd.Run()
|
||||
} else {
|
||||
log.Println("tor not found at", s.TorPath())
|
||||
return fmt.Errorf("tor not found at %s", s.TorPath())
|
||||
}
|
||||
case "darwin":
|
||||
cmd := exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"")
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
case "windows":
|
||||
cmd := exec.Command("cmd", "/c", "start", "\""+s.TBDirectory()+"\"", "\"Tor Browser.exe\"")
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
default:
|
||||
}
|
||||
|
Reference in New Issue
Block a user