mirror of
https://github.com/tj/n.git
synced 2024-11-28 21:22:03 +01:00
Add option to specify a mirror repo.
This commit is contained in:
parent
328d7c0e1c
commit
58a9d64cac
19
bin/n
19
bin/n
@ -9,6 +9,7 @@ N_PREFIX=${N_PREFIX-/usr/local}
|
||||
VERSIONS_DIR=$N_PREFIX/n/versions
|
||||
UP=$'\033[A'
|
||||
DOWN=$'\033[B'
|
||||
MIRROR="http://nodejs.org/dist/"
|
||||
|
||||
test -d $VERSIONS_DIR || mkdir -p $VERSIONS_DIR
|
||||
|
||||
@ -238,7 +239,7 @@ tarball_url() {
|
||||
*armv6l*) arch=arm-pi ;;
|
||||
esac
|
||||
|
||||
echo "http://nodejs.org/dist/v${version}/node-v${version}-${os}-${arch}.tar.gz"
|
||||
echo "${MIRROR}v${version}/node-v${version}-${os}-${arch}.tar.gz"
|
||||
}
|
||||
|
||||
#
|
||||
@ -278,7 +279,7 @@ install_node() {
|
||||
|
||||
local dots=`echo $version | sed 's/[^.]*//g'`
|
||||
if test ${#dots} -eq 1; then
|
||||
version=`$GET 2> /dev/null http://nodejs.org/dist/ \
|
||||
version=`$GET 2> /dev/null $MIRROR \
|
||||
| egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| egrep -v '^0\.[0-7]\.' \
|
||||
| egrep -v '^0\.8\.[0-5]$' \
|
||||
@ -369,7 +370,7 @@ execute_with_version() {
|
||||
#
|
||||
|
||||
display_latest_version() {
|
||||
$GET 2> /dev/null http://nodejs.org/dist/ \
|
||||
$GET 2> /dev/null $MIRROR \
|
||||
| egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| sort -u -k 1,1n -k 2,2n -k 3,3n -t . \
|
||||
| tail -n1
|
||||
@ -380,7 +381,7 @@ display_latest_version() {
|
||||
#
|
||||
|
||||
display_latest_stable_version() {
|
||||
$GET 2> /dev/null http://nodejs.org/dist/ \
|
||||
$GET 2> /dev/null $MIRROR \
|
||||
| egrep -o '[0-9]+\.[0-9]*[02468]\.[0-9]+' \
|
||||
| sort -u -k 1,1n -k 2,2n -k 3,3n -t . \
|
||||
| tail -n1
|
||||
@ -391,9 +392,10 @@ display_latest_stable_version() {
|
||||
#
|
||||
|
||||
display_remote_versions() {
|
||||
echo "displaying remote versions"
|
||||
check_current_version
|
||||
local versions=""
|
||||
versions=`$GET 2> /dev/null http://nodejs.org/dist/ \
|
||||
versions=`$GET 2> /dev/null $MIRROR \
|
||||
| egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| egrep -v '^0\.[0-7]\.' \
|
||||
| egrep -v '^0\.8\.[0-5]$' \
|
||||
@ -415,6 +417,12 @@ display_remote_versions() {
|
||||
echo
|
||||
}
|
||||
|
||||
set_mirror() {
|
||||
test -z $1 && abort "mirror URL required"
|
||||
MIRROR=`echo $1 | egrep -i "http(s)?:\/\/([a-z0-9_\-]+\.)+[a-z]+([\/][a-z0-9_\-]*)+"`
|
||||
test -z "$MIRROR" && abort "invalid mirror URL $1"
|
||||
}
|
||||
|
||||
#
|
||||
# Handle arguments.
|
||||
#
|
||||
@ -427,6 +435,7 @@ else
|
||||
case $1 in
|
||||
-V|--version) display_n_version ;;
|
||||
-h|--help|help) display_help ;;
|
||||
-m|--mirror) shift; set_mirror $@ ;;
|
||||
--latest) display_latest_version; exit ;;
|
||||
--stable) display_latest_stable_version; exit ;;
|
||||
bin|which) display_bin_path_for_version $2; exit ;;
|
||||
|
Loading…
Reference in New Issue
Block a user