blob: 1f795de833a7c23aa7001a0c82597e9bec5d659c [file] [log] [blame]
ashu2ad32e22015-05-29 13:37:40 -05001#!/bin/bash
Vince Lehmanb8b18062015-07-14 13:07:22 -05002# -*- Mode:bash; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
3#
Junxiao Shi48ada892021-11-04 09:02:21 -06004# Copyright (C) 2015-2021, The University of Memphis,
Ashlesh Gawande0cccdb82016-08-15 12:58:06 -05005# Arizona Board of Regents,
6# Regents of the University of California.
Vince Lehmanb8b18062015-07-14 13:07:22 -05007#
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/>.
ashu2ad32e22015-05-29 13:37:40 -050024
Junxiao Shi48ada892021-11-04 09:02:21 -060025set -eo pipefail
26cd "$(dirname "${BASH_SOURCE[0]}")"
ashu2ad32e22015-05-29 13:37:40 -050027
Junxiao Shi48ada892021-11-04 09:02:21 -060028# 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.
30NEEDED_BINARIES=(
31 awk
32 git
33 sudo
34)
35MISSING_BINARIES=()
ashu2ad32e22015-05-29 13:37:40 -050036
Junxiao Shi48ada892021-11-04 09:02:21 -060037SUDO=
38if [[ $(id -u) -eq 0 ]]; then
39 if [[ -n $SUDO_USER ]] && [[ -z $SKIPSUDOCHECK ]]; then
40 cat <<EOT
41Do not run this script through sudo
42Instead, run this script as a regular user; the script will call sudo when needed
43To bypass this check, set the environment variable SKIPSUDOCHECK=1
44EOT
45 exit 1
46 fi
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050047else
Junxiao Shi48ada892021-11-04 09:02:21 -060048 SUDO=sudo
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050049fi
50
Junxiao Shi48ada892021-11-04 09:02:21 -060051for B in "${NEEDED_BINARIES[@]}"; do
52 if ! command -v "$B" >/dev/null; then
53 MISSING_BINARIES+=("$B")
54 fi
55done
56if [[ ${#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 Gawande670ff152018-06-08 12:26:39 -050061fi
Junxiao Shi48ada892021-11-04 09:02:21 -060062
63CODEROOT="$(pwd)/dl"
64NJOBS=$(nproc)
65MEM_JOBS=$(awk '$1=="MemAvailable:" { print int($2/(1536*1024)); exit }' /proc/meminfo)
66if [[ $MEM_JOBS -lt 1 ]]; then
67 NJOBS=1
68 echo 'Insufficient available RAM, build may fail'
69elif [[ $MEM_JOBS -lt $NJOBS ]]; then
70 NJOBS=$MEM_JOBS
71fi
72PREFER_FROM=ppa
73PPA_PKGS=()
74
75ARGS=$(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' -- "$@")
76eval set -- "$ARGS"
77while 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
101done
102
103if [[ $NJOBS -le 0 ]]; then
104 cat <<EOT
105--jobs must be a positive integer.
106Run ./install.sh -h to see help message.
107EOT
108 exit 1
109fi
110
111if [[ $HELP -eq 1 ]]; then
112 cat <<EOT
113./install.sh [OPTION]...
114
115General 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
125Install 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
132Source 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.
155Acceptable 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
161Misc 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.
168EOT
169 exit 0
170fi
171
172trap 'set +e; trap - ERR; echo "Error!"; exit 1;' ERR
173
174PKGDEPDIR="$(pwd)/util/pkgdep"
175if [[ -e /etc/os-release ]]; then
176 source /etc/os-release
177fi
178for 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
184done
185echo "Unsupported platform ${ID}, aborting"
186exit 1