mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 12:03:52 +00:00
108 lines
3.9 KiB
Bash
Executable file
108 lines
3.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "$0")/.." && pwd)"
|
|
out_dir="${1:-$repo_root/inventory/current}"
|
|
|
|
mkdir -p "$out_dir"
|
|
|
|
run_to_file() {
|
|
local name="$1"
|
|
shift
|
|
"$@" >"$out_dir/$name"
|
|
}
|
|
|
|
run_shell_to_file() {
|
|
local name="$1"
|
|
local cmd="$2"
|
|
bash -lc "$cmd" >"$out_dir/$name"
|
|
}
|
|
|
|
cat >"$out_dir/README.md" <<EOF
|
|
# Machine Snapshot
|
|
|
|
Generated by \`scripts/snapshot-machine.sh\`.
|
|
|
|
These files are intentionally raw inventories of the current machine state.
|
|
They are meant to answer "what was on the box?" before a migration, not to be
|
|
hand-edited.
|
|
EOF
|
|
|
|
run_to_file system-uname.txt uname -a
|
|
run_to_file system-sw_vers.txt sw_vers
|
|
run_to_file system-computer-name.txt scutil --get ComputerName
|
|
run_to_file system-local-host-name.txt scutil --get LocalHostName
|
|
run_to_file system-hostname.txt hostname
|
|
|
|
run_to_file applications-system.txt ls -1 /Applications
|
|
run_to_file applications-user.txt ls -1 "$HOME/Applications"
|
|
run_shell_to_file applications-app-store.txt "mdfind 'kMDItemAppStoreHasReceipt==1' | sort"
|
|
|
|
run_to_file fonts-user.txt find "$HOME/Library/Fonts" -maxdepth 1 -type f
|
|
run_to_file fonts-system.txt find /Library/Fonts -maxdepth 1 -type f
|
|
|
|
run_to_file launchagents-user.txt find "$HOME/Library/LaunchAgents" -maxdepth 1 -type f
|
|
run_to_file launchagents-system.txt find /Library/LaunchAgents -maxdepth 1 -type f
|
|
run_to_file launchdaemons-system.txt find /Library/LaunchDaemons -maxdepth 1 -type f
|
|
run_shell_to_file login-items.txt "osascript -e 'tell application \"System Events\" to get the name of every login item' 2>/dev/null || true"
|
|
|
|
run_to_file home-top-level.txt find "$HOME" -maxdepth 1 -mindepth 1
|
|
run_to_file home-top-level-dirs.txt find "$HOME" -maxdepth 1 -mindepth 1 -type d
|
|
run_to_file home-top-level-files.txt find "$HOME" -maxdepth 1 \( -type f -o -type l \)
|
|
|
|
run_to_file dot-config-top.txt find "$HOME/.config" -maxdepth 2 -mindepth 1
|
|
run_to_file library-application-support-top.txt find "$HOME/Library/Application Support" -maxdepth 1 -mindepth 1 -type d
|
|
run_to_file library-preferences-top.txt find "$HOME/Library/Preferences" -maxdepth 1 -type f
|
|
|
|
run_to_file repos-github.txt find "$HOME/Documents/GitHub" -maxdepth 1 -mindepth 1 -type d
|
|
run_shell_to_file repos-outside-github.txt "find \"$HOME\" -maxdepth 3 -type d -name .git 2>/dev/null | sed 's#/.git\$##' | sort"
|
|
|
|
if command -v brew >/dev/null 2>&1; then
|
|
run_shell_to_file brew-bundle.txt "brew bundle dump --force --file=-"
|
|
run_shell_to_file brew-formulae.txt "brew list --formula"
|
|
run_shell_to_file brew-casks.txt "brew list --cask"
|
|
run_shell_to_file brew-leaves.txt "HOMEBREW_NO_AUTO_UPDATE=1 brew leaves | sort"
|
|
run_shell_to_file brew-services.txt "brew services list"
|
|
fi
|
|
|
|
if command -v npm >/dev/null 2>&1; then
|
|
run_shell_to_file npm-global.txt "npm ls -g --depth=0 2>/dev/null || true"
|
|
fi
|
|
|
|
if command -v pnpm >/dev/null 2>&1; then
|
|
run_shell_to_file pnpm-global.txt "pnpm ls -g --depth=0 2>/dev/null || true"
|
|
fi
|
|
|
|
if command -v pipx >/dev/null 2>&1; then
|
|
run_shell_to_file pipx.txt "pipx list 2>/dev/null || true"
|
|
fi
|
|
|
|
if command -v uv >/dev/null 2>&1; then
|
|
run_shell_to_file uv-tools.txt "uv tool list 2>/dev/null || true"
|
|
fi
|
|
|
|
if command -v cargo >/dev/null 2>&1; then
|
|
run_shell_to_file cargo-installs.txt "cargo install --list 2>/dev/null || true"
|
|
run_shell_to_file cargo-bin.txt "ls -1 \"$HOME/.cargo/bin\" 2>/dev/null | sort"
|
|
fi
|
|
|
|
if command -v go >/dev/null 2>&1; then
|
|
run_shell_to_file go-env.txt "go env"
|
|
run_shell_to_file go-bin.txt "ls -1 \"\$(go env GOPATH 2>/dev/null)/bin\" 2>/dev/null | sort"
|
|
fi
|
|
|
|
if command -v python3 >/dev/null 2>&1; then
|
|
run_shell_to_file python-user-packages.txt "python3 -m pip list --user --format=freeze 2>/dev/null || true"
|
|
fi
|
|
|
|
if command -v gem >/dev/null 2>&1; then
|
|
run_shell_to_file ruby-gems.txt "gem list 2>/dev/null || true"
|
|
fi
|
|
|
|
if command -v nix >/dev/null 2>&1; then
|
|
run_shell_to_file nix-profile.txt "nix --extra-experimental-features 'nix-command flakes' profile list 2>/dev/null || true"
|
|
fi
|
|
|
|
echo "Wrote snapshot to $out_dir"
|
|
|