-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-ruby-gem-macos.zsh
More file actions
56 lines (53 loc) · 2.45 KB
/
update-ruby-gem-macos.zsh
File metadata and controls
56 lines (53 loc) · 2.45 KB
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
#!/bin/zsh --no-rcs
#
# Update Ruby Gem by Name
# This script will update the named Ruby Gem to the latest version.
# It will only work with the default macOS installed Ruby system (2.6.0 when written) and WILL NOT update any homebrew installed versions.
# If the default version of the gem being updated is older than the latest, it will remove the older default spec file and set the updated version as the default.
# This script was written for use with JAMF and looks for the Ruby Gem name to be provided as paramater 4. Adjust the script as needed for your use case.
#
testforgem=$(/usr/bin/gem list ${4} --installed)
if [[ $testforgem == "true" ]]; then
echo "Specified Gem [${4}] is already installed, updating it now..."
/usr/bin/gem update ${4}
else
echo "Specificed Gem [${4}] not installed, nothing to update now."
exit 0
fi
testforgemdefault=$(/usr/bin/gem list ${4}|grep "${4}")
testforgemdefault=${testforgemdefault#*\(}
testforgemdefault=${testforgemdefault%\)*}
#echo $testforgemdefault
installedGemVersion=$(echo $testforgemdefault| awk -F',' '{print $1}')
echo "Installed version: $installedGemVersion"
defaultGemVersion=${$(echo $testforgemdefault|cut -d':' -f2)// /}
echo "Default version: $defaultGemVersion"
installedGemVersionNum=${$(echo $testforgemdefault| awk -F',' '{print $1}')//[^0-9]/}
defaultGemVersionNum=${$(echo $testforgemdefault|cut -d':' -f2)//[^0-9]/}
if [[ -z $defaultGemVersionNum ]]; then
defaultGemVersionNum=0
fi
#echo $installedversionnum
#echo $defaultversionnum
echo "Removing older Gem references..."
specDeletion=$(ls /Library/Ruby/Gems/2.6.0/specifications/$4*)
specCount=$(wc -l <<< "$specDeletion")
while (( specCount >1 )); do
itemToDelete=$(echo "$specDeletion" | head -n1)
echo "Removing $itemToDelete..."
rm $itemToDelete
specDeletion=$(ls /Library/Ruby/Gems/2.6.0/specifications/$4*)
specCount=$(wc -l <<< "$specDeletion")
done
echo "Removing older Gem default references..."
/bin/cp "/Library/Ruby/Gems/2.6.0/specifications/$4-$installedGemVersion.gemspec" "/Library/Ruby/Gems/2.6.0/specifications/default/"
specDeletion=$(ls /Library/Ruby/Gems/2.6.0/specifications/default/$4*)
specCount=$(wc -l <<< "$specDeletion")
while (( specCount >1 )); do
itemToDelete=$(echo "$specDeletion" | head -n1)
echo "Removing $itemToDelete..."
rm $itemToDelete
specDeletion=$(ls /Library/Ruby/Gems/2.6.0/specifications/default/$4*)
specCount=$(wc -l <<< "$specDeletion")
done
echo "$(/usr/bin/gem list ${4})"