Skip to content

Instantly share code, notes, and snippets.

@arcizan
Created April 8, 2015 05:54
Show Gist options
  • Save arcizan/06368f112d1a4d344c03 to your computer and use it in GitHub Desktop.
Save arcizan/06368f112d1a4d344c03 to your computer and use it in GitHub Desktop.
Install script for Mew
#!/bin/bash
######################################################################
# declare variables
full_cmdname="$0"
cmdname=$(basename -- "$full_cmdname" ".sh")
LD_RUN_PATH="/usr/local/lib"
export LD_RUN_PATH
# define functions
function error(){
[[ "$#" -gt 0 ]] && printf -- "%b\n" "$*" 1>&2
exit 1
}
function yes_no(){
local _prompt="(yes/no) "
[[ "$#" -gt 0 ]] && _prompt="$@ $_prompt"
while [[ 1 ]]; do
read -p "$_prompt"
REPLY=$(tr '[A-Z]' '[a-z]' <<< "$REPLY")
case "$REPLY" in
yes) return 0;;
no) return 1;;
esac
_prompt="Please answer (yes/no) "
done
}
# check the current directory
basename=$(basename -- "$PWD")
if ! grep -qxe 'mew-[0-9]\+\.[0-9]' <<< "$basename" ; then
error "${cmdname}: Please execute this script at \`mew-(version)' directory"
fi
# prefix
read -p "${cmdname}: Prefix (default /usr/local): " prefix
[[ -z "$prefix" ]] && prefix="/usr/local"
# emacs flavor
read -p "${cmdname}: Emacs version: " emacs_version
emacs="${prefix}/bin/emacs-$emacs_version"
[[ -x "$emacs" ]] || error "${cmdname}: Not found \`$emacs'"
# lisp directory
site_lisp="${prefix}/share/emacs/${emacs_version}/site-lisp"
[[ -d "$site_lisp" ]] || error "${cmdname}: No such directory \`$site_lisp'"
elispdir="${site_lisp}/.$basename"
# etc directory
etcdir="${elispdir}/etc"
# configure options
configure_opts="--prefix=${prefix} --with-emacs=${emacs} --with-elispdir=${elispdir} --with-etcdir=${etcdir}"
# do configure
./configure $configure_opts 2>&1 | tee -- "${basename}_configure.log"
[[ "${PIPESTATUS[0]}" -eq 0 ]] || exit ${PIPESTATUS[0]}
# do make all
make all 2>&1 | tee -- "${basename}_make.log"
[[ "${PIPESTATUS[0]}" -eq 0 ]] || exit ${PIPESTATUS[0]}
# do make install install-jinfo
if yes_no "${cmdname}: Do \`make install install-jinfo'?"; then
sudo make install install-jinfo 2>&1 | tee -- "${basename}_make-install.log"
[[ "${PIPESTATUS[0]}" -eq 0 ]] || exit ${PIPESTATUS[0]}
sudo ln -sf -- ".$basename" "${site_lisp}/mew" || exit $?
sudo touch -- "${etcdir}/.nosearch" || exit $?
[[ -d "contrib" ]] && { sudo cp -r -- contrib "$elispdir" || exit $?; }
fi
exit 0
######################################################################
### Local Variables:
### mode: shell-script
### coding: utf-8-unix
### tab-width: 4
### End:
######################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment