-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
Β·164 lines (135 loc) Β· 5.53 KB
/
setup.sh
File metadata and controls
executable file
Β·164 lines (135 loc) Β· 5.53 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
set -e
# --- Configuration ---
CONTAINER_NAME="dev"
IMAGE="fedora:latest"
HOME_DIR="$HOME/Documents/containers/$CONTAINER_NAME"
USER_ID=$(id -u)
# The "Source of Truth" for your SSH Agent on the Host
SSH_SOCK_PATH="/run/user/$USER_ID/gcr/ssh"
NVIM_SOCKET="/tmp/nvimsocket"
echo "=========================================="
echo "π Starting DevBox Rebuild for $USER"
echo "=========================================="
# 1. Host Pre-check
if ! ssh-add -l > /dev/null 2>&1; then
echo "β ERROR: No SSH identities found. Run 'ssh-add ~/.ssh/personal' on host."
exit 1
fi
# 2. Cleanup
distrobox rm $CONTAINER_NAME --force 2>/dev/null || true
# 3. Check for Podman socket
PODMAN_SOCK="/run/user/$USER_ID/podman/podman.sock"
VOLUME_FLAGS=""
echo "==> Checking for Podman socket..."
if [ -S "$PODMAN_SOCK" ]; then
VOLUME_FLAGS="--volume $PODMAN_SOCK:/run/user/1000/podman/podman.sock"
echo " β Podman socket found - will be forwarded to container"
else
echo " β Podman socket not found at $PODMAN_SOCK"
echo " Podman functionality will not be available in container"
echo " To enable: systemctl --user enable --now podman.socket"
fi
# 4. Create Container
# SSH agent forwarding is automatic via SSH_AUTH_SOCK - no key files needed
distrobox create --name $CONTAINER_NAME \
--image $IMAGE \
--home "$HOME_DIR" \
$VOLUME_FLAGS \
--yes
# 3.5. Copy setup scripts to container home
echo "==> Copying setup scripts to container home..."
cp "$PWD/setup-env.sh" "$HOME_DIR/"
cp "$PWD/setup-user-env.sh" "$HOME_DIR/"
cp "$PWD/tmux.conf" "$HOME_DIR/"
cp "$PWD/status.sh" "$HOME_DIR/"
# 4. Provisioning - Phase 1 (Root)
distrobox enter $CONTAINER_NAME -- sudo "$HOME_DIR/setup-env.sh"
# 5. Provisioning - Phase 2 (User)
# Distrobox automatically forwards SSH_AUTH_SOCK from host
echo "==> Running Phase 2: User Setup ($USER)..."
distrobox enter $CONTAINER_NAME -- "$HOME_DIR/setup-user-env.sh"
# 7. Neovim Service Configuration
mkdir -p ~/.config/systemd/user/
cat > ~/.config/systemd/user/nvim-server.service << EOF
[Unit]
Description=Neovim Headless Server (Distrobox: $CONTAINER_NAME)
After=network.target
[Service]
Type=simple
Environment=SSH_AUTH_SOCK=$SSH_SOCK_PATH
ExecStartPre=/usr/bin/rm -f $NVIM_SOCKET
ExecStart=/usr/bin/distrobox enter $CONTAINER_NAME -- /usr/bin/nvim --headless --listen $NVIM_SOCKET
Restart=always
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable nvim-server.service
systemctl --user restart nvim-server.service
# 8. Create GNOME Keyboard Shortcuts
echo "==> Creating GNOME keyboard shortcuts..."
# Detect binary paths (use absolute paths for GNOME shortcuts)
DISTROBOX_BIN=$(command -v distrobox || echo "/usr/bin/distrobox")
PTYXIS_BIN=$(command -v ptyxis || echo "/usr/bin/ptyxis")
NEOVIDE_BIN=$(command -v neovide || echo "/usr/bin/neovide")
# Define commands
CMD_TERM="$PTYXIS_BIN --new-window -- $DISTROBOX_BIN enter $CONTAINER_NAME -- /bin/zsh -l -c 'cd && tmux -u'"
CMD_NEOVIDE="$NEOVIDE_BIN --server $NVIM_SOCKET"
# Function to add a GNOME shortcut
add_gnome_shortcut() {
local name="$1"
local command="$2"
local binding="$3"
local base_path="org.gnome.settings-daemon.plugins.media-keys"
local keybinding_list_path="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings"
# Get current list
local current_list=$(gsettings get $base_path custom-keybindings)
# Check if shortcut already exists
local existing_paths=$(echo "$current_list" | grep -o "'[^']*'" | tr -d "'")
for path in $existing_paths; do
local existing_name=$(gsettings get "$base_path.custom-keybinding:$path" name 2>/dev/null | tr -d "'")
if [[ "$existing_name" == "$name" ]]; then
echo " Shortcut '$name' already exists. Skipping."
return 0
fi
done
# Find next available index
local last_index=$(echo "$current_list" | grep -o 'custom[0-9]*' | sed 's/custom//' | sort -n | tail -1)
local new_index=0
local new_list=""
if [[ -z "$last_index" ]]; then
new_index=0
new_list="['$keybinding_list_path/custom$new_index/']"
else
new_index=$((last_index + 1))
if [[ "$current_list" == "@as []" ]]; then
new_list="['$keybinding_list_path/custom$new_index/']"
else
new_list=${current_list/]/", '$keybinding_list_path/custom$new_index/']"}
fi
fi
local new_path="$keybinding_list_path/custom$new_index/"
# Apply settings
gsettings set $base_path custom-keybindings "$new_list"
gsettings set "$base_path.custom-keybinding:$new_path" name "$name"
gsettings set "$base_path.custom-keybinding:$new_path" command "$command"
gsettings set "$base_path.custom-keybinding:$new_path" binding "$binding"
echo " Created: '$name' β $binding"
}
# Create shortcuts
add_gnome_shortcut "DevBox Terminal" "$CMD_TERM" "<Super>r"
add_gnome_shortcut "DevBox Neovide" "$CMD_NEOVIDE" "<Super>t"
echo ""
echo "β
DevBox Provisioned Successfully!"
echo "ββββββββββββββββββββββββββββββββββββββββ"
echo "π¦ Container: $CONTAINER_NAME"
echo "π§ Neovim Service: Active (systemd)"
echo "β¨οΈ Keyboard Shortcuts:"
echo " β’ Super+T β Launch Neovide GUI"
echo " β’ Super+R β Open terminal in container"
echo "ββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo "Manual commands:"
echo " distrobox enter $CONTAINER_NAME"
echo " neovide --server $NVIM_SOCKET"