#!/usr/bin/env bash # # Install the Master Password CLI tool. set -e cd "${BASH_SOURCE%/*}" source bashlib inf "This will install the mpw tool." # Try to guess then ask for the bin dir to install to. IFS=: read -a paths <<< "$PATH" if inArray ~/bin "${paths[@]}"; then bindir=~/bin elif inArray ~/.bin "${paths[@]}"; then bindir=~/.bin elif inArray /usr/local/bin "${paths[@]}"; then bindir=/usr/local/bin else bindir=~/bin fi bindir=$(ask -d "$bindir" "What bin directory should I install to?") [[ -d "$bindir" ]] || mkdir "$bindir" || ftl 'Cannot create missing bin directory: %s' "$bindir" || exit [[ -w "$bindir" ]] || ftl 'Cannot write to bin directory: %s' "$bindir" || exit # Install Master Password. install -m555 mpw "$bindir" [[ ! -e "$bindir/bashlib" ]] && install bashlib "$bindir" ||: # Convenience bash function. inf "Installation successful!" echo inf "To improve usability, you can install an mpw function in your bash shell." inf "This function adds the following features:" inf " - Automatically remember your user name in the shell if not set." inf " - Automatically put the password in the clipboard (some platforms)." echo inf "To do this you need the following function in ~/.bashrc:\n%s" "$(> ~/.bashrc inf "Done! Don't forget to run '%s' to apply the changes!" "source ~/.bashrc" fi echo inf "You can also save your user name in ~/.bashrc. Leave blank to skip this step." if MP_FULLNAME=$(ask "Your full name:") && [[ $MP_FULLNAME ]] ; then printf 'export MP_FULLNAME=%q\n' "$MP_FULLNAME" >> ~/.bashrc fi echo inf "To begin using Master Password, type: mpw [site name]"