NFS-aware .bashrc.local and VS Code dirs for work servers

- Remove zet* from _is_work_host (local git server, not a work host)
- setup_enterprise_ai_bash.sh: detect NFS home on work servers, relocate
  .bashrc.local to /opt/kenjim/ with symlink, handle re-runs safely
- setup_enterprise_ai_bash.sh: symlink ~/.vscode-server and
  ~/.vscode-remote-containers to /opt/kenjim/ on NFS hosts
- dotfiles_manager.sh: deploy-to detects NFS on remote, deploys
  .bashrc.local to /opt/kenjim/ with symlink, backs up symlink targets
- hosts/etqc-kenjim-11.bashrc.local: add NFS note to header
This commit is contained in:
Kenji Morishige
2026-02-24 09:57:29 -06:00
parent 074ab05908
commit 67926c37bd
5 changed files with 101 additions and 4 deletions

View File

@@ -14,7 +14,7 @@ _is_work_host() {
[[ "${MACHINE_PROFILE:-}" == "work" ]] && return 0
# Fallback hostname pattern for work servers where .bashrc.local may not exist
case "$(hostname -s)" in
kenjim-mbp*|etqc-*|etbg-*|engtech-dev-*|zet*) return 0 ;;
kenjim-mbp*|etqc-*|etbg-*|engtech-dev-*) return 0 ;;
*) return 1 ;;
esac
}

View File

@@ -84,9 +84,12 @@ Host kold
HostName etqc-kenjim-01.juniper.net
# TaaS dev machine
Host ktaas
Host qtaas
HostName kenjim-taas.qengk8.juniper.net
Host btaas
HostName kenjim-taas.bengk8.juniper.net
# Temp machine — Bangalore K8
Host ktb
HostName kenjim-temp.bengk8.juniper.net

View File

@@ -1,6 +1,8 @@
### MACHINE_LOCAL — managed centrally in dotfiles/hosts/ on kenjim-mbp
### Deployed via: dotfiles deploy-to kenjim@etqc-kenjim-11
### DO NOT edit directly on the server — edit in ~/dotfiles/hosts/ and re-deploy
### NFS NOTE: On NFS-home servers, this file lives at /opt/kenjim/.bashrc.local
### with a symlink from ~/.bashrc.local → /opt/kenjim/.bashrc.local
# Host : etqc-kenjim-11
# Profile : work (server)
# =============================================================================

View File

