Skip to content

Commit

Permalink
bw: show generic information and unit status on login
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Jul 1, 2024
1 parent 96e3c2a commit 38c1a9c
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 30 deletions.
3 changes: 3 additions & 0 deletions bundlewrap/bundles/isc-dhcp-server/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
'isc-dhcp-server': {
'fixed_allocations': allocs,
},
'unit-status-on-login': {
'isc-dhcp-server',
},
}


Expand Down
3 changes: 3 additions & 0 deletions bundlewrap/bundles/sysconfig/files/motd
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@
10
10
10
% for line in description:
${line}
% endfor

25 changes: 25 additions & 0 deletions bundlewrap/bundles/sysconfig/files/unit-status-on-login
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

[[ -n "$DEBUG" ]] && set -x

echo "systemd unit status:"

% for idx, unitname in enumerate(sorted(units)):
status="$(systemctl is-active "${unitname}")"
if [[ "$?" -eq 0 ]]
then
tput setaf 2
else
tput setaf 1
fi
echo -n " ${unitname.ljust(30)}"
tput sgr0
% if idx % 2:
echo ""
% endif
% endfor

% if not idx % 2:
echo ""
% endif
echo ""
90 changes: 67 additions & 23 deletions bundlewrap/bundles/sysconfig/items.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,78 @@
from inspect import cleandoc
from uuid import UUID
from bundlewrap.utils.text import bold, italic, yellow

from bundlewrap.utils.text import italic
description = []
event = node.metadata.get('event/slug', None)
if event:
description.append('Event: {} ({})'.format(
node.metadata.get('event/name', '?'),
node.metadata.get('event/slug'),
))
description.append('Room: {}'.format(node.metadata.get('event/room_name', '?')))

files = {
'/etc/hosts': {
'content_type': 'mako',
},
'/etc/htoprc.global': {
'source': 'htoprc',
},
'/etc/motd': {},
'/etc/modules': {
'content': '\n'.join(node.metadata.get('modules', set())) + '\n',
},
if node.has_bundle('voctocore'):
description.append('')
description.append(bold('voctocore source config'))
for name, opts in node.metadata.get('voctocore/sources', {}).items():
if opts.get('kind', 'decklink') == 'decklink':
description.append(' {} kind=decklink - input {} @ {}'.format(
name,
opts['devicenumber'],
opts['mode']
))
else:
description.append(' {} kind={}'.format(
name,
yellow(opts['kind']),
))

if node.has_bundle('samba'):
description.append('')
description.append(bold('samba shares:'))
for name, opts in node.metadata.get('samba/shares', {}).items():
description.append(' {} as //{}/{}{}'.format(
opts['path'],
node.hostname,
name,
' (writable)' if opts.get('writable', True) else '',
))

desc = node.metadata.get('description', [])
if desc:
description.append('')
for line in desc:
description.append('# {}'.format(italic(line)))

files['/etc/hosts'] = {
'content_type': 'mako',
}

description = []
files['/etc/htoprc.global'] = {
'source': 'htoprc',
}

# TODO add some more information to this file, for example voc2mix
# config or such
files['/etc/motd'] = {
'content_type': 'mako',
'context': {
'description': description,
},
}

for line in node.metadata.get('description', []):
description.append('# {}'.format(italic(line)))
files['/etc/modules'] = {
'content': '\n'.join(node.metadata.get('modules', set())) + '\n',
}

if description:
files['/etc/node.description'] = {
'content': '\n'.join(description) + '\n',
unit_status_on_login = node.metadata.get('unit-status-on-login', set())
if unit_status_on_login:
files['/usr/local/bin/unit-status-on-login'] = {
'mode': '0755',
'content_type': 'mako',
'context': {
'units': unit_status_on_login,
},
}
else:
files['/etc/node.description'] = {
files['/usr/local/bin/unit-status-on-login'] = {
'delete': True,
}

files['/etc/node.description'] = {'delete': True}
4 changes: 4 additions & 0 deletions bundlewrap/bundles/unbound-with-knot/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
'max_ttl': 3600,
'cache_size': '512M',
},
'unit-status-on-login': {
'unbound',
'knot',
},
}


Expand Down
18 changes: 11 additions & 7 deletions bundlewrap/bundles/users/files/bash.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ else
fi
unset PROMPT_COMMAND

if [[ -f "/etc/node.description" ]]
then
echo
cat "/etc/node.description"
echo
fi

uptime
echo
last | head -n5
echo

if [[ -x "/usr/local/bin/unit-status-on-login" ]]
then
/usr/local/bin/unit-status-on-login
fi
</%text>

% for cmd in sorted(node.metadata.get('extra-commands-on-login', set())):
${cmd}
% endfor

<%text>
export HISTCONTROL=ignoredups
export HISTSIZE=50000
export HISTTIMEFORMAT="%d/%m/%y %T "
Expand Down
1 change: 1 addition & 0 deletions bundlewrap/bundles/users/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
files['/etc/vim/vimrc.local'] = {}
files['/usr/local/etc/screenrc'] = {}


if node.os_version[0] < 10:
files['/usr/share/terminfo/x/xterm-kitty'] = {}

Expand Down
3 changes: 3 additions & 0 deletions bundlewrap/bundles/voc2dmx/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import bwkeepass as keepass

defaults = {
'unit-status-on-login': {
'voc2dmx',
},
'voc2dmx': {
'mqtt': {
'host': keepass.url(['ansible', 'mqtt']),
Expand Down
9 changes: 9 additions & 0 deletions bundlewrap/bundles/voctocore/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
'xauth': {}, # for x11 forwarding
},
},
'extra-commands-on-login': {
'''echo "Free space in /video: $(df -h --output=avail /video | tail -n1 | sed 's/ //g')"'''
},
'unit-status-on-login': {
'voctomix2-voctocore',
'voctomix2-streaming-sink',
'voctomix2-recording-sink',
},
'users': {
'voc': {
'groups': {
Expand Down Expand Up @@ -74,6 +82,7 @@ def streaming_endpoint(metadata):
},
}


@metadata_reactor.provides(
'voctocore/sources',
)
Expand Down
3 changes: 3 additions & 0 deletions bundlewrap/bundles/voctogui/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
'python3-wheel': {},
},
},
'unit-status-on-login': {
'voctomix2-voctogui',
},
'voctogui' : {
'high_dpi': True,
'play_audio': False,
Expand Down

0 comments on commit 38c1a9c

Please sign in to comment.