From 1396231daa76aa0e80db794a16a7bbda39f94729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augusto=20C=C3=A9sar?= Date: Fri, 21 Mar 2025 15:16:11 +0100 Subject: [PATCH 1/3] feat: support installing next release from shell script --- linkup-cli/install.sh | 61 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/linkup-cli/install.sh b/linkup-cli/install.sh index 059e42ce..e4dd4613 100755 --- a/linkup-cli/install.sh +++ b/linkup-cli/install.sh @@ -1,5 +1,21 @@ #!/bin/sh +INSTALL_PRERELEASE=0 + +while [ $# -gt 0 ]; do + case "$1" in + --pre-release|-p) + INSTALL_PRERELEASE=1 + shift + ;; + *) + printf '%s\n' "Unknown option: $1" 1>&2 + printf '%s\n' "Usage: ./install.sh [--pre-release|-p]" 1>&2 + exit 1 + ;; + esac +done + if command -v -- "linkup" >/dev/null 2>&1; then printf '%s\n' "Linkup is already installed. To update it, run 'linkup update'." 1>&2 exit 0 @@ -52,17 +68,44 @@ if [ -z "$FETCH_OS" ] || [ -z "$FETCH_ARCH" ]; then exit 1 fi -LOOKUP_FILE_DOWNLOAD_URL="https://github.com/mentimeter/linkup/releases/download/.*/linkup-.*-$FETCH_ARCH-$FETCH_OS.tar.gz" -FILE_DOWNLOAD_URL=$( - curl -sL \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/mentimeter/linkup/releases/latest | - grep -Eio "$LOOKUP_FILE_DOWNLOAD_URL" -) +if [ "$INSTALL_PRERELEASE" -eq 1 ]; then + printf '%s\n' "Looking for the latest pre-release version..." 1>&2 + + RELEASES_JSON=$( + curl -sL \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/mentimeter/linkup/releases" + ) + + RELEASE_DATA=$(echo "$RELEASES_JSON" | jq -r '[.[] | select(.prerelease==true)][0]') + + if [ "$RELEASE_DATA" = "null" ] || [ -z "$RELEASE_DATA" ]; then + printf '%s\n' "No pre-releases found. Falling back to latest stable release." 1>&2 + RELEASE_DATA=$( + curl -sL \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/mentimeter/linkup/releases/latest" + ) + else + RELEASE_TAG=$(echo "$RELEASE_DATA" | jq -r '.tag_name') + printf '%s\n' "Found pre-release version: $RELEASE_TAG" 1>&2 + fi +else + RELEASE_DATA=$( + curl -sL \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/mentimeter/linkup/releases/latest" + ) +fi + +ASSET_FILTER="linkup-.+-$FETCH_ARCH-$FETCH_OS\\.tar\\.gz$" +FILE_DOWNLOAD_URL=$(echo "$RELEASE_DATA" | jq -r --arg filter "$ASSET_FILTER" '.assets[] | select(.name | test($filter)) | .browser_download_url') if [ -z "$FILE_DOWNLOAD_URL" ]; then - printf '%s\n' "Could not find file with pattern '$LOOKUP_FILE_DOWNLOAD_URL' on the latest GitHub release." 1>&2 + printf '%s\n' "Could not find file with pattern 'linkup-*-$FETCH_ARCH-$FETCH_OS.tar.gz' in the GitHub release." 1>&2 exit 1 fi From ea227ea261223a249ee9f8344f54b2d7f28df48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augusto=20C=C3=A9sar?= Date: Mon, 24 Mar 2025 13:14:11 +0100 Subject: [PATCH 2/3] refactor: restructure install.sh --- linkup-cli/install.sh | 264 ++++++++++++++++++++++++------------------ 1 file changed, 149 insertions(+), 115 deletions(-) diff --git a/linkup-cli/install.sh b/linkup-cli/install.sh index e4dd4613..57fd9724 100755 --- a/linkup-cli/install.sh +++ b/linkup-cli/install.sh @@ -1,151 +1,185 @@ #!/bin/sh -INSTALL_PRERELEASE=0 +command_exists() { + command -v -- "$1" >/dev/null 2>&1 +} + +check_dependencies() { + if ! command_exists "cloudflared"; then + printf '%s\n' "WARN: 'cloudflared' is not installed. Please install it before installing Linkup." 1>&2 + printf '%s\n' "For more info check: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/" 1>&2 + exit 1 + fi -while [ $# -gt 0 ]; do - case "$1" in - --pre-release|-p) - INSTALL_PRERELEASE=1 - shift + if ! command_exists "dnsmasq"; then + printf '%s\n' "WARN: 'dnsmasq' is not installed. Some features will not work as expected. Please install it." 1>&2 + printf '%s\n' "For more info check: https://thekelleys.org.uk/dnsmasq/doc.html" 1>&2 + fi +} + +detect_platform() { + OS=$(uname -s) + ARCH=$(uname -m) + + case "$OS" in + Darwin*) + FETCH_OS='apple-darwin' + case "$ARCH" in + arm64 | aarch64) + FETCH_ARCH='aarch64' ;; - *) - printf '%s\n' "Unknown option: $1" 1>&2 - printf '%s\n' "Usage: ./install.sh [--pre-release|-p]" 1>&2 - exit 1 + x86_64) + FETCH_ARCH='x86_64' ;; - esac -done - -if command -v -- "linkup" >/dev/null 2>&1; then - printf '%s\n' "Linkup is already installed. To update it, run 'linkup update'." 1>&2 - exit 0 -fi - -# region: Dependencies -# TODO: Maybe we want this script to be able to install the dependencies as well? -if ! command -v -- "cloudflared" >/dev/null 2>&1; then - printf '%s\n' "WARN: 'cloudflared' is not installed. Please install it before installing Linkup.\nFor more info check: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/" 1>&2 - exit 1 -fi - -if ! command -v -- "dnsmasq" >/dev/null 2>&1; then - printf '%s\n' "WARN: 'dnsmasq' is not installed. Some features will not work as expected. Please install it.\nFor more info check: https://thekelleys.org.uk/dnsmasq/doc.html" 1>&2 -fi -# endregion: Dependencies - -OS=$(uname -s) -ARCH=$(uname -m) - -FETCH_OS='' -FETCH_ARCH='' -case "$OS" in -Darwin*) - FETCH_OS='apple-darwin' - case "$ARCH" in - arm64 | aarch64) - FETCH_ARCH='aarch64' - ;; - x86_64) - FETCH_ARCH='x86_64' - ;; - esac - ;; -Linux*) - FETCH_OS='unknown-linux-gnu' - case "$ARCH" in - arm64 | aarch64) - FETCH_ARCH='aarch64' + esac ;; - x86_64) - FETCH_ARCH='x86_64' + Linux*) + FETCH_OS='unknown-linux-gnu' + case "$ARCH" in + arm64 | aarch64) + FETCH_ARCH='aarch64' + ;; + x86_64) + FETCH_ARCH='x86_64' + ;; + esac ;; esac - ;; -esac - -if [ -z "$FETCH_OS" ] || [ -z "$FETCH_ARCH" ]; then - printf '%s\n' "Unsupported OS/Arch combination: $OS/$ARCH" 1>&2 - exit 1 -fi -if [ "$INSTALL_PRERELEASE" -eq 1 ]; then - printf '%s\n' "Looking for the latest pre-release version..." 1>&2 - - RELEASES_JSON=$( - curl -sL \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/mentimeter/linkup/releases" - ) + if [ -z "$FETCH_OS" ] || [ -z "$FETCH_ARCH" ]; then + printf '%s\n' "Unsupported OS/Arch combination: $OS/$ARCH" 1>&2 + exit 1 + fi +} - RELEASE_DATA=$(echo "$RELEASES_JSON" | jq -r '[.[] | select(.prerelease==true)][0]') +get_release_data() { + if [ "$INSTALL_PRERELEASE" -eq 1 ]; then + printf '%s\n' "Looking for the latest pre-release version..." 1>&2 - if [ "$RELEASE_DATA" = "null" ] || [ -z "$RELEASE_DATA" ]; then - printf '%s\n' "No pre-releases found. Falling back to latest stable release." 1>&2 - RELEASE_DATA=$( + RELEASES_JSON=$( curl -sL \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/mentimeter/linkup/releases/latest" + "https://api.github.com/repos/mentimeter/linkup/releases" ) + + RELEASE_DATA=$(echo "$RELEASES_JSON" | jq -r '[.[] | select(.prerelease==true)][0]') + + if [ "$RELEASE_DATA" = "null" ] || [ -z "$RELEASE_DATA" ]; then + printf '%s\n' "No pre-releases found. Falling back to latest stable release." 1>&2 + get_latest_stable_release + else + RELEASE_TAG=$(echo "$RELEASE_DATA" | jq -r '.tag_name') + printf '%s\n' "Found pre-release version: $RELEASE_TAG" 1>&2 + fi else - RELEASE_TAG=$(echo "$RELEASE_DATA" | jq -r '.tag_name') - printf '%s\n' "Found pre-release version: $RELEASE_TAG" 1>&2 + get_latest_stable_release fi -else +} + +get_latest_stable_release() { RELEASE_DATA=$( curl -sL \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/mentimeter/linkup/releases/latest" ) -fi +} -ASSET_FILTER="linkup-.+-$FETCH_ARCH-$FETCH_OS\\.tar\\.gz$" -FILE_DOWNLOAD_URL=$(echo "$RELEASE_DATA" | jq -r --arg filter "$ASSET_FILTER" '.assets[] | select(.name | test($filter)) | .browser_download_url') +download_and_extract() { + ASSET_FILTER="linkup-.+-$FETCH_ARCH-$FETCH_OS\\.tar\\.gz$" + FILE_DOWNLOAD_URL=$(echo "$RELEASE_DATA" | jq -r --arg filter "$ASSET_FILTER" '.assets[] | select(.name | test($filter)) | .browser_download_url') -if [ -z "$FILE_DOWNLOAD_URL" ]; then - printf '%s\n' "Could not find file with pattern 'linkup-*-$FETCH_ARCH-$FETCH_OS.tar.gz' in the GitHub release." 1>&2 - exit 1 -fi + if [ -z "$FILE_DOWNLOAD_URL" ]; then + printf '%s\n' "Could not find file with pattern 'linkup-*-$FETCH_ARCH-$FETCH_OS.tar.gz' in the GitHub release." 1>&2 + exit 1 + fi -printf '%s\n' "Downloading: $FILE_DOWNLOAD_URL" 1>&2 -curl -sLO --output-dir "/tmp" $FILE_DOWNLOAD_URL + printf '%s\n' "Downloading: $FILE_DOWNLOAD_URL" 1>&2 + curl -sLO --output-dir "/tmp" "$FILE_DOWNLOAD_URL" -LOCAL_FILE_PATH="/tmp/$(basename $FILE_DOWNLOAD_URL)" + LOCAL_FILE_PATH="/tmp/$(basename "$FILE_DOWNLOAD_URL")" -printf '%s\n' "Decompressing $LOCAL_FILE_PATH" 1>&2 -tar -xzf $LOCAL_FILE_PATH -C /tmp + printf '%s\n' "Decompressing $LOCAL_FILE_PATH" 1>&2 + tar -xzf "$LOCAL_FILE_PATH" -C /tmp -mkdir -p $HOME/.linkup/bin -mv /tmp/linkup $HOME/.linkup/bin/ -printf '%s\n' "Linkup installed on $HOME/.linkup/bin/linkup" 1>&2 + mkdir -p "$HOME/.linkup/bin" + mv /tmp/linkup "$HOME/.linkup/bin/" + chmod +x "$HOME/.linkup/bin/linkup" + printf '%s\n' "Linkup installed on $HOME/.linkup/bin/linkup" 1>&2 -rm "$LOCAL_FILE_PATH" + rm "$LOCAL_FILE_PATH" +} -case ":$PATH:" in -*":$HOME/.linkup/bin:"*) - # PATH already contains the directory - ;; -*) - SHELL_NAME=$(basename "$SHELL") - case "$SHELL_NAME" in - bash) - PROFILE_FILE="$HOME/.bashrc" - ;; - zsh) - PROFILE_FILE="$HOME/.zshrc" - ;; - fish) - PROFILE_FILE="$HOME/.config/fish/config.fish" +setup_path() { + case ":$PATH:" in + *":$HOME/.linkup/bin:"*) + # PATH already contains the directory ;; *) - PROFILE_FILE="$HOME/.profile" + SHELL_NAME=$(basename "$SHELL") + case "$SHELL_NAME" in + bash) + PROFILE_FILE="$HOME/.bashrc" + ;; + zsh) + PROFILE_FILE="$HOME/.zshrc" + ;; + fish) + PROFILE_FILE="$HOME/.config/fish/config.fish" + ;; + *) + PROFILE_FILE="$HOME/.profile" + ;; + esac + + printf '%s\n' "Adding Linkup bin to PATH in $PROFILE_FILE" 1>&2 + printf "\n# Linkup bin\nexport PATH=\$PATH:\$HOME/.linkup/bin" >>"$PROFILE_FILE" + printf '%s\n' "Please source your profile file or restart your terminal to apply the changes." 1>&2 ;; esac +} + +parse_arguments() { + while [ $# -gt 0 ]; do + case "$1" in + --pre-release | -p) + INSTALL_PRERELEASE=1 + shift + ;; + *) + printf '%s\n' "Unknown option: $1" 1>&2 + printf '%s\n' "Usage: ./install.sh [--pre-release|-p]" 1>&2 + exit 1 + ;; + esac + done +} + +#------------------------------------------------- +# Main script +#------------------------------------------------- + +INSTALL_PRERELEASE=${INSTALL_PRERELEASE:-0} +FETCH_OS='' +FETCH_ARCH='' +RELEASE_DATA='' + +main() { + parse_arguments "$@" + + if command_exists "linkup"; then + printf '%s\n' "Linkup is already installed. To update it, run 'linkup update'." 1>&2 + exit 0 + fi + + check_dependencies + detect_platform + get_release_data + download_and_extract + setup_path + + printf '%s\n' "Linkup installation complete! 🎉" 1>&2 +} - printf '%s\n' "Adding Linkup bin to PATH in $PROFILE_FILE" 1>&2 - printf "\n# Linkup bin\nexport PATH=\$PATH:\$HOME/.linkup/bin" >>"$PROFILE_FILE" - printf '%s\n' "Please source your profile file or restart your terminal to apply the changes." 1>&2 - ;; -esac +main "$@" From f21d23d005af402c0fc472a769827407659c8b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Augusto=20C=C3=A9sar?= Date: Mon, 24 Mar 2025 13:14:31 +0100 Subject: [PATCH 3/3] docs: add install.sh installation to docs --- docs/src/content/docs/guides/local-env.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/src/content/docs/guides/local-env.md b/docs/src/content/docs/guides/local-env.md index 2501e360..a2561106 100644 --- a/docs/src/content/docs/guides/local-env.md +++ b/docs/src/content/docs/guides/local-env.md @@ -1,5 +1,5 @@ --- -title: Run a Local Linkup Session +title: Run a Local Linkup Session description: Get started with linkup by running a local linkup session sidebar: order: 1 @@ -11,6 +11,8 @@ sidebar: ## Installing the CLI +### With Homebrew + To use link up locally the easiest way to get started is to use the linkup cli: ```sh @@ -18,6 +20,16 @@ brew tap mentimeter/mentimeter brew install linkup ``` +### Using the install.sh script + +```sh +curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/mentimeter/linkup/refs/heads/main/linkup-cli/install.sh | sh + +# Or to install a pre-release version (beta) + +INSTALL_PRERELEASE=1 curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/mentimeter/linkup/refs/heads/main/linkup-cli/install.sh | sh +``` + Once you have the cli installed you can start a linkup session by running: ```zsh