From d1131511416cfca404504e7b09015aa8711be3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sandstr=C3=B6m?= Date: Tue, 4 Oct 2016 23:00:59 +0200 Subject: [PATCH] Adds missing exit value checks in install script --- README.md | 6 +++--- etc/create_bridge.sh | 11 ++++++++--- etc/install_build_requirements.sh | 10 +++++----- install.sh | 32 +++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ae69dbccad..54e126e28d 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,12 @@ A longer list of features and limitations is on the [wiki feature list](https:// ### Install libraries +**NOTE:** The script will install packages and create a network bridge, and thus will ask for sudo access. + ``` $ git clone https://github.com/hioa-cs/IncludeOS $ cd IncludeOS - $ sudo ./install.sh + $ ./install.sh ``` **The script will:** @@ -57,8 +59,6 @@ A longer list of features and limitations is on the [wiki feature list](https:// * Build the vmbuilder, which turns your service into a bootable image. * Copy `vmbuild` and `qemu-ifup` from the repo, over to `$INCLUDEOS_HOME`. -**NOTE:** The script will install packages, and thus will require sudo access. - Detailed installation instructions for [Vagrant](https://github.com/hioa-cs/IncludeOS/wiki/Vagrant), [OS X](https://github.com/hioa-cs/IncludeOS/wiki/OS-X) and [Ubuntu](https://github.com/hioa-cs/IncludeOS/wiki/Ubuntu) are available in the Wiki, as well as instructions for [building everything from source](https://github.com/hioa-cs/IncludeOS/wiki/Ubuntu#b-completely-build-everything-from-source-slow). ### Testing the installation diff --git a/etc/create_bridge.sh b/etc/create_bridge.sh index ebfe0ab7b4..0ded13d848 100755 --- a/etc/create_bridge.sh +++ b/etc/create_bridge.sh @@ -8,11 +8,16 @@ GATEWAY=10.0.0.1 NETWORK=10.0.0.0 DHCPRANGE=10.0.0.2,10.0.0.254 -brctl addbr $BRIDGE -ifconfig $BRIDGE $GATEWAY netmask $NETMASK up +# Check if bridge already is created +if brctl show $BRIDGE 2>&1 | grep --silent "No such device"; then + sudo brctl addbr $BRIDGE || exit 1 +fi + +sudo ifconfig $BRIDGE $GATEWAY netmask $NETMASK up || exit 1 # HÄreks cool hack: # - First two bytes is fixed to "c001" because it's cool # - Last four is the gateway IP, 10.0.0.1 -ifconfig include0 hw ether c0:01:0a:00:00:01 +sudo ifconfig include0 hw ether c0:01:0a:00:00:01 || exit 1 +exit 0 diff --git a/etc/install_build_requirements.sh b/etc/install_build_requirements.sh index 1d4b5f31d5..8ed64892f6 100755 --- a/etc/install_build_requirements.sh +++ b/etc/install_build_requirements.sh @@ -15,10 +15,10 @@ case $SYSTEM in case $RELEASE in "Ubuntu") UBUNTU_VERSION=`lsb_release -rs` - if [ $(awk 'BEGIN{ print "'$UBUNTU_VERSION'"<"'16.04'" }') -eq 1 ]; then + if [ $(awk 'BEGIN{ print "'$UBUNTU_VERSION'"<"'16.04'" }') -eq 1 ]; then clang_version="3.6" DEPENDENCIES="gcc-5 g++-5" - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test || exit 1 else clang_version="3.8" fi @@ -26,15 +26,15 @@ case $SYSTEM in DEPENDENCIES="curl make clang-$clang_version nasm bridge-utils qemu jq $DEPENDENCIES" echo ">>> Installing dependencies (requires sudo):" echo " Packages: $DEPENDENCIES" - sudo apt-get update - sudo apt-get install -y $DEPENDENCIES + sudo apt-get update || exit 1 + sudo apt-get install -y $DEPENDENCIES || exit 1 exit 0; ;; "Fedora") DEPENDENCIES="curl make clang nasm bridge-utils qemu jq" echo ">>> Installing dependencies (requires sudo):" echo " Packages: $DEPENDENCIES" - sudo dnf install $DEPENDENCIES + sudo dnf install $DEPENDENCIES || exit 1 exit 0; ;; esac diff --git a/install.sh b/install.sh index a67be62d32..3eb49b26a2 100755 --- a/install.sh +++ b/install.sh @@ -32,6 +32,13 @@ check_os_support() { return 1; } +# check if sudo is available +if ! command -v sudo > /dev/null 2>&1; then + echo -e ">>> Sorry <<< \n\ +The command sudo was not found. \n" + exit 1 +fi + # check if system is supported at all if ! check_os_support $SYSTEM $RELEASE; then echo -e ">>> Sorry <<< \n\ @@ -43,22 +50,35 @@ fi # now install build requirements (compiler, etc). This was moved into # a function of its own as it can easen the setup. -./etc/install_build_requirements.sh $SYSTEM $RELEASE +if ! ./etc/install_build_requirements.sh $SYSTEM $RELEASE; then + echo -e ">>> Sorry <<< \n\ +Could not install build requirements. \n" + exit 1 +fi # if the --all-source parameter was given, build it the hard way if [ "$1" = "--all-source" ]; then echo ">>> Installing everything from source" ./etc/install_all_source.sh + elif [ "Darwin" = "$SYSTEM" ]; then - # TODO: move build dependencies to the install build requirements step - ./etc/install_osx.sh -elif [ "Linux" = "$SYSTEM" ]; then + # TODO: move build dependencies to the install build requirements step + ./etc/install_osx.sh +elif [ "Linux" = "$SYSTEM" ]; then echo -e "\n\n>>> Calling install_from_bundle.sh script" - ./etc/install_from_bundle.sh + if ! ./etc/install_from_bundle.sh; then + echo -e ">>> Sorry <<< \n\ +Could not install from bundle. \n" + exit 1 + fi echo -e "\n\n>>> Creating a virtual network, i.e. a bridge. (Requires sudo)" - sudo ./etc/create_bridge.sh + if ! ./etc/create_bridge.sh; then + echo -e ">>> Sorry <<< \n\ +Could not create or configure bridge. \n" + exit 1 + fi echo -e "\n\n>>> Done! Test your installation with ./test.sh" fi