Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. (package-install 'auctex)
  2.  
  3. (setq my-package-list '(package1 package2 packageN))
  4. (mapc #'package-install my-package-list)
  5.  
  6. path = .emacs
  7. path = .emacs.d
  8. ignore = Path {.emacs.d/semanticdb}
  9.  
  10. (el-get 'sync '(packages))
  11.  
  12. machine mymachine login myloginname password mypassword port myport
  13.  
  14. (require 'auth-source)
  15.  
  16. ;;; EXAMPLE:
  17. ;;; (get-auth-info "12.34.567.89" "username")
  18. ;;; (get-auth-info "localhost" "root")
  19. (defun get-auth-info (host user &optional port)
  20. (let ((info (nth 0 (auth-source-search
  21. :host host
  22. :user user
  23. :port port
  24. :require '(:user :secret)
  25. :create t))))
  26. (if info
  27. (let* ((port (plist-get info :port))
  28. (secret-maybe (plist-get info :secret))
  29. (secret
  30. (if (functionp secret-maybe)
  31. (funcall secret-maybe)
  32. secret-maybe)))
  33. (list port secret))
  34. nil)))
  35.  
  36. (defun rsync-filter (proc string)
  37. (cond
  38. ((string-match
  39. "^\([a-zA-Z0-9_\-\.]+\)@\([a-zA-Z0-9_\-\.]+\)'s password: "
  40. string)
  41. (let* ((user (substring string (match-beginning 1) (match-end 1)))
  42. (host (substring string (match-beginning 2) (match-end 2)))
  43. (password (car (cdr (get-auth-info host user)))))
  44. (process-send-string proc (concat password "n"))))
  45. ((not (or (string-match "files\.\.\.r" string)
  46. (string-match "files to considern" string)))
  47. (with-current-buffer (messages-buffer)
  48. (let ((inhibit-read-only t))
  49. (goto-char (point-max))
  50. (when (not (bolp))
  51. (insert "n"))
  52. (insert string)
  53. (when (not (bolp))
  54. (insert "n")))))))
  55.  
  56. (defun rsync-remote ()
  57. "Use rsync to a remote server via ssh. Back-up your data first!!!"
  58. (interactive)
  59. (let* (
  60. (host "localhost")
  61. (username "root")
  62. (port (or (car (get-auth-info host username))
  63. (number-to-string (read-number "Port: "))))
  64. (source
  65. (let ((dir (expand-file-name (locate-user-emacs-file "elpa/"))))
  66. (if (file-directory-p dir)
  67. dir
  68. (let ((debug-on-quit nil)
  69. (msg (format "`%s` is not a valid directory." dir)))
  70. (signal 'quit `(,msg))))))
  71. (target "/private/var/mobile/elpa/")
  72. (ssh "/usr/bin/ssh")
  73. (rsync "/usr/bin/rsync")
  74. (rsync-include-file "/path/to/include-file.txt")
  75. (rsync-exclude-file "/path/to/exclude-file.txt")
  76. (rsh (concat "--rsh=ssh -p " port " -l " username))
  77. (host+target (concat host ":" target)))
  78. (start-process
  79. "rsync-process"
  80. nil
  81. rsync
  82. "-avr" ;; must specify the `-r` argument when using `--files-from`
  83. "--delete"
  84. ;; The paths inside the exclusion file must be relative, NOT absolute.
  85. ;;; (concat "--files-from=" rsync-include-file)
  86. ;;; (concat "--exclude-from=" rsync-exclude-file)
  87. rsh
  88. source
  89. host+target)
  90. (set-process-filter (get-process "rsync-process") 'rsync-filter)
  91. (set-process-sentinel
  92. (get-process "rsync-process")
  93. (lambda (p e) (when (= 0 (process-exit-status p))
  94. (message "rsync-remote: synchronizing ... done."))))))
  95.  
  96. (defun rsync-local ()
  97. "Use rsync locally -- e.g., over a trusted home network.
  98. Back-up your data first!!!"
  99. (interactive)
  100. (let (
  101. (rsync-program "/usr/bin/rsync")
  102. (source
  103. (let ((dir (expand-file-name
  104. (file-name-as-directory
  105. (read-directory-name "Source Directory: " nil nil nil nil)))))
  106. (if (file-directory-p dir)
  107. dir
  108. (let ((debug-on-quit nil)
  109. (msg (format "`%s` is not a valid directory." dir)))
  110. (signal 'quit `(,msg))))))
  111. (target (expand-file-name
  112. (file-name-as-directory
  113. (read-directory-name "Target Directory: " nil nil nil nil)))))
  114. (unless (y-or-n-p (format "SOURCE: %s | TARGET: %s" source target))
  115. (let ((debug-on-quit nil))
  116. (signal 'quit `("You have exited the function."))))
  117. (start-process "rsync-process"
  118. nil
  119. rsync-program
  120. "--delete"
  121. "-arzhv"
  122. source
  123. target)
  124. (set-process-filter (get-process "rsync-process") #'rsync-process-filter)
  125. (set-process-sentinel
  126. (get-process "rsync-process")
  127. (lambda (p e)
  128. (when (= 0 (process-exit-status p))
  129. (message "Done!"))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement