Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NB-12742: Added PWM MacOS architecture detection, redirection to ARM download #600

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

oalobajijc
Copy link

@oalobajijc oalobajijc commented Sep 5, 2024

Issues

  • NB-12742 - Update PWM Installation script to support ARM builds

Dependencies

What does this solve?

It adds the ability for the script to download arm64 PWM builds directly instead of Intel based builds.

Is there anything particularly tricky?

No, just to note that when the dependency PR gets merged, we will be able to successfully test it on the prod cdn. (using the prod link)
This is how the prod link for MacOS ARM builds will look like:
https://cdn.pwm.jumpcloud.com/DA/release/arm64/JumpCloud-Password-Manager-latest.dmg
Staging link (just for reference):
https://cdn.pwm.stg01.jumpcloud.com/DA/staging/release/arm64/JumpCloud-Password-Manager-Staging-latest.dmg

How should this be tested?

Testing is done only on MacOS, no need for any other OS.
***NOTE: If you're to test on staging (before the release is merged & deployed) please check the end of the How should this be tested? block right after step 2.

  1. Make sure your device is arm64 architecture (you can run uname -m in your terminal, output should be arm64)
  2. Create a .sh file containing the following:
#!/bin/bash

# This script will install password manager in Users/$user/Applications for all user accounts based on their architecture (x64 or arm64)
DownloadUrl="https://cdn.pwm.jumpcloud.com/DA/release/JumpCloud-Password-Manager-latest.dmg"

# Detect device architecture
DeviceArchitecture=$(uname -m)


if [ "$DeviceArchitecture" = "arm64" ]; then
    DownloadUrl="https://cdn.pwm.jumpcloud.com/DA/release/arm64/JumpCloud-Password-Manager-latest.dmg"
fi


regex='^https.*.dmg$'
if [[ $DownloadUrl =~ $regex ]]; then
    echo "URL points to direct DMG download"
    validLink="True"
else
    echo "Searching headers for download links"
    urlHead=$(curl -s --head $DownloadUrl)

    locationSearch=$(echo "$urlHead" | grep https:)

    if [ -n "$locationSearch" ]; then

        locationRaw=$(echo "$locationSearch" | cut -d' ' -f2)

        locationFormatted="$(echo "${locationRaw}" | tr -d '[:space:]')"

        regex='^https.*'
        if [[ $locationFormatted =~ $regex ]]; then
            echo "Download link found"
            DownloadUrl=$(echo "$locationFormatted")
        else
            echo "No https location download link found in headers"
            exit 1
        fi

    else

        echo "No location download link found in headers"
        exit 1
    fi

fi



#Create Temp Folder
DATE=$(date '+%Y-%m-%d-%H-%M-%S')

TempFolder="Download-$DATE"

mkdir /tmp/$TempFolder

# Navigate to Temp Folder
cd /tmp/$TempFolder

# Download File into Temp Folder
curl -s -O "$DownloadUrl"

# Capture name of Download File
DownloadFile="$(ls)"

echo "Downloaded $DownloadFile to /tmp/$TempFolder"

# Verifies DMG File
regex='\.dmg$'
if [[ $DownloadFile =~ $regex ]]; then
    DMGFile="$(echo "$DownloadFile")"
    echo "DMG File Found: $DMGFile"
else
    echo "File: $DownloadFile is not a DMG"
    rm -r /tmp/$TempFolder
    echo "Deleted /tmp/$TempFolder"
    exit 1
fi

# Mount DMG File -nobrowse prevents the volume from popping up in Finder

hdiutilAttach=$(hdiutil attach /tmp/$TempFolder/$DMGFile -nobrowse)

echo "Used hdiutil to mount $DMGFile "

err=$?
if [ ${err} -ne 0 ]; then
    echo "Could not mount $DMGFile Error: ${err}"
    rm -r /tmp/$TempFolder
    echo "Deleted /tmp/$TempFolder"
    exit 1
fi

regex='\/Volumes\/.*'
if [[ $hdiutilAttach =~ $regex ]]; then
    DMGVolume="${BASH_REMATCH[@]}"
    echo "Located DMG Volume: $DMGVolume"
else
    echo "DMG Volume not found"
    rm -r /tmp/$TempFolder
    echo "Deleted /tmp/$TempFolder"
    exit 1
fi

# Identify the mount point for the DMG file
DMGMountPoint="$(hdiutil info | grep "$DMGVolume" | awk '{ print $1 }')"

echo "Located DMG Mount Point: $DMGMountPoint"

# Capture name of App file

cd "$DMGVolume"

AppName="$(ls | Grep .app)"

cd ~

echo "Located App: $AppName"


DMGAppPath=$(find "$DMGVolume" -name "*.app" -depth 1)

userInstall=false

