-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
98 lines (95 loc) · 2.95 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
#!/bin/sh
run_and_add_perms() {
unzip "$1"
if [ -e "hajime" ]
then
echo "Assigning the CAP_PERFMON capability to Hajime..."
sudo setcap 'cap_perfmon+pe' hajime
chmod +x hajime
rm "$1"
./hajime
exit 0
fi
}
update_and_install() {
echo "Installing necessary packages..."
if [ "$USER" != "root" ]
then
echo "You may need to be the root user to install g++, git, and cmake."
fi
if [ "$OSTYPE" = "FreeBSD" ]
then
echo "FreeBSD detected"
pkg update
pkg install gcc10 git cmake
pkg upgrade
fi
if [ "$OSTYPE" = "OpenBSD" ]
then
echo "OpenBSD detected"
pkg_add git cmake
fi
if [ "$(uname -s)" = "Linux" ]
then
sudo apt update
sudo apt install -y g++10 cmake git
sudo yum install -y clang && sudo yum install -y git
sudo yum install -y cmake
fi
}
if [ "$(uname -s)" = "Darwin" ]
then
echo "macOS detected"
if [ "$(uname -m)" = "arm64" ]
then
echo "Downloading Hajime for macOS ARM directly"
curl -s -o hajime-macos-arm64.zip -L https://github.com/Slackadays/Hajime/releases/latest/download/hajime-macos-arm64.zip
run_and_add_perms hajime-macos-arm64.zip
fi
if [ "$(uname -m)" = "x86_64" ]
then
echo "Downloading Hajime for macOS x86_64 directly"
curl -s -o hajime-macos-amd64.zip -L https://github.com/Slackadays/Hajime/releases/latest/download/hajime-macos-amd64.zip
run_and_add_perms hajime-macos-amd64.zip
fi
echo "Can't find a supported platform; compiling Hajime now"
update_and_install
fi
if [ "$(uname -s)" = "Linux" ]
then
echo "Linux detected"
echo "Updating and installing the unzip package..."
sudo apt update
sudo apt install -y unzip
sudo yum install -y unzip
if [ "$(uname -m)" = "x86_64" ]
then
echo "Trying to download Hajime for Linux amd64 directly"
curl -s -o hajime-linux-amd64.zip -L https://github.com/Slackadays/Hajime/releases/latest/download/hajime-linux-amd64.zip
run_and_add_perms hajime-linux-amd64.zip
fi
if [ -n "$(uname -m | grep armv7l)" ] || [ -n "$(uname -m | grep aarch64)" ]
then
echo "Trying to download Hajime for Linux arm32hf directly"
curl -s -o hajime-linux-arm32hf.zip -L https://github.com/Slackadays/Hajime/releases/latest/download/hajime-linux-arm32hf.zip
run_and_add_perms hajime-linux-arm32hf.zip
fi
echo "Can't find a supported platform; compiling Hajime now"
update_and_install
fi
echo "Cloning repo..."
git clone https://github.com/slackadays/Hajime
echo "Compiling..."
echo "This may take from a few seconds to a few minutes depending on your system speed."
cd Hajime
cmake source
cmake --build . -j 9
echo "Cleaning up..."
chown -R "$USER" "../Hajime/.git" #change perms for certain misbehaving files that come with git
mv hajime "../" #move the binary to the original folder where the script was started
rm -rf ../Hajime #remove the cloned directory, ignore junk files from .git
cd ../
echo "Assigning the CAP_PERFMON capability to Hajime..."
sudo setcap 'cap_perfmon+pe' hajime
./hajime
exit 0