Compare commits

...

18 Commits

Author SHA1 Message Date
cee0af195e
Running dpkg-source is not necessary 2021-04-10 04:03:01 +00:00
01a0601652
Suppress make clean rm errors when files are missing 2021-04-10 04:03:00 +00:00
ffe2c08a35
Ignore the build directory 2021-04-10 04:03:00 +00:00
5b1bdefacd
Make RPM package 2021-04-10 04:02:59 +00:00
d38a5df36f
Clean up Debian artifacts 2021-04-10 04:02:59 +00:00
55dd8d743d
Move Debian packages to root of build directory 2021-04-10 04:02:59 +00:00
7e6249bc3c
Improve Debian packaging by creating a source package 2021-04-10 03:02:08 +00:00
adbda33078
Separate make and build in Debian package 2021-04-10 02:54:50 +00:00
693ac6e677
Generate Debian package from template
Refs #7
2021-04-09 00:19:56 +00:00
953b1009d3
Fix PREFIX AND DESTDIR
Refs #7
2021-04-09 00:19:50 +00:00
11053571d5
Move debian files
Refs #7
2021-04-09 00:19:38 +00:00
86720c72f9
Initial Debian package
Refs #7
2021-04-08 05:38:02 +00:00
0df1524976
Use PREFIX and DESTDIR for make install
Refs #7
2021-04-08 05:37:54 +00:00
965b1b4339
Don't get LDFLAGS from the environment
Refs #7
2021-04-08 05:37:37 +00:00
a9936a0f1b
Add make install 2021-04-07 01:38:00 +00:00
c229df8506
Change Makefile variable make 2021-04-07 01:37:19 +00:00
9c92d7945d
Add visual power indicator character 2021-04-04 23:34:52 +00:00
a4c305c2e9
Fix bug where configuration is being overridden by a default configuration 2021-04-04 22:53:35 +00:00
10 changed files with 159 additions and 13 deletions

3
.gitignore vendored
View File

@ -21,3 +21,6 @@
.vscode/configurationCache.log .vscode/configurationCache.log
.vscode/dryrun.log .vscode/dryrun.log
.vscode/targets.log .vscode/targets.log
# packaging
/build

View File

