-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-ubuntu.sh
More file actions
executable file
·135 lines (107 loc) · 3.35 KB
/
install-ubuntu.sh
File metadata and controls
executable file
·135 lines (107 loc) · 3.35 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
129
130
131
132
133
134
135
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "K8sMissions Installation (Ubuntu)"
echo "================================="
echo
if ! command -v sudo >/dev/null 2>&1; then
echo "ERROR: sudo is required on Ubuntu to install missing packages."
exit 1
fi
if ! command -v apt-get >/dev/null 2>&1; then
echo "ERROR: This installer is for Ubuntu/Debian systems with apt-get."
exit 1
fi
APT_UPDATED=0
apt_install() {
if [ "$APT_UPDATED" -eq 0 ]; then
echo "Refreshing apt package index..."
sudo apt-get update
APT_UPDATED=1
fi
sudo apt-get install -y "$@"
}
ensure_cmd() {
local cmd="$1"
local package="$2"
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Installing missing package: $package"
apt_install "$package"
fi
}
echo "Checking system dependencies..."
ensure_cmd curl curl
ensure_cmd jq jq
ensure_cmd python3 python3
ensure_cmd kind kind
if ! command -v kubectl >/dev/null 2>&1; then
echo "ERROR: kubectl is not installed."
echo "Install it first, for example:"
echo " sudo snap install kubectl --classic"
echo "or follow:"
echo " https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/"
exit 1
fi
if ! python3 -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 9) else 1)'; then
echo "ERROR: Python 3.9+ is required."
python3 --version || true
exit 1
fi
echo "Python version: $(python3 --version 2>&1)"
if ! python3 -m venv --help >/dev/null 2>&1; then
echo "Installing Python venv support..."
apt_install python3-venv
fi
echo "System dependencies are ready."
echo
if [ -d "venv" ] && [ ! -x "venv/bin/python" ]; then
echo "Removing incompatible virtual environment copied from another machine..."
rm -rf venv
fi
if [ -L "venv/bin/python3" ] && readlink "venv/bin/python3" | grep -q "/opt/homebrew/"; then
echo "Removing macOS virtual environment so Ubuntu can rebuild it..."
rm -rf venv
fi
if [ ! -d "venv" ]; then
echo "Creating Python virtual environment..."
python3 -m venv venv
fi
echo "Installing Python dependencies..."
VENV_PYTHON="$SCRIPT_DIR/venv/bin/python"
if [ ! -x "$VENV_PYTHON" ]; then
echo "Installing Python venv support..."
apt_install python3-venv python3-pip python3-full
rm -rf venv
python3 -m venv venv
fi
if ! "$VENV_PYTHON" -m pip --version >/dev/null 2>&1; then
echo "Rebuilding virtual environment with pip support..."
apt_install python3-venv python3-pip python3-full
rm -rf venv
python3 -m venv venv
fi
"$VENV_PYTHON" -m pip install -q --upgrade pip
"$VENV_PYTHON" -m pip install -q -r requirements.txt
echo "Python packages installed."
echo
CLUSTER_NAME="k8smissions"
if kind get clusters 2>/dev/null | grep -q "^${CLUSTER_NAME}$"; then
echo "Cluster '${CLUSTER_NAME}' already exists."
else
echo "Creating Kubernetes cluster '${CLUSTER_NAME}'..."
kind create cluster --name "${CLUSTER_NAME}"
fi
kubectl config use-context "kind-${CLUSTER_NAME}" >/dev/null
echo "Setting up namespace '${CLUSTER_NAME}'..."
kubectl create namespace "${CLUSTER_NAME}" --dry-run=client -o yaml | kubectl apply -f -
echo "Applying RBAC safety guards..."
if [ -f "rbac/k8smissions-rbac.yaml" ]; then
kubectl apply -f rbac/k8smissions-rbac.yaml
echo "RBAC configured."
else
echo "WARNING: rbac/k8smissions-rbac.yaml not found; skipping."
fi
echo
echo "K8sMissions is ready."
echo "Run: ./play.sh"