@@ -1065,14 +1065,43 @@ cmd_deploy_to() {
# Back up existing remote .bashrc.local if not already captured above
if $no_backup; then
: # skip
elif ssh "$target" '[ -L ~/.bashrc.local ]' 2>/dev/null; then
# It's a symlink (NFS setup) — back up the target file
local real_path
real_path=$(ssh "$target" 'readlink -f ~/.bashrc.local' 2>/dev/null || true)
if [[ -n "$real_path" ]]; then
local bl_backup="$HOME/.dotfiles_backup/remote-${remote_short}-$(date +%Y%m%d_%H%M%S)"
mkdir -p "$bl_backup"
scp -q "$target:$real_path" "$bl_backup/.bashrc.local" 2>/dev/null || true
info "Backed up remote $real_path$bl_backup/.bashrc.local"
fi
elif ssh "$target" '[ -f ~/.bashrc.local ]' 2>/dev/null; then
local bl_backup="$HOME/.dotfiles_backup/remote-${remote_short}-$(date +%Y%m%d_%H%M%S)"
mkdir -p "$bl_backup"
scp -q "$target:~/.bashrc.local" "$bl_backup/.bashrc.local" 2>/dev/null || true
info "Backed up remote ~/.bashrc.local → $bl_backup/.bashrc.local"
fi
scp -q "$host_local" "$target:~/.bashrc.local"
success "Deployed: hosts/${remote_short}.bashrc.local → ~/.bashrc.local"
# Detect NFS home on the remote and deploy to /opt/kenjim/ if needed
local _remote_nfs=false
if ssh "$target" 'df -P "$HOME" 2>/dev/null | tail -1 | grep -qE ":|nfs"' 2>/dev/null; then
_remote_nfs=true
fi
if $_remote_nfs; then
info "NFS home detected on $target — deploying to /opt/kenjim/.bashrc.local"
# Ensure /opt/kenjim exists — skip sudo if it already does
if ! ssh "$target" '[ -d /opt/kenjim ]' 2>/dev/null; then
info "Creating /opt/kenjim on $target (requires sudo)..."
ssh -t "$target" 'sudo mkdir -p /opt/kenjim && sudo chown $(id -u):$(id -g) /opt/kenjim && chmod 700 /opt/kenjim'
fi
scp -q "$host_local" "$target:/opt/kenjim/.bashrc.local"
ssh "$target" 'chmod 600 /opt/kenjim/.bashrc.local && ln -sfn /opt/kenjim/.bashrc.local ~/.bashrc.local'
success "Deployed: hosts/${remote_short}.bashrc.local → /opt/kenjim/.bashrc.local (symlinked from ~)"
else
scp -q "$host_local" "$target:~/.bashrc.local"
success "Deployed: hosts/${remote_short}.bashrc.local → ~/.bashrc.local"
fi
(( deployed++ )) || true
fi
else

View File

@@ -186,6 +186,69 @@ fi
echo "✅ .bashrc.local written for profile: $MACHINE_PROFILE"
# ---- NFS-aware placement for work servers ----
# Work servers with NFS-mounted home dirs share ~/.bashrc.local across hosts.
# To keep per-machine overrides, store the real file in /opt/kenjim/ and symlink.
if [[ "$MACHINE_PROFILE" == "work" ]]; then
_is_nfs_home=false
case "$(hostname -s)" in
etqc-*|etbg-*|engtech-dev-*)
if df -P "$HOME" 2>/dev/null | tail -1 | grep -qE ':|nfs'; then
_is_nfs_home=true
elif mount | grep -q "on ${HOME%%/} .*type nfs"; then
_is_nfs_home=true
fi
;;
esac
if $_is_nfs_home; then
OPT_DIR="/opt/kenjim"
OPT_LOCAL="$OPT_DIR/.bashrc.local"
echo "🔗 NFS home detected — relocating .bashrc.local to $OPT_LOCAL"
if [ ! -d "$OPT_DIR" ]; then
echo " Creating $OPT_DIR ..."
sudo mkdir -p "$OPT_DIR"
sudo chown "$(id -u):$(id -g)" "$OPT_DIR"
chmod 700 "$OPT_DIR"
fi
# If ~/.bashrc.local is already a symlink (previous run), the cat above
# wrote through it into the target. Remove the symlink first so mv
# doesn't see source and destination as the same file.
if [ -L "$BASHRC_LOCAL" ]; then
rm -f "$BASHRC_LOCAL"
# Content already landed at the symlink target; just ensure perms
chmod 600 "$OPT_LOCAL"
else
mv "$BASHRC_LOCAL" "$OPT_LOCAL"
chmod 600 "$OPT_LOCAL"
fi
ln -sfn "$OPT_LOCAL" "$BASHRC_LOCAL"
echo " Linked: ~/.bashrc.local → $OPT_LOCAL"
# VS Code Remote stores large caches in ~/.vscode-server and
# ~/.vscode-remote-containers — keep them on local disk, not NFS.
for _vsdir in .vscode-server .vscode-remote-containers; do
_opt_target="$OPT_DIR/$_vsdir"
_home_link="$HOME_DIR/$_vsdir"
mkdir -p "$_opt_target"
if [ -d "$_home_link" ] && [ ! -L "$_home_link" ]; then
# Existing real directory — move contents then replace with symlink
echo " Moving ~/$_vsdir$OPT_DIR/$_vsdir ..."
rsync -a "$_home_link/" "$_opt_target/" 2>/dev/null || \
cp -a "$_home_link/." "$_opt_target/" 2>/dev/null || true
rm -rf "$_home_link"
fi
ln -sfn "$_opt_target" "$_home_link"
echo " Linked: ~/$_vsdir$_opt_target"
done
echo "✅ Per-machine .bashrc.local and VS Code dirs stored outside NFS at $OPT_DIR"
fi
fi
# ------------------------------------------------------
# 4⃣ INITIALIZE DOTFILES REPO (with Gitea remote)
# ------------------------------------------------------