1
1
mirror of https://github.com/nboughton/dotfiles synced 2024-11-22 14:51:56 +01:00

use systemd timers to run package check services and poll output in tmp

This commit is contained in:
Nick Boughton 2020-12-09 15:07:18 +00:00
parent 81039fdaeb
commit 24da8e6983
14 changed files with 206 additions and 22 deletions

@ -86,7 +86,7 @@ exec /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
exec mako
exec nm-applet --indicator
exec gammastep-indicator
#exec insync start
exec insync start
### Window config
for_window [app_id=aptus-upgrade] floating enable
@ -98,7 +98,7 @@ for_window [app_id=ristretto] floating enable
for_window [app_id=ranger] floating enable
for_window [app_id=transmission-gtk] floating enable
for_window [app_id=io.github.celluloid_player.Celluloid] floating enable
for_window [app_id=".*"] border pixel 2
for_window [app_id=".*"] border pixel
### Key bindings
#

@ -28,6 +28,7 @@
"custom/separator",
"battery",
"custom/pacman",
"custom/aurcheck",
"clock"
],
"sway/workspaces": {
@ -122,13 +123,20 @@
"custom/pacman": {
"format": " {}",
"return-type": "json",
"interval": 3600, // every hour
"exec": "go run ~/.config/waybar/modules/updates/update-check.go",
"exec-if": "~/.config/waybar/modules/updates/update-run.sh",
"on-click": "~/.config/waybar/modules/updates/update-system.sh; pkill -RTMIN+8 waybar",
"interval": 5,
"exec": "cat ~/tmp/updates.json",
"exec-if": "exit 0",
"on-click": "~/.config/waybar/modules/updates/update-system.sh; systemctl --user restart updates.timer; pkill -RTMIN+8 waybar",
"signal": 8,
"tooltip": true
},
"custom/aurcheck": {
"format": " {}",
"return-type": "json",
"exec": "cat ~/tmp/aur-vcheck.json",
"interval": 5,
"tooltip": true
},
"custom/swap": {
"format": " {}",
"interval": 5,

@ -0,0 +1,117 @@
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"strings"
"github.com/esiqveland/notify"
"github.com/godbus/dbus/v5"
regex "github.com/nboughton/go-utils/regex/common"
)
type config struct {
Versions []string `json:"versions,omitempty"`
}
type jsonOutput struct {
Text string `json:"text,omitempty"`
Alt string `json:"alt,omitempty"`
Tooltip string `json:"tooltip,omitempty"`
Class string `json:"class,omitempty"`
Percentage int `json:"percentage,omitempty"`
}
var outfile = fmt.Sprintf("%s/tmp/aur-vcheck.json", os.Getenv(("HOME")))
func main() {
confPath := "config.json"
// Check for config path
if len(os.Args) > 1 {
confPath = os.Args[1]
}
// Read config
log.Println("Reading config")
f, err := os.Open(confPath)
if err != nil {
log.Fatalf("cannot open config: %s", err)
}
c := config{}
if err := json.NewDecoder(f).Decode(&c); err != nil {
log.Fatalf("failed to decode config: %s", err)
}
f.Close()
// Check Versions
log.Println("Checking versions")
out := []string{}
for _, appVer := range c.Versions {
app := fmt.Sprintf("@%s", strings.Split(appVer, "@")[1])
o, err := exec.Command("npm", "info", app).CombinedOutput()
if err != nil {
log.Fatalf("npm exec failed: %s", err)
}
v := regex.ANSI.ReplaceAllString(strings.Fields(strings.Split(string(o), "\n")[1])[0], "")
if appVer != v {
out = append(out, fmt.Sprintf("%s -> %s", appVer, v))
}
}
if len(out) > 0 {
log.Println("Connecting to DBUS")
conn, err := dbus.SessionBusPrivate()
if err != nil {
log.Fatal(err)
}
defer conn.Close()
if err = conn.Auth(nil); err != nil {
log.Fatal(err)
}
if err = conn.Hello(); err != nil {
log.Fatal(err)
}
// Send notification
log.Println("Sending notification")
notify.SendNotification(conn, notify.Notification{
AppName: "AUR VCHECK",
ReplacesID: uint32(0),
AppIcon: "mail-message-new",
Summary: "AUR NPM Packages Need Updating",
Body: strings.Join(out, "\n"),
Hints: map[string]dbus.Variant{},
ExpireTimeout: 10000,
})
}
// Write output for waybar module
n := len(out)
o := jsonOutput{
Text: fmt.Sprintf("%d", n),
Alt: fmt.Sprintf("%d", n),
Tooltip: strings.Join(out, "\n"),
}
if n > 0 {
o.Class = "updates"
o.Percentage = n
} else {
o.Class = "no-updates"
o.Percentage = 0
}
f, err = os.Create(outfile)
if err != nil {
log.Println(err)
return
}
json.NewEncoder(f).Encode(o)
f.Close()
}

@ -0,0 +1,8 @@
{
"versions": [
"@vue/cli@4.5.8",
"@vue/cli-service-global@4.5.8",
"@quasar/cli@1.1.2",
"@quasar/icongenie@2.3.3"
]
}

@ -0,0 +1,9 @@
module github.com/nboughton/dotfiles/waybar/modules/aur-vcheck
go 1.15
require (
github.com/esiqveland/notify v0.9.1
github.com/godbus/dbus/v5 v5.0.3
github.com/nboughton/go-utils v0.0.0-20200108161841-5007e997f484
)

@ -0,0 +1,7 @@
github.com/esiqveland/notify v0.9.1 h1:hX6ZD3FCQJXI46AzUM/iWekcMfnZ9TPE4uIu9Hrn1D4=
github.com/esiqveland/notify v0.9.1/go.mod h1:63UbVSaeJwF0LVJARHFuPgUAoM7o1BEvCZyknsuonBc=
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/nboughton/go-utils v0.0.0-20200108161841-5007e997f484 h1:mqED7SC5umrSOUC4eUleOuHUsrwvbVl/DQy+jVHFlvo=
github.com/nboughton/go-utils v0.0.0-20200108161841-5007e997f484/go.mod h1:iSex0rTt7j+NRoVAEwO0ADC0jkx53W/3OsbYgNMxSWU=

@ -0,0 +1,9 @@
[Unit]
Description=Check for new upstream AUR versions of maintained NPM packages
[Service]
User=nick
Type=oneshot
Environment=DISPLAY=:0.0
Environment=XAUTHORITY=/home/nick/.Xauthority
ExecStart=go run /home/nick/.config/waybar/modules/aur-vcheck/aur-vcheck.go /home/nick/.config/waybar/modules/aur-vcheck/config.json

@ -0,0 +1,9 @@
[Unit]
Description=Check for new upstream AUR versions of NPM packages
[Timer]
OnBootSec=15min
OnUnitActiveSec=1h
[Install]
WantedBy=timers.target

@ -0,0 +1,3 @@
module github.com/nboughton/dotfiles/waybar/modules/updates
go 1.15

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"strings"
@ -16,6 +17,8 @@ type jsonOutput struct {
Percentage int `json:"percentage,omitempty"`
}
var outfile = fmt.Sprintf("%s/tmp/updates.json", os.Getenv(("HOME")))
func main() {
o := jsonOutput{}
@ -52,7 +55,12 @@ func main() {
o.Percentage = n
}
json.NewEncoder(os.Stdout).Encode(o)
f, err := os.Create(outfile)
if err != nil {
log.Println(err)
}
json.NewEncoder(f).Encode(o)
f.Close()
}
func removeEmptyLines(list []string) []string {

@ -1,12 +0,0 @@
#!/bin/bash
pgrep checkupdates
pac=$?
pgrep yay
aur=$?
if [[ pac -eq 1 ]] && [[ aur -eq 1 ]]; then
exit 0
fi
exit 1

@ -0,0 +1,7 @@
[Unit]
Description=Check for Pacman and AUR/git package updates
[Service]
User=nick
Type=oneshot
ExecStart=go run /home/nick/.config/waybar/modules/updates/update-check.go

@ -0,0 +1,9 @@
[Unit]
Description=Check for Pacman/AUR/git package updates
[Timer]
OnBootSec=15min
OnUnitActiveSec=1h
[Install]
WantedBy=timers.target

@ -26,7 +26,7 @@ window#waybar {
#backlight,
#disk,
#custom-pacman,
#custom-aur,
#custom-aurcheck,
#custom-swap,
#custom-spotify,
#custom-separator,
@ -64,10 +64,12 @@ window#waybar {
border-bottom-right-radius: 7px;
}
#custom-pacman.no-updates {
#custom-pacman.no-updates,
#custom-aurcheck.no-updates {
background: rgba(163, 190, 140, 0.75);
}
#custom-pacman.updates {
#custom-pacman.updates,
#custom-aurcheck.updates {
background: rgba(180, 142, 173, 0.75);
}
#custom-pacman.error {