-
Notifications
You must be signed in to change notification settings - Fork 8
/
install.sh
executable file
·117 lines (110 loc) · 3.8 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
#!/bin/bash
#
# Copyright 2018 Abraham Massry
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
#
curl_installed=$(curl --version 2>&1)
freeSpaceK=$(df -k $HOME | tail -n 1| awk '{print $4}')
echoerr() {
echo "$@" 1>&2;
}
bashInstall () {
#not sure that put alias in both bash_profile and bashrc is a good idea.
if [[ ! -e "$HOME/.bashrc" || ! $(grep "alias wsend=" $HOME/.bashrc) ]]; then
echo "alias wsend='$HOME/.wsend/wsend'" >> $HOME/.bashrc
echo "alias wsend='$HOME/.wsend/wsend'" >> $HOME/.bash_profile
fi
}
cshInstall () {
if [[ ! -e "$HOME/.cshrc" || ! $(grep "alias wsend=" $HOME/.cshrc) ]]
then
echo "alias wsend '$HOME/.wsend/wsend'" >> $HOME/.cshrc
fi
}
kshInstall () {
if [[ ! -e "$HOME/.kshrc" || ! $(grep "alias wsend=" $HOME/.kshrc) ]]; then
echo "alias wsend='$HOME/.wsend/wsend'" >> $HOME/.kshrc
fi
}
zshInstall () {
if [[ ! -e "$HOME/.zshrc" || ! $(grep "alias wsend=" $HOME/.zshrc) ]]; then
echo "alias -g wsend='$HOME/.wsend/wsend'" >> $HOME/.zshrc
fi
}
downloadLastVersion() {
curl -L -s -o $HOME/.wsend/wsend https://raw.github.com/abemassry/wsend/master/wsend
chmod +x $HOME/.wsend/wsend
#supporting files as well
curl -L -s -o $HOME/.wsend/README.md https://raw.github.com/abemassry/wsend/master/README.md
curl -L -s -o $HOME/.wsend/COPYING https://raw.github.com/abemassry/wsend/master/COPYING
curl -L -s -o $HOME/.wsend/version https://raw.github.com/abemassry/wsend/master/version
curl -L -s -o $HOME/.wsend/update.sh https://raw.github.com/abemassry/wsend/master/update.sh
}
if [[ ! $curl_installed ]]; then
echoerr -e "\e[01;31m"
echoerr "error: curl is required but it is not installed. Aborting";
echoerr "error: For ubuntu please run: sudo apt-get install curl";
echoerr -e "\e[00m"
exit 1;
fi
if [ -d "$HOME/.wsend" ]; then
wsend_dir="$HOME/.wsend"
#check version
installedVersion=$(cat $wsend_dir/version)
latestVersion=$(curl -L -s https://raw.github.com/abemassry/wsend/master/version)
if [ "$installedVersion" != "$latestVersion" ]; then
echoerr -e "\033[01;36m"
echoerr "info: "
echoerr "info: new version detected, auto updating"
echoerr "info: "
echoerr -e "\033[00m"
downloadLastVersion
fi
else
# if not, install
if [ "$freeSpaceK" -gt 100 ]; then
mkdir $HOME/.wsend
downloadLastVersion
else
echoerr "not enough free space to continue. Aborting";
exit 1;
fi
#add alias to shell
#execute alias command
if [ $SHELL == "/bin/bash" ]; then
bashInstall
echo "enter this to use the wsend command:"
echo "alias wsend='$HOME/.wsend/wsend'"
elif [ $SHELL == "/bin/csh" ]; then
cshInstall
echo "enter this to use the wsend command:"
echo "alias wsend '$HOME/.wsend/wsend'"
elif [ $SHELL == "/bin/tcsh" ]; then
cshInstall
echo "enter this to use the wsend command:"
echo "alias wsend '$HOME/.wsend/wsend'"
elif [ $SHELL == "/bin/ksh" ]; then
kshInstall
echo "enter this to use the wsend command:"
echo "alias wsend='$HOME/.wsend/wsend'"
elif [ $SHELL == "/bin/zsh" ]; then
zshInstall
echo "enter this to use the wsend command:"
echo "alias -g wsend='$HOME/.wsend/wsend'"
fi # install done
fi # check for installation done
echo ''
echo "install done"