executable_vnc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. help_main()
  5. {
  6. echo "\
  7. Usage: vnc COMMANDS ARGS...
  8. Run COMMANDS with ARGS
  9. COMMAND must be one of the sub-commands listed below:
  10. mjru
  11. vm
  12. server
  13. Report bugs to: go.wigust@gmail.com."
  14. }
  15. help_server()
  16. {
  17. echo "\
  18. Usage: vnc server [OPTION] PORT...
  19. Run vnc server at PORT.
  20. -h, --help display this help and exit
  21. Report bugs to: go.wigust@gmail.com."
  22. }
  23. case "$1" in
  24. --help)
  25. help_main
  26. ;;
  27. client)
  28. case "$2" in
  29. vm1*)
  30. # NOTE: Could append X509Plain and VncAuth separated by command to SecurityTypes.
  31. ssh vm1.wugi.info -- "pgrep -fa 'Xvnc :1'" \
  32. || ssh vm1.wugi.info -- 'vncserver -X509Key ~/.vnc/key.pem -X509Cert ~/.vnc/x509_ca.pem -SecurityTypes X509Vnc :1'
  33. vncviewer -passwd ~/.vnc/passwd X509CA=/home/oleg/.vnc/x509_ca.pem vm1.wugi.info:5901
  34. ;;
  35. mjru)
  36. ssh majordomo.intr -- "pgrep -fa 'Xvnc :3'" \
  37. || ssh majordomo.intr -- 'vncserver -xstartup "$HOME/.vnc/xstartup" :3'
  38. ss -o state listening '( dport = 59588 or sport = 59588 )' | grep -q :59588 \
  39. || ssh -fNL 59588:localhost:5903 majordomo.intr
  40. vncviewer -PasswordFile ~/.vnc/passwd -NoJpeg localhost:59588
  41. ;;
  42. vm)
  43. ss -o state listening '( dport = 5911 or sport = 5911 )' | grep -q :5911 \
  44. || ssh -fNL 5911:localhost:5901 guix.vm.wugi.info
  45. vncviewer -AutoSelect=0 -PreferredEncoding=Raw -FullColor=1 -NoJPEG=1 -CompressLevel=0 -passwd ~/.vnc/passwd 127.0.0.1:5911
  46. ;;
  47. novnc)
  48. docker run --restart unless-stopped --detach --name novnc --network=host geek1011/easy-novnc:latest --addr 127.0.0.1:5911 --port 5910 --novnc-params "resize=remote"
  49. ;;
  50. guix)
  51. vnc_directory="$(mktemp -d -t "vnc.XXXXXXXXXX")"
  52. trap 'rm -rf "$vnc_directory"' EXIT
  53. (
  54. cd "$vnc_directory" || exit 1
  55. pass show localhost/vncserver \
  56. | guix shell tigervnc-server -- vncpasswd -f > passwd
  57. if [[ $HOSTNAME == "guixsd" ]]
  58. then
  59. X509CA="${HOME}/.vnc/x509_ca.pem" vncviewer -passwd passwd -Shared "192.168.0.144:${3:-5902}"
  60. fi
  61. )
  62. ;;
  63. windows)
  64. vnc_directory="$(mktemp -d -t "vnc.XXXXXXXXXX")"
  65. trap 'rm -rf "$vnc_directory"' EXIT
  66. (
  67. cd "$vnc_directory" || exit 1
  68. pass show windows.local/oleg \
  69. | guix shell tigervnc-server -- vncpasswd -f > passwd
  70. vncviewer -passwd passwd "windows.local"
  71. )
  72. ;;
  73. *)
  74. vncviewer -AutoSelect=0 -PreferredEncoding=Raw -FullColor=1 -NoJPEG=1 -CompressLevel=0 -passwd "$HOME/.vnc/passwd" 127.0.0.1:"$2"
  75. ;;
  76. esac
  77. ;;
  78. server)
  79. case "$2" in
  80. --help)
  81. help_server
  82. ;;
  83. 5901|firefox)
  84. vncserver -xstartup "$HOME/.vnc/xstartup-firefox" :1
  85. ;;
  86. 5902|workstation)
  87. vncserver -geometry 1920x1080 -xstartup "$HOME/.vnc/xstartup-stumpwm" :2
  88. ;;
  89. 5903|small)
  90. vncserver -geometry 1366x768 -xstartup "$HOME/.vnc/xstartup-stumpwm" :3
  91. ;;
  92. 5910|quassel)
  93. vncserver -xstartup "$HOME/.vnc/xstartup-quassel" :10
  94. ;;
  95. *)
  96. help_server
  97. ;;
  98. esac
  99. ;;
  100. ssl)
  101. case "$2" in
  102. vm1*)
  103. # [[https://zalinux.ru/?p=3905][Как настроить и использовать сервер TigerVNC в Linux - ZaLinux.ru]]
  104. openssl req -x509 -newkey rsa -days 365 -nodes -keyout key.pem -out x509_ca.pem -subj '/CN=vm1.wugi.info'
  105. ;;
  106. guix.wugi.info)
  107. # [[https://zalinux.ru/?p=3905][Как настроить и использовать сервер TigerVNC в Linux - ZaLinux.ru]]
  108. openssl req -x509 -newkey rsa -days 365 -nodes -keyout key.pem -out x509_ca.pem -subj '/CN=guix.wugi.info'
  109. install --backup x509_ca.pem "$HOME"/.vnc/x509_ca.pem
  110. install --backup key.pem "$HOME"/.vnc/key.pem
  111. ;;
  112. esac
  113. ;;
  114. password)
  115. # vnc password PASSWORD_TEXT kvm12.intr:12345
  116. vnc_directory="$(mktemp -d -t "vnc.XXXXXXXXXX")"
  117. (
  118. set -x
  119. trap 'rm -rf "$vnc_directory"' EXIT
  120. cd "$vnc_directory"
  121. echo "$2" | guix shell tigervnc-server -- vncpasswd -f > passwd
  122. command vncviewer -passwd passwd "$3"
  123. )
  124. ;;
  125. *)
  126. help_main
  127. ;;
  128. esac