scripts/install.sh

58 lines
1.3 KiB
Bash
Raw Normal View History

2020-02-17 20:21:31 +00:00
#!/bin/sh
_install_dir="/usr/local/bin/"
_uninstall=0
2020-02-25 09:12:33 +00:00
_overwrite=0
2020-02-25 09:21:03 +00:00
_exit_status=0
_show_help=0
2020-02-17 20:21:31 +00:00
for _arg in "$@" ; do
if [ "$_arg" = "-u" ] || [ "$_arg" = "--uninstall" ] ; then
_uninstall=1
2020-02-25 09:12:33 +00:00
elif [ "$_arg" = "-o" ] || [ "$_arg" = "--overwrite" ] ; then
_overwrite=1
2020-02-25 09:21:03 +00:00
elif [ "$_arg" = "-h" ] || [ "$_arg" = "--help" ] ; then
_show_help=1
2020-02-17 20:21:31 +00:00
else
echo "warning: unknown option."
2020-02-25 09:21:03 +00:00
_show_help=1
2020-02-17 20:21:31 +00:00
fi
done
2020-02-25 09:21:03 +00:00
if [ "$_show_help" -eq 1 ] ; then
echo ""
echo "TODO - Show Help"
echo "Look at source code for now - there's only two options."
exit "$_exit_status"
fi
2020-02-17 20:21:31 +00:00
echo "Install directory: '$_install_dir'"
echo ""
for _file in ./src/* ; do
_destination="$_install_dir"$(basename "$_file")
2020-02-17 20:21:31 +00:00
if [ $_uninstall -eq 0 ] ; then
2020-02-25 09:12:33 +00:00
if [ ! -e "$_destination" ] || [ "$_overwrite" -eq 1 ] ; then
echo "installing: $_file"
sudo cp "$_file" "$_install_dir"
else
echo "file present - skipping: $_file"
fi
2020-02-17 20:21:31 +00:00
elif [ $_uninstall -eq 1 ] ; then
# WARNING - need to ensure $_filename is not empty (/usr/local/bin will be deleted)
if [ -n "$_destination" ] ; then
echo "uninstalling: $_destination"
sudo rm "$_install_dir$_destination"
2020-02-17 20:21:31 +00:00
fi
fi
done
if [ $_uninstall -eq 0 ] ; then
echo ""
echo "Install complete -- uninstall with"
echo " ./install -u"
else
echo ""
echo "Uninstall complete"
fi