Unverified Commit fa609170 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Add a bunch of seed messages for GENERAL.

parent 561977c3
Loading
Loading
Loading
Loading
+36 −10
Original line number Diff line number Diff line
@@ -20,9 +20,6 @@ import (
//go:embed crontab
var crontabTemplate string

//go:embed announcement-2.06.txt
var announce206 string

// Reboot deletes all messages with `shutdown` set.
func Reboot() int {
	ctx := storage.Context()
@@ -73,7 +70,19 @@ func Install() int {
	q := storage.New(store.DB)

	// Create the initial users.
	fmt.Println(`Welcome to the BULLETIN install process.  This will create
the following files:

  * ~/.local/share/BULLETIN/bulletin.db - BULLETIN's folder and user db.
	* ~/.bulletin-installed - A file to make sure install isn't run again.
	* ~/.config/BULLETIN/* - history files for each user.
	* ~/.ssh/authorized_keys - key lines to let users connect to BULLETIN

To complete the installation, please enter the login, name and ssh key for
the first user.
`)
	login, err := ask.GetLine("Enter login of initial user: ")
	login = strings.ToUpper(login)
	ask.CheckErr(err)
	name, err := ask.GetLine("Enter name of initial user: ")
	ask.CheckErr(err)
@@ -81,21 +90,38 @@ func Install() int {
	ask.CheckErr(err)

	// Seed data.
	seedMsgs, err := GetSeedMessages()
	ask.CheckErr(err)
	ask.CheckErr(q.SeedUserSystem(ctx))
	ask.CheckErr(q.SeedFolderGeneral(ctx))
	ask.CheckErr(q.SeedGeneralOwner(ctx))
	ask.CheckErr(q.SeedCreateMessage(ctx, storage.SeedCreateMessageParams{
		Folder:     "GENERAL",
		Folder_2:   "GENERAL",
		Subject:    "Announcing PFC BULLETIN 2.06",
		Message:    announce206,
		Expiration: time.Now(),
	}))
	_, err = q.AddUser(ctx, storage.AddUserParams{
		Login: login,
		Name:  name,
	})
	key.Add(login, sshkey)
	userCreated := map[string]bool{
		"SYSTEM": true,
		login:    true,
	}
	for i := range seedMsgs {
		if !userCreated[seedMsgs[i].Login] {
			_, err = q.AddUser(ctx, storage.AddUserParams{
				Login: seedMsgs[i].Login,
				Name:  seedMsgs[i].Name,
			})
			ask.CheckErr(err)
			userCreated[seedMsgs[i].Login] = true
		}
		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.Now(),
		}))
	}

	// Install crontab.
	bulletin, err := os.Executable()

batch/messages.go

0 → 100644
+95 −0
Original line number Diff line number Diff line
package batch

import (
	"embed"
	"fmt"
	"io/fs"
	"path"
	"strings"
	"time"
)

//go:embed seed/*
var messagesFS embed.FS

// SeedMessage is the struct version of the messages.
type SeedMessage struct {
	Login   string
	Name    string
	Date    time.Time
	Subject string
	Message string
}

// GetSeedMessages gets the embedded seed messages and returns them in
// a data structure.
func GetSeedMessages() ([]SeedMessage, error) {
	var messages []SeedMessage

	entries, err := fs.ReadDir(messagesFS, "seed")
	if err != nil {
		return nil, fmt.Errorf("reading directory: %w", err)
	}

	for _, entry := range entries {
		if entry.IsDir() {
			continue
		}

		data, err := fs.ReadFile(messagesFS, path.Join("seed", entry.Name()))
		if err != nil {
			return nil, fmt.Errorf("reading file %s: %w", entry.Name(), err)
		}

		lines := strings.Split(string(data), "\n")
		if len(lines) < 4 {
			continue // skip malformed
		}

		// Extract fields
		var login, name, subj string
		var date time.Time

		for i := 0; i < 3; i++ {
			line := strings.TrimSpace(lines[i])
			switch {
			case strings.HasPrefix(line, "From: "):
				rest := strings.TrimPrefix(line, "From: ")
				parts := strings.SplitN(rest, `"`, 2)
				if len(parts) == 2 {
					login = strings.TrimSpace(strings.TrimSuffix(parts[0], " "))
					name = strings.Trim(parts[1], `"`)
				} else {
					login = rest
				}
			case strings.HasPrefix(line, "Date: "):
				datestr := strings.TrimPrefix(line, "Date: ")
				// Expected format: 01-JAN-1982 12:00
				date, err = time.Parse("02-Jan-2006 15:04", datestr)
				if err != nil {
					return nil, fmt.Errorf("parsing date in %s: %w", entry.Name(), err)
				}
			case strings.HasPrefix(line, "Subj: "):
				subj = strings.TrimPrefix(line, "Subj: ")
			}
		}

		// Find start of message body
		bodyIndex := 3
		for bodyIndex < len(lines) && strings.TrimSpace(lines[bodyIndex]) != "" {
			bodyIndex++
		}
		body := strings.Join(lines[bodyIndex+1:], "\n")

		msg := SeedMessage{
			Login:   login,
			Name:    name,
			Date:    date,
			Subject: subj,
			Message: body,
		}
		messages = append(messages, msg)
	}

	return messages, nil
}
+56 −0
Original line number Diff line number Diff line
From: MRL "Mark R. London"
Date: 01-JAN-1982 12:00
Subj: BULLETIN utility.

                          BULLETIN

     BULLETIN provides an effective  means  for  the  system
managers  to  disseminate information to users in a friendly
fashion.

                          Features

      o  Bulletins of general interest can be  sent  to  all
         users
      o  Bulletins can be filed by subject  for  perusal  by
         interested users
      o  Users  are  presented  with  bulletins  only   once
         (unless they request old ones)
      o  Users  are   informed   of   new   information   on
         specialized topics only once
      o  Users may optionally file or print bulletins


                         Setting up

The nicest feature about bulletin is  its  friendly  nature.
Unwanted and indecipherable information is not forced down a
users' throats, but is there for any interested user.  Thus,
for  example,  if  you  file a bulletin under the subject of
PASCAL, all users will be informed (only once!)  that  there
is new information on PASCAL.  Interested users can read the
new bulletins, while those not using PASCAL can ignore them.
There  are  three things to set up for most effective use of
the program.

     1.  Put the BULLETIN help  file  in  your  system  help
         file:
          $  LIBR/HELP SYS$HELP:HELPLIB BULLETIN


     2.  If you have  a  system  wide  login.com  file,  you
         should enter the command:
         $ if "''f$mode()" .eqs.  "INTERACTIVE" then -
                 $bulletin
         If  you  enter   this   command   before   enabling
         control-Y,  this  will  force  users  to  read  new
         BULLETINS  filed   under   the   general   interest
         category.

     3.  Encourage  users  to  place   in   their   personal
         LOGIN.COM   files   BULLETIN   commands   to   read
         information on subjects of interest to them.


Refer to the first bulletin and the  HELP  BULLETIN  command
for more info.
+14 −0
Original line number Diff line number Diff line
From: MRL "Mark R. London"
Date: 01-JAN-1982 12:00
Subj: BULLETIN utility.


	Some users have missed bulletins of interest to them either because
they missed the announcement that there were new bulletins on a subject, or
for other reasons.  I am sending you a list of subjects which contain bull-
etins you have not read as of this mailing.  If you do not wish to read any
of them, please ignore this letter.   You may read new bulletins on a given
subject by typing "BULL/SUB=subject".   You should include this command for
subjects of interest in  your login command  file (login.com),  so that you
will always get the lastest information.
+27 −0
Original line number Diff line number Diff line
From: MRL "Mark R. London"
Date: 01-JAN-1982 12:00
Subj: BULLETIN utility.

This program displays bulletins of general interest.  You may  get  information
on  how to use it by typing "HELP BULLETIN".  When you log in, the program will
print messages you have not yet read (unless you ask  for  old  messages).   It
will  also  tell  you  when  new messages have been added on possible topics of
interest, but you must specifically ask to read these messages.  You  may  wish
to  put  "BULL/SUBJECT=subject"  in  your  login.com file for those subjects in
which you are interested.  Those subjects on which there are bulletins  can  be
listed by typing "BULL/DIRECTORY".

At the end of each message (as below), the program will  allow  you  to  select
various  options.   Typing "Go" will cause all messages to be displayed without
further interruption (except at the bottom of the screen).  Typing "Quit"  will
discontinue  the  bulletins, but they will all be typed again the next time you
login (or ask for bulletins).  Typing "File" will save the preceding message in
a  file  named  "AAASYSBUL.BUL" or "subject.BUL" on your login directory, while
typing "Print" will print the bulletin.  A carriage return will proceed to  the
next message.

                                  *** NOTE ***

Do not delete  your  file  SYS$LOGIN:SYSBULL.DAT!  This  file  remembers  which
bulletins  you  have  read  and  not  read.  Deleting it will cause BULLETIN to
recreate it next time, and assume you have read no bulletins!
Loading