fix flag parsing, usage generation

This commit is contained in:
idk
2022-07-15 18:19:53 -04:00
parent 3f0b0d8fdb
commit 8f3a5594c6
7 changed files with 113 additions and 157 deletions

View File

@ -311,18 +311,6 @@ tor-browser/unpack/i2p.firefox:
tor-browser/unpack/i2p.firefox.config:
@echo "TODO"
#refresh-tor-keys: clean-tor-keys tor-browser/TPO-signing-key.pub
#tor-keys: tor-browser/TPO-signing-key.pub
#clean-tor-keys:
# rm -f tor-browser/TPO-signing-key.pub
#tor-browser/TPO-signing-key.pub:
# gpg --armor --output ./tor-browser/TPO-signing-key.pub --export
# 0xEF6E286DDA85EA2A4BA7DE684E2C6E8793298290
# gpg --show-key ./tor-browser/TPO-signing-key.pub
deb: clean
./changelog.sh
rm ../i2p.plugins.tor-manager_$(VERSION).orig.tar.gz -f
@ -353,7 +341,7 @@ debsrc: clean
DATE=`date +%Y/%m/%d`
usage:
TOR_MANAGER_CLEARNET_MIRROR=true TOR_MANAGER_REQUIRE_PASSWORD=false ./i2p.plugins.tor-manager --ptop=false --help
TOR_MANAGER_CLEARNET_MIRROR=true TOR_MANAGER_REQUIRE_PASSWORD=false ./i2p.plugins.tor-manager --p2p=false --help=true
usagemd:
@echo "Tor(And sometimes Firefox) Manager for I2P" | tee USAGE.md
@ -364,7 +352,7 @@ usagemd:
@echo "### Options:" | tee -a USAGE.md
@echo "" | tee -a USAGE.md
@echo '```sh' | tee -a USAGE.md
TOR_MANAGER_CLEARNET_MIRROR=true TOR_MANAGER_REQUIRE_PASSWORD=false ./i2p.plugins.tor-manager --help 2>&1 | grep -v $(DATE) | grep -v $(HOME) | tee -a USAGE.md
TOR_MANAGER_CLEARNET_MIRROR=true TOR_MANAGER_REQUIRE_PASSWORD=false ./i2p.plugins.tor-manager --p2p=false --help=true 2>&1 | grep -v $(DATE) | grep -v $(HOME) | tee -a USAGE.md
@echo '```' | tee -a USAGE.md
@echo "" | tee -a USAGE.md

187
USAGE.md
View File

