From e35b5675ca60440a9527ab504f4ce3bfc2c8a45b Mon Sep 17 00:00:00 2001 From: Szymon Lorenz Date: Fri, 15 Sep 2023 18:11:17 +1000 Subject: [PATCH 1/4] Add linux install script --- README.md | 19 +++++++++----- carton-install.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 carton-install.sh diff --git a/README.md b/README.md index 2c2410ce..21f8fa99 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ development workflow such as toolchain and SDK installations. ### Installation +## MacOS + On macOS `carton` can be installed with [Homebrew](https://brew.sh/). Make sure you have Homebrew installed and then run: @@ -40,18 +42,23 @@ brew install swiftwasm/tap/carton > If you can't install the latest carton via `brew upgrade swiftwasm/tap/carton`, please try `rm -rf $(brew --prefix)/Library/Taps/swiftwasm/homebrew-tap/ && brew tap swiftwasm/tap` and retry again. The `master` branch was renamed to `main`, so you need to update your local tap repo. +## Linux + +To download carton and install it, run the following in your terminal, then follow the on-screen instructions. +Overall, this script ensures that Carton is installed or updated to the latest release on your system, making it ready for use. + +``` +curl -sSL https://example.com/path/to/your/carton-install.sh | bash +``` + +## Diocker + `carton` is also available as a Docker image for Linux. You can pull it with this command: ``` docker pull ghcr.io/swiftwasm/carton:latest ``` -If Docker images are not suitable for you, you'll have to build `carton` from sources on Ubuntu. -Clone the repository and run `./install_ubuntu_deps.sh` in the root directory of the clone. After -that completes successfully, run `swift build -c release`, the `carton` binary will be located in -the `.build/release` directory after that. Unfortunately, other Linux distributions are currently -not supported. - ### Version compatibility `carton` previously embedded runtime parts of [the JavaScriptKit library](https://github.com/swiftwasm/JavaScriptKit). diff --git a/carton-install.sh b/carton-install.sh new file mode 100644 index 00000000..113494df --- /dev/null +++ b/carton-install.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# Define the destination directory +DEST="/usr/local/bin/carton" + +# Function to clean up files +cleanup() { + # Clean up: Remove unnecessary files and the cloned repository + cd .. + rm -rf carton +} + +# Check if the 'swift' command is available +if ! command -v swift &> /dev/null; then + echo "Swift is not installed. Installing Swift..." + + # Install Swift using swiftly-install.sh + curl -L https://swift-server.github.io/swiftly/swiftly-install.sh | bash + swiftly install latest + + # Check if Swift installation was successful + if ! command -v swift &> /dev/null; then + echo "Failed to install Swift. Please check the installation and try again." + cleanup + exit 1 + fi +fi + +# Clone the Carton repository +git clone https://github.com/swiftwasm/carton.git +cd carton + +# Find the latest release tag +latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1)) + +# Checkout the latest release tag +git checkout $latest_tag + +# Install dependencies +./install_ubuntu_deps.sh + +# Build Carton +swift build -c release + +# Check if the build was successful +if [ $? -eq 0 ]; then + # Remove the old Carton binary if it exists + if [ -f $DEST ]; then + sudo rm $DEST + fi + + # Move the binary to the destination + sudo mv .build/release/carton $DEST + + # Set the correct permissions + sudo chmod 755 $DEST + + echo "Carton has been successfully built and updated to the newest release ($latest_tag) at $DEST." + +else + echo "Carton build failed. Please check the dependencies and try again." +fi + +# Clean up in both success and failure cases +cleanup \ No newline at end of file From f4e19555056dc99847721a49ce66ec1a92d640bf Mon Sep 17 00:00:00 2001 From: Szymon Lorenz Date: Fri, 15 Sep 2023 18:19:57 +1000 Subject: [PATCH 2/4] update path to script --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 21f8fa99..5878688d 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ To download carton and install it, run the following in your terminal, then foll Overall, this script ensures that Carton is installed or updated to the latest release on your system, making it ready for use. ``` -curl -sSL https://example.com/path/to/your/carton-install.sh | bash +curl -sSL https://github.com/swiftwasm/carton/blob/main/carton-install.sh | bash ``` ## Diocker From 4e0d2d1eab5ad90017ccee7f08ed99e2a0b6cf45 Mon Sep 17 00:00:00 2001 From: Szymon Lorenz Date: Fri, 15 Sep 2023 18:57:34 +1000 Subject: [PATCH 3/4] quick push --- carton-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/carton-install.sh b/carton-install.sh index 113494df..f4656b90 100644 --- a/carton-install.sh +++ b/carton-install.sh @@ -11,7 +11,7 @@ cleanup() { } # Check if the 'swift' command is available -if ! command -v swift &> /dev/null; then +if [ ! -f "$HOME/.local/bin/swift" ]; then echo "Swift is not installed. Installing Swift..." # Install Swift using swiftly-install.sh @@ -19,7 +19,7 @@ if ! command -v swift &> /dev/null; then swiftly install latest # Check if Swift installation was successful - if ! command -v swift &> /dev/null; then +if [ ! -f "$HOME/.local/bin/swift" ]; then echo "Failed to install Swift. Please check the installation and try again." cleanup exit 1 From 818635683ab195624259f757553a18dca505340e Mon Sep 17 00:00:00 2001 From: Szymon Lorenz Date: Fri, 15 Sep 2023 18:59:58 +1000 Subject: [PATCH 4/4] update readme to raw sh --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5878688d..fa721797 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ To download carton and install it, run the following in your terminal, then foll Overall, this script ensures that Carton is installed or updated to the latest release on your system, making it ready for use. ``` -curl -sSL https://github.com/swiftwasm/carton/blob/main/carton-install.sh | bash +curl -sSL https://raw.githubusercontent.com/swiftwasm/carton/main/carton-install.sh | bash ``` ## Diocker