2017-05-21 20:25:30 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
":"; command -v emacs >/dev/null || { >&2 echo "Emacs isn't installed"; exit 1; }
|
|
|
|
":"; [[ $(emacs --version | head -n1) == *\ 2[0-2].[0-1].[0-9] ]] && echo 'Emacs version is too old, check your PATH' || exec emacs --no-site-file --batch -l "$0" # -*-emacs-lisp-*-
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
;; Uses a couple simple heuristics to locate issues with your environment that
|
|
|
|
;; could interfere with running or setting up DOOM Emacs.
|
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
;; In case it isn't defined (in really old versions of Emacs, like the one that
|
|
|
|
;; ships with MacOS).
|
|
|
|
(defvar user-emacs-directory (expand-file-name "~/.emacs.d/"))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
2017-05-21 14:10:33 +02:00
|
|
|
(unless (equal (expand-file-name user-emacs-directory)
|
|
|
|
(expand-file-name "~/.emacs.d/"))
|
|
|
|
(error "Couldn't find ~/.emacs.d"))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
(defvar doom-errors 0)
|
|
|
|
(defmacro check! (cond &rest body)
|
|
|
|
(declare (indent defun))
|
|
|
|
`(when ,cond
|
|
|
|
,@body
|
|
|
|
(setq doom-errors (1+ doom-errors))))
|
|
|
|
|
|
|
|
(defun indented (spc msg)
|
|
|
|
(declare (indent defun))
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert msg)
|
|
|
|
(indent-rigidly (point-min) (point-max) spc)
|
|
|
|
(buffer-string)))
|
|
|
|
|
2017-05-21 14:10:33 +02:00
|
|
|
(defun autofill (&rest msgs)
|
|
|
|
(declare (indent defun))
|
|
|
|
(let ((fill-column 70))
|
|
|
|
(with-temp-buffer
|
|
|
|
(dolist (line msgs)
|
|
|
|
(when line
|
|
|
|
(insert line)))
|
|
|
|
(fill-region (point-min) (point-max))
|
|
|
|
(buffer-string))))
|
|
|
|
|
2017-05-20 18:15:40 +02:00
|
|
|
(defun columns (cols length strings)
|
|
|
|
(declare (indent defun))
|
|
|
|
(with-temp-buffer
|
|
|
|
(let ((sub-format (format "%%-%ds " (1- length)))
|
|
|
|
col-format)
|
2017-05-21 14:10:33 +02:00
|
|
|
(dotimes (i (1- cols))
|
2017-05-20 18:15:40 +02:00
|
|
|
(setq col-format (concat col-format sub-format)))
|
2017-05-21 14:10:33 +02:00
|
|
|
(setq col-format (concat col-format "%s"))
|
2017-05-20 18:15:40 +02:00
|
|
|
(while strings
|
|
|
|
(insert (apply #'format col-format
|
|
|
|
(let (args)
|
|
|
|
(dotimes (i cols (nreverse args))
|
|
|
|
(push (if strings (pop strings) "") args))))
|
|
|
|
"\n")))
|
|
|
|
(buffer-string)))
|
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
(defun color (code msg &rest args)
|
|
|
|
(format "\e[%dm%s\e[%dm" code (apply #'format msg args) 0))
|
|
|
|
|
|
|
|
(defalias 'msg! #'message)
|
|
|
|
(defmacro error! (&rest args) `(message (color 1 (color 31 ,@args))))
|
|
|
|
(defmacro warn! (&rest args) `(message (color 1 (color 33 ,@args))))
|
|
|
|
(defmacro success! (&rest args) `(message (color 1 (color 32 ,@args))))
|
|
|
|
(defmacro explain! (&rest args) `(message (indented 2 (autofill ,@args))))
|
|
|
|
|
|
|
|
;;; Polyfills
|
|
|
|
;; early versions of emacs won't have this
|
|
|
|
(unless (fboundp 'string-match-p)
|
|
|
|
(defun string-match-p (regexp string &optional start)
|
|
|
|
(save-match-data
|
|
|
|
(string-match regexp string &optional start))))
|
2017-05-21 14:10:33 +02:00
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
|
|
|
|
;; --- start a'doctorin' --------------------------------------
|
|
|
|
|
|
|
|
(msg! "%s\nRunning Emacs v%s"
|
|
|
|
(color 1 "DOOM Doctor")
|
|
|
|
(color 1 emacs-version))
|
|
|
|
(msg! "Compiled with:\n%s" (indented 2 (autofill system-configuration-features)))
|
|
|
|
(msg! "uname -a:\n%s" (indented 2 (autofill (shell-command-to-string "uname -a"))))
|
|
|
|
(msg! "----\n")
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
;; --- is emacs set up properly? ------------------------------
|
|
|
|
|
|
|
|
(check! (version< emacs-version "25.1")
|
2017-05-21 14:10:33 +02:00
|
|
|
(error! "Important: Emacs %s detected [%s]" emacs-version (executable-find "emacs"))
|
|
|
|
(explain!
|
|
|
|
"DOOM only supports >= 25.1. Perhaps your PATH wasn't set up properly."
|
2017-05-21 20:25:30 +02:00
|
|
|
(when (eq system-type 'darwin)
|
2017-05-21 14:10:33 +02:00
|
|
|
(concat "\nMacOS users should use homebrew (https://brew.sh) to install Emacs\n"
|
|
|
|
" brew install emacs --with-modules --with-imagemagick --with-cocoa"))))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
;; --- is the environment set up properly? --------------------
|
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
;; gnutls-cli & openssl
|
|
|
|
(unless (not (executable-find "gnutls-cli"))
|
|
|
|
(cond ((executable-find "openssl")
|
|
|
|
(let* ((output (shell-command-to-string "openssl ciphers -v"))
|
|
|
|
(protocols
|
|
|
|
(let (protos)
|
|
|
|
(mapcar (lambda (row)
|
|
|
|
(add-to-list 'protos (cadr (split-string row " " t))))
|
|
|
|
(split-string (shell-command-to-string "openssl ciphers -v") "\n"))
|
|
|
|
(delq nil protos))))
|
|
|
|
(check! (not (or (member "TLSv1.1" protocols)
|
|
|
|
(member "TLSv1.2" protocols)))
|
|
|
|
(let ((version (cadr (split-string (shell-command-to-string "openssl version") " " t))))
|
|
|
|
(warn! "Warning: couldn't find gnutls-cli, and OpenSSL is out-of-date (v%s)" version)
|
|
|
|
(explain!
|
|
|
|
"This may not affect your Emacs experience, but there are security "
|
|
|
|
"vulnerabilities in the SSL2/3 & TLS1.0 protocols. You should use "
|
|
|
|
"TLS 1.1+, which wasn't introduced until OpenSSL v1.0.1.\n\n"
|
|
|
|
|
|
|
|
"Please considering updating (or installing gnutls-cli, which is preferred).")))))
|
|
|
|
(t
|
|
|
|
(check! t
|
|
|
|
(error! "Important: couldn't find either gnutls-cli or openssl")
|
|
|
|
(explain!
|
|
|
|
"You won't be able to install/update packages because Emacs won't be able to "
|
|
|
|
"verify HTTPS ELPA sources. Install gnutls-cli or openssl v1.0.0+. If for some "
|
|
|
|
"reason you can't, you can bypass this verification with the INSECURE flag:\n\n"
|
|
|
|
|
|
|
|
" INSECURE=1 make install\n\n"
|
|
|
|
|
|
|
|
"Or change `package-archives' to use non-https sources.\n\n"
|
|
|
|
|
|
|
|
"But remember that you're leaving your security in the hands of your "
|
|
|
|
"network, provider, government, neckbearded mother-in-laws, geeky roommates, "
|
|
|
|
"or just about anyone who knows more about computers than you do!")))))
|
|
|
|
|
|
|
|
;; git
|
2017-05-20 18:15:40 +02:00
|
|
|
(check! (not (executable-find "git"))
|
2017-05-21 20:25:30 +02:00
|
|
|
(error! "Important: couldn't find git"))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
;; windows? windows
|
2017-05-20 18:15:40 +02:00
|
|
|
(check! (memq system-type '(windows-nt ms-dos cygwin))
|
2017-05-21 14:10:33 +02:00
|
|
|
(warn! "Warning: Windows detected")
|
|
|
|
(explain! "DOOM was designed for MacOS and Linux. Expect a bumpy ride!"))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
;; bsd vs gnu tar
|
2017-05-20 18:15:40 +02:00
|
|
|
(if (executable-find "tar")
|
|
|
|
(check! (not (string-match-p "(GNU tar)" (shell-command-to-string "tar --version")))
|
2017-05-21 14:10:33 +02:00
|
|
|
(warn! "Warning: BSD tar detected")
|
|
|
|
(explain!
|
|
|
|
"QUELPA (through package-build) uses the system tar to build plugins."
|
|
|
|
"BSD tar *could* cause errors during package installation or updating from"
|
|
|
|
"non-ELPA sources."
|
2017-05-21 20:25:30 +02:00
|
|
|
(when (eq system-type 'darwin)
|
2017-05-21 14:10:33 +02:00
|
|
|
(concat "\nMacOS users can install gnu-tar via homebrew:\n"
|
|
|
|
" brew install gnu-tar"))))
|
2017-05-21 20:25:30 +02:00
|
|
|
(check! t ; very unlikely
|
|
|
|
(error! "Important: Couldn't find tar")
|
|
|
|
(explain! "This is required by package.el and QUELPA to build packages.")))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
;; --- report! ------------------------------------------------
|
|
|
|
|
|
|
|
(when (getenv "DEBUG")
|
2017-05-21 20:25:30 +02:00
|
|
|
(msg! "\n====\nHave some debug information:\n")
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
(let (doom-core-packages doom-debug-mode)
|
|
|
|
(condition-case ex
|
|
|
|
(progn
|
|
|
|
(let ((inhibit-message t))
|
|
|
|
(load "~/.emacs.d/core/core.el" nil t))
|
|
|
|
(doom-initialize-packages)
|
2017-05-21 14:10:33 +02:00
|
|
|
(success! " + Attempt to load DOOM: success! Loaded v%s" doom-version)
|
2017-05-20 18:15:40 +02:00
|
|
|
(when (executable-find "git")
|
2017-05-21 20:25:30 +02:00
|
|
|
(msg! " Revision %s"
|
2017-05-20 18:15:40 +02:00
|
|
|
(or (ignore-errors
|
|
|
|
(let ((default-directory user-emacs-directory))
|
|
|
|
(shell-command-to-string "git rev-parse HEAD")))
|
|
|
|
"\n"))))
|
2017-05-21 14:10:33 +02:00
|
|
|
('error (warn! " + Attempt to load DOOM: failed\n %s\n" (or (cdr-safe ex) (car ex))))))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
(when (bound-and-true-p doom-modules)
|
2017-05-21 20:25:30 +02:00
|
|
|
(msg! " + enabled modules:\n%s"
|
2017-05-20 18:15:40 +02:00
|
|
|
(indented 4
|
2017-05-21 14:10:33 +02:00
|
|
|
(columns 3 23
|
2017-05-20 18:15:40 +02:00
|
|
|
(mapcar (lambda (x) (format "+%s" x))
|
2017-05-21 14:10:33 +02:00
|
|
|
(mapcar #'cdr (doom--module-pairs)))))))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
(when (and (bound-and-true-p doom-packages)
|
|
|
|
(require 'package nil t))
|
|
|
|
(msg! " + enabled packages:\n%s"
|
2017-05-20 18:15:40 +02:00
|
|
|
(indented 4
|
2017-05-21 14:10:33 +02:00
|
|
|
(columns 2 35
|
2017-05-20 18:15:40 +02:00
|
|
|
(mapcar (lambda (pkg)
|
|
|
|
(let ((desc (cadr (assq pkg package-alist))))
|
|
|
|
(when desc
|
|
|
|
(package-desc-full-name desc))))
|
|
|
|
(sort (mapcar #'car doom-packages) #'string-lessp))))))
|
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
(msg! " + byte-compiled files:\n%s"
|
2017-05-20 18:15:40 +02:00
|
|
|
(indented 4
|
2017-05-21 14:10:33 +02:00
|
|
|
(columns 2 39
|
2017-05-20 18:15:40 +02:00
|
|
|
(let ((files (append (directory-files-recursively doom-core-dir ".elc$")
|
|
|
|
(directory-files-recursively doom-modules-dir ".elc$"))))
|
|
|
|
(or (and files (mapcar (lambda (file) (file-relative-name file doom-emacs-dir))
|
|
|
|
(nreverse files)))
|
|
|
|
(list "n/a"))))))
|
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
(msg! " + exec-path:\n%s"
|
2017-05-20 18:15:40 +02:00
|
|
|
(indented 4
|
2017-05-21 14:10:33 +02:00
|
|
|
(columns 1 79 exec-path)))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
2017-05-21 20:25:30 +02:00
|
|
|
(msg! " + PATH:\n%s"
|
2017-05-20 18:15:40 +02:00
|
|
|
(indented 4
|
2017-05-21 14:10:33 +02:00
|
|
|
(columns 1 79 (split-string (getenv "PATH") ":")))))
|
2017-05-20 18:15:40 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
(if (= doom-errors 0)
|
2017-05-21 14:10:33 +02:00
|
|
|
(success! "Everything seems fine, happy Emacs'ing!")
|
|
|
|
(message "\n----")
|
|
|
|
(warn! "There were issues!")
|
2017-05-20 18:15:40 +02:00
|
|
|
(unless (getenv "DEBUG")
|
2017-05-21 20:25:30 +02:00
|
|
|
(msg! "\nHopefully these can help you find problems. If not, run this doctor again with DEBUG=1:")
|
|
|
|
(msg! "\n DEBUG=1 make doctor\n")
|
|
|
|
(msg! "And file a bug report with its output at https://github.com/hlissner/.emacs.d/issues")))
|