discover_package_manager 1.86 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7
#! /bin/bash

function discover_package_manager() {
  if [ x"$1" = x"osx" ]; then
    command -v brew >/dev/null
    if [ $? -eq 0 ]; then
      discover_package_manager_ret="brew"
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
      brew_idir=$(brew --prefix)
      brew_path=$(which brew)
      brew_user=$(stat -f '%Su' $brew_path)
      if [ x$"brew_user" == root ]; then
        discover_package_ret="sudo brew"
        return
      else
        if [ ! -w $brew_idir ]; then
          echo -e "\033[43;30;1;5mWARNING: \033[0m $brew_idir is not writtable, brew require that $brew_idir is writtable and $brew_idir/bin is in your PATH, otherwise it will be not possible to install with brew"
          commands[0]="sudo chown -R $USER $brew_idir && chmod -R u+w $brew_idir"
          possible_solutions "${commands[@]}"
          echo "Executing: ${command[$possible_solutions_ret]}"
          eval ${commands[$possible_solutions_ret]}
        fi
      fi
      if [ ! -w  ]; then
        echo -e "\033[43,33;5mWARNING: \033[0m $brew_idir is not writtable, brew require that $brew_idir is writtable and $brew_idir/bin is in your PATH, otherwise it will be not possible to install with brew"
incardon's avatar
incardon committed
25
        sleep 10
incardon's avatar
incardon committed
26 27 28 29 30 31 32 33
      fi
      return
    fi
    command -v port >/dev/null
    if [ command -v port >/dev/null 2>&1 ]; then
      discover_package_manager_ret="sudo port"
      return
    else
Incardona Pietro's avatar
Incardona Pietro committed
34
      discover_package_manager_ret=""
incardon's avatar
incardon committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48
      return
    fi
  elif [ x"$1" = x"linux"  ]; then
    command -v yum >/dev/null
    if [ $? -eq 0 ]; then
      discover_package_manager_ret="yum"
      return
    fi
    command -v apt-get >/dev/null
    if [ $? -eq 0 ]; then
      discover_package_manager_ret="apt-get"
      return
    fi
    command -v zypper >/dev/null
Yaser Afshar's avatar
Yaser Afshar committed
49
    if [ $? -eq 0 ]; then
incardon's avatar
incardon committed
50 51 52
      discover_package_manager_ret="zypper"
      return
    else
Incardona Pietro's avatar
Incardona Pietro committed
53
      discover_package_manager_ret=""
incardon's avatar
incardon committed
54 55 56 57 58 59 60
      return
    fi
  fi
}

echo "$discover_package_manager_ret"