Created
December 12, 2024 00:49
-
-
Save nshores/f2f82b3bc50ccd40367d86ad21b51303 to your computer and use it in GitHub Desktop.
homebrew_backup_and_restore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Directory containing cellar packages | |
cellar_dir="/Volumes/.timemachine/ED216C5A-CEF7-48C8-9196-BAC050C0B070/2024-11-30-192221.backup/2024-11-30-192221.backup/Data/opt/homebrew/Cellar/" | |
# Initialize a variable to hold the list of packages | |
package_list="" | |
# Loop through each subdirectory in the directory | |
for dir in "$cellar_dir"*/*; do | |
#echo "Checking $dir" | |
if [ -d "$dir" ]; then | |
json_file="$dir/INSTALL_RECEIPT.json" | |
if [ -f "$json_file" ]; then | |
# Check if "installed_as_dependency" is false | |
installed_as_dependency=$(jq '.installed_as_dependency' "$json_file") | |
if [ "$installed_as_dependency" = false ]; then | |
package_name=$(basename "$(dirname "$dir")") | |
echo "Package: $package_name" | |
# Append the package name to the list | |
package_list+="$package_name\n" | |
fi | |
fi | |
fi | |
done | |
# Output the list of packages | |
echo -e "$package_list" > "$HOME/reinstall_packages.txt" | |
echo "Package list saved to reinstall_packages.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment