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

Add linux install script #408

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
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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://raw.githubusercontent.com/swiftwasm/carton/main/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).
Expand Down
65 changes: 65 additions & 0 deletions carton-install.sh
Original file line number Diff line number Diff line change
@@ -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 [ ! -f "$HOME/.local/bin/swift" ]; 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 [ ! -f "$HOME/.local/bin/swift" ]; 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
Loading