|
2 | 2 |
|
3 | 3 | set -Eeou pipefail |
4 | 4 |
|
5 | | -echo "==========================================" |
6 | 5 | echo "Setting up IBM container runtime (rootless)" |
7 | | -echo "==========================================" |
8 | 6 |
|
9 | 7 | # Setup XDG_RUNTIME_DIR for rootless podman |
10 | | -# This directory must exist and be writable for rootless containers |
11 | | -setup_runtime_dir() { |
12 | | - local uid |
13 | | - uid=$(id -u) |
14 | | - local runtime_dir="/run/user/${uid}" |
15 | | - |
16 | | - if [[ ! -d "${runtime_dir}" ]]; then |
17 | | - echo "Creating XDG_RUNTIME_DIR: ${runtime_dir}" |
| 8 | +uid=$(id -u) |
| 9 | +runtime_dir="/run/user/${uid}" |
| 10 | +if [[ ! -d "${runtime_dir}" ]]; then |
18 | 11 | sudo mkdir -p "${runtime_dir}" |
19 | 12 | sudo chown "$(whoami):$(whoami)" "${runtime_dir}" |
20 | 13 | sudo chmod 700 "${runtime_dir}" |
21 | | - elif [[ ! -w "${runtime_dir}" ]]; then |
22 | | - echo "Fixing permissions on XDG_RUNTIME_DIR: ${runtime_dir}" |
23 | | - sudo chown "$(whoami):$(whoami)" "${runtime_dir}" |
24 | | - sudo chmod 700 "${runtime_dir}" |
25 | | - fi |
26 | | - |
27 | | - export XDG_RUNTIME_DIR="${runtime_dir}" |
28 | | - echo "XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}" |
29 | | - |
30 | | - # Create containers subdirectory |
31 | | - mkdir -p "${runtime_dir}/containers" 2>/dev/null || true |
32 | | -} |
33 | | - |
34 | | -setup_runtime_dir |
35 | | - |
36 | | -echo "Cleaning DNF cache..." |
37 | | -sudo dnf clean all && sudo rm -rf /var/cache/dnf || true |
38 | | - |
39 | | -echo "Installing/upgrading crun..." |
40 | | -sudo dnf upgrade -y crun --disableplugin=subscription-manager || \ |
41 | | -sudo dnf install -y crun --disableplugin=subscription-manager || \ |
42 | | -sudo yum upgrade -y crun --disableplugin=subscription-manager || \ |
43 | | -sudo yum install -y crun --disableplugin=subscription-manager |
44 | | - |
45 | | -# Find crun path - it might be in different locations |
46 | | -crun_path="" |
47 | | -for path in /usr/bin/crun /usr/local/bin/crun /bin/crun; do |
48 | | - if [[ -x "${path}" ]]; then |
49 | | - crun_path="${path}" |
50 | | - break |
51 | | - fi |
52 | | -done |
53 | | - |
54 | | -if [[ -z "${crun_path}" ]]; then |
55 | | - # Try to find it |
56 | | - crun_path=$(command -v crun 2>/dev/null || true) |
57 | | -fi |
58 | | - |
59 | | -if [[ -z "${crun_path}" || ! -x "${crun_path}" ]]; then |
60 | | - echo "❌ crun not found after installation" |
61 | | - echo "Searching for crun..." |
62 | | - find /usr -name "crun" -type f 2>/dev/null || true |
63 | | - exit 1 |
64 | 14 | fi |
| 15 | +export XDG_RUNTIME_DIR="${runtime_dir}" |
65 | 16 |
|
66 | | -echo "Found crun at: ${crun_path}" |
67 | | -current_version=$("${crun_path}" --version | head -n1) |
68 | | -echo "✅ Using crun: ${current_version}" |
69 | | - |
70 | | -# Clean up any existing conflicting configurations (user-level only for rootless) |
71 | | -echo "Cleaning up existing container configurations..." |
72 | | -rm -f ~/.config/containers/containers.conf 2>/dev/null || true |
73 | | - |
74 | | -# Configure for rootless podman with explicit crun path |
75 | | -config="[containers] |
76 | | -cgroup_manager = \"cgroupfs\" |
77 | | -
|
78 | | -[engine] |
79 | | -runtime = \"${crun_path}\"" |
| 17 | +# Install crun |
| 18 | +echo "Installing crun..." |
| 19 | +sudo dnf clean all || true |
| 20 | +sudo dnf install -y crun --disableplugin=subscription-manager || \ |
| 21 | +sudo yum install -y crun --disableplugin=subscription-manager || true |
80 | 22 |
|
| 23 | +# Configure rootless podman |
81 | 24 | mkdir -p ~/.config/containers |
82 | | -echo "${config}" > ~/.config/containers/containers.conf |
83 | 25 |
|
84 | | -# Also set storage driver explicitly for rootless |
85 | | -storage_config="[storage] |
86 | | -driver = \"overlay\" |
87 | | -runroot = \"${XDG_RUNTIME_DIR}/containers\" |
88 | | -graphroot = \"${HOME}/.local/share/containers/storage\"" |
| 26 | +cat > ~/.config/containers/containers.conf << 'EOF' |
| 27 | +[containers] |
| 28 | +cgroup_manager = "cgroupfs" |
| 29 | +EOF |
89 | 30 |
|
90 | | -echo "${storage_config}" > ~/.config/containers/storage.conf |
| 31 | +cat > ~/.config/containers/storage.conf << EOF |
| 32 | +[storage] |
| 33 | +driver = "overlay" |
| 34 | +runroot = "${XDG_RUNTIME_DIR}/containers" |
| 35 | +graphroot = "${HOME}/.local/share/containers/storage" |
| 36 | +EOF |
91 | 37 |
|
92 | | -echo "✅ Configured crun for rootless podman" |
93 | | -echo "Config written to ~/.config/containers/containers.conf" |
94 | | -echo "Storage config written to ~/.config/containers/storage.conf" |
| 38 | +echo "Done" |
0 commit comments