Completed initial version of bash-snippets script

This commit is contained in:
Alex Epstein 2018-02-21 22:08:05 -05:00
parent b1e586528d
commit 3ddb9a0aa9
1 changed files with 100 additions and 22 deletions

122
bash-snippets.sh Normal file → Executable file
View File

@ -1,5 +1,7 @@
#!/bin/env bash
#!/usr/bin/env bash
# Author: Navan Chauhan and Alexander Epstein
declare -a tools=(cheat cloudup crypt cryptocurrency currency geo lyrics meme movies newton pwned qrify short siteciphers stocks taste todo transfer weather ytview)
declare -a validTools=()
currentVersion="1.21.0"
configuredClient=""
@ -32,10 +34,9 @@ httpGet()
grablatestversion()
{
repositoryName="Bash-Snippets"
repositoryName="Bash-Snippets"
githubUserName="alexanderepstein"
latestVersion=$(httpGet https://api.github.com/repos/$githubUserName/$repositoryName/tags | grep -Eo '"name":.*?[^\\]",'| head -1 | grep -Eo "[0-9.]+" ) #always grabs the tag without the v option
}
checkInternet()
@ -43,33 +44,110 @@ checkInternet()
httpGet github.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query github with a get request
}
header(){
COLUMNS=$(tput cols)
header()
{
title="Bash Snippets"
installver="Installed Version : $currentVersion"
latestver="Latest Version : $latestVersion"
printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$title"
printf "%*s\n" $(((${#installver}+$COLUMNS)/2)) "$installver"
printf "%*s\n" $(((${#latestver}+$COLUMNS)/2)) "$latestver"
installver="Installed Version: $currentVersion"
latestver="Latest Version: $latestVersion"
printf "\t\t\t\t %s\n" "$title"
printf "\t\t%s\t\t%s\n" "$latestver" "$installver"
}
installationcheck(){
cd /usr/local/bin
for f in cheat cloudup crypt cryptocurrency currency geo lyrics meme movies newton qrify short siteciphers stocks taste todo transfer weather ytview
do
if [ -e $f ]
then
echo "$f is installed"
else
echo "$f is not installed"
fi
toolMenu()
{
while true; do
clear
header
count=1
for command in "${validTools[@]}"; do
if [[ $count -gt 9 ]];then c=$count
else c="0$count"; fi
spaces=$((40 - $(echo $command | wc -c)))
echo -n -e "\t\t\t$c."
for (( i = 0 ; i < $spaces; i++)) ;do
printf " "
done
echo "$command"
count=$(( $count + 1 ))
done
echo -e -n "\t\tChoose a tool or just press enter to go back: "
read choice
if [[ $choice == "" ]];then break; fi
echo -e -n "\t\tEnter any arguments you want to use with the tool: "
read args
clear
${validTools[$(($choice-1))]} $args
exit 0
done
}
menu()
{
while true; do
echo -e "\t\t\t01.\t\t\t\tTools"
echo -e "\t\t\t02.\t\t\t\tInstallation Check"
echo -e "\t\t\t03.\t\t\t\tView man page"
echo -e "\t\t\t04.\t\t\t\tUpdate"
echo -e "\t\t\t05.\t\t\t\tDonate"
echo -e "\t\t\t06.\t\t\t\tQuit"
echo -e -n "\n\t\t\tChoose an option: "
read choice
if [[ $choice -gt 6 || $choice -lt 1 ]];then echo "Error invalid option!"; exit 1; fi
clear
header
if [[ $choice -eq 1 ]];then toolMenu
elif [[ $choice -eq 2 ]];then installationcheck
elif [[ $choice -eq 3 ]];then man bash-snippets
elif [[ $choice -eq 4 ]];then ${validTools[1]} -u
elif [[ $choice -eq 5 ]];then
clear
echo -e "\t\tThanks for thinking of donating, that's pretty cool of you"
echo -e "\n\t\tCryptocurrency Donation Addresses"
echo -e "\t\t\tBTC: 38Q5VbH63MtouxHu8BuPNLzfY5B5RNVMDn"
echo -e "\t\t\tETH: 0xf7c60C06D298FF954917eA45206426f79d40Ac9D"
echo -e "\t\t\tLTC: LWZ3T19YUk66dgkczN7dRhiXDMqSYrXUV4\n"
echo -e "\t\tNormal Methods"
echo -e "\t\t\tVenmo: AlexanderEpstein"
echo -e "\t\t\tSquare Cash: AlexEpstein\n\n\n\n"
exit 0
elif [[ $choice -eq 6 ]]; then exit 0
fi
done
}
installationcheck()
{
validTools=()
for tool in "${tools[@]}"; do
if [ -e "/usr/local/bin/$tool" ]; then
state="present";
start=51;
validTools+=($tool);
else state="absent"; start=52; fi
if $1; then
echo -n -e "\t\t$tool"
spaces=$(($start - $( echo $tool | wc -c)))
for (( i = 0 ; i < $spaces; i++)) ;do
printf " "
done
echo $state
fi
done
if $1; then
echo -n "Press enter to go back to the menu"
read
clear
header
fi
}
clear
checkInternet
getConfiguredClient
grablatestversion
header
installationcheck
installationcheck false
echo
menu