Compare commits
1 Commits
2a5c5428d0
...
12ae1616ec
Author | SHA1 | Date | |
---|---|---|---|
12ae1616ec |
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
||||||
|
bin/
|
||||||
|
dist/
|
||||||
|
sonar.pi/
|
||||||
media/
|
media/
|
||||||
crontab.in/
|
crontab.in/
|
||||||
|
|
20
Makefile
20
Makefile
|
@ -18,6 +18,26 @@ build:
|
||||||
gofmt -w .
|
gofmt -w .
|
||||||
go build $(LDFLAGS) -i -o bin/sonar cmd/sonar/main.go
|
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.
|
# `make run` to run it in debug mode.
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run:
|
run:
|
||||||
|
|
25
README.md
25
README.md
|
@ -38,6 +38,16 @@ Example to start the playlist via `curl`:
|
||||||
$ curl -X POST http://localhost:8000/playlist/start
|
$ 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
|
# Crontab
|
||||||
|
|
||||||
The schedule system installs into the user's local crontab. The cron entries
|
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
|
# License
|
||||||
|
|
||||||
Noah Petherbridge © 2018
|
Noah Petherbridge © 2018
|
||||||
|
|
|
@ -2,25 +2,38 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kirsle.net/apps/sonar"
|
"git.kirsle.net/apps/sonar"
|
||||||
"github.com/kirsle/golog"
|
"github.com/kirsle/golog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Build hash.
|
||||||
|
var Build = "N/A"
|
||||||
|
|
||||||
var debug bool
|
var debug bool
|
||||||
var listen string
|
var listen string
|
||||||
|
var version bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
flag.StringVar(&listen, "listen", "127.0.0.1:8000", "Interface to listen on, default localhost only")
|
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(&debug, "debug", false, "Debug level logging")
|
||||||
|
flag.BoolVar(&version, "version", false, "Version number")
|
||||||
|
flag.BoolVar(&version, "v", false, "Version number (alias)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if version {
|
||||||
|
fmt.Printf("sonar v%s build %s\n", sonar.Version, Build)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
log := golog.GetLogger("sonar")
|
log := golog.GetLogger("sonar")
|
||||||
log.Config.Level = golog.DebugLevel
|
log.Config.Level = golog.DebugLevel
|
||||||
|
|
|
@ -75,6 +75,7 @@ func LoadConfig() *Config {
|
||||||
}
|
}
|
||||||
defer fh.Close()
|
defer fh.Close()
|
||||||
|
|
||||||
|
log.Info("Reading config from %s", filepath)
|
||||||
var c *Config
|
var c *Config
|
||||||
decoder := json.NewDecoder(fh)
|
decoder := json.NewDecoder(fh)
|
||||||
decoder.Decode(&c)
|
decoder.Decode(&c)
|
||||||
|
|
6
etc/supervisor.conf
Normal file
6
etc/supervisor.conf
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[program:sonar]
|
||||||
|
command = /home/kirsle/sonar.pi/sonar
|
||||||
|
directory = /home/kirsle/sonar.pi
|
||||||
|
user = kirsle
|
||||||
|
|
||||||
|
# vim:ft=dosini
|
|
@ -19,8 +19,6 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1>time.caskir.net</h1>
|
|
||||||
|
|
||||||
{{ range .Flashes }}
|
{{ range .Flashes }}
|
||||||
<div class="alert alert-info">{{ . }}</div>
|
<div class="alert alert-info">{{ . }}</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -60,7 +58,7 @@
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
Alan Watts Alarm Clock
|
Alarm Clock Playlist
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p>
|
<p>
|
||||||
|
@ -93,7 +91,7 @@
|
||||||
<form method="POST" action="/playlist/schedule">
|
<form method="POST" action="/playlist/schedule">
|
||||||
|
|
||||||
<label for="time">Time:</label>
|
<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>
|
<label>Days of week:</label>
|
||||||
<ul class="list-unstyled">
|
<ul class="list-unstyled">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user