@ -1,12 +1,6 @@
Tor(And sometimes Firefox) Manager for I2P
===========================================
## Usage: i2p.plugins.tor-manager [options]
### Options:
```sh
Using clearnet mirror
TorrentDownloaded: Torrent Download complete: tor-browser-linux64-11.5_en-US.tar.xz 110909932 110909932 9 9
UnpackSite: /home/idk/go/src/i2pgit.org/idk/i2p.plugins.tor-manager/tmp-i2pbrowser/tor-browser/www
comparing sizes: 1109 1109
Usage: i2p.plugins.tor-manager [options]
Downloads, verifies and unpacks Tor Browser. Manages the Tor Browser
@ -15,120 +9,88 @@ Tor process and downloads updates when Tor is not available.
Options:
Usage of ./i2p.plugins.tor-manager:
-apparmor
Generate apparmor rules
-arch string
OS/arch to download (default "64")
-bemirror
Act as an in-I2P mirror when you're done downloading
-chat
Open a WebChat client
-clearnet
Use clearnet (no Tor or I2P) in Tor Browser
-destruct
Destructively delete the working directory when finished
-directory string
Directory operate in (default "tmp-i2pbrowser")
-help
Print help and quit
-host string
Host to serve on (default "127.0.0.1")
-i2pbrowser
Open I2P in Tor Browser
-i2pconfig
Open I2P routerconsole in Tor Browser with javscript enabled and non-routerconsole sites disabled
-lang string
Language to download
-mirror string
Mirror to use. I2P will be used if an I2P proxy is present, if system Tor is available, it will be downloaded over the Tor proxy. (default "https://dist.torproject.org/torbrowser/")
-notor
Do not automatically start Tor
-nounpack
Do not unpack the Tor Browser
-offline
Work offline. Differs from Firefox's offline mode in that cannot be disabled until the browser is closed.
-onion
Serve an onion site which shows some I2P propaganda
-os string
OS/arch to download (default "linux")
-p2p
Use bittorrent over I2P to download the initial copy of Tor Browser (default true)
-password string
Password to encrypt the working directory with. Implies -destruct, only the encrypted container will be saved.
-port int
Port to serve on (default 7695)
-profile string
use a custom profile path, normally blank
-shortcuts
Create desktop shortcuts
-snowflake
Offer a Snowflake to other Tor Browser users
-snowflake-broker string
broker URL (default "https://snowflake-broker.torproject.net/")
-snowflake-capacity uint
maximum concurrent clients
-snowflake-directory string
directory with a page to serve locally for your snowflake. If empty, no local page is served.
-snowflake-keep-local-addresses
keep local LAN address ICE candidates
-snowflake-log string
log filename
-snowflake-port string
port to serve info page(directory) on (default "7676")
-snowflake-relay string
websocket relay URL (default "wss://snowflake.bamsoftware.com/")
-snowflake-stun string
broker URL (default "stun:stun.stunprotocol.org:3478")
-snowflake-unsafe-logging
prevent logs from being scrubbed
-torbrowser
Open Tor Browser
-torrent
Create a torrent of the downloaded files and seed it over I2P using an Open Tracker (default true)
-verbose
Verbose output
-watch-profiles string
Monitor and control these Firefox profiles. Temporarily Unused.
--apparmor Generate apparmor rules
--arch string OS/arch to download (default "64")
--bemirror Act as an in-I2P mirror when you're done downloading
--chat Open a WebChat client
--clearnet Use clearnet (no Tor or I2P) in Tor Browser
--destruct Destructively delete the working directory when finished
--directory string Directory operate in (default "tmp-i2pbrowser")
--help Print help and quit
--host string Host to serve on (default "127.0.0.1")
--i2pbrowser Open I2P in Tor Browser
--i2pconfig Open I2P routerconsole in Tor Browser with javscript enabled and non-routerconsole sites disabled
--i2peditor Open I2P Site Editor in Tor Browser
--lang string Language to download (default "en-US")
--license Print the license and exit
--mirror string Mirror to use. I2P will be used if an I2P proxy is present, if system Tor is available, it will be downloaded over the Tor proxy. (default "https://dist.torproject.org/torbrowser/")
--mirrorall Download and mirror every language and OS/arch combination
--nevertor Never use Tor for downloading Tor Browser
--notor Do not automatically start Tor
--nounpack Do not unpack the Tor Browser
--offline Work offline. Differs from Firefox's offline mode in that cannot be disabled until the browser is closed.
--onion Serve an onion site which shows some I2P propaganda (default true)
--os string OS/arch to download (default "linux")
--p2p Use bittorrent over I2P to download the initial copy of Tor Browser (default true)
--password string Password to encrypt the working directory with. Implies -destruct, only the encrypted container will be saved.
--port int Port to serve on (default 7695)
--profile string use a custom profile path, normally blank
--shortcuts Create desktop shortcuts
--snowflake Offer a Snowflake to other Tor Browser users
--snowflake-broker string broker URL (default "https://snowflake-broker.torproject.net/")
--snowflake-capacity uint maximum concurrent clients
--snowflake-directory string directory with a page to serve locally for your snowflake. If empty, no local page is served.
--snowflake-keep-local-addresses keep local LAN address ICE candidates
--snowflake-log string log filename
--snowflake-port string port to serve info page(directory) on (default "7676")
--snowflake-relay string websocket relay URL (default "wss://snowflake.bamsoftware.com/")
--snowflake-stun string broker URL (default "stun:stun.stunprotocol.org:3478")
--snowflake-unsafe-logging prevent logs from being scrubbed
--systray Create a systray icon
--torbrowser Open Tor Browser
--torrent Create a torrent of the downloaded files and seed it over I2P using an Open Tracker (default true)
--torversion Print the version of Tor Browser that will be downloaded and exit
--verbose Verbose output
--watch-profiles string Monitor and control these Firefox profiles. Temporarily Unused.
Available Languages:
- ar
- my
- cs
- en-US
- id
- nl
- ro
- tr
- zh-TW
- ar
- de
- es-AR
- it
- ms
- pt-BR
- da
- es-ES
- ka
- nb-NO
- zh-CN
- fa
- is
- ja
- nb-NO
- lt
- ka
- ko
- pl
- vi
- zh-TW
- ca
- fr
- id
- mk
- zh-CN
- cs
- de
- el
- en-US
- th
- es-AR
- ga-IE
- he
- hu
- ko
- vi
- ca
- el
- es-ES
- mk
- ms
- pt-BR
- th
- ga-IE
- my
- pl
- ru
- da
- sv-SE
- tr
- hu
- ja
Usage: ./firefox.real [ options ... ] [URL]
where options include:
@ -168,7 +130,8 @@ Firefox options
--search <term> Search <term> with your default search engine.
--setDefaultBrowser Set this app as the default browser.
--first-startup Run post-install actions before opening a new window.
--kiosk Start the browser in kiosk mode.
--kiosk Start the browser in kiosk mode.
--disable-pinch Disable touch-screen and touch-pad pinch gestures.
--jsconsole Open the Browser Console.
--jsdebugger [<path>] Open the Browser Toolbox. Defaults to the local build
but can be overridden by a firefox path.
@ -191,5 +154,3 @@ Tor Browser Script Options
--detach Detach from terminal and run Tor Browser in the background.
--register-app Register Tor Browser as a desktop app for this user
--unregister-app Unregister Tor Browser as a desktop app for this user
```

