You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.1 KiB

#!/bin/bash
set -e
OS=$(uname -s)
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
Parameterize the install script for relative install of fnm (#48) What are your thoughts on parameterizing the install script for local install? I know this seems weird but it means that I don't have to rely on developers having any tools already installed except bash and some way to edit the files. Here is an actual example script setup I would use. Here is an example local install script `installLocal.sh` ```bash #!/usr/bin/env bash DESIRED_NODE_VERSION=v$(cat package.json | grep -Ei "\"node\"" | grep -Eoi "[0-9]+\.[0-9]+\.[0-9]+") export FNM_DIR="$(pwd)/.fnm" if [ ! -d "$FNM_DIR" ]; then curl 'https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh' | INSTALL_DIR=`pwd` bash fi set -e NODE_DIR="$FNM_DIR/node-versions/$DESIRED_NODE_VERSION/installation/bin" export PATH=$FNM_DIR:$NODE_DIR:$PATH #TODO: support fish eval `fnm env --multi` if [ ! -f "$NODE_DIR/node" ]; then fnm install $DESIRED_NODE_VERSION fi sumOfPackageJson() { cat package.json | md5sum | cut -d' ' -f1 } if [ ! -f ".packageRevision" ] || [ "$(cat .packageRevision)" != "$(sumOfPackageJson)" ]; then sumOfPackageJson > .packageRevision npm install fi ``` then in script called `nodew` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node "$@" ``` and `npmw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh npm "$@" ``` and for completeness sake I usually go one step further and do an `appw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node ./app/index.js "$@" ```
6 years ago
INSTALL_DIR="$HOME/.fnm"
# Parse Flags
parse_args() {
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-d|--install-dir)
INSTALL_DIR="$2"
shift # past argument
shift # past value
;;
-s|--skip-shell)
SKIP_SHELL="true"
shift # past argument
;;
*)
echo "Unrecognized argument $key"
exit 1
;;
esac
done
}
download_fnm() {
URL=https://github.com/Schniz/fnm/releases/latest/download/$FILENAME.zip
DOWNLOAD_DIR=$(mktemp -d)
echo "Downloading $URL..."
Parameterize the install script for relative install of fnm (#48) What are your thoughts on parameterizing the install script for local install? I know this seems weird but it means that I don't have to rely on developers having any tools already installed except bash and some way to edit the files. Here is an actual example script setup I would use. Here is an example local install script `installLocal.sh` ```bash #!/usr/bin/env bash DESIRED_NODE_VERSION=v$(cat package.json | grep -Ei "\"node\"" | grep -Eoi "[0-9]+\.[0-9]+\.[0-9]+") export FNM_DIR="$(pwd)/.fnm" if [ ! -d "$FNM_DIR" ]; then curl 'https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh' | INSTALL_DIR=`pwd` bash fi set -e NODE_DIR="$FNM_DIR/node-versions/$DESIRED_NODE_VERSION/installation/bin" export PATH=$FNM_DIR:$NODE_DIR:$PATH #TODO: support fish eval `fnm env --multi` if [ ! -f "$NODE_DIR/node" ]; then fnm install $DESIRED_NODE_VERSION fi sumOfPackageJson() { cat package.json | md5sum | cut -d' ' -f1 } if [ ! -f ".packageRevision" ] || [ "$(cat .packageRevision)" != "$(sumOfPackageJson)" ]; then sumOfPackageJson > .packageRevision npm install fi ``` then in script called `nodew` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node "$@" ``` and `npmw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh npm "$@" ``` and for completeness sake I usually go one step further and do an `appw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node ./app/index.js "$@" ```
6 years ago
mkdir -p $INSTALL_DIR &> /dev/null
6 years ago
curl --progress-bar -L $URL -o $DOWNLOAD_DIR/$FILENAME.zip
unzip -q $DOWNLOAD_DIR/$FILENAME.zip -d $DOWNLOAD_DIR
Parameterize the install script for relative install of fnm (#48) What are your thoughts on parameterizing the install script for local install? I know this seems weird but it means that I don't have to rely on developers having any tools already installed except bash and some way to edit the files. Here is an actual example script setup I would use. Here is an example local install script `installLocal.sh` ```bash #!/usr/bin/env bash DESIRED_NODE_VERSION=v$(cat package.json | grep -Ei "\"node\"" | grep -Eoi "[0-9]+\.[0-9]+\.[0-9]+") export FNM_DIR="$(pwd)/.fnm" if [ ! -d "$FNM_DIR" ]; then curl 'https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh' | INSTALL_DIR=`pwd` bash fi set -e NODE_DIR="$FNM_DIR/node-versions/$DESIRED_NODE_VERSION/installation/bin" export PATH=$FNM_DIR:$NODE_DIR:$PATH #TODO: support fish eval `fnm env --multi` if [ ! -f "$NODE_DIR/node" ]; then fnm install $DESIRED_NODE_VERSION fi sumOfPackageJson() { cat package.json | md5sum | cut -d' ' -f1 } if [ ! -f ".packageRevision" ] || [ "$(cat .packageRevision)" != "$(sumOfPackageJson)" ]; then sumOfPackageJson > .packageRevision npm install fi ``` then in script called `nodew` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node "$@" ``` and `npmw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh npm "$@" ``` and for completeness sake I usually go one step further and do an `appw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node ./app/index.js "$@" ```
6 years ago
mv $DOWNLOAD_DIR/$FILENAME/fnm $INSTALL_DIR/fnm
chmod u+x $INSTALL_DIR/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)
if [ "$CURRENT_SHELL" == "zsh" ]; then
6 years ago
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 --multi`"'
6 years ago
echo '' >> $CONF_FILE
echo '# fnm' >> $CONF_FILE
echo 'export PATH=$HOME/.fnm:$PATH' >> $CONF_FILE
echo 'eval "`fnm env --multi`"' >> $CONF_FILE
elif [ "$CURRENT_SHELL" == "fish" ]; then
6 years ago
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 ' fnm env --multi | source'
6 years ago
echo '' >> $CONF_FILE
echo '# fnm' >> $CONF_FILE
echo 'set PATH $HOME/.fnm $PATH' >> $CONF_FILE
echo 'fnm env --multi | source' >> $CONF_FILE
elif [ "$CURRENT_SHELL" == "bash" ]; then
if [ "$OS" == "Darwin" ]; then
CONF_FILE=$HOME/.profile
else
CONF_FILE=$HOME/.bashrc
fi
6 years ago
echo "Installing for Bash. Appending the following to $CONF_FILE:"
echo ""
echo ' # fnm'
echo ' export PATH=$HOME/.fnm:$PATH'
echo ' eval "`fnm env --multi`"'
6 years ago
echo '' >> $CONF_FILE
echo '# fnm' >> $CONF_FILE
echo 'export PATH=$HOME/.fnm:$PATH' >> $CONF_FILE
echo 'eval "`fnm env --multi`"' >> $CONF_FILE
else
echo "Could not infer shell type. Please set up manually."
exit 1
fi
6 years ago
echo ""
echo "In order to apply the changes, open a new terminal or run the following command:"
echo ""
echo " source $CONF_FILE"
}
parse_args "$@"
check_dependencies
download_fnm
Parameterize the install script for relative install of fnm (#48) What are your thoughts on parameterizing the install script for local install? I know this seems weird but it means that I don't have to rely on developers having any tools already installed except bash and some way to edit the files. Here is an actual example script setup I would use. Here is an example local install script `installLocal.sh` ```bash #!/usr/bin/env bash DESIRED_NODE_VERSION=v$(cat package.json | grep -Ei "\"node\"" | grep -Eoi "[0-9]+\.[0-9]+\.[0-9]+") export FNM_DIR="$(pwd)/.fnm" if [ ! -d "$FNM_DIR" ]; then curl 'https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh' | INSTALL_DIR=`pwd` bash fi set -e NODE_DIR="$FNM_DIR/node-versions/$DESIRED_NODE_VERSION/installation/bin" export PATH=$FNM_DIR:$NODE_DIR:$PATH #TODO: support fish eval `fnm env --multi` if [ ! -f "$NODE_DIR/node" ]; then fnm install $DESIRED_NODE_VERSION fi sumOfPackageJson() { cat package.json | md5sum | cut -d' ' -f1 } if [ ! -f ".packageRevision" ] || [ "$(cat .packageRevision)" != "$(sumOfPackageJson)" ]; then sumOfPackageJson > .packageRevision npm install fi ``` then in script called `nodew` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node "$@" ``` and `npmw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh npm "$@" ``` and for completeness sake I usually go one step further and do an `appw` ```bash #!/usr/bin/env bash cd "$( dirname "${BASH_SOURCE[0]}" )" source ./installLocal.sh node ./app/index.js "$@" ```
6 years ago
if [ "$SKIP_SHELL" != "true" ]; then
setup_shell
fi