Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ It is used to:
Run **from macOS Recovery only**:

1. Boot into macOS Recovery
2. Open **Utilities → Terminal**
2. Open **Utilities → Terminal** (or use ⌘⇧T)
3. Execute the script from a trusted source. The following command provides the shortest command for convenient typing in Recovery Terminal:
```sh
sh <(curl -s add2abm.inetum.zone)
Expand Down Expand Up @@ -112,7 +112,7 @@ The script operates in two modes:
2. Hold Touch ID/power button to boot into _Options_ (macOS Recovery)
3. Authenticate as volume owner
4. Connect to network (if not connected)
5. Open **Utilities → Terminal**
5. Open **Utilities → Terminal** (or use ⌘⇧T)
6. Execute the script to backup user records and reboot
7. Unlock disk upon boot, if encrypted
8. Proceed in Setup Assistant to _Country & Region_ step
Expand All @@ -122,7 +122,7 @@ The script operates in two modes:
12. Hold Touch ID/power button to boot into _Options_ (macOS Recovery) once again
13. Authenticate as volume owner
14. Connect to network (if not connected)
15. Open **Utilities → Terminal**
15. Open **Utilities → Terminal** (or use ⌘⇧T)
16. Execute the script again to restore user records from backup and reboot
17. Unlock disk upon boot, if encrypted
18. Agree to macOS _Terms and Conditions_
Expand All @@ -140,6 +140,19 @@ The script operates in two modes:

---

## Troubleshooting

If the script does not behave as expected, you can enable tracing to run it in a verbose mode for debugging:
```sh
sh -x <(curl -s add2abm.inetum.zone)
```
or if you’re hosting it yourself:
```sh
sh -x <(curl -s script_hosting_fqdn/add2abm.sh)
```

---

## Support

Before reporting issues, verify that:
Expand Down
21 changes: 11 additions & 10 deletions add2abm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ read -r ANSWER
case "${ANSWER}" in
[Yy]*)
unset ANSWER
echo
;;
*) exit 0 ;;
esac
Expand All @@ -46,36 +45,37 @@ DATA_VOLUME="Macintosh HD - Data"

! grep -q "${DATA_VOLUME}" <<<"$(diskutil list)" && DATA_VOLUME="Data"
if ! diskutil mount "${DATA_VOLUME}" &>/dev/null; then
printf '\nPlease, provide SecureToken–enabled user password or a FileVault Personal Recovery Key to unlock Data volume…'
printf '\nPlease, provide SecureToken–enabled user password or a FileVault Personal Recovery Key to unlock Data volume…\n'
diskutil apfs unlockVolume "${DATA_VOLUME}"
fi

if [[ ! -d "${USERS_PATH}" ]]; then
printf 'Data volume still locked or path does not exist. Terminating…'
printf 'Data volume still locked or path does not exist. Terminating…\n'
exit 1
fi

# RESTORE: —————————————————————————————————————————————————————————————————————————————————————————

# Check for any .bak files:
if ls "${USERS_PATH}"/*.bak &>/dev/null; then
printf '[*] Found .bak files. Restoring…'
printf '\n[*] Found .bak files. Restoring…\n'
for BACKUP_FILE in "${USERS_PATH}"/*.bak; do
[ -e "${BACKUP_FILE}" ] || continue
mv -v "${BACKUP_FILE}" "${BACKUP_FILE%.bak}.plist"
done

printf '\n[*] Restoring AppleSetupDone…'
printf '\n[*] Restoring AppleSetupDone…\n'
touch "${ASD_FILE}"
chmod 400 "${ASD_FILE}"

printf "\n[✓] Restore complete. Note that you’ll have to agree to Terms & Conditions again.\n"

printf 'Would you like to restart to macOS now? (y/n): '
printf '\nWould you like to restart to macOS now? (y/n): '
read -r ANSWER
case "${ANSWER}" in
[Yy]*)
printf 'Performing restart…'
sleep 0.5
reboot
;;
esac
Expand All @@ -86,7 +86,7 @@ fi
# BACKUP: ——————————————————————————————————————————————————————————————————————————————————————————

# No .bak files found — backup eligible .plist files:
printf "[*] No .bak files found. Backing up local users’ .plist files…"
printf "\n[*] No .bak files found. Backing up local users’ .plist files…\n"

for USER_FILE in "${USERS_PATH}"/*.plist; do
# Skip files starting with underscore:
Expand All @@ -100,22 +100,23 @@ for USER_FILE in "${USERS_PATH}"/*.plist; do

# Check if UID is greater than 500:
if ((USER_UID > 500)); then
printf 'Backing up "%s" (UID: %s)…' "$(basename "${USER_FILE%.plist}")" "${USER_UID}"
printf 'Backing up "%s" (UID: %s)…\n' "$(basename "${USER_FILE%.plist}")" "${USER_UID}"
mv -v "${USER_FILE}" "${USER_FILE%.plist}.bak"
# place your action here if needed
fi
done

printf '\n[*] Removing AppleSetupDone…'
printf '\n[*] Removing AppleSetupDone…\n'
rm -f "${ASD_FILE}"

printf '\n[✓] Backup complete. macOS Setup Assistant will now open upon drive unlock.\n'

printf 'Would you like to restart to macOS now? (y/n): '
printf '\nWould you like to restart to macOS now? (y/n): '
read -r ANSWER
case "${ANSWER}" in
[Yy]*)
printf 'Performing restart…'
sleep 0.5
reboot
;;
esac
Expand Down