Advertisement
themacdweeb

Nike Thin Imaging Client for Macs

Nov 1st, 2016 (edited)
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 24.74 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # NikeThinProvisioningHelper.sh - copyright© 2016, david koff
  4. # No portion of this script can be used without also pasting this entire header.
  5. #
  6. # SYNOPSIS
  7. #   script executes the retail thin-imaging process
  8. #
  9. # DESCRIPTION
  10. #   This script profides a series of checks and actions for new client enrollment.
  11. #
  12. # CREDITS & THANKS
  13. #   Borrows some kick-ass concepts, ideas and code from the über talented Jeff Grisso, Daniel Chapa & Mark Stratman.
  14. #   https://github.com/mstratman/cocoadialog
  15. #
  16. # CHANGE LOG
  17. #   Date        Version     Description
  18. #--------------------------------------------------------------------------------------------------
  19. # 01/20/2016    1.0     -   Created First Retail build with retail JSS API.
  20. # 02/15/2016            -   Fixed JAMF curl download errors, initial recon and some flow logic.
  21. # 02/18/2016    1.1     -   Fixed secureExit and JAMF binary install bugs.
  22. # 02/24/2016    1.1.2   -   Added flushPolicyHistory & Bomgar install, fixed syntax/order with stopJamfHelper.
  23. # 02/18/2016    1.1.3   -   Removed verbose policy logs once Casper is installed.
  24. # 04/06/2016    1.1.4   -   Added asking for the type of experience and floor number for location.
  25. # 04/07/2016    1.1.5   -   Added escape routine with visual feedback to secure exit sub-routine.
  26. # 04/10/2016    2.0     -   New, unified custom trigger for imaging process.
  27. # 04/21/2016    2.1     -   Fixed final touch file; removed old experience codes; added pre-flight user check.
  28. # 04/25/2016    2.2     -   Added new computer name confirm message, fixed progress bar status.
  29. # 04/29/2016    2.3     -   Added naming convention fork for breakroom iMacs.
  30. # 04/29/2016    2.4     -   Changed fullscreen jamfHelper notifications to update during the imaging process.
  31. # 05/03/2016    2.5     -   Changed log to use simple name and to pause for full Bomgar install.
  32. # 05/04/2016    2.6     -   Created GUI alerts for each error to educate end-user.
  33. # 06/04/2016    2.7     -   Removed certain choices from dropdown menus. Added country codes.
  34. # 07/28/2016    3.0     -   Major rev which includes:
  35. #                               * Added country codes for emerging markets
  36. #                               * Changed CocoaDialogue pop-up error window functionality
  37. #                               * Fixed code to isolate CocoaDialogue button presses
  38. #                               * Included initial error code/description
  39. #                               * Deleted migrationStatus function as we'll want to thin-image regardless
  40. #                               * Changed progress bar to only start once Bomgar/JAMF install begins
  41. #                               * Dropped NikeTools icon into Resources folder for use in CocoaDialogue
  42. #                               * Changed code to isolate if an ethernet cable is plugged in to any port
  43. # 07/28/2016    3.1     -   Changes include:
  44. #                               * altered ethernet test response to "baseT" as 10.11.6 changed response verbiage
  45. #                               * REVERTED store number request to accept either 5 or 6 digit entry
  46. #                               * set autoproxy discovery to DISABLE
  47. # 09/16/2016    3.2     -   syntax checked with "shellcheck" and corrected where indicated to avoid deprecated syntax.
  48. # 10/18/2016    3.3     -   Changes include:
  49. #                               * updated for use MacOS Sierra
  50. #                               * updated list of included countries in dropdown menu and fixed mis-spellings
  51. #                               * fixed syntax error for power source check
  52. #                               * improved verbiage when prompting for computer/experience number
  53. #                               * changed to a green checkmark icon for the final dialogue, when imaging is successful
  54. #                               * force users to select a country & experience from dropdown menu
  55. # 10/26/2016    3.4     -   Changes include:
  56. #                               * reverting to standard naming convention
  57. #                               * convention is: RTGEOStoreNumberExperienceNameExperienceNumber or "RTUS000368ID001"
  58.  
  59. ####################################################################################################
  60. set -u      ### Set Verbose error check during execution
  61. ####################################################################################################
  62. ### Set Variables
  63. ####################################################################################################
  64. oldifs="$IFS"   #Internal Field Separator
  65. counter=0
  66. password="nike"
  67. jamf="/usr/local/bin/jamf"
  68. osVer="$(sw_vers -productVersion)"
  69. Bomgar="$(sudo launchctl list | grep bomgar <<< "${password}")"
  70. NikeUserPresent="$(dscl . -list /Users | grep nike)"
  71. NikeUserAdmin="$(dscl . -read /Groups/admin | grep nike)"
  72. userCheck="$(ls /Users | wc -l | awk '{ print $1 }')"
  73.  
  74. # Application recource folder
  75. AppDir="$(dirname "$0")"
  76. CD="${AppDir}/../Resources/cocoaDialog.app/Contents/MacOS/cocoaDialog"
  77. icon="${AppDir}/../Resources/success.png"
  78.  
  79. # Quick Add locations
  80. quickAddDir="/tmp"
  81. quickAdd="${quickAddDir}/QuickAdd"
  82.  
  83. # Initial Error Codes
  84. ErrorCode="THIN IMAGING ABORTED"
  85. ErrorExplain="The thin-imaging process has been halted on this Mac."
  86.  
  87. ####################################################################################################
  88. ### Initial Cleanup
  89. ####################################################################################################
  90. sudo -S rm -fv /var/NikeRetail.* <<< "${password}"
  91. sudo -S rm -fv /var/touch.txt <<< "${password}"
  92. sudo -S rm -drv /Library/Logs/Nike/ <<< "${password}"
  93. sudo -S rm -Rvf "${quickAdd}".* <<< "${password}"
  94. sudo -S rm -Rf /tmp/cookie.txt
  95.  
  96. ####################################################################################################
  97. ### Script logging
  98. ####################################################################################################
  99. appName="NikeRetail-ThinImaging.InstallBase"
  100. appVer="3.4"
  101. appAuthor="David Koff"
  102. appDepartment="Nike Retail Mobility"
  103. appDate="01/20/2016"
  104. appUpDate="10/26/2016"
  105.  
  106. sudo -S mkdir /Library/Logs/Nike <<< "${password}"
  107. logFile="/Library/Logs/Nike/${appName}.log"
  108. sudo -S touch $logFile <<< "${password}"
  109. sudo -S chmod 777 $logFile <<< "${password}"
  110. exec >> $logFile 2>&1
  111.  
  112. ####################################################################################################
  113. #Functions
  114. ####################################################################################################
  115. appLog() {
  116.     time="$(date +%H:%M:%S)"
  117.     printf "${time}: ${1}"
  118. }
  119.  
  120. assetTagPrompt() {
  121.     stopProgressBar
  122.     AssetInput=$($CD inputbox \
  123.     --string-output \
  124.     --title "Enter the Asset Tag" \
  125.     --informative-text "The Nike asset tag barcode sticker can be found on the back or bottom of this computer. It starts with the letter 'N'. Please enter the tag number." \
  126.     --button1 "OK" | awk 'NR==2{print}')
  127.    
  128.     ## Convert assetTag to uppercase
  129.     assetTag=$(tr '[:lower:]' '[:upper:]' <<< "${AssetInput}")
  130.     appLog "The assetTag is set to ${assetTag}.\n"
  131.    
  132.     ## Confirm correct length
  133.     if [[ ${#assetTag} -ne "10" ]]; then appLog "Incorrect asset tag entered. Prompting user for re-entry.\n"
  134.         $CD msgbox --no-newline \
  135.         --text "Error: Incorrect Asset Tag Entered" \
  136.         --informative-text "You must enter a TEN-DIGIT number such as 'N000226379'. Please try again..." \
  137.         --button1 "OK" \
  138.         --icon "x"
  139.         assetTagPrompt
  140.     else
  141.         appLog "Asset Tag seems valid, continuing.\n"
  142.     fi
  143. }
  144.  
  145. confirmContinue() {
  146.     Continue=$($CD msgbox \
  147.         --no-newline \
  148.         --title "Nike Retail Thin-Imaging" \
  149.         --text "NIKE RETAIL IMAGING ALERT:" \
  150.         --informative-text "You are about to image a Macintosh for Nike Retail. The process takes 30-60min depending on your internet speed. If you are ready to continue, click OK. If not, click Cancel and this script will terminate." \
  151.         --float \
  152.         --icon-file $"{AppDir}"/../Resources/NikeTools.icns \
  153.         --button1 "OK" \
  154.         --button2 "Cancel" | awk 'NR==1{print}')
  155.    
  156.     ## Confirm Result
  157.     if [ "$Continue" = "2" ]; then appLog "The Cancel button has been pressed. Exiting script. \n"
  158.         secureExit
  159.         exit 1
  160.     else
  161.         appLog "The user has chosen to proceed. Continuing script. \n"
  162.     fi
  163. }
  164.  
  165. confirmMachineName() {
  166.     # Naming convention is now unified for all Macs with same syntax
  167.     ComputerName=RT$GEO$StoreNumb$EXP$ExpNumb
  168.  
  169.     MachineName=$($CD msgbox \
  170.     --no-newline \
  171.     --title "Confirm Computer Name" \
  172.     --text "Please note this Mac's new name:" \
  173.     --informative-text "$ComputerName \
  174.    
  175.    
  176. To begin thin-imaging, Click 'OK'. To cancel, click 'Cancel'." \
  177.     --float \
  178.     --icon-file "${AppDir}"/../Resources/NikeTools.icns \
  179.     --button1 "OK" \
  180.     --button2 "Cancel" | awk 'NR==1{print}')
  181.  
  182.     ## Confirm Result
  183.     if [ "$MachineName" = "2" ]; then appLog "The Cancel button has been pressed. Exiting script. \n"
  184.         secureExit
  185.         exit 1
  186.     else
  187.         appLog "The user has chosen to proceed. Continuing script. \n"
  188.     fi
  189. }
  190.  
  191. ctrl_c() {
  192.     printf "CTL+C was caught.\n"
  193.     ErrorCode="CTRL+C Pressed"
  194.     ErrorExplain="CTRL+C was pressed by tech. Script now ending."
  195.     secureExit
  196. }
  197.  
  198. logHead() {
  199.     printf -- "-------------------------------------------\n"
  200.     printf "Start: $(date)\n"
  201.     printf "Program name: ${appName}\n"
  202.     printf "ProgramVersion: ${appVer}\n"
  203.     printf "Author: ${appAuthor}\n"
  204.     printf "Development Department: ${appDepartment}\n"
  205.     printf "Program Creation Date: ${appDate}\n"
  206.     printf "Program Modification date: ${appUpDate}\n"
  207.     printf -- "-------------------------------------------\n"
  208. }
  209.  
  210. progressUpdate() {
  211.     echo "$1" >> /tmp/hpipe
  212. }
  213.  
  214. request_Country() {
  215.     stopProgressBar
  216.     Country=$($CD dropdown \
  217.     --title "Select a Country" \
  218.     --text "Select the country or region where this Mac will live." \
  219.     --items "Click Here to Select a Country" "ARGENTINA" "AUSTRALIA" "BRAZIL" "CANADA" "CHILE" "CHINA" "EMEA" "INDIA" "JAPAN" "KOREA" "MALAYSIA" "MEXICO" "NEW ZEALAND" "SINGAPORE" "SOUTH AFRICA" "SOUTH KOREA" "THAILAND" "URUGUAY" "USA" "OTHER" \
  220.     --button1 "Ok" --string-output --no-cancel --float | awk 'NR==2{print}')
  221.    
  222.     # force response, then based on it, create file for auto-detection
  223.     if [ "$Country" = "ARGENTINA" ]; then GEO="AR"
  224.     elif [ "$Country" = "AUSTRALIA" ]; then GEO="AU"
  225.     elif [ "$Country" = "BRAZIL" ]; then GEO="BR"
  226.     elif [ "$Country" = "CANADA" ]; then GEO="CA"
  227.     elif [ "$Country" = "CHILE" ]; then GEO="CL"
  228.     elif [ "$Country" = "CHINA" ]; then GEO="CN"
  229.     elif [ "$Country" = "EMEA" ]; then GEO="EM"
  230.     elif [ "$Country" = "INDIA" ]; then GEO="IN"
  231.     elif [ "$Country" = "JAPAN" ]; then GEO="JP"
  232.     elif [ "$Country" = "KOREA" ]; then GEO="KR"
  233.     elif [ "$Country" = "MALAYSIA" ]; then GEO="MY"
  234.     elif [ "$Country" = "MEXICO" ]; then GEO="MX"
  235.     elif [ "$Country" = "NEW ZEALAND" ]; then GEO="NZ"
  236.     elif [ "$Country" = "SINGAPORE" ]; then GEO="SG"
  237.     elif [ "$Country" = "SOUTH AFRICA" ]; then GEO="ZA"
  238.     elif [ "$Country" = "SOUTH KOREA" ]; then GEO="KR"
  239.     elif [ "$Country" = "THAILAND" ]; then GEO="TH"
  240.     elif [ "$Country" = "URUGUAY" ]; then GEO="UY"
  241.     elif [ "$Country" = "USA" ]; then GEO="US"
  242.     elif [ "$Country" = "OTHER" ]; then GEO="ZZ"
  243.     elif [ "$Country" = "Click Here to Select a Country" ]; then request_Country
  244.     fi
  245.  
  246.     sudo -S touch /var/NikeRetail.CountryCode."${GEO}" <<< "${password}"
  247.     appLog "The country is: $Country. An ID file was created at: /var/NikeRetail.CountryCode.${GEO} \n"
  248. }
  249.  
  250. request_Experience() {
  251.     stopProgressBar
  252.     Experience=$($CD dropdown \
  253.     --title "What Kind of Mac Is This?" \
  254.     --text "Choose the type of Mac you need." \
  255.     --items "Click Here to Select Type of Mac" "Breakroom iMac" "NikeID" "Athlete Macbook" "Caching Server" "Misc" \
  256.     --button1 "Ok" --string-output --no-cancel --float | awk 'NR==2{print}')
  257.    
  258.     # force response, then based on it, create file for auto-detection
  259.     if [ "$Experience" = "Breakroom iMac" ]; then EXP="BR"
  260.     elif [ "$Experience" = "NikeID" ]; then EXP="ID"
  261.     elif [ "$Experience" = "Athlete Macbook" ]; then EXP="AM"
  262.     elif [ "$Experience" = "Caching Server" ]; then EXP="CS"
  263.     elif [ "$Experience" = "Click Here to Select Type of Mac" ]; then request_Experience
  264.     fi
  265.    
  266.     sudo -S touch /var/NikeRetail.ExperienceCode."${EXP}" <<< "${password}"
  267.     appLog "This Mac will be set as: $Experience. An ID file was created at: /var/NikeRetail.ExperienceCode.${EXP} \n"
  268. }
  269.  
  270. request_ExperienceNumber() {
  271.     ExpNumb=$($CD inputbox \
  272.     --string-output \
  273.     --title "Enter the Experience Number" \
  274.     --informative-text "For the first Mac in a series, enter '001'. For the second, enter '002', etc.
  275.  
  276. Please enter a three-digit number now." \
  277.     --button1 "OK" | awk 'NR==2{print}')
  278.  
  279.     ## Confirm correct length
  280.     if [[ ${#ExpNumb} -ne "3" ]]; then appLog "Incorrect Mac number entered. Prompting user for re-entry.\n"
  281.         $CD msgbox --no-newline \
  282.         --text "Error: Incorrect Number Entered" \
  283.         --informative-text "You must enter a THREE-DIGIT number such as '001'. Please try again..." \
  284.         --button1 "OK" \
  285.         --icon "x"
  286.         request_ExperienceNumber
  287.     else
  288.         appLog "The experience number is: $ExpNumb. \n"
  289.     fi
  290. }
  291.  
  292. request_StoreNumber() {
  293.     stopProgressBar
  294.     # The inputbox call differs from the standard-input call by also providing a cancel button.
  295.     StoreNumb=$($CD inputbox \
  296.     --string-output \
  297.     --title "Enter the Store Number" \
  298.     --informative-text "Please enter a 5 or 6-DIGIT store number. For example: 00368" \
  299.     --button1 "Next" | awk 'NR==2')
  300.  
  301.     ## Confirm if store number is correct length
  302.     if [ ${#StoreNumb} -lt "5" ] || [ ${#StoreNumb} -gt "7" ]; then appLog "Incorrect store number entered. Prompting user for re-entry.\n"
  303.         $CD msgbox --no-newline \
  304.         --text "Error: Incorrect Store Number Entered" \
  305.         --informative-text "You must enter a FIVE or SIX-DIGIT number such as '00368'. Please try again..." \
  306.         --button1 "OK" \
  307.         --icon "x"
  308.         request_StoreNumber
  309.     else
  310.         appLog "The Nike Store number is: $StoreNumb. \n"
  311.     fi
  312. }
  313.  
  314. secureExit() {
  315.     stopProgressBar
  316.     if [ "$ErrorCode" = "THIN IMAGING COMPLETED" ]; then ## Show good news icon
  317.         $CD msgbox --no-newline \
  318.             --title "Imaging Complete" \
  319.             --text "$ErrorCode" \
  320.             --informative-text "$ErrorExplain" \
  321.             --float \
  322.             --icon-file "$icon" \
  323.             --button1 "OK"
  324.     else                                                ## Show bad news icon
  325.         $CD msgbox --no-newline \
  326.             --title "Now Quitting" \
  327.             --text "$ErrorCode" \
  328.             --informative-text "$ErrorExplain" \
  329.             --float \
  330.             --icon "x" \
  331.             --button1 "OK"
  332.     fi
  333.     rm -f /tmp/hpipe
  334.     rm /tmp/output.txt
  335.     rm -Rf /tmp/QuickAdd.pkg
  336.     rm -Rf /tmp/cookie.txt
  337.     [ "$oldifs" != "" ] && IFS=$oldifs
  338. }
  339.  
  340. setMachineName() {
  341.     echo ""
  342.     echo "### Set Mac Name..."
  343.     sudo -S scutil --set LocalHostName "$ComputerName" <<< "${password}"
  344.     sudo -S scutil --set HostName "$ComputerName" <<< "${password}"
  345.     sudo -S scutil --set ComputerName "$ComputerName" <<< "${password}"
  346.     appLog "HostName is: $(scutil --get HostName). \n"
  347.     appLog "LocalHostName is: $(scutil --get LocalHostName). \n"
  348.     appLog "ComputerName is: $(scutil --get ComputerName). \n"
  349. }
  350.  
  351. startJamfHelper() {
  352.     appLog "Executing jamfHelper \n"
  353.     "${AppDir}/../Resources/jamfHelper.app/Contents/MacOS/jamfHelper" -windowType fs -heading "Nike Retail Thin Imaging:" -alignHeading center -description 'Phase 1 - Base Installations: Now beginning.
  354. You will be updated as the process continues.' -icon "${AppDir}/../Resources/nikeswoosh.png" &
  355.     appLog "Done\n"
  356. }
  357.  
  358. startProgressBar() {
  359.     appLog "Starting Progress bar... "
  360.     rm -f /tmp/hpipe; sleep 1; mkfifo /tmp/hpipe
  361.     $CD progressbar \
  362.     --indeterminate \
  363.     --title "Nike Retail Thin Provisioning" \
  364.     --text "Performing pre-imaging checks. Please stand by..." < /tmp/hpipe &
  365.     exec 3<> /tmp/hpipe; echo -n . >&3
  366.     appLog "Done\n"
  367. }
  368.  
  369. stopProgressBar() {
  370.     appLog "Stopping Progress bar... "
  371.     exec 3>&-
  372.     appLog "Done\n"
  373. }
  374.  
  375. ####################################################################################################
  376. #Script
  377. ####################################################################################################
  378. ### trap ctrl-c and call ctrl_c()
  379. trap ctrl_c INT
  380.  
  381. ### Confirm user wishes to continue
  382. confirmContinue
  383.  
  384. ####### PRE-FLIGHT CHECKS BEGIN ##################
  385.  
  386. logHead
  387. startProgressBar
  388.  
  389. # check for and remove any previous JAMF clients
  390. if [ -f "$jamf" ]; then
  391.     echo "Previous install of jamf has been found. Now deleting..."
  392.     sudo -S jamf removeFramework <<< "${password}"
  393. fi
  394.  
  395. echo ""
  396. echo "### Look for unexpected users & if found prompt"
  397. progressUpdate "1 Checking for existing users..."
  398. if [[ "$userCheck" -gt "3" ]]; then
  399.     stopProgressBar
  400.     ErrorCode="Too Many User Accounts Found:"
  401.     ErrorExplain="RetailMyMac.app only works if the 'nike' user is the ONLY user account on this Mac.
  402.    
  403. Please restore this Mac to its 'out-of-box' state. On first boot, create a user account named 'nike' with the password 'nike'. Do not create any other user account. Then re-run RetailMyMac.app."
  404.     appLog "Error: Too Many User Accounts Found. Ending script & informing user. \n"
  405.     appLog "ls -la /Users \n"
  406.     secureExit
  407.     exit 0
  408. else
  409.     appLog "No Extra users were found in /Users. \n"
  410. fi
  411.  
  412. echo ""
  413. echo "### Confirm the Nike user account is present."
  414. progressUpdate "1 Confirm the Nike user account is present.."
  415. if [ "$NikeUserPresent" = "nike" ]; then
  416.     appLog "The Nike user account has been found. \n"
  417. else
  418.     stopProgressBar
  419.     ErrorCode="Nike User Account Not Found:"
  420.     ErrorExplain="Please create one administrative user account named 'nike' with the password 'nike'. Then re-run RetailMyMac.app."
  421.     appLog "Error: Nike user account was not found. Ending script & informing user. \n"
  422.     secureExit
  423.     exit 0
  424. fi
  425.  
  426. echo ""
  427. echo "### Confirm the Nike user account is administrative."
  428. progressUpdate "1 Confirm the Nike user account is administrative..."
  429. if [ ! -z "$NikeUserAdmin" ]; then
  430.     appLog "The Nike user account is confirmed as administrative. \n"
  431. else
  432.     stopProgressBar
  433.     ErrorCode="Nike User Account Not Administrative:"
  434.     ErrorExplain="Please ensure the 'nike' user account has been made administrative. Then re-run RetailMyMac.app."
  435.     appLog "Error: Nike user account is not administrative. Ending script & informing user. \n"
  436.     secureExit
  437.     exit 0
  438. fi
  439.  
  440. echo ""
  441. echo "### Confirm local credentials are nike:nike"
  442. progressUpdate "1 Checking local account credentials..."
  443. sudo -S touch /var/touch.txt <<< "nike"
  444. if [[ "$?" == "0" ]]; then
  445.     appLog "User account has been set up correctly with user name, password and admin rights. \n"
  446. else
  447.     stopProgressBar
  448.     ErrorCode="Nike user account password must be changed:"
  449.     ErrorExplain="The password for the Nike user account must be set to 'nike'. Please change the password from within System Preferences.
  450.    
  451. After appliying the change, restart the computer and re-launch RetailMyMac.app"
  452.     appLog "Error: Nike user account password must be changed. Ending script & informing user. \n"
  453.     open /System/Library/PreferencePanes/Accounts.prefPane
  454.     secureExit
  455.     exit 0
  456. fi
  457.  
  458. echo ""
  459. echo "### Disable Auto Proxy on all valid ports"
  460. progressUpdate "1 Disabling auto proxy on all ports..."
  461. appLog "Disabling AutoProxy Discovery on all ports AND Checking OS Level... \n"
  462. appLog "Force Mac to detect new hardware. \n"
  463. sudo -S networksetup -detectnewhardware <<< "${password}"
  464. appLog "Sleep 5 to allow detection to conclude... \n"
  465. sleep 5
  466. appLog "Start detection logic. \n"
  467.  
  468. if [[ "${osVer}" == 10.11* ]] || [[ "${osVer}" == 10.12* ]]; then
  469.     appLog "OS is ${osVer}. \n"
  470.     list="$(networksetup -listallnetworkservices | grep -v 'An asterisk')"
  471.     appLog "Hardware ports detected: \n"
  472.     appLog "$list \n"
  473.     appLog "DISABLE auto proxy discovery on detected ports. \n"
  474.     echo "$list" | while read lines
  475.     do
  476.         case "$lines" in
  477.             "Display Firewire"*)
  478.                 ;;
  479.             Firewire*)
  480.                 ;;
  481.             Bluetooth*)
  482.                 ;;
  483.             *)
  484.                 echo "$password" | sudo -S  networksetup -setproxyautodiscovery "$lines" off
  485.                 appLog "AutoProxy has been DISABLED for: $lines. \n"
  486.                 ;;
  487.         esac
  488.     done
  489. else
  490.     stopProgressBar
  491.     ErrorCode="Mac OS is not Current:"
  492.     ErrorExplain="The thin provisioning process is ONLY designed to work with Mac OS X 10.11 and newer. Please update your system to Mac OS X 10.11 then re-run RetailMyMac.app."
  493.     appLog "This version of the Mac OS -- $(sw_vers -productVersion) -- must be updated. Ending script & informing user. \n"
  494.     secureExit
  495.     exit 0
  496. fi
  497.  
  498. echo ""
  499. echo "### Check Ethernet Connection"
  500. progressUpdate "1 Checking network connection..."
  501. ethernetCheck="$(ifconfig -a | grep baseT)"
  502. if [[ -z $ethernetCheck ]]; then
  503.     stopProgressBar
  504.     ErrorCode="Ethernet not connected:"
  505.     ErrorExplain="An Ethernet cable is not plugged in. Please connect an Ethernet cable and then re-run this app."
  506.     appLog "FAILED ethernet check. Ending script & informing user. \n"
  507.     secureExit
  508.     exit 0
  509. else
  510.     appLog "CONFIRMED this Mac is using Ethernet. \n"
  511. fi
  512.  
  513. echo ""
  514. echo "### Check for AC Power"
  515. progressUpdate "1 Checking for AC power..."
  516. powerMode=`pmset -g ps | awk 'NR>1{exit};1' | awk '{print $4,$5}' | sed "s/'//g"`
  517. if [[ $powerMode == "AC Power" ]]; then
  518.     appLog "CONFIRMED on AC Power. \n"
  519. else
  520.     stopProgressBar
  521.     ErrorCode="Not Plugged into AC Power:"
  522.     ErrorExplain="Your system is not connected to AC power. Please attach an AC power cord and re-run RetailMyMac.app."
  523.     appLog "FAILED AC power check. Ending script & informing user. \n"
  524.     secureExit
  525.     exit 0
  526. fi
  527.  
  528. echo ""
  529. echo "### Check for Free HDD Space"
  530. progressUpdate "1 Checking for enough free storage space..."
  531. freeSpace="$(df -Hl | grep -A 1 "Mounted on" | grep -v "Avail" | awk '{print $4}' | sed '$s/.$//')"
  532. appLog "# of GB avail as freespace on HD is: $freeSpace. \n"
  533. if [[ "$freeSpace" -le "20" ]]; then
  534.     stopProgressBar
  535.     ErrorCode="Not Enough FreeSpace on Hard Drive:"
  536.     ErrorExplain="Your Boot Volume has less than 20GB free. Please free up some space and re-run RetailMyMac.app."
  537.     appLog "Boot volume has less than 20GB free. Ending script & informing user. \n"
  538.     secureExit
  539.     exit 0
  540. else
  541.     appLog "CONFIRMED: enough space to continue... \n"
  542. fi
  543.  
  544. ####### PRE-FLIGHT CHECKS DONE ##################
  545. progressUpdate "1 Checks done."
  546.  
  547. echo ""
  548. echo "### Adding touch file to indicate thin-imaging is beginning."
  549. appLog "Creating touchfile for revised thin provisioning process. \n"
  550. appLog "$password" | sudo -S mkdir /var/nike
  551. appLog "$password" | sudo -S touch /var/nike/.thinImageProcess_beginning
  552.  
  553. echo ""
  554. echo "### Querying for Computer Naming Info & Setting Final Name"
  555. request_Country
  556. request_Experience
  557. request_ExperienceNumber
  558. request_StoreNumber
  559. assetTagPrompt
  560. sleep 2
  561. confirmMachineName
  562. setMachineName
  563.  
  564. echo ""
  565. echo "### Downloading JAMF Client"
  566. startProgressBar
  567. progressUpdate "1 Installing Casper software. Please stand by..."
  568. appLog "Attempting download of quickadd.pkg. \n"
  569. curl -k https://cmext01.nike.com/quickadd/quickadd.pkg.zip -o "${quickAdd}.zip"
  570. unzip -t "${quickAdd}.zip" && unzip "${quickAdd}.zip" -d "${quickAddDir}"
  571. if [ ! -f "${quickAdd}.pkg" ]; then
  572.     echo "" && appLog "ERROR: CURL OF QUICKADD FAILED. TRYING SECOND LINK. \n"
  573.     curl -k https://cmint01.nike.com/quickadd/quickadd.pkg.zip -o "${quickAdd}.zip"
  574.     unzip -t "${quickAdd}.zip" && unzip "${quickAdd}.zip" -d "${quickAddDir}"
  575.     if [ ! -f "${quickAdd}.pkg" ]; then
  576.         stopProgressBar
  577.         ErrorCode="Can't Download The Casper Software:"
  578.         ErrorExplain="Your Mac isn't able to download the JAMF binary. Please contact your network administrator and report this error."
  579.         appLog "ERROR: UNABLE TO DOWNLOAD JAMF QUICKADD. Contact your administrator. \n"
  580.         secureExit
  581.         exit 0
  582.     fi
  583. fi
  584.  
  585. echo ""
  586. echo "### Installing JAMF Client"
  587. appLog "SUCCESS: DOWNLOAD OF QUICKADD FINISHED. NOW INSTALLING JAMF. \n"
  588. appLog "$password" | sudo -S installer -pkg "${quickAdd}.pkg" -allowUntrusted -target /
  589. appLog "The quickadd package has installed. See /var/log/install.log for details. \n"
  590.  
  591. echo ""
  592. echo "### Install Bomgar"
  593. progressUpdate "1 Downloading Bomgar Remote Software. Please stand by..."
  594. sudo -S $jamf policy -trigger installbomgar <<< "${password}"
  595. ### Wait for installation to complete
  596. while [ $counter -lt 10 ]; do
  597.     if [[ -z $Bomgar ]]; then
  598.         appLog "Installing Bomgar and waiting for Launch Agents to load... \n"
  599.         progressUpdate "1 Bomgar installation in progress, Please stand by..."
  600.         sleep 5
  601.         let counter=counter+1
  602.     else
  603.         appLog "SUCCESS: Bomgar has been installed. \n"
  604.         break
  605.     fi
  606. done
  607.  
  608. echo ""
  609. echo "### Starting JAMF Tasks"
  610. progressUpdate "1 starting lock screen."
  611. appLog "Starting Lock Screen. \n"
  612. stopProgressBar
  613. startJamfHelper
  614.  
  615. echo ""
  616. appLog "Executing initial recon to set the Asset Tag. \n"
  617. sudo -S $jamf recon -assetTag "${assetTag}" <<< "${password}" && sleep 2
  618.  
  619. echo ""
  620. appLog "Executing verbose jamf manage. \n"
  621. sudo -S $jamf manage <<< "${password}" && sleep 2
  622.  
  623. echo ""
  624. appLog "Executing verbose jamf recon again. \n"
  625. sudo -S $jamf recon <<< "${password}" && sleep 2
  626.  
  627. echo ""
  628. appLog "Flushing any previous jamf policies for this piece of hardware. \n"
  629. sudo -S $jamf flushPolicyHistory <<< "${password}"
  630.  
  631. echo ""
  632. echo "### Starting Thin Provisioning process...Please see JAMF log for process"
  633. sudo -S $jamf policy -trigger OSX-UpgradeScripts  <<< "${password}" &
  634.  
  635. appLog "+++++++++++++++++++++++++++++++++++++++++++ \n"
  636. appLog "script has completed: ${appName}. \n"
  637. ErrorCode="THIN IMAGING COMPLETED"
  638. ErrorExplain="The thin-imaging process has completed on this Mac. The computer will restart itself in approximately two minutes."
  639. secureExit
  640. appLog "+++++++++++++++++++++++++++++++++++++++++++"
  641.  
  642. #catch-all exit
  643. appLog "ERROR: catch-all exit was reached! \n"
  644. exit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement