• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2################################################################################
3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6################################################################################
7#
8# This script will install the llvm toolchain on the different
9# Debian and Ubuntu versions
10
11set -eux
12
13# read optional command line argument
14LLVM_VERSION=10
15if [ "$#" -eq 1 ]; then
16    LLVM_VERSION=$1
17fi
18
19DISTRO=$(lsb_release -is)
20VERSION=$(lsb_release -sr)
21DIST_VERSION="${DISTRO}_${VERSION}"
22
23if [[ $EUID -ne 0 ]]; then
24   echo "This script must be run as root!"
25   exit 1
26fi
27
28declare -A LLVM_VERSION_PATTERNS
29LLVM_VERSION_PATTERNS[9]="-9"
30LLVM_VERSION_PATTERNS[10]="-10"
31LLVM_VERSION_PATTERNS[11]="-11"
32
33if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
34    echo "This script does not support LLVM version $LLVM_VERSION"
35    exit 3
36fi
37
38LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]}
39
40# find the right repository name for the distro and version
41case "$DIST_VERSION" in
42    Debian_9* )       REPO_NAME="deb http://apt.llvm.org/stretch/  llvm-toolchain-stretch$LLVM_VERSION_STRING main" ;;
43    Debian_10* )      REPO_NAME="deb http://apt.llvm.org/buster/   llvm-toolchain-buster$LLVM_VERSION_STRING  main" ;;
44    Debian_unstable ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING         main" ;;
45    Debian_testing )  REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING         main" ;;
46    Ubuntu_16.04 )    REPO_NAME="deb http://apt.llvm.org/xenial/   llvm-toolchain-xenial$LLVM_VERSION_STRING  main" ;;
47    Ubuntu_18.04 )    REPO_NAME="deb http://apt.llvm.org/bionic/   llvm-toolchain-bionic$LLVM_VERSION_STRING  main" ;;
48    Ubuntu_18.10 )    REPO_NAME="deb http://apt.llvm.org/cosmic/   llvm-toolchain-cosmic$LLVM_VERSION_STRING  main" ;;
49    Ubuntu_19.04 )    REPO_NAME="deb http://apt.llvm.org/disco/    llvm-toolchain-disco$LLVM_VERSION_STRING   main" ;;
50    Ubuntu_19.10 )   REPO_NAME="deb http://apt.llvm.org/eoan/      llvm-toolchain-eoan$LLVM_VERSION_STRING    main" ;;
51    Ubuntu_20.04 )   REPO_NAME="deb http://apt.llvm.org/focal/     llvm-toolchain-focal$LLVM_VERSION_STRING    main" ;;
52    * )
53        echo "Distribution '$DISTRO' in version '$VERSION' is not supported by this script (${DIST_VERSION})."
54        exit 2
55esac
56
57
58# install everything
59wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
60add-apt-repository "${REPO_NAME}"
61apt-get update
62apt-get install -y clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION
63