-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·101 lines (78 loc) · 2.41 KB
/
install.sh
File metadata and controls
executable file
·101 lines (78 loc) · 2.41 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
#!/usr/bin/env bash
set -euo pipefail
VAGRANT_VERSION="${VAGRANT_VERSION:-2.4.9}"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
TMP_DIR="${TMP_DIR:-${TMPDIR:-/tmp}/vagrant-install}"
ZIP_URL="https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_linux_amd64.zip"
TARGET_BIN="${INSTALL_DIR}/vagrant"
require_cmd() {
local cmd="$1"
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: ${cmd} is required." >&2
exit 1
fi
}
install_vagrant() {
echo "Installing Vagrant ${VAGRANT_VERSION}"
mkdir -p "${INSTALL_DIR}" "${TMP_DIR}"
require_cmd curl
require_cmd python3
local zip_path="${TMP_DIR}/vagrant_${VAGRANT_VERSION}.zip"
echo "Downloading ${ZIP_URL}"
curl -fL "${ZIP_URL}" -o "${zip_path}"
echo "Extracting Vagrant binary"
python3 - "${zip_path}" "${TARGET_BIN}" <<'PY'
import os
import stat
import sys
import zipfile
zip_path, target_bin = sys.argv[1], sys.argv[2]
with zipfile.ZipFile(zip_path) as zf:
data = zf.read("vagrant")
with open(target_bin, "wb") as f:
f.write(data)
current_mode = os.stat(target_bin).st_mode
os.chmod(target_bin, current_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
PY
if [[ ":$PATH:" != *":${INSTALL_DIR}:"* ]]; then
echo "Warning: ${INSTALL_DIR} is not currently on PATH." >&2
echo "Add this line to your shell profile if needed:" >&2
echo " export PATH=\"${INSTALL_DIR}:\$PATH\"" >&2
fi
echo "Installed to ${TARGET_BIN}"
"${TARGET_BIN}" --version
}
install_system_packages() {
if ! command -v apt >/dev/null 2>&1; then
echo "Skipping apt-based package install: apt not found." >&2
return 0
fi
echo "Installing libvirt dependencies with apt"
sudo apt update
sudo apt install -y build-essential ruby-dev libvirt-dev pkg-config
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients virtinst
sudo usermod -aG libvirt "$USER"
}
install_libvirt_plugin() {
require_cmd vagrant
require_cmd make
if vagrant plugin list | grep -q '^vagrant-libvirt '; then
echo "vagrant-libvirt plugin is already installed."
else
echo "Installing vagrant-libvirt plugin"
vagrant plugin install vagrant-libvirt
fi
}
print_next_steps() {
cat <<'EOF'
Install complete.
You may need to log out and back in for the libvirt group change to apply.
Next steps:
cd p1
vagrant up --provider=libvirt
EOF
}
install_vagrant
install_system_packages
install_libvirt_plugin
print_next_steps