osal.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. # Identifies OS type and variant
  3. # Setups variables and provides OS-agnostic wrapper functions
  4. OS_TYPE=$(grep "^ID=" /etc/os-release | cut -f 2 -d '=' | sed -e 's/^"//' -e 's/"$//')
  5. case "$OS_TYPE" in
  6. debian|Debian)
  7. OS_BASE='debian'
  8. OS_VERSION=$(cat /etc/debian_version|grep -o "[0-9]\{1,2\}"|head -n1)
  9. ;;
  10. ubuntu|Ubuntu)
  11. OS_BASE='debian'
  12. OS_VERSION="$(lsb_release -s -r)"
  13. ;;
  14. centos|CentOS|rhel|RHEL|fedora|Fedora|RedHat)
  15. OS_BASE='rhel'
  16. OS_VERSION=$(cat /etc/os-release | grep VERSION_ID | sed -e "s/VERSION_ID=//" | sed -e 's/^"//' -e 's/"$//')
  17. ;;
  18. *)
  19. OS_BASE='unknown'
  20. ;;
  21. esac
  22. OSAL_PATH="$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P)"
  23. for OSAL_FILE in "osal_${OS_BASE}_based" \
  24. "osal_${OS_TYPE}" \
  25. "osal_${OS_TYPE}_${OS_VERSION}"
  26. do
  27. # Search for OS specific OSAL file and source it
  28. if [ -f "$OSAL_PATH/${OSAL_FILE}.sh" ]; then
  29. source "$OSAL_PATH/${OSAL_FILE}.sh"
  30. fi
  31. done
  32. # VAR = $(ini_get 'file' 'section' 'param' 'newvalue')
  33. ini_get() {
  34. /usr/bin/crudini --get "$@"
  35. }
  36. # ini_set 'file' 'section' 'param' 'newvalue'
  37. ini_set() {
  38. /usr/bin/crudini --set "$@"
  39. }
  40. execute_with_spinner() {
  41. if [ "$OSAL_DEBUG" ]; then
  42. echo "$@"
  43. $@
  44. else
  45. $@ > /dev/null 2>&1 &
  46. BACK_PID=$!
  47. spinner="/-\|"
  48. spin_i=1
  49. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  50. printf "\b${spinner:spin_i++%${#spinner}:1}"
  51. sleep 0.5
  52. done
  53. # Do a blank echo to get the \n back
  54. echo
  55. fi
  56. }