Files
dotfiles/config/scripts/.local/scripts/targo
T
2026-03-28 07:53:51 +01:00

30 lines
691 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
[ -z "${1:-}" ] && { echo "Usage: $0 <tarball>"; exit 1; }
tarball=$(realpath "$1")
top_dir=$(tar -tf "$tarball" | sed -e 's/^\.\///' | cut -d/ -f1 | sort -u)
if [ "$(echo "$top_dir" | wc -l)" -ne 1 ]; then
echo "Error: Tarball must contain a single top-level directory."
exit 1
fi
mountpoint=$(mktemp -d)
cleanup() {
cd /
sudo umount "$mountpoint" 2>/dev/null || true
rmdir "$mountpoint"
}
trap cleanup EXIT
sudo mount -t tmpfs -o size=8G tmpfs "$mountpoint"
tar -xf "$tarball" -C "$mountpoint"
pushd "$mountpoint/$top_dir" > /dev/null
echo "Spawning shell in tmpfs. Type 'exit' to finish and cleanup."
bash
popd > /dev/null