From 5d765768ccd41df826ef2da4e8fe3f2418b1da1d Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 9 Jul 2019 17:24:31 +0100 Subject: [PATCH 1/2] Allow the build system to work without bash. --- Makefile | 4 ++-- configure | 21 ++++++++++----------- scripts/clean-old.sh | 39 ++++++++++++++++----------------------- scripts/dep-update | 2 +- scripts/dev-dep-update | 2 +- scripts/doc-build.sh | 10 +++++----- scripts/install.sh | 7 ------- scripts/release.sh | 4 ++-- scripts/relocate.sh | 4 ++-- 9 files changed, 39 insertions(+), 54 deletions(-) diff --git a/Makefile b/Makefile index 4e00647a19cf0..eabaecbfea740 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # vim: set softtabstop=2 shiftwidth=2: -SHELL = bash +SHELL = sh PUBLISHTAG = $(shell node scripts/publish-tag.js) BRANCH = $(shell git rev-parse --abbrev-ref HEAD) @@ -182,7 +182,7 @@ publish: gitclean ls-ok link doc-clean doc release: gitclean ls-ok markedclean marked-manclean doc-clean doc node bin/npm-cli.js prune --production --no-save - @bash scripts/release.sh + @${SHELL} scripts/release.sh sandwich: @[ $$(whoami) = "root" ] && (echo "ok"; echo "ham" > sandwich) || (echo "make it yourself" && exit 13) diff --git a/configure b/configure index b13c8d0d73e22..c7f00498bca22 100755 --- a/configure +++ b/configure @@ -1,33 +1,32 @@ -#!/bin/bash +#!/bin/sh # set configurations that will be "sticky" on this system, # surviving npm self-updates. -CONFIGS=() -i=0 - # get the location of this file. -unset CDPATH +CDPATH= CONFFILE=$(cd $(dirname "$0"); pwd -P)/npmrc +CONFIGS= +NL=" +" + while [ $# -gt 0 ]; do conf="$1" - case $conf in + case "$conf" in --help) echo "./configure --param=value ..." exit 0 ;; --*) - CONFIGS[$i]="${conf:2}" + CONFIGS="$CONFIGS${conf#--*}$NL" ;; *) - CONFIGS[$i]="$conf" + CONFIGS="$CONFIGS$conf$NL" ;; esac let i++ shift done -for c in "${CONFIGS[@]}"; do - echo "$c" >> "$CONFFILE" -done +printf %s "$CONFIGS" > "$CONFFILE" diff --git a/scripts/clean-old.sh b/scripts/clean-old.sh index cda80f2f4845d..6a77dac65240d 100755 --- a/scripts/clean-old.sh +++ b/scripts/clean-old.sh @@ -1,13 +1,10 @@ -#!/bin/bash +#!/bin/sh +NL=" +" # look for old 0.x cruft, and get rid of it. # Should already be sitting in the npm folder. -# This doesn't have to be quite as cross-platform as install.sh. -# There are some bash-isms, because maintaining *two* -# fully-portable posix/bourne sh scripts is too much for -# one project with a sane maintainer. - # If readlink isn't available, then this is just too tricky. # However, greadlink is fine, so Solaris can join the party, too. readlink="readlink" @@ -57,8 +54,7 @@ done packages=`echo $packages` -filelist=() -fid=0 +filelist= for prefix in $PREFIXES; do # remove any links into the .npm dir, or links to @@ -68,8 +64,7 @@ for prefix in $PREFIXES; do target=`$readlink $file | grep '/\.npm/'` if [ "x$target" != "x" ]; then # found one! - filelist[$fid]="$file" - let 'fid++' + filelist="$filelist$file$NL" # also remove any symlinks to this file. base=`basename "$file"` base=`echo "$base" | awk -F@ '{print $1}'` @@ -78,8 +73,7 @@ for prefix in $PREFIXES; do | while read l; do target=`$readlink "$l" | grep "$base"` if [ "x$target" != "x" ]; then - filelist[$fid]="$1" - let 'fid++' + filelist="$filelist$file$NL" fi done fi @@ -91,33 +85,29 @@ for prefix in $PREFIXES; do find $prefix/$folder -type f \ | xargs grep -sl '// generated by npm' \ | while read file; do - filelist[$fid]="$file" - let 'fid++' + filelist="$filelist$file$NL" done done # now remove the package modules, and the .npm folder itself. if [ "x$packages" != "x" ]; then for pkg in $packages; do - filelist[$fid]="$prefix/lib/node/$pkg" - let 'fid++' + filelist="$filelist$prefix/lib/node/$pkg$NL" for i in $prefix/lib/node/$pkg\@*; do - filelist[$fid]="$i" - let 'fid++' + filelist="$filelist$i$NL" done done fi for folder in lib/node/.npm lib/npm share/npm; do if [ -d $prefix/$folder ]; then - filelist[$fid]="$prefix/$folder" - let 'fid++' + filelist="$filelist$prefix/$folder/$NL" fi done done # now actually clean, but only if there's anything TO clean -if [ "${#filelist[@]}" -gt 0 ]; then +if [ "x$filelist" != "x" ]; then echo "" echo "This script will find and eliminate any shims, symbolic" echo "links, and other cruft that was installed by npm 0.x." @@ -139,13 +129,16 @@ if [ "${#filelist[@]}" -gt 0 ]; then OK="yes" fi + set -o noglob + IFS=" +" while [ "$OK" != "y" ] && [ "$OK" != "yes" ] && [ "$OK" != "no" ]; do echo "Is this OK?" echo " enter 'yes' or 'no'" echo " or 'show' to see a list of files " read OK if [ "x$OK" = "xshow" ] || [ "x$OK" = "xs" ]; then - for i in "${filelist[@]}"; do + for i in $filelist; do echo "$i" done fi @@ -154,7 +147,7 @@ if [ "${#filelist[@]}" -gt 0 ]; then echo "Aborting" exit 1 fi - for i in "${filelist[@]}"; do + for i in $filelist; do rm -rf "$i" done fi diff --git a/scripts/dep-update b/scripts/dep-update index 52abd518c317b..e0c0602b73906 100755 --- a/scripts/dep-update +++ b/scripts/dep-update @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh node . install --save $1@$2 &&\ node scripts/gen-dev-ignores.js &&\ git add node_modules package.json package-lock.json &&\ diff --git a/scripts/dev-dep-update b/scripts/dev-dep-update index c8c9604759165..b1b14f98836d4 100755 --- a/scripts/dev-dep-update +++ b/scripts/dev-dep-update @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh node . install --save --save-dev $1@$2 &&\ node scripts/gen-dev-ignores.js &&\ git add package.json package-lock.json &&\ diff --git a/scripts/doc-build.sh b/scripts/doc-build.sh index a37a5e2618fa8..458504339f3d3 100755 --- a/scripts/doc-build.sh +++ b/scripts/doc-build.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env bash +#!/bin/sh -if [[ $DEBUG != "" ]]; then +if [ -n "$DEBUG" ]; then set -x fi set -o errexit @@ -15,7 +15,7 @@ version=$(node bin/npm-cli.js -v) mkdir -p $(dirname $dest) html_replace_tokens () { - local url=$1 + url=$1 sed "s|@NAME@|$name|g" \ | sed "s|@DATE@|$date|g" \ | sed "s|@URL@|$url|g" \ @@ -29,7 +29,7 @@ html_replace_tokens () { | perl -p -e 's/([^"-])([^\(> ]+)(\(5\))/\1\2\3<\/a>/g' \ | perl -p -e 's/([^"-])([^\(> ]+)(\(7\))/\1\2\3<\/a>/g' \ | perl -p -e 's/\([1357]\)<\/a><\/h1>/<\/a><\/h1>/g' \ - | (if [ $(basename $(dirname $dest)) == "doc" ]; then + | (if [ $(basename $(dirname $dest)) = "doc" ]; then perl -p -e 's/ href="\.\.\// href="/g' else cat @@ -52,7 +52,7 @@ case $dest in exit $? ;; *.html) - url=${dest/html\//} + url=$(echo $dest | sed -e 's/html\///g') (cat html/dochead.html && \ cat $src | ./node_modules/.bin/marked && cat html/docfoot.html)\ diff --git a/scripts/install.sh b/scripts/install.sh index 4ed1062aa1308..0283bfdd12f9a 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -146,13 +146,6 @@ else make=NOMAKE fi -# If there's no bash, then don't even try to clean -if [ -x "/bin/bash" ]; then - (exit 0) -else - clean="no" -fi - node_version=`"$node" --version 2>&1` ret=$? if [ $ret -ne 0 ]; then diff --git a/scripts/release.sh b/scripts/release.sh index 705f21502adfb..8032ff71e4ece 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,8 +1,8 @@ -#!/bin/bash +#!/bin/sh # script for creating a zip and tarball for inclusion in node -unset CDPATH +CDPATH= set -e diff --git a/scripts/relocate.sh b/scripts/relocate.sh index b7483f2963aea..fb7cb21f74dd2 100755 --- a/scripts/relocate.sh +++ b/scripts/relocate.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Change the cli shebang to point at the specified node # Useful for when the program is moved around after install. @@ -6,7 +6,7 @@ # npm at the newly installed node, rather than the first one # in the PATH, which would be the default otherwise. -# bash /path/to/npm/scripts/relocate.sh $nodepath +# sh /path/to/npm/scripts/relocate.sh $nodepath # If $nodepath is blank, then it'll use /usr/bin/env dir="$(dirname "$(dirname "$0")")" From ffb462b4cc31859519b73330b9244c8a531190b0 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 9 Jul 2019 17:54:12 +0100 Subject: [PATCH 2/2] Use set -e rather than set -o errxit. Don't set -o pipefail as that's bash specific with no equivalent. --- scripts/doc-build.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/doc-build.sh b/scripts/doc-build.sh index 458504339f3d3..1fd74449c721b 100755 --- a/scripts/doc-build.sh +++ b/scripts/doc-build.sh @@ -3,8 +3,7 @@ if [ -n "$DEBUG" ]; then set -x fi -set -o errexit -set -o pipefail +set -e src=$1 dest=$2