62 lines
2.5 KiB
Bash
Executable File
62 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
||
################################################################################
|
||
# Shellscript : Support info
|
||
# Autor : Andreas Vogel, NEXT Enterprise gmbh, 2022
|
||
################################################################################
|
||
# set -x
|
||
################################### variables ##################################
|
||
#get logged in user
|
||
loggedInUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/{print $3}')
|
||
if [[ -z ${loggedInUser} || ${loggedInUser} == "root" ]]; then
|
||
echo "$(/bin/date +%Y-%m-%d\ %H:%M:%S) Info: No user logged in."
|
||
exit 0
|
||
fi
|
||
uid=$(id -u "${loggedInUser}")
|
||
#icons for use with applescript display dialog
|
||
icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AllMyFiles.icns"
|
||
serial=$(system_profiler SPHardwareDataType | grep 'Serial Number (system)' | awk '{print $NF}')
|
||
lastreboot=$(date -jf "%s" "$(sysctl kern.boottime | awk -F'[= |,]' '{print $6}')" +"%d.%m.%Y %T")
|
||
macos=$(sw_vers -productVersion)
|
||
|
||
interface="$(route get default | grep interface | awk '{print $2}')"
|
||
result=$(ifconfig $interface | grep -v "inet6" | grep "inet" | awk '{print $2}')
|
||
ip=$result
|
||
|
||
################################### functions ##################################
|
||
#Function to use applescript "display dialog" to display message to user and check which button (2 buttons) was clicked
|
||
askforbutton2() {
|
||
message=${1}
|
||
title="Support Info"
|
||
button1="close"
|
||
#button2="close"
|
||
launchctl asuser "${uid}" /usr/bin/osascript <<-EndOfScript
|
||
button returned of ¬
|
||
(display dialog "${message}" ¬
|
||
buttons {"${button1}"} ¬
|
||
default button "${button1}" with icon POSIX file "${icon}" with title "${title}")
|
||
EndOfScript
|
||
}
|
||
|
||
|
||
|
||
################################### execution ##################################
|
||
while [[ ${exit} != "close" ]]; do
|
||
|
||
if [[ $(sw_vers -buildVersion) > "19" ]]; then
|
||
exit=$(askforbutton2 "𝗡𝗲𝘁𝘄𝗼𝗿𝗸\
|
||
\n====================================\
|
||
\nIP\t\t\t\t\t${ip}\
|
||
\n\
|
||
\n𝗗𝗲𝘃𝗶𝗰𝗲\
|
||
\n====================================\
|
||
\nHostname:\t\t\t$(hostname)\
|
||
\nSerial :\t\t\t\t${serial}\
|
||
\nCurrent user:\t\t\t${loggedInUser}\
|
||
\nmacOS:\t\t\t\t${macos}\
|
||
\nLast reboot:\t\t\t${lastreboot}")
|
||
fi
|
||
done
|
||
|
||
################################### end ########################################
|
||
exit 0
|