-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·128 lines (101 loc) · 3.45 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·128 lines (101 loc) · 3.45 KB
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
#!/bin/bash
# -e Exit if single command, fails
# -u Exit when expanding unset variables
# -o pipefail Exit if one of the command in a pipeline fails
set -e -u -o pipefail
# Interactive installation (default 1)
# Set to 0 to disable interaction.
interactive=${VMNET_INTERACTIVE:-1}
# Configure sudo to allow running vmnet-helper without a password.
# - Not set: auto mode (enabled on macOS 15 and earlier, disabled on macOS 26+)
# - Set to 1: enable (in interactive mode, asks for confirmation)
# - Set to 0: disable
configure_sudo=${VMNET_CONFIGURE_SUDO:-}
# GitHub user to install from (default nirs)
# Modify to install from your fork.
user=${VMNET_USER:-nirs}
# GitHub repo to install from (default vmnet-helper)
# Modify to install from your fork if you renamed it.
repo=${VMNET_REPO:-vmnet-helper}
# Version to install (default latest)
# Versions before v0.7.0 not supported.
version=${VMNET_VERSION:-latest}
# Temp directory for downloaded release, cleaned up on exit.
download_tmpdir=""
main() {
local tarball="${1:-}"
validate_options
if [ "$interactive" = "1" ]; then
authorize_user
if [ "$configure_sudo" = "1" ]; then
confirm_sudo_configuration
fi
fi
echo
if [ -z "$tarball" ]; then
create_download_tmpdir
tarball="$download_tmpdir/vmnet-helper.tar.gz"
download_release "$tarball"
fi
install_files "$tarball"
if [ "$configure_sudo" = "1" ]; then
install_sudoers
fi
echo
echo "✅ vmnet-helper was installed successfully!"
}
validate_options() {
if [ -z "$configure_sudo" ]; then
# On macOS 26+, vmnet-helper can run without root privileges.
local major_version
major_version=$(sw_vers -productVersion | cut -d. -f1)
if [ "$major_version" -ge 26 ]; then
configure_sudo=0
else
configure_sudo=1
fi
fi
}
create_download_tmpdir() {
download_tmpdir=$(mktemp -d -t vmnet-helper)
trap 'rm -rf "$download_tmpdir"' EXIT
}
download_release() {
local tarball="$1"
local url
if [ "$version" = "latest" ]; then
url="https://github.com/$user/$repo/releases/latest/download/vmnet-helper.tar.gz"
else
url="https://github.com/$user/$repo/releases/download/$version/vmnet-helper.tar.gz"
fi
echo "Downloading $url"
curl --fail --silent --show-error --location --output "$tarball" "$url"
}
install_files() {
local tarball="$1"
echo "Installing vmnet-helper at /opt/vmnet-helper"
# IMPORTANT: The vmnet-helper executable and the directory where it is installed
# must be owned by root and may not be modifiable by unprivileged users.
sudo tar --extract --verbose --gunzip --file "$tarball" --directory / opt/vmnet-helper 2>&1
}
install_sudoers() {
echo "Installing /etc/sudoers.d/vmnet-helper"
sudo install -m 0640 /opt/vmnet-helper/share/doc/vmnet-helper/sudoers.d/vmnet-helper /etc/sudoers.d/
}
authorize_user() {
echo "Installation requires your password to install vmnet-helper as root"
sudo true
}
confirm_sudo_configuration() {
read -p "Configure sudo to run vmnet-helper without a password? (Y/n): " reply </dev/tty
case "$reply" in
Y|y|"")
;;
*)
configure_sudo=0
echo "Please check /opt/vmnet-helper/share/doc/vmnet-helper/sudoers.d/README.md"
echo "if you want to configure sudo later."
;;
esac
}
main "$@"