-
Notifications
You must be signed in to change notification settings - Fork 5
/
fvm.sh
executable file
·139 lines (132 loc) · 3.7 KB
/
fvm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# feather Version Manager
# liberally based on:
# Node Version Manager
# Implemented as a bash function
# To use source this file from your bash profile
#
# Implemented by Tim Caswell <[email protected]>
# with much bash help from Matthew Ranney
# adapted for use with feather by Ryan Gahl ([email protected])
# Auto detect the FVM_DIR
if [ ! -d "$FVM_DIR" ]; then
export FVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}); pwd)
fi
# we'll make a hard dependency on wget wince curl had issues with github's auto tarballing urls
if [ ! `which wget` ]; then
echo 'Need wget to proceed.' >&2;
return 13
fi
# Expand a version using the version cache
fvm_version()
{
PATTERN=$1
VERSION=''
# If it looks like an explicit version, don't do anything funny
if [[ "$PATTERN" == v*.*.* ]]; then
VERSION="$PATTERN"
fi
if [[ "$PATTERN" == ./ ]]; then
VERSION="pwd"
fi
if [ ! "$VERSION" ]; then
echo "N/A"
return 13
elif [ -e "$FVM_DIR/$VERSION" ]; then
(cd $FVM_DIR; \ls -dG "$VERSION")
else
echo "$VERSION"
fi
}
fvm()
{
if [ $# -lt 1 ]; then
fvm help
return
fi
case $1 in
"help" )
echo
echo "Feather Version Manager"
echo
echo "Usage:"
echo " fvm help Show this message"
echo " fvm install <version> Download and install a <version>"
echo " fvm use <version> Modify PATH to use <version>. If <version> is omitted, display current version."
echo " fvm ls Display a list of installed versions."
echo
echo "Example:"
echo " fvm install v0.1.3 Install a specific version number"
echo
;;
"install" )
if [ $# -ne 2 ]; then
fvm help
return
fi
VERSION=`fvm_version $2`
if (
mkdir -p "$FVM_DIR/$VERSION" && \
mkdir -p "$FVM_DIR/src" && \
cd "$FVM_DIR/src" && \
mkdir -p "$VERSION" && \
cd "$VERSION" && \
wget --no-check-certificate "https://github.com/theVolary/feather/tarball/$VERSION" -O "$VERSION" && \
tar -xzf "$VERSION" && \
cd the* && \
cp -r * ../../../${VERSION}/ && \
cd ../../../${VERSION}/ && \
echo "installing global modules. cwd = "`pwd`
npm install -g `cat bin/global_modules.txt` # space separate modules in this file!
echo "installing npm modules (via package.json and npm-shrinkwrap.json)"
npm install
)
then
fvm use $VERSION
else
echo "fvm: install $VERSION failed!"
fi
;;
"use" )
if [ $# -ne 2 ]; then
if [[ "$FEATHER_HOME" != "" ]]; then
echo "Currently using feather "`expr //$FEATHER_HOME : '.*/\(.*\)'`
else
printf "\033[1;31mNo FEATHER_HOME variable found, or it is empty.\e[0m"
fvm help
fi
return
fi
VERSION=`fvm_version $2`
if [ "$VERSION" == pwd ]; then
featherpath=`pwd`
FEATHER_HOME=$featherpath
PATH="$featherpath/bin:$PATH"
VERSION=$featherpath
else
if [ ! -d $FVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet"
return;
fi
if [[ $PATH == *$FVM_DIR/*/bin* ]]; then
PATH=${PATH%$FVM_DIR/*/bin*}$FVM_DIR/$VERSION/bin${PATH#*$FVM_DIR/*/bin}
else
PATH="$FVM_DIR/$VERSION/bin:$PATH"
fi
FEATHER_HOME=$FVM_DIR/$VERSION
fi
export PATH
export FEATHER_HOME
hash -r
echo "Now using feather $VERSION"
;;
"ls" )
node $FVM_DIR/tags.js
;;
"version" )
fvm_version $2
;;
* )
fvm help
;;
esac
}