-
Notifications
You must be signed in to change notification settings - Fork 28
/
addWebShortcutToDesktop.sh
executable file
·77 lines (64 loc) · 2.92 KB
/
addWebShortcutToDesktop.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
#!/bin/bash
#########################################################################################
# Author: Darren Wallace - Amsys
# Name: addWebShortcutToDesktop.sh
#
# Purpose: This script will add a Web Shortcut (weblock) file to the currently
# logged in user's desktop.
# The URL used can be specified on line 24, and the name of the file
# can be specified in line 22.
# The script will bail out if it detects 'root' or blank as the logged
# in user.
# Usage: CLI | Jamf Pro
#
# Version 2017.12.14 - DW - Initial Creation
#
#########################################################################################
##################################### Set variables #####################################
# Name you wish the shortcut (weblock) file to have
webLockFileName="Apple Support Pages"
# URL you want the shortcut to point to
webLockDestination="https://www.apple.com/support"
# Name of the script
scriptName="addWebShortcutToDesktop.sh"
# Location of the LogFile to save output to
logFile="/Library/Logs/${scriptName}"
# Work out the currently logged in user
loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
# Work out the final destination for the file
# This next line works out the user's home, even if working direct from a network volume (yuk)
eval usersNetworkHome="~${loggedInUser}"
finalLocation="${usersNetworkHome}/Desktop/${webLockFileName}.webloc"
################################## Declare functions ####################################
# Function to write input to the terminal and a logfile
writeLog ()
{
/bin/echo "$(date) - ${1}"
/bin/echo "$(date) - ${1}" >> "${logFile}"
}
##################################### Run Script #######################################
writeLog "Starting script: ${scriptName}"
# Check if the current user is 'root' or blank
if [[ "${loggedInUser}" == "root" ]]; then
# Current user detected as root so we will exit
writeLog "Current user detected as 'root', bailing out..."
exit 0
elif [[ "${loggedInUser}" == "" ]]; then
# Current user detected as blank so we will exit
writeLog "Current user detected as blank, bailing out..."
exit 0
fi
# Current user detected correctly, so off we go
writeLog "Saving shortcut to: ${finalLocation}"
# Create Web lock file
/bin/echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>URL</key>
<string>${webLockDestination}</string>
</dict>
</plist>" > "${finalLocation}"
# Permission the file correctly
/usr/sbin/chown "${loggedInUser}" "${finalLocation}"
##################################### End Script #######################################