-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile-dev-update.sh
185 lines (152 loc) · 4.83 KB
/
mobile-dev-update.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# Created by Nicolae Ghimbovschi 2015
# https://github.com/xfreebird
function showActionMessage() { echo "⏳`tput setaf 12` $1 `tput op`"; }
function abort() { echo "!!! $@" >&2; exit 1; }
function disablePasswordlessSudo() {
sudo bash -c "cp /etc/sudoers.orig /etc/sudoers"
}
function enablePasswordlessSudo() {
USERNAME=$(whoami)
trap disablePasswordlessSudo SIGHUP SIGINT SIGTERM EXIT
sudo bash -c "cp /etc/sudoers /etc/sudoers.orig; echo '${USERNAME} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
#fix permissions
sudo chown -R "$(whoami)" /usr/local
}
function updateOSX() {
sudo softwareupdate -i -a -v
}
function ver() {
printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' ')
}
function updateXcodeBuildTools() {
# https://github.com/timsutton/osx-vm-templates/blob/master/scripts/xcode-cli-tools.sh
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
softwareupdate -i "$PROD" -v
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
}
function updateXcode() {
echo -n "Apple Account (e.g. [email protected]): "
read APPLE_USERNAME
echo -n "Apple Account Password: "
read -s APPLE_PASSWORD
echo
[[ "$APPLE_USERNAME" == "" ]] && abort "Set APPLE_USERNAME env variable with the email of an Apple Developer Account."
[[ "$APPLE_PASSWORD" == "" ]] && abort "Set APPLE_PASSWORD env variable with the passowrd of an Apple Developer Account."
export XCODE_INSTALL_USER="$APPLE_USERNAME"
export XCODE_INSTALL_PASSWORD="$APPLE_PASSWORD"
xcode_version_installed=""
#get the latest xcode version (non beta)
for xcode_version in $(xcversion installed | grep -v beta | cut -f1)
do
xcode_version_installed=$xcode_version
done
xcversion update
xcode_version_install=""
#get the latest xcode version (non beta)
for xcode_version in $(xcversion list | grep -v beta)
do
xcode_version_install=$xcode_version
done
[ x"$xcode_version_install" == x"" ] && return
if [ $(ver $xcode_version_install) -gt $(ver "$xcode_version_installed") ]; then
xcversion install "$xcode_version_install"
sudo xcodebuild -license accept
updateXcodeBuildTools
fi
}
function updatePHPPackages() {
sudo easy_install jira
}
function updateAndroidSDK() {
packages=""
for package in $(android list sdk --no-ui | \
grep -v -e "Obsolete" -e "Sources" -e "x86" -e "Samples" \
-e "Documentation" -e "MIPS" -e "Android TV" \
-e "Glass" -e "XML" -e "URL" -e "Packages available" \
-e "Fetch" -e "Web Driver" -e "GPU Debugging" -e "Android Auto" | \
cut -d'-' -f1)
do
packages=$(printf "${packages},${package}")
done
if [[ $packages != "" ]]; then
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk --no-ui --filter "$packages"
fi
packages=""
for package in $(android list sdk --no-ui -a | grep -v "Obsolete" | grep -e "Build-tools" -e "Platform-tools" | \
cut -d'-' -f1)
do
packages=$(printf "${packages},${package}")
done
if [[ $packages != "" ]]; then
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk -a --no-ui --filter "$packages"
fi
}
function updateBrewPackages() {
current_android_sdk_version=$(brew list --versions | grep android-sdk | rev | cut -d' ' -f 1 | rev)
brew update
brew upgrade
new_android_sdk_version=$(brew list --versions | grep android-sdk | rev | cut -d' ' -f 1 | rev)
if [ x"$current_android_sdk_version" != x"$new_android_sdk_version" ]
then
updateAndroidSDK
fi
}
function updateCasks() {
brew update
brew upgrade brew-cask
brew cask update
for file in $(brew cask list) ; do brew cask install $file --force; done
for java_home in $(/usr/libexec/java_home -V 2>&1 | uniq | grep -v Matching | grep "Java SE" | cut -f3 | sort)
do
( sleep 1 && while [ 1 ]; do sleep 1; echo y; done ) | jenv add "$java_home"
done
}
function updateRubyPackages() {
gem cleanup
gem update -p
# temporary fix for cocoapods
# https://github.com/CocoaPods/CocoaPods/issues/2908
gem uninstall psych --all
gem install psych -v 2.0.0
}
function updateNPMPackages() {
npm install npm@latest -g
npm update -g
}
function updateAll() {
enablePasswordlessSudo
updateXcode
updateOSX
updatePHPPackages
updateBrewPackages
updateAndroidSDK
updateRubyPackages
updateNPMPackages
}
case "$1" in
osx) enablePasswordlessSudo
updateOSX
;;
xcode) enablePasswordlessSudo
updateXcode
updateOSX
;;
php) enablePasswordlessSudo
updatePHPPackages
;;
android) updateAndroidSDK
;;
brew) updateBrewPackages
;;
cask) enablePasswordlessSudo
updateCasks
;;
gem) updateRubyPackages
;;
npm) updateNPMPackages
;;
*) updateAll
;;
esac