Select Git revision
signer_test.go
-
Niall Sheridan authoredNiall Sheridan authored
batch.go 2.39 KiB
// Package batch contains the non-interactive maintenence commands.
package batch
import (
"context"
_ "embed"
"errors"
"fmt"
"os"
"path"
"strings"
"text/template"
"git.lyda.ie/kevin/bulletin/ask"
"git.lyda.ie/kevin/bulletin/key"
"git.lyda.ie/kevin/bulletin/storage"
"github.com/adrg/xdg"
)
//go:embed crontab
var crontabTemplate string
// Reboot deletes all messages with `shutdown` set.
func Reboot() int {
fmt.Println("TODO: Delete messages with shutdown != 0.")
return 0
}
// Expire deletes all messages that have hit their expiration date.
func Expire() int {
fmt.Println("TODO: expire messages.")
return 0
}
// Install is an interactive command used to install the crontab.
func Install() int {
// Check if install has run before.
touchfile := path.Join(xdg.Home, ".bulletin-installed")
if _, err := os.Stat(touchfile); err == nil {
ask.CheckErr(errors.New("~/.bulletin-installed exists; BULLETIN install has run"))
} else {
if !errors.Is(err, os.ErrNotExist) {
fmt.Println("ERROR: Unknown error checking in ~/.bulletin-installed exists.")
fmt.Println("ERROR: Can't see if BULLETIN has been installed.")
ask.CheckErr(err)
}
}
// Connect to the database.
store, err := storage.Open()
ask.CheckErr(err)
q := storage.New(store.DB)
// Create the initial users.
login, err := ask.GetLine("Enter login of initial user: ")
ask.CheckErr(err)
name, err := ask.GetLine("Enter name of initial user: ")
ask.CheckErr(err)
sshkey, err := ask.GetLine("Enter ssh public key of initial user: ")
ask.CheckErr(err)
// Seed data.
ctx := context.TODO()
ask.CheckErr(q.SeedUserSystem(ctx))
ask.CheckErr(q.SeedFolderGeneral(ctx))
ask.CheckErr(q.SeedGeneralOwner(ctx))
_, err = q.AddUser(ctx, storage.AddUserParams{
Login: login,
Name: name,
})