From e165cd628a43068af9e836c4da352b00ffd0a996 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Mon, 4 Sep 2023 17:33:32 +0300 Subject: [PATCH 1/6] added draft CLI install script --- packages/cli/install.sh | 360 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 packages/cli/install.sh diff --git a/packages/cli/install.sh b/packages/cli/install.sh new file mode 100644 index 000000000..dafd91257 --- /dev/null +++ b/packages/cli/install.sh @@ -0,0 +1,360 @@ +#!/bin/sh + +# adapted from https://github.com/teaxyz/setup/blob/main/install.sh + +set -e +set -o noglob + +# prevent existing env breaking this script +unset POLYWRAP_DESTDIR +unset POLYWRAP_VERSION + +unset stop +while test "$#" -gt 0 -a -z "$stop"; do + case $1 in + --prefix) + # we don’t use POLYWRAP_PREFIX so any already installed polywrap that we use in this script doesn't break + POLYWRAP_DESTDIR="$2" + if test -z "$POLYWRAP_DESTDIR"; then + echo "polywrap: error: --prefix requires an argument" >&2 + exit 1 + fi + shift;shift;; + --version) + POLYWRAP_VERSION="$2" + if test -z "$POLYWRAP_VERSION"; then + echo "polywrap: error: --version requires an argument" >&2 + exit 1 + fi + shift;shift;; + --yes|-y) + POLYWRAP_YES=1 + shift;; + --help|-h) + echo "polywrap: docs: https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README.md#installation" + exit;; + *) + stop=1;; + esac +done +unset stop + + +####################################################################### funcs +prepare() { + # ensure ⌃C works + trap "echo; exit" INT + + if ! command -v tar >/dev/null; then + echo "polywrap: error: sorry. pls install tar :(" >&2 + fi + + if test -n "$VERBOSE" -o -n "$GITHUB_ACTIONS" -a -n "$RUNNER_DEBUG"; then + set -x + fi + + if test $# -eq 0; then + MODE="install" + else + MODE="exec" + fi + + HW_TARGET=$(uname)/$(uname -m) + + ZZ=gz + + case $HW_TARGET in + Darwin/arm64) + ZZ=xz + POLYWRAP_OSARCH=macos-arm64;; + Darwin/x86_64) + ZZ=xz + POLYWRAP_OSARCH=macos-x64;; + Linux/arm64|Linux/aarch64) + POLYWRAP_OSARCH=linux-arm64;; + Linux/x86_64) + POLYWRAP_OSARCH=linux-x64;; + CYGWIN_NT-10.0/arm64|MSYS_NT-10.0/arm64) + POLYWRAP_OSARCH=win-arm64;; + CYGWIN_NT-10.0/x86_64|MSYS_NT-10.0/x86_64) + POLYWRAP_OSARCH=win-x64;; + *) + echo "polywrap: error: (currently) unsupported OS or architecture ($HW_TARGET)" >&2 + echo "let’s talk about it: https://discord.com/invite/Z5m88a5qWu" >&2 + exit 1;; + esac + + if test $ZZ = 'gz'; then + if command -v base64 >/dev/null; then + BASE64_TARXZ="/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AFNdADMb7AG6cMNAaNMVK8FvZMaza8QKKTQY6wZ3kG/F814lHE9ruhkFO5DAG7XNamN7JMHavgmbbLacr72NaAzgGUXOstqUaGb6kbp7jrkF+3aQT12CAAB8Uikc1gG8RwABb4AMAAAAeGbHwbHEZ/sCAAAAAARZWg==" + if echo "$BASE64_TARXZ" | base64 -d | tar Jtf - >/dev/null 2>&1; then + ZZ=xz + fi + elif command -v uudecode >/dev/null; then + TMPFILE=$(mktemp) + cat >"$TMPFILE" <<-EOF + begin 644 foo.tar.xz + M_3=Z6%H\`\`\`3FUK1&\`@\`A\`18\`\`\`!T+^6CX\`7_\`%-=\`#,;[\`&Z<,-\`:-,5*\%O + M9,:S:\0**308ZP9WD&_%\UXE'$]KNAD%.Y#\`&[7-:F-[),':O@F;;+:&;' + -P;'\$9_L"\`\`\`\`\`\`196@\`\` + \` + end + EOF + if uudecode -p "$TMPFILE" | tar Jtf - >/dev/null 2>&1; then + ZZ=xz + fi + fi + fi + + case "$ZZ" in + gz) + TAR_FLAGS=xz;; # confusingly + xz) + TAR_FLAGS=xJ;; + esac + + if test -z "$POLYWRAP_DESTDIR"; then + # update existing installation if found + if command -v polywrap >/dev/null; then + set +e + POLYWRAP_DESTDIR="$(which polywrap)" + if test $? -eq 0 -a -n "$POLYWRAP_DESTDIR"; then + ALREADY_INSTALLED=1 + else + unset POLYWRAP_DESTDIR + fi + set -e + fi + + # we check again: in case the above failed for some reason + if test -z "$POLYWRAP_DESTDIR"; then + if test "$MODE" = exec; then + POLYWRAP_DESTDIR="$(mktemp -dt polywrap-XXXXXX)" + else + POLYWRAP_DESTDIR="$HOME/.polywrap" + fi + fi + fi + + # be portable + case "$POLYWRAP_DESTDIR" in + "$HOME"/*) + POLYWRAP_DESTDIR_WRITABLE="\$HOME${POLYWRAP_DESTDIR#$HOME}" + ;; + *) + POLYWRAP_DESTDIR_WRITABLE="$POLYWRAP_DESTDIR" + ;; + esac + + if test -z "$CURL"; then + if command -v curl >/dev/null; then + CURL="curl -Ssf" +# elif test -f "$POLYWRAP_DESTDIR/curl.se/v*/bin/curl"; then +# CURL="$POLYWRAP_DESTDIR/curl.se/v*/bin/curl -Ssf" + else + # how they got here without curl: we dunno + echo "polywrap: error: you need curl (or set \`\$CURL\`)" >&2 + exit 1 + fi + fi +} + +welcome() { + cat <<-EoMD + # Hi 👋 Welcome to Polywrap! + * Let's get you set up. + * We'll install polywrap at: $POLYWRAP_DESTDIR + * Everything Polywrap installs goes there. + * (we won't touch anything else) + + > docs https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README.md#installation + EoMD + + if test -z "$POLYWRAP_YES"; then + choice="1" + else + echo #spacer + echo "How about it?" + echo "1) install polywrap" + echo "2) cancel" + read -p "Choice: " choice + fi + + if [ "$choice" != "1" ]; then + cat <<-EoMD + # aborting + Aborting! No changes were made. + Check out https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README for more info + EoMD + echo #spacer + exit 1 + fi + unset choice +} + +get_polywrap_version() { + if test -n "$POLYWRAP_VERSION"; then + return + fi + + v_sh="$(mktemp)" + cat <<-EoMD >"$v_sh" + $CURL "https://raw.githubusercontent.com/polywrap/cli/origin-dev/VERSION" | head -n1 > "$v_sh" + EoMD + + echo "determining polywrap version" + sh "$v_sh" + + POLYWRAP_VERSION="$(cat "$v_sh")" + + if test -z "$POLYWRAP_VERSION"; then + echo "failed to get the latest version" >&2 + exit 1 + fi +} + +fix_links() { + OLDWD="$PWD" + + link() { + if test -d "v$1" -a ! -L "v$1"; then + echo "'v$1' is unexpectedly a directory" >&2 + else + rm -f "v$1" + ln -s "v$POLYWRAP_VERSION" "v$1" + fi + } + + cd "$POLYWRAP_DESTDIR"/polywrap + link \* + link "$(echo "$POLYWRAP_VERSION" | cut -d. -f1)" + link "$(echo "$POLYWRAP_VERSION" | cut -d. -f1-2)" + cd "$OLDWD" +} + +install() { + if test -n "$ALREADY_INSTALLED"; then + TITLE="updating to polywrap v$POLYWRAP_VERSION" + else + TITLE="fetching polywrap v$POLYWRAP_VERSION" + fi + + mkdir -p "$POLYWRAP_DESTDIR" + POLYWRAP_DESTDIR="$(cd $POLYWRAP_DESTDIR && pwd)" # we need this PATH to be an absolute path for later stuff + POLYWRAP_TMP_SCRIPT="$(mktemp)" + URL="https://github.com/polywrap/cli/releases/download/v$POLYWRAP_VERSION/$POLYWRAP_OSARCH" + echo "set -e; $CURL '$URL' | tar '$TAR_FLAGS' -C '$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/'" > "$POLYWRAP_TMP_SCRIPT" + echo "$TITLE" + sh "$POLYWRAP_TMP_SCRIPT" + + fix_links + + if ! test "$MODE" = exec; then + gum_func format -- "Successfully installed \`$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap\`" + fi + + POLYWRAP_VERSION_MAJOR="$(echo "$POLYWRAP_VERSION" | cut -d. -f1)" + POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin/polywrap" + + echo #spacer +} + +check_path() { + cat <<-EoMD + Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin to your PATH? + EoMD + + if test -z "$POLYWRAP_YES"; then + choice="1" + else + echo #spacer + echo "How about it?" + echo "1) Yes" + echo "2) Skip" + read -p "Choice: " choice + fi + + if [ "$choice" = "1" ]; then + echo #spacer + + # NOTE: Binary -a and -o are inherently ambiguous. Use 'test EXPR1 + # && test EXPR2' or 'test EXPR1 || test EXPR2' instead. + # https://man7.org/linux/man-pages/man1/test.1.html + if test -w /usr/local/bin || (test ! -e /usr/local/bin && mkdir -p /usr/local/bin >/dev/null 2>&1) + then + mkdir -p /usr/local/bin + ln -sf "$POLYWRAP_EXENAME" /usr/local/bin/polywrap + elif command -v sudo >/dev/null + then + sudo --reset-timestamp + sudo mkdir -p /usr/local/bin + sudo ln -sf "$POLYWRAP_EXENAME" /usr/local/bin/polywrap + else + echo #spacer + cat <<-EoMD + > sudo command not found. + > try installing sudo + EoMD + fi + + if ! command -v polywrap >/dev/null + then + echo #spacer + gum_func format -- <<-EoMD + > It seems \`/usr/local/bin\` isn’t in your PATH, or we couldn't write to it. + \`PATH=$PATH\` + EoMD + fi + fi + + echo #spacer +} + +########################################################################## go +prepare "$@" +if test $MODE = install -a -z "$ALREADY_INSTALLED"; then + welcome +fi +get_polywrap_version +if ! test -f "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap"; then + install +else + fix_links # be proactive in repairing the user installation just in case that's what they ran this for + POLYWRAP_IS_CURRENT=1 + POLYWRAP_VERSION_MAJOR="$(echo "$POLYWRAP_VERSION" | cut -d. -f1)" + POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin/polywrap" +fi + +case $MODE in +install) + if ! test -n "$ALREADY_INSTALLED"; then + check_path + if test -n "$GITHUB_ACTIONS"; then + # if the user did call us directly from GHA may as well help them out + echo "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin" >> "$GITHUB_PATH" + fi + cat -- <<-EoMD + # You’re all set! + EoMD + elif test -n "$POLYWRAP_IS_CURRENT"; then + cat <<-EoMD + # The latest version of polywrap is already installed + > $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap + EoMD + fi + echo #spacer + ;; +exec) + # ensure we use the just installed polywrap + export POLYWRAP_PREFIX="$POLYWRAP_DESTDIR" + + if test -z "$ALREADY_INSTALLED" -a -t 1; then + $POLYWRAP_EXENAME "$@" + echo #spacer + else + export PATH="$POLYWRAP_PREFIX/polywrap/v*/bin:$PATH" + exec $POLYWRAP_EXENAME "$@" + fi + ;; +esac \ No newline at end of file From e072bb327267435da3005161dab2fb65752795fa Mon Sep 17 00:00:00 2001 From: krisbitney Date: Mon, 4 Sep 2023 18:35:50 +0300 Subject: [PATCH 2/6] various fixes for CLI install script --- packages/cli/install.sh | 76 +++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 33 deletions(-) mode change 100644 => 100755 packages/cli/install.sh diff --git a/packages/cli/install.sh b/packages/cli/install.sh old mode 100644 new mode 100755 index dafd91257..93627ddd5 --- a/packages/cli/install.sh +++ b/packages/cli/install.sh @@ -13,7 +13,6 @@ unset stop while test "$#" -gt 0 -a -z "$stop"; do case $1 in --prefix) - # we don’t use POLYWRAP_PREFIX so any already installed polywrap that we use in this script doesn't break POLYWRAP_DESTDIR="$2" if test -z "$POLYWRAP_DESTDIR"; then echo "polywrap: error: --prefix requires an argument" >&2 @@ -119,8 +118,18 @@ prepare() { if command -v polywrap >/dev/null; then set +e POLYWRAP_DESTDIR="$(which polywrap)" + echo Found polywrap in $POLYWRAP_DESTDIR if test $? -eq 0 -a -n "$POLYWRAP_DESTDIR"; then - ALREADY_INSTALLED=1 + case "$POLYWRAP_DESTDIR" in + */.yarn/*|*/.npm/*) + echo #spacer + echo Warning: The existing installation is managed by a package manager. If you continue, this script will create a separate installation. + unset POLYWRAP_DESTDIR + ;; + *) + ALREADY_INSTALLED=1 + ;; + esac else unset POLYWRAP_DESTDIR fi @@ -150,8 +159,6 @@ prepare() { if test -z "$CURL"; then if command -v curl >/dev/null; then CURL="curl -Ssf" -# elif test -f "$POLYWRAP_DESTDIR/curl.se/v*/bin/curl"; then -# CURL="$POLYWRAP_DESTDIR/curl.se/v*/bin/curl -Ssf" else # how they got here without curl: we dunno echo "polywrap: error: you need curl (or set \`\$CURL\`)" >&2 @@ -162,16 +169,17 @@ prepare() { welcome() { cat <<-EoMD - # Hi 👋 Welcome to Polywrap! - * Let's get you set up. - * We'll install polywrap at: $POLYWRAP_DESTDIR - * Everything Polywrap installs goes there. - * (we won't touch anything else) - > docs https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README.md#installation - EoMD +# Hi 👋 Welcome to Polywrap! +* Let's get you set up. +* We'll install polywrap at: $POLYWRAP_DESTDIR +* Everything Polywrap installs goes there. +* (we won't touch anything else) - if test -z "$POLYWRAP_YES"; then +> docs https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README.md#installation +EoMD + + if test -n "$POLYWRAP_YES"; then choice="1" else echo #spacer @@ -183,10 +191,10 @@ welcome() { if [ "$choice" != "1" ]; then cat <<-EoMD - # aborting - Aborting! No changes were made. - Check out https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README for more info - EoMD + +# Aborting! No changes were made. +> Check out https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README for more info +EoMD echo #spacer exit 1 fi @@ -200,10 +208,10 @@ get_polywrap_version() { v_sh="$(mktemp)" cat <<-EoMD >"$v_sh" - $CURL "https://raw.githubusercontent.com/polywrap/cli/origin-dev/VERSION" | head -n1 > "$v_sh" - EoMD +$CURL "https://raw.githubusercontent.com/polywrap/cli/origin-dev/VERSION" | head -n1 > "$v_sh" +EoMD - echo "determining polywrap version" + echo "Determining polywrap version" sh "$v_sh" POLYWRAP_VERSION="$(cat "$v_sh")" @@ -212,6 +220,8 @@ get_polywrap_version() { echo "failed to get the latest version" >&2 exit 1 fi + + echo "Latest polywrap version: $POLYWRAP_VERSION" } fix_links() { @@ -262,8 +272,8 @@ install() { check_path() { cat <<-EoMD - Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin to your PATH? - EoMD +Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin to your PATH? +EoMD if test -z "$POLYWRAP_YES"; then choice="1" @@ -293,18 +303,18 @@ check_path() { else echo #spacer cat <<-EoMD - > sudo command not found. - > try installing sudo - EoMD +> sudo command not found. +> try installing sudo +EoMD fi if ! command -v polywrap >/dev/null then echo #spacer - gum_func format -- <<-EoMD - > It seems \`/usr/local/bin\` isn’t in your PATH, or we couldn't write to it. - \`PATH=$PATH\` - EoMD + cat -- <<-EoMD +> It seems \`/usr/local/bin\` isn’t in your PATH, or we couldn't write to it. +\`PATH=$PATH\` +EoMD fi fi @@ -335,13 +345,13 @@ install) echo "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin" >> "$GITHUB_PATH" fi cat -- <<-EoMD - # You’re all set! - EoMD +# You’re all set! +EoMD elif test -n "$POLYWRAP_IS_CURRENT"; then cat <<-EoMD - # The latest version of polywrap is already installed - > $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap - EoMD +# The latest version of polywrap is already installed +> $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap +EoMD fi echo #spacer ;; From b145447d3ac48a14ad482b92da0c2f8950e82bcc Mon Sep 17 00:00:00 2001 From: krisbitney Date: Mon, 4 Sep 2023 19:51:40 +0300 Subject: [PATCH 3/6] more fixes for CLI script --- .github/workflows/ci-javascript.yaml | 2 +- packages/cli/install.sh | 62 +++----------- packages/cli/package.json | 16 +++- .../cli/scripts/buildStandaloneBinaries.ts | 80 ------------------- packages/cli/src/__tests__/e2e/utils.ts | 2 +- 5 files changed, 27 insertions(+), 135 deletions(-) delete mode 100644 packages/cli/scripts/buildStandaloneBinaries.ts diff --git a/.github/workflows/ci-javascript.yaml b/.github/workflows/ci-javascript.yaml index dac3ac1ba..9e8878fac 100644 --- a/.github/workflows/ci-javascript.yaml +++ b/.github/workflows/ci-javascript.yaml @@ -339,7 +339,7 @@ jobs: mv wrappers packages/test-cases/cases - name: Build CLI standalone package for testing - run: yarn pkg:dev + run: yarn pkg:ci working-directory: ./packages/cli - name: Test CLI standalone package diff --git a/packages/cli/install.sh b/packages/cli/install.sh index 93627ddd5..67a1bcf39 100755 --- a/packages/cli/install.sh +++ b/packages/cli/install.sh @@ -44,10 +44,6 @@ prepare() { # ensure ⌃C works trap "echo; exit" INT - if ! command -v tar >/dev/null; then - echo "polywrap: error: sorry. pls install tar :(" >&2 - fi - if test -n "$VERBOSE" -o -n "$GITHUB_ACTIONS" -a -n "$RUNNER_DEBUG"; then set -x fi @@ -60,14 +56,10 @@ prepare() { HW_TARGET=$(uname)/$(uname -m) - ZZ=gz - case $HW_TARGET in Darwin/arm64) - ZZ=xz POLYWRAP_OSARCH=macos-arm64;; Darwin/x86_64) - ZZ=xz POLYWRAP_OSARCH=macos-x64;; Linux/arm64|Linux/aarch64) POLYWRAP_OSARCH=linux-arm64;; @@ -83,36 +75,6 @@ prepare() { exit 1;; esac - if test $ZZ = 'gz'; then - if command -v base64 >/dev/null; then - BASE64_TARXZ="/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AFNdADMb7AG6cMNAaNMVK8FvZMaza8QKKTQY6wZ3kG/F814lHE9ruhkFO5DAG7XNamN7JMHavgmbbLacr72NaAzgGUXOstqUaGb6kbp7jrkF+3aQT12CAAB8Uikc1gG8RwABb4AMAAAAeGbHwbHEZ/sCAAAAAARZWg==" - if echo "$BASE64_TARXZ" | base64 -d | tar Jtf - >/dev/null 2>&1; then - ZZ=xz - fi - elif command -v uudecode >/dev/null; then - TMPFILE=$(mktemp) - cat >"$TMPFILE" <<-EOF - begin 644 foo.tar.xz - M_3=Z6%H\`\`\`3FUK1&\`@\`A\`18\`\`\`!T+^6CX\`7_\`%-=\`#,;[\`&Z<,-\`:-,5*\%O - M9,:S:\0**308ZP9WD&_%\UXE'$]KNAD%.Y#\`&[7-:F-[),':O@F;;+:&;' - -P;'\$9_L"\`\`\`\`\`\`196@\`\` - \` - end - EOF - if uudecode -p "$TMPFILE" | tar Jtf - >/dev/null 2>&1; then - ZZ=xz - fi - fi - fi - - case "$ZZ" in - gz) - TAR_FLAGS=xz;; # confusingly - xz) - TAR_FLAGS=xJ;; - esac - if test -z "$POLYWRAP_DESTDIR"; then # update existing installation if found if command -v polywrap >/dev/null; then @@ -221,7 +183,9 @@ EoMD exit 1 fi - echo "Latest polywrap version: $POLYWRAP_VERSION" + POLYWRAP_VERSION_MINOR="$(echo "$POLYWRAP_VERSION" | cut -d. -f1-2)" + + echo "Latest polywrap version: v$POLYWRAP_VERSION" } fix_links() { @@ -253,26 +217,25 @@ install() { mkdir -p "$POLYWRAP_DESTDIR" POLYWRAP_DESTDIR="$(cd $POLYWRAP_DESTDIR && pwd)" # we need this PATH to be an absolute path for later stuff POLYWRAP_TMP_SCRIPT="$(mktemp)" - URL="https://github.com/polywrap/cli/releases/download/v$POLYWRAP_VERSION/$POLYWRAP_OSARCH" - echo "set -e; $CURL '$URL' | tar '$TAR_FLAGS' -C '$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/'" > "$POLYWRAP_TMP_SCRIPT" + URL="https://github.com/polywrap/cli/releases/download/$POLYWRAP_VERSION/polywrap-$POLYWRAP_OSARCH" + echo "set -e; $CURL -L '$URL' -o '$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/'" > "$POLYWRAP_TMP_SCRIPT" echo "$TITLE" sh "$POLYWRAP_TMP_SCRIPT" fix_links if ! test "$MODE" = exec; then - gum_func format -- "Successfully installed \`$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap\`" + echo -- "Successfully installed \`$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap-$POLYWRAP_OSARCH\`" fi - POLYWRAP_VERSION_MAJOR="$(echo "$POLYWRAP_VERSION" | cut -d. -f1)" - POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin/polywrap" + POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin/polywrap-$POLYWRAP_OSARCH" echo #spacer } check_path() { cat <<-EoMD -Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin to your PATH? +Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin to your PATH? EoMD if test -z "$POLYWRAP_YES"; then @@ -327,13 +290,12 @@ if test $MODE = install -a -z "$ALREADY_INSTALLED"; then welcome fi get_polywrap_version -if ! test -f "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap"; then +if ! test -f "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap-$POLYWRAP_OSARCH"; then install else fix_links # be proactive in repairing the user installation just in case that's what they ran this for POLYWRAP_IS_CURRENT=1 - POLYWRAP_VERSION_MAJOR="$(echo "$POLYWRAP_VERSION" | cut -d. -f1)" - POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin/polywrap" + POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin/polywrap-$POLYWRAP_OSARCH" fi case $MODE in @@ -342,7 +304,7 @@ install) check_path if test -n "$GITHUB_ACTIONS"; then # if the user did call us directly from GHA may as well help them out - echo "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin" >> "$GITHUB_PATH" + echo "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin" >> "$GITHUB_PATH" fi cat -- <<-EoMD # You’re all set! @@ -350,7 +312,7 @@ EoMD elif test -n "$POLYWRAP_IS_CURRENT"; then cat <<-EoMD # The latest version of polywrap is already installed -> $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap +> $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap-$POLYWRAP_OSARCH EoMD fi echo #spacer diff --git a/packages/cli/package.json b/packages/cli/package.json index 7681d387b..633602ed5 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -35,8 +35,9 @@ "test:golang": "yarn test:cmd -- --config ./jest.go.config.js", "test:watch": "yarn test -- --watch", "test:pkg": "PKG_CLI=true yarn test:e2e:p1 && yarn test:e2e:p2", - "pkg:prod": "ts-node ./scripts/buildStandaloneBinaries.ts --prod", - "pkg:dev": "ts-node ./scripts/buildStandaloneBinaries.ts" + "pkg:prod": "pkg . --compress Brotli", + "pkg:dev": "pkg . --compress GZip", + "pkg:ci": "pkg . --compress GZip -t node18-linux-x64 --output ./standalone-binaries/polywrap-linux-x64" }, "resolutions": { "colors": "1.4.0" @@ -112,6 +113,15 @@ "build/lib/defaults/build-strategies/**/*", "build/lib/defaults/deploy-modules/**/*", "build/lib/defaults/infra-modules/**/*" - ] + ], + "targets": [ + "node18-macos-arm64", + "node18-macos-x64", + "node18-linux-arm64", + "node18-linux-x64", + "node18-win-arm64", + "node18-win-x64" + ], + "outputPath":"./standalone-binaries" } } diff --git a/packages/cli/scripts/buildStandaloneBinaries.ts b/packages/cli/scripts/buildStandaloneBinaries.ts deleted file mode 100644 index 7bcbd60bd..000000000 --- a/packages/cli/scripts/buildStandaloneBinaries.ts +++ /dev/null @@ -1,80 +0,0 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import { exec } from "pkg"; -import path from "path"; -import os from "os"; - -const cliRoot = path.resolve(__dirname + "/.."); -const binPath = path.join(cliRoot, "standalone-binaries"); -const isProd = process.argv.includes("--prod"); -const targets = [ - "macos-arm64", - "macos-x64", - "linux-arm64", - "linux-x64", - "win-arm64", - "win-x64", -]; - -async function main() { - const compression = isProd ? "Brotli" : "GZip"; - - if (isProd) { - for (const target of targets) { - await compileTarget(target, cliRoot, binPath, compression); - } - } else { - const target = getPlatformAndArch(); - await compileTarget(target, cliRoot, binPath, compression); - } -} - -async function compileTarget( - target: string, - cliRoot: string, - binPath: string, - compression: string -) { - const targetPath = path.join(binPath, target, "polywrap"); - await exec([ - cliRoot, - "-t", - `node18-${target}`, - "--output", - targetPath, - "--compress", - compression, - ]); -} - -const getPlatformAndArch = (): string => { - const supportedPlatforms: Record = { - darwin: "macos", - win32: "win", - linux: "linux", - }; - const supportedArchitectures: Record = { - x64: "x64", - arm64: "arm64", - }; - - const platform = supportedPlatforms[os.platform()]; - const arch = supportedArchitectures[os.arch()]; - - if (!platform || !arch) { - throw new Error(`Unsupported platform or architecture. -Supported platforms: ${Object.keys(supportedPlatforms).toString()}. -Supported architectures: ${Object.keys(supportedArchitectures).toString()}`); - } - - if (platform === "win") { - return `${platform}-${arch}.exe`; - } - return `${platform}-${arch}`; -}; - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); diff --git a/packages/cli/src/__tests__/e2e/utils.ts b/packages/cli/src/__tests__/e2e/utils.ts index 93188cfb5..fc50273d6 100644 --- a/packages/cli/src/__tests__/e2e/utils.ts +++ b/packages/cli/src/__tests__/e2e/utils.ts @@ -98,7 +98,7 @@ const getCli = (): string => { if (process.env.PKG_CLI === "true") { const binPath = path.resolve(`${__dirname}/../../../standalone-binaries`); const platformArch = getPlatformAndArch(); - return `${binPath}/${platformArch}/polywrap`; + return `${binPath}/polywrap-${platformArch}`; } return `${__dirname}/../../../bin/polywrap`; } From 26521cff7faa1d8b14c3db599170cd8c453387d7 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Mon, 4 Sep 2023 20:00:17 +0300 Subject: [PATCH 4/6] adjusted install script ui text --- packages/cli/install.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/cli/install.sh b/packages/cli/install.sh index 67a1bcf39..a0fd95b75 100755 --- a/packages/cli/install.sh +++ b/packages/cli/install.sh @@ -145,7 +145,7 @@ EoMD choice="1" else echo #spacer - echo "How about it?" + echo "Let's gooooo! 🚀" echo "1) install polywrap" echo "2) cancel" read -p "Choice: " choice @@ -234,15 +234,11 @@ install() { } check_path() { - cat <<-EoMD -Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin to your PATH? -EoMD - if test -z "$POLYWRAP_YES"; then choice="1" else echo #spacer - echo "How about it?" + echo Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin to your PATH? echo "1) Yes" echo "2) Skip" read -p "Choice: " choice From 76909a838407b0fc1a5a1259ef714c39bc268859 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Tue, 5 Sep 2023 15:27:48 +0300 Subject: [PATCH 5/6] bug fix in install script paths; added install script usage instructions to CLI readme --- packages/cli/install.sh => install.sh | 107 ++++++++++++++------------ packages/cli/README.md | 13 ++++ 2 files changed, 69 insertions(+), 51 deletions(-) rename packages/cli/install.sh => install.sh (71%) diff --git a/packages/cli/install.sh b/install.sh similarity index 71% rename from packages/cli/install.sh rename to install.sh index a0fd95b75..41fbb4bc6 100755 --- a/packages/cli/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/bin/sh -# adapted from https://github.com/teaxyz/setup/blob/main/install.sh +# Adapted from https://github.com/teaxyz/setup/blob/main/install.sh set -e set -o noglob @@ -61,17 +61,13 @@ prepare() { POLYWRAP_OSARCH=macos-arm64;; Darwin/x86_64) POLYWRAP_OSARCH=macos-x64;; - Linux/arm64|Linux/aarch64) + Linux/arm64|Linux/aarch64|CYGWIN_NT-10.0/arm64|MSYS_NT-10.0/arm64) POLYWRAP_OSARCH=linux-arm64;; - Linux/x86_64) + Linux/x86_64|CYGWIN_NT-10.0/x86_64|MSYS_NT-10.0/x86_64) POLYWRAP_OSARCH=linux-x64;; - CYGWIN_NT-10.0/arm64|MSYS_NT-10.0/arm64) - POLYWRAP_OSARCH=win-arm64;; - CYGWIN_NT-10.0/x86_64|MSYS_NT-10.0/x86_64) - POLYWRAP_OSARCH=win-x64;; *) echo "polywrap: error: (currently) unsupported OS or architecture ($HW_TARGET)" >&2 - echo "let’s talk about it: https://discord.com/invite/Z5m88a5qWu" >&2 + echo "Let’s talk about it: https://discord.com/invite/Z5m88a5qWu" >&2 exit 1;; esac @@ -79,13 +75,22 @@ prepare() { # update existing installation if found if command -v polywrap >/dev/null; then set +e - POLYWRAP_DESTDIR="$(which polywrap)" - echo Found polywrap in $POLYWRAP_DESTDIR + if [ "$(uname)" = "Darwin" ]; then + POLYWRAP_DESTDIR=$(stat -f%Y "$(which polywrap)") + else + POLYWRAP_DESTDIR=$(readlink -f "$(which polywrap)") + fi + POLYWRAP_DESTDIR=$(dirname "$POLYWRAP_DESTDIR") + # reverse path, split on "/polywrap/" to get the last occurrence, take the second part, reverse again + # this makes sure we get the correct path even if a user or destination folder is named polywrap + POLYWRAP_DESTDIR=$(echo "$POLYWRAP_DESTDIR" | rev | awk -F'/parwylop/' '{print $2}' | rev) + + echo Found polywrap in $POLYWRAP_DESTDIR + if test $? -eq 0 -a -n "$POLYWRAP_DESTDIR"; then case "$POLYWRAP_DESTDIR" in - */.yarn/*|*/.npm/*) - echo #spacer - echo Warning: The existing installation is managed by a package manager. If you continue, this script will create a separate installation. + */.yarn/*|*/.npm/*|*/node_modules/*) + echo The existing installation is managed by a JavaScript package manager. If you continue, this script will create a separate installation that may conflict with it. unset POLYWRAP_DESTDIR ;; *) @@ -108,21 +113,10 @@ prepare() { fi fi - # be portable - case "$POLYWRAP_DESTDIR" in - "$HOME"/*) - POLYWRAP_DESTDIR_WRITABLE="\$HOME${POLYWRAP_DESTDIR#$HOME}" - ;; - *) - POLYWRAP_DESTDIR_WRITABLE="$POLYWRAP_DESTDIR" - ;; - esac - if test -z "$CURL"; then if command -v curl >/dev/null; then CURL="curl -Ssf" else - # how they got here without curl: we dunno echo "polywrap: error: you need curl (or set \`\$CURL\`)" >&2 exit 1 fi @@ -144,23 +138,28 @@ EoMD if test -n "$POLYWRAP_YES"; then choice="1" else - echo #spacer - echo "Let's gooooo! 🚀" - echo "1) install polywrap" - echo "2) cancel" - read -p "Choice: " choice + cat <<-EoMD + +Let's gooooo! 🚀 +1) Install polywrap +2) Cancel +EoMD + printf "Choice: " + read -r choice fi if [ "$choice" != "1" ]; then cat <<-EoMD # Aborting! No changes were made. -> Check out https://github.com/polywrap/cli/blob/origin-dev/packages/cli/README for more info +> Learn more about Polywrap at https://docs.polywrap.io/ EoMD echo #spacer exit 1 fi unset choice + + echo #spacer } get_polywrap_version() { @@ -183,7 +182,7 @@ EoMD exit 1 fi - POLYWRAP_VERSION_MINOR="$(echo "$POLYWRAP_VERSION" | cut -d. -f1-2)" + POLYWRAP_VERSION_MAJOR="$(echo "$POLYWRAP_VERSION" | cut -d. -f1)" echo "Latest polywrap version: v$POLYWRAP_VERSION" } @@ -209,39 +208,45 @@ fix_links() { install() { if test -n "$ALREADY_INSTALLED"; then - TITLE="updating to polywrap v$POLYWRAP_VERSION" + TITLE="Updating to polywrap v$POLYWRAP_VERSION" else - TITLE="fetching polywrap v$POLYWRAP_VERSION" + TITLE="Fetching polywrap v$POLYWRAP_VERSION" fi - mkdir -p "$POLYWRAP_DESTDIR" - POLYWRAP_DESTDIR="$(cd $POLYWRAP_DESTDIR && pwd)" # we need this PATH to be an absolute path for later stuff + mkdir -p "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/" + POLYWRAP_DESTDIR="$(cd "$POLYWRAP_DESTDIR" && pwd)" # we need this PATH to be an absolute path for later stuff POLYWRAP_TMP_SCRIPT="$(mktemp)" URL="https://github.com/polywrap/cli/releases/download/$POLYWRAP_VERSION/polywrap-$POLYWRAP_OSARCH" - echo "set -e; $CURL -L '$URL' -o '$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/'" > "$POLYWRAP_TMP_SCRIPT" + echo "set -e; $CURL -L '$URL' -o '$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap-$POLYWRAP_OSARCH'" > "$POLYWRAP_TMP_SCRIPT" echo "$TITLE" sh "$POLYWRAP_TMP_SCRIPT" + POLYWRAP_TMP_SCRIPT="$(mktemp)" + echo "chmod +x '$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap-$POLYWRAP_OSARCH';" > "$POLYWRAP_TMP_SCRIPT" + sh "$POLYWRAP_TMP_SCRIPT" + fix_links if ! test "$MODE" = exec; then echo -- "Successfully installed \`$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap-$POLYWRAP_OSARCH\`" fi - POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin/polywrap-$POLYWRAP_OSARCH" - - echo #spacer + POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin/polywrap-$POLYWRAP_OSARCH" } check_path() { - if test -z "$POLYWRAP_YES"; then + if test -n "$POLYWRAP_YES"; then choice="1" else - echo #spacer - echo Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin to your PATH? - echo "1) Yes" - echo "2) Skip" - read -p "Choice: " choice + cat <<-EoMD + +Should we add $POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin to your PATH? +This may require your root password. +1) Yes +2) Skip +EoMD + printf "Choice: " + read -r choice fi if [ "$choice" = "1" ]; then @@ -254,11 +259,13 @@ check_path() { then mkdir -p /usr/local/bin ln -sf "$POLYWRAP_EXENAME" /usr/local/bin/polywrap + echo "Added PATH alias at \`/usr/local/bin/polywrap\`" elif command -v sudo >/dev/null then sudo --reset-timestamp sudo mkdir -p /usr/local/bin sudo ln -sf "$POLYWRAP_EXENAME" /usr/local/bin/polywrap + echo "Added PATH alias at \`/usr/local/bin/polywrap\`" else echo #spacer cat <<-EoMD @@ -291,7 +298,7 @@ if ! test -f "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION/bin/polywrap-$POLYWR else fix_links # be proactive in repairing the user installation just in case that's what they ran this for POLYWRAP_IS_CURRENT=1 - POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin/polywrap-$POLYWRAP_OSARCH" + POLYWRAP_EXENAME="$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin/polywrap-$POLYWRAP_OSARCH" fi case $MODE in @@ -300,11 +307,9 @@ install) check_path if test -n "$GITHUB_ACTIONS"; then # if the user did call us directly from GHA may as well help them out - echo "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MINOR/bin" >> "$GITHUB_PATH" + echo "$POLYWRAP_DESTDIR/polywrap/v$POLYWRAP_VERSION_MAJOR/bin" >> "$GITHUB_PATH" fi - cat -- <<-EoMD -# You’re all set! -EoMD + echo "You’re all set!" elif test -n "$POLYWRAP_IS_CURRENT"; then cat <<-EoMD # The latest version of polywrap is already installed @@ -322,7 +327,7 @@ exec) echo #spacer else export PATH="$POLYWRAP_PREFIX/polywrap/v*/bin:$PATH" - exec $POLYWRAP_EXENAME "$@" + exec "$POLYWRAP_EXENAME" "$@" fi ;; esac \ No newline at end of file diff --git a/packages/cli/README.md b/packages/cli/README.md index 90d9619de..32582d142 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -26,6 +26,19 @@ You can install Cue by following the instructions found [here](https://cuelang.o ## Installation +### Standalone Executable + +For MacOS, Linux, and WSL: + +```shell +$ sh <(curl https://raw.githubusercontent.com/polywrap/cli/origin-dev/install.sh) + +# Installs to `~/.polywrap` +# If polywrap is already installed, the script instead checks for updates +``` + +### With NodeJS + Within a single project: ```bash From dbe95c60f75bbc36dcb0ca1687d9cea31f9d54bb Mon Sep 17 00:00:00 2001 From: krisbitney Date: Wed, 6 Sep 2023 14:25:04 +0300 Subject: [PATCH 6/6] added windows text to readme --- packages/cli/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/cli/README.md b/packages/cli/README.md index 32582d142..b1fbb16d8 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -37,6 +37,8 @@ $ sh <(curl https://raw.githubusercontent.com/polywrap/cli/origin-dev/install.sh # If polywrap is already installed, the script instead checks for updates ``` +We do not have an easy installation script for native Windows users, but we do produce a standalone executable for Windows users to download. You can find the latest release [here](https://github.com/polywrap/cli/releases). + ### With NodeJS Within a single project: