複数のユーザーが使用する 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"