-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7415 from jandubois/sudo-prompt
Create "Rancher Desktop.app" for the sudo-prompt script on macOS
- Loading branch information
Showing
11 changed files
with
200 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import path from 'path'; | ||
|
||
import { AlpineLimaISOVersion, Dependency, DownloadContext } from 'scripts/lib/dependencies'; | ||
import { simpleSpawn } from 'scripts/simple_process'; | ||
|
||
/** | ||
* SudoPrompt represents the sudo-prompt.app applet used by sudo-prompt on macOS. | ||
*/ | ||
export class SudoPrompt implements Dependency { | ||
name = 'sudo-prompt'; | ||
|
||
async download(_: DownloadContext): Promise<void> { | ||
// Rather than actually downloading anything, this builds the source code. | ||
const sourceDir = path.join(process.cwd(), 'src', 'sudo-prompt'); | ||
|
||
console.log(`Building sudo-prompt applet`); | ||
await simpleSpawn('./build-sudo-prompt', [], { cwd: sourceDir }); | ||
} | ||
|
||
getAvailableVersions(_includePrerelease?: boolean | undefined): Promise<string[]> { | ||
throw new Error('sudo-prompt dependencies do not have available versions.'); | ||
} | ||
|
||
rcompareVersions(_version1: string | AlpineLimaISOVersion, _version2: string): 0 | 1 | -1 { | ||
throw new Error('sudo-prompt dependencies do not have available versions.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# shellcheck disable=SC2164 # Use 'cd ... || exit' or 'cd ... || return' in case cd fails. | ||
REPO=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.."; pwd) | ||
|
||
# The APP name must be "Rancher Desktop.app" because this name is used in the dialog as | ||
# "Rancher Desktop wants to make changes." | ||
RESOURCES="${REPO}/resources" | ||
APP="${RESOURCES}/darwin/internal/Rancher Desktop.app" | ||
CONTENTS="${APP}/Contents" | ||
|
||
rm -rf "$APP" | ||
mkdir -p "$(dirname "$APP")" | ||
osacompile -o "$APP" sudo-prompt.applescript | ||
|
||
# Don't put the script into ${CONTENTS}/MacOS/ because that breaks signing the applet | ||
cp sudo-prompt-script "${CONTENTS}/Resources/Scripts/" | ||
sips -s format icns "${RESOURCES}/icons/mac-icon.png" --out "${CONTENTS}/Resources/applet.icns" | ||
|
||
plutil -replace CFBundleName -string "Rancher Desktop Password Prompt" "${CONTENTS}/Info.plist" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
# This script is executed by the applet with root permissions. | ||
# The caller will have created a temporary directory containing just the | ||
# `sudo-prompt-command` shell script. This script will add the `code`, | ||
# `stdout` and `stderr` files. The caller will delete this directory | ||
# again after reading the files. | ||
|
||
# Set sudo timestamp for subsequent sudo calls if tty_tickets are disabled: | ||
/bin/mkdir -p /var/db/sudo/$USER > /dev/null 2>&1 | ||
/usr/bin/touch /var/db/sudo/$USER > /dev/null 2>&1 | ||
# AppleScript's "do shell script" may alter stdout line-endings. | ||
# It may also set stdout to stderr if there was a non-zero return code and no stderr. | ||
# We therefore prefer to redirect output streams and capture return code manually: | ||
/bin/bash sudo-prompt-command 1>stdout 2>stderr | ||
/bin/echo $? > code | ||
# Correct ownership of stdout, stderr and code so that user can delete them: | ||
/usr/sbin/chown $USER stdout stderr code | ||
# Always return 0 so that AppleScript does not show error dialog: | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set appletPath to POSIX path of (path to me) | ||
if appletPath ends with ".app/" then | ||
set appletPath to appletPath & "Contents/Resources/Scripts" | ||
else | ||
set appletPath to do shell script "dirname " & quoted form of appletPath | ||
end if | ||
set promptScript to appletPath & "/sudo-prompt-script" | ||
do shell script (quoted form of promptScript) with administrator privileges |