#!/usr/bin/env bash# setup-wm.sh — deploy the pentest-env BSPWM rice.# Symlinks each WM app dir into $XDG_CONFIG_HOME and makes the scripts# executable. Self-locating: works run from the repo OR from the installed# payload ($DEST/wm). Idempotent; existing real dirs are backed up once.## ./setup-wm.sh install rice deps + link configs into ~/.config# ./setup-wm.sh --no-deps skip the apt dependency install# ./setup-wm.sh --unlink remove the symlinks (restores nothing else)# ./setup-wm.sh --dry-run print actions onlyset -eu
WM_DIR=$(cd"$(dirname "$0")"&&pwd): "${XDG_CONFIG_HOME:=$HOME/.config}"DRYRUN=0; UNLINK=0; DO_DEPS=1for a in"$@"; docase$ain --dry-run)DRYRUN=1 ;;
--unlink)UNLINK=1 ;;
--no-deps)DO_DEPS=0 ;;
-h|--help) sed -n '7,12p'"$0" | sed 's/^# \{0,1\}//'; exit0 ;;
*)printf'unknown option: %s\n'"$a" >&2; exit1 ;;
esacdonec_i='\033[38;2;196;167;231m'; c_o='\033[38;2;156;207;216m'c_w='\033[38;2;246;193;119m'; c_z='\033[0m'info(){printf"${c_i}[*]${c_z} %s\n""$*"; }ok(){printf"${c_o}[+]${c_z} %s\n""$*"; }warn(){printf"${c_w}[!]${c_z} %s\n""$*" >&2; }run(){if["$DRYRUN"=1]; thenprintf' [dry-run] %s\n'"$*"; elseeval"$@"; fi; }APPS="bspwm sxhkd polybar rofi picom dunst"# ── unlink mode ─────────────────────────────────────────────────────if["$UNLINK"=1]; then info "removing pentest-env rice symlinks"for app in$APPS; dotgt="$XDG_CONFIG_HOME/$app"if[ -L "$tgt"]; then run "rm -f '$tgt'"; ok "unlinked $app"; fidoneexit0fi# ── link mode ───────────────────────────────────────────────────────[ -d "$WM_DIR/bspwm"]||{ warn "payload missing at $WM_DIR — wrong dir?"; exit1; }# ── runtime dependencies (Debian/Kali) ──────────────────────────────# The rice needs these at runtime. clipmenu + xsel/xclip power the clipboard# history popup (super+c); libnotify-bin provides notify-send (used in sxhkdrc).# Mac<->VM shared clipboard comes from Parallels Tools, not apt (sudo pt-install).if["$DO_DEPS"=1]&&command -v apt-get >/dev/null 2>&1; thenWM_DEPS="bspwm sxhkd polybar rofi picom dunst feh xclip xsel clipmenu libnotify-bin papirus-icon-theme maim xdotool playerctl brightnessctl pavucontrol pulseaudio-utils unclutter network-manager-gnome lxpolkit imagemagick i3lock xss-lock" info "installing rice runtime deps: $WM_DEPS" run "sudo apt-get update -qq"|| warn "apt update failed — continuing" run "sudo apt-get install -y $WM_DEPS"|| warn "some rice deps failed — install them manually"elif["$DO_DEPS"=0]; then info "skipping rice deps (--no-deps)"fiinfo "deploying BSPWM rice from $WM_DIR -> $XDG_CONFIG_HOME"run "mkdir -p '$XDG_CONFIG_HOME' '$HOME/Pictures'"for app in$APPS; dosrc="$WM_DIR/$app"tgt="$XDG_CONFIG_HOME/$app"if[ -L "$tgt"]; then run "rm -f '$tgt'"# refresh stale symlinkelif[ -e "$tgt"]; then run "mv '$tgt' '$tgt.bak.\$(date +%s)'"# back up a real dir once warn "backed up existing $app -> $tgt.bak.*"fi run "ln -sfn '$src' '$tgt'" ok "linked $app"done# executable bits (symlinks point back into the repo/payload)run "chmod +x '$WM_DIR/bspwm/bspwmrc' '$WM_DIR/bspwm/make-wallpaper.sh' \ '$WM_DIR/polybar/launch.sh' '$WM_DIR/rofi/powermenu.sh' \ '$WM_DIR/polybar/scripts/'*.sh"# ── wallpaper: generate once if missing (uses imagemagick from the deps above) ─# bspwmrc globs ~/.config/bspwm/wallpaper.* (symlinked here), so this is picked up.WALL="$WM_DIR/bspwm/wallpaper.png"if[ ! -f "$WALL"]; then info "generating Rose Pine wallpaper -> $WALL" run "'$WM_DIR/bspwm/make-wallpaper.sh'"|| warn "wallpaper gen failed (need imagemagick)"fi# ── install the Xsession launcher (so the login greeter lists BSPWM) ─# The `bspwm` apt package usually ships /usr/share/xsessions/bspwm.desktop.# If it's missing, drop our own so LightDM/GDM can start the rice.XSESS=/usr/share/xsessions/bspwm.desktop
if[ ! -f "$XSESS"]&&command -v sudo >/dev/null 2>&1; then info "installing Xsession entry -> $XSESS" run "sudo tee '$XSESS' >/dev/null <<'EOF'[Desktop Entry]Name=bspwmComment=Binary space partitioning window managerExec=bspwmType=ApplicationEOF"|| warn "could not write $XSESS (no sudo?) — pick BSPWM another way"fiok "rice deployed."cat <<'EOF' next: • log out, then at the greeter pick the "bspwm" session and log back in • or, for startx users: echo 'exec bspwm' >> ~/.xinitrc && startx • first keys: super+Return terminal · super+space launcher · super+shift+e power • full keymap: ~/.config/sxhkd/sxhkdrcEOF