17 Commits

Author SHA1 Message Date
b186f77bea Remove replace directive 2021-08-22 15:07:45 -07:00
adb297c6dd Fix find and replace error 2021-08-22 13:53:32 -07:00
b4992cb393 Update infinitime library to fix connection bug 2021-08-22 13:13:37 -07:00
a5490b8364 Use new pair timeout option 2021-08-21 20:35:21 -07:00
44d1f5552b Mention interactive mode in readme 2021-08-21 19:07:59 -07:00
5e34f656b3 Disable completion command 2021-08-21 19:03:18 -07:00
560d19860e Fix binary download link 2021-08-21 18:52:11 -07:00
ea1a7fa9f4 Add badges 2021-08-21 18:48:43 -07:00
81fe634ed8 Add uninstall rule to makefile 2021-08-21 17:17:25 -07:00
281e1dcbac Add CI status to readme 2021-08-21 16:36:10 -07:00
4847eee540 Add GOFLAGS environment variable to makefile 2021-08-21 16:03:54 -07:00
19caa3ee83 Add gitm for mirroring 2021-08-21 15:59:19 -07:00
e523a024ec Specify minimum go version in readme 2021-08-21 15:35:36 -07:00
4a3dff646c Add starting to readme 2021-08-21 15:14:37 -07:00
986d2064a7 Change recoverable errors to warn log level to stop shell from exiting 2021-08-21 14:15:55 -07:00
95cf5bfe6b Add interactive mode to itctl 2021-08-21 12:30:16 -07:00
0d70dd9b11 Prioritize config in home directory over /etc 2021-08-21 10:26:12 -07:00
10 changed files with 114 additions and 24 deletions

3
.gitm.toml Normal file
View File

@@ -0,0 +1,3 @@
[repos]
origin = "ssh://git@192.168.100.62:2222/Arsen6331/itd.git"
gitlab = "git@gitlab.com:moussaelianarsen/itd.git"

View File

@@ -4,8 +4,12 @@ SERVICE_PREFIX = $(DESTDIR)$(PREFIX)/lib/systemd/user
CFG_PREFIX = $(DESTDIR)/etc
all:
go build
go build ./cmd/itctl
go build $(GOFLAGS)
go build ./cmd/itctl $(GOFLAGS)
clean:
rm -f itctl
rm -f itd
install:
install -Dm755 ./itd $(BIN_PREFIX)/itd
@@ -13,8 +17,10 @@ install:
install -Dm644 ./itd.service $(SERVICE_PREFIX)/itd.service
install -Dm644 ./itd.toml $(CFG_PREFIX)/itd.toml
clean:
rm -f itctl
rm -f itd
uninstall:
rm $(BIN_PREFIX)/itd
rm $(BIN_PREFIX)/itctl
rm $(SERVICE_PREFIX)/itd.service
rm $(CFG_PREFIX)/itd.toml
.PHONY: all install clean
.PHONY: all clean install uninstall

View File