@ -1,29 +1,95 @@
V ?= 0 V ?= 0
Q = $(if $(filter 1, $V),, @) Q = $(if $(filter 1, $V),, @)
BINDIR=$(CURDIR)/bin
PREFIX=/usr
DESTDIR=bin
BUILDDIR=$(CURDIR)/build
BIN_DIR=./bin DEBBUILDDIR=$(BUILDDIR)/deb
DEBTMPLDIR=$(CURDIR)/packaging/debian
DEBDATE=$(shell date -R)
DEBORIGSRC=lume_$(DEBVERSION).orig.tar.xz
DEBORIGSRCDIR=lume-$(DEBVERSION)
RPMVERSION=$(subst -,_,$(LUME_VERSION))
RPMBUILDDIR=$(BUILDDIR)/rpm
RPMTMPLDIR=$(CURDIR)/packaging/rpm
RPMDATE=$(shell date "+%a %b %d %Y")
RPMORIGSRC=lume-$(RPMVERSION).tar.xz
RPMORIGSRCDIR=lume-$(RPMVERSION)
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
EXE=$(BIN_DIR)/lume.exe EXE=$(BINDIR)/lume.exe
RM=del /f /q RM=del /f /q
BUILD_DATE=$(shell powershell Get-Date -Format "yyyy-MM-ddThh:mm:sszzz") BUILD_DATE=$(shell powershell Get-Date -Format "yyyy-MM-ddThh:mm:sszzz")
else else
EXE=$(BIN_DIR)/lume EXE=$(BINDIR)/lume
RM=rm -f RM=rm -f
BUILD_DATE=$(shell date --iso-8601=seconds) BUILD_DATE=$(shell date --iso-8601=seconds)
endif endif
LUME_VERSION ?= $(shell git describe --tags --always) LUME_VERSION ?= $(shell git describe --tags --always)
GIT_COMMIT := $(shell git rev-parse --short HEAD) GIT_COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := $(LDFLAGS) \ GIT_TAG=$(shell git describe --tags --abbrev=0)
LDFLAGS = \
-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \ -X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \
-X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE) \ -X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE) \
-X git.kill0.net/chill9/lume/cmd.GitCommit=$(GIT_COMMIT) -X git.kill0.net/chill9/lume/cmd.GitCommit=$(GIT_COMMIT)
ifneq (,$(findstring -,$(LUME_VERSION)))
DEBVERSION=$(GIT_TAG)+git$(shell date +%Y%m%d)+$(GIT_COMMIT)
else
DEBVERSION=$(LUME_VERSION)
endif
.PHONY: build .PHONY: build
build: build:
$(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume $(Q) go build -o $(EXE) -ldflags="$(LDFLAGS)" ./cmd/lume
.PHONY: clean .PHONY: clean
clean: clean: deb-clean rpm-clean
$(Q) $(RM) $(EXE) $(Q) $(RM) $(EXE)
.PHONY: install
install:
$(Q) install -p -D -m 0755 $(EXE) $(DESTDIR)${PREFIX}/bin/lume
$(Q) install -p -D -m 0644 .lumerc.sample $(DESTDIR)${PREFIX}/share/lume/lumerc
.PHONY: deb
deb:
$(Q) mkdir -p $(DEBBUILDDIR)
$(Q) git archive --format tar --prefix lume-$(DEBVERSION)/ $(LUME_VERSION) | xz > $(DEBBUILDDIR)/$(DEBORIGSRC)
$(Q) tar xf $(DEBBUILDDIR)/$(DEBORIGSRC) -C $(DEBBUILDDIR)
$(Q) mkdir $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian
$(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' $(DEBTMPLDIR)/rules > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/rules
$(Q) sed -e 's/__VERSION__/$(DEBVERSION)/g' -e 's/__DATE__/$(DEBDATE)/g' $(DEBTMPLDIR)/changelog > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/changelog
$(Q) echo 9 > $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/compat
$(Q) cp $(DEBTMPLDIR)/control $(DEBBUILDDIR)/$(DEBORIGSRCDIR)/debian/control
$(Q) cd $(DEBBUILDDIR)/$(DEBORIGSRCDIR) && dpkg-buildpackage -us -uc
$(Q) mv $(DEBBUILDDIR)/*.dsc $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.changes $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.buildinfo $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.deb $(BUILDDIR)
$(Q) mv $(DEBBUILDDIR)/*.tar.* $(BUILDDIR)
.PHONY: rpm
rpm:
$(Q) mkdir -p $(RPMBUILDDIR)/SPECS
$(Q) mkdir -p $(RPMBUILDDIR)/SOURCES
$(Q) sed -e 's/__VERSION__/$(RPMVERSION)/g' -e 's/__DATE__/$(RPMDATE)/g' $(RPMTMPLDIR)/lume.spec > $(RPMBUILDDIR)/SPECS/lume.spec
$(Q) git archive --format tar --prefix $(RPMORIGSRCDIR)/ $(LUME_VERSION) | xz > $(RPMBUILDDIR)/SOURCES/$(RPMORIGSRC)
$(Q) rpmbuild --define "_topdir $(RPMBUILDDIR)" -ba $(RPMBUILDDIR)/SPECS/lume.spec
$(Q) mv $(RPMBUILDDIR)/RPMS/*/*.rpm $(BUILDDIR)
$(Q) mv $(RPMBUILDDIR)/SRPMS/*.rpm $(BUILDDIR)
deb-clean:
$(Q) rm -rf $(DEBBUILDDIR)
$(Q) rm -f $(BUILDDIR)/*.dsc
$(Q) rm -f $(BUILDDIR)/*.changes
$(Q) rm -f $(BUILDDIR)/*.buildinfo
$(Q) rm -f $(BUILDDIR)/*.deb
$(Q) rm -f $(BUILDDIR)/*.tar.*
rpm-clean:
$(Q) rm -rf $(RPMBUILDDIR)
$(Q) rm -f $(BUILDDIR)/*.rpm

View File

@ -12,6 +12,7 @@ import (
const lumercFile string = ".lumerc" const lumercFile string = ".lumerc"
const lumeConfigFile string = "lume.conf" const lumeConfigFile string = "lume.conf"
const defaultPowerIndicator rune = '●'
type Config struct { type Config struct {
AccessToken string `toml:"access_token"` AccessToken string `toml:"access_token"`
@ -19,6 +20,7 @@ type Config struct {
Colors map[string][]float32 `toml:"colors"` Colors map[string][]float32 `toml:"colors"`
userAgent string userAgent string
Debug bool `toml:"debug"` Debug bool `toml:"debug"`
Indicator string `toml:"indicator"`
} }
var ( var (
@ -33,6 +35,7 @@ func NewConfig() *Config {
c.userAgent = initUserAgent() c.userAgent = initUserAgent()
c.Debug = false c.Debug = false
c.OutputFormat = "simple" c.OutputFormat = "simple"
c.Indicator = string(defaultPowerIndicator)
return c return c
} }
@ -48,6 +51,10 @@ func (c *Config) Validate() error {
return errors.New("access_token is not set") return errors.New("access_token is not set")
} }
if len([]rune(c.Indicator)) != 1 {
return errors.New("indicator must be a single rune")
}
if err = c.validateColors(); err != nil { if err = c.validateColors(); err != nil {
return err return err
} }
@ -87,8 +94,6 @@ func LoadConfig(s string) (*Config, error) {
var err error var err error
var c *Config = GetConfig() var c *Config = GetConfig()
*c = DefaultConfig
if _, err := toml.Decode(s, &c); err != nil { if _, err := toml.Decode(s, &c); err != nil {
err = fmt.Errorf("fatal: failed to parse; %w", err) err = fmt.Errorf("fatal: failed to parse; %w", err)
} }
@ -101,8 +106,6 @@ func LoadConfigFile(configPath string) (*Config, error) {
var c *Config = GetConfig() var c *Config = GetConfig()
*c = DefaultConfig
if _, err := toml.DecodeFile(configPath, &c); err != nil { if _, err := toml.DecodeFile(configPath, &c); err != nil {
err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err) err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err)
} }

View File

@ -102,6 +102,15 @@ func (tp *tablePrinter) Lights(lights []lifx.Light) {
table.Render() table.Render()
} }
func ColorizeIndicator(s string) string {
c := color.New(color.FgRed)
if s == "on" {
c = color.New(color.FgGreen)
}
return c.Sprint(GetConfig().Indicator)
}
func ColorizePower(s string) string { func ColorizePower(s string) string {
c := color.New(color.FgRed) c := color.New(color.FgRed)
if s == "on" { if s == "on" {
@ -130,10 +139,11 @@ func PrintfWithIndent(indent int, format string, a ...interface{}) (n int, err e
} }
func makeLightsTable(lights []lifx.Light) (hdr []string, rows [][]string) { func makeLightsTable(lights []lifx.Light) (hdr []string, rows [][]string) {
hdr = []string{"ID", "Location", "Group", "Label", "Last Seen", "Power"} hdr = []string{"", "ID", "Location", "Group", "Label", "Last Seen", "Power"}
for _, l := range lights { for _, l := range lights {
rows = append(rows, []string{ rows = append(rows, []string{
fmt.Sprint(ColorizeIndicator(l.Power)),
fmt.Sprint(l.Id), fmt.Sprint(l.Id),
fmt.Sprint(l.Location.Name), fmt.Sprint(l.Location.Name),
fmt.Sprint(l.Group.Name), fmt.Sprint(l.Group.Name),

View File

@ -39,12 +39,13 @@ func ShowCmd(ctx Context) (int, error) {
for i, l := range lights { for i, l := range lights {
indent = 0 indent = 0
fmt.Printf( fmt.Printf(
"Light ID: %s, %s, Power: %s\n", "%s Light ID: %s, %s, Power: %s\n",
ColorizeIndicator(l.Power),
l.Id, l.Id,
connected(l.Connected), connected(l.Connected),
ColorizePower(l.Power), ColorizePower(l.Power),
) )
indent += Tabstop indent += Tabstop + 2
PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id) PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id)
PrintfWithIndent(indent, "UUID: %s\n", l.UUID) PrintfWithIndent(indent, "UUID: %s\n", l.UUID)
PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id) PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id)

View File

@ -0,0 +1,5 @@
lume (__VERSION__) UNRELEASED; urgency=medium
* Package generated with make deb
-- Ryan Cavicchioni <ryan@cavi.cc> __DATE__

1
packaging/debian/compat Normal file
View File

@ -0,0 +1 @@
9

7
packaging/debian/control Normal file
View File

@ -0,0 +1,7 @@
Source: lume
Maintainer: Ryan Cavicchioni <ryan@cavi.cc>
Package: lume
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: A CLI tool for the LIFX HTTP API

18
packaging/debian/rules Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/make -f
DISTRIBUTION = $(shell lsb_release -sr)
VERSION = __VERSION__
PACKAGEVERSION = $(VERSION)
%:
dh $@
override_dh_auto_clean:
override_dh_auto_test:
override_dh_auto_build:
make
override_dh_auto_install:
make install DESTDIR=debian/lume
override_dh_gencontrol:
dh_gencontrol -- -v$(PACKAGEVERSION)

32
packaging/rpm/lume.spec Normal file
View File

@ -0,0 +1,32 @@
Name: lume
Version: __VERSION__
Release: 1%{?dist}
Summary: A CLI tool for the LIFX HTTP API
License: MPL
URL: https://git.kill0.net/chill9/lume
Source: %{name}-%{version}.tar.xz
%global debug_package %{nil}
%description
%prep
%setup
%build
%make_build
%install
%make_install DESTDIR=%{buildroot}
%files
%{_bindir}/lume
%license LICENSE
/usr/share/lume/lumerc
%changelog
* __DATE__ Ryan Cavicchioni <ryan@cavi.cc>
- lume __VERSION__