executable_pers 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/run/current-system/profile/bin/guile \
  2. --no-auto-compile -e (pers) -s
  3. !#
  4. ;;;; pers --- Run screen with handling a connection to server
  5. ;;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
  6. ;;;; Released under the GNU GPLv3 or any later version.
  7. (define-module (pers)
  8. #:use-module (srfi srfi-37)
  9. #:use-module (ice-9 ftw)
  10. #:use-module (ice-9 match)
  11. #:export (main))
  12. ;;; Commentary:
  13. ;;;
  14. ;;; Program for connection to servers via "connect" script in "screen"
  15. ;;; sessions.
  16. ;;;
  17. ;;; Code:
  18. (define %options
  19. (let ((display-and-exit-proc (lambda (msg)
  20. (lambda (opt name arg loads)
  21. (display msg) (quit)))))
  22. (list (option '(#\v "version") #f #f
  23. (display-and-exit-proc "pers version 0.0.1\n"))
  24. (option '(#\h "help") #f #f
  25. (display-and-exit-proc
  26. "Usage: pers ...")))))
  27. (define %default-options
  28. '())
  29. (define %servers
  30. '("web15.intr" "web16.intr" "web17.intr" "web18.intr" "web19.intr"
  31. "web20.intr" "web21.intr" "web22.intr" "web23.intr" "web24.intr" "web25.intr" "web26.intr" "web27.intr" "web28.intr" "web29.intr"
  32. "web30.intr" "web31.intr" "web32.intr" "web33.intr" "web34.intr" "web35.intr" "web36.intr" "web37.intr"
  33. "kvm1.intr" "kvm2.intr" "kvm5.intr" "kvm6.intr" "kvm9.intr" "kvm10.intr"
  34. "kvm11.intr" "kvm12.intr" "kvm13.intr" "kvm14.intr" "kvm15.intr" "kvm16.intr" "kvm17.intr" "kvm19.intr"
  35. "kvm21.intr" "kvm22.intr" "kvm23.intr" "kvm24.intr" "kvm25.intr" "kvm26.intr" "kvm27.intr" "kvm28.intr" "kvm29.intr"
  36. "kvm30.intr" "kvm31.intr" "kvm32.intr" "kvm33.intr" "kvm34.intr" "kvm35.intr" "kvm37.intr"))
  37. (define (main args)
  38. (define opts
  39. (args-fold (cdr (program-arguments))
  40. %options
  41. (lambda (opt name arg loads)
  42. (error "Unrecognized option `~A'" name))
  43. (lambda (op loads)
  44. (cons op loads))
  45. %default-options))
  46. (define option
  47. (car opts))
  48. (if (and=> (file-system-tree "/tmp/uscreens/S-oleg"))
  49. (lambda (files)
  50. (if (string= option "kill")
  51. (for-each (lambda (server)
  52. (when (filter (match-lambda ((file-name _ ...)
  53. (string-suffix? server file-name))
  54. (_ #f))
  55. files)
  56. (system (string-join (list "screen" "-r" server)))
  57. (format #t "screen ~a killed.~%" server)))
  58. %servers)
  59. (for-each (lambda (server)
  60. (if (null? (filter (match-lambda ((file-name _ ...)
  61. (string-suffix? server file-name))
  62. (_ #f))
  63. files))
  64. (system (string-join (list "screen" "-dmS" server "connect" "ssh" server)))
  65. (format #t "~a already connected.~%" server)))
  66. %servers)))
  67. (error "No /tmp/uscreens/S-oleg. Hint: Start any `screen' session.")
  68. (exit 1)))
  69. ;;; pers ends here