sudo-prefix.sh 650 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. scriptname=$(basename ${BASH_SOURCE[0]})
  3. scriptdirname=$(dirname ${BASH_SOURCE[0]})
  4. function alias_prefix_sudo_if_exists() {
  5. cmd="$1"
  6. shift
  7. opts="$*"
  8. debug "cmd='$cmd' opt='$opts'"
  9. if [ -n "$(command -v $cmd)" ]; then
  10. alias $cmd="sudo $cmd $opts"
  11. fi
  12. }
  13. if [ $UID -ne 0 ]; then
  14. debug "I am not 'root'."
  15. if [ -n "$(command -v sudo)" ]; then
  16. debug "sudo is installed."
  17. alias_prefix_sudo_if_exists reboot
  18. alias_prefix_sudo_if_exists apt-get
  19. alias_prefix_sudo_if_exists pacman
  20. alias_prefix_sudo_if_exists dnf
  21. alias_prefix_sudo_if_exists zypper
  22. fi
  23. fi