6

我正处于设计脚本以自动化我的 Active Directory 绑定的最后阶段,该绑定将被多人使用。因此,我需要提示输入用户名和密码。我已经成功创建了提示,但想找到一些方法来防止密码出现在询问密码的对话框中(这将远程完成,我不希望密码可见)。

它可以变成星星,点,根本不显示,任何东西,我只需要它不显示在视觉上,但仍然可以传递给 dsconfigad 命令。

我已经测试了脚本本身并且它可以工作,这是我需要让它生效的最后一部分。

(请原谅这里有任何额外的评论,我从很多不同的来源拼凑而成)

#!/bin/bash

while :; do # Loop until valid input is entered or Cancel is pressed.
    user=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network user name:" default answer ""' -e 'text returned of result' 2>/dev/null)
    if (( $? )); then exit 1; fi  # Abort, if user pressed Cancel.
    user=$(echo -n "$user" | sed 's/^ *//' | sed 's/ *$//')  # Trim leading and trailing whitespace.
    if [[ -z "$user" ]]; then
        # The user left the project name blank.
        osascript -e 'Tell application "System Events" to display alert "You must enter a user name; please try again." as warning' >/dev/null
        # Continue loop to prompt again.
    else
        # Valid input: exit loop and continue.
        break
    fi
done

while :; do # Loop until valid input is entered or Cancel is pressed.
    netpass=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" default answer ""' -e 'text returned of result' 2>/dev/null)
    if (( $? )); then exit 1; fi  # Abort, if user pressed Cancel.
    netpass=$(echo -n "$netpass" | sed 's/^ *//' | sed 's/ *$//')  # Trim leading and trailing whitespace.
    if [[ -z "$netpass" ]]; then
        # The user left the project name blank.
        osascript -e 'Tell application "System Events" to display alert "You must enter a password; please try again." as warning' >/dev/null
        # Continue loop to prompt again.
    else
        # Valid input: exit loop and continue.
            break
        fi
    done

MACNAME=$(scutil --get ComputerName)

sudo dsconfigad -add DOMAIN \
-username $user \
-password $netpass \
-computer $MACNAME \
-mobile disable \
-mobileconfirm disable \
-localhome enable \
-useuncpath enable \
-shell /bin/bash \
-ou OU=Macs,CN=Computers,DC=corp,DC=DOMAIN,DC=net \
-force \
-localpassword LOCALPASS \
-groups "GROUPS"

#sudo rm -- "$0"
4

1 回答 1

9

使用with hidden answer. 关联:

https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/reference/aslr_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW12

osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" with hidden answer default answer ""' -e 'text returned of result' 2>/dev/null
于 2014-08-29T20:36:02.750 回答