#!/bin/bash # set -x # erase-install # by Graham Pugh. # # WARNING. This is a self-destruct script. Do not try it out on your own device! # # This script downloads and runs installinstallmacos.py from Greg Neagle, # which expects you to choose a value corresponding to the version of macOS you wish to download. # This script automatically fills in that value so that it can be run remotely. # # See README.md for details on use. # # Requirements: # macOS 10.13.4+ is already installed on the device (for eraseinstall option) # Device file system is APFS # shellcheck disable=SC2034 # this is due to the dynamic variable assignments used in the localization strings # shellcheck disable=SC2001 # this is to use sed in the case statements # script name script_name="erase-install" # Version: version="0.21.0" # all output is written also to a log file LOG_FILE=/var/log/erase-install.log exec > >(tee ${LOG_FILE}) 2>&1 # URL for downloading installinstallmacos.py installinstallmacos_url="https://raw.githubusercontent.com/grahampugh/macadmin-scripts/master/installinstallmacos.py" # Directory in which to place the macOS installer. Overridden with --path installer_directory="/Applications" # Temporary working directory workdir="/Library/Management/erase-install" # place any extra packages that should be installed as part of the erase-install into this folder. The script will find them and install. # https://derflounder.wordpress.com/2017/09/26/using-the-macos-high-sierra-os-installers-startosinstall-tool-to-install-additional-packages-as-post-upgrade-tasks/ extras_directory="$workdir/extras" # Dialog helper apps jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" DEP_NOTIFY_APP="/Applications/Utilities/DEPNotify.app" DEP_NOTIFY_LOG="/var/tmp/depnotify.log" DEP_NOTIFY_CONFIRMATION_FILE="/var/tmp/com.depnotify.provisioning.done" # Dialogue localizations - download window dialog_dl_title_en="Downloading macOS" dialog_dl_title_de="Download macOS" dialog_dl_title_nl="Downloaden macOS" dialog_dl_title_fr="Téléchargement de macOS" dialog_dl_desc_en="We need to download the macOS installer to your computer; this will take several minutes." dialog_dl_desc_de="Der macOS Installer wird heruntergeladen, dies dauert mehrere Minuten." dialog_dl_desc_nl="We moeten het macOS besturingssysteem downloaden, dit duurt enkele minuten." dialog_dl_desc_fr="Nous devons télécharger le programme d'installation de macOS sur votre ordinateur, cela prendra plusieurs minutes." # Dialogue localizations - erase lockscreen dialog_erase_title_en="Erasing macOS" dialog_erase_title_de="macOS Wiederherstellen" dialog_erase_title_nl="macOS Herinstalleren" dialog_erase_title_fr="Effacement de macOS" dialog_erase_desc_en="Preparing the installer may take up to 30 minutes. Once completed your computer will reboot and continue the reinstallation." dialog_erase_desc_de="Das Vorbereiten des Installationsprogramms kann bis zu 30 Minuten dauern. Nach Abschluss wird Ihr Computer neu gestartet und die Neuinstallation fortgesetzt." dialog_erase_desc_nl="Het voorbereiden van het installatieprogramma kan tot 30 minuten duren. Zodra het proces is voltooid, wordt uw computer opnieuw opgestart en wordt de herinstallatie voortgezet." dialog_erase_desc_fr="La préparation de l'installation peut prendre jusqu'à 30 minutes. Une fois terminée, votre ordinateur redémarrera et poursuivra la réinstallation." # Dialogue localizations - reinstall lockscreen dialog_reinstall_title_en="Upgrading macOS" dialog_reinstall_title_de="Upgrading macOS" dialog_reinstall_title_nl="macOS upgraden" dialog_reinstall_title_fr="Mise à niveau de macOS" dialog_reinstall_status_en="Preparing macOS for reinstallation" dialog_reinstall_status_de="Vorbereiten von macOS für die Neuinstallation" dialog_reinstall_status_nl="MacOS voorbereiden voor herinstallatie" dialog_reinstall_status_fr="Préparation de macOS pour la réinstallation" dialog_reinstall_heading_en="Please wait as we prepare your computer for upgrading macOS." dialog_reinstall_heading_de="Bitte warten, das Upgrade macOS wird ausgeführt." dialog_reinstall_heading_nl="Even geduld terwijl we uw computer voorbereiden voor de upgrade van macOS." dialog_reinstall_heading_fr="Veuillez patienter pendant que nous préparons votre ordinateur pour la mise à niveau de macOS." dialog_reinstall_desc_en="This process may take up to 30 minutes. Once completed your computer will reboot and begin the upgrade." dialog_reinstall_desc_de="Dieser Prozess benötigt bis zu 30 Minuten. Der Mac startet anschliessend neu und beginnt mit dem Update." dialog_reinstall_desc_nl="Dit proces duurt ongeveer 30 minuten. Zodra dit is voltooid, wordt uw computer opnieuw opgestart en begint de upgrade." dialog_reinstall_desc_fr="Ce processus peut prendre jusqu'à 30 minutes. Une fois terminé, votre ordinateur redémarrera et commencera la mise à niveau." # Dialogue localizations - confirmation window dialog_confirmation_title_en="Erasing macOS" dialog_confirmation_title_de="macOS wiederherstellen" dialog_confirmation_title_nl="macOS wissen" dialog_confirmation_title_fr="Effacement de macOS" dialog_confirmation_desc_en="Please confirm that you want to ERASE ALL DATA FROM THIS DEVICE and reinstall macOS" dialog_confirmation_desc_de="Bitte bestätigen, dass Sie ALLE DATEN VON DIESEM GERÄT LÖSCHEN und macOS neu installieren wollen" dialog_confirmation_desc_nl="Weet je zeker dat je ALLE GEGEVENS VAN DIT APPARAAT WILT WISSEN en macOS opnieuw installeert?" dialog_confirmation_desc_fr="Veuillez confirmer que vous souhaitez EFFACER TOUTES LES DONNÉES DE CET APPAREIL et réinstaller macOS" dialog_confirmation_status_en="Press Cmd + Ctrl + C to Cancel" dialog_confirmation_status_de="Drücken Sie Cmd + Ctrl + C zum Abbrechen" dialog_confirmation_status_nl="Druk op Cmd + Ctrl + C om te Annuleren" dialog_confirmation_status_fr="Appuyez sur Cmd + Ctrl + C pour annuler" # Dialogue buttons dialog_confirmation_button_en="Confirm" dialog_confirmation_button_de="Bestätigen" dialog_confirmation_button_nl="Ja" dialog_confirmation_button_fr="Confirmer" dialog_cancel_button_en="Stop" dialog_cancel_button_de="Abbrechen" dialog_cancel_button_nl="Annuleren" dialog_cancel_button_fr="Annuler" dialog_enter_button_en="Enter" dialog_enter_button_de="Eingeben" dialog_enter_button_nl="Enter" dialog_enter_button_fr="Entrer" # Dialogue localizations - free space check dialog_check_desc_en="The macOS upgrade cannot be installed as there is not enough space left on the drive." dialog_check_desc_de="Das macOS-Upgrade kann nicht installiert werden, da nicht genügend Speicherplatz auf dem Laufwerk vorhanden ist." dialog_check_desc_nl="De macOS-upgrade kan niet worden geïnstalleerd op een computer met minder dan 45 GB schijfruimte." dialog_check_desc_fr="La mise à niveau de macOS ne peut pas être installée car il n'y a pas assez d'espace disponible sur ce volume." # Dialogue localizations - power check dialog_power_title_en="Waiting for AC Power Connection" dialog_power_title_de="Warten auf AC-Netzteil" dialog_power_title_nl="Wachten op Stroomadapter" dialog_power_title_fr="En attente de l'alimentation secteur" dialog_power_desc_en="Please connect your computer to power using an AC power adapter. This process will continue once AC power is detected." dialog_power_desc_de="Bitte schließen Sie Ihren Computer mit einem AC-Netzteil an das Stromnetz an. Dieser Prozess wird fortgesetzt, sobald die AC-Stromversorgung erkannt wird." dialog_power_desc_nl="Sluit uw computer aan met de stroomadapter. Zodra deze is gedetecteerd gaat het proces verder" dialog_power_desc_fr="Veuillez connecter votre ordinateur à un adaptateur secteur. Ce processus se poursuivra une fois que l'alimentation secteur sera détectée." # Dialogue localizations - ask for short name dialog_short_name_en="Please enter an account name to start the reinstallation process" dialog_short_name_de="Bitte geben Sie einen Kontonamen ein, um die Neuinstallation zu starten" dialog_short_name_nl="Voer een accountnaam in om het installatieproces te starten" dialog_short_name_fr="Veuillez entrer un nom de compte pour démarrer le processus de réinstallation" # Dialogue localizations - ask for password dialog_not_volume_owner_en="account is not a Volume Owner! Please login using one of the following accounts and try again" dialog_not_volume_owner_de="Konto ist kein Volume-Besitzer! Bitte melden Sie sich mit einem der folgenden Konten an und versuchen Sie es erneut" dialog_not_volume_owner_nl="Account is geen volume-eigenaar! Log in met een van de volgende accounts en probeer het opnieuw" dialog_not_volume_owner_fr="le compte n'est pas propriétaire du volume ! Veuillez vous connecter en utilisant l'un des comptes suivants et réessayer" # Dialogue localizations - invalid user dialog_invalid_user_en="This account cannot be used to to perform the reinstall" dialog_invalid_user_de="Dieses Konto kann nicht zur Durchführung der Neuinstallation verwendet werden" dialog_invalid_user_nl="Dit account kan niet worden gebruikt om de herinstallatie uit te voeren" dialog_invalid_user_fr="Ce compte ne peut pas être utilisé pour effectuer la réinstallation" # Dialogue localizations - invalid password dialog_invalid_password_en="ERROR: The password entered is NOT the login password for" dialog_invalid_password_de="ERROR: Das eingegebene Kennwort ist NICHT das Anmeldekennwort für" dialog_invalid_password_nl="FOUT: Het ingevoerde wachtwoord is NIET het inlogwachtwoord voor" dialog_invalid_password_fr="ERREUR : Le mot de passe entré n'est PAS le mot de passe de connexion pour" # Dialogue localizations - not a volume owner dialog_get_password_en="Please enter the password for the account" dialog_get_password_de="Bitte geben Sie das Passwort für das Konto ein" dialog_get_password_nl="Voer het wachtwoord voor het account in" dialog_get_password_fr="Veuillez saisir le mot de passe du compte" # icon for download window dialog_dl_icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/SidebarDownloadsFolder.icns" # icon for confirmation dialog dialog_confirmation_icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns" # Grab currently logged in user to set the language for Dialogue messages current_user=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk -F': ' '/[[:space:]]+Name[[:space:]]:/ { if ( $2 != "loginwindow" ) { print $2 }}') language=$(/usr/libexec/PlistBuddy -c 'print AppleLanguages:0' "/Users/${current_user}/Library/Preferences/.GlobalPreferences.plist") if [[ $language = de* ]]; then user_language="de" elif [[ $language = nl* ]]; then user_language="nl" elif [[ $language = fr* ]]; then user_language="fr" else user_language="en" fi # set localisation variables dialog_dl_title=dialog_dl_title_${user_language} dialog_dl_desc=dialog_dl_desc_${user_language} dialog_erase_title=dialog_erase_title_${user_language} dialog_erase_desc=dialog_erase_desc_${user_language} dialog_reinstall_title=dialog_reinstall_title_${user_language} dialog_reinstall_heading=dialog_reinstall_heading_${user_language} dialog_reinstall_desc=dialog_reinstall_desc_${user_language} dialog_reinstall_status=dialog_reinstall_status_${user_language} dialog_confirmation_title=dialog_confirmation_title_${user_language} dialog_confirmation_desc=dialog_confirmation_desc_${user_language} dialog_confirmation_status=dialog_confirmation_status_${user_language} dialog_confirmation_button=dialog_confirmation_button_${user_language} dialog_cancel_button=dialog_cancel_button_${user_language} dialog_enter_button=dialog_enter_button_${user_language} dialog_check_desc=dialog_check_desc_${user_language} dialog_power_desc=dialog_power_desc_${user_language} dialog_power_title=dialog_power_title_${user_language} dialog_short_name=dialog_short_name_${user_language} dialog_invalid_user=dialog_invalid_user_${user_language} dialog_get_password=dialog_get_password_${user_language} dialog_invalid_password=dialog_invalid_password_${user_language} dialog_not_volume_owner=dialog_not_volume_owner_${user_language} kill_process() { process="$1" if /usr/bin/pgrep -a "$process" >/dev/null ; then /usr/bin/pkill -a "$process" && echo " [$script_name] '$process' ended" || \ echo " [$script_name] '$process' could not be killed" fi } dep_notify() { # configuration taken from https://github.com/jamf/DEPNotify-Starter DEP_NOTIFY_CONFIG_PLIST="/Users/$current_user/Library/Preferences/menu.nomad.DEPNotify.plist" # /usr/bin/defaults write "$DEP_NOTIFY_CONFIG_PLIST" pathToPlistFile "$DEP_NOTIFY_USER_INPUT_PLIST" STATUS_TEXT_ALIGN="center" /usr/bin/defaults write "$DEP_NOTIFY_CONFIG_PLIST" statusTextAlignment "$STATUS_TEXT_ALIGN" chown "$current_user":staff "$DEP_NOTIFY_CONFIG_PLIST" # Configure the window's look echo "Command: Image: $dn_icon" >> "$DEP_NOTIFY_LOG" echo "Command: MainTitle: $dn_title" >> "$DEP_NOTIFY_LOG" echo "Command: MainText: $dn_desc" >> "$DEP_NOTIFY_LOG" if [[ $dn_button ]]; then echo "Command: ContinueButton: $dn_button" >> "$DEP_NOTIFY_LOG" fi if ! pgrep DEPNotify ; then # Opening the app after initial configuration if [[ "$window_type" == "fs" ]]; then sudo -u "$current_user" open -a "$DEP_NOTIFY_APP" --args -path "$DEP_NOTIFY_LOG" -fullScreen else sudo -u "$current_user" open -a "$DEP_NOTIFY_APP" --args -path "$DEP_NOTIFY_LOG" fi fi # set message below progress bar echo "Status: $dn_status" >> "$DEP_NOTIFY_LOG" # set alternaitve quit key (default is X) if [[ $dn_quit_key ]]; then echo "Command: QuitKey: $dn_quit_key" >> "$DEP_NOTIFY_LOG" fi } dep_notify_quit() { # quit DEP Notify echo "Command: Quit" >> "$DEP_NOTIFY_LOG" # reset all the settings that might be used again rm "$DEP_NOTIFY_LOG" "$DEP_NOTIFY_CONFIRMATION_FILE" 2>/dev/null dn_button="" dn_quit_key="" dn_cancel="" } ask_for_shortname() { # required for Silicon Macs /usr/bin/osascript <