mirror of
https://github.com/zhigang1992/npm.git
synced 2026-06-15 02:09:12 +08:00
39 lines
731 B
Bash
39 lines
731 B
Bash
#!/bin/bash
|
|
TMP=$(mktemp -dt npm.XXXXXX)
|
|
if [ -n "$TMP" ]; then
|
|
TMP=$PWD/npm-install-please-remove-this
|
|
rm -rf -- $TMP || true
|
|
mkdir -- "$TMP"
|
|
if [ $? -ne 0 ]; then
|
|
echo "failed to mkdir $TMP" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
BACK="$PWD"
|
|
tar="${TAR}"
|
|
if [ -z "$tar" ]; then
|
|
if which gtar 1>/dev/null 2>/dev/null; then
|
|
tar=gtar
|
|
else
|
|
tar=tar
|
|
fi
|
|
fi
|
|
|
|
if which gegrep 1>/dev/null 2>/dev/null; then
|
|
egrep="gegrep"
|
|
else
|
|
egrep="egrep"
|
|
fi
|
|
|
|
cd -- "$TMP" \
|
|
&& curl -L $(
|
|
curl http://registry.npmjs.org/npm/latest \
|
|
| $egrep -o 'tarball":"[^"]+' \
|
|
| $egrep -o 'http://.*'
|
|
) | $tar -xzf - \
|
|
&& cd * \
|
|
&& make uninstall install \
|
|
&& cd -- "$BACK" \
|
|
&& rm -rf -- "$TMP" \
|
|
&& echo "It worked"
|