949f738db464286e2552494a7e24c566eba64a72
[leap_pycommon.git] / pkg / pip_install_requirements.sh
1 #!/bin/sh
2 # Update pip and install LEAP base/testing requirements.
3 # For convenience, $insecure_packages are allowed with insecure flags enabled.
4 # Use at your own risk.
5 # See $usage for help
6
7 insecure_packages="dirspec"
8
9 return_wheelhouse() {
10     if [ "$WHEELHOUSE" = "" ]; then
11         WHEELHOUSE=$HOME/wheelhouse
12     fi
13
14     if [ ! -d "$WHEELHOUSE" ]; then
15         mkdir $WHEELHOUSE
16     fi
17
18     echo "$WHEELHOUSE"
19 }
20
21 show_help() {
22     usage="Usage: $0 [--testing]\n --testing\tInstall dependencies from requirements-testing.pip\n
23 \t\tOtherwise, it will install requirements.pip"
24     echo $usage
25
26     exit 1
27 }
28
29 process_arguments() {
30     testing=false
31     while [ "$#" -gt 0 ]; do
32         # From http://stackoverflow.com/a/31443098
33         case "$1" in
34             --help) show_help;;
35             --testing) testing=true; shift 1;;
36
37             -h) show_help;;
38             -*) echo "unknown option: $1" >&2; exit 1;;
39         esac
40     done
41 }
42
43 return_insecure_flags() {
44     for insecure_package in $insecure_packages; do
45         flags="$flags --allow-external $insecure_package --allow-unverified $insecure_package"
46     done
47
48     echo $flags
49 }
50
51 return_packages() {
52     if $testing ; then
53         packages="-r pkg/requirements-testing.pip"
54     else
55         packages="-r pkg/requirements.pip"
56     fi
57
58     echo $packages
59 }
60
61 process_arguments $@
62 wheelhouse=`return_wheelhouse`
63 install_options="-U --find-links=$wheelhouse"
64 insecure_flags=`return_insecure_flags`
65 packages=`return_packages`
66
67 pip install -U wheel
68 pip install $install_options pip
69 pip install $install_options $insecure_flags $packages