|
1 | | -#!/bin/sh |
| 1 | +#!/bin/bash |
2 | 2 | # |
3 | 3 | # Install dependencies |
4 | 4 |
|
5 | | -SYSTEM=$1 |
6 | | -RELEASE=$2 |
| 5 | +############################################################ |
| 6 | +# OPTIONS: |
| 7 | +############################################################ |
7 | 8 |
|
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 | +############################################################ |
9 | 82 |
|
10 | 83 | case $SYSTEM in |
11 | 84 | "Darwin") |
12 | 85 | exit 0; |
13 | 86 | ;; |
14 | 87 | "Linux") |
15 | | - echo ">>> Installing dependencies (requires sudo):" |
| 88 | + echo ">>> Installing missing dependencies (requires sudo):" |
16 | 89 | case $RELEASE in |
17 | 90 | "debian"|"ubuntu"|"linuxmint") |
18 | 91 | DEPENDENCIES="$DEPENDENCIES" |
19 | | - echo " Packages: $DEPENDENCIES" |
20 | 92 | sudo apt-get -qq update || exit 1 |
21 | 93 | sudo apt-get -qqy install $DEPENDENCIES > /dev/null || exit 1 |
22 | 94 | exit 0; |
23 | 95 | ;; |
24 | 96 | "fedora") |
25 | 97 | DEPENDENCIES="$DEPENDENCIES" |
26 | | - echo " Packages: $DEPENDENCIES" |
27 | 98 | sudo dnf install $DEPENDENCIES || exit 1 |
28 | 99 | exit 0; |
29 | 100 | ;; |
30 | 101 | "arch") |
31 | 102 | DEPENDENCIES="$DEPENDENCIES python2 python2-jsonschema python2-psutil" |
32 | | - echo " Packages: $DEPENDENCIES" |
33 | 103 | sudo pacman -Syyu |
34 | 104 | sudo pacman -S --needed $DEPENDENCIES |
35 | 105 | exit 0; |
|
0 commit comments