for user in $(dscl . list /Users | grep -vE 'root|daemon|nobody|^_')
do
    if [[ -d /Users/$user ]]; then
        # Create ~/Applications folder
        if [[ ! -d /Users/$user/Applications ]]; then
            mkdir /Users/$user/Applications
        fi
        if [[ -d /Users/$user/Applications/JumpCloud\ Password\ Manager.app ]]; then
            # remove if exists
            rm -rf /Users/$user/Applications/JumpCloud\ Password\ Manager.app
        fi

        # Copy the contents of the DMG file to /Users/$user/Applications/
        # Preserves all file attributes and ACLs
        cp -pPR "$DMGAppPath" /Users/$user/Applications/

        # Change ownership of the file to the user of this loop iteration
        chown -v $user /Users/$user/Applications/JumpCloud\ Password\ Manager.app

        if [[ -d /Users/$user/Desktop/JumpCloud\ Password\ Manager.app ]]; then
            # remove alias on desktop if exists
            rm -rf /Users/$user/Desktop/JumpCloud\ Password\ Manager.app
        fi

        err=$?
        if [ ${err} -ne 0 ]; then
            echo "Could not copy $DMGAppPath Error: ${err}"
            hdiutil detach $DMGMountPoint
            echo "Used hdiutil to detach $DMGFile from $DMGMountPoint"
            rm -r /tmp/$TempFolder
            echo "Deleted /tmp/$TempFolder"
            exit 1
        fi

        userInstall=true
        echo "Copied $DMGAppPath to /Users/$user/Applications"

        # Create an alias on desktop
        ln -s /Users/$user/Applications/JumpCloud\ Password\ Manager.app /Users/$user/Desktop/JumpCloud\ Password\ Manager.app
    fi
done


# Check if password manager is installed in /Applications; remove if we installed in user directory
if [ -d /Applications/JumpCloud\ Password\ Manager.app ] && [ $userInstall = true ]; then
    # remove if exists
    rm -rf /Applications/JumpCloud\ Password\ Manager.app
fi

# Unmount the DMG file
hdiutil detach $DMGMountPoint

echo "Used hdiutil to detach $DMGFile from $DMGMountPoint"

err=$?
if [ ${err} -ne 0 ]; then
    abort "Could not detach DMG: $DMGMountPoint Error: ${err}"
fi

# Remove Temp Folder and download
rm -r /tmp/$TempFolder

echo "Deleted /tmp/$TempFolder"

exit
  1. IF you're testing with the staging link, after waiting for the app to download you'll notice a blank shortcut on your desktop. Ignore this as the script manually creates this based on the prod app name (theyre different, its a blank shortcut, this wont happen using the prod link)
  2. Go to ~/Applications/
  3. You should see JumpCloud Password Manager if you're using the prod link, JC Password Manager Staging if you're using staging
  4. Right click on the app -> Get info -> You should see Apple Silicon as the app type (Screenshot attached)

If you're testing on staging, you should modify the following in the .sh file:

if [ "$DeviceArchitecture" = "arm64" ]; then
    DownloadUrl="https://cdn.pwm.stg01.jumpcloud.com/DA/staging/release/arm64/JumpCloud-Password-Manager-Staging-latest.dmg"
fi

Screenshots

image

@oalobajijc oalobajijc self-assigned this Sep 5, 2024
@oalobajijc oalobajijc changed the title NB-12742: Added device architecture detection, redirection to ARM download NB-12742: Added PWM device architecture detection, redirection to ARM download Sep 5, 2024
@oalobajijc oalobajijc changed the title NB-12742: Added PWM device architecture detection, redirection to ARM download NB-12742: Added PWM MacOS architecture detection, redirection to ARM download Sep 5, 2024
@oalobajijc oalobajijc marked this pull request as ready for review September 23, 2024 09:50
@oalobajijc oalobajijc requested a review from a team as a code owner September 23, 2024 09:50
Copy link
Contributor

@kmaranionjc kmaranionjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests looks good to me. Thanks for the change.
image

@jworkmanjc
Copy link
Contributor

@oalobajijc feel free to merge, I'm sorry this went so long without us looking at it.

@oalobajijc
Copy link
Author

oalobajijc commented Oct 1, 2024

@oalobajijc feel free to merge, I'm sorry this went so long without us looking at it.

@jworkmanjc No worries! Thanks for the approval. I won't be merging this now, as we discovered & are investigating an issue related to ARM builds unrelated to this script. I'll merge when it's fixed
Should I keep this PR as open or mark it as a draft?

@jworkmanjc
Copy link
Contributor

@oalobajijc feel free to merge, I'm sorry this went so long without us looking at it.

@jworkmanjc No worries! Thanks for the approval. I won't be merging this now, as we discovered & are investigating an issue related to ARM builds unrelated to this script. I'll merge when it's fixed Should I keep this PR as open or mark it as a draft?

Feel free to just leave it open, doesn't matter to me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants