scripts/install.sh

66 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
# The directory where this script lives - used as the base for finding all
# of the scripts to be installed.
src_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Set default values for installation parameters.
script_dir="$HOME/.local/bin"
install_target="all"
install_scripts=true
display_targets () {
echo 'Valid targets: all, scripts'
}
display_usage () {
echo 'Usage: install.sh [--script-dir <path>] [-h|--help]'
echo ''
echo 'Install scripts.'
echo ''
echo ' --script-dir Location for installed scripts.'
echo " Default = \$HOME/.local/bin"
echo ' -h|--help Display this usage text.'
echo ''
echo 'Examples:'
echo ''
echo "./install.sh"
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--script-dir)
script_dir="$2"
shift
shift
;;
-h|--help)
display_usage
exit 0
;;
*)
echo "Unrecognized option: $1"
display_usage
exit 1
;;
esac
done
# Validate the selected script directory.
if [ ! -d "$script_dir" ]; then
echo "Installation directory for scripts does not exist or is not a directory (${script_dir})"
exit 1
fi
if $install_scripts; then
echo "Installing all scripts to: ${script_dir}"
cp -f "$src_dir"/src/* "${script_dir}"
fi