~welt/murse

49d619400399a075e4231488e5ac083cb469fadd — welt 4 months ago a8532f0
Fix directories, lockfile support, remove sql debug log
5 files changed, 33 insertions(+), 35 deletions(-)

M crypto.go
M files.go
M flags.go
M local.go
M main.go
M crypto.go => crypto.go +1 -1
@@ 13,7 13,7 @@ import (
)

func init() {
	k, err := downloadDevKey()
	k, err := getKey()
	if err != nil {
		log.Fatal(err)
	}

M files.go => files.go +8 -6
@@ 3,7 3,6 @@ package main
import (
	"crypto/rsa"
	"database/sql"
	"fmt"
	"log"
	"os"
	"strings"


@@ 14,9 13,12 @@ func init() {
	if err != nil {
		log.Fatal(err)
	}
	err = os.Mkdir(cd + "/murse", 0777)
	if err != nil {
		log.Fatal(err)

	if !fileExists(cd) {
		err = os.Mkdir(cd+"/murse", 0777)
		if err != nil {
			log.Fatal(err)
		}
	}
}



@@ 60,7 62,6 @@ func getRevisedFiles(db *sql.DB, lrev int, nrev int) (map[string]string, error) 

		for k, v := range mp {
			rf[k] = v
			fmt.Println(rf[k])
		}
	}
	return rf, nil


@@ 79,7 80,8 @@ func isProtected(file string) bool {
}

func fileExists(file string) bool {
	if _, err := os.Stat(file); !os.IsNotExist(err) {
	_, err := os.Stat(file)
	if !os.IsNotExist(err) || err == nil {
		return true
	}
	return false

M flags.go => flags.go +11 -10
@@ 6,22 6,23 @@ import (
	"github.com/jessevdk/go-flags"
)

func init() {
	_, err := flags.Parse(&opt)
	if err != nil {
		os.Exit(1)
	}

	lmd = opt.Directory + "/.murse/local.json"
	lfd = opt.Directory + "/.murse/lockfile"
}

var opt struct {
	Threads            int    `short:"t" short:"n" default:"0" description:"Number of threads to use. Don't touch this unless you know what you're doing. 0 = auto."`
	Directory          string `short:"d" short:"p" default:"./open_fortress" description:"Directory to download to or modify. Will be created if it doesn't already exist."`
	URL                string `short:"u" default:"https://svn.openfortress.fun/launcher/files/" description:"The URL for the launcher files."`
	OverwriteProtected bool   `short:"x" long:"cfg-overwrite" description:"Overwrite protected files (such as demos, modified .cfg files)."`
	IgnoreLockfile     bool   `short:"b" description:"Ignore the lockfile, in case the program was previously ungracefully killed."`
	// Backward compatibility flags
	DisableSigning bool `short:"z" long:"disable-signing" description:"Disable signature checks. Note that unlike ofatomic, we only check the file database's signature, so this should have no performance impact during file download."`
	DisableHashing bool `short:"#" long:"disable-hashing" description:"This is a dummy flag meant for compatability purposes."`
}

func init() {
	_, err := flags.Parse(&opt)
	if err != nil {
		os.Exit(1)
	}

	lmd = opt.Directory + "/.murse/local.json"
	lfd = opt.Directory + "/.murse/lockfile"
}

M local.go => local.go +3 -5
@@ 12,6 12,7 @@ import (
	"encoding/json"
	"log"
	"os"
	"time"
)

type localManifest struct {


@@ 57,11 58,8 @@ func (m *localManifest) read() error {
}

func lockInstall() error {
	_, err := os.Create(lfd)
	if err != nil {
		return err
	}
	return nil
	err := os.WriteFile(lfd, []byte(time.Now().String()), 0777)
	return err
}

func unlockInstall() {

M main.go => main.go +10 -13
@@ 4,7 4,6 @@ import (
	"context"
	"crypto/rsa"
	"database/sql"
	"fmt"
	"log"
	"os"
	"runtime"


@@ 29,25 28,23 @@ type file struct {
}

func main() {
	confdir := opt.Directory + "/.murse/"
	if fileExists(lfd) && !opt.IgnoreLockfile {
		log.Fatal("Lockfile exists, are you running another installation? Re-run with -b to delete the lockfile.")
	}

	if !fileExists(confdir + "/local.json") {
	if !fileExists(lmd) {
		install = true
	}

	// In ofatomic, to ensure the files are legitimate it checks
	// *every file* for if the signature is correct. This is terrible for
	// performance. Why verify the signature for *every* file when you can
	// verify the list of hashes, and then simply compare the file's hash to
	// the list? Why verify the database the first time anyways? This is why
	// we're storing the database locally (temporarily)

	m, err := get(opt.URL + "/ofmanifest.db")
	if err != nil {
		log.Fatal(err)
	}

	// TODO: cache key locally and not download every time.
	// In ofatomic, to ensure the files are legitimate it checks
	// *every file* for if the signature is correct. This is bad for
	// performance. Instead we verify the database and then trust its
	// hashes.
	if !opt.DisableSigning {
		ms, err := get(opt.URL + "/ofmanifest.sig")
		if err != nil {


@@ 96,8 93,6 @@ func main() {
		log.Fatal(err)
	}

	fmt.Println(newFiles)

	if !fileExists(opt.Directory) {
		err := os.Mkdir(opt.Directory, 0700)
		if err != nil {


@@ 105,6 100,8 @@ func main() {
		}
	}

	confdir := opt.Directory + "/.murse"

	if !fileExists(confdir) {
		err := os.Mkdir(confdir, 0700)
		if err != nil {