-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·151 lines (113 loc) · 3.67 KB
/
install
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
# Verify installed components (* = may not be needed):
# - bash5 duh
# - brew Installer
# - curl To curl stuff
# - jq Json parser
# - *jc For converting some common command output to json
# - jp For graphing
# - *imgcat For webcam view stuff
# - netcat For checking if specific ports are online
# - gdate A better alternative to date cmd
# - noti Notifications for job completions, errors, etc
# - yq For parsing yml config files
_error(){
printf "ERROR: %s\n" "$?" 1>&2
}
#
# STEP 1: Make sure brew is installed
#
printf "Checking for %-13s " "brew..."
type -fp brew
if [[ $? != 0 ]]; then
echo "Not found"
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
read -p "Install brew now? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
[[ $? -ne 0 ]] && _error "Failed to install brew" && exit 1
else
echo "Not installing brew - exiting"
exit 1
fi
fi
echo
brew_bin=$(type -fp brew)
check_brew_package(){
brew list | grep -Eq "^${1}$"
}
#
# STEP 2: Make sure were using bash5 - Can be installed via brew if not found
#
printf "Checking for %-13s " "bash (v5)..."
if [[ $BASH_VERSINFO < 5 ]]; then
echo "Old bash version ($BASH_VERSINFO) - Must use bash v5"
check_brew_package bash &&
_error "Looks like bash v5 is already installed via brew - Please execute this installer with that bash binary" &&
exit 1
echo "Installing bash via brew... "
sleep 1
brew install bash
echo "bash5 installed successfully - Please re-execute this installer with bash v5"
exit
else
echo "$BASH_VERSINFO ($BASH_VERSION)"
fi
echo
function check_or_install {
declare -a _packages=($@)
declare -a _notfound=()
for p in ${_packages[@]}; do
printf "Checking for %-13s " "${p}..."
type -fp $p
if [[ $? != 0 ]]; then
echo "Not found"
_notfound+=($p)
fi
done
if [[ ${#_notfound[@]} -gt 0 ]]; then
echo
echo "There are ${#_notfound[@]} packages to install: ${_notfound[@]}"
sleep 1
echo "Executing: brew install ${_notfound[@]}..."
sleep 1
brew install ${_notfound[@]}
[[ $? -ne 0 ]] &&
echo &&
_error "Brew returned non-zero exit status" &&
exit 1
echo
echo "Brew installed ${#_notfound[@]} package(s) successfully"
sleep 1
fi
}
#check_or_install curl
minimum_packages="curl jq jp yq gawk netcat socat"
extra_packages="noti httping"
install_minimum(){
echo "Verifying minimum packages: ${minimum_packages}"
check_or_install $minimum_packages
[[ $? != 0 ]] && _error "Error installing minimum packages" && exit 1
}
install_extra(){
echo "Verifying extra packages: ${extra_packages}"
check_or_install $extra_packages
[[ $? != 0 ]] && _error "Error installing extra packages" && exit 1
}
install_all(){
echo "Verifying all packages: ${minimum_packages} ${extra_packages}"
check_or_install $minimum_packages $extra_packages
[[ $? != 0 ]] && _error "Error installing all packages" && exit 1
}
#install_minimum && install_extra
install_all
echo
if ! test -L /usr/local/bin/moonraker; then
echo "Creating symlink /usr/local/bin/moonraker for moonraker script at $(realpath ./moonraker)"
sleep 1
sudo ln -vs $(realpath ./moonraker)
else
echo "Moonraker symlink found at /usr/local/bin/moonraker"
fi