-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeep_Freeze_cloudagent_install_settings.jss.zsh
More file actions
executable file
·161 lines (127 loc) · 4.28 KB
/
Deep_Freeze_cloudagent_install_settings.jss.zsh
File metadata and controls
executable file
·161 lines (127 loc) · 4.28 KB
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
#!/bin/zsh --no-rcs
# Jason Filice
# jfilice@csumb.edu
# Technology Support Services in IT
# California State University, Monterey Bay
# https://csumb.edu/it
# This script requires 3 arguments as Jamf Pro script parameters:
#
# Parameter 4: ServerUrl
# Parameter 5: FileID=
# Parameter 6: OrganizationID
# Parameter 7: plist file path
# examples:
# /Library/Preferences
# "/Library/Preferences/com.faronics.cloudagent.plist"
#
# # Jamf Waiting Room
# "/Library/Application Support/JAMF/Waiting Room/com.faronics.cloudagent.plist"
#
# Jamf Downloads
# "/Library/Application Support/JAMF/Downloads/com.faronics.cloudagent.plist"
#
# Use as script in Jamf JSS.
# Change History:
# 2025/05/29: Creation.
# 2025/08/06: Added improved error handling, directory creation, and logging
#
SCRIPTNAME=$(/usr/bin/basename "$0")
SCRIPTDIR=$(/usr/bin/dirname "$0")
# # Set up logging
# readonly LOGFILE="/var/log/jamf_deepfreeze_config.log"
# Logging function
log() {
local timestamp
timestamp=$(/bin/date '+%Y-%m-%d %H:%M:%S')
echo "${timestamp}: $1"
# echo "${timestamp}: $1" >> "${LOGFILE}"
}
# Error handling function
error_exit() {
log "ERROR: $1"
exit 1
}
# Jamf JSS Parameters 1 through 3 are predefined as mount point, computer name, and username
pathToScript=$0
mountPoint=$1
computerName=$2
userName=$3
shift 3
# Shift off the $1 $2 $3 parameters passed by the JSS so that parameter 4 is now $1
log "Script started"
log "pathToScript=$pathToScript"
log "mountPoint=$mountPoint"
log "computerName=$computerName"
log "userName=$userName"
# ##### Debugging flags #####
# debug bash script by enabling verbose “-v” option
# set -v
# debug bash script using noexec (Test for syntaxt errors)
# set -n
# identify the unset variables while debugging bash script
# set -u
# debug bash script using xtrace
# set -x
readonly ServerUrl="${1}"
readonly FileID="${2}"
readonly OrganizationID="${3}"
readonly configFile="${4}"
readonly DIR_PERMS=755
readonly FILE_PERMS=644
# Validate required parameters
if [[ -z "${ServerUrl}" ]]; then
error_exit "ServerUrl parameter is missing"
fi
if [[ -z "${FileID}" ]]; then
error_exit "FileID parameter is missing"
fi
if [[ -z "${OrganizationID}" ]]; then
error_exit "OrganizationID parameter is missing"
fi
if [[ -z "${configFile}" ]]; then
error_exit "Config file path parameter is missing"
fi
# Validate ServerUrl format (basic check for http/https)
if [[ ! "${ServerUrl}" =~ ^https?:// ]]; then
error_exit "Invalid ServerUrl format. Must start with http:// or https://"
fi
write_cloudagent_plist() {
local ServerUrl=${1}
local FileID=${2}
local OrganizationID=${3}
local configFile=${4}
# Create directory if it doesn't exist
local configDir
configDir=$(/usr/bin/dirname "${configFile}")
if [[ ! -d "${configDir}" ]]; then
log "Creating directory: ${configDir}"
/bin/mkdir -p "${configDir}" || error_exit "Failed to create directory ${configDir}"
/bin/chmod $DIR_PERMS "${configDir}" || error_exit "Failed to set directory permissions"
fi
# if file exists, Removes all default information
if [[ -e "${configFile}" ]]; then
log "Removing existing plist settings"
/usr/bin/defaults delete "${configFile}" || log "Warning: Failed to delete existing settings"
fi
log "Writing new plist settings"
# Write plist file
/usr/bin/defaults write "${configFile}" ServerUrl "${ServerUrl}" || error_exit "Failed to write ServerUrl"
/usr/bin/defaults write "${configFile}" FileID "${FileID}" || error_exit "Failed to write FileID"
/usr/bin/defaults write "${configFile}" OrganizationID "${OrganizationID}" || error_exit "Failed to write OrganizationID"
log "Setting file permissions"
/bin/chmod $FILE_PERMS "${configFile}" || error_exit "Failed to set file permissions"
# Check the property list files for syntax errors
log "Validating plist file"
ls -la "${configFile}"
if ! /usr/bin/plutil "${configFile}"; then
error_exit "Plist validation failed"
fi
# debugging: print plist file
# /usr/bin/plutil -p "${configFile}"
log "Successfully wrote and validated plist file"
return 0
}
# Execute main function
write_cloudagent_plist "${ServerUrl}" "${FileID}" "${OrganizationID}" "${configFile}"
log "Script completed successfully"
exit 0