#!/usr/bin/env bash# parallels-tools.sh — install Parallels Tools on Kali, fixing the common# "Permission denied" failure caused by the Tools ISO auto-mounting with the# `noexec` option (so its ./install script can't be executed).## It unmounts the auto-mounted CD, remounts it at a directory you control WITH# exec permission, ensures the kernel build dependencies are present, then runs# the installer.## pt-install # unmount, remount exec, install (default)# pt-install --mount-only # just remount; run ./install yourself# pt-install --no-deps # skip the build-deps apt step# pt-install --help## Run WITHOUT sudo: the script self-elevates. (`sudo pt-install` fails because# ~/.local/bin isn't on sudo's secure_path — run the bare command instead.)# First attach the CD in Parallels: Actions > Install Parallels Tools.# Override the mount point with: PT_MOUNT=/mnt/foo pt-installset -eu
MOUNT_TARGET="${PT_MOUNT:-/mnt/parallels-tools}"MOUNT_ONLY=0WITH_DEPS=1c_i='\033[38;2;196;167;231m'; c_o='\033[38;2;156;207;216m'c_w='\033[38;2;246;193;119m'; c_e='\033[38;2;235;111;146m'; 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; }die(){printf"${c_e}[-]${c_z} %s\n""$*" >&2; exit1; }# --- args -------------------------------------------------------------------while[$# -gt 0]; docase$1in --mount-only)MOUNT_ONLY=1 ;;
--no-deps)WITH_DEPS=0 ;;
-h|--help) sed -n '2,16p'"$0" | sed 's/^# \{0,1\}//'; exit0 ;;
*) die "unknown option: $1 (try --help)" ;;
esacshiftdone# --- sanity: Linux only -----------------------------------------------------["$(uname -s)"= Linux ]|| die "this script is for the Kali guest, not the host."# --- self-elevate to root (mounting + module install need it) ---------------if["$(id -u)" -ne 0]; then info "elevating with sudo..."exec sudo -E PT_MOUNT="$MOUNT_TARGET""$0"\$(["$MOUNT_ONLY"=1]&&printf -- --mount-only )\$(["$WITH_DEPS"=0]&&printf -- --no-deps )fi# --- 1. locate the Parallels Tools CD device --------------------------------find_device(){ifd=$(blkid -L 'Parallels Tools'2>/dev/null); thenprintf'%s'"$d"; return0; fifor c in /dev/cdrom /dev/sr0 /dev/sr1; do[ -b "$c"]||continueprintf'%s'"$(readlink -f "$c")"; return0donereturn1}DEV=$(find_device)\|| die "Parallels Tools CD not found. In Parallels: Actions > Install Parallels Tools, then re-run."DEV=$(readlink -f "$DEV")info "Parallels Tools device: $DEV"# --- 2. unmount it wherever the desktop auto-mounted it (noexec) -------------unmount_dev(){ umount "$DEV"2>/dev/null &&return0 umount "$1"2>/dev/null &&return0 udisksctl unmount -b "$DEV"2>/dev/null &&return0return1}while :; domp=$(findmnt -rn -o TARGET --source "$DEV"2>/dev/null | head -n1 ||true)[ -n "$mp"]||break info "unmounting auto-mounted CD at: $mp" unmount_dev "$mp"|| die "could not unmount $mp — close any file manager browsing the CD and retry."done# --- 3. remount at our directory WITH exec ----------------------------------mkdir -p "$MOUNT_TARGET"info "mounting $DEV -> $MOUNT_TARGET (exec)"mount -o exec,ro "$DEV""$MOUNT_TARGET"\|| die "mount failed (is the Tools CD still attached?)"INSTALLER="$MOUNT_TARGET/install"[ -x "$INSTALLER"]|| die "installer not found at $INSTALLER — that CD isn't Parallels Tools."ok "mounted with exec at $MOUNT_TARGET"if["$MOUNT_ONLY"=1]; then ok "ready. Run: cd $MOUNT_TARGET && sudo ./install"exit0fi# --- 4. ensure kernel build deps (Parallels Tools compiles modules) ---------# Tools builds prl_fs/prl_eth via DKMS, which needs headers matching the# *running* kernel. Try the exact version, fall back to the arch metapackage,# then verify a real header tree exists before handing off to the installer —# otherwise it dies with a cryptic "failed to install mandatory packages".if["$WITH_DEPS"=1]&&command -v apt-get >/dev/null 2>&1; thenKREL=$(uname -r)ARCH=$(dpkg --print-architecture 2>/dev/null ||echo amd64) info "installing build dependencies for kernel $KREL ($ARCH)" apt-get update -qq || warn "apt update failed — continuing on cached index" apt-get install -y --no-install-recommends build-essential dkms \|| warn "build-essential/dkms install hit errors — continuing"# exact-version headers first, then the arch metapackage (linux-headers-arm64/amd64)if ! apt-get install -y --no-install-recommends "linux-headers-$KREL"; then warn "'linux-headers-$KREL' not in the apt index; trying linux-headers-$ARCH" apt-get install -y --no-install-recommends "linux-headers-$ARCH"||truefi# hard gate: no header tree => the Parallels build is guaranteed to failif[ ! -e "/lib/modules/$KREL/build"]; then warn "no kernel headers at /lib/modules/$KREL/build." warn "your running kernel is newer than the packaged headers. Fix with:" warn " sudo apt update && sudo apt full-upgrade -y && sudo reboot" warn "then re-run: pt-install" die "kernel headers for $KREL unavailable — aborting before the doomed build."fi ok "kernel headers present: /lib/modules/$KREL/build"# Parallels' installer hardcodes a "libfuse2" dependency. On time64# Debian/Kali the FUSE runtime ships as libfuse2t64 and the literal name# has no candidate, so the installer dies "failed to install mandatory# packages". Pre-satisfy it: install the real lib, then drop a tiny# transitional shim so the installer's `apt-get install libfuse2` passes. apt-get install -y --no-install-recommends binfmt-support 2>/dev/null ||trueif ! apt-get install -y --no-install-recommends libfuse2 2>/dev/null; then info "libfuse2 has no candidate (time64 rename) — using libfuse2t64 + shim"if ! apt-get install -y --no-install-recommends libfuse2t64; then# not in the configured index — pull the .deb straight from the pool.# (version-pinned; if it 404s, bump it from kali.download/.../f/fuse/) warn "libfuse2t64 not in apt index — fetching .deb from kali.download ($ARCH)"_fdeb=$(mktemp --suffix=.deb)_furl="https://kali.download/kali/pool/main/f/fuse/libfuse2t64_2.9.9-9+b1_${ARCH}.deb"if curl -fsSL -o "$_fdeb""$_furl"&& dpkg -i "$_fdeb"; then ok "installed libfuse2t64 from pool .deb"else apt-get -f install -y >/dev/null 2>&1||true warn "libfuse2t64 install failed; FUSE shared folders may not work"fi rm -f "$_fdeb"fiif ! dpkg -s libfuse2 >/dev/null 2>&1\&& apt-get install -y --no-install-recommends equivs >/dev/null 2>&1; then_shim=$(mktemp -d) cat > "$_shim/libfuse2"<<'CTL'Section: libsPriority: optionalStandards-Version: 4.6.2Package: libfuse2Version: 2.9.9-pe1Depends: libfuse2t64Description: transitional shim mapping libfuse2 onto libfuse2t64 Satisfies the Parallels Tools installer's hardcoded libfuse2 dependency on time64 Debian/Kali, where the FUSE runtime ships as libfuse2t64.CTLif(cd"$_shim"&& equivs-build libfuse2 >/dev/null 2>&1)\&& apt-get install -y "$_shim"/libfuse2_*.deb >/dev/null 2>&1; then ok "installed libfuse2 -> libfuse2t64 transitional shim"else warn "could not build the libfuse2 shim; installer may still reject it"fi rm -rf "$_shim"fifielse info "skipping build-deps (--no-deps): needs linux-headers-$(uname -r) + libfuse2"fi# --- 5. run the Parallels installer -----------------------------------------info "running the Parallels Tools installer"cd"$MOUNT_TARGET"if ./install --help 2>&1 | grep -q -- '--install-unattended-with-deps'; then ./install --install-unattended-with-deps
else ./install
fiok "Parallels Tools installed. Reboot to finish: sudo reboot"