-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsuppressUpdateCheckForVisualStudio.sh
executable file
·73 lines (60 loc) · 2.81 KB
/
suppressUpdateCheckForVisualStudio.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
#!/bin/bash
#########################################################################################
# Author: Darren Wallace - Amsys
# Name: suppressUpdateCheckForVisualStudio.sh
#
# Purpose: This script will a configuration file for Visual Studio to the
# currently logged in user's Application Support folder.
# The script will bail out if it detects 'root' or blank as the logged
# in user.
# Source: https://code.visualstudio.com/docs/supporting/FAQ#_how-do-i-opt-out-of-vs-code-autoupdates
# Usage: CLI | Jamf Pro
#
# Version 2017.12.29 - DW - Initial Creation
#
#########################################################################################
##################################### Set variables #####################################
# Name of the script
scriptName="suppressUpdateCheckForVisualStudio.sh"
# Name of the file
fileName="settings.json"
# 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}"
# Path to the Directory
directoryPath="${usersNetworkHome}/Library/Application Support/Code/User"
# Final full path
finalLocation="${directoryPath}/${fileName}"
##################################### Run Script #######################################
/bin/echo "$(date) 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
/bin/echo "$(date) Current user detected as 'root', bailing out..."
exit 0
elif [[ "${loggedInUser}" == "" ]]; then
# Current user detected as blank so we will exit
/bin/echo "$(date) Current user detected as blank, bailing out..."
exit 0
fi
# Current user detected correctly, so off we go
/bin/echo "$(date) Saving file to: ${finalLocation}"
# Create the directory if required
if [[ -d "${directoryPath}" ]]; then
/bin/echo "$(date) Directory already present, skipping"
else
/bin/echo "$(date) Directory not found, creating..."
/bin/mkdir -p "${directoryPath}"
/usr/sbin/chown -R "${loggedInUser}" "${usersNetworkHome}/Library/Application Support/Code"
fi
# Create the final file
/bin/echo "$(date) Writing the file in place"
/bin/echo "{
"update.channel": "none"
}" > "${finalLocation}"
# Permission the file correctly
/usr/sbin/chown "${loggedInUser}" "${finalLocation}"
/bin/echo "$(date) Script complete"
##################################### End Script #######################################