-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgem.sh
executable file
·76 lines (60 loc) · 2.04 KB
/
gem.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
#!/bin/bash
if [ -x "$(command -v gem)" ]; then # start check gem command
# variables for comparison
upd=`gem search rubygems-update | awk '{print $2}' | sed -e 's/[(|)]//g'`
cur=`gem -v`
echo "-Checking for rubygems update-"
if [[ "$cur" =~ "$upd" ]]; then # start version compare
echo "ruby gem does not need to be updated..."
printf '\n'
echo "Current version: $cur"
else
echo "ruby gems needs to be updated..."
printf '\n'
echo "Installed Version: $cur"
echo "Latest Version: $upd"
printf '\n'
sleep 2
# rubygems is out of date so ask if want to update it
read -p "-Do you want to update rubygems? (y/n)- " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then # start reply check
# old version broken see: https://rubygems.org/pages/download
if [[ "$cur" =~ "1.1"* ]] || [[ "$cur" =~ "1.2"* ]]; then # start old version check
printf '\n'
gem install rubygems-update
update_rubygems
# rehash the env once changes were made
rbenv rehash
else
printf '\n'
gem update --system
# rehash the env once changes were made
rbenv rehash
fi # end old version check
else
printf '\n'
echo "Skipping Gem Update"
fi # end reply check
fi # end version compare
printf '\n'
sleep 2
# now that RubyGems is updated, lets update actual gems
echo "-Displaying out of date ruby gems-"
outdated=`gem outdated | column -t`
if [ -z ${outdated+x} ]; then # start ruby gems outdated check
echo "$outdated"
printf '\n'
read -p "-Do you want to update those gems? (y/n)- " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then # start gem update reply check
printf '\n'
gem update
elif [[ ! $REPLY =~ ^[Yy]$ ]]; then # check any other input reply
printf '\n'
echo "Skipping update of the above gems..."
fi # end gem update reply check
else # outdated variable is blank so skip update
echo "Nothing to update..."
fi # end ruby gems outdated check
else
echo "-Ruby Gems is not installed, skipping updates-"
fi # end check gem command