[feat] WHEELHOUSE can be a url + --use-leap-wheels
[leap_pycommon.git] / pkg / pip_install_requirements.sh
1 #!/bin/bash
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 leap_wheelhouse=https://lizard.leap.se/wheels
9
10 show_help() {
11     usage="Usage: $0 [--testing] [--use-leap-wheels]\n --testing\t\tInstall dependencies from requirements-testing.pip\n
12 \t\t\tOtherwise, it will install requirements.pip\n
13 --use-leap-wheels\tUse wheels from leap.se"
14     echo -e $usage
15
16     exit 1
17 }
18
19 process_arguments() {
20     testing=false
21     use_leap_wheels=false
22
23     while [ "$#" -gt 0 ]; do
24         # From http://stackoverflow.com/a/31443098
25         case "$1" in
26             --help) show_help;;
27             --testing) testing=true; shift 1;;
28             --use-leap-wheels) use_leap_wheels=true; shift 1;;
29
30             -h) show_help;;
31             -*) echo "unknown option: $1" >&2; exit 1;;
32         esac
33     done
34 }
35
36 return_wheelhouse() {
37     if $use_leap_wheels ; then
38         WHEELHOUSE=$leap_wheelhouse
39     elif [ "$WHEELHOUSE" = "" ]; then
40         WHEELHOUSE=$HOME/wheelhouse
41     fi
42
43     # Tested with bash and zsh
44     if [[ $WHEELHOUSE != http* && ! -d "$WHEELHOUSE" ]]; then
45             mkdir $WHEELHOUSE
46     fi
47
48     echo "$WHEELHOUSE"
49 }
50
51 return_install_options() {
52     wheelhouse=`return_wheelhouse`
53     install_options="-U --find-links=$wheelhouse"
54     if $use_leap_wheels ; then
55         install_options="$install_options --trusted-host lizard.leap.se"
56     fi
57
58     echo $install_options
59 }
60
61 return_insecure_flags() {
62     for insecure_package in $insecure_packages; do
63         flags="$flags --allow-external $insecure_package --allow-unverified $insecure_package"
64     done
65
66     echo $flags
67 }
68
69 return_packages() {
70     if $testing ; then
71         packages="-r pkg/requirements-testing.pip"
72     else
73         packages="-r pkg/requirements.pip"
74     fi
75
76     echo $packages
77 }
78
79 process_arguments $@
80 install_options=`return_install_options`
81 insecure_flags=`return_insecure_flags`
82 packages=`return_packages`
83
84 pip install -U wheel
85 pip install $install_options pip
86 pip install $install_options $insecure_flags $packages