View File

@ -10,6 +10,7 @@ import (
func CleanupArgs() (args []string, trailers []string) {
// get a list of all possible flags from the flag package
args = []string{os.Args[0]}
for i, arg := range os.Args[1:] {
log.Printf("arg %d: %s", i, arg)
trailer := true

View File

@ -350,8 +350,8 @@ func (wc *WriteCounter) Write(p []byte) (int, error) {
}
func (wc WriteCounter) PrintProgress() {
fmt.Printf("\r%s", strings.Repeat(" ", 35))
fmt.Printf("\rDownloading... %s complete", humanize.Bytes(wc.Total))
fmt.Fprintf(os.Stderr, "\r%s", strings.Repeat(" ", 35))
fmt.Fprintf(os.Stderr, "\rDownloading... %s complete", humanize.Bytes(wc.Total))
}
func (t *TBDownloader) StartConf() *tor.StartConf {
@ -609,13 +609,13 @@ func (t *TBDownloader) BotherToDownload(dl, name string) bool {
}
lenString := strconv.Itoa(int(contentLength))[:l]
lenSize := strconv.Itoa(int(stat.Size()))[:l]
fmt.Println("comparing sizes:", lenString, lenSize)
fmt.Fprintf(os.Stderr, "comparing sizes: %v %v", lenString, lenSize)
if stat.Size() == contentLength {
//if lenString != lenSize {
// return true
//} else {
fmt.Printf("BotherToDownload(): %s is fully downloaded\n", name)
fmt.Fprintf(os.Stderr, "BotherToDownload(): %s is fully downloaded\n", name)
return false
//}
}
@ -794,7 +794,7 @@ func (t *TBDownloader) UnpackUpdater(binpath string) (string, error) {
}
return t.BrowserDir(), nil
}
fmt.Printf("Unpacking %s %s\n", binpath, t.UnpackPath)
fmt.Fprintf(os.Stderr, "Unpacking %s %s\n", binpath, t.UnpackPath)
os.MkdirAll(t.UnpackPath, 0755)
UNPACK_DIRECTORY, err := os.Open(t.UnpackPath)
if err != nil {
@ -834,7 +834,7 @@ func (t *TBDownloader) UnpackUpdater(binpath string) (string, error) {
//remember to chmod the file afterwards
file.Chmod(mode)
if t.Verbose {
fmt.Printf("Unpacked %s\n", header.Name)
fmt.Fprintf(os.Stderr, "Unpacked %s\n", header.Name)
}
}
if !FileExists(t.I2PBrowserDir()) {

View File

@ -292,11 +292,11 @@ func TorrentDownloaded(ietf, rtpair string) bool {
if info.Size() == int64(cmpsize) {
sizeString := fmt.Sprintf("%d", info.Size())
cmpString := fmt.Sprintf("%d", cmpsize)
fmt.Println("TorrentDownloaded: Torrent Download complete:", path, info.Size(), int64(cmpsize), len(sizeString), len(cmpString))
fmt.Fprintf(os.Stderr, "TorrentDownloaded: Torrent Download complete:", path, info.Size(), int64(cmpsize), len(sizeString), len(cmpString))
found = true
return nil
} else {
fmt.Println("TorrentDownloaded: Torrent Download incomplete:", path, info.Size(), int64(cmpsize))
fmt.Fprintf(os.Stderr, "TorrentDownloaded: Torrent Download incomplete:", path, info.Size(), int64(cmpsize))
return fmt.Errorf("TorrentDownloaded: Torrent Download found but size is too small: %s", path)
}
}

48
main.go
View File

@ -57,7 +57,7 @@ func LICENSE() {
if err != nil {
log.Fatal(err)
}
fmt.Println(string(license_bytes))
fmt.Fprintf(os.Stderr, string(license_bytes))
I2P.PrintLicenses()
os.Exit(0)
}
@ -190,36 +190,36 @@ func Password() string {
func Mirror() string {
if mir := os.Getenv("TOR_MANAGER_MIRROR"); mir != "" {
fmt.Println("Using environment mirror", mir)
fmt.Fprintf(os.Stderr, "Using environment mirror %s", mir)
return mir
}
if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
fmt.Println("Using arm64 mirror")
fmt.Fprintf(os.Stderr, "Using arm64 mirror")
return "https://sourceforge.net/projects/tor-browser-ports/files"
}
clear := os.Getenv("TOR_MANAGER_CLEARNET")
switch clear {
case "1", "true", "yes", "on":
fmt.Println("Using clearnet mirror")
fmt.Fprintf(os.Stderr, "Using clearnet mirror")
return "https://dist.torproject.org/torbrowser/"
}
clearmirror := os.Getenv("TOR_MANAGER_CLEARNET_MIRROR")
switch clearmirror {
case "1", "true", "yes", "on":
fmt.Println("Using clearnet mirror")
fmt.Fprintf(os.Stderr, "Using clearnet mirror")
return "https://dist.torproject.org/torbrowser/"
}
if tbget.Torrent(*lang, OS()+ARCH()) {
fmt.Println("Using torrent mirror")
fmt.Fprintf(os.Stderr, "Using torrent mirror")
return "http://localhost:7657/i2psnark/"
}
if tbget.TestHTTPDefaultProxy() {
//fmt.Println("Using I2P mirror")
//fmt.Fprintf(os.Stderr,"Using I2P mirror")
//return "http://dist.torproject.i2p/torbrowser/"
fmt.Println("Using clearnet mirror instead of I2P mirror due to hash sum mismatch issue")
fmt.Fprintf(os.Stderr, "Using clearnet mirror instead of I2P mirror due to hash sum mismatch issue")
return "https://dist.torproject.org/torbrowser/"
}
fmt.Println("Using clearnet mirror")
fmt.Fprintf(os.Stderr, "Using clearnet mirror")
return "https://dist.torproject.org/torbrowser/"
}
@ -241,20 +241,24 @@ func main() {
SnowflakeFlag()
usage := flag.Usage
flag.Usage = func() {
fmt.Printf("Usage: %s %s\n", filename, "[options]")
fmt.Printf("\n")
fmt.Printf("Downloads, verifies and unpacks Tor Browser. Manages the Tor Browser\n")
fmt.Printf("system in environments where Tor is not in use. Monitors a long-running\n")
fmt.Printf("Tor process and downloads updates when Tor is not available.\n")
fmt.Printf("\n")
fmt.Printf("Options:\n")
fmt.Printf("\n")
fmt.Fprintf(os.Stdout, "Usage: %s %s\n", filename, "[options]")
fmt.Fprintf(os.Stdout, "\n")
fmt.Fprintf(os.Stdout, "Downloads, verifies and unpacks Tor Browser. Manages the Tor Browser\n")
fmt.Fprintf(os.Stdout, "system in environments where Tor is not in use. Monitors a long-running\n")
fmt.Fprintf(os.Stdout, "Tor process and downloads updates when Tor is not available.\n")
fmt.Fprintf(os.Stdout, "\n")
fmt.Fprintf(os.Stdout, "Options:\n")
fmt.Fprintf(os.Stdout, "\n")
// redirect stderr to stdout
flag.CommandLine.SetOutput(os.Stdout)
usage()
fmt.Printf("\nAvailable Languages:\n\n")
// redirect stderr back to stderr
flag.CommandLine.SetOutput(os.Stderr)
fmt.Fprintf(os.Stdout, "\nAvailable Languages:\n\n")
for _, l := range tbget.Languages() {
fmt.Printf(" - %s\n", l)
fmt.Fprintf(os.Stdout, " - %s\n", l)
}
fmt.Printf("\n")
fmt.Fprintf(os.Stdout, "\n")
}
args, trailers := CleanupArgs()
log.Printf("Args: %v\n", args)
@ -285,7 +289,7 @@ func main() {
if err != nil {
log.Panicln(err)
}
fmt.Println(torbrowserversion)
fmt.Fprintf(os.Stderr, torbrowserversion)
os.Exit(0)
}
if *ptop {
@ -405,7 +409,9 @@ func main() {
}
// log.Fatalf("%s", client.TBS.PassThroughArgs)
if *help {
log.Println("Usage:")
flag.Usage()
if err := client.TBS.RunTBHelpWithLang(); err != nil {
log.Fatal(err)
}

View File

@ -167,7 +167,7 @@ func (ios *I2POnionService) ListenAndServe() error {
func (ios *I2POnionService) UnpackSite() error {
docroot := ios.ServeDir
fmt.Println("UnpackSite: ", docroot)
fmt.Fprintf(os.Stderr, "UnpackSite: %s", docroot)
if dir, err := os.Stat(docroot); err == nil && dir.IsDir() {
return nil
}