deps 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. set -eu -o pipefail
  3. deps_exec=(git xdelta3 aria2c unzip)
  4. scripts_path=`cd "\`dirname \"$0\"\`"; echo "$PWD"`
  5. check_deps() {
  6. code=0
  7. for dep in ${deps_exec[@]}; do
  8. if ! command -v $dep >/dev/null; then
  9. code=1
  10. echo "$dep"
  11. fi
  12. done
  13. exit $code
  14. }
  15. install_deps() {
  16. declare -A managers=(
  17. [apt]="install -y git xdelta3 aria2 unzip"
  18. [yum]="install -y git xdelta aria2 unzip"
  19. [dnf]="install -y git xdelta3 aria2 unzip"
  20. [pacman]="-S --noconfirm xdelta3 aria2 unzip"
  21. )
  22. pkg=
  23. for p in ${!managers[@]}; do
  24. if command -v $p >/dev/null 2>&1; then
  25. pkg="$p ${managers[$p]}"
  26. break
  27. fi
  28. done
  29. if [ -z "$pkg" ]
  30. then
  31. echo "Cannot detect package manager" >&2
  32. exit 1
  33. fi
  34. tmp=$(mktemp)
  35. trap "rm $tmp" EXIT
  36. if ! "$scripts_path/sudo-wrapper" $pkg 2>$tmp; then
  37. cat $tmp
  38. exit 1
  39. fi
  40. echo "Dependencies installed successfully"
  41. }
  42. case "${1:-?}" in
  43. check)
  44. check_deps
  45. ;;
  46. install)
  47. install_deps
  48. ;;
  49. *)
  50. echo "$0 [check|install]" >&1
  51. exit 1
  52. ;;
  53. esac