LumberjackUser.bash 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # Get full user name of current user
  3. # E.g. "Robbie Hanson"
  4. full1=$(osascript -e "tell application \"System Events\"" -e "get the full name of the current user" -e "end tell")
  5. #echo $full1
  6. # Convert to lower case
  7. # E.g. "robbie hanson"
  8. full2=$(echo $full1 | awk '{print tolower($0)}')
  9. #echo $full2
  10. # Replace spaces with underscores
  11. # E.g. "robbie_hanson"
  12. full3=$(echo ${full2// /_})
  13. #echo $full3
  14. # Remove any characters that are illegal in a macro name
  15. full4=$(echo $full3 | sed 's/[^0-9a-zA-Z_]*//g')
  16. #echo $full4
  17. # If blank, set the name to an anonymous user
  18. if [ "$full4" == "" ]
  19. then
  20. full4='anonymous_user'
  21. fi
  22. # If we output directly to our intended file, even when nothing has changed,
  23. # then we'll essentially be doing a touch on the file.
  24. # The compiler will see this, and recompile any files that include the header.
  25. # This may mean recompiling every single source file, every single time we do a build!
  26. # So instead we're going to output to a temporary file, and use diff to detect changes.
  27. temp_filepath="${SRCROOT}/PerUserLogLevels/LumberjackUser.temp.h"
  28. final_filepath="${SRCROOT}/PerUserLogLevels/LumberjackUser.h"
  29. echo "// This file is automatically generated" > ${temp_filepath}
  30. echo "#define $full4 1" >> ${temp_filepath}
  31. if [ -a ${final_filepath} ]
  32. then
  33. DIFF=$(diff ${temp_filepath} ${final_filepath})
  34. if [ "$DIFF" != "" ]
  35. then
  36. cp -f ${temp_filepath} ${final_filepath}
  37. fi
  38. else
  39. cp -f ${temp_filepath} ${final_filepath}
  40. fi