25 lines
678 B
Nix
25 lines
678 B
Nix
{ pkgs }:
|
|
pkgs.writeScriptBin "myvnc" ''
|
|
#!${pkgs.runtimeShell}
|
|
|
|
uid=`id -u`
|
|
port=$((9000+$uid))
|
|
shell=`getent passwd $(id -un) | awk -F : '{print $NF}'`
|
|
# vnc=${pkgs.tigervnc}/bin/vncserver
|
|
vnc=/nix/store/czp2b60dwk75widi8y287hr0xx1wgv2a-tigervnc-1.10.1/bin/vncserver
|
|
|
|
case $1 in
|
|
-p|--port) shift; port=$1 ;;
|
|
kill|stop)
|
|
display=$($vnc -list | sed -n 's/^\(:[0-9]\+\).*/\1/p'| head -1)
|
|
$vnc -kill $display
|
|
exit 0
|
|
;;
|
|
esac
|
|
ps ax | sed '/grep/d' | grep "Xvnc.*-rfbport $port" >/dev/null 2>&1
|
|
[ $? = 1 ] && $vnc -rfbport $port
|
|
echo "Xvnc server is running on port $port."
|
|
exec $shell -i
|
|
''
|
|
|