edoit - poor man's gnuserv
Some months ago, I expressed frustration here with the direction
upstream was taking gnuserv, and the fact that the Debian maintainer
seemed happy with it. Since then, there has been a new Debian
maintainer, but other than that nothing significant has happened. So
I decided to drop gnuserv altogether and switch back to
emacsserver/emacsclient. Of course, that left me without gnudoit
functionality, so I wrote this little hack of my own. Comments are
invited, especially about potential security hazards.
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2002-05-13 13:52 PDT by <itz@kronstadt>.
# Source directory was `/home/itz/edoit'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 544 -rwxr-xr-x edoit
# 3047 -rw-r--r-- edoit.el
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh23570; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= edoit ==============
if test -f 'edoit' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'edoit' '(file already exists)'
else
shar: Saving edoit (text)
$echo 'x -' extracting 'edoit' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'edoit' &&
#! /bin/sh
X
PATH=/bin:/usr/bin
X
type=
file=
X
usage () {
X echo 'Usage: edoit ELISP_FORM | edoit - | edoit -f FILE' >&2
X echo '-f : take Lisp from FILE, copy to spool' >&2
X exit 1
}
X
if [ $# -eq 0 ]; then usage ; fi
X
spoolfile=`tempfile --directory $HOME/.edoit`
X
case "$1" in
X -) if [ $# -ne 1 ]; then usage ; fi ; cat > $spoolfile ;;
X -f) if [ $# -ne 2 ]; then usage ; fi ; cp "$2" $spoolfile ;;
X *) if [ $# -ne 1 ]; then usage ; fi ; echo "$1" > $spoolfile ;;
esac
X
emacsclient --no-wait $spoolfile
SHAR_EOF
(set 20 02 05 13 13 40 25 'edoit'; eval "$shar_touch") &&
chmod 0755 'edoit' ||
$echo 'restore of' 'edoit' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'edoit:' 'MD5 check failed'
7e494af85cbef2bace33cfc80b2f6ae8 edoit
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'edoit'`"
test 544 -eq "$shar_count" ||
$echo 'edoit:' 'original size' '544,' 'current size' "$shar_count!"
fi
fi
# ============= edoit.el ==============
if test -f 'edoit.el' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'edoit.el' '(file already exists)'
else
shar: Saving edoit.el (text)
$echo 'x -' extracting 'edoit.el' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'edoit.el' &&
;;; edoit.el --- poor man's gnuserv.el on top of emacsserver
X
;; Copyright (C) 2002 Ian Zimmerman <itz@speakeasy.org>
X
;; Keywords: processes
X
;; This file is not part of GNU Emacs, but is nonetheless distributed
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
X
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
X
;;; Commentary:
X
;; The purpose of this library is to provide a remote Lisp evaluation
;; functionality similar to what is available in the gnuserv package
;; (which is getting more and more optimized for XEmacs, so I gave up
;; on it).
X
;; In order to use it, you must put this code in your .emacs file.
X
;; (load-library "edoit")
;; (server-start)
X
;; You can then send remote commands to Emacs by running the program
;; "edoit". For example,
;;
;; edoit '(gnus)'
;;
;; Type "edoit -h" (sorry, no Info manual yet) for details.
X
;;; Code:
X
(defvar edoit-directory (concat (expand-file-name "~") "/.edoit/")
X "Directory for spooled Lisp files submitted for evaluation by Emacs server.")
X
(defun edoit-safe-file (filename)
X "Check that FILENAME is owned by user running Emacs, and has perms at most 700."
X (let ((attrs (file-attributes filename)))
X (and (= (nth 2 attrs) (user-uid))
X (string-equal (substring (nth 8 attrs) 4) "------"))))
X
(defun edoit-server-visit-hook ()
X "Hook function to evaluate Lisp sent from remote processes.
If `server-visit-hook' is set to this, files in a special subdirectory
of ~ get evaluated when visited in a server buffer."
X (if (string-equal edoit-directory
X (file-name-directory (expand-file-name
X buffer-file-name)))
X (if (and (edoit-safe-file edoit-directory)
X (edoit-safe-file buffer-file-name))
X (eval-buffer)
X (message "Suspect remote evaluation request, not evaluating"))))
X
(defun edoit-server-switch-hook ()
X "Hook function to clean up after evaluating Lisp sent from remote processes.
If `server-switch-hook' is set to this, server buffers visiting files
in a special subdirectory of ~ get killed, and the corresponding files
deleted, as soon as Emacs switches to them."
X (if (string-equal edoit-directory
X (file-name-directory (expand-file-name
X buffer-file-name)))
X (if (and (edoit-safe-file edoit-directory)
X (edoit-safe-file buffer-file-name))
X (progn
X (delete-file buffer-file-name)
X (kill-buffer nil))
X (message "Suspect remote evaluation request, not killing"))))
X
(add-hook 'server-switch-hook 'edoit-server-switch-hook t)
(add-hook 'server-visit-hook 'edoit-server-visit-hook)
X
(provide 'edoit)
X
;;; edoit.el ends here
X
X
X
X
X
X
SHAR_EOF
(set 20 02 05 13 13 40 25 'edoit.el'; eval "$shar_touch") &&
chmod 0644 'edoit.el' ||
$echo 'restore of' 'edoit.el' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'edoit.el:' 'MD5 check failed'
997cd55da0c3cbbd1ae20a0fd64c4251 edoit.el
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'edoit.el'`"
test 3047 -eq "$shar_count" ||
$echo 'edoit.el:' 'original size' '3047,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh23570
exit 0
--
Ian Zimmerman, Oakland, California, U.S.A.
GPG: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087
EngSoc adopts market economy: cheap is wasteful, efficient is expensive.
--
To UNSUBSCRIBE, email to debian-emacsen-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to: