From f47474bf74f3739a5bb67bf83a63aea74a8a39a5 Mon Sep 17 00:00:00 2001 From: Bader Nasser Date: Sun, 25 Jun 2017 22:23:26 +0400 Subject: [PATCH 1/3] Change Bash shebang --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 7b669a0db..ce5dfe33a 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash set -e reset="\033[0m" From fa48abc4366215e35aff01cf2055f4c91bf61bad Mon Sep 17 00:00:00 2001 From: Bader Nasser Date: Tue, 27 Jun 2017 14:27:53 +0400 Subject: [PATCH 2/3] Use sh syntax --- install.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index ce5dfe33a..d1ef046f0 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh set -e reset="\033[0m" @@ -45,12 +45,12 @@ yarn_get_tarball() { # Verifies the GPG signature of the tarball yarn_verify_integrity() { # Check if GPG is installed - if [[ -z "$(command -v gpg)" ]]; then + if [ -z "$(command -v gpg)" ]; then printf "$yellow> WARNING: GPG is not installed, integrity can not be verified!$reset\n" return fi - if [ "$YARN_GPG" == "no" ]; then + if [ "$YARN_GPG" = "no" ]; then printf "$cyan> WARNING: Skipping GPG integrity check!$reset\n" return fi @@ -88,7 +88,7 @@ yarn_link() { command printf "${SOURCE_STR}" else if ! grep -q 'yarn' "$YARN_PROFILE"; then - if [[ $YARN_PROFILE == *"fish"* ]]; then + if [ $YARN_PROFILE = *"fish"* ]; then command fish -c 'set -U fish_user_paths $fish_user_paths ~/.yarn/bin' else command printf "$SOURCE_STR" >> "$YARN_PROFILE" @@ -201,11 +201,11 @@ yarn_install() { yarn_verify_or_quit() { read -p "$1 [y/N] " -n 1 -r echo - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + case $REPLY in [^yY]* ) printf "$red> Aborting$reset\n" exit 1 - fi + ;; + esac } cd ~ From 3daa17abf31e1e1a97112dc550b41468a6a8c399 Mon Sep 17 00:00:00 2001 From: Bader Nasser Date: Wed, 28 Jun 2017 17:36:25 +0400 Subject: [PATCH 3/3] Use sh syntax (round 2) --- install.sh | 97 +++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/install.sh b/install.sh index d1ef046f0..8fbafe56b 100755 --- a/install.sh +++ b/install.sh @@ -10,7 +10,7 @@ white="\033[37m" gpg_key=9D41F3C3 yarn_get_tarball() { - printf "$cyan> Downloading tarball...$reset\n" + echo "${cyan}> Downloading tarball...${reset}" if [ "$1" = '--nightly' ]; then url=https://nightly.yarnpkg.com/latest.tar.gz elif [ "$1" = '--rc' ]; then @@ -18,26 +18,26 @@ yarn_get_tarball() { elif [ "$1" = '--version' ]; then # Validate that the version matches MAJOR.MINOR.PATCH to avoid garbage-in/garbage-out behavior version=$2 - if echo $version | grep -qE "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$"; then + if echo "$version" | grep -qE "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$"; then url="https://yarnpkg.com/downloads/$version/yarn-v$version.tar.gz" else - printf "$red> Version number must match MAJOR.MINOR.PATCH.$reset\n" + echo "${red}> Version number must match MAJOR.MINOR.PATCH.${reset}" exit 1; fi else url=https://yarnpkg.com/latest.tar.gz fi # Get both the tarball and its GPG signature - tarball_tmp=`mktemp -t yarn.tar.gz.XXXXXXXXXX` + tarball_tmp=$(mktemp -t yarn.tar.gz.XXXXXXXXXX) if curl --fail -L -o "$tarball_tmp#1" "$url{,.asc}"; then - yarn_verify_integrity $tarball_tmp + yarn_verify_integrity "$tarball_tmp" - printf "$cyan> Extracting to ~/.yarn...$reset\n" + echo "${cyan}> Extracting to ~/.yarn...${reset}" mkdir .yarn - tar zxf $tarball_tmp -C .yarn --strip 1 # extract tarball - rm $tarball_tmp* + tar zxf "$tarball_tmp" -C .yarn --strip 1 # extract tarball + rm $tarball_tmp* # Ignore shellcheck warning; it's intended to have globbing! else - printf "$red> Failed to download $url.$reset\n" + echo "${red}> Failed to download ${url}.${reset}" exit 1; fi } @@ -46,65 +46,65 @@ yarn_get_tarball() { yarn_verify_integrity() { # Check if GPG is installed if [ -z "$(command -v gpg)" ]; then - printf "$yellow> WARNING: GPG is not installed, integrity can not be verified!$reset\n" + echo "${yellow}> WARNING: GPG is not installed, integrity can not be verified!${reset}" return fi if [ "$YARN_GPG" = "no" ]; then - printf "$cyan> WARNING: Skipping GPG integrity check!$reset\n" + echo "${cyan}> WARNING: Skipping GPG integrity check!${reset}" return fi - printf "$cyan> Verifying integrity...$reset\n" + echo "${cyan}> Verifying integrity...${reset}" # Grab the public key if it doesn't already exist gpg --list-keys $gpg_key >/dev/null 2>&1 || (curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import) if [ ! -f "$1.asc" ]; then - printf "$red> Could not download GPG signature for this Yarn release. This means the release can not be verified!$reset\n" + echo "${red}> Could not download GPG signature for this Yarn release. This means the release can not be verified!${reset}" yarn_verify_or_quit "> Do you really want to continue?" return fi # Actually perform the verification - if gpg --verify "$1.asc" $1; then - printf "$green> GPG signature looks good$reset\n" + if gpg --verify "$1.asc" "$1"; then + echo "${green}> GPG signature looks good.${reset}" else - printf "$red> GPG signature for this Yarn release is invalid! This is BAD and may mean the release has been tampered with. It is strongly recommended that you report this to the Yarn developers.$reset\n" + echo "${red}> GPG signature for this Yarn release is invalid! This is BAD and may mean the release has been tampered with. It is strongly recommended that you report this to the Yarn developers.${reset}" yarn_verify_or_quit "> Do you really want to continue?" fi } yarn_link() { - printf "$cyan> Adding to \$PATH...$reset\n" + echo "${cyan}> Adding to \$PATH...${reset}" YARN_PROFILE="$(yarn_detect_profile)" SOURCE_STR="\nexport PATH=\"\$HOME/.yarn/bin:\$PATH\"\n" - if [ -z "${YARN_PROFILE-}" ] ; then - printf "$red> Profile not found. Tried ${YARN_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.\n" + if [ -z "${YARN_PROFILE-}" ]; then + echo "${red}> Profile not found. Tried ${YARN_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." echo "> Create one of them and run this script again" echo "> Create it (touch ${YARN_PROFILE}) and run this script again" echo " OR" - printf "> Append the following lines to the correct file yourself:$reset\n" + echo "> Append the following lines to the correct file yourself:${reset}" command printf "${SOURCE_STR}" else if ! grep -q 'yarn' "$YARN_PROFILE"; then - if [ $YARN_PROFILE = *"fish"* ]; then - command fish -c 'set -U fish_user_paths $fish_user_paths ~/.yarn/bin' + if echo "$YARN_PROFILE" | grep -q "fish"; then + command fish -c "set -U fish_user_paths ${fish_user_paths} ~/.yarn/bin" else command printf "$SOURCE_STR" >> "$YARN_PROFILE" fi fi - printf "$cyan> We've added the following to your $YARN_PROFILE\n" + echo "${cyan}> We've added the following to your ${YARN_PROFILE}" echo "> If this isn't the profile of your current shell then please add the following to your correct profile:" - printf " $SOURCE_STR$reset\n" + echo " ${SOURCE_STR}${reset}" - version=`$HOME/.yarn/bin/yarn --version` || ( - printf "$red> Yarn was installed, but doesn't seem to be working :(.$reset\n" + version=$("$HOME"/.yarn/bin/yarn --version) || ( + echo "${red}> Yarn was installed, but doesn't seem to be working :(.${reset}" exit 1; ) - printf "$green> Successfully installed Yarn $version! Please open another terminal where the \`yarn\` command will now be available.$reset\n" + echo "${green}> Successfully installed Yarn ${version}! Please open another terminal where the \`yarn\` command will now be available.${reset}" fi } @@ -114,9 +114,9 @@ yarn_detect_profile() { return fi - local DETECTED_PROFILE + # local DETECTED_PROFILE DETECTED_PROFILE='' - local SHELLTYPE + # local SHELLTYPE SHELLTYPE="$(basename "/$SHELL")" if [ "$SHELLTYPE" = "bash" ]; then @@ -155,58 +155,59 @@ yarn_reset() { } yarn_install() { - printf "${white}Installing Yarn!$reset\n" + echo "${white}Installing Yarn!${reset}" if [ -d "$HOME/.yarn" ]; then if which yarn; then - local latest_url - local specified_version - local version_type + # local latest_url + # local specified_version + # local version_type if [ "$1" = '--nightly' ]; then latest_url=https://nightly.yarnpkg.com/latest-tar-version - specified_version=`curl -sS $latest_url` + specified_version=$(curl -sS $latest_url) version_type='latest' elif [ "$1" = '--version' ]; then specified_version=$2 version_type='specified' elif [ "$1" = '--rc' ]; then latest_url=https://yarnpkg.com/latest-rc-version - specified_version=`curl -sS $latest_url` + specified_version=$(curl -sS $latest_url) version_type='rc' else latest_url=https://yarnpkg.com/latest-version - specified_version=`curl -sS $latest_url` + specified_version=$(curl -sS $latest_url) version_type='latest' fi - yarn_version=`yarn -V` - yarn_alt_version=`yarn --version` - if [ "$specified_version" = "$yarn_version" -o "$specified_version" = "$yarn_alt_version" ]; then - printf "$green> Yarn is already at the $specified_version version.$reset\n" + yarn_version=$(yarn -V) + yarn_alt_version=$(yarn --version) + if [ "$specified_version" = "$yarn_version" ] || [ "$specified_version" = "$yarn_alt_version" ]; then + echo "${green}> Yarn is already at the ${specified_version} version.${reset}" exit 0 else rm -rf "$HOME/.yarn" fi else - printf "$red> $HOME/.yarn already exists, possibly from a past Yarn install.$reset\n" - printf "$red> Remove it (rm -rf $HOME/.yarn) and run this script again.$reset\n" + echo "${red}> ${HOME}/.yarn already exists, possibly from a past Yarn install." + echo "$> Remove it (rm -rf ${HOME}/.yarn) and run this script again.${reset}" exit 0 fi fi - yarn_get_tarball $1 $2 + yarn_get_tarball "$1" "$2" yarn_link yarn_reset } yarn_verify_or_quit() { - read -p "$1 [y/N] " -n 1 -r - echo - case $REPLY in [^yY]* ) - printf "$red> Aborting$reset\n" + echo "$1 [y/N] \c" + read -r REPLY + + case $REPLY in [!yY]* ) + echo "${red}> Aborting${reset}" exit 1 ;; esac } cd ~ -yarn_install $1 $2 +yarn_install "$1" "$2"