Compare commits

..

1 Commits

Author SHA1 Message Date
Noah 12ae1616ec Crontab installation support 2018-10-24 13:44:22 -07:00
7 changed files with 70 additions and 4 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
bin/
dist/
sonar.pi/
media/
crontab.in/

View File

@ -18,6 +18,26 @@ build:
gofmt -w .
go build $(LDFLAGS) -i -o bin/sonar cmd/sonar/main.go
# `make dist` makes a distribution bundle.
.PHONY: dist
dist:
rm -rf dist
mkdir dist
cp -r crontab.in www dist/
go build $(LDFLAGS) -i -o dist/sonar cmd/sonar/main.go
cd dist
tar -czvf sonar-$(VERSION).tar.gz *
mv *.tar.gz ../
# `make pi` makes a distribution for the Raspberry Pi.
.PHONY: pi
pi:
rm -rf sonar.pi
mkdir sonar.pi
cp -r crontab.in www sonar.pi/
GOOS=linux GOARCH=arm go build $(LDFLAGS) -i -o sonar.pi/sonar cmd/sonar/main.go
zip -r sonar-pi.zip sonar.pi
# `make run` to run it in debug mode.
.PHONY: run
run:

View File

@ -38,6 +38,16 @@ Example to start the playlist via `curl`:
$ curl -X POST http://localhost:8000/playlist/start
```
# Makefile
* `make setup` to fetch dependencies.
* `make build` to build the binary to `bin/`
* `make dist` to build a distribution for your current setup
* `make run` to run it in debug mode
* `make watch` to run it in debug mode, auto-reloading (sometimes flaky control over mplayer tho!)
* `make pi` to build a zipped distribution for Raspberry Pi.
See [Cross Compile for Raspberry Pi](#cross-compile-for-raspberry-pi)
# Crontab
The schedule system installs into the user's local crontab. The cron entries
@ -111,6 +121,21 @@ A default config file looks like this, annotated:
}
```
## Cross Compile for Raspberry Pi
Use the `make pi` command to build a distribution for Raspberry Pi.
If you get permission errors when trying to download the standard library for
ARM64, make and chown the folders as a workaround:
```bash
sudo mkdir /usr/lib/golang/pkg/linux_arm
sudo chown kirsle:kirsle /usr/lib/golang/pkg/linux_arm
make pi
```
It outputs a `sonar-pi.zip` that you can scp over and run.
# License
Noah Petherbridge © 2018

View File

@ -2,25 +2,38 @@ package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
"git.kirsle.net/apps/sonar"
"github.com/kirsle/golog"
)
// Build hash.
var Build = "N/A"
var debug bool
var listen string
var version bool
func init() {
rand.Seed(time.Now().UnixNano())
flag.StringVar(&listen, "listen", "127.0.0.1:8000", "Interface to listen on, default localhost only")
flag.BoolVar(&debug, "debug", false, "Debug level logging")
flag.BoolVar(&version, "version", false, "Version number")
flag.BoolVar(&version, "v", false, "Version number (alias)")
}
func main() {
flag.Parse()
if version {
fmt.Printf("sonar v%s build %s\n", sonar.Version, Build)
os.Exit(0)
}
if debug {
log := golog.GetLogger("sonar")
log.Config.Level = golog.DebugLevel

View File

@ -75,6 +75,7 @@ func LoadConfig() *Config {
}
defer fh.Close()
log.Info("Reading config from %s", filepath)
var c *Config
decoder := json.NewDecoder(fh)
decoder.Decode(&c)

6
etc/supervisor.conf Normal file
View File

@ -0,0 +1,6 @@
[program:sonar]
command = /home/kirsle/sonar.pi/sonar
directory = /home/kirsle/sonar.pi
user = kirsle
# vim:ft=dosini

View File

@ -19,8 +19,6 @@
<div class="container">
<div class="row">
<div class="col">
<h1>time.caskir.net</h1>
{{ range .Flashes }}
<div class="alert alert-info">{{ . }}</div>
{{ end }}
@ -60,7 +58,7 @@
<div class="col">
<div class="card mb-4">
<div class="card-header">
Alan Watts Alarm Clock
Alarm Clock Playlist
</div>
<div class="card-body">
<p>
@ -93,7 +91,7 @@
<form method="POST" action="/playlist/schedule">
<label for="time">Time:</label>
<input type="time" name="time" class="form-control mb-2" value="{{ .Hour }}:{{ .Minute }}">
<input type="time" name="time" class="form-control mb-2" value="{{ printf "%02d" .Hour }}:{{ .Minute }}">
<label>Days of week:</label>
<ul class="list-unstyled">