Files
skillshare/.devcontainer/ensure-skillshare-linux-binary.sh
T
Willie c5d32111f7 dev: overhaul devcontainer experience with persistence and enhanced tooling
Improve the sandbox development environment to support "new user" simulation
while maintaining a high-quality developer experience.

Changes:
- Persistence: Redirect HOME to /home/developer and add a persistent volume
  to preserve shell history, gh auth state, and isolated environments.
- Tooling: Pre-install GitHub CLI (gh), air (hot-reload), and delve (dlv)
  in the sandbox Dockerfile.
- Isolated Envs:
    - Update ssenv to store environments in persistent $HOME/.ss-envs.
    - Add --init flag to ssnew/ssenv to auto-run 'ss init -g' in new envs.
    - Add visual PS1 indicator when an isolated environment is active.
- DX Refinements:
    - Add a centralized 'help' command (aliased to override bash built-in).
    - Fix ANSI color rendering in help script.
    - Robust PROJECT_ROOT redirection in skillshare wrapper script.
    - Support /home/developer in setup.sh environment checks.
2026-02-25 07:02:54 +08:00

69 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Ensure devcontainer commands point to a Linux-built skillshare binary.
set -euo pipefail
if [ ! -d /workspace ] || [ ! -f /workspace/go.mod ]; then
echo "ensure-skillshare-linux-binary: /workspace is not available" >&2
exit 1
fi
BIN_DIR=/workspace/bin
BIN=$BIN_DIR/skillshare
WRAPPER_DIR=/workspace/.devcontainer/bin
NEED_REBUILD=0
REASON=""
GO_BIN=/usr/local/go/bin/go
mkdir -p "$BIN_DIR"
if [ ! -x "$BIN" ]; then
NEED_REBUILD=1
REASON="binary missing"
elif command -v file >/dev/null 2>&1; then
FILE_TYPE="$(file -b "$BIN" || true)"
if [[ "$FILE_TYPE" != *ELF* ]]; then
NEED_REBUILD=1
REASON="non-Linux binary detected: $FILE_TYPE"
fi
fi
if [ "$NEED_REBUILD" -eq 0 ] && ! "$BIN" version >/dev/null 2>&1; then
NEED_REBUILD=1
REASON="binary exists but cannot execute in container"
fi
if [ ! -x "$GO_BIN" ]; then
GO_BIN="$(command -v go || true)"
fi
if [ -z "${GO_BIN:-}" ]; then
echo "ensure-skillshare-linux-binary: go toolchain not found" >&2
exit 1
fi
if [ "$NEED_REBUILD" -eq 1 ]; then
echo "▸ Rebuilding skillshare for Linux ($REASON) ..."
(
cd /workspace
"$GO_BIN" build -o "$BIN" ./cmd/skillshare
)
fi
# Keep command resolution deterministic in interactive shells.
ln -sf "$BIN" /workspace/bin/ss
# Prefer wrapper entrypoints for /usr/local/bin so commands stay Linux-safe
# even when /workspace/bin/skillshare is overwritten by a host-built binary.
if [ -x "$WRAPPER_DIR/skillshare" ] && [ -x "$WRAPPER_DIR/ss" ]; then
ln -sf "$WRAPPER_DIR/skillshare" /usr/local/bin/skillshare
ln -sf "$WRAPPER_DIR/ss" /usr/local/bin/ss
else
ln -sf "$BIN" /usr/local/bin/skillshare
ln -sf "$BIN" /usr/local/bin/ss
fi
for cmd in ssenv sshelp ssnew ssuse ssback ssls help; do
if [ -x "$WRAPPER_DIR/$cmd" ]; then
ln -sf "$WRAPPER_DIR/$cmd" "/usr/local/bin/$cmd"
fi
done