-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.sh
65 lines (55 loc) · 2.01 KB
/
slack.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
#!/bin/sh
set -x # Enable debugging
# Script to check for, download, and install Slack.
dmgfile="slack.dmg"
volname="Slack"
logfile="$HOME/SlackInstallScript.log"
slack_path="/Applications/Slack.app"
url="https://downloads.slack-edge.com/releases/macos/4.34.119/prod/arm64/Slack-4.34.119-macOS.dmg" # Replace with your URL
# Check if Slack is already installed
if [ -d "${slack_path}" ]; then
/bin/echo "$(date): Slack is already installed." | tee -a "${logfile}"
exit 0
fi
# Download the Slack installer
/bin/echo "$(date): Downloading Slack." | tee -a "${logfile}"
/usr/bin/curl -fSL -o "/tmp/${dmgfile}" "${url}"
if [ $? -ne 0 ]; then
/bin/echo "$(date): Failed to download Slack." | tee -a "${logfile}"
exit 1
fi
# Verify the downloaded file is a valid disk image
if ! hdiutil verify "/tmp/${dmgfile}"; then
/bin/echo "$(date): Downloaded file is not a valid disk image." | tee -a "${logfile}"
exit 1
fi
# Mount the installer disk image
/bin/echo "$(date): Mounting installer disk image." | tee -a "${logfile}"
attach_output=$(hdiutil attach "/tmp/${dmgfile}" -nobrowse 2>&1)
if [ $? -ne 0 ]; then
/bin/echo "$(date): Failed to mount disk image." | tee -a "${logfile}"
/bin/echo "Error details: ${attach_output}" | tee -a "${logfile}"
exit 1
fi
# Install Slack
/bin/echo "$(date): Installing Slack." | tee -a "${logfile}"
sudo ditto -rsrc "/Volumes/${volname}/Slack.app" "${slack_path}"
if [ $? -ne 0 ]; then
/bin/echo "$(date): Failed to install Slack." | tee -a "${logfile}"
exit 1
fi
# Unmount the installer disk image
/bin/echo "$(date): Unmounting installer disk image." | tee -a "${logfile}"
hdiutil detach "/Volumes/${volname}" -quiet
if [ $? -ne 0 ]; then
/bin/echo "$(date): Failed to unmount disk image." | tee -a "${logfile}"
exit 1
fi
# Delete the installer disk image
/bin/echo "$(date): Deleting disk image." | tee -a "${logfile}"
/bin/rm "/tmp/${dmgfile}"
if [ $? -ne 0 ]; then
/bin/echo "$(date): Failed to delete disk image." | tee -a "${logfile}"
exit 1
fi
exit 0