@@ -3,6 +3,10 @@
`itd` is a daemon that uses my infinitime [library](https://go.arsenm.dev/infinitime) to interact with the [PineTime](https://www.pine64.org/pinetime/) running [InfiniTime](https://infinitime.io).
[![Build status](https://ci.appveyor.com/api/projects/status/xgj5sobw76ndqaod?svg=true)](https://ci.appveyor.com/project/moussaelianarsen/itd)
[![Binary downloads](https://img.shields.io/badge/download-binary-orange)](https://minio.arsenm.dev/minio/itd/)
[![AUR package](https://img.shields.io/aur/version/itd-git?label=itd-git&logo=archlinux)](https://aur.archlinux.org/packages/itd-git/)
---
### Features
@@ -56,11 +60,29 @@ Flags:
Use "itctl [command] --help" for more information about a command.
```
#### Interactive mode
Running `itctl` by itself will open interactive mode. It's essentially a shell where you can enter commands. For example:
```
$ itctl
itctl> fw ver
1.3.0
itctl> get batt
81%
itctl> get heart
92 BPM
itctl> set time 2021-08-22T00:06:18-07:00
itctl> set time now
itctl> exit
```
---
### Installation
To install, install the go compiler and make. Usually, go is provided by a package either named `go` or `golang`, and make is usually provided by `make`.
To install, install the go compiler and make. Usually, go is provided by a package either named `go` or `golang`, and make is usually provided by `make`. The go compiler must be version 1.16 or newer for the `io/fs` module.
To install, run
```shell
@@ -69,6 +91,21 @@ make && sudo make install
---
### Starting
To start the daemon, run the following **without root**:
```shell
systemctl --user start itd
```
To autostart on login, run:
```shell
systemctl --user enable itd
```
---
### Cross compiling
To cross compile, simply set the go environment variables. For example, for PinePhone, use:

View File

@@ -19,6 +19,7 @@
package cmd
import (
"github.com/abiosoft/ishell"
"github.com/spf13/cobra"
)
@@ -26,10 +27,39 @@ import (
var rootCmd = &cobra.Command{
Use: "itctl",
Short: "Control the itd daemon for InfiniTime smartwatches",
Run: func(cmd *cobra.Command, args []string) {
// Create new shell
sh := ishell.New()
sh.SetPrompt("itctl> ")
// For every command in cobra
for _, subCmd := range cmd.Commands() {
// Add top level command to ishell
sh.AddCmd(&ishell.Cmd{
Name: subCmd.Name(),
Help: subCmd.Short,
Aliases: subCmd.Aliases,
LongHelp: subCmd.Long,
Func: func(ctx *ishell.Context) {
// Append name and arguments of command
args := append([]string{ctx.Cmd.Name}, ctx.Args...)
// Set root command arguments
cmd.SetArgs(args)
// Execute root command with new arguments
cmd.Execute()
},
})
}
// Start shell
sh.Run()
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
rootCmd.CompletionOptions.DisableDefaultCmd = true
cobra.CheckErr(rootCmd.Execute())
}

View File

@@ -36,7 +36,8 @@ var timeCmd = &cobra.Command{
// Ensure required arguments
if len(args) != 1 {
cmd.Usage()
log.Fatal().Msg("Command time requires one argument")
log.Warn().Msg("Command time requires one argument")
return
}
// Connect to itd UNIX socket

View File

@@ -60,7 +60,8 @@ var upgradeCmd = &cobra.Command{
}
} else {
cmd.Usage()
log.Fatal().Msg("Upgrade command requires either archive or init packet and firmware.")
log.Warn().Msg("Upgrade command requires either archive or init packet and firmware.")
return
}
// Encode response into connection

5
go.mod
View File

@@ -4,8 +4,11 @@ go 1.16
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/abiosoft/ishell v2.0.0+incompatible
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db // indirect
github.com/cheggaaa/pb/v3 v3.0.8
github.com/fatih/color v1.12.0 // indirect
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/fsnotify/fsnotify v1.5.0 // indirect
github.com/godbus/dbus/v5 v5.0.4
github.com/mattn/go-isatty v0.0.13 // indirect
@@ -16,7 +19,7 @@ require (
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
go.arsenm.dev/infinitime v0.0.0-20210821070429-ea488067fb9b
go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609
golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55 // indirect
golang.org/x/text v0.3.7 // indirect
)

12
go.sum
View File

@@ -42,6 +42,10 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/abiosoft/ishell v2.0.0+incompatible h1:zpwIuEHc37EzrsIYah3cpevrIc8Oma7oZPxr03tlmmw=
github.com/abiosoft/ishell v2.0.0+incompatible/go.mod h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg=
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db h1:CjPUSXOiYptLbTdr1RceuZgSFDQ7U15ITERUGrUORx8=
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod h1:rB3B4rKii8V21ydCbIzH5hZiCQE7f5E9SzUb/ZZx530=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
@@ -51,8 +55,10 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
@@ -77,6 +83,8 @@ github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BMXYYRWTLOJKlh+lOBt6nUQgXAfB7oVIQt5cNreqSLI=
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.0 h1:NO5hkcB+srp1x6QmwvNZLeaOgbM8cmBTN32THzjvu2k=
github.com/fsnotify/fsnotify v1.5.0/go.mod h1:BX0DCEr5pT4jm2CnQdVP1lFV521fcCNcyEeNp4DQQDk=
@@ -279,8 +287,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.arsenm.dev/infinitime v0.0.0-20210821070429-ea488067fb9b h1:Wwj7F0gqYHUx+9H8fCCIy5JZTlCusJRpPuzeSFM0EoU=
go.arsenm.dev/infinitime v0.0.0-20210821070429-ea488067fb9b/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q=
go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609 h1:QH7hsVjulEs1OP8lcQ7EfVy2UO/rtwRsxUo3ylde83E=
go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q=
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

View File

@@ -36,8 +36,8 @@ func init() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
// Set config settings
viper.AddConfigPath("/etc")
viper.AddConfigPath("$HOME/.config")
viper.AddConfigPath("/etc")
viper.SetConfigName("itd")
viper.SetConfigType("toml")
viper.WatchConfig()

View File

@@ -51,7 +51,7 @@ const (
)
func startSocket(dev *infinitime.Device) error {
// Make socket directory if non existant
// Make socket directory if non-existent
err := os.MkdirAll(filepath.Dir(SockPath), 0755)
if err != nil {
return err
@@ -149,14 +149,14 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
case ReqTypeNotify:
// If no data, return error
if req.Data == nil {
connErr(conn, nil, "Data required for notify types.Request")
connErr(conn, nil, "Data required for notify request")
break
}
var reqData types.ReqDataNotify
// Decode data map to notify types.Request data
// Decode data map to notify request data
err = mapstructure.Decode(req.Data, &reqData)
if err != nil {
connErr(conn, err, "Error decoding types.Request data")
connErr(conn, err, "Error decoding request data")
break
}
// Send notification to watch
@@ -170,13 +170,13 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
case ReqTypeSetTime:
// If no data, return error
if req.Data == nil {
connErr(conn, nil, "Data required for settime types.Request")
connErr(conn, nil, "Data required for settime request")
break
}
// Get string from data or return error
reqTimeStr, ok := req.Data.(string)
if !ok {
connErr(conn, nil, "Data for settime types.Request must be RFC3339 formatted time string")
connErr(conn, nil, "Data for settime request must be RFC3339 formatted time string")
break
}
@@ -184,7 +184,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
if reqTimeStr == "now" {
reqTime = time.Now()
} else {
// Parse time as RFC3339/ISO9601
// Parse time as RFC3339/ISO8601
reqTime, err = time.Parse(time.RFC3339, reqTimeStr)
if err != nil {
connErr(conn, err, "Invalid time format. Time string must be formatted as ISO8601 or the word `now`")
@@ -202,14 +202,14 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
case ReqTypeFwUpgrade:
// If no data, return error
if req.Data == nil {
connErr(conn, nil, "Data required for firmware upgrade types.Request")
connErr(conn, nil, "Data required for firmware upgrade request")
break
}
var reqData types.ReqDataFwUpgrade
// Decode data map to firmware upgrade types.Request data
// Decode data map to firmware upgrade request data
err = mapstructure.Decode(req.Data, &reqData)
if err != nil {
connErr(conn, err, "Error decoding types.Request data")
connErr(conn, err, "Error decoding request data")
break
}
switch reqData.Type {
@@ -272,6 +272,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
err = dev.DFU.Start()
if err != nil {
connErr(conn, err, "Error performing upgrade")
firmwareUpdating = false
break
}
firmwareUpdating = false