mirror of https://github.com/aminya/setup-cpp.git
Merge pull request #331 from aminya/llvm-remove-repo [skip ci]
feat: remove the LLVM repo on apt install failures + support LLVM 11-16 on Ubuntu 24 + fix GCC on Linux Arm64 + install GCC without PPA if possible
This commit is contained in:
commit
60dbf57778
|
|
@ -0,0 +1,147 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# This script will remove the llvm repository from the system
|
||||
# It's the opposite of https://apt.llvm.org/llvm.sh
|
||||
|
||||
set -eux
|
||||
|
||||
CURRENT_LLVM_STABLE=18
|
||||
BASE_URL="http://apt.llvm.org"
|
||||
|
||||
# Check for required tools
|
||||
needed_binaries=(lsb_release wget add-apt-repository gpg)
|
||||
missing_binaries=()
|
||||
for binary in "${needed_binaries[@]}"; do
|
||||
if ! which $binary &>/dev/null ; then
|
||||
missing_binaries+=($binary)
|
||||
fi
|
||||
done
|
||||
if [[ ${#missing_binaries[@]} -gt 0 ]] ; then
|
||||
echo "You are missing some tools this script requires: ${missing_binaries[@]}"
|
||||
echo "(hint: apt install lsb-release wget software-properties-common gnupg)"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# Set default values for commandline arguments
|
||||
# We default to the current stable branch of LLVM
|
||||
LLVM_VERSION=$CURRENT_LLVM_STABLE
|
||||
ALL=0
|
||||
DISTRO=$(lsb_release -is)
|
||||
VERSION=$(lsb_release -sr)
|
||||
UBUNTU_CODENAME=""
|
||||
CODENAME_FROM_ARGUMENTS=""
|
||||
# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives)
|
||||
source /etc/os-release
|
||||
DISTRO=${DISTRO,,}
|
||||
case ${DISTRO} in
|
||||
debian)
|
||||
# Debian Trixie has a workaround because of
|
||||
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383
|
||||
if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then
|
||||
CODENAME=unstable
|
||||
LINKNAME=
|
||||
else
|
||||
# "stable" Debian release
|
||||
CODENAME=${VERSION_CODENAME}
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# ubuntu and its derivatives
|
||||
if [[ -n "${UBUNTU_CODENAME}" ]]; then
|
||||
CODENAME=${UBUNTU_CODENAME}
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# read optional command line arguments
|
||||
if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then
|
||||
if [ "$1" != "all" ]; then
|
||||
LLVM_VERSION=$1
|
||||
else
|
||||
# special case for ./llvm.sh all
|
||||
ALL=1
|
||||
fi
|
||||
OPTIND=2
|
||||
if [ "$#" -ge 2 ]; then
|
||||
if [ "$2" == "all" ]; then
|
||||
# Install all packages
|
||||
ALL=1
|
||||
OPTIND=3
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
while getopts ":hm:n:" arg; do
|
||||
case $arg in
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
m)
|
||||
BASE_URL=${OPTARG}
|
||||
;;
|
||||
n)
|
||||
CODENAME=${OPTARG}
|
||||
if [[ "${CODENAME}" == "unstable" ]]; then
|
||||
# link name does not apply to unstable repository
|
||||
LINKNAME=
|
||||
else
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
CODENAME_FROM_ARGUMENTS="true"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
declare -A LLVM_VERSION_PATTERNS
|
||||
LLVM_VERSION_PATTERNS[9]="-9"
|
||||
LLVM_VERSION_PATTERNS[10]="-10"
|
||||
LLVM_VERSION_PATTERNS[11]="-11"
|
||||
LLVM_VERSION_PATTERNS[12]="-12"
|
||||
LLVM_VERSION_PATTERNS[13]="-13"
|
||||
LLVM_VERSION_PATTERNS[14]="-14"
|
||||
LLVM_VERSION_PATTERNS[15]="-15"
|
||||
LLVM_VERSION_PATTERNS[16]="-16"
|
||||
LLVM_VERSION_PATTERNS[17]="-17"
|
||||
LLVM_VERSION_PATTERNS[18]="-18"
|
||||
LLVM_VERSION_PATTERNS[19]="-19"
|
||||
LLVM_VERSION_PATTERNS[20]=""
|
||||
|
||||
if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
|
||||
echo "This script does not support LLVM version $LLVM_VERSION"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]}
|
||||
|
||||
# join the repository name
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main"
|
||||
|
||||
# check if the repository exists for the distro and version
|
||||
if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null; then
|
||||
if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then
|
||||
echo "Specified codename '${CODENAME}' is not supported by this script."
|
||||
else
|
||||
echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script."
|
||||
fi
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then
|
||||
# add it twice to workaround:
|
||||
# https://github.com/llvm/llvm-project/issues/62475
|
||||
add-apt-repository -y "${REPO_NAME}"
|
||||
fi
|
||||
|
||||
add-apt-repository -y --no-update --remove "${REPO_NAME}"
|
||||
apt-get update
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,147 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# This script will remove the llvm repository from the system
|
||||
# It's the opposite of https://apt.llvm.org/llvm.sh
|
||||
|
||||
set -eux
|
||||
|
||||
CURRENT_LLVM_STABLE=18
|
||||
BASE_URL="http://apt.llvm.org"
|
||||
|
||||
# Check for required tools
|
||||
needed_binaries=(lsb_release wget add-apt-repository gpg)
|
||||
missing_binaries=()
|
||||
for binary in "${needed_binaries[@]}"; do
|
||||
if ! which $binary &>/dev/null ; then
|
||||
missing_binaries+=($binary)
|
||||
fi
|
||||
done
|
||||
if [[ ${#missing_binaries[@]} -gt 0 ]] ; then
|
||||
echo "You are missing some tools this script requires: ${missing_binaries[@]}"
|
||||
echo "(hint: apt install lsb-release wget software-properties-common gnupg)"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# Set default values for commandline arguments
|
||||
# We default to the current stable branch of LLVM
|
||||
LLVM_VERSION=$CURRENT_LLVM_STABLE
|
||||
ALL=0
|
||||
DISTRO=$(lsb_release -is)
|
||||
VERSION=$(lsb_release -sr)
|
||||
UBUNTU_CODENAME=""
|
||||
CODENAME_FROM_ARGUMENTS=""
|
||||
# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives)
|
||||
source /etc/os-release
|
||||
DISTRO=${DISTRO,,}
|
||||
case ${DISTRO} in
|
||||
debian)
|
||||
# Debian Trixie has a workaround because of
|
||||
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383
|
||||
if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then
|
||||
CODENAME=unstable
|
||||
LINKNAME=
|
||||
else
|
||||
# "stable" Debian release
|
||||
CODENAME=${VERSION_CODENAME}
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# ubuntu and its derivatives
|
||||
if [[ -n "${UBUNTU_CODENAME}" ]]; then
|
||||
CODENAME=${UBUNTU_CODENAME}
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# read optional command line arguments
|
||||
if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then
|
||||
if [ "$1" != "all" ]; then
|
||||
LLVM_VERSION=$1
|
||||
else
|
||||
# special case for ./llvm.sh all
|
||||
ALL=1
|
||||
fi
|
||||
OPTIND=2
|
||||
if [ "$#" -ge 2 ]; then
|
||||
if [ "$2" == "all" ]; then
|
||||
# Install all packages
|
||||
ALL=1
|
||||
OPTIND=3
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
while getopts ":hm:n:" arg; do
|
||||
case $arg in
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
m)
|
||||
BASE_URL=${OPTARG}
|
||||
;;
|
||||
n)
|
||||
CODENAME=${OPTARG}
|
||||
if [[ "${CODENAME}" == "unstable" ]]; then
|
||||
# link name does not apply to unstable repository
|
||||
LINKNAME=
|
||||
else
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
CODENAME_FROM_ARGUMENTS="true"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
declare -A LLVM_VERSION_PATTERNS
|
||||
LLVM_VERSION_PATTERNS[9]="-9"
|
||||
LLVM_VERSION_PATTERNS[10]="-10"
|
||||
LLVM_VERSION_PATTERNS[11]="-11"
|
||||
LLVM_VERSION_PATTERNS[12]="-12"
|
||||
LLVM_VERSION_PATTERNS[13]="-13"
|
||||
LLVM_VERSION_PATTERNS[14]="-14"
|
||||
LLVM_VERSION_PATTERNS[15]="-15"
|
||||
LLVM_VERSION_PATTERNS[16]="-16"
|
||||
LLVM_VERSION_PATTERNS[17]="-17"
|
||||
LLVM_VERSION_PATTERNS[18]="-18"
|
||||
LLVM_VERSION_PATTERNS[19]="-19"
|
||||
LLVM_VERSION_PATTERNS[20]=""
|
||||
|
||||
if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
|
||||
echo "This script does not support LLVM version $LLVM_VERSION"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]}
|
||||
|
||||
# join the repository name
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main"
|
||||
|
||||
# check if the repository exists for the distro and version
|
||||
if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null; then
|
||||
if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then
|
||||
echo "Specified codename '${CODENAME}' is not supported by this script."
|
||||
else
|
||||
echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script."
|
||||
fi
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then
|
||||
# add it twice to workaround:
|
||||
# https://github.com/llvm/llvm-project/issues/62475
|
||||
add-apt-repository -y "${REPO_NAME}"
|
||||
fi
|
||||
|
||||
add-apt-repository -y --no-update --remove "${REPO_NAME}"
|
||||
apt-get update
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -26,10 +26,11 @@
|
|||
"tsconfig.json"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "turbo build && run-p lint.root.tsc build.vite build.vite.legacy && run-s build.json",
|
||||
"build": "turbo build && run-p lint.root.tsc build.vite build.vite.legacy && run-p build.json build.bash",
|
||||
"build.vite": "cross-env NODE_ENV=production vite build",
|
||||
"build.vite.legacy": "cross-env NODE_ENV=production TARGET=legacy vite build",
|
||||
"build.json": "shx cp ./src/*/*.json ./dist/legacy/ && shx cp ./dist/legacy/*.json ./dist/modern && minijson --file ./dist/**/*.json",
|
||||
"build.bash": "shx cp ./src/*/*.bash ./dist/legacy/ && shx cp ./dist/legacy/*.bash ./dist/modern",
|
||||
"bump": "ncu -u -x execa,numerous,eslint,@types/eslint,which && pnpm update && pnpx typesync && pnpm run clean",
|
||||
"bump.llvm": "GITHUB_TOKEN=$(gh auth token) tsx ./src/llvm/assets-list.ts",
|
||||
"bump.gcc": "GITHUB_TOKEN=$(gh auth token) tsx ./src/gcc/assets-list.ts",
|
||||
|
|
@ -191,7 +192,7 @@
|
|||
"node": ">=12.x",
|
||||
"pnpm": "^9"
|
||||
},
|
||||
"packageManager": "pnpm@9.15.3",
|
||||
"packageManager": "pnpm@9.15.4",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "setup-apt",
|
||||
"version": "2.0.2",
|
||||
"version": "2.1.0",
|
||||
"description": "Setup apt packages and repositories in Debian/Ubuntu-based distributions",
|
||||
"repository": "https://github.com/aminya/setup-cpp",
|
||||
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/setup-apt",
|
||||
|
|
|
|||
|
|
@ -26,3 +26,16 @@ export async function installAddAptRepo(apt: string) {
|
|||
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
||||
)
|
||||
}
|
||||
|
||||
export async function removeAptRepository(repo: string, apt = getApt()) {
|
||||
await initAptMemoized(apt)
|
||||
await installAddAptRepo(apt)
|
||||
execRootSync("add-apt-repository", ["-y", "--no-update", "--remove", repo], {
|
||||
...defaultExecOptions,
|
||||
env: getAptEnv(apt),
|
||||
})
|
||||
|
||||
// Update the repos
|
||||
updateAptReposMemoized.clear() // ensure update is called
|
||||
updateAptReposMemoized(apt)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,20 +37,32 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
|
|||
break
|
||||
}
|
||||
case "linux": {
|
||||
if (arch === "x64") {
|
||||
if (isArch()) {
|
||||
installationInfo = await setupPacmanPack("gcc", version)
|
||||
} else if (hasDnf()) {
|
||||
installationInfo = await setupDnfPack([
|
||||
{ name: "gcc", version },
|
||||
{ name: "gcc-c++", version },
|
||||
{ name: "libstdc++-devel" },
|
||||
])
|
||||
} else if (isUbuntu()) {
|
||||
if (version === "") {
|
||||
// the default version
|
||||
installationInfo = await installAptPack([{ name: "gcc" }, { name: "g++" }])
|
||||
} else {
|
||||
if (isArch()) {
|
||||
installationInfo = await setupPacmanPack("gcc", version)
|
||||
} else if (hasDnf()) {
|
||||
installationInfo = await setupDnfPack([
|
||||
{ name: "gcc", version },
|
||||
{ name: "gcc-c++", version },
|
||||
{ name: "libstdc++-devel" },
|
||||
])
|
||||
} else if (isUbuntu()) {
|
||||
if (version === "") {
|
||||
// the default version
|
||||
installationInfo = await installAptPack([{ name: "gcc" }, { name: "g++" }])
|
||||
} else {
|
||||
try {
|
||||
// first try to install the version from the default repository
|
||||
installationInfo = await installAptPack([
|
||||
{
|
||||
name: "gcc",
|
||||
version,
|
||||
},
|
||||
{
|
||||
name: "g++",
|
||||
version,
|
||||
},
|
||||
])
|
||||
} catch (err) {
|
||||
// add the PPA for access to more versions
|
||||
installationInfo = await installAptPack([
|
||||
{
|
||||
|
|
@ -68,25 +80,30 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
|
|||
])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
||||
if (isArch()) {
|
||||
installationInfo = await setupPacmanPack("gcc-multilib", version)
|
||||
} else if (isUbuntu()) {
|
||||
if (version === "") {
|
||||
// the default version
|
||||
installationInfo = await installAptPack([{ name: "gcc-multilib" }])
|
||||
} else {
|
||||
// add the PPA for access to more versions
|
||||
installationInfo = await installAptPack([{
|
||||
name: "gcc-multilib",
|
||||
version,
|
||||
repository: "ppa:ubuntu-toolchain-r/test",
|
||||
key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
|
||||
}])
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (arch !== "x64") {
|
||||
// try {
|
||||
// info(`Install g++-multilib because gcc for ${arch} was requested`)
|
||||
// if (isArch()) {
|
||||
// installationInfo = await setupPacmanPack("gcc-multilib", version)
|
||||
// } else if (isUbuntu()) {
|
||||
// if (version === "") {
|
||||
// // the default version
|
||||
// installationInfo = await installAptPack([{ name: "gcc-multilib" }])
|
||||
// } else {
|
||||
// // add the PPA for access to more versions
|
||||
// installationInfo = await installAptPack([{
|
||||
// name: "gcc-multilib",
|
||||
// version,
|
||||
// repository: "ppa:ubuntu-toolchain-r/test",
|
||||
// key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" },
|
||||
// }])
|
||||
// }
|
||||
// }
|
||||
// } catch (err) {
|
||||
// info(`Failed to install gcc-multilib ${err}\nSkipping the dependency`)
|
||||
// }
|
||||
// }
|
||||
break
|
||||
}
|
||||
// TODO support bare-metal (need to support passing it as the input)
|
||||
|
|
|
|||
|
|
@ -71,12 +71,17 @@ async function setupLLVMOnly(
|
|||
packages: LLVMPackages = LLVMPackages.All,
|
||||
) {
|
||||
const majorVersion = majorLLVMVersion(version)
|
||||
try {
|
||||
if (isUbuntu()) {
|
||||
if (isUbuntu()) {
|
||||
try {
|
||||
return await setupLLVMApt(majorVersion, packages)
|
||||
} catch (err) {
|
||||
info(`Failed to install llvm via system package manager ${err}. Trying to remove the repository`)
|
||||
try {
|
||||
execRootSync(join(dirname, "llvm_repo_remove.bash"), [`${majorVersion}`])
|
||||
} catch (err) {
|
||||
info(`Failed to remove llvm repository ${err}`)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
info(`Failed to install llvm via system package manager ${err}`)
|
||||
}
|
||||
|
||||
const installationInfo = await setupBin("llvm", version, getLLVMPackageInfo, setupDir, arch)
|
||||
|
|
@ -114,7 +119,11 @@ async function llvmBinaryDeps_(majorVersion: number) {
|
|||
execRootSync("dpkg", ["-i", join(tmpdir(), fileName)])
|
||||
}
|
||||
} else {
|
||||
await installAptPack([{ name: "libtinfo-dev" }])
|
||||
try {
|
||||
await installAptPack([{ name: "libtinfo6" }])
|
||||
} catch (err) {
|
||||
info(`Failed to install libtinfo6 ${err}\nSkipping the dependency`)
|
||||
}
|
||||
}
|
||||
} else if (isArch()) {
|
||||
// https://aur.archlinux.org/packages/ncurses5-compat-libs
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ function debugScript(script: string) {
|
|||
function nonInteractiveScript(script: string) {
|
||||
// make the scirpt non-interactive and fix broken packages
|
||||
return script.replace(
|
||||
/add-apt-repository "\${REPO_NAME}"/g,
|
||||
/add-apt-repository\s*(-y)?\s*"\${REPO_NAME}"/g,
|
||||
`add-apt-repository -y -n "\${REPO_NAME}"
|
||||
apt-get update -o ${aptTimeout} -y`,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,147 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# This script will remove the llvm repository from the system
|
||||
# It's the opposite of https://apt.llvm.org/llvm.sh
|
||||
|
||||
set -eux
|
||||
|
||||
CURRENT_LLVM_STABLE=18
|
||||
BASE_URL="http://apt.llvm.org"
|
||||
|
||||
# Check for required tools
|
||||
needed_binaries=(lsb_release wget add-apt-repository gpg)
|
||||
missing_binaries=()
|
||||
for binary in "${needed_binaries[@]}"; do
|
||||
if ! which $binary &>/dev/null ; then
|
||||
missing_binaries+=($binary)
|
||||
fi
|
||||
done
|
||||
if [[ ${#missing_binaries[@]} -gt 0 ]] ; then
|
||||
echo "You are missing some tools this script requires: ${missing_binaries[@]}"
|
||||
echo "(hint: apt install lsb-release wget software-properties-common gnupg)"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# Set default values for commandline arguments
|
||||
# We default to the current stable branch of LLVM
|
||||
LLVM_VERSION=$CURRENT_LLVM_STABLE
|
||||
ALL=0
|
||||
DISTRO=$(lsb_release -is)
|
||||
VERSION=$(lsb_release -sr)
|
||||
UBUNTU_CODENAME=""
|
||||
CODENAME_FROM_ARGUMENTS=""
|
||||
# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives)
|
||||
source /etc/os-release
|
||||
DISTRO=${DISTRO,,}
|
||||
case ${DISTRO} in
|
||||
debian)
|
||||
# Debian Trixie has a workaround because of
|
||||
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383
|
||||
if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then
|
||||
CODENAME=unstable
|
||||
LINKNAME=
|
||||
else
|
||||
# "stable" Debian release
|
||||
CODENAME=${VERSION_CODENAME}
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# ubuntu and its derivatives
|
||||
if [[ -n "${UBUNTU_CODENAME}" ]]; then
|
||||
CODENAME=${UBUNTU_CODENAME}
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# read optional command line arguments
|
||||
if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then
|
||||
if [ "$1" != "all" ]; then
|
||||
LLVM_VERSION=$1
|
||||
else
|
||||
# special case for ./llvm.sh all
|
||||
ALL=1
|
||||
fi
|
||||
OPTIND=2
|
||||
if [ "$#" -ge 2 ]; then
|
||||
if [ "$2" == "all" ]; then
|
||||
# Install all packages
|
||||
ALL=1
|
||||
OPTIND=3
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
while getopts ":hm:n:" arg; do
|
||||
case $arg in
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
m)
|
||||
BASE_URL=${OPTARG}
|
||||
;;
|
||||
n)
|
||||
CODENAME=${OPTARG}
|
||||
if [[ "${CODENAME}" == "unstable" ]]; then
|
||||
# link name does not apply to unstable repository
|
||||
LINKNAME=
|
||||
else
|
||||
LINKNAME=-${CODENAME}
|
||||
fi
|
||||
CODENAME_FROM_ARGUMENTS="true"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
declare -A LLVM_VERSION_PATTERNS
|
||||
LLVM_VERSION_PATTERNS[9]="-9"
|
||||
LLVM_VERSION_PATTERNS[10]="-10"
|
||||
LLVM_VERSION_PATTERNS[11]="-11"
|
||||
LLVM_VERSION_PATTERNS[12]="-12"
|
||||
LLVM_VERSION_PATTERNS[13]="-13"
|
||||
LLVM_VERSION_PATTERNS[14]="-14"
|
||||
LLVM_VERSION_PATTERNS[15]="-15"
|
||||
LLVM_VERSION_PATTERNS[16]="-16"
|
||||
LLVM_VERSION_PATTERNS[17]="-17"
|
||||
LLVM_VERSION_PATTERNS[18]="-18"
|
||||
LLVM_VERSION_PATTERNS[19]="-19"
|
||||
LLVM_VERSION_PATTERNS[20]=""
|
||||
|
||||
if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
|
||||
echo "This script does not support LLVM version $LLVM_VERSION"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]}
|
||||
|
||||
# join the repository name
|
||||
if [[ -n "${CODENAME}" ]]; then
|
||||
REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main"
|
||||
|
||||
# check if the repository exists for the distro and version
|
||||
if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null; then
|
||||
if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then
|
||||
echo "Specified codename '${CODENAME}' is not supported by this script."
|
||||
else
|
||||
echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script."
|
||||
fi
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then
|
||||
# add it twice to workaround:
|
||||
# https://github.com/llvm/llvm-project/issues/62475
|
||||
add-apt-repository -y "${REPO_NAME}"
|
||||
fi
|
||||
|
||||
add-apt-repository -y --no-update --remove "${REPO_NAME}"
|
||||
apt-get update
|
||||
Loading…
Reference in New Issue