#!/usr/bin/env bash # install.sh — deploy the pentest-env ("pe") toolkit onto Ubuntu/Debian, Kali, # macOS, or another Unix host with the core dependencies available. # # ./install.sh full install # ./install.sh --dry-run print every action, change nothing # ./install.sh --no-theme skip Rose Pine GNOME/XFCE theming # ./install.sh --no-deps skip the package-manager step # ./install.sh --no-fonts skip the MesloLGS NF Nerd Font install # ./install.sh --no-wm skip the optional BSPWM rice (GNOME stays untouched) # ./install.sh --no-wordlists skip the sparse SecLists checkout # ./install.sh --parallels-tools also install Parallels Tools (Kali guest; CD attached) # ./install.sh --uninstall remove integration (keeps your database) # ./install.sh --help # # Idempotent: safe to re-run. rc-file edits live inside a single marked block. set -eu umask 022 # --------------------------------------------------------------------------- # paths & options # --------------------------------------------------------------------------- REPO=$(cd "$(dirname "$0")" && pwd) PAYLOAD="$REPO/config" : "${XDG_CONFIG_HOME:=$HOME/.config}" : "${XDG_DATA_HOME:=$HOME/.local/share}" : "${XDG_STATE_HOME:=$HOME/.local/state}" DEST="$XDG_CONFIG_HOME/pentest-env" BIN_LINK="$HOME/.local/bin/pe" ZSHRC="$HOME/.zshrc" TMUXCONF="$HOME/.tmux.conf" ZSH_DIR="${ZSH:-$HOME/.oh-my-zsh}" ZSH_CUSTOM="${ZSH_CUSTOM:-$ZSH_DIR/custom}" HTB_LINK="$HOME/.local/bin/htb-session" DESKTOP_DIR="$XDG_DATA_HOME/applications" ICON_DIR="$XDG_DATA_HOME/icons/hicolor/scalable/apps" WORDLIST_ROOT="${PE_WORDLIST_ROOT:-$HOME/voidwalker/wordlists/SecLists}" ALACRITTY_DST="$XDG_CONFIG_HOME/alacritty" ALACRITTY_CONFIG="$ALACRITTY_DST/alacritty.toml" GNOME_ROLLBACK="$XDG_STATE_HOME/pentest-env/gnome-before-rose-pine.dconf" DRYRUN=0; DO_THEME=1; DO_DEPS=1; DO_PLUGINS=1; UNINSTALL=0; DO_PT=0; DO_FONTS=1; DO_WM=1; DO_WORDLISTS=1 # --------------------------------------------------------------------------- # output # --------------------------------------------------------------------------- c_info='\033[38;2;196;167;231m'; c_ok='\033[38;2;156;207;216m' c_warn='\033[38;2;246;193;119m'; c_err='\033[38;2;235;111;146m'; c_z='\033[0m' info() { printf "${c_info}[*]${c_z} %s\n" "$*"; } ok() { printf "${c_ok}[+]${c_z} %s\n" "$*"; } warn() { printf "${c_warn}[!]${c_z} %s\n" "$*" >&2; } die() { printf "${c_err}[-]${c_z} %s\n" "$*" >&2; exit 1; } # run CMD... -> execute, or just print under --dry-run run() { if [ "$DRYRUN" = 1 ]; then printf ' [dry-run] %s\n' "$*"; else eval "$@"; fi } # Execute an argv-safe command. New ownership-sensitive helpers use this rather # than the legacy string runner so paths containing spaces or quotes stay data. run_argv() { if [ "$DRYRUN" = 1 ]; then printf ' [dry-run]' printf ' %q' "$@" printf '\n' else "$@" fi } usage() { sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'; exit 0; } # --------------------------------------------------------------------------- # arg parsing # --------------------------------------------------------------------------- while [ $# -gt 0 ]; do case $1 in --dry-run) DRYRUN=1 ;; --no-theme) DO_THEME=0 ;; --no-deps) DO_DEPS=0 ;; --no-fonts) DO_FONTS=0 ;; --no-wm) DO_WM=0 ;; --no-wordlists) DO_WORDLISTS=0 ;; --no-plugins) DO_PLUGINS=0 ;; --parallels-tools) DO_PT=1 ;; --uninstall) UNINSTALL=1 ;; -h|--help) usage ;; *) die "unknown option: $1 (try --help)" ;; esac shift done # --------------------------------------------------------------------------- # OS detection # --------------------------------------------------------------------------- OS=other if [ "$(uname -s)" = Darwin ]; then OS=macos elif [ -f /etc/debian_version ]; then OS=debian; fi IS_KALI=0 if grep -qi kali /etc/os-release 2>/dev/null; then IS_KALI=1; fi IS_GNOME=0 case "${XDG_CURRENT_DESKTOP:-}:${XDG_SESSION_DESKTOP:-}" in *GNOME*|*gnome*|*Ubuntu*|*ubuntu*) IS_GNOME=1 ;; esac # --------------------------------------------------------------------------- # rc-block helper: keep exactly one marked block in $1 # --------------------------------------------------------------------------- ensure_block() { _file=$1; _marker=$2; _content=$3 _start="# >>> $_marker >>>"; _end="# <<< $_marker <<<" if [ "$DRYRUN" = 1 ]; then printf ' [dry-run] ensure block "%s" in %s\n' "$_marker" "$_file"; return 0 fi touch "$_file" if grep -qF "$_start" "$_file"; then _tmp=$(mktemp) awk -v s="$_start" -v e="$_end" ' $0==s{skip=1} !skip{print} $0==e{skip=0}' "$_file" > "$_tmp" mv "$_tmp" "$_file" fi printf '%s\n%s\n%s\n' "$_start" "$_content" "$_end" >> "$_file" } remove_block() { _file=$1; _marker=$2 _start="# >>> $_marker >>>"; _end="# <<< $_marker <<<" [ -f "$_file" ] || return 0 if [ "$DRYRUN" = 1 ]; then printf ' [dry-run] remove block "%s" from %s\n' "$_marker" "$_file"; return 0; fi grep -qF "$_start" "$_file" || return 0 _tmp=$(mktemp) awk -v s="$_start" -v e="$_end" '$0==s{skip=1} !skip{print} $0==e{skip=0}' "$_file" > "$_tmp" mv "$_tmp" "$_file" } install_owned_link() { _src=$1; _link=$2; _backup="$_link.before-pentest-env" if [ -L "$_link" ] && [ "$(readlink "$_link")" = "$_src" ]; then info "link already installed: $_link" return 0 fi if [ -e "$_link" ] || [ -L "$_link" ]; then [ ! -e "$_backup" ] && [ ! -L "$_backup" ] \ || die "cannot preserve existing $_link: backup already exists at $_backup" run "mv -- '$_link' '$_backup'" fi run "ln -s '$_src' '$_link'" } restore_owned_link() { _src=$1; _link=$2; _backup="$_link.before-pentest-env" if [ -L "$_link" ] && [ "$(readlink "$_link")" = "$_src" ]; then run "rm -f -- '$_link'" elif [ -e "$_link" ] || [ -L "$_link" ]; then warn "keeping non-pentest-env path: $_link" return 0 fi if [ -e "$_backup" ] || [ -L "$_backup" ]; then run "mv -- '$_backup' '$_link'" fi } # Install a project-owned file without losing a pre-existing file or a later # user edit. The snapshot records the exact version last installed, allowing a # rerun to distinguish a managed file from one the user changed afterwards. install_managed_file() { _src=$1; _dst=$2; _mode=$3 _backup="$_dst.before-pentest-env" _snapshot="$_dst.pentest-env-managed" if [ -f "$_snapshot" ]; then if { [ -e "$_dst" ] || [ -L "$_dst" ]; } \ && { [ -L "$_dst" ] || [ ! -f "$_dst" ] || ! cmp -s "$_dst" "$_snapshot"; }; then warn "keeping user-modified file: $_dst" return 0 fi elif [ -e "$_dst" ] || [ -L "$_dst" ]; then if [ -e "$_backup" ] || [ -L "$_backup" ]; then if [ -L "$_dst" ] || [ ! -f "$_dst" ] || ! cmp -s "$_dst" "$_src"; then warn "keeping user-modified file: $_dst (original remains at $_backup)" return 0 fi else run_argv mv -- "$_dst" "$_backup" fi fi run_argv install -m "$_mode" "$_src" "$_dst" run_argv install -m 600 "$_src" "$_snapshot" } restore_managed_file() { _src=$1; _dst=$2 _backup="$_dst.before-pentest-env" _snapshot="$_dst.pentest-env-managed" if [ -f "$_snapshot" ]; then if { [ -e "$_dst" ] || [ -L "$_dst" ]; } \ && { [ -L "$_dst" ] || [ ! -f "$_dst" ] || ! cmp -s "$_dst" "$_snapshot"; }; then warn "keeping user-modified file: $_dst (management snapshot and backup retained)" return 0 fi run_argv rm -f -- "$_dst" elif [ -e "$_dst" ] || [ -L "$_dst" ]; then if [ ! -L "$_dst" ] && [ -f "$_dst" ] && [ -f "$_src" ] \ && cmp -s "$_dst" "$_src"; then run_argv rm -f -- "$_dst" else warn "keeping non-pentest-env file: $_dst" return 0 fi fi if [ -e "$_backup" ] || [ -L "$_backup" ]; then run_argv mv -f -- "$_backup" "$_dst" fi [ ! -e "$_snapshot" ] && [ ! -L "$_snapshot" ] \ || run_argv rm -f -- "$_snapshot" } # =========================================================================== # UNINSTALL # =========================================================================== if [ "$UNINSTALL" = 1 ]; then info "uninstalling pentest-env integration (your database is kept)" restore_owned_link "$DEST/bin/pe" "$BIN_LINK" restore_owned_link "$DEST/bin/htb-session" "$HTB_LINK" restore_owned_link "$DEST/scripts/parallels-tools.sh" "$HOME/.local/bin/pt-install" restore_managed_file "$DEST/theme/gnome/htb-workspace.desktop" "$DESKTOP_DIR/htb-workspace.desktop" restore_managed_file "$DEST/theme/gnome/htb-workspace.svg" "$ICON_DIR/htb-workspace.svg" restore_managed_file "$DEST/alacritty/alacritty.toml" "$ALACRITTY_CONFIG" remove_block "$ZSHRC" pentest-env remove_block "$TMUXCONF" pentest-env if [ -f "$GNOME_ROLLBACK" ] && [ -x "$DEST/theme/install-gnome.sh" ]; then run "'$DEST/theme/install-gnome.sh' --restore || true" fi [ -x "$DEST/wm/setup-wm.sh" ] && run "'$DEST/wm/setup-wm.sh' --unlink" ok "removed pe symlink, rc integration, and BSPWM rice symlinks." info "kept: $DEST and your data in $XDG_DATA_HOME/pentest-env" info "to remove everything: rm -rf '$DEST' '$XDG_DATA_HOME/pentest-env'" exit 0 fi # =========================================================================== # INSTALL # =========================================================================== [ -d "$PAYLOAD" ] || die "payload not found: $PAYLOAD (run from the repo root)" info "pentest-env installer (OS=$OS kali=$IS_KALI dry-run=$DRYRUN)" # --- 1. dependencies -------------------------------------------------------- DEB_DEPS="zsh tmux sqlcipher fzf bat ripgrep fd-find gnupg jq git curl xclip wl-clipboard alacritty openvpn pipx desktop-file-utils dconf-cli python3 bsdextrautils eza" BREW_DEPS="zsh tmux sqlcipher fzf bat ripgrep fd gnupg jq git eza openvpn python" # BSPWM rice deps (Linux/X11 only — installed when DO_WM is on) WM_DEPS="bspwm sxhkd polybar rofi picom dunst feh libnotify-bin maim xdotool \ brightnessctl playerctl pulseaudio-utils papirus-icon-theme x11-xserver-utils" if [ "$DO_DEPS" = 1 ]; then case $OS in debian) info "installing apt packages: $DEB_DEPS" run "sudo apt-get update -qq" # eza isn't in older repos; install best-effort, don't fail the run run "sudo apt-get install -y $DEB_DEPS || sudo apt-get install -y ${DEB_DEPS% eza}" if [ "$DO_WM" = 1 ] && [ "$IS_GNOME" = 0 ]; then info "installing BSPWM rice packages: $WM_DEPS" run "sudo apt-get install -y $WM_DEPS || true" # best-effort; rice degrades gracefully fi ;; macos) command -v brew >/dev/null 2>&1 || die "Homebrew required on macOS: https://brew.sh" info "installing brew packages: $BREW_DEPS" run "brew install $BREW_DEPS || true" run "brew install --cask alacritty || true" ;; *) warn "unknown OS — install these yourself: $DEB_DEPS" ;; esac else info "skipping dependency install (--no-deps)" fi # Optional challenge helpers: keep these best-effort so a missing wheel or an # older Ubuntu repository never prevents the encrypted workspace from working. if [ "$DO_DEPS" = 1 ] && [ "$OS" = debian ]; then case "$(uname -m)" in aarch64|arm64|armv8*) info "installing ARM64 x86 challenge helpers (best-effort)" run "sudo apt-get install -y qemu-user qemu-user-binfmt gdb-multiarch || true" ;; esac if command -v pipx >/dev/null 2>&1; then if ! command -v nxc >/dev/null 2>&1 && ! command -v netexec >/dev/null 2>&1; then info "installing NetExec via pipx (best-effort)" run "pipx install netexec || true" fi fi fi # --- 2. deploy payload to XDG config ---------------------------------------- info "deploying toolkit to $DEST" run "mkdir -p '$DEST' '$HOME/.local/bin' '$XDG_DATA_HOME/pentest-env'" run "cp -R '$PAYLOAD/.' '$DEST/'" run "chmod +x '$DEST/bin/pe' '$DEST/bin/htb-session' '$DEST/theme/install-theme.sh' '$DEST/theme/install-gnome.sh' '$DEST/theme/restore-gnome.sh' '$DEST/scripts/parallels-tools.sh'" run "chmod +x '$DEST/wm/setup-wm.sh' '$DEST/wm/bspwm/bspwmrc' '$DEST/wm/polybar/launch.sh' '$DEST/wm/rofi/powermenu.sh' '$DEST/wm/polybar/scripts/'*.sh" run "chmod -R go-w '$DEST'" install_owned_link "$DEST/bin/pe" "$BIN_LINK" install_owned_link "$DEST/bin/htb-session" "$HTB_LINK" install_owned_link "$DEST/scripts/parallels-tools.sh" "$HOME/.local/bin/pt-install" ok "pe -> $BIN_LINK · htb-session -> $HTB_LINK · pt-install -> Parallels Tools helper" # --- 2a. HTML handbook + HTB workspace skeleton ---------------------------- run "mkdir -p '$HOME/htb' '$HOME/htb/lab'" run "chmod 700 '$HOME/htb' '$HOME/htb/lab'" if [ ! -e "$HOME/htb/README.md" ]; then run "cp -f '$DEST/templates/htb/README.md' '$HOME/htb/README.md'"; fi if [ ! -e "$HOME/htb/.gitignore" ]; then run "cp -f '$DEST/templates/htb/.gitignore' '$HOME/htb/.gitignore'"; fi run "mkdir -p '$DESKTOP_DIR' '$ICON_DIR'" install_managed_file "$DEST/theme/gnome/htb-workspace.desktop" "$DESKTOP_DIR/htb-workspace.desktop" 644 install_managed_file "$DEST/theme/gnome/htb-workspace.svg" "$ICON_DIR/htb-workspace.svg" 644 if command -v update-desktop-database >/dev/null 2>&1; then run "update-desktop-database '$DESKTOP_DIR' >/dev/null 2>&1 || true"; fi # --- 2a. sparse SecLists (only the useful lab lists) ------------------------ install_wordlists() { [ "$DO_WORDLISTS" = 1 ] || { info "skipping wordlists (--no-wordlists)"; return 0; } if [ "$DO_DEPS" = 0 ] && [ "${PE_FORCE_WORDLISTS:-0}" != 1 ]; then info "skipping SecLists with --no-deps (set PE_FORCE_WORDLISTS=1 to fetch)" return 0 fi command -v git >/dev/null 2>&1 || { warn "git missing — skipping SecLists"; return 0; } _sl='Discovery/Web-Content/raft-medium-words.txt Discovery/Web-Content/raft-small-words.txt Discovery/Web-Content/quickhits.txt Discovery/DNS/subdomains-top1million-110000.txt Passwords/Common-Credentials/xato-net-10-million-passwords-100000.txt Usernames/top-usernames-shortlist.txt Fuzzing/special-chars.txt Fuzzing/LFI/LFI-Jhaddix.txt' if [ ! -d "$WORDLIST_ROOT/.git" ]; then info "cloning sparse SecLists -> $WORDLIST_ROOT" run "mkdir -p \"$(dirname \"$WORDLIST_ROOT\")\"" run "git clone --depth 1 --filter=blob:none --sparse https://github.com/danielmiessler/SecLists.git '$WORDLIST_ROOT'" fi run "git -C '$WORDLIST_ROOT' sparse-checkout set --no-cone $_sl" || return 1 if [ "$DRYRUN" = 1 ]; then printf ' [dry-run] persist PE_WORDLIST_ROOT=%s in %s\n' "$WORDLIST_ROOT" "$DEST/wordlist-root" else printf '%s\n' "$WORDLIST_ROOT" > "$DEST/wordlist-root" chmod 600 "$DEST/wordlist-root" fi } install_wordlists || warn "SecLists setup failed — set PE_WORDLIST_ROOT manually" # --- 2b. Alacritty Rose Pine config (OS-agnostic) --------------------------- info "installing Alacritty Rose Pine config -> $ALACRITTY_DST/alacritty.toml" run "mkdir -p '$ALACRITTY_DST'" install_managed_file "$DEST/alacritty/alacritty.toml" "$ALACRITTY_CONFIG" 644 ok "Alacritty themed (font: MesloLGS NF)" # --- 2c. MesloLGS NF Nerd Font (the family alacritty.toml + prompt expect) --- # The exact "MesloLGS NF" family lives in romkatv/powerlevel10k-media as four # plain TTFs. fontconfig matches on the font's internal family name, not the # filename, so we just drop the files and refresh the cache (macOS scans live). FONT_BASE="https://github.com/romkatv/powerlevel10k-media/raw/master" install_fonts() { case $OS in macos) _fdir="$HOME/Library/Fonts" ;; *) _fdir="$XDG_DATA_HOME/fonts" ;; esac if [ -f "$_fdir/MesloLGS NF Regular.ttf" ] || \ { command -v fc-list >/dev/null 2>&1 && fc-list 2>/dev/null | grep -qi 'MesloLGS NF'; }; then info "MesloLGS NF already installed"; return 0 fi info "installing MesloLGS NF Nerd Font -> $_fdir" run "mkdir -p '$_fdir'" for _style in Regular Bold Italic 'Bold Italic'; do _enc=$(printf '%s' "$_style" | sed 's/ /%20/g') run "curl -fsSL '$FONT_BASE/MesloLGS%20NF%20$_enc.ttf' -o '$_fdir/MesloLGS NF $_style.ttf'" done if command -v fc-cache >/dev/null 2>&1; then run "fc-cache -f >/dev/null"; fi ok "MesloLGS NF installed (restart Alacritty to pick it up)" } if [ "$DO_FONTS" = 1 ]; then install_fonts || warn "font install failed — grab MesloLGS NF manually from $FONT_BASE" else info "skipping font install (--no-fonts)" fi # --- 3. oh-my-zsh + custom plugins ------------------------------------------ if [ "$DO_PLUGINS" = 1 ]; then if [ ! -d "$ZSH_DIR" ]; then info "installing oh-my-zsh" run "git clone --depth 1 https://github.com/ohmyzsh/ohmyzsh.git '$ZSH_DIR'" else info "oh-my-zsh already present"; fi run "mkdir -p '$ZSH_CUSTOM/plugins'" clone_plugin() { # name url if [ ! -d "$ZSH_CUSTOM/plugins/$1" ]; then run "git clone --depth 1 '$2' '$ZSH_CUSTOM/plugins/$1'" else info "plugin $1 already present"; fi } clone_plugin zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions clone_plugin zsh-syntax-highlighting https://github.com/zsh-users/zsh-syntax-highlighting clone_plugin zsh-you-should-use https://github.com/MichaelAquilina/zsh-you-should-use clone_plugin fzf-tab https://github.com/Aloxaf/fzf-tab ok "zsh plugins ready" else info "skipping zsh plugins (--no-plugins)"; fi # --- 4. rc integration (idempotent marked blocks) --------------------------- info "wiring ~/.zshrc and ~/.tmux.conf" ensure_block "$ZSHRC" pentest-env \ "[ -f \"$DEST/zsh/pentest.zsh\" ] && source \"$DEST/zsh/pentest.zsh\"" ensure_block "$TMUXCONF" pentest-env \ "source-file \"$DEST/tmux/tmux.conf\"" ok "rc files wired" # --- 5. database init ------------------------------------------------------- if [ "$DRYRUN" = 1 ]; then printf ' [dry-run] %s\n' "$BIN_LINK init (generates GPG-wrapped key + schema)" else info "initializing the encrypted database (you'll set a key passphrase)" "$BIN_LINK" init || warn "db init skipped/failed — run 'pe init' manually later" fi # --- 6. Rose Pine desktop theme (GNOME/Wayland or XFCE/X11) ------------------ if [ "$DO_THEME" = 1 ]; then if [ "$IS_GNOME" = 1 ] && [ -x "$DEST/theme/install-gnome.sh" ]; then info "applying Rose Pine theme (GNOME/Wayland)" run "'$DEST/theme/install-gnome.sh'" else info "applying Rose Pine theme (XFCE when available)" run "'$DEST/theme/install-theme.sh'" fi else info "skipping theme (--no-theme)"; fi # --- 7. BSPWM rice (opt-in on GNOME; Linux/X11 only) ------------------------- if [ "$DO_WM" = 1 ] && [ "$OS" != macos ] && [ "$IS_GNOME" = 0 ]; then info "deploying BSPWM rice (bspwm/sxhkd/polybar/rofi/picom/dunst)" if [ "$DRYRUN" = 1 ]; then run "'$DEST/wm/setup-wm.sh' --dry-run" else run "'$DEST/wm/setup-wm.sh'" fi elif [ "$IS_GNOME" = 1 ]; then info "skipping BSPWM rice (GNOME detected; use --no-theme/--no-wm as desired)" elif [ "$OS" = macos ]; then info "skipping BSPWM rice (X11-only, not macOS)" else info "skipping BSPWM rice (--no-wm)"; fi # --- 8. Parallels Tools (opt-in; requires the Tools CD attached) ------------- if [ "$DO_PT" = 1 ]; then info "installing Parallels Tools (self-elevates with sudo)" run "'$DEST/scripts/parallels-tools.sh'" fi # --- 9. default shell ------------------------------------------------------- if [ "$OS" != macos ] && command -v zsh >/dev/null 2>&1; then case "${SHELL:-}" in *zsh) : ;; *) warn "your login shell isn't zsh. Set it with: chsh -s \"$(command -v zsh)\"" ;; esac fi # --------------------------------------------------------------------------- ok "install complete." cat < --ip # create your first target 3. pe guide # open the offline HTML handbook 4. pe cheat env # quick terminal cheatsheet Optional BSPWM rice (only when GNOME was not detected): log out, pick the "bspwm" session at the greeter, then log back in. super+Return terminal · super+space launcher · super+shift+e power menu full keymap: ~/.config/sxhkd/sxhkdrc on a Parallels VM? attach the Tools CD (Actions > Install Parallels Tools), then: pt-install # fixes the noexec mount + installs (self-elevates) EOF