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