forked from natterstefan/speedtest-cron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.sh
executable file
·98 lines (83 loc) · 2.02 KB
/
installer.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/bash
# Get OS
OS=`echo $(uname)`
# Install paths
SM_OPT="/usr/local/opt/speedmob"
SM_BIN="/usr/local/bin/speedmob"
# Launchd
ID="speedmob"
IDENTIFIER="com.kyletaylored.speedmob"
LAUNCH_AGENT_PLIST="$HOME/Library/LaunchAgents/$IDENTIFIER.plist"
# Detect if speedmob exists.
if [ -e "$SM_BIN" ] || [ -e "$SM_OPT" ] || [[ $(which speedmob) != "" ]]; then
echo "Speedmob detected, removing and reinstalling..."
if [ -e "$SM_BIN" ]; then
unlink $SM_BIN
fi
if [ -e "$SM_OPT" ]; then
rm -rf $SM_OPT
fi
fi
# Remove Launchd on Mac
if [[ $OS == "Darwin" ]]; then
STATUS=`/bin/launchctl list | /usr/bin/grep $ID | /usr/bin/awk '{print $3}'`
/bin/launchctl unload $LAUNCH_AGENT_PLIST
rm -f $LAUNCH_AGENT_PLIST
fi
# Check if function exists.
function sm_fn_exists() {
if [[ $(type -t $1) != "" ]]; then
echo 1
else
echo 0
fi
}
function sm_brew_install() {
upgrade=$(sm_fn_exists $1)
if [[ $upgrade == 0 ]]; then
brew install $1
else
brew upgrade $1
fi
}
function sm_install_nix() {
echo "Installing speedmob..."
# Create opt path if doesn't exist already.
mkdir -p /usr/local/opt
git clone -q https://github.com/kyletaylored/speedmob /usr/local/opt/speedmob
ln -s /usr/local/opt/speedmob/speedmob /usr/local/bin/speedmob
# Install speedmob and crontab
cd /usr/local/opt/speedmob
chmod +x utils/install_crontab utils/install_raspian
bash utils/install_crontab
if [[ $OS == "Linux" ]]; then
bash utils/install_raspian
fi
}
# Install speedmob
case $OS in
Darwin)
echo "Mac OS detected..."
# Check for Homebrew
if [[ $(type -t brew) = "" ]]; then
echo "Homebrew not available, and is required for installation. Please install Homebrew by visiting https://brew.sh"
exit 1
fi
# Homebrew
sm_brew_install speedtest-cli
sm_brew_install jq
sm_brew_install bc
# Install speedmob
sm_install_nix
;;
Linux)
echo "Linux detected..."
sudo apt-get update
sudo apt-get install jq bc git -y
# Install speedmob
sm_install_nix
;;
*) echo "System not supported."
exit 1
;;
esac