#!/bin/bash
#
#管理员密码
Passwd=$(/usr/bin/osascript -e 'display dialog "请输入管理员密码" with hidden answer default answer "" with icon note buttons {"Continue"} default button "Continue"
set result1 to result
set the text_data to text returned of the result
set the button_data to button returned of the result1
if button_data = "Cancel" then
return ""
end if
return text_data')
if [ -z "$Passwd" ]; then
exit 0;
fi
if [ $Passwd != 'xxxxxxx' ]; then
$(/usr/bin/osascript -e 'display dialog "管理员密码不对!" buttons {"OK"} default button "OK"')
exit 0;
fi
max_uid=`sudo dscl . list /Users UniqueID | awk '{print $NF}' | sort -rn | head -n 1` #得到最大的uid
let max_uid=$max_uid+1
sudo dscl . -create /Users/JS-temp UniqueID $max_uid
sudo dscl . -create /Users/JS-temp PrimaryGroupID 20
sudo dscl . -create /Users/JS-temp NFSHomeDirectory /Users/JS-temp
sudo dscl . -create /Users/JS-temp UserShell /bin/zsh
sudo dscl . -create /Users/JS-temp RealName "temp"
sudo dscl . -passwd /Users/JS-temp "1234"
sudo dscl . -append /Groups/admin GroupMembership JS-temp
$(/usr/bin/osascript -e 'display dialog "无须重启,已创建新的临时管理员 temp,密码为 1234 ,当处理当前的事情后,请删除此临时用户!" buttons {"OK"} default button "OK"')
echo "OK";