Commit 58d50b50 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Add a reseed command

parent 287bda5b
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@
//     all shutdown messages.
//   - `expire` removes all expired messages and deletes broadcast messages
//     older than 3 days.
//   - `reseed` deletes all messages in the GENERAL folder and reseeds
//     them from the embedded seed data, creating missing seed authors
//     as disabled users.
package batch

import (
@@ -71,6 +74,46 @@ func Expire() int {
	return 0
}

// Reseed deletes all messages in the GENERAL folder and reseeds them
// from the embedded seed data.  Any seed message authors not already
// in the database are created as disabled users.
func Reseed() int {
	ctx := storage.Context()

	store, err := storage.Open()
	ask.CheckErr(err)
	q := storage.New(store.DB)

	ask.CheckErr(q.DeleteAllMessages(ctx, "GENERAL"))

	seedMsgs, err := GetSeedMessages()
	ask.CheckErr(err)

	for i := range seedMsgs {
		u, err := q.GetUser(ctx, seedMsgs[i].Login)
		ask.CheckErr(err)
		if u.Login == "" {
			_, err = q.AddUser(ctx, storage.AddUserParams{
				Login:    seedMsgs[i].Login,
				Name:     seedMsgs[i].Name,
				Disabled: 1,
			})
			ask.CheckErr(err)
		}
		ask.CheckErr(q.SeedCreateMessage(ctx, storage.SeedCreateMessageParams{
			Folder:     "GENERAL",
			Author:     seedMsgs[i].Login,
			Subject:    seedMsgs[i].Subject,
			Message:    seedMsgs[i].Message,
			CreateAt:   seedMsgs[i].Date,
			Expiration: time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC),
		}))
	}

	fmt.Printf("Reseeded %d messages in GENERAL.\n", len(seedMsgs))
	return 0
}

// Install is an interactive command used to install the crontab.
func Install() int {
	ctx := storage.Context()
+673 −0

File added.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
From: V510UEFS "Kevin Lyda"
From: V510UEFS "Sister Kevin"
Date: 16-MAY-2025 16:13
Subj: Go version of BULLETIN

@@ -54,4 +54,4 @@ It will create a crontab for the user it is run as and the following files:
  * ~/.ssh/authorized_keys - keys are added and removed from here to
    let users connect.

Kevin
Sister Kevin
+56 −0
Original line number Diff line number Diff line
From: V510UEFS "Sister Kevin"
Date: 18-FEB-2026 19:32
Subj: Go version 1.0.0 of BULLETIN

This is the Go port of BULLETIN based on the original FORTRAN BULLETIN
at version 2.07.

The Go port lacks news and mailing list. In addition remote folders
are not supported.  Commands and flags related to those haven't been
implemented.  In addition, it just uses a basic text editor, not an
editor like EDT.  Though I'm open to implementing one.

Several commands accepted files or allowed messages to be put in files.
All the file related functionality has been removed.

The PRINT command has been implemented, but it depends on a terminal
emulator implementing the passtrhru printing codes.  Most do not.

However the rest of BULLETIN works.  There are message boards, you can
add and read messages in them.  Not all the commands work yet, but they
are being added.

There's a small mail system sort of like VMS mail.  Additional
enhancements being considered are:

  * Code highlighting.
  * Better editor options (current one is a stripped down tview example).

All of this should work as an unprivileged user and only need a single
binary that is started via an ssh connection.

Future enhancements that might be done:

  * Remote folder support - possibly using something like activitypub?
  * A notification system to other chat systems.

To install this just run the following (assumes the go bin directory is
in your path):

    bulletin$ go install git.lyda.ie:pp/bulletin@latest
    bulletin$ bulletin -u SYSTEM -b install

It will ask you for an initial account and seed the GENERAL board with
historical messages and this one.  It will also make some disabled
accounts who authored the seeded messages in GENERAL (like this one).

It will create a crontab for the user it is run as and the following files:

  * ~/.bulletin-installed - a touch file to make sure install only
    runs once.
  * ~/.local/share/BULLETIN/bulletin.db - contains all the messages
    and users.
  * ~/.ssh/authorized_keys - keys are added and removed from here to
    let users connect.

Sister Kevin
+3 −1
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ func main() {
				}
				// Don't sandbox install/migrate-keys/new-user as they need
				// broader filesystem and network access.
				if batchFlag != "install" && batchFlag != "migrate-keys" && batchFlag != "new-user" {
				if batchFlag != "install" && batchFlag != "migrate-keys" && batchFlag != "new-user" && batchFlag != "reseed" {
					if err := security.InitSandbox(); err != nil {
						fmt.Printf("ERROR: %s.\n", err)
						os.Exit(1)
@@ -132,6 +132,8 @@ func main() {
					exitcode = batch.NewUser(cmd.Args().Slice())
				case "migrate-keys":
					exitcode = batch.MigrateKeys()
				case "reseed":
					exitcode = batch.Reseed()
				default:
					fmt.Println("ERROR: unknown batch command.")
					exitcode = 1