| 1 |
#!/bin/sh -e |
| 2 |
|
| 3 |
# syntax: update-issue [port [hostname [ipaddr [protocol]]]] |
| 4 |
# each argument can be given as the empty string to use the default |
| 5 |
|
| 6 |
# port number from cmdline, then systemctl file, then 9090 |
| 7 |
# take the last Listen line; this will be the user-specified one |
| 8 |
port=${1:-$(systemctl show --property Listen cockpit.socket | |
| 9 |
sed -E '$!d;$s/.*[^0-9]([0-9]+).*/\1/;')} |
| 10 |
port=${port:-9090} |
| 11 |
|
| 12 |
# hostname from cmdline, then `hostname -f` |
| 13 |
hostname=${2:-$(hostname -f || hostname)} |
| 14 |
|
| 15 |
# ip addr from cmdline, then default route source addr |
| 16 |
ip=${3:-$(ip -o route get 255.0 2>/dev/null | sed -e 's/.*src \([^ ]*\) .*/\1/')} |
| 17 |
|
| 18 |
# protocol from cmdline, then https |
| 19 |
protocol=${4:-https} |
| 20 |
|
| 21 |
hostname_url="${protocol}://${hostname}:${port}/" |
| 22 |
ip_url="${ip:+ or ${protocol}://${ip}:${port}/}" |
| 23 |
|
| 24 |
printf 'Web console: %s%s\n\n' "${hostname_url}" "${ip_url}" > /run/cockpit/active.issue |