-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
89 lines (68 loc) · 1.97 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
#/bin/bash
# This script will install the latest version of the `brewc` into /usr/local/bin
# Check if the user has curl, jq, cut installed
green='\033[0;32m'
red='\033[0;31m'
end='\033[0m'
echo -e "${green}Checking if curl, jq, cut are installed...${end}"
if ! command -v curl &> /dev/null
then
echo "curl could not be found"
exit
fi
if ! command -v jq &> /dev/null
then
echo "jq could not be found"
exit
fi
if ! command -v cut &> /dev/null
then
echo "cut could not be found"
exit
fi
# lowercase uname output
arch=$(uname -m | tr '[:upper:]' '[:lower:]')
goos=$(uname -s | tr '[:upper:]' '[:lower:]')
if [ "$arch" = "x86_64" ]; then
arch="amd64"
fi
if [ "$arch" = "aarch64" ]; then
arch="arm64"
fi
latest_tag=$(curl -sL https://api.github.com/repos/hamza72x/brewc/tags | jq -r '.[0].name' | cut -d 'v' -f 2)
url=https://github.com/hamza72x/brewc/releases/download/v$latest_tag/brewc_$latest_tag\_$goos\_$arch.tar.gz
echo -e "${green}Detected OS: $goos${end}"
echo -e "${green}Detected Arch: $arch${end}"
echo ""
echo -e "${green}Latest version: $latest_tag${end}"
echo -e "${green}Download URL: $url${end}"
echo -e "${green}Installing brewc into /usr/local/bin${end}"
echo ""
# now ask if everything looks good and want to continue
read -p "Looks good? Continue? [y/N] " -n 1 -r
# quit if the user doesn't want to continue
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo
echo "Aborting..."
exit 1
fi
# ask sudo user for extracting to /usr/local/bin
echo ""
echo -e "${red}need sudo permission to extract to /usr/local/bin${end}"
sudo echo ""
# download the latest version
curl -L $url | sudo tar -xz -C /usr/local/bin
sudo chmod +x /usr/local/bin/brewc
# print usage
echo ""
echo -e "${green}Verifying installation...${end}"
echo -e "Running: ${green}brewc --help${end}"
echo ""
if command -v brewc &> /dev/null
then
brewc --help
else
echo "brewc could not be found, make sure /usr/local/bin is in your PATH, or try /usr/local/bin/brewc --help"
exit
fi