el-get-install.el 3.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
;;; el-get-install.el --- installer for the lazy
;;
;; Copyright (C) 2010 Dimitri Fontaine
;;
;; Author: Dimitri Fontaine <dim@tapoueh.org>
;; URL: http://www.emacswiki.org/emacs/el-get.el
;; Created: 2010-06-17
;; Keywords: emacs package elisp install elpa git git-svn bzr cvs apt-get fink http http-tar
;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/
;;
;; This file is NOT part of GNU Emacs.
;;
;; bootstrap your el-get installation, the goal is then to use el-get to
;; update el-get.
15
;;
16 17 18
;; So the idea is that you copy/paste this code into your *scratch* buffer,
;; hit C-j, and you have a working el-get.

19 20
(let ((el-get-root
       (file-name-as-directory
Ryan C. Thompson's avatar
Ryan C. Thompson committed
21 22
        (or (bound-and-true-p el-get-dir)
            (concat (file-name-as-directory user-emacs-directory) "el-get")))))
23 24 25 26 27 28 29 30 31 32

  (when (file-directory-p el-get-root)
    (add-to-list 'load-path el-get-root))

  ;; try to require el-get, failure means we have to install it
  (unless (require 'el-get nil t)
    (unless (file-directory-p el-get-root)
      (make-directory el-get-root t))

    (let* ((package   "el-get")
Ryan C. Thompson's avatar
Ryan C. Thompson committed
33 34 35 36 37 38 39 40
           (buf       (switch-to-buffer "*el-get bootstrap*"))
           (pdir      (file-name-as-directory (concat el-get-root package)))
           (git       (or (executable-find "git")
                          (error "Unable to find `git'")))
           (url       (or (bound-and-true-p el-get-git-install-url)
                          "http://github.com/dimitri/el-get.git"))
           (default-directory el-get-root)
           (process-connection-type nil)   ; pipe, no pty (--no-progress)
41

Ryan C. Thompson's avatar
Ryan C. Thompson committed
42 43 44 45
           ;; First clone el-get
           (status
            (call-process
             git nil `(,buf t) t "--no-pager" "clone" "-v" url package)))
46 47

      (unless (zerop status)
Ryan C. Thompson's avatar
Ryan C. Thompson committed
48
        (error "Couldn't clone el-get from the Git repository: %s" url))
49 50

      ;; switch branch if we have to
51 52
      (let* ((branch (cond
                      ;; Check if a specific branch is requested
53
                      ((bound-and-true-p el-get-install-branch))
54 55 56 57 58 59 60 61 62 63 64 65 66
                      ;; Check if master branch is requested
                      ((boundp 'el-get-master-branch) "master")
                      ;; Read the default branch from the el-get recipe
                      ((plist-get (with-temp-buffer
                                    (insert-file-contents-literally
                                     (expand-file-name "recipes/el-get.rcp" pdir))
                                    (read (current-buffer)))
                                  :branch))
                      ;; As a last resort, use the master branch
                      ("master")))
             (remote-branch (format "origin/%s" branch))
             (default-directory pdir)
             (bstatus
Ryan C. Thompson's avatar
Ryan C. Thompson committed
67 68 69
              (if (string-equal branch "master")
                  0
                (call-process git nil (list buf t) t "checkout" "-t" remote-branch))))
70 71
        (unless (zerop bstatus)
          (error "Couldn't `git checkout -t %s`" branch)))
72

73 74 75
      (add-to-list 'load-path pdir)
      (load package)
      (let ((el-get-default-process-sync t) ; force sync operations for installer
Ryan C. Thompson's avatar
Ryan C. Thompson committed
76
            (el-get-verbose t))             ; let's see it all
77
        (el-get-post-install "el-get"))
78
      (unless (boundp 'el-get-install-skip-emacswiki-recipes)
79
        (el-get-emacswiki-build-local-recipes))
80
      (with-current-buffer buf
Ryan C. Thompson's avatar
Ryan C. Thompson committed
81 82
        (goto-char (point-max))
        (insert "\nCongrats, el-get is installed and ready to serve!")))))