Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu 24.04, 23.10 Fedora 39 and Debian 12 #115

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ xcuserdata/
DerivedData/
.swiftpm/
.vscode/
.devcontainer/
130 changes: 112 additions & 18 deletions install/swiftly-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bold () {
echo "$(tput bold)$1$(tput sgr0)"
}

# Fetch the list of required system dependencies from the apple/swift-docker
# Fetch the list of required system dependencies from the swiftlang/swift-docker
# repository and attempt to install them using the system's package manager.
#
# $docker_platform_name, $docker_platform_version, and $package manager need
Expand All @@ -127,29 +127,39 @@ install_system_deps () {
return
fi

dockerfile_url="https://raw.githubusercontent.com/apple/swift-docker/main/nightly-main/$docker_platform_name/$docker_platform_version/Dockerfile"
dockerfile_url="https://raw.githubusercontent.com/swiftlang/swift-docker/main/nightly-main/$docker_platform_name/$docker_platform_version/Dockerfile"
set +e
dockerfile="$(curl --silent --retry 3 --location --fail $dockerfile_url)"
if [[ "$?" -ne 0 ]]; then
# if we couldn't find Dockerfile in nightly-main use swift-ci/master version
if [[ -z "$dockerfile" ]]; then
dockerfile_url="https://raw.githubusercontent.com/swiftlang/swift-docker/main/swift-ci/master/$docker_platform_name/$docker_platform_version/Dockerfile"
dockerfile="$(curl --silent --retry 3 --location --fail $dockerfile_url)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid duplicating this incantation, can we factor it out to a function we can call here and above? we can also move the set +e and set -e in there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want the curl call and set +e -e in a separate function or the full test one location if it doesn't exist test the other location

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking the curl and set +e -e so we could avoid duplicating the curl invocation. That way if we ever need to change the arguments or whatever we can do it in once place.

fi
set -e
if [[ -z "$dockerfile" ]]; then
echo "Error enumerating system dependencies, skipping installation of system dependencies."
return
fi

# Find the line number of the RUN command associated with installing system dependencies.
beg_line_num=$(printf "$dockerfile" | grep -n --max-count=1 "$package_manager.*install" | cut -d ":" -f1)
beg_line_num=$(echo "$dockerfile" | grep -n --max-count=1 "$package_manager.*install" | cut -d ":" -f1)

# Starting from there, find the first line that starts with an & or doesn't end in a backslash.
relative_end_line_num=$(printf "$dockerfile" |
relative_end_line_num=$(echo "$dockerfile" |
tail --lines=+"$((beg_line_num + 1))" |
grep -n --max-count=1 --invert-match '[[:space:]]*[^&].*\\$' | cut -d ":" -f1)
end_line_num=$((beg_line_num + relative_end_line_num))

# Read the lines between those two, deleting any spaces and backslashes.
readarray -t package_list < <(printf "$dockerfile" | sed -n "$((beg_line_num + 1)),${end_line_num}p" | sed -r 's/[\ ]//g')
readarray -t package_list < <(echo "$dockerfile" | sed -n "$((beg_line_num + 1)),${end_line_num}p" | sed -r 's/[\ ]//g')

# If the installation command from the Dockerfile included some cleanup as part of a second command, drop that.
if [[ "${package_list[-1]}" =~ ^\&\& ]]; then
unset 'package_list[-1]'
fi

echo "Found ${package_list[@]}"

# Always install gpg, since swiftly itself needs it for signature verification.
package_list+=("gpg")

Expand Down Expand Up @@ -209,6 +219,30 @@ set_platform_rhel () {
fi
}

set_platform_debian () {
PLATFORM_NAME="debian$1"
PLATFORM_NAME_FULL="debian$1"
docker_platform_name="debian"
docker_platform_version="$1"
package_manager="apt-get"

if [[ -z "$PLATFORM_NAME_PRETTY" ]]; then
PLATFORM_NAME_PRETTY="Debian $1"
fi
}

set_platform_fedora () {
PLATFORM_NAME="fedora$1"
PLATFORM_NAME_FULL="fedora$1"
docker_platform_name="fedora"
docker_platform_version="$1"
package_manager="yum"

if [[ -z "$PLATFORM_NAME_PRETTY" ]]; then
PLATFORM_NAME_PRETTY="Fedora Linux $1"
fi
}

detect_platform () {
if [[ -f "/etc/os-release" ]]; then
OS_RELEASE="/etc/os-release"
Expand All @@ -232,6 +266,14 @@ detect_platform () {

*"ubuntu"*)
case "$UBUNTU_CODENAME" in
"noble")
set_platform_ubuntu "24" "04"
;;

"mantic")
set_platform_ubuntu "23" "10"
;;

"jammy")
set_platform_ubuntu "22" "04"
;;
Expand All @@ -258,6 +300,22 @@ detect_platform () {
fi
;;

*"debian"*)
if [[ "$VERSION_ID" != 12 ]]; then
manually_select_platform
else
set_platform_debian "12"
fi
;;

*"fedora"*)
if [[ "$VERSION_ID" != 39 ]]; then
manually_select_platform
else
set_platform_fedora "39"
fi
;;

*)
manually_select_platform
;;
Expand All @@ -274,34 +332,54 @@ manually_select_platform () {
echo "Please select the platform to use for toolchain downloads:"

echo "0) Cancel"
echo "1) Ubuntu 22.04"
patrickfreed marked this conversation as resolved.
Show resolved Hide resolved
echo "2) Ubuntu 20.04"
echo "3) Ubuntu 18.04"
echo "4) RHEL 9"
echo "5) Amazon Linux 2"
echo "1) Ubuntu 24.04"
echo "2) Ubuntu 23.10"
echo "3) Ubuntu 22.04"
echo "4) Ubuntu 20.04"
echo "5) Ubuntu 18.04"
echo "6) RHEL 9"
echo "7) Amazon Linux 2"
echo "8) Debian 12"
echo "9) Fedora 39"

read_input_with_default "0"
case "$READ_INPUT_RETURN" in
"1" | "1)")
set_platform_ubuntu "22" "04"
set_platform_ubuntu "24" "04"
;;

"2" | "2)")
set_platform_ubuntu "20" "04"
set_platform_ubuntu "23" "10"
;;

"3" | "3)")
set_platform_ubuntu "18" "04"
set_platform_ubuntu "22" "04"
;;

"4" | "4)")
set_platform_rhel "9"
set_platform_ubuntu "20" "04"
;;

"5" | "5)")
set_platform_ubuntu "18" "04"
;;

"6" | "6)")
set_platform_rhel "9"
;;

"7" | "7)")
set_platform_amazonlinux "2"
;;

"8" | "8)")
set_platform_debian "12"
;;

"9" | "9)")
set_platform_fedora "39"
;;

*)
echo "Cancelling installation."
exit 0
Expand Down Expand Up @@ -362,8 +440,8 @@ OPTIONS:
--no-import-pgp-keys Do not attempt to import Swift's PGP keys.
-p, --platform <platform> Specifies which platform's toolchains swiftly will download. If
unspecified, the platform will be automatically detected. Available
options are "ubuntu22.04", "ubuntu20.04", "ubuntu18.04", "rhel9", and
"amazonlinux2".
options are "ubuntu24.04", "ubuntu23.10", "ubuntu22.04", "ubuntu20.04",
"ubuntu18.04", "rhel9", "amazonlinux2", "debian12 and "fedora39".
--overwrite Overwrite the existing swiftly installation found at the configured
SWIFTLY_HOME, if any. If this option is unspecified and an existing
installation is found, the swiftly executable will be updated, but
Expand Down Expand Up @@ -401,6 +479,14 @@ EOF

"--platform" | "-p")
case "$2" in
"ubuntu24.04")
set_platform_ubuntu "24" "04"
;;

"ubuntu23.10")
set_platform_ubuntu "23" "10"
;;

"ubuntu22.04")
set_platform_ubuntu "22" "04"
;;
Expand All @@ -421,6 +507,14 @@ EOF
set_platform_rhel "9"
;;

"debian12")
set_platform_debian "12"
;;

"fedora39")
set_platform_fedora "39"
;;

*)
echo "Error: unrecognized platform $2"
exit 1
Expand Down Expand Up @@ -577,7 +671,7 @@ mkdir -p $HOME_DIR/toolchains
mkdir -p $BIN_DIR

EXECUTABLE_NAME="swiftly-$ARCH-unknown-linux-gnu"
DOWNLOAD_URL="https://github.com/swift-server/swiftly/releases/latest/download/$EXECUTABLE_NAME"
DOWNLOAD_URL="https://github.com/swiftlang/swiftly/releases/latest/download/$EXECUTABLE_NAME"
echo "Downloading swiftly from $DOWNLOAD_URL..."
curl \
--retry 3 \
Expand Down