#!/bin/sh # # Install skyserver.el in the desired place, and configure .emacs # as appropriate # emacs="?"; : modify .emacs file force=0 install_dir="." MacOSX=0; : hack input files for Mac OS/X mkpath=0; : make output dir if neccessary rhl_lisp=0; : install RHL lisp hacks stdout="?"; : write lisp to stdout use_curl=0; : use curl not lynx verbose=0 while [ X"$1" != X"" ]; do case "$1" in -c) use_curl=1;; -d) shift if [ X"$1_dir" = X"" ]; then echo "Please specify a directory with -d" >&2 exit 1 fi install_dir=$1;; -e) emacs=1;; -f) force=1;; -m) MacOSX=1;; -p) mkpath=1;; -r) rhl_lisp=1;; -s) stdout=1;; -S) stdout=0;; -v) verbose=1;; *) if [ X$1 != X"-h" ]; then echo "Unknown option $1" >&2 fi cat <&2 Usage: install -(e|s|S) [-c] [-d DIR] [-f] [-h] [-m] [-p] [-r] [-v] Install the emacs skyserver-mode code into directory DIR (default: .) and write the magic lisp that should be added to the user's .emacs file to stdout (with -s) or modify the user's .emacs file directly (with -e). If the files to be installed are already present, they won't be overwritten unless -f is specified. Options: -c Use curl, not lynx, to connect to skyserver -d DIR Install files in directory DIR -e Modify user's .emacs file -f Install files even if they exist -h Print this help message -m Assume that you're running Mac OS/X (implies -c) -p Create path to install directory if needed -r Install all RHL lisp, not just minimal set to run -s Don't modify user's .emacs file, write lisp to stdout -S Neither modify user's .emacs file nor write lisp to stdout -v Be chattier For example, on my G4 powerbook, I said install -d . -e -m emacs examples.sql to try out skyserver mode (the -m works around Mac OS/X emacs bug and selects curl not lynx to talk http); I could have then said mv \$HOME/save.emacs \$HOME/.emacs install -d /usr/local/emacs/lisp -e -m -r to install in a Standard Place, and to install a bit more RHL lisp. Your old .emacs file is backed up in \$HOME/save.emacs, but the conservative amongst you will make your own secret backup too. EOT exit 1;; esac shift done # # They must tell us where to write the lisp # if [ $emacs = "1" ]; then if [ $stdout = "1" ]; then echo "You may not specify -e and -s; please make up your mind and try again" >&2 fi stdout=0 fi if [ $emacs = "?" -a \( $stdout = 0 -o $stdout = "1" \) ]; then emacs=0 fi if [ $emacs = "?" -a $stdout = "?" ]; then echo "I'm afraid that you must specify -e, -s, or -S" >&2 exit 1 fi # # Done with argument parsing # if [ `uname` = "Darwin" ]; then if [ $verbose = 1 ]; then echo " You're running `uname`; setting -m" fi MacOSX=1 fi if [ "X$MacOSX" != X"" ]; then use_curl=1 fi # # Which files do we want to install # files=""; for f in *.el; do files="$files $f"; done if [ X"$files" = X" *.el" ]; then echo "I cannot find the files that I should install; are you in the source directory?" >&2 exit 2 fi if [ ! -d $install_dir -a $mkpath = 1 ]; then if [ $verbose = 1 ]; then echo " Creating $install_dir" fi mkdir -p $install_dir fi if [ ! -d $install_dir ]; then echo "Directory $install_dir doesn't exist" >&2 exit 1 fi if [ $verbose = 1 ]; then echo " Installing $files into $install_dir" fi if [ "`ls -id .`" != "`ls -id $install_dir`" ]; then allow_copy=1 else if [ $verbose = 1 ]; then echo "Install directory is current directory; not copying files" >&2 fi allow_copy=0 fi if [ "$install_dir" = "." ]; then apath=`pwd | awk "{print \$1}"` if [ $verbose = 1 ]; then echo " Changing install dir \"$install_dir\" into absolute path \"$apath\"" fi install_dir=$apath fi if [ $allow_copy = 1 ]; then for f in $files; do if [ -e "$install_dir/$f" -a $force != 1 ]; then echo "$f already exists in $install_dir; not copying" >&2 else cp $f $install_dir fi done fi # # Time to create correct lisp to use those files # idir=`echo $install_dir | sed -e 's/\//\\\\\//g'` fix_path="s/\\/your\\/site\\/lisp\\/directory/$idir/" if [ $rhl_lisp = 0 ]; then noRHL="/eval-after-load/q" else noRHL="s/XXX/XXX/" fi # # Print lisp/modify .emacs file # if [ $stdout = 1 ]; then sed -e "$fix_path" -e "$noRHL" dot.emacs elif [ $emacs = 1 ]; then demacs=$HOME/.emacs if [ "`grep -s skyserver-mode $demacs`" != "" ]; then echo "Code to install skyserver-mode is already present in $demacs; not changing file" >&2 else if [ $verbose = 1 ]; then echo " Installing skyserver-mode code in file $demacs" fi backup=$HOME/save.emacs if [ -e $demacs ]; then if [ -e $backup ]; then if [ $force = 0 ]; then echo "File $backup exists; not modifying .emacs; specify -f to override" >&2 exit 1 else cp $demacs $backup fi else cp $demacs $backup fi fi sed -e "$fix_path" -e "$noRHL" dot.emacs >> $demacs fi else echo "You may need to setup your lisp environment by hand, or consider using -e or -s" fi # # Customize installation enough to work # if [ $MacOSX = 1 -o $use_curl = 1 ]; then custom=0 if [ $MacOSX = 1 ]; then custom=1 set1="(customize-save-variable 'skyserver-read-result-via-disk t)" else set1="(sit-for 0)" fi if [ $use_curl = 1 ]; then custom=1 set2="(customize-save-variable 'skyserver-send-url \"curl -q -m 99999 -s -S\")" else set2="(sit-for 0)" fi if [ $custom = 1 ]; then if [ $verbose = 1 ]; then echo " Setting customisation variables" fi if [ $stdout = 1 ]; then echo ""; echo "-=-=-=-=-=-=-=-=-=- End of Cut-And-Paste -=-=-=-=-=-=-=-=-=-" echo "" echo "You need to set these variables:" for s in "$set1" "$set2"; do if [ "`echo $s | grep 'sit-for'`" = "" ]; then s=`echo $s | sed -e "s/^[^ ]* '//" -e "s/ / /" -e "s/)\$//"` echo " $s" fi done elif [ $emacs = 1 ]; then emacs -nw --eval "$set1" --eval "$set2" \ --eval "(kill-emacs)" < /dev/tty > /dev/null 2>&1 fi fi fi