]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/bin/bash |
2 | # | |
3 | # Ceph distributed storage system | |
4 | # | |
5 | # Copyright (C) 2014 Red Hat <contact@redhat.com> | |
6 | # | |
7 | # Author: Loic Dachary <loic@dachary.org> | |
8 | # | |
9 | # This library is free software; you can redistribute it and/or | |
10 | # modify it under the terms of the GNU Lesser General Public | |
11 | # License as published by the Free Software Foundation; either | |
12 | # version 2.1 of the License, or (at your option) any later version. | |
13 | # | |
14 | ||
15 | # | |
16 | # Return MAX(1, (number of processors / 2)) by default or NPROC | |
17 | # | |
18 | function get_processors() { | |
19 | if test -n "$NPROC" ; then | |
20 | echo $NPROC | |
21 | else | |
22 | if test $(nproc) -ge 2 ; then | |
23 | expr $(nproc) / 2 | |
24 | else | |
25 | echo 1 | |
26 | fi | |
27 | fi | |
28 | } | |
29 | ||
30 | function run() { | |
31 | local install_cmd | |
31f18b77 | 32 | local which_pkg="which" |
7c673cae FG |
33 | if test -f /etc/redhat-release ; then |
34 | source /etc/os-release | |
35 | if ! type bc > /dev/null 2>&1 ; then | |
36 | echo "Please install bc and re-run." | |
37 | exit 1 | |
38 | fi | |
39 | if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then | |
40 | install_cmd="dnf -y install" | |
41 | else | |
42 | install_cmd="yum install -y" | |
43 | fi | |
31f18b77 FG |
44 | else |
45 | which_pkg="debianutils" | |
7c673cae FG |
46 | fi |
47 | ||
48 | type apt-get > /dev/null 2>&1 && install_cmd="apt-get install -y" | |
49 | type zypper > /dev/null 2>&1 && install_cmd="zypper --gpg-auto-import-keys --non-interactive install" | |
50 | ||
51 | if ! type sudo > /dev/null 2>&1 ; then | |
52 | echo "Please install sudo and re-run. This script assumes it is running" | |
53 | echo "as a normal user with the ability to run commands as root via sudo." | |
54 | exit 1 | |
55 | fi | |
56 | if [ -n "$install_cmd" ]; then | |
31f18b77 | 57 | $DRY_RUN sudo $install_cmd ccache jq $which_pkg |
7c673cae FG |
58 | else |
59 | echo "WARNING: Don't know how to install packages" >&2 | |
60 | fi | |
61 | ||
62 | if test -f ./install-deps.sh ; then | |
63 | $DRY_RUN ./install-deps.sh || return 1 | |
64 | fi | |
65 | ||
66 | # Init defaults after deps are installed. get_processors() depends on coreutils nproc. | |
67 | DEFAULT_MAKEOPTS=${DEFAULT_MAKEOPTS:--j$(get_processors)} | |
68 | BUILD_MAKEOPTS=${BUILD_MAKEOPTS:-$DEFAULT_MAKEOPTS} | |
69 | CHECK_MAKEOPTS=${CHECK_MAKEOPTS:-$DEFAULT_MAKEOPTS} | |
70 | ||
71 | $DRY_RUN ./do_cmake.sh $@ || return 1 | |
72 | $DRY_RUN cd build | |
73 | $DRY_RUN make $BUILD_MAKEOPTS tests || return 1 | |
74 | $DRY_RUN ctest $CHECK_MAKEOPTS --output-on-failure || return 1 | |
75 | } | |
76 | ||
77 | function main() { | |
78 | if [[ $EUID -eq 0 ]] ; then | |
79 | echo "For best results, run this script as a normal user configured" | |
80 | echo "with the ability to run commands as root via sudo." | |
81 | fi | |
82 | echo -n "Checking hostname sanity... " | |
83 | if hostname --fqdn >/dev/null 2>&1 ; then | |
84 | echo "OK" | |
85 | else | |
86 | echo "NOT OK" | |
87 | echo "Please fix 'hostname --fqdn', otherwise 'make check' will fail" | |
88 | return 1 | |
89 | fi | |
90 | if run "$@" ; then | |
91 | rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv* | |
92 | echo "cmake check: successful run on $(git rev-parse HEAD)" | |
93 | return 0 | |
94 | else | |
95 | rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv* | |
96 | return 1 | |
97 | fi | |
98 | } | |
99 | ||
100 | main "$@" |