diff --git a/Makefile b/Makefile index 68db4ff..4ebb9ab 100644 --- a/Makefile +++ b/Makefile @@ -2,28 +2,14 @@ OS = $(shell uname -s) ifeq ($(OS), Darwin) - PREFIX = /usr/local + PREFIX ?= /usr/local else - PREFIX = /usr + PREFIX ?= /usr endif MANPREFIX = $(PREFIX)/share/man install: - mkdir -p $(DESTDIR)$(PREFIX)/bin - for script in bin/*; do \ - cp -f $$script $(DESTDIR)$(PREFIX)/bin/; \ - chmod 755 $(DESTDIR)$(PREFIX)/$$script; \ - done - mkdir -p $(DESTDIR)$(PREFIX)/share/mutt-wizard - for shared in share/*; do \ - cp -f $$shared $(DESTDIR)$(PREFIX)/share/mutt-wizard; \ - done - if [ "$(OS)" = "Darwin" ]; then \ - sed -iba 's/\/usr\//\/usr\/local\//' $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrc; \ - rm $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrcba; \ - fi - mkdir -p $(DESTDIR)$(MANPREFIX)/man1 - cp -f mw.1 $(DESTDIR)$(MANPREFIX)/man1/mw.1 + utils/install.sh -p "$(PREFIX)" uninstall: for script in bin/*; do \ diff --git a/share/mutt-wizard.muttrc b/share/mutt-wizard.muttrc index a6a19f3..2690d84 100644 --- a/share/mutt-wizard.muttrc +++ b/share/mutt-wizard.muttrc @@ -3,7 +3,15 @@ # mutt-wizard will have this file sourced from your muttrc. # In the interest of seamless updating, do not edit this file. # If you want to override any settings, set those in your muttrc. -set mailcap_path = /usr/share/mutt-wizard/mailcap + +# mailcap_path +# PREFIX will be substituted during install. However, if you prefer to +# use this configuration file as a standalone, consider substituting it +# (along with the %'s surrounding it) for the path to your mutt-wizard's +# mailcap file +# +set mailcap_path = %PREFIX%/share/mutt-wizard/mailcap + set certificate_file = ~/.cache/mutt-wizard/certificates set date_format="%y/%m/%d %I:%M%p" set index_format="%2C %zs %?X?A& ? %D %-15.15F %s (%-4.4c)" diff --git a/utils/install.sh b/utils/install.sh new file mode 100755 index 0000000..532f0c0 --- /dev/null +++ b/utils/install.sh @@ -0,0 +1,102 @@ +#!/bin/bash + + +has_color=false + +if which tput >&/dev/null; then + num_colors=$(tput colors) + [[ -n "${num_colors}" ]] && [[ num_colors -ge 8 ]] && has_color=true +fi + +color_reset='\e[0m' +color_info='\e[1;96m' +color_err='\e[1;91m' +color_bold='\e[0;1m' + +if ! $has_color ; then + color_reset= + color_info= + color_err= + color_bold= +fi + +info() { + echo -e "${color_info}info: ${color_bold}$*${color_reset}" +} + +err() { + >&2 echo -e "${color_err}error: ${color_bold}$*${color_reset}" +} + +prefix=/usr +[[ "$(uname -s)" == "Darwin" ]] && prefix=/usr/local + +usage() { + cat <] [-v] + + -p instalation prefix + (default: ${default_prefix}) + -v verbose + -h | --help this message + +EOF +} + +while [[ $# -gt 0 ]]; do + case $1 in + -h|--help) usage ; exit 0 ;; + -v) set -x ;; + -p) + [[ -z "$2" ]] && \ + err "'-p' requires a prefix to be provided" && exit 1 + prefix=$(realpath -m ${2}) + shift 1 + ;; + *) + err "unrecognized option '${1}'" + exit 1 + ;; + esac + shift 1 +done + +if [[ ! -d "${prefix}" ]] && ! mkdir -p ${prefix} ; then + err "error creating '${prefix}'" + exit 1 +fi + +bindir=${prefix}/bin +sharedir=${prefix}/share +mandir=${sharedir}/man1 + +mkdir -p ${bindir} +for target in bin/*; do + script=$(basename ${target}) + if ! cp -f ${target} ${bindir}; then + err "error: failed copying '${target}' to '${bindir}'" && exit 1 + fi + chmod 755 ${bindir}/${script} +done + +mkdir -p ${sharedir} || exit 1 +for target in share/*; do + shared=$(basename ${target}) + dest=${sharedir}/${shared} + + if ! cp -f ${target} ${dest}; then + err "error: failed copying '${target}' to '${dest}'" && exit 1 + fi + + sed -i "s,%PREFIX%,${concat_dest}," ${dest} + if $(grep -q '%PREFIX%' ${dest}); then + err "error: failed performingg substitutions on '${dest}'" && exit 1 + fi +done + +mkdir -p ${mandir} || exit 1 +if ! cp -f mw.1 ${mandir}/mw.1; then + err "error: failed copying 'mw.1' to '${mandir}'" && exit 1 +fi + +info "install success"