Skip to content

Commit

Permalink
Add gorleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
willgorman committed May 30, 2021
1 parent da43c27 commit ac3fa9f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
40 changes: 40 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- env:
- CGO_ENABLED=1
goos:
- linux
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
nfpms:
- vendor: Coaxial Flutter Labs
maintainer: Will Gorman<will@coaxialflutter.com>
description: HTTP server for exporting metrics from Bluetooth sensors
formats:
- deb
- rpm
files:
"scripts/systemd/sensor-bridge.service": "/etc/systemd/system/sensor-bridge.service"
scripts:
postinstall: "scripts/systemd/postinstall.sh"
preremove: "scripts/systemd/preremove.sh"
1 change: 1 addition & 0 deletions govee.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (p H5102Parser) Parse(a ble.Advertisement) (*Reading, error) {
}, nil
}

// https://github.com/Home-Is-Where-You-Hang-Your-Hack/sensor.goveetemp_bt_hci
func decodeReading(a ble.Advertisement) (float32, float32, error) {
data := a.ManufacturerData()[4:7]
hex := fmt.Sprintf("%X", data)
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func init() {
viper.AutomaticEnv()
viper.SetDefault("Scanner.Duration", 15*time.Second)
viper.SetDefault("Scanner.Interval", 5*time.Minute)
viper.SetDefault("prometheus.port", 2112)
viper.AddConfigPath("/etc/sensor-bridge")
viper.AddConfigPath("$HOME/.sensorbridge")
viper.AddConfigPath(".")
viper.SetConfigName("config")
Expand Down Expand Up @@ -206,7 +208,7 @@ func main() {
}

http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":2112", nil)
go http.ListenAndServe(fmt.Sprintf(":%d", viper.GetInt("prometheus.port")), nil)

go func() {
for {
Expand Down
4 changes: 4 additions & 0 deletions scripts/systemd/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

systemctl enable sensor-bridge
systemctl restart sensor-bridge
6 changes: 6 additions & 0 deletions scripts/systemd/preremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

systemctl stop sensor-bridge
systemctl disable sensor-bridge

rm -rf /etc/sensor-bridge
8 changes: 8 additions & 0 deletions scripts/systemd/sensor-bridge.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Bluetooth Sensor Bridge Service

[Service]
ExecStart=/usr/local/bin/sensor-bridge

[Install]
WantedBy=multi-user.target

0 comments on commit ac3fa9f

Please sign in to comment.