-
-
Save futurejones/5d85565b2a5669fd4f4f2a78b80fdac6 to your computer and use it in GitHub Desktop.
#! /bin/bash | |
# | |
# Install script for the Swift Community Apt Repository - swiftlang.xyz | |
# | |
# check distribution version and infer distro with switch/case | |
## as all distribution versions have different names we can use this information to infer the distribution name. | |
check_ver () { | |
for var in "${SUPPORTED_VER[@]}" | |
do | |
if grep -q $var tmp_sources.txt; | |
then | |
vers=$var | |
case $vers in | |
bookworm|bullseye|buster) dist="debian";; | |
lunar|kinetic|jammy|focal|bionic) dist="ubuntu";; | |
esac | |
break | |
fi | |
done | |
} | |
## raspbian is an edge case | |
## check for raspbian | |
check_raspbian () { | |
if grep -q "raspbian" tmp_sources.txt; | |
then | |
dist="raspbian" | |
fi | |
} | |
check_arch () { | |
arch=$(dpkg --print-architecture) | |
} | |
## deepin is an edge case | |
## check for deepin | |
check_deepin () { | |
if grep -q "deepin" tmp_sources.txt; | |
then | |
dist="debian" | |
vers="buster" | |
fi | |
} | |
## check if dist/version is supported | |
check_supported () { | |
if [ $dist == "unsupported" ] || [ $vers == "unsupported" ] | |
then | |
echo sorry your system is unsupported. | |
echo | |
exit 0 | |
fi | |
} | |
## user_input allows the selection of the available repository sections | |
user_input_all () { | |
# User Input | |
echo | |
echo "--------------- Choose Swift Release Version ---------------" | |
echo | |
echo " If you always want to have the latest release/stable version of Swift available choose [1]," | |
echo " or you can choose the Swift version most suitable for your project." | |
echo " The latest release/stable version of Swift in this repository is currently 5.8.1 " | |
echo | |
echo "---------------------------------------------------------" | |
echo | |
echo " 1) latest/main - This will update to the latest release/stable version of Swift available" | |
echo " 2) Swift version 5.4.* - this will update to the latest point/patch release of Swift 5.4" | |
echo " 3) Swift version 5.5.* - this will update to the latest point/patch release of Swift 5.5" | |
echo " 4) Swift version 5.6.* - this will update to the latest point/patch release of Swift 5.6" | |
echo " 5) Swift version 5.7.* - this will update to the latest point/patch release of Swift 5.7" | |
echo | |
echo "---------------------------------------------------------" | |
echo | |
read -r -p "Enter number [1/2/3/4/5] : " n < /dev/tty | |
echo | |
case $n in | |
1) main=" main"; echo "Installing the Swift main/latest repository"; echo;; | |
2) v5_4=" v5_4"; main=""; echo "Installing the Swift version 5.4.* repository"; echo;; | |
3) v5_5=" v5_5"; main=""; echo "Installing the Swift version 5.5.* repository"; echo;; | |
4) v5_6=" v5_6"; main=""; echo "Installing the Swift version 5.6.* repository"; echo;; | |
5) v5_7=" v5_7"; main=""; echo "Installing the Swift version 5.7.* repository"; echo;; | |
*) echo "Invalid option"; echo; exit 1;; | |
esac | |
} | |
user_input_armhf () { | |
# User Input | |
echo | |
echo "--------------- Choose Swift Release Version ---------------" | |
echo | |
echo " If you always want to have the latest release/stable version of Swift available choose [1]," | |
echo " or you can choose the Swift version most suitable for your project." | |
echo " The latest release/stable version of Swift in this repository is currently 5.7 " | |
echo | |
echo "---------------------------------------------------------" | |
echo | |
echo " 1) latest/main - This will update to the latest release/stable version of Swift available" | |
echo " 2) Swift version 5.1.* - this will update to the latest point/patch release of Swift 5.1.5" | |
echo | |
echo "---------------------------------------------------------" | |
echo | |
read -r -p "Enter number [1/2] : " n < /dev/tty | |
echo | |
case $n in | |
1) main=" main"; echo "Installing the Swift main/latest repository"; echo;; | |
2) v5_1=" v5_1"; main=""; echo "Installing the Swift version 5.1.* repository"; echo;; | |
*) echo "Invalid option"; echo; exit 1;; | |
esac | |
} | |
## check gpg is installed | |
gpg_check () { | |
echo "Checking for gpg..." | |
if command -v gpg > /dev/null; then | |
echo "Detected gpg..." | |
else | |
echo -n "Installing gnupg for GPG verification... " | |
apt-get install -y gnupg &> /dev/null | |
echo "done." | |
if [ "$?" -ne "0" ]; then | |
echo "Unable to install GPG! Your base system has a problem; please check your default OS's package repositories because GPG should work." | |
echo "Repository installation aborted." | |
exit 1 | |
fi | |
fi | |
} | |
install_debian_keyring () { | |
if [ "${dist}" = "debian" ]; then | |
echo "Installing debian-archive-keyring which is needed for installing " | |
echo "apt-transport-https on many Debian systems." | |
apt-get install -y debian-archive-keyring &> /dev/null | |
fi | |
} | |
file_check () { | |
if [ -f "$apt_source_path" ] | |
then | |
rm $apt_source_path | |
# remove old format list file | |
rm -f /etc/apt/sources.list.d/swiftlang.list | |
fi | |
} | |
main() { | |
# default repo values | |
v5_1="" | |
v5_4="" | |
v5_5="" | |
v5_6="" | |
v5_7="" | |
main=" main" | |
# default values | |
gpg_key="swiftlang_repo.gpg.key" | |
gpg_key_url="https://archive.swiftlang.xyz/swiftlang_repo.gpg.key" | |
apt_source_path="/etc/apt/sources.list.d/swiftlang-release.list" | |
# SUPPORTED_DIST=('ubuntu' 'debian' 'raspbian') | |
SUPPORTED_VER=('lunar' 'kinetic' 'jammy' 'focal' 'bionic' 'bookworm' 'bullseye' 'buster') | |
# default to unsupported | |
dist="unsupported" | |
vers="unsupported" | |
# ---- | |
# run apt update | |
echo -n "running update... " | |
apt-get update > tmp_sources.txt | |
echo "done." | |
# scan tmp_sources.txt | |
echo -n "scanning sources... " | |
#check_dist | |
check_arch | |
check_ver | |
check_deepin | |
check_raspbian | |
echo "done." | |
# clean tmp file | |
rm tmp_sources.txt | |
# check if system is supported - if not - exit | |
check_supported | |
# if ok continue with install | |
# ---- | |
echo system detected is compatible with $dist/$vers | |
echo | |
# check prerequisists | |
gpg_check | |
install_debian_keyring | |
echo -n "Installing apt-transport-https... " | |
apt-get install -y apt-transport-https &> /dev/null | |
echo "done." | |
# import the gpg key | |
echo -n "Importing swiftlang gpg key... " | |
sudo rm /usr/share/keyrings/${gpg_key} &> /dev/null | |
curl -fsSL "${gpg_key_url}" | sudo gpg --dearmor -o /usr/share/keyrings/${gpg_key} | |
echo "done." | |
# user input | |
if [ "${arch}" == "armhf" ]; | |
then | |
case $vers in | |
bionic|focal|jammy|buster|bullseye) user_input_armhf;; | |
*) user_input_armhf;; | |
esac | |
elif [ "${dist}" != "raspbian" ]; | |
then | |
case $vers in | |
bionic|focal|jammy|kinetic|lunar|buster|bullseye|bookworm) user_input_all;; | |
*) user_input_all;; | |
esac | |
fi | |
# add source list file | |
echo -n "Installing $apt_source_path... " | |
file_check | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/$gpg_key] https://archive.swiftlang.xyz/$dist/ $vers$v5_1$v5_4$v5_5$v5_6$v5_7$main" | sudo tee $apt_source_path > /dev/null | |
echo "done." | |
# | |
echo -n "Running apt-get update... " | |
# update apt on this system | |
apt-get update &> /dev/null | |
echo "done." | |
echo | |
echo "The repository is setup!" | |
echo "You can now install swift using 'sudo apt install swiftlang' " | |
echo | |
echo | |
echo "+--------------------------------- ❤️ ---------------------------------+" | |
echo "│ Please help support this repository at 'https://ko-fi.com/futurejones' │" | |
echo "+------------------------------------------------------------------------+" | |
echo | |
} | |
main |
@MaxDesiatov you will need to change from this script to a manual install of the repo.
In your workflow script change -
curl -s https://archive.swiftlang.xyz/install.sh | $sudoCommand bash
to this -
# install dependencies
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && apt-get -q update && \
apt-get -q install -y \
ca-certificates \
curl \
gnupg
# add repo key
curl -fsSL https://archive.swiftlang.xyz/swiftlang_repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/swiftlang_repo.gpg.key
# add repo to sources.list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/swiftlang_repo.gpg.key] https://archive.swiftlang.xyz/ubuntu jammy main" | tee /etc/apt/sources.list.d/swiftlang.list > /dev/null
# install swift
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && apt-get -q update && \
apt-get -q install -y \
swiftlang
you may need to add sudo
to some of these commands.
This makes sense, thanks!
5.7 please
Looks like archive.swiftlang.xyz is down since at least one day
@diegotl The repository is currently offline for maintenance.
https://forums.swift.org/t/new-swift-package-repository-for-ubuntu-debian-linux-distributions/50412/109#maintenance-notice-for-swift-community-apt-repository-1
I had to add a swift.conf to /etc/ld.so.conf.d/
That contained
/usr/lib/swift/linux
Update to add swift 5.8 and Ubuntu 23.04 / lunar
Update to add Debian 12 bookworm
Seems like archive.swiftlang.xyz is down, for good now it seems :-(
https://forums.swift.org/t/new-swift-package-repository-for-ubuntu-debian-linux-distributions/50412/137
@Macariel info and updates about the repo can be found on the swift forums
https://forums.swift.org/t/new-swift-package-repository-for-ubuntu-debian-linux-distributions/50412/137
Found it as well in the meanwhile. Sorry for creating any inconveniences 🙈
@futurejones I'm trying to use this script (or at least what's served at https://archive.swiftlang.xyz/install.sh) on CI, and the requirement of user input makes it fail, see this log for example https://github.com/swiftwasm/carton/runs/7747219715?check_suite_focus=true. Is there any way to make this non-interactive? Thanks!