macOS Pre OS Migration Script

Script still in draft designed to collect bookmarks and other pertinent information pre- migration, the thought was to perform this pre-migration and then construct a reversal of sorts to migrate this data back into the new machine – account. Full circle
Link: https://gist.github.com/patent-ed/b3c0f95f14815a581a78a51f4fb2f863.js

#!/bin/bash
# This Script-Project started off as a method of saving bookmarks ahead of a macOS computer migration; and evolved... 03/21/2022 06:50
name=$(/bin/date +"%Y-%m-%dT%H%M"."backup")
hostmac=$(hostname)
MacUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
# Kill Google Chrome
#kill `ps -A | grep -w Google\ Chrome.app | grep -v grep | awk '{print $1}'`
# Kill Safari
#kill `ps -A | grep -w Safari.app | grep -v grep | awk '{print $1}'`
# Kill Firefox
#kill `ps -A | grep -w Firefox.app | grep -v grep | awk '{print $1}'`
# Kill Microsoft Edge
#kill `ps -A | grep -w Microsoft\ Edge.app | grep -v grep | awk '{print $1}'`
# Create folder(s) & files
mkdir -p ~/Desktop/"$name"/Browser/SafariBookmarks
mkdir -p ~/Desktop/"$name"/Browser/ChromeBookmarks
mkdir -p ~/Desktop/"$name"/Browser/MSEdgeBookmarks
mkdir -p ~/Desktop/"$name"/Browser/FirefoxBookmarks
mkdir -p ~/Desktop/"$name"/Notes
mkdir -p ~/Desktop/"$name"/PrinterDrivers
mkdir -p ~/Desktop/"$name"/Stickies
mkdir -p ~/Desktop/"$name"/DockSettings
mkdir -p ~/Desktop/"$name"/History
mkdir -p ~/Desktop/"$name"/Importfile
mkdir -p ~/Desktop/"$name"/Importfile
touch ~/Desktop/"$name"/Importfile/"$hostmac"_"$name"_Imp.txt
# backup Safari bookmarks file to desktop
#sudo ditto -V ~/Library/Safari/Bookmarks.plist ~/Desktop/"$name"/Browser/SafariBookmarks/
rsync -a --prune-empty-dirs --include='*/' --include='*Bookmarks*' --exclude='*' ~/Library/Safari/ ~/Desktop/"$name"/Browser/SafariBookmarks/
sudo ditto -V ~/Library/Application\ Support/Google/Chrome/Default/Bookmarks.bak ~/Desktop/"$name"/Browser/ChromeBookmarks/
sudo ditto -V ~/Library/Application\ Support/Microsoft\ Edge/Default/Bookmarks ~/Desktop/"$name"/Browser/MSEdgeBookmarks/
# Handling FireFox bookmarks
#sudo ditto -V ~/Library/Application\ Support/Firefox/Profiles/ ~/Desktop/"$name"/Browser/FirefoxBookmarks/
#rsync -avh --include='*/' --include='*bookmark*' --exclude='*' ~/Library/Application\ Support/Firefox/Profiles/ ~/Desktop/"$name"/Browser/FirefoxBookmarks/
rsync -a --prune-empty-dirs --include='*/' --include='*bookmark*' --exclude='*' ~/Library/Application\ Support/Firefox/Profiles ~/Desktop/"$name"/Browser/FirefoxBookmarks
# Handling Notes
#rsync -a --prune-empty-dirs --include='*/' --include='*notes*' --exclude='*' ~/Library/Group Containers/ ~/Desktop/"$name"/Notes/
sudo ditto -V ~/Library/Group\ Containers/group.com.apple.notes/ ~/Desktop/"$name"/Notes/
# Handling Printer Drivers
rsync -a --prune-empty-dirs --include='*/' --include='*' ~/Library/Printers ~/Desktop/"$name"/PrinterDrivers/
rsync -a --prune-empty-dirs --include='*/' --include='*print*' --exclude='*' ~/Library/Preferences ~/Desktop/"$name"/PrinterPreferences/
# Handling Dock Preferences
sudo ditto -V ~/Library/Preferences/com.apple.dock.plist ~/Desktop/"$name"/DockSettings/
# stickies - > https://discussions.apple.com/thread/250728309
rsync -a --prune-empty-dirs --include='*/' --include='*Stickies*' --exclude='*' ~/Library/Containers ~/Desktop/"$name"/Stickies/
# Create Import File
#echo -E "Bin Bash hello World\0041\n~/Desktop/"."\$name"."/Browser/SafariBookmarks/" >> ~/Desktop/"$name"/Importfile/Importfile.txt
sudo echo -n "Bin Bash hello World\0041\n~/Desktop/$name" >> ~/Desktop/"$name"/Importfile/Importfile.txt
sudo echo -e "Bin Bash hello World\0041\n~/Desktop/$name" >> ~/Desktop/"$name"/Importfile/Importfile.txt
sudo echo -e "Bin Bash hello World\0041\n~/Desktop/$name" >> ~/Desktop/"$name"/Importfile/Importfile.txt
sudo echo -e "New line hello World\0041\n~/Desktop/$name" >> ~/Desktop/"$name"/Importfile/Importfile.txt
#echo -n $name >> ~/Desktop/"$name"/Importfile/Importfile.txt
# $name >> ~/Desktop/"$name"/Importfile/Importfile.txt
#echo -e "/Browser/SafariBookmarks/" >> ~/Desktop/"$name"/Importfile/Importfile.txt
# Pull Software history report
system_profiler SPInstallHistoryDataType >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_SoftReport.txt
# List Desktop items report
sudo ls -S -lh | awk '{print $5, $9}' >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_DesktopReport.txt
sudo echo -e "Full $MacUser Desktop Report" >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_DesktopReport.txt
sudo ls -lhS ~/Desktop >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_DesktopReport.txt
# List Printer Drivers report
sudo lpinfo -m >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_PrinterReport.txt
# List Volumes Report
sudo echo -e "$hostmac - $MacUser Domain Controllers " >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_Volumes.txt
netstat -a | grep ldap >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_Volumes.txt
sudo ls -al /Volumes >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_Volumes.txt
# System Report
sudo system_profiler SPSoftwareDataType SPHardwareDataType >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_SystemReport.txt
# THIS IS THE WHOLE APPLE SYSTEM REPORT PROFILER, TAKES TIME! TO RUN
#sudo system_profiler >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_FullReport.txt
# User report
dscl . list /Users UniqueID | grep -v '^_' >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_UserReport.txt
dscacheutil -q user | grep -A 3 -B 2 -e uid:\ 5'[0-9][0-9]' >> ~/Desktop/"$name"/History/"$hostmac"_"$name"_UserReport.txt
# Enter share
#echo "Hello, "$MacUser". This script will register your share in database."
#echo -n "Enter your share and press [ENTER]: "
#read share
#echo
#grep -i "$share"
exit 1

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *