2017-07-21 06:16:52 +02:00
#!/usr/bin/env bash
2017-06-27 01:57:39 +02:00
# Author: Alexander Epstein https://github.com/alexanderepstein
2017-08-30 08:12:13 +02:00
currentVersion = "1.19.1"
2017-08-20 19:44:05 +02:00
declare -a tools = ( cheat cloudup crypt cryptocurrency currency geo lyrics movies newton qrify short siteciphers stocks taste todo transfer weather ytview)
2017-07-25 02:49:49 +02:00
declare -a extraLinuxTools = ( maps)
declare -a extraDarwinTools
2017-07-18 23:04:01 +02:00
usedGithubInstallMethod = "0"
2017-07-26 20:27:17 +02:00
prefix = "/usr/local"
2017-07-26 17:26:56 +02:00
2017-07-07 02:45:32 +02:00
askInstall( )
{
echo -n " Do you wish to install $1 [Y/n]: "
2017-07-04 02:09:22 +02:00
read -r answer
2017-07-26 20:18:59 +02:00
if [ [ " $answer " = = [ Yy] ] ] ; then
2017-07-07 02:45:32 +02:00
cd $1 || return 1
2017-07-07 23:06:51 +02:00
echo -n " Installing $1 : "
chmod a+x $1
cp $1 /usr/local/bin > /dev/null 2>& 1 || { echo "Failure" ; echo "Error copying file, try running install script as sudo" ; exit 1; }
echo "Success"
2017-07-07 02:45:32 +02:00
cd .. || return 1
2017-07-04 02:09:22 +02:00
fi
2017-07-07 02:45:32 +02:00
}
2017-07-04 02:09:22 +02:00
2017-07-07 02:45:32 +02:00
updateTool( )
{
2017-07-26 20:18:59 +02:00
if [ [ -f /usr/local/bin/$1 ] ] ; then
2017-07-18 23:04:01 +02:00
usedGithubInstallMethod = "1"
2017-07-07 06:18:07 +02:00
cd $1 || return 1
2017-07-07 23:06:51 +02:00
echo -n " Installing $1 : "
chmod a+x $1
cp $1 /usr/local/bin > /dev/null 2>& 1 || { echo "Failure" ; echo "Error copying file, try running install script as sudo" ; exit 1; }
echo "Success"
2017-07-07 06:18:07 +02:00
cd .. || return 1
2017-07-04 15:04:37 +02:00
fi
2017-07-07 02:45:32 +02:00
}
2017-07-08 08:40:29 +02:00
2017-07-25 02:49:49 +02:00
extraUpdateTool( )
{
2017-07-26 20:18:59 +02:00
if [ [ -f /usr/local/bin/$1 ] ] ; then
2017-07-25 02:49:49 +02:00
usedGithubInstallMethod = "1"
cd extras || return 1
cd $2 || return 1
cd $1 || return 1
echo -n " Installing $1 : "
chmod a+x $1
cp $1 /usr/local/bin > /dev/null 2>& 1 || { echo "Failure" ; echo "Error copying file, try running install script as sudo" ; exit 1; }
echo "Success"
cd .. || return 1
cd .. || return 1
cd .. || return 1
fi
}
2017-07-07 06:18:07 +02:00
singleInstall( )
{
cd $1 || exit 1
2017-07-07 23:06:51 +02:00
echo -n " Installing $1 : "
chmod a+x $1
2017-07-26 17:26:56 +02:00
cp $1 $prefix /bin > /dev/null 2>& 1 || { echo "Failure" ; echo "Error copying file, try running install script as sudo" ; exit 1; }
2017-07-07 23:06:51 +02:00
echo "Success"
2017-07-05 19:00:17 +02:00
cd .. || exit 1
2017-07-07 06:18:07 +02:00
}
2017-07-08 08:40:29 +02:00
copyManpage( )
{
2017-08-02 03:16:27 +02:00
manPath = " $prefix /share/man/man1 "
if [ -f " $prefix /man/man1/bash-snippets.1 " ] ; then rm -f " $prefix /man/man1/bash-snippets.1 " ; fi
2017-07-26 20:18:59 +02:00
cp bash-snippets.1 $manPath 2>& 1 || { echo "Failure" ; echo "Error copying file, try running install script as sudo" ; exit 1; }
2017-07-08 08:40:29 +02:00
}
2017-07-26 17:26:56 +02:00
response = $( echo " $@ " | grep -Eo "\-\-prefix" )
2017-07-26 20:18:59 +02:00
if [ [ $response = = "--prefix" ] ] ; then
2017-08-01 16:49:28 +02:00
prefix = $( echo -n " $@ " | sed -e 's/--prefix=\(.*\) .*/\1/' | cut -d " " -f 1)
2017-08-02 03:16:27 +02:00
mkdir -p $prefix /bin $prefix /share/man/man1
2017-07-30 19:31:05 +02:00
if [ [ $2 = = "all" ] ] ; then
for tool in " ${ tools [@] } " ; do
singleInstall $tool || exit 1
done
else
2017-08-01 03:14:18 +02:00
for tool in " ${ @ : 2 } " ; do
singleInstall $tool || exit 1
done
2017-07-30 19:31:05 +02:00
fi
2017-07-26 17:26:56 +02:00
copyManpage || exit 1
elif [ [ $# = = 0 ] ] ; then
2017-07-26 20:18:59 +02:00
for tool in " ${ tools [@] } " ; do
2017-07-07 06:18:07 +02:00
askInstall $tool || exit 1
done
2017-07-08 08:40:29 +02:00
copyManpage || exit 1
2017-06-28 04:24:43 +02:00
elif [ [ $1 = = "update" ] ] ; then
echo "Updating scripts..."
2017-07-26 20:18:59 +02:00
for tool in " ${ tools [@] } " ; do
2017-07-07 06:18:07 +02:00
updateTool $tool || exit 1
done
2017-07-26 20:18:59 +02:00
if [ [ $( uname -s) = = "Linux" ] ] ; then
for tool in " ${ extraLinuxTools [@] } " ; do
2017-07-25 02:49:49 +02:00
extraUpdateTool $tool Linux || exit 1
done
fi
if [ [ $( uname) = = "Darwin" ] ] ; then
2017-07-26 20:18:59 +02:00
for tool in " ${ extraDarwinTools [@] } " ; do
2017-07-25 02:49:49 +02:00
extraUpdateTool $tool Darwin || exit 1
done
fi
2017-07-26 20:18:59 +02:00
if [ [ $usedGithubInstallMethod = = "1" ] ] ; then
copyManpage || exit 1
else
echo "It appears you have installed bash-snippets through a package manager, you must update it with the respective package manager."
2017-08-02 05:52:28 +02:00
exit 1
2017-07-26 20:18:59 +02:00
fi
elif [ [ $1 = = "all" ] ] ; then
for tool in " ${ tools [@] } " ; do
2017-07-07 06:18:07 +02:00
singleInstall $tool || exit 1
done
2017-07-08 08:40:29 +02:00
copyManpage || exit 1
2017-07-07 06:18:07 +02:00
else
singleInstall $1 || exit 1
2017-07-08 08:40:29 +02:00
copyManpage || exit 1
2017-06-28 03:47:23 +02:00
fi
2017-07-05 19:00:17 +02:00
echo -n "( •_•)"
sleep .75
echo -n -e "\r( •_•)>⌐■-■"
sleep .75
echo -n -e "\r "
echo -e "\r(⌐■_■)"
sleep .5
2017-06-28 03:47:23 +02:00
echo " Bash Snippets version $currentVersion "
echo "https://github.com/alexanderepstein/Bash-Snippets"