blob: 8d4ef9a7011f6c53e866eda8a97fcb34ebf9edb0 [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
awlane022b2bf2024-08-28 19:22:46 -050075ARGS=$(getopt -o 'hy' -l 'help,dir:,jobs:,no-wifi,ppa,source,release:,cxx:,dummy-keychain,nfd:,psync:,nlsr:,tools:,traffic:,infoedit:,mininet:,mnwifi:,dl-only,ignore-existing' -- "$@")
Junxiao Shi48ada892021-11-04 09:02:21 -060076eval 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;;
awlane022b2bf2024-08-28 19:22:46 -050086 --release) RELEASE_VERSION=$2; source util/releases/current_release.sh; NO_PPA=1; shift 2;;
Junxiao Shi48ada892021-11-04 09:02:21 -060087 --cxx) CXX_VERSION=$2; NO_PPA=1; shift 2;;
88 --dummy-keychain) CXX_DUMMY_KEYCHAIN=1; NO_PPA=1; shift;;
89 --nfd) NFD_VERSION=$2; NO_PPA=1; shift 2;;
90 --psync) PSYNC_VERSION=$2; NO_PPA=1; shift 2;;
91 --nlsr) NLSR_VERSION=$2; NO_PPA=1; shift 2;;
92 --tools) TOOLS_VERSION=$2; NO_PPA=1; shift 2;;
93 --traffic) TRAFFIC_VERSION=$2; NO_PPA=1; shift 2;;
94 --infoedit) INFOEDIT_VERSION=$2; shift 2;;
95 --mininet) MININET_VERSION=$2; shift 2;;
96 --mnwifi) MNWIFI_VERSION=$2; shift 2;;
97 --dl-only) DL_ONLY=1; shift;;
98 --ignore-existing) IGNORE_EXISTING=1; shift;;
99 --) shift; break;;
100 *) exit 1;;
101 esac
102done
103
104if [[ $NJOBS -le 0 ]]; then
105 cat <<EOT
106--jobs must be a positive integer.
107Run ./install.sh -h to see help message.
108EOT
109 exit 1
110fi
111
112if [[ $HELP -eq 1 ]]; then
113 cat <<EOT
114./install.sh [OPTION]...
115
116General options:
117 -h Display help and exit.
118 -y Skip confirmation.
119 --dir=${CODEROOT}
120 Set where to download and compile the code.
121 --jobs=${NJOBS}
122 Set number of parallel jobs.
123 --no-wifi
124 Do not install Mininet-WiFi.
125
126Install preference options:
127 --ppa
128 Install available packages from named-data PPA.
129 This is the default on Ubuntu, unless a source code version option is used.
130 --source
131 Install all packages from source code.
132
133Source code version options:
awlane022b2bf2024-08-28 19:22:46 -0500134 --release=[RELEASE]
135 Use specified major release. To install the most recent, use 'current'. A list of
136 other possible values is located in the installation docs.
Junxiao Shi48ada892021-11-04 09:02:21 -0600137 --cxx=[VERSION]
138 Set ndn-cxx version.
139 --dummy-keychain
140 Patch ndn-cxx to use dummy KeyChain.
141 This disables signing and verifications, which allows experiments to run faster.
142 Use this option only if your scenario does not require signature verification.
143 --nfd=[VERSION]
144 Set NFD version.
145 --psync=[VERSION]
146 Set PSync version.
147 --nlsr=[VERSION]
148 Set NLSR version.
149 --tools=[VERSION]
150 Set NDN Essential Tools version.
151 --traffic=[VERSION]
152 Set NDN Traffic Generator version.
153 --infoedit=[VERSION]
154 Set infoedit version.
155 --mininet=[VERSION]
156 Set Mininet version.
157 --mnwifi=[VERSION]
158 Set Mininet-WiFi version.
159Acceptable version syntaxes:
160 * git commit/tag/branch, example: --nfd=NFD-0.7.1
161 * git repository (e.g. fork) and commit/tag/branch, example:
162 --nfd=https://github.com/named-data/NFD.git@NFD-0.7.1
163 * change,patchset on named-data Gerrit, example: --nfd=6236,8
164
165Misc options:
166 --dl-only
167 Download the source code only.
168 You may modify the code in ${CODEROOT} and then rerun this script to install them.
169 --ignore-existing
170 Ignore already installed binaries and libraries, and attempt to reinstall.
171 This is useful if you have modified source code checkout and want to install again.
172EOT
173 exit 0
174fi
175
176trap 'set +e; trap - ERR; echo "Error!"; exit 1;' ERR
177
178PKGDEPDIR="$(pwd)/util/pkgdep"
179if [[ -e /etc/os-release ]]; then
180 source /etc/os-release
181fi
182for id in ${ID,,} ${ID_LIKE,,}; do
183 if [[ -e $PKGDEPDIR/$id.sh ]]; then
184 source "$PKGDEPDIR/$id.sh"
185 source "$PKGDEPDIR/common.sh"
186 exit 0
187 fi
188done
189echo "Unsupported platform ${ID}, aborting"
190exit 1