Skip to content

Commit 07aa647

Browse files
authored
Merge pull request #1276 from mnordsletten/dependency_classes
Improvements to dependency installation
2 parents fd42f5a + 8a9ed3c commit 07aa647

2 files changed

Lines changed: 99 additions & 12 deletions

File tree

etc/install_build_requirements.sh

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,105 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# Install dependencies
44

5-
SYSTEM=$1
6-
RELEASE=$2
5+
############################################################
6+
# OPTIONS:
7+
############################################################
78

8-
DEPENDENCIES="curl make clang cmake nasm bridge-utils qemu jq python-jsonschema python-psutil"
9+
BUILD_DEPENDENCIES="curl make clang cmake nasm bridge-utils qemu jq python-jsonschema python-psutil"
10+
TEST_DEPENDENCIES="g++ g++-multilib python-junit.xml"
11+
12+
############################################################
13+
# COMMAND LINE PROPERTIES:
14+
############################################################
15+
16+
# Initialize variables:
17+
SYSTEM=0
18+
RELEASE=0
19+
CHECK_ONLY=0
20+
PRINT_INSTALL_STATUS=0
21+
DEPENDENCIES_TO_INSTALL=build
22+
23+
while getopts "h?s:r:cpd:" opt; do
24+
case "$opt" in
25+
h|\?)
26+
printf "%s\n" "Options:"\
27+
"-s System: What system to install on"\
28+
"-r Release: What release of said system"\
29+
"-c Only check: Will only check what packages are needed (will always print status as well)"\
30+
"-p Print install status: Flag for wheter or not to print dependency status"\
31+
"-d Dependencies to install: [build | test | all] are the options"
32+
exit 0 ;;
33+
s) SYSTEM=$OPTARG ;;
34+
r) RELEASE=$OPTARG ;;
35+
c) CHECK_ONLY=1 ; PRINT_INSTALL_STATUS=1;;
36+
p) PRINT_INSTALL_STATUS=1 ;;
37+
d) DEPENDENCIES_TO_INSTALL=$OPTARG ;;
38+
esac
39+
done
40+
41+
# Figure out which dependencies to check
42+
case "$DEPENDENCIES_TO_INSTALL" in
43+
build) ALL_DEPENDENCIES=$BUILD_DEPENDENCIES ;;
44+
test) ALL_DEPENDENCIES=$TEST_DEPENDENCIES ;;
45+
all) ALL_DEPENDENCIES="$BUILD_DEPENDENCIES $TEST_DEPENDENCIES" ;;
46+
esac
47+
48+
############################################################
49+
# CHECK INSTALLED PACKAGES:
50+
############################################################
51+
52+
if [ $PRINT_INSTALL_STATUS -eq 1 ]; then
53+
printf "%-15s %-20s %s \n"\
54+
"Status" "Package" "Version"\
55+
"------" "-------" "-------"
56+
for package in $ALL_DEPENDENCIES; do
57+
dpkg-query -W $package > /dev/null 2>&1
58+
if [ $? -eq 0 ]; then
59+
printf '\e[32m%-15s\e[0m %-20s %s \n'\
60+
"INSTALLED" $(dpkg-query -W $package)
61+
else
62+
printf '\e[31m%-15s\e[0m %-20s %s \n'\
63+
"MISSING" $package
64+
DEPENDENCIES="$DEPENDENCIES $package"
65+
fi
66+
done
67+
# Exits if CHECK_ONLY is set, exit code 1 if there are packages to install
68+
if [ $CHECK_ONLY -eq 1 ]; then
69+
if [ -z "$DEPENDENCIES" ]; then
70+
exit 0
71+
else
72+
exit 1
73+
fi
74+
fi
75+
else
76+
DEPENDENCIES=$ALL_DEPENDENCIES
77+
fi
78+
79+
############################################################
80+
# INSTALL MISSING PACKAGES:
81+
############################################################
982

1083
case $SYSTEM in
1184
"Darwin")
1285
exit 0;
1386
;;
1487
"Linux")
15-
echo ">>> Installing dependencies (requires sudo):"
88+
echo ">>> Installing missing dependencies (requires sudo):"
1689
case $RELEASE in
1790
"debian"|"ubuntu"|"linuxmint")
1891
DEPENDENCIES="$DEPENDENCIES"
19-
echo " Packages: $DEPENDENCIES"
2092
sudo apt-get -qq update || exit 1
2193
sudo apt-get -qqy install $DEPENDENCIES > /dev/null || exit 1
2294
exit 0;
2395
;;
2496
"fedora")
2597
DEPENDENCIES="$DEPENDENCIES"
26-
echo " Packages: $DEPENDENCIES"
2798
sudo dnf install $DEPENDENCIES || exit 1
2899
exit 0;
29100
;;
30101
"arch")
31102
DEPENDENCIES="$DEPENDENCIES python2 python2-jsonschema python2-psutil"
32-
echo " Packages: $DEPENDENCIES"
33103
sudo pacman -Syyu
34104
sudo pacman -S --needed $DEPENDENCIES
35105
exit 0;

install.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,15 @@ if [ "Darwin" = "$SYSTEM" ]; then
113113
exit 1
114114
fi
115115
else
116-
if ! ./etc/install_build_requirements.sh $SYSTEM $RELEASE; then
117-
printf "%s\n" ">>> Sorry <<<"\
118-
"Could not install build requirements."
119-
exit 1
116+
# Will only check if build dependencies are installed at this point
117+
if [ $INCLUDEOS_ENABLE_TEST == "ON" ]; then
118+
dependency_level=all
119+
else
120+
dependency_level=build
121+
fi
122+
echo ">>> Dependencies required:"
123+
if ! ./etc/install_build_requirements.sh -s $SYSTEM -r $RELEASE -c -d $dependency_level; then
124+
missing_dependencies=1
120125
fi
121126
fi
122127

@@ -147,6 +152,9 @@ done
147152

148153
# Print currently set install options
149154
printf "\n\n>>> IncludeOS will be installed with the following options:\n\n"
155+
if [ ! -z $missing_dependencies ]; then
156+
printf ' \e[31m%-s\e[0m %-s\n\n' "[NOTICE]" "Missing dependencies will be installed"
157+
fi
150158
printf " %-25s %-25s %s\n"\
151159
"Env variable" "Description" "Value"\
152160
"------------" "-----------" "-----"\
@@ -168,6 +176,15 @@ if tty -s && [ $install_yes -eq 0 ]; then
168176
esac
169177
fi
170178

179+
# Install dependencies if there are any missing
180+
if [ ! -z $missing_dependencies ]; then
181+
if ! ./etc/install_build_requirements.sh -s $SYSTEM -r $RELEASE -d $dependency_level; then
182+
printf "%s\n" ">>> Sorry <<<"\
183+
"Could not install dependencies"
184+
exit 1
185+
fi
186+
fi
187+
171188
# Trap that cleans the cmake output file in case of exit
172189
function clean {
173190
if [ -f /tmp/cmake_output.txt ]; then

0 commit comments

Comments
 (0)