8000 feat(next, cli): support installing beta releases from shell script by augustoccesar · Pull Request #211 · mentimeter/linkup · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(next, cli): support installing beta releases from shell script #211

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 8000 privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
14 changes: 13 additions & 1 deletion docs/src/content/docs/guides/local-env.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,13 +11,25 @@ sidebar:

## Installing the CLI

### With Homebrew

To use link up locally the easiest way to get started is to use the linkup cli:

```sh
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
8000 Expand Down
271 changes: 174 additions & 97 deletions linkup-cli/install.sh
Original file line number Diff line number Diff line change
@@ -1,108 +1,185 @@
#!/bin/sh

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)
command_exists() {
command -v -- "$1" >/dev/null 2>&1
}

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'
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

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'
;;
x86_64)
FETCH_ARCH='x86_64'
;;
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

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 [ -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
exit 1
fi

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)"

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

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"

if [ -z "$FETCH_OS" ] || [ -z "$FETCH_ARCH" ]; then
printf '%s\n' "Unsupported OS/Arch combination: $OS/$ARCH" 1>&2
exit 1
fi
}

get_release_data() {
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
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
get_latest_stable_release
fi
}

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"
)
}

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

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")"

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/"
chmod +x "$HOME/.linkup/bin/linkup"
printf '%s\n' "Linkup installed on $HOME/.linkup/bin/linkup" 1>&2

rm "$LOCAL_FILE_PATH"
}

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 "$@"
0