Add self-destructing option

This commit is contained in:
idk
2022-03-03 23:48:32 -05:00
parent 01da2b0605
commit 06b6bf6453
2 changed files with 36 additions and 0 deletions

View File

@ -93,6 +93,7 @@ var (
mirror = flag.String("mirror", "https://dist.torproject.org/torbrowser/", "Mirror to use") mirror = flag.String("mirror", "https://dist.torproject.org/torbrowser/", "Mirror to use")
solidarity = flag.Bool("onion", false, "Serve an onion site which shows some I2P propaganda") solidarity = flag.Bool("onion", false, "Serve an onion site which shows some I2P propaganda")
torrent = flag.Bool("torrent", tbget.TorrentReady(), "Create a torrent of the downloaded files and seed it over I2P using an Open Tracker") torrent = flag.Bool("torrent", tbget.TorrentReady(), "Create a torrent of the downloaded files and seed it over I2P using an Open Tracker")
destruct = flag.Bool("destruct", false, "Destructively delete the working directory when finished")
/*ptop = flag.Bool("p2p", false, "Use bittorrent over I2P to download the initial copy of Tor Browser")*/ /*ptop = flag.Bool("p2p", false, "Use bittorrent over I2P to download the initial copy of Tor Browser")*/
) )
@ -121,6 +122,9 @@ func main() {
if *snowflake { if *snowflake {
go Snowflake() go Snowflake()
} }
if *destruct {
defer OverwriteDirectoryContents(*directory)
}
tbget.WORKING_DIR = *directory tbget.WORKING_DIR = *directory
if filename == "i2pbrowser" { if filename == "i2pbrowser" {
log.Println("Starting I2P in Tor Browser") log.Println("Starting I2P in Tor Browser")

32
rmdir.go Normal file
View File

@ -0,0 +1,32 @@
package main
import (
"log"
"os"
"path/filepath"
)
func OverwriteDirectoryContents(directory string) {
//walk the contents of directory recursively
//and zero-out the files to the length of the file
filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
go func() {
if err != nil {
log.Println("Error:", err)
}
if info.IsDir() {
log.Println("Error:", err)
}
file, err := os.OpenFile(path, os.O_RDWR, 0)
if err != nil {
log.Println("Error:", err)
}
defer file.Close()
bytes := info.Size()
file.Truncate(0)
file.Write(make([]byte, bytes))
log.Println("Error:", err)
}()
return nil
})
}