-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathruby-install
executable file
·84 lines (75 loc) · 2.29 KB
/
ruby-install
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
#!/bin/bash
while getopts fh OPT
do
case $OPT in
"f") FLAG_FORCE="TRUE" ;;
"h") FLAG_HELP="TRUE" ;;
* ) FLAG_HELP="TRUE" ;;
esac
done
shift `expr $OPTIND - 1`
TARGET_VERSION="$1"
LOCATION="$2"
if [ "x"$FLAG_HELP != "x" -o "x$LOCATION" = "x" ]; then
echo "[usage] ruby-install [-f] VERSION LOCATION"
echo " ex: ruby-install 2.6.0 ~/local/ruby-2.6"
exit 0
fi
cd $(dirname $0)
XBUILD_PATH=$(pwd)
mkdir -p var
oldcheck=$(find var -name "ruby-build.date" -mtime -1)
if [ ! -f ./var/ruby-build.date -o "x"$oldcheck = "x" ]; then
(
echo "cloning latest ruby-build."
set -e
cd var
[ -d ./ruby-build -o -d ruby-build-repo ] && rm -rf ruby-build-repo ruby-build ruby-build.date
git clone -q https://github.com/sstephenson/ruby-build.git ruby-build-repo
touch ruby-build.date
cd ruby-build-repo
PREFIX="$XBUILD_PATH"/var/ruby-build ./install.sh >/dev/null 2>&1
)
if [ $? -ne 0 ]; then
echo "failed to download ruby-build"
exit 1
fi
fi
rm -f ./var/.24hours
if [ "x"$FLAG_FORCE = "x" -a -d "$LOCATION" -a -x "$LOCATION/bin/ruby" ]; then
miss=""
current_ver=$("$LOCATION"/bin/ruby -v)
for p in $(echo "$TARGET_VERSION" | sed -e 's/\./\\\./g;s/-/ /g');
do
hit=$(echo "$current_ver" | grep "$p")
if [ "x$hit" = "x" ]; then
miss="1"$miss
fi
done
if [ "x$miss" = "x" ]; then
echo "ruby $TARGET_VERSION already installed on $LOCATION"
echo "To do force re-install, use '-f' option"
exit 0
fi
fi
echo "Start to build ruby $TARGET_VERSION ..."
./var/ruby-build/bin/ruby-build "$TARGET_VERSION" "$LOCATION" > /tmp/$USER-ruby-install.log 2>&1
if [ $? -ne 0 ]; then
echo "ruby-build failed. see log: /tmp/$USER-ruby-install.log"
exit 1
fi
(
export PATH="$LOCATION"/bin:"$PATH"
gems="pry"
if [ ! -x "$LOCATION"/bin/bundle ]; then
gems="bundler $gems"
fi
set -e
"$LOCATION"/bin/gem install --no-document $gems > /tmp/$USER-ruby-install-bundler.log 2>&1
)
if [ $? -ne 0 ]; then
echo "gem install failed. see log /tmp/$USER-ruby-install-bundler.log"
exit 2
fi
echo "ruby $TARGET_VERSION successfully installed on $LOCATION"
echo "To use this ruby, do 'export PATH=$LOCATION/bin:\$PATH'."