if [ "$RELEASE" = "latest" ]; then URL="https://github.com/Schniz/fnm/releases/latest/download/$FILENAME.zip" else URL="https://github.com/Schniz/fnm/releases/download/$RELEASE/$FILENAME.zip" fi
if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then echo"Download failed. Check that the release/filename are correct." exit 1 fi
他还是要通过 github 下载,无法访问的话自然会下载失败。但是他会提示你正在哪个链接下载,比如https://github.com/Schniz/fnm/releases/latest/download/fnm-linux.zip。 后面的那个 zip 文件就是需要下载的文件,所以去 fnm 的 github releases 里手动下载这个 zip 文件,然后传到服务器里。
parse_args "$@" # set_filename check_dependencies download_fnm if [ "$SKIP_SHELL" != "true" ]; then setup_shell fi
然后进入download_fnm函数里
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# 将下载相关的命令注释掉,不需要从github下载了 # if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then # echo "Download failed. Check that the release/filename are correct." # exit 1 # fi
if [ -d "$HOME/.fnm" ]; then INSTALL_DIR="$HOME/.fnm" elif [ -n "$XDG_DATA_HOME" ]; then INSTALL_DIR="$XDG_DATA_HOME/fnm" elif [ "$OS" = "Darwin" ]; then INSTALL_DIR="$HOME/Library/Application Support/fnm" else INSTALL_DIR="$HOME/.local/share/fnm" fi
# Parse Flags parse_args() { while [[ $# -gt 0 ]]; do key="$1"
case$keyin -d | --install-dir) INSTALL_DIR="$2" shift# past argument shift# past value ;; -s | --skip-shell) SKIP_SHELL="true" shift# past argument ;; --force-install | --force-no-brew) echo"\`--force-install\`: I hope you know what you're doing." >&2 FORCE_INSTALL="true" shift ;; -r | --release) RELEASE="$2" shift# past release argument shift# past release value ;; *) echo"Unrecognized argument $key" exit 1 ;; esac done }
set_filename() { if [ "$OS" = "Linux" ]; then # Based on https://stackoverflow.com/a/45125525 case"$(uname -m)"in arm | armv7*) FILENAME="fnm-arm32" ;; aarch* | armv8*) FILENAME="fnm-arm64" ;; *) FILENAME="fnm-linux" esac elif [ "$OS" = "Darwin" ] && [ "$FORCE_INSTALL" = "true" ]; then FILENAME="fnm-macos" USE_HOMEBREW="false" echo"Downloading the latest fnm binary from GitHub..." echo" Pro tip: it's easier to use Homebrew for managing fnm in macOS." echo" Remove the \`--force-no-brew\` so it will be easy to upgrade." elif [ "$OS" = "Darwin" ]; then USE_HOMEBREW="true" echo"Downloading fnm using Homebrew..." elif [ "$OS" = "Windows" ] ; then FILENAME="fnm-windows" echo"Downloading the latest fnm binary from GitHub..." 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 }
download_fnm() { if [ "$USE_HOMEBREW" = "true" ]; then brew install fnm else if [ "$RELEASE" = "latest" ]; then URL="https://github.com/Schniz/fnm/releases/latest/download/$FILENAME.zip" else URL="https://github.com/Schniz/fnm/releases/download/$RELEASE/$FILENAME.zip" fi
DOWNLOAD_DIR=$(mktemp -d)
# echo "Downloading $URL..."
mkdir -p "$INSTALL_DIR" &>/dev/null
# if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then # echo "Download failed. Check that the release/filename are correct." # exit 1 # fi
if [ -f "$DOWNLOAD_DIR/fnm" ]; then mv"$DOWNLOAD_DIR/fnm""$INSTALL_DIR/fnm" else mv"$DOWNLOAD_DIR/$FILENAME/fnm""$INSTALL_DIR/fnm" fi
chmod u+x "$INSTALL_DIR/fnm" fi }
check_dependencies() { echo"Checking dependencies for the installation script..."
echo -n "Checking availability of unzip... " ifhash unzip 2>/dev/null; then echo"OK!" else echo"Missing!" SHOULD_EXIT="true" fi
if [ "$USE_HOMEBREW" = "true" ]; then echo -n "Checking availability of Homebrew (brew)... " ifhash brew 2>/dev/null; then echo"OK!" else echo"Missing!" SHOULD_EXIT="true" fi fi
if [ "$SHOULD_EXIT" = "true" ]; then echo"Not installing fnm due to missing dependencies." exit 1 fi }
ensure_containing_dir_exists() { local CONTAINING_DIR CONTAINING_DIR="$(dirname "$1")" if [ ! -d "$CONTAINING_DIR" ]; then echo" >> Creating directory $CONTAINING_DIR" mkdir -p "$CONTAINING_DIR" fi }