From cd464ac1f82dbbeeb5fa07c88fb66e114f85664c Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Thu, 31 Jan 2019 13:08:10 +0200 Subject: [PATCH 1/7] Add installation script --- .ci/install.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 .ci/install.sh diff --git a/.ci/install.sh b/.ci/install.sh new file mode 100755 index 0000000..187b3a2 --- /dev/null +++ b/.ci/install.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +OS=$(uname -a | cut -d" " -f 1) + +if [ "$OS" == "Darwin" ]; then + FILENAME="fnm-macos" +elif [ "$OS" == "Linux" ]; then + FILENAME="fnm-linux" +else + echo "OS $OS is not supported." + echo "If you think that's a bug - please file an issue to https://github.com/Schniz/fnm/issues" + exit 1 +fi + +get_latest_release() { + # Taken from https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + grep '"tag_name":' | # Get tag line + sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +} + +download_fnm() { + LATEST_RELEASE=$(get_latest_release Schniz/fnm) + URL=https://github.com/Schniz/fnm/releases/download/$LATEST_RELEASE/$FILENAME.zip + DOWNLOAD_DIR=$(mktemp -d -t fnm) + + echo "Downloading $URL..." + + mkdir -p $HOME/.fnm &> /dev/null + curl -L $URL -o $DOWNLOAD_DIR/$FILENAME.zip + unzip $DOWNLOAD_DIR/$FILENAME.zip -d $DOWNLOAD_DIR + mv $DOWNLOAD_DIR/$FILENAME/fnm $HOME/.fnm/fnm + chmod u+x $HOME/.fnm/fnm +} + +setup_shell() { + CURRENT_SHELL=$(basename $SHELL) + + if [ "$CURRENT_SHELL" == "zsh" ]; then + echo "Installing for Zsh. Appending the following to $HOME/.zshrc:" + echo 'export PATH=$HOME/.fnm:$PATH' >> $HOME/.zshrc + echo 'eval `fnm env`' >> $HOME/.zshrc + elif [ "$CURRENT_SHELL" == "fish" ]; then + echo 'Installation for Fish is WIP' + exit 1 + elif [ "$CURRENT_SHELL" == "bash" ]; then + echo "Installing for Bash. Appending the following to $HOME/.bashrc:" + echo 'export PATH=$HOME/.fnm:$PATH' + echo 'eval `fnm env`' + + echo 'export PATH=$HOME/.fnm:$PATH' >> $HOME/.bashrc + echo 'eval `fnm env`' >> $HOME/.bashrc + else + echo "Could not infer shell type. Please set up manually." + exit 1 + fi +} + +download_fnm +setup_shell From 8e4f6f1913e9848c9c6dbcbc550448a75a99d637 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Tue, 5 Feb 2019 17:01:04 +0200 Subject: [PATCH 2/7] Fish installation and Zsh text --- .ci/install.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index 187b3a2..b3aef46 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -38,11 +38,20 @@ setup_shell() { if [ "$CURRENT_SHELL" == "zsh" ]; then echo "Installing for Zsh. Appending the following to $HOME/.zshrc:" + echo 'export PATH=$HOME/.fnm:$PATH' + echo 'eval `fnm env`' + echo 'export PATH=$HOME/.fnm:$PATH' >> $HOME/.zshrc echo 'eval `fnm env`' >> $HOME/.zshrc + elif [ "$CURRENT_SHELL" == "fish" ]; then - echo 'Installation for Fish is WIP' - exit 1 + echo "Installing for Fish. Appending the following to $HOME/.config/fish/config.fish:" + echo 'set PATH $HOME/.fnm $PATH' + echo 'eval (fnm env)' + + echo 'set PATH $HOME/.fnm $PATH' >> $HOME/.config/fish/config.fish + echo 'eval (fnm env)' >> $HOME/.config/fish/config.fish + elif [ "$CURRENT_SHELL" == "bash" ]; then echo "Installing for Bash. Appending the following to $HOME/.bashrc:" echo 'export PATH=$HOME/.fnm:$PATH' @@ -50,6 +59,7 @@ setup_shell() { echo 'export PATH=$HOME/.fnm:$PATH' >> $HOME/.bashrc echo 'eval `fnm env`' >> $HOME/.bashrc + else echo "Could not infer shell type. Please set up manually." exit 1 From 17ca446e0c69694b4a48424fdb7a8842e48ffa20 Mon Sep 17 00:00:00 2001 From: Spencer Elliott Date: Tue, 5 Feb 2019 17:13:36 +0200 Subject: [PATCH 3/7] Apply suggestions from code review Co-Authored-By: Schniz --- .ci/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index b3aef46..d3a6a79 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -47,10 +47,10 @@ setup_shell() { elif [ "$CURRENT_SHELL" == "fish" ]; then echo "Installing for Fish. Appending the following to $HOME/.config/fish/config.fish:" echo 'set PATH $HOME/.fnm $PATH' - echo 'eval (fnm env)' + echo 'eval (fnm env --fish)' echo 'set PATH $HOME/.fnm $PATH' >> $HOME/.config/fish/config.fish - echo 'eval (fnm env)' >> $HOME/.config/fish/config.fish + echo 'eval (fnm env --fish)' >> $HOME/.config/fish/config.fish elif [ "$CURRENT_SHELL" == "bash" ]; then echo "Installing for Bash. Appending the following to $HOME/.bashrc:" From 2b7af929cfeb834d0489195433d518ec8a6851a5 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Tue, 5 Feb 2019 17:29:50 +0200 Subject: [PATCH 4/7] moar text --- .ci/install.sh | 54 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index d3a6a79..495b3ac 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -27,8 +27,8 @@ download_fnm() { echo "Downloading $URL..." mkdir -p $HOME/.fnm &> /dev/null - curl -L $URL -o $DOWNLOAD_DIR/$FILENAME.zip - unzip $DOWNLOAD_DIR/$FILENAME.zip -d $DOWNLOAD_DIR + curl --progress-bar -L $URL -o $DOWNLOAD_DIR/$FILENAME.zip + unzip -q $DOWNLOAD_DIR/$FILENAME.zip -d $DOWNLOAD_DIR mv $DOWNLOAD_DIR/$FILENAME/fnm $HOME/.fnm/fnm chmod u+x $HOME/.fnm/fnm } @@ -37,33 +37,53 @@ setup_shell() { CURRENT_SHELL=$(basename $SHELL) if [ "$CURRENT_SHELL" == "zsh" ]; then - echo "Installing for Zsh. Appending the following to $HOME/.zshrc:" - echo 'export PATH=$HOME/.fnm:$PATH' - echo 'eval `fnm env`' + CONF_FILE=$HOME/.zshrc + echo "Installing for Zsh. Appending the following to $CONF_FILE:" + echo "" + echo ' # fnm' + echo ' export PATH=$HOME/.fnm:$PATH' + echo ' eval `fnm env`' - echo 'export PATH=$HOME/.fnm:$PATH' >> $HOME/.zshrc - echo 'eval `fnm env`' >> $HOME/.zshrc + echo '' >> $CONF_FILE + echo '# fnm' >> $CONF_FILE + echo 'export PATH=$HOME/.fnm:$PATH' >> $CONF_FILE + echo 'eval `fnm env`' >> $CONF_FILE elif [ "$CURRENT_SHELL" == "fish" ]; then - echo "Installing for Fish. Appending the following to $HOME/.config/fish/config.fish:" - echo 'set PATH $HOME/.fnm $PATH' - echo 'eval (fnm env --fish)' + CONF_FILE=$HOME/.config/fish/config.fish + echo "Installing for Fish. Appending the following to $CONF_FILE:" + echo "" + echo ' # fnm' + echo ' set PATH $HOME/.fnm $PATH' + echo ' eval (fnm env --fish)' - echo 'set PATH $HOME/.fnm $PATH' >> $HOME/.config/fish/config.fish - echo 'eval (fnm env --fish)' >> $HOME/.config/fish/config.fish + echo '' >> $CONF_FILE + echo '# fnm' >> $CONF_FILE + echo 'set PATH $HOME/.fnm $PATH' >> $CONF_FILE + echo 'eval (fnm env --fish)' >> $CONF_FILE elif [ "$CURRENT_SHELL" == "bash" ]; then - echo "Installing for Bash. Appending the following to $HOME/.bashrc:" - echo 'export PATH=$HOME/.fnm:$PATH' - echo 'eval `fnm env`' + CONF_FILE=$HOME/.bashrc + echo "Installing for Bash. Appending the following to $CONF_FILE:" + echo "" + echo ' # fnm' + echo ' export PATH=$HOME/.fnm:$PATH' + echo ' eval `fnm env`' - echo 'export PATH=$HOME/.fnm:$PATH' >> $HOME/.bashrc - echo 'eval `fnm env`' >> $HOME/.bashrc + echo '' >> $CONF_FILE + echo '# fnm' >> $CONF_FILE + echo 'export PATH=$HOME/.fnm:$PATH' >> $CONF_FILE + echo 'eval `fnm env`' >> $CONF_FILE else echo "Could not infer shell type. Please set up manually." exit 1 fi + + echo "" + echo "In order to apply the changes, open a new terminal or run the following command:" + echo "" + echo " source $CONF_FILE" } download_fnm From a081ea0797d789997c118c068eade1318a8fb6e8 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Wed, 6 Feb 2019 10:34:55 +0200 Subject: [PATCH 5/7] Add installation steps to README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 6cec1b7..7a9a105 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,16 @@ ## Installation +### Using a script + +For `bash`, `zsh` and `fish` shells, there's an [automatic installation script](./.ci/install.sh): + +```bash +curl https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh | bash +``` + +### Manually + * Download the [latest release binary](https://github.com/Schniz/fnm/releases) for your system * Make it available globally on `$PATH` * Add the following line to your `.bashrc`/`.zshrc` file: From 373ed8c361b8e0082d8613743762ebc4250acb37 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Wed, 6 Feb 2019 11:05:11 +0200 Subject: [PATCH 6/7] Check dependencies --- .ci/install.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.ci/install.sh b/.ci/install.sh index 495b3ac..51f6b74 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -22,7 +22,7 @@ get_latest_release() { download_fnm() { LATEST_RELEASE=$(get_latest_release Schniz/fnm) URL=https://github.com/Schniz/fnm/releases/download/$LATEST_RELEASE/$FILENAME.zip - DOWNLOAD_DIR=$(mktemp -d -t fnm) + DOWNLOAD_DIR=$(mktemp -d) echo "Downloading $URL..." @@ -33,6 +33,30 @@ download_fnm() { chmod u+x $HOME/.fnm/fnm } +check_dependencies() { + echo "Checking dependencies for the installation script..." + + echo -n "Checking availablity of curl... " + if hash curl 2>/dev/null; then + echo "OK!" + else + echo "Missing!" + SHOULD_EXIT="true" + fi + + echo -n "Checking availablity of unzip... " + if hash unzip 2>/dev/null; then + echo "OK!" + else + echo "Missing!" + SHOULD_EXIT="true" + fi + + if [ "$SHOULD_EXIT" = "true" ]; then + exit 1 + fi +} + setup_shell() { CURRENT_SHELL=$(basename $SHELL) @@ -86,5 +110,6 @@ setup_shell() { echo " source $CONF_FILE" } +check_dependencies download_fnm setup_shell From 3700b5f95c84702608656c44a6ff35cd8080681a Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Wed, 6 Feb 2019 12:49:44 +0200 Subject: [PATCH 7/7] Remove from todo --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 7a9a105..5380058 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,6 @@ Lists the Node versions available to download remotely. Prints the required shell commands in order to configure your shell, Bash compliant by default. Provide `--fish` to output the Fish-compliant version. ## Future Plans -- [ ] Add a simpler way of installing it (`curl | bash`?) - [ ] Feature: make versions complete the latest: `10` would infer the latest minor and patch versions of node 10. `10.1` would infer the latest patch version of node 10.1 - [ ] Feature: `fnm use --install`, `fnm use --quiet` - [ ] Feature: `fnm install lts`?