Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- Main() {
- export PATH=/bin:/usr/bin:/opt/local/bin:/usr/local/bin
- MyTmpFile="$(mktemp /tmp/${0##*/}.XXXXXX || (echo -e "Not able to create temporary file below /tmp/. Exiting." | logger ; exit 1))"
- trap "rm -f \"${MyTmpFile}\"; exit 0" 0 1 2 3 15
- # PathToSmartCtl="$(GetSmartCtl)"
- PathToSmartCtl="${0%/*}"/smartctl
- PathToKeys="${0%/*}"/keys
- CreateShellAlias
- sleep 1
- IsShiftPressed=$("${PathToKeys}" shift)
- IsOptionPressed=$("${PathToKeys}" option)
- case ${IsShiftPressed} in
- 1)
- # shift is pressed, we are in test mode!
- # if option is pressed as well we're
- # performing a long test otherwise short
- if [ "X${IsOptionPressed}" = "X1" ]; then
- TestMode=long
- else
- TestMode=short
- fi
- GetListOfVolumes | while read ; do
- # check whether device is SMART capable
- "${PathToSmartCtl}" -a ${REPLY} >/dev/null 2>&1
- if [ $? -eq 0 ]; then
- echo -e "${AbstandSchraddel}Previous test results for ${REPLY}:\n"
- "${PathToSmartCtl}" -l selftest ${REPLY}
- echo -e "\nNow performing a ${TestMode} test on ${REPLY} in the background. You can close this window and try again in several minutes. Please see below the smartctl output.\n"
- "${PathToSmartCtl}" -t ${TestMode} ${REPLY}
- AbstandSchraddel="\n\n\n"
- fi
- done
- ;;
- *)
- # we simply display SMART status for all devices
- GetListOfVolumes | while read ; do
- echo -e "${AbstandSchraddel}Examining ${REPLY}\n"
- "${PathToSmartCtl}" -a ${REPLY} | tee "${MyTmpFile}"
- # check for warning
- ButtonPressed=""
- grep "WARNING" "${MyTmpFile}" >/dev/null 2>&1 && ButtonPressed="$(DisplayWarning "${MyTmpFile}")"
- if [ "X${ButtonPressed}" = "XMore Info" ]; then
- grep "^http" "${MyTmpFile}" | while read ; do
- open -b com.apple.Safari "${REPLY}"
- done
- fi
- AbstandSchraddel="\n\n\n"
- done
- ;;
- esac
- } # Main
- CreateShellAlias() {
- if [ -f "${HOME}/.profile" ]; then
- grep -v "^alias smartctl" <"${HOME}/.profile" >"${MyTmpFile}"
- echo -e "alias smartctl=\"${PathToSmartCtl}\"" >>"${MyTmpFile}"
- cat "${MyTmpFile}" >"${HOME}/.profile"
- else
- echo -e "alias smartctl=\"${PathToSmartCtl}\"" >>"${HOME}/.profile"
- fi
- } # CreateShellAlias
- GetListOfVolumes() {
- /usr/sbin/diskutil list | grep "^/dev/" | while read ; do
- /usr/sbin/diskutil corestorage info ${REPLY} >/dev/null 2>&1 || echo ${REPLY}
- done
- } # GetListOfVolumes
- GetSmartCtl() {
- mdfind "kMDItemCFBundleIdentifier == 'de.kaiser-edv.k-smart'" | grep "\.app$" | while read ; do
- SmartCtlVersion=$("${REPLY}"/Contents/Resources/smartctl | awk -F" " '/^smartctl / {print $2}')
- echo -e "${SmartCtlVersion}\t${REPLY}/Contents/Resources/smartctl"
- done | sort -r | head -n1 | cut -f2
- } # GetSmartCtl
- DisplayWarning() {
- DisplayString=$(grep "WARNING" "$1" | sed -e 's/\"/\\\"/g' -e 's/^==\>\ //')
- grep "^http" "$1" >/dev/null 2>&1
- if [ $? -eq 0 ]; then
- Buttons='{"More Info", "OK"}'
- else
- Buttons='{"OK"}'
- fi
- osascript <<-EOF
- tell application "System Events"
- activate
- set ButtonPressed to (button returned of (display dialog "${DisplayString}" buttons ${Buttons} default button 1 with icon caution giving up after 30))
- end tell
- EOF
- } # DisplayWarning
- Main "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement