barista icon indicating copy to clipboard operation
barista copied to clipboard

Ideas for more modules

Open shibumi opened this issue 5 years ago • 3 comments

Hi, I am currently working on my own status bar based on barista (https://github.com/shibumi/ryoukai/blob/master/main.go)

My plan is to port all functions of my i3blocks status bar (which uses shell scripts). What I need to port is:

  • read a value from sysctl or /proc/sys/kernel for USBDeny (a special value in linux-hardened kernels)
  • get current song + status from MPD
  • retrieve external IP via https://ipinfo.io
  • show DNS servers (not sure with thi one.. maybe I will just drop it)
  • Status of Wireguard

I have finished the reading of the usb_deny value from /proc/sys/kernel/. I am a newbie on go, so maybe you have a better idea to read the value:

func usbDeny() bool {
	data, err := ioutil.ReadFile("/proc/sys/kernel/deny_new_usb")
	if err != nil {
		return false
	}
	dataString := strings.Split(string(data), "\n")
	out, err := strconv.ParseBool(dataString[0])
	if err != nil {
		return false
	}
	return out
}

	barista.Add(funcs.Every(5*time.Second, func(s bar.Sink) {
		out := outputs.Text("USB")
		if usbDeny() {
			out.Color(colors.Scheme("good"))
		} else {
			out.Color(colors.Scheme("bad"))
		}
		s.Output(out)
	}))

I am a little bit confused. Should I write an own module for reading from sysctl or is my way via your func module the better way?

I really want to write some modules for your status bar, but I am unsure which one would be good and which one could be easily achieved via using static or func module.

shibumi avatar Mar 05 '19 01:03 shibumi

Mhh I think I could use your file watchers for checking the deny_new_usb file. Will it also work for files in procfs?

shibumi avatar Mar 05 '19 03:03 shibumi

Should I write an own module for reading from sysctl or is my way via your func module the better way?

Either is fine. Your module is simple enough that it's very reasonable to add it directly.

I really want to write some modules for your status bar, but I am unsure which one would be good and which one could be easily achieved via using static or func module.

It depends on how specific the module would be, and how much code it takes to add it directly. In this case, either would be fine. It's not a lot of code, but I can see a sysctl module being valuable.

Similarly for retrieving the external IP, it might be worth adding a generic module that makes an HTTP request and formats the body for display, from which building the external IP module would be very simple.

get current song + status from MPD

If mpd doesn't support MPRIS, then this is a perfect example of a module that would be useful in general. If you want to dive deep into go, you could try extracting a generic media module and writing the current one as an mpris implementation, allowing mpd to be another parallel implementation of the same module. (Since much of the data/command flow will be the same for both). Otherwise I can try writing something up once my themes work is complete.

I think I could use your file watchers for checking the deny_new_usb file. Will it also work for files in procfs?

Unfortunately not. It does not work for most special fs, like procfs or sysfs. I tried using it for cputemp but it went nowhere, so we're back to polling.

However, in this particular case, it's possible you may be able to watch a log file for quicker updates, if something is logged when the sysctl value changes. And if this is general enough, definitely worth adding a module that can watch for sysctl changes :) (Or you could write a systemd unit that controls the deny_new_usb value, and watch its status. Something like https://blog.lizzie.io/preventing-usb-attacks-with-grsecurity.html).

soumya92 avatar Mar 05 '19 06:03 soumya92

Yes, this is correct mpd doesn't support MPRIS and it looks like that mpd behaves different. We have access to a big bunch of information via gompd: https://www.musicpd.org/doc/html/protocol.html

I am currently working on a first version of a mpd module, but I am not sure yet if it will be good enough to include it. I am still a go newbie and need to look up a lot + test a lot.

+1 from me for adding a sysctl module.

shibumi avatar Mar 06 '19 00:03 shibumi