4

I would like to, as part of Emacs Lisp package set-up process to run some programs which typically require superuser access, for instance, I would like to make sure that certain system packages are installed, and if not, then install them, I would also need to configure a database, which, will also require superuser access (once, in order to add a user with reduced privileges to operate on her own database).

I was hoping to enlist Tramp for help, but after some searching, couldn't find a way to do it.

Note, what I need is:

  1. Make sure I need the permissions to do what I want.
  2. If test comes out positive, ask the user to start a shell with elevated permissions.

From that point on, I think I could manage it.

  • el-get's apt-get method does something like this, the idea is to run sudo directly (not as a shell command) and use a process-filter to catch the password prompt. – npostavs Dec 1 '15 at 15:30
  • 1
    Question 1: Is detecting that login account is or isn't superuser sufficient? Question 2: Will the shell be interactive or just run a specific script or command without any user interaction? Question 3: Will emacs be running locally or on a remote server? – Melioratus Jan 28 '16 at 5:41
  • @Melioratus sorry it took me forever to reply. (1) Nope, detecting is not sufficient, I will need to run programs on user's behalf. (2) No need for interactive shell. (3) Emacs will be running locally. – wvxvw Feb 21 '16 at 17:06
1

This could almost be it, except for the part, where I don't know how to make the shell buffer wait until the user finishes the interaction

(defun sphinx-install-prerequisites ()
  (let ((dir (format "/sudo::%s" (sphinx-install-dir)))
        (current default-directory))
    (cd dir)
    (condition-case error
        (progn
          (shell "sphinx-install")
          (pop-to-buffer (current-buffer))
          (goto-char (point-max))
          (insert "./install.sh")
          (comint-send-input))
      ;; Wait until the script finishes
      (with-local-quit
        (while (get-buffer-process "sphinx-install")
          (sleep-for 5)
          (accept-process-output)))
      (error
       (message "Installation failed. 
You may still try to read %s and perform the required installations manually.")))
    (cd current)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.