-
Notifications
You must be signed in to change notification settings - Fork 27
/
install.sh
executable file
·69 lines (53 loc) · 1.49 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
#!/bin/bash
# package information.
url="https://github.com/fbzhong/git-gerrit/tarball/v0.3.0"
md5="3289ad86d22c3422701361a639d67573"
src_bin=bin
src_completion=completion
dst=/tmp/git-gerrit.latest.tar.gz
dst_bin=/usr/local/bin/
dst_completion=/etc/bash_completion.d/
# common functions.
die() {
echo "${@}"
exit 1
}
#Let mac user use homebrew to install.
name=$(uname)
if [ "Darwin" = "$name" ] ; then
die "Use homebrew to install: brew install https://raw.github.com/fbzhong/homebrew-library/master/Library/git-gerrit.rb"
fi
# download package.
curl -L $url > $dst
# verify download package.
dst_md5=$(md5sum $dst | awk '{print $1}')
if [ "$md5" != "$dst_md5" ] ; then
die "The file is corrupted, please check your network and try again."
fi
# install.
cd /tmp
extract_dir=$(tar -tzf $dst 2>/dev/null | head -1)
tar -xzf $dst
pushd $extract_dir 1>/dev/null
# copy bin.
echo "installing git-gerrit to /usr/local/bin..."
if [ -w "$dst_bin" ]; then
cp $src_bin/* "$dst_bin"
else
echo "request sudo authorization to install git-gerrit to /usr/local/bin:"
sudo cp $src_bin/* "$dst_bin"
fi
if [ ! -d "$dst_completion" ] ; then
mkdir -p "$dst_completion"
fi
# copy bash-completion.
if [ -w "$dst_completion" ]; then
cp $src_completion/* "$dst_completion"
else
echo "request sudo authorization to install git-gerrit to /usr/local/bin:"
sudo cp $src_completion/* "$dst_completion"
fi
popd 1>/dev/null
rm -rf "$extract_dir"
rm -rf "$dst"
echo "git-gerrit install success."