-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·57 lines (47 loc) · 1.38 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
#!/bin/bash
has_command() {
command -v "$1" >/dev/null 2>&1
}
get_latest_release() {
wget -q -O- "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
install_osx(){
if has_command "brew" ; then
brew install rettier/tap/c
else
echo "Please install Homebrew first"
echo "https://brew.sh/"
exit 1
fi
}
install_debian(){
wget "https://github.com/rettier/c/releases/download/${version}/c_${version:1}.deb" -q -O c.deb
$run_sudo dpkg -i c.deb >/dev/null
}
install_linux_common(){
wget "https://github.com/rettier/c/releases/download/${version}/c_${version:1}.tar.gz" -q -O c.tar.gz
tar -xf c.tar.gz
mv c_${version:1}/* /usr/bin/
}
install_linux(){
tempdir="$(mktemp -d)"
pushd "${tempdir}" >/dev/null
version=$(get_latest_release "rettier/c")
run_sudo=''
if (( $EUID != 0 )); then
run_sudo='sudo'
fi
if has_command "dpkg" ; then
install_debian "${version}"
else
install_linux_common "${version}"
fi
rm -r "${tempdir}"
}
case "$(uname -s)" in
Linux*) install_linux;;
Darwin*) install_osx;;
*) echo "Unknown OS, exiting..."; exit 1;;
esac