2014-05-05 15:16:59 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-06-07 19:51:11 +00:00
|
|
|
#
|
|
|
|
# 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
|
2014-05-05 15:16:59 +00:00
|
|
|
fi
|
2014-06-07 19:51:11 +00:00
|
|
|
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.
|
2017-03-29 04:32:15 +00:00
|
|
|
install -m555 mpw "$bindir"
|
2014-06-07 19:51:11 +00:00
|
|
|
[[ ! -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" "$(<mpw.bashrc)"
|
|
|
|
echo
|
|
|
|
inf "We can do this for you automatically now."
|
|
|
|
if ask -c Y!n "Append the mpw function to your .bashrc?"; then
|
|
|
|
cat mpw.bashrc >> ~/.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."
|
2017-09-04 18:17:20 +00:00
|
|
|
if MPW_FULLNAME=$(ask "Your full name:") && [[ $MPW_FULLNAME ]] ; then
|
|
|
|
printf 'export MPW_FULLNAME=%q\n' "$MPW_FULLNAME" >> ~/.bashrc
|
|
|
|
fi
|
|
|
|
inf "If you have an askpass program you'd like to use, you can specify it here."
|
|
|
|
inf "An askpass program provides a graphical interface for entering things like your master password."
|
|
|
|
inf "Leave blank to skip this step and enter passwords using the terminal."
|
|
|
|
if [[ ! $MPW_ASKPASS ]] && hash ssh-askpass 2>/dev/null; then
|
|
|
|
MPW_ASKPASS=ssh-askpass
|
|
|
|
fi
|
|
|
|
if MPW_ASKPASS=$(ask +"$MPW_ASKPASS" "askpass program:") && [[ $MPW_ASKPASS ]] ; then
|
|
|
|
printf 'export MPW_ASKPASS=%q\n' "$MPW_ASKPASS" >> ~/.bashrc
|
2014-06-07 19:51:11 +00:00
|
|
|
fi
|
|
|
|
echo
|
|
|
|
|
2017-09-04 18:17:20 +00:00
|
|
|
inf "Shell features installed."
|
|
|
|
inf "To load these convenience features into your already running shell, type: source ~/.bashrc"
|
|
|
|
inf "To begin using Master Password, type: mpw -h or mpw my-site-name"
|