- 
                Notifications
    You must be signed in to change notification settings 
- Fork 253
Use a curlbash script for installing swiftly #1133
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
5689d02
              e8a5359
              f4a9338
              9b36b3e
              62c93ee
              42653b5
              fe5af9d
              6b83669
              992e04f
              14efa21
              59a539b
              0571c74
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/bin/bash | ||
| ##===----------------------------------------------------------------------===## | ||
| ## | ||
| ## This source file is part of the Swift.org open source project | ||
| ## | ||
| ## Copyright (c) 2025 Apple Inc. and the Swift.org project authors | ||
| ## Licensed under Apache License v2.0 | ||
| ## | ||
| ## See LICENSE.txt for license information | ||
| ## See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| ## | ||
| ## SPDX-License-Identifier: Apache-2.0 | ||
| ## | ||
| ##===----------------------------------------------------------------------===## | ||
|  | ||
|         
                  marcprux marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| # Install script for Swiftly | ||
| # Usage: curl -fsSL https://swift.org/swiftly-install | sh | ||
| OS_NAME=$(uname -s) | ||
| OS_ARCH=$(uname -m) | ||
| TMPDIR=$(mktemp -d) | ||
|  | ||
| cd ${TMPDIR} | ||
|         
                  marcprux marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| case "$OS_NAME" in | ||
| "Linux") | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Linux, almost no command line tool is guaranteed to be installed. It's worth checking if all of the programs the script needs are installed. 
 mktemp and uname come from coreutils, but those are a bit too fundamental to bother checking for IMO. cd is a shell builtin. Or, you could detect apt-get and dnf and try to install the relevant packages to ensure they'll be there (without  something like this: if command -v apt-get >/dev/null 2>&1 ; then # debian, ubuntu
    apt-get update
    apt-get install curl procps tar
elif command -v dnf >/dev/null 2>&1 ; then # rhel
    dnf update
    dnf install curl procps tar
elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
    yum update
    yum install curl procps tar
elif ! command -v curl >/dev/null 2>&1 || ! command -v ps >/dev/null 2>&1 || ! command -v tar >/dev/null 2>&1 ; then
    echo "Missing one of more of the following programs: curl, ps, tar" >&2
    exit 1
fiThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. I think that automatically running their package manager to install the missing utilities is a bit heavy-handed, so I just went with the fail-fast exit when one of the necessary commands is not present. | ||
| curl -fsSLO https://download.swift.org/swiftly/linux/swiftly-${OS_ARCH}.tar.gz | ||
|         
                  marcprux marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| tar zxf swiftly-${OS_ARCH}.tar.gz | ||
|         
                  marcprux marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| ./swiftly init | ||
| SWIFTLY_HOME_DIR=${SWIFTLY_HOME_DIR:-$HOME/.swiftly} | ||
| ;; | ||
| "Darwin") | ||
| curl -fsSLO https://download.swift.org/swiftly/darwin/swiftly.pkg | ||
| installer -pkg swiftly.pkg -target CurrentUserHomeDirectory | ||
| ~/.swiftly/bin/swiftly init | ||
| SWIFTLY_HOME_DIR=${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly} | ||
| ;; | ||
| *) | ||
| echo "Unknown platform: $OS_NAME" | ||
| echo "This script supports Linux and Darwin/macOS only" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|  | ||
| echo "Swiftly installed! Run the following command to set up your environment:" | ||
| PARENT_SHELL=$(ps -o comm= -p "$PPID") | ||
| if [ "$PARENT_SHELL" = "fish" ]; then | ||
| echo "source ${SWIFTLY_HOME_DIR}/env.fish" | ||
| else | ||
| # Not fish: assume sh-compatible (bash/zsh) | ||
| echo "source ${SWIFTLY_HOME_DIR}/env.sh" | ||
| fi | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
#!/bin/shfor maximum portability?shellcheckcan help validate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
soundness.sh seems to prefer bash