create_folder.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. #
  3. # create_folder.sh — Detect the current Linux distro and dispatch to the
  4. # matching distro-specific folder-creation script.
  5. # Usage: su -c "./create_folder.sh <foldername>" or sudo ./create_folder.sh <foldername>
  6. #
  7. # The distro-specific scripts (_create_folder_fedora.sh, _create_folder_ubuntu.sh)
  8. # are prefixed with an underscore so they don't clutter tab-completion for
  9. # "create_folder".
  10. #
  11. set -euo pipefail
  12. RED='\033[0;31m'
  13. NC='\033[0m' # No Color
  14. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  15. if [[ ! -r /etc/os-release ]]; then
  16. echo -e "${RED}ERROR: Cannot detect distro (/etc/os-release not found).${NC}" >&2
  17. exit 1
  18. fi
  19. # shellcheck disable=SC1091
  20. source /etc/os-release
  21. DISTRO_ID="${ID:-}"
  22. DISTRO_ID_LIKE="${ID_LIKE:-}"
  23. case "$DISTRO_ID $DISTRO_ID_LIKE" in
  24. *fedora*|*rhel*)
  25. TARGET="$SCRIPT_DIR/_create_folder_fedora.sh"
  26. ;;
  27. *ubuntu*|*debian*)
  28. TARGET="$SCRIPT_DIR/_create_folder_ubuntu.sh"
  29. ;;
  30. *)
  31. echo -e "${RED}ERROR: Unsupported distro '$DISTRO_ID' (ID_LIKE='$DISTRO_ID_LIKE').${NC}" >&2
  32. exit 1
  33. ;;
  34. esac
  35. if [[ ! -x "$TARGET" ]]; then
  36. echo -e "${RED}ERROR: Expected script not found or not executable: $TARGET${NC}" >&2
  37. exit 1
  38. fi
  39. exec "$TARGET" "$@"