-
-
Notifications
You must be signed in to change notification settings - Fork 845
/
install.sh
executable file
·131 lines (122 loc) · 3.69 KB
/
install.sh
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
#!/usr/bin/env bash
# Author: Alexander Epstein https://github.com/alexanderepstein
currentVersion="1.23.0"
declare -a tools=(bak2dvd bash-snippets cheat cloudup crypt cryptocurrency currency geo gist lyrics meme movies newton pwned qrify short siteciphers stocks taste todo transfer weather ytview)
declare -a extraLinuxTools=(maps)
declare -a extraDarwinTools
usedGithubInstallMethod="0"
prefix="/usr/local"
askInstall()
{
read -p "Do you wish to install $1 [Y/n]: " answer
answer=${answer:-Y}
if [[ "$answer" == [Yy] ]]; then
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
fi
}
updateTool()
{
if [[ -f /usr/local/bin/$1 ]]; then
usedGithubInstallMethod="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
fi
}
extraUpdateTool()
{
if [[ -f /usr/local/bin/$1 ]]; then
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
}
singleInstall()
{
cd "$1" || exit 1
echo -n "Installing $1: "
chmod a+x "$1"
cp "$1" $prefix/bin > /dev/null 2>&1 || { echo "Failure"; echo "Error copying file, try running install script as sudo"; exit 1; }
echo "Success"
cd .. || exit 1
}
copyManpage()
{
manPath="$prefix/share/man/man1"
if [ -f "$prefix/man/man1/bash-snippets.1" ]; then rm -f "$prefix/man/man1/bash-snippets.1"; fi
cp bash-snippets.1 $manPath 2>&1 || { echo "Failure"; echo "Error copying file, try running install script as sudo"; exit 1; }
}
response=$( echo "$@" | grep -Eo "\-\-prefix")
if [[ $response == "--prefix" ]]; then
prefix=$(echo -n "$@" | sed -e 's/--prefix=\(.*\) .*/\1/' | cut -d " " -f 1)
mkdir -p "$prefix"/bin "$prefix"/share/man/man1
if [[ $2 == "all" ]];then
for tool in "${tools[@]}"; do
singleInstall "$tool" || exit 1
done
else
for tool in "${@:2}"; do
singleInstall "$tool" || exit 1
done
fi
copyManpage || exit 1
elif [[ $# == 0 ]]; then
for tool in "${tools[@]}"; do
askInstall "$tool" || exit 1
done
copyManpage || exit 1
elif [[ $1 == "update" ]]; then
echo "Updating scripts..."
for tool in "${tools[@]}"; do
updateTool "$tool" || exit 1
done
if [[ $(uname -s) == "Linux" ]]; then
for tool in "${extraLinuxTools[@]}"; do
extraUpdateTool "$tool" Linux || exit 1
done
fi
if [[ $(uname) == "Darwin" ]];then
for tool in "${extraDarwinTools[@]}"; do
extraUpdateTool "$tool" Darwin || exit 1
done
fi
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."
exit 1
fi
elif [[ $1 == "all" ]]; then
for tool in "${tools[@]}"; do
singleInstall "$tool" || exit 1
done
copyManpage || exit 1
else
singleInstall "$1" || exit 1
copyManpage || exit 1
fi
echo -n "( •_•)"
sleep .75
echo -n -e "\r( •_•)>⌐■-■"
sleep .75
echo -n -e "\r "
echo -e "\r(⌐■_■)"
sleep .5
echo "Bash Snippets version $currentVersion"
echo "https://github.com/alexanderepstein/Bash-Snippets"