3 # setup-linux.sh -- install everything needed to build rsync on Ubuntu.
5 # Tested on Ubuntu 22.04.5 LTS and 26.04 LTS. Covers both build systems:
6 # the autoconf one (./configure && make) and the CMake one (CMakeLists.txt),
7 # plus the optional feature libraries and the manpage generator.
10 # ./setup-linux.sh # install required + optional
11 # ./setup-linux.sh --minimal # required only (no ACLs/xattrs/zstd/...)
12 # ./setup-linux.sh --dry-run # show what would be installed
14 # Safe to re-run: apt skips anything already present.
23 --minimal) MINIMAL=1 ;;
24 --dry-run) DRY_RUN=1 ;;
26 sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//'
29 echo "setup-linux.sh: unknown option '$arg' (try --help)" >&2
34 # ---------------------------------------------------------------- helpers
36 red() { printf '\033[31m%s\033[0m\n' "$*"; }
37 green() { printf '\033[32m%s\033[0m\n' "$*"; }
38 bold() { printf '\033[1m%s\033[0m\n' "$*"; }
40 die() { red "ERROR: $*"; exit 1; }
42 # ------------------------------------------------------- sanity checks
44 command -v apt-get >/dev/null 2>&1 \
45 || die "no apt-get found -- this script is for Debian/Ubuntu systems."
49 if [ -r /etc/os-release ]; then
50 # shellcheck disable=SC1091 # runtime file, not available to the linter
52 DISTRO="${ID:-unknown}"
53 RELEASE="${VERSION_ID:-unknown}"
56 bold "rsync build dependencies"
57 echo " distro ......... ${PRETTY_NAME:-$DISTRO $RELEASE}"
58 echo " architecture ... $(uname -m)"
61 ubuntu|debian|linuxmint|pop) ;;
63 red "Warning: this script targets Ubuntu/Debian; '$DISTRO' is untested."
64 echo "Continuing anyway -- package names may differ."
68 # apt needs root. Re-exec under sudo rather than sprinkling it around, so
69 # that a single password prompt covers the whole run.
70 if [ "$(id -u)" -ne 0 ] && [ "$DRY_RUN" -eq 0 ]; then
71 command -v sudo >/dev/null 2>&1 \
72 || die "not running as root and sudo is not installed."
74 echo "Re-running under sudo..."
75 # Plain sudo, not "sudo -E": some sudoers configs refuse to preserve the
76 # environment, and the exports below happen in the root instance anyway.
80 export DEBIAN_FRONTEND=noninteractive
81 export NEEDRESTART_MODE=a # don't prompt about restarting services
83 # ------------------------------------------------------------- packages
85 # Needed to build rsync at all.
87 build-essential # gcc, g++, make, libc headers
88 gawk # rsync needs a modern awk for its code generators
89 autoconf # ./configure is generated from configure.ac
91 python3 # manpage + header generators, and the test suite
92 cmake # the CMake build
93 ninja-build # ...and its default generator
94 git # version stamping (git-version.h)
98 # Optional: each one switches on an rsync feature. Missing ones only mean
99 # a smaller feature set, never a failed build.
101 acl libacl1-dev # --acls (helper tools also used by the tests)
102 attr libattr1-dev # --xattrs (likewise)
103 libxxhash-dev # xxhash checksums (becomes the default)
104 libzstd-dev # zstd compression (becomes the default)
105 liblz4-dev # lz4 compression
106 libssl-dev # OpenSSL MD4/MD5
107 zlib1g-dev # for cmake -DRSYNC_EXTERNAL_ZLIB=ON
108 libpopt-dev # for ./configure --with-included-popt=no
111 # Development tooling: not needed to build rsync, but useful when working on
112 # its shell scripts -- including this one, which shellcheck keeps honest.
116 OPTIONAL+=("${DEVTOOLS[@]}")
118 # The manpages need one of two python3 markdown libraries; upstream prefers
119 # cmarkgfm. Pick whichever this release actually offers.
121 for p in python3-cmarkgfm python3-commonmark; do
122 cand=$(apt-cache policy "$p" 2>/dev/null | awk '/Candidate:/{print $2}')
123 if [ -n "$cand" ] && [ "$cand" != "(none)" ]; then
128 if [ -n "$MARKDOWN_PKG" ]; then
129 OPTIONAL+=("$MARKDOWN_PKG")
132 if [ "$MINIMAL" -eq 1 ]; then
136 if [ "$DRY_RUN" -eq 1 ]; then
138 bold "Would install (required):"
139 printf ' %s\n' "${REQUIRED[@]}"
140 if [ ${#OPTIONAL[@]} -gt 0 ]; then
141 bold "Would install (optional):"
142 printf ' %s\n' "${OPTIONAL[@]}"
147 # ------------------------------------------------------------- install
150 bold "Updating package lists..."
151 if ! apt-get update -qq; then
152 red "apt-get update failed -- continuing with the cached lists."
156 bold "Installing required packages..."
157 if ! apt-get install -y "${REQUIRED[@]}"; then
158 # Fall back to one-at-a-time so the failing package is obvious.
159 red "Bulk install failed; retrying individually to find the culprit..."
161 for p in "${REQUIRED[@]}"; do
162 apt-get install -y "$p" || FAILED+=("$p")
164 [ ${#FAILED[@]} -eq 0 ] || die "could not install: ${FAILED[*]}"
168 if [ ${#OPTIONAL[@]} -gt 0 ]; then
170 bold "Installing optional packages..."
171 if ! apt-get install -y "${OPTIONAL[@]}"; then
172 red "Bulk install failed; retrying individually..."
173 for p in "${OPTIONAL[@]}"; do
174 apt-get install -y "$p" || OPT_FAILED+=("$p")
179 # --------------------------------------------------------------- verify
182 bold "Verifying the toolchain..."
186 if command -v "$1" >/dev/null 2>&1; then
187 printf ' %-16s %s\n' "$1" "$(command -v "$1")"
189 printf ' %-16s %s\n' "$1" "MISSING"
194 for c in gcc g++ make gawk autoconf automake cmake ninja python3 git; do
198 # Not required to build, so report it without failing the run.
199 if command -v shellcheck >/dev/null 2>&1; then
200 printf ' %-16s %s\n' "shellcheck" "$(command -v shellcheck)"
202 printf ' %-16s %s\n' "shellcheck" "not installed (optional)"
206 bold "Verifying optional libraries..."
208 # $1 = human name, $2 = header path
209 if [ -e "/usr/include/$2" ] || \
210 find /usr/include -maxdepth 3 -name "$(basename "$2")" -print -quit \
211 2>/dev/null | grep -q .; then
212 printf ' %-16s yes\n' "$1"
214 printf ' %-16s no\n' "$1"
217 check_header acl sys/acl.h
218 check_header xattr sys/xattr.h
219 check_header xxhash xxhash.h
220 check_header zstd zstd.h
221 check_header lz4 lz4.h
222 check_header openssl openssl/md5.h
223 check_header zlib zlib.h
226 bold "Verifying the manpage generator..."
228 for m in cmarkgfm commonmark; do
229 if python3 -c "import $m" >/dev/null 2>&1; then
230 echo " python3 module '$m' importable"
235 if [ "$MD_OK" -eq 0 ]; then
236 if [ "$MINIMAL" -eq 1 ]; then
237 echo " skipped (--minimal); build with ./configure --disable-md2man"
239 red " neither cmarkgfm nor commonmark is importable."
240 echo " Install one with: python3 -mpip install --user commonmark"
241 echo " ...or build with: ./configure --disable-md2man"
245 # ---------------------------------------------------------------- done
248 if [ ${#MISSING[@]} -ne 0 ]; then
249 red "Missing required tools: ${MISSING[*]}"
253 if [ ${#OPT_FAILED[@]} -ne 0 ]; then
254 red "Optional packages that failed to install: ${OPT_FAILED[*]}"
255 echo "The build will still work, with those features disabled."
258 green "All required build dependencies are installed."
261 Build rsync with either build system:
263 autoconf: ./configure && make
264 CMake: cmake -B build -G Ninja && cmake --build build
266 Run the test suite (needs the autoconf build's helper programs):