/
bash-snippets
executable file
·174 lines (162 loc) · 4.59 KB
/
bash-snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/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.22.1"
configuredClient=""
## This function determines which http get tool the system has installed and returns an error if there isnt one
getConfiguredClient()
{
if command -v curl &>/dev/null; then
configuredClient="curl"
elif command -v wget &>/dev/null; then
configuredClient="wget"
elif command -v http &>/dev/null; then
configuredClient="httpie"
elif command -v fetch &>/dev/null; then
configuredClient="fetch"
else
echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2
return 1
fi
}
httpGet()
{
case "$configuredClient" in
curl) curl -A curl -s "$@" ;;
wget) wget -qO- "$@" ;;
httpie) http -b GET "$@" ;;
fetch) fetch -q "$@" ;;
esac
}
grablatestversion()
{
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()
{
httpGet github.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query github with a get request
}
header()
{
title="Bash Snippets"
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"
}
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 clear; header; break; fi
echo -e -n "\t\tEnter any arguments you want to use with the tool: "
read args
clear
if [[ $choice =~ [0-9] ]]; then ${validTools[$(($choice-1))]} $args
else $choice $args; fi
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!"
sleep 2
clear
header
continue
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
sleep 2
clear
header
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 clear; 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
}
if [[ $# -eq 0 ]]; then
clear
checkInternet
getConfiguredClient
grablatestversion
header
installationcheck false
echo
menu
elif [[ $# -eq 1 ]]; then
if [[ $1 == "-u" || $1 == "update" ]]; then
installationcheck false
${validTools[1]} -u
elif [[ $1 == "-h" || $1 == "help" ]];then man bash-snippets
elif [[ $1 == "-v" ]]; then echo "Version $currentVersion"
fi
fi