diff --git a/.github/workflows/install_test.yml b/.github/workflows/install_test.yml new file mode 100644 index 0000000..5802568 --- /dev/null +++ b/.github/workflows/install_test.yml @@ -0,0 +1,31 @@ +name: install_test.sh +on: + push: + branches: "main" + paths-ignore: + - README.md + - LICENSE + - .gitignore + - .github/** + - "!.github/workflows/install_test.yml" + pull_request: + paths-ignore: + - README.md + - LICENSE + - .gitignore + - .github/** + - "!.github/workflows/install_test.yml" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: shellcheck install.sh + install_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: bash ./install_test.sh diff --git a/README.md b/README.md index dfc301b..1e31884 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # typst_install 🤖 curl | sh installer script for Typst + +## Usage + +Linux, macOS, WSL + +```sh +curl -fsSL https://typst.community/install_typst/install.sh | sh +``` + +Windows + +```ps1 +irm https://typst.community/install_typst/install.ps1 | iex +``` + +## Development + +GitHub Pages is enabled and pulls straight from the `main` branch's root folder. +That's how the `https://typst.community/typst_install/install.sh` script is +published. That means it's a good idea to **make sure that the `main` branch +always works!** 😉 diff --git a/index.html b/index.html new file mode 100644 index 0000000..f5fdd92 --- /dev/null +++ b/index.html @@ -0,0 +1,2 @@ + + diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..cdcc8f7 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,51 @@ +#!/usr/bin/env pwsh +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +# TODO(everyone): Keep this script simple and easily auditable. +# Forked from Deno's install.ps1 script + +$ErrorActionPreference = 'Stop' + +if ($v) { + $Version = "v${v}" +} +if ($Args.Length -eq 1) { + $Version = $Args.Get(0) +} + +$TypstInstall = $env:TYPST_INSTALL +$BinDir = if ($TypstInstall) { + "${TypstInstall}\bin" +} else { + "${Home}\.typst\bin" +} + +$TypstZip = "$BinDir\typst.zip" +$TypstExe = "$BinDir\typst.exe" +$Target = 'x86_64-pc-windows-msvc' + +$DownloadUrl = if (!$Version) { + "https://github.com/typst/typst/releases/latest/download/typst-${Target}.zip" +} else { + "https://github.com/typst/typst/releases/download/${Version}/typst-${Target}.zip" +} + +if (!(Test-Path $BinDir)) { + New-Item $BinDir -ItemType Directory | Out-Null +} + +curl.exe -Lo $TypstZip $DownloadUrl + +tar.exe xf $TypstZip -C $BinDir --strip-components=1 + +Remove-Item $TypstZip + +$User = [System.EnvironmentVariableTarget]::User +$Path = [System.Environment]::GetEnvironmentVariable('Path', $User) +if (!(";${Path};".ToLower() -like "*;${BinDir};*".ToLower())) { + [System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinDir}", $User) + $Env:Path += ";${BinDir}" +} + +Write-Output "Typst was installed successfully to ${TypstExe}" +Write-Output "Run 'typst --help' to get started" +Write-Output "Stuck? Join our Discord https://discord.gg/2uDybryKPe" diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..12dbb0f --- /dev/null +++ b/install.sh @@ -0,0 +1,81 @@ +#!/bin/sh +# Copyright 2019 the Deno authors. All rights reserved. MIT license. +# TODO(everyone): Keep this script simple and easily auditable. +# Forked from Deno's install.sh script + +set -e + +use_unzip=false + +if [ "$OS" = "Windows_NT" ]; then + target="x86_64-pc-windows-msvc" + use_unzip=true +else + case $(uname -sm) in + "Darwin x86_64") target="x86_64-apple-darwin" ;; + "Darwin arm64") + echo "Error: Official Typst builds for Darwin arm64 are not available." 1>&2 # (see: https://github.com/denoland/deno/issues/1846 )" 1>&2 + exit 1 + ;; + "Linux aarch64") + echo "Error: Official Typst builds for Linux aarch64 are not available." 1>&2 # (see: https://github.com/denoland/deno/issues/1846 )" 1>&2 + exit 1 + ;; + *) target="x86_64-unknown-linux-gnu" ;; + esac +fi + +if [ "$use_unzip" = true ] && ! command -v unzip >/dev/null; then + echo "Error: unzip is required to install Typst." 1>&2 # (see: https://github.com/denoland/deno_install#unzip-is-required )." 1>&2 + exit 1 +fi + +typst_install="${TYPST_INSTALL:-$HOME/.typst}" +bin_dir="$typst_install/bin" +exe="$bin_dir/typst" + +if [ ! -d "$bin_dir" ]; then + mkdir -p "$bin_dir" +fi + +if [ "$use_unzip" = true ]; then + if [ $# -eq 0 ]; then + typst_uri="https://github.com/typst/typst/releases/latest/download/typst-${target}.zip" + else + typst_uri="https://github.com/typst/typst/releases/download/${1}/typst-${target}.zip" + fi + + curl --fail --location --progress-bar --output "$exe.zip" "$typst_uri" + unzip -d "$bin_dir" -o "$exe.zip" + mv "$bin_dir/typst-${target}/*" "$bin_dir" + chmod +x "$exe" + rm -r "$bin_dir/typst-${target}/*" + rm "$exe.zip" +else + if [ $# -eq 0 ]; then + typst_uri="https://github.com/typst/typst/releases/latest/download/typst-${target}.tar.gz" + else + typst_uri="https://github.com/typst/typst/releases/download/${1}/typst-${target}.tar.gz" + fi + + curl --fail --location --progress-bar --output "$exe.tar.gz" "$typst_uri" + tar -xf "$exe.tar.gz" -C "$bin_dir" --strip-components=1 + chmod +x "$exe" + rm "$exe.tar.gz" +fi + +echo "Typst was installed successfully to $exe" +if command -v typst >/dev/null; then + echo "Run 'typst --help' to get started" +else + case $SHELL in + /bin/zsh) shell_profile=".zshrc" ;; + *) shell_profile=".bashrc" ;; + esac + echo "Manually add the directory to your \$HOME/$shell_profile (or similar)" + echo " export TYPST_INSTALL=\"$typst_install\"" + echo " export PATH=\"\$TYPST_INSTALL/bin:\$PATH\"" + echo "Run '$exe --help' to get started" +fi +echo +echo "Stuck? Join our Discord https://discord.gg/2uDybryKPe" diff --git a/install_test.sh b/install_test.sh new file mode 100644 index 0000000..06ebd61 --- /dev/null +++ b/install_test.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +if [ "$OS" = "Windows_NT" ]; then + +else + +fi