# HG changeset patch # User Ted Unangst # Date 1723577105 14400 # Tue Aug 13 15:25:05 2024 -0400 # Node ID a5e5581d3023d4ba4b2e2da39e823d5bdff36fb0 # Parent 7896398d062344f4e1396a6985cd11ef9e10b93f add back a scriptable init function diff --git a/docs/changelog.txt b/docs/changelog.txt --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,6 +1,8 @@ changelog -### next +### 1.4.1 Antiquated Automaton + ++ Add back a scriptable init function. + Document that go 1.20+ is now required. diff --git a/go.mod b/go.mod --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ golang.org/x/net v0.28.0 humungus.tedunangst.com/r/go-sqlite3 v1.2.1 humungus.tedunangst.com/r/gonix v0.1.4 - humungus.tedunangst.com/r/termvc v0.1.2 + humungus.tedunangst.com/r/termvc v0.1.3 humungus.tedunangst.com/r/webs v0.7.18 ) diff --git a/go.sum b/go.sum --- a/go.sum +++ b/go.sum @@ -78,7 +78,7 @@ humungus.tedunangst.com/r/go-sqlite3 v1.2.1/go.mod h1:YrRIH0O7uePPLbJriXrER44ym5aQ0QxK8CnaT/GWOkg= humungus.tedunangst.com/r/gonix v0.1.4 h1:FuvWYQlFIzmfHxfvIfq5SYpSiHhFcpJqq3pi+w45s78= humungus.tedunangst.com/r/gonix v0.1.4/go.mod h1:VFBc2bPDXr1ayHOmHUutxYu8fSM+pkwK8o36h4rkORg= -humungus.tedunangst.com/r/termvc v0.1.2 h1:TPH5ThFRjR+f1ko9Uh4dhm3ieNKvmoPZAvu3tU5lNIE= -humungus.tedunangst.com/r/termvc v0.1.2/go.mod h1:TnlG9PbH77OpEf46iDyb/H9drjegQNwhpXalmGGrbhU= +humungus.tedunangst.com/r/termvc v0.1.3 h1:BYxcqdA2Ijhqolf2BdNlGw5355qE80EzAqiNgi7d5tk= +humungus.tedunangst.com/r/termvc v0.1.3/go.mod h1:TnlG9PbH77OpEf46iDyb/H9drjegQNwhpXalmGGrbhU= humungus.tedunangst.com/r/webs v0.7.18 h1:tCPZuC7p/8chlOSb1RBJYxnGauBg2Lzm5DO4cu+82HI= humungus.tedunangst.com/r/webs v0.7.18/go.mod h1:ylhqHSPI0Oi7b4nsnx5mSO7AjLXN7wFpEHayLfN/ugk= diff --git a/util.go b/util.go --- a/util.go +++ b/util.go @@ -16,6 +16,7 @@ package main import ( + "bufio" "crypto/rand" "crypto/rsa" "database/sql" @@ -77,14 +78,27 @@ prepareStatements(db) + setcsrfkey() + setconfig("dbversion", myVersion) + + setconfig("servermsg", "

Things happen.

") + setconfig("aboutmsg", "

What is honk?

Honk is amazing!") + setconfig("loginmsg", "

login

") + setconfig("devel", 0) + cleanup := func() { os.Remove(dbname) os.Remove(blobdbname) os.Exit(1) } + defer cleanup() + + if !termvc.IsTerm() { + simplesetup(db) + return + } termvc.Start() - defer cleanup() defer termvc.Restore() go termvc.Catch(cleanup) @@ -147,16 +161,58 @@ return } - setcsrfkey() - setconfig("dbversion", myVersion) + db.Close() + termvc.Restore() + fmt.Printf("done.\n") + os.Exit(0) +} - setconfig("servermsg", "

Things happen.

") - setconfig("aboutmsg", "

What is honk?

Honk is amazing!") - setconfig("loginmsg", "

login

") - setconfig("devel", 0) +func simplesetup(db *sql.DB) { + r := bufio.NewReader(os.Stdin) + fmt.Printf("username: ") + name, err := r.ReadString('\n') + name = name[:len(name)-1] + fmt.Printf("password: ") + pass, err := r.ReadString('\n') + pass = pass[:len(pass)-1] + err = createuser(db, name, pass) + if err != nil { + elog.Print(err) + return + } + // must came later or user above will have negative id + err = createserveruser(db) + if err != nil { + elog.Print(err) + return + } + + fmt.Printf("listen address: ") + addr, err := r.ReadString('\n') + if err != nil { + elog.Print(err) + return + } + addr = addr[:len(addr)-1] + if len(addr) < 1 { + elog.Print("that's way too short") + return + } + setconfig("listenaddr", addr) + fmt.Printf("server name: ") + addr, err = r.ReadString('\n') + if err != nil { + elog.Print(err) + return + } + addr = addr[:len(addr)-1] + if len(addr) < 1 { + elog.Print("that's way too short") + return + } + setconfig("servername", addr) db.Close() - termvc.Restore() fmt.Printf("done.\n") os.Exit(0) }