ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 2 | # -*- Mode:bash; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 3 | # |
Junxiao Shi | 48ada89 | 2021-11-04 09:02:21 -0600 | [diff] [blame^] | 4 | # Copyright (C) 2015-2021, The University of Memphis, |
Ashlesh Gawande | 0cccdb8 | 2016-08-15 12:58:06 -0500 | [diff] [blame] | 5 | # Arizona Board of Regents, |
| 6 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 7 | # |
| 8 | # This file is part of Mini-NDN. |
| 9 | # See AUTHORS.md for a complete list of Mini-NDN authors and contributors. |
| 10 | # |
| 11 | # Mini-NDN is free software: you can redistribute it and/or modify |
| 12 | # it under the terms of the GNU General Public License as published by |
| 13 | # the Free Software Foundation, either version 3 of the License, or |
| 14 | # (at your option) any later version. |
| 15 | # |
| 16 | # Mini-NDN is distributed in the hope that it will be useful, |
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | # GNU General Public License for more details. |
| 20 | # |
| 21 | # You should have received a copy of the GNU General Public License |
| 22 | # along with Mini-NDN, e.g., in COPYING.md file. |
| 23 | # If not, see <http://www.gnu.org/licenses/>. |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 24 | |
Junxiao Shi | 48ada89 | 2021-11-04 09:02:21 -0600 | [diff] [blame^] | 25 | set -eo pipefail |
| 26 | cd "$(dirname "${BASH_SOURCE[0]}")" |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 27 | |
Junxiao Shi | 48ada89 | 2021-11-04 09:02:21 -0600 | [diff] [blame^] | 28 | # These commands are generally installed on most systems. If not, user must install manually. |
| 29 | # 'sudo' is not directly used by this script, but Mininet install.sh uses it, so we check that also. |
| 30 | NEEDED_BINARIES=( |
| 31 | awk |
| 32 | git |
| 33 | sudo |
| 34 | ) |
| 35 | MISSING_BINARIES=() |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 36 | |
Junxiao Shi | 48ada89 | 2021-11-04 09:02:21 -0600 | [diff] [blame^] | 37 | SUDO= |
| 38 | if [[ $(id -u) -eq 0 ]]; then |
| 39 | if [[ -n $SUDO_USER ]] && [[ -z $SKIPSUDOCHECK ]]; then |
| 40 | cat <<EOT |
| 41 | Do not run this script through sudo |
| 42 | Instead, run this script as a regular user; the script will call sudo when needed |
| 43 | To bypass this check, set the environment variable SKIPSUDOCHECK=1 |
| 44 | EOT |
| 45 | exit 1 |
| 46 | fi |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 47 | else |
Junxiao Shi | 48ada89 | 2021-11-04 09:02:21 -0600 | [diff] [blame^] | 48 | SUDO=sudo |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 49 | fi |
| 50 | |
Junxiao Shi | 48ada89 | 2021-11-04 09:02:21 -0600 | [diff] [blame^] | 51 | for B in "${NEEDED_BINARIES[@]}"; do |
| 52 | if ! command -v "$B" >/dev/null; then |
| 53 | MISSING_BINARIES+=("$B") |
| 54 | fi |
| 55 | done |
| 56 | if [[ ${#MISSING_BINARIES[@]} -gt 0 ]] ; then |
| 57 | echo "Missing commands (${MISSING_BINARIES[*]}) to start this script. To install, run:" |
| 58 | echo " $SUDO apt install --no-install-recommends ca-certificates curl git mawk sudo" |
| 59 | echo " $SUDO yum install ca-certificates curl git mawk sudo" |
| 60 | exit 1 |
Ashlesh Gawande | 670ff15 | 2018-06-08 12:26:39 -0500 | [diff] [blame] | 61 | fi |
Junxiao Shi | 48ada89 | 2021-11-04 09:02:21 -0600 | [diff] [blame^] | 62 | |
| 63 | CODEROOT="$(pwd)/dl" |
| 64 | NJOBS=$(nproc) |
| 65 | MEM_JOBS=$(awk '$1=="MemAvailable:" { print int($2/(1536*1024)); exit }' /proc/meminfo) |
| 66 | if [[ $MEM_JOBS -lt 1 ]]; then |
| 67 | NJOBS=1 |
| 68 | echo 'Insufficient available RAM, build may fail' |
| 69 | elif [[ $MEM_JOBS -lt $NJOBS ]]; then |
| 70 | NJOBS=$MEM_JOBS |
| 71 | fi |
| 72 | PREFER_FROM=ppa |
| 73 | PPA_PKGS=() |
| 74 | |
| 75 | ARGS=$(getopt -o 'hy' -l 'help,dir:,jobs:,no-wifi,ppa,source,cxx:,dummy-keychain,nfd:,psync:,nlsr:,tools:,traffic:,infoedit:,mininet:,mnwifi:,dl-only,ignore-existing' -- "$@") |
| 76 | eval set -- "$ARGS" |
| 77 | while true; do |
| 78 | case $1 in |
| 79 | -h|--help) HELP=1; shift;; |
| 80 | -y) CONFIRM=1; shift;; |
| 81 | --dir) CODEROOT=$2; shift 2;; |
| 82 | --jobs) NJOBS=$((0+$2)); shift 2;; |
| 83 | --no-wifi) NO_WIFI=1; shift;; |
| 84 | --ppa) PREFER_FROM=ppa; shift;; |
| 85 | --source) PREFER_FROM=source; shift;; |
| 86 | --cxx) CXX_VERSION=$2; NO_PPA=1; shift 2;; |
| 87 | --dummy-keychain) CXX_DUMMY_KEYCHAIN=1; NO_PPA=1; shift;; |
| 88 | --nfd) NFD_VERSION=$2; NO_PPA=1; shift 2;; |
| 89 | --psync) PSYNC_VERSION=$2; NO_PPA=1; shift 2;; |
| 90 | --nlsr) NLSR_VERSION=$2; NO_PPA=1; shift 2;; |
| 91 | --tools) TOOLS_VERSION=$2; NO_PPA=1; shift 2;; |
| 92 | --traffic) TRAFFIC_VERSION=$2; NO_PPA=1; shift 2;; |
| 93 | --infoedit) INFOEDIT_VERSION=$2; shift 2;; |
| 94 | --mininet) MININET_VERSION=$2; shift 2;; |
| 95 | --mnwifi) MNWIFI_VERSION=$2; shift 2;; |
| 96 | --dl-only) DL_ONLY=1; shift;; |
| 97 | --ignore-existing) IGNORE_EXISTING=1; shift;; |
| 98 | --) shift; break;; |
| 99 | *) exit 1;; |
| 100 | esac |
| 101 | done |
| 102 | |
| 103 | if [[ $NJOBS -le 0 ]]; then |
| 104 | cat <<EOT |
| 105 | --jobs must be a positive integer. |
| 106 | Run ./install.sh -h to see help message. |
| 107 | EOT |
| 108 | exit 1 |
| 109 | fi |
| 110 | |
| 111 | if [[ $HELP -eq 1 ]]; then |
| 112 | cat <<EOT |
| 113 | ./install.sh [OPTION]... |
| 114 | |
| 115 | General options: |
| 116 | -h Display help and exit. |
| 117 | -y Skip confirmation. |
| 118 | --dir=${CODEROOT} |
| 119 | Set where to download and compile the code. |
| 120 | --jobs=${NJOBS} |
| 121 | Set number of parallel jobs. |
| 122 | --no-wifi |
| 123 | Do not install Mininet-WiFi. |
| 124 | |
| 125 | Install preference options: |
| 126 | --ppa |
| 127 | Install available packages from named-data PPA. |
| 128 | This is the default on Ubuntu, unless a source code version option is used. |
| 129 | --source |
| 130 | Install all packages from source code. |
| 131 | |
| 132 | Source code version options: |
| 133 | --cxx=[VERSION] |
| 134 | Set ndn-cxx version. |
| 135 | --dummy-keychain |
| 136 | Patch ndn-cxx to use dummy KeyChain. |
| 137 | This disables signing and verifications, which allows experiments to run faster. |
| 138 | Use this option only if your scenario does not require signature verification. |
| 139 | --nfd=[VERSION] |
| 140 | Set NFD version. |
| 141 | --psync=[VERSION] |
| 142 | Set PSync version. |
| 143 | --nlsr=[VERSION] |
| 144 | Set NLSR version. |
| 145 | --tools=[VERSION] |
| 146 | Set NDN Essential Tools version. |
| 147 | --traffic=[VERSION] |
| 148 | Set NDN Traffic Generator version. |
| 149 | --infoedit=[VERSION] |
| 150 | Set infoedit version. |
| 151 | --mininet=[VERSION] |
| 152 | Set Mininet version. |
| 153 | --mnwifi=[VERSION] |
| 154 | Set Mininet-WiFi version. |
| 155 | Acceptable version syntaxes: |
| 156 | * git commit/tag/branch, example: --nfd=NFD-0.7.1 |
| 157 | * git repository (e.g. fork) and commit/tag/branch, example: |
| 158 | --nfd=https://github.com/named-data/NFD.git@NFD-0.7.1 |
| 159 | * change,patchset on named-data Gerrit, example: --nfd=6236,8 |
| 160 | |
| 161 | Misc options: |
| 162 | --dl-only |
| 163 | Download the source code only. |
| 164 | You may modify the code in ${CODEROOT} and then rerun this script to install them. |
| 165 | --ignore-existing |
| 166 | Ignore already installed binaries and libraries, and attempt to reinstall. |
| 167 | This is useful if you have modified source code checkout and want to install again. |
| 168 | EOT |
| 169 | exit 0 |
| 170 | fi |
| 171 | |
| 172 | trap 'set +e; trap - ERR; echo "Error!"; exit 1;' ERR |
| 173 | |
| 174 | PKGDEPDIR="$(pwd)/util/pkgdep" |
| 175 | if [[ -e /etc/os-release ]]; then |
| 176 | source /etc/os-release |
| 177 | fi |
| 178 | for id in ${ID,,} ${ID_LIKE,,}; do |
| 179 | if [[ -e $PKGDEPDIR/$id.sh ]]; then |
| 180 | source "$PKGDEPDIR/$id.sh" |
| 181 | source "$PKGDEPDIR/common.sh" |
| 182 | exit 0 |
| 183 | fi |
| 184 | done |
| 185 | echo "Unsupported platform ${ID}, aborting" |
| 186 | exit 1 |