]>
Commit | Line | Data |
---|---|---|
e1d50c8c TE |
1 | #!/bin/bash |
2 | ||
3 | # `snapctl get services` returns a JSON array, example: | |
4 | #{ | |
5 | #"n6801": { | |
6 | # "listen": 6801, | |
7 | # "vnc": "localhost:5901" | |
8 | #}, | |
9 | #"n6802": { | |
10 | # "listen": 6802, | |
11 | # "vnc": "localhost:5902" | |
12 | #} | |
13 | #} | |
14 | snapctl get services | jq -c '.[]' | while read service; do # for each service the user sepcified.. | |
15 | # get the important data for the service (listen port, VNC host:port) | |
16 | listen_port="$(echo $service | jq --raw-output '.listen')" | |
17 | vnc_host_port="$(echo $service | jq --raw-output '.vnc')" # --raw-output removes any quotation marks from the output | |
18 | ||
19 | # check whether those values are valid | |
20 | expr "$listen_port" : '^[0-9]\+$' > /dev/null | |
21 | listen_port_valid=$? | |
22 | if [ ! $listen_port_valid ] || [ -z "$vnc_host_port" ]; then | |
23 | # invalid values mean the service is disabled, do nothing except for printing a message (logged in /var/log/system or systemd journal) | |
24 | echo "novnc: not starting service ${service} with listen_port ${listen_port} and vnc_host_port ${vnc_host_port}" | |
25 | else | |
26 | # start (and fork with '&') the service using the specified listen port and VNC host:port | |
27 | $SNAP/utils/launch.sh --listen $listen_port --vnc $vnc_host_port & | |
28 | fi | |
29 | done |