-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·53 lines (45 loc) · 1.5 KB
/
init.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.5 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
#!/bin/bash
# Configuration
IMAGE_NAME="zmk-toolchain:0.17.0"
VOL_CCACHE="zmk-ccache-data"
VOL_MODULES="zmk-modules-cache"
VOL_ZEPHYR="zmk-zephyr-data"
# --- 1. Auto-Build Logic ---
if ! podman image exists "$IMAGE_NAME"; then
echo "📦 Image $IMAGE_NAME not found. Building the image now..."
podman build -t "$IMAGE_NAME" .
fi
# --- 2. SSH Agent Self-Heal ---
if [ -z "$SSH_AUTH_SOCK" ]; then
echo "🔑 SSH_AUTH_SOCK not found. Starting ssh-agent..."
eval "$(ssh-agent -s)"
[ -f "$HOME/.ssh/id_ed25519" ] && ssh-add "$HOME/.ssh/id_ed25519"
fi
# --- 3. Persistent Volumes ---
for vol in $VOL_CCACHE $VOL_MODULES $VOL_ZEPHYR; do
podman volume inspect $vol >/dev/null 2>&1 || podman volume create $vol
done
# --- 4. Mapping Logic ---
SSH_MOUNT=""
[ -n "$SSH_AUTH_SOCK" ] && SSH_MOUNT="-v $SSH_AUTH_SOCK:/run/ssh-agent:Z -e SSH_AUTH_SOCK=/run/ssh-agent"
GIT_MOUNT=""
HOST_GIT_CONFIG="$HOME/.config/git/config"
if [ -f "$HOST_GIT_CONFIG" ]; then
GIT_MOUNT="-v $HOST_GIT_CONFIG:/root/.gitconfig:Z"
elif [ -f "$HOME/.gitconfig" ]; then
GIT_MOUNT="-v $HOME/.gitconfig:/root/.gitconfig:Z"
fi
echo "🚀 Starting ZMK Interactive Session..."
# --- 5. Run Container ---
podman run --rm -it \
--name zmk-dev-session \
--workdir /workdir \
-v "$(pwd):/workdir:Z" \
-v "$VOL_CCACHE:/root/.cache/ccache:Z" \
-v "$VOL_MODULES:/workdir/modules:Z" \
-v "$VOL_ZEPHYR:/root/.zephyr:Z" \
$GIT_MOUNT \
$SSH_MOUNT \
-e CCACHE_DIR=/root/.cache/ccache \
"$IMAGE_NAME" \
/bin/bash