Last active
October 10, 2023 12:54
-
-
Save futurejones/5d85565b2a5669fd4f4f2a78b80fdac6 to your computer and use it in GitHub Desktop.
Install script for the Swift Community Apt Repository - https://swiftlang.xyz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found it as well in the meanwhile. Sorry for creating any inconveniences 🙈