-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSwift-Install.sh
235 lines (191 loc) · 6.62 KB
/
Swift-Install.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
#Swift-Install
#MIT License
#Copyright (c) 2022 roto31
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
LC_CTYPE=en_US.utf8
shopt -s extglob
# Swift-Install
# Based on swiftDialog and Installomater
# roto31
# Credits to Bart Reardon for developing and maintaining #swiftDialog
# and the developers and maintainers of the Installomater script
#Variables
dialogApp="/usr/local/bin/dialog"
title="Select Your Application"
message="The below applications are available to install for your computer. Please select from drop down below"
icon="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns"
selecttitle="Available Applications"
selectvalues="Firefox Pkg,Atom,Brave,Keka,Microsoft Edge,Opera,Google Chrome Pkg,Slack, Universal Type Client"
application=""
while [[ -z $application ]]; do
result=$("$dialogApp" \
--title "$title" \
--message "$message" \
--icon "$icon" \
--selecttitle "$selecttitle" \
--button1text Install \
--button2 Cancel \
--button2text Cancel \
--moveable \
--small \
--selectvalues "$selectvalues")
application=$(grep "$selecttitle :" <<< "$result" | awk -F " : " '{print $NF}')
done
# Install Function
echo "$result"
echo "application = $application"
labels=(
"${application// /}" # Remove all spaces.
)
# bash script that will take a list of installomator labels and run through each
# displays's a dialog with the list of applications and their progress
#
# Requires Dialog v1.9.1 or later https://github.com/bartreardon/Dialog/releases
#
# ©2022 Bart Reardon
# List of Installomator labels to process
#) $application
#)
# -------------------------------------
# *** script variables
# location of dialog and installomator scripts
dialogApp="/usr/local/bin/dialog"
dialog_command_file="/var/tmp/dialog.log"
installomator="/usr/local/Installomator/Installomator.sh"
# check we are running as root
if [[ $(id -u) -ne 0 ]]; then
echo "This script should be run as root"
exit 1
fi
# check Installomator exists and the specified path
if [[ ! -e $installomator ]]; then
echo "Installomator not found at path $installomator"
exit 1
fi
# *** functions
# take an installomator label and output the full app name
function label_to_name(){
#name=$(grep -A2 "${1})" "$installomator" | grep "name=" | head -1 | cut -d '"' -f2) # pre Installomator 9.0
name=$(${installomator} ${1} RETURN_LABEL_NAME=1 LOGGING=REQ | tail -1)
if [[ "$name" != "#" ]]; then
echo $name
else
echo $1
fi
}
# execute a dialog command
function dialog_command(){
echo $1
echo $1 >> $dialog_command_file
}
function finalise(){
dialog_command "progresstext: Install of Applications complete"
dialog_command "progress: complete"
dialog_command "button1text: Done"
dialog_command "button1: enable"
exit 0
}
# work out the number of increment steps based on the number of items
# and the average # of steps per item (rounded up to the nearest 10)
output_steps_per_app=30
number_of_apps=${#labels[@]}
progress_total=$(( $output_steps_per_app ))
# initial dialog starting arguments
title="Installing Applications"
message="Please wait while we download and install the following applications:"
# set icon based on whether computer is a desktop or laptop
hwType=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "Book")
if [ "$hwType" != "" ]; then
icon="SF=laptopcomputer.and.arrow.down,weight=thin,colour1=#51a3ef,colour2=#5154ef"
else
icon="SF=desktopcomputer.and.arrow.down,weight=thin,colour1=#51a3ef,colour2=#5154ef"
fi
dialogCMD="$dialogApp -p --title \"$title\" \
--message \"$message\" \
--icon \"$hwType\"
--overlayicon \"$icon\"
--small \
--moveable \
--progress $progress_total \
--button1text \"Please Wait\" \
--button1disabled"
# create the list of labels
listitems=""
for label in "${labels[@]}"; do
#echo "apps label is $label"
appname=$(label_to_name $label)
listitems="$listitems --listitem \"${appname}\" "
done
# final command to execute
dialogCMD="$dialogCMD $listitems"
echo $dialogCMD
# Launch dialog and run it in the background sleep for a second to let thing initialise
eval $dialogCMD &
sleep 2
# now start executing installomator labels
progress_index=0
for label in "${labels[@]}"; do
step_progress=$(( $output_steps_per_app * $progress_index ))
dialog_command "progress: $step_progress"
appname=$(label_to_name $label | tr -d "\"")
dialog_command "listitem: $appname: wait"
dialog_command "progresstext: Installing $label"
installomator_error=0
installomator_error_message=""
while IFS= read -r line; do
case $line in
*"DEBUG"*)
;;
*"BLOCKING_PROCESS_ACTION"*)
;;
*"NOTIFY"*)
;;
*"LOGO"*)
logofile=$(echo $line | awk -F "=" '{print $NF}')
dialog_command "icon: $logofile"
;;
*"ERROR"*)
installomator_error=1
installomator_error_message=$(echo $line | awk -F "ERROR: " '{print $NF}')
;;
*"##################"*)
;;
*)
# Installomator v8
#progress_text=$(echo $line | awk '{for(i=4;i<=NF;i++){printf "%s ", $i}; printf "\n"}')
# Installomator v9
progress_text=$(echo $line | awk -F " : " '{print $NF}')
if [[ ! -z $progress_text ]]; then
dialog_command "progresstext: $progress_text"
dialog_command "progress: increment"
fi
;;
esac
done < <($installomator $label)
if [[ $installomator_error -eq 1 ]]; then
dialog_command "progresstext: Install Failed for $appname"
dialog_command "listitem: $appname: $installomator_error_message ❌"
else
dialog_command "progresstext: Install of $appname complete"
dialog_command "listitem: $appname: ✅"
fi
progress_index=$(( $progress_index + 1 ))
echo "at item number $progress_index"
done
# all done. close off processing and enable the "Done" button
finalise