-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack-fix.sh
105 lines (82 loc) · 2.59 KB
/
slack-fix.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
#!/bin/bash
# CHECKS IF DIALOG IS INSTALLED AND INSTALLS IF NOT
if [ ! -e "/usr/local/bin/dialog" ]; then
/usr/local/Installomator/Installomator.sh dialog BLOCKING_PROCESS_ACTION=quit_kill NOTIFY=silent
fi
apps=(
"Removing the broken version and permissions...,/tmp/slckremvd.log"
"Installing the patched version...,/tmp/slckinstalld.log"
"Ready to use!,/tmp/slckrdy.log"
)
# Dialog display settings, change as desired
title="PurplePatch: Fix Slack Script"
message="Fixing Broken Slack once and for all..."
# location of dialog and dialog command file
dialogApp="/usr/local/bin/dialog"
dialog_command_file="/var/tmp/dialog.log"
# check we are running as root
if [[ $(id -u) -ne 0 ]]; then
echo "This script should be run as root"
exit 1
fi
# *** functions
# execute a dialog command
function dialog_command(){
echo "$1"
echo "$1" >> $dialog_command_file
}
function finalise(){
dialog_command "progresstext: Patched Slack Successfully!"
dialog_command "progress: complete"
dialog_command "button1text: Done"
dialog_command "button1: enable"
exit 0
}
function appCheck(){
dialog_command "listitem: $(echo "$app" | cut -d ',' -f1): wait"
while [ ! -e "$(echo "$app" | cut -d ',' -f2)" ]
do
sleep 2
done
dialog_command "progresstext: \"$(echo $app | cut -d ',' -f1)\"."
dialog_command "listitem: $(echo "$app" | cut -d ',' -f1): ✅"
progress_index=$(( progress_index + 1 ))
echo "at item number $progress_index"
}
# *** end functions
# set progress total to the number of apps in the list
progress_total=${#apps[@]}
# 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="https://store.prpl.uk/slack.png"
else
icon="https://store.prpl.uk/slack.png"
fi
dialogCMD="$dialogApp -p --title \"$title\" \
--message $message \
--icon \"$icon\" \
--progress $progress_total \
--button1text \"Please Wait\" \
--button1disabled"
# create the list of apps
listitems=""
for app in "${apps[@]}"; do
listitems="$listitems --listitem '$(echo "$app" | cut -d ',' -f1)'"
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
progress_index=0
(for app in "${apps[@]}"; do
step_progress=$(( 1 + progress_index ))
dialog_command "progress: $step_progress"
appCheck &
done
wait)
# all done. close off processing and enable the "Done" button
finalise
rm -rf /tmp/slckremvd.log /tmp/slckinstalld.log /tmp/ztnetjoined.log