-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProTools25_Demo_Files_Post-Install.jss.zsh
More file actions
executable file
·217 lines (182 loc) · 6.5 KB
/
ProTools25_Demo_Files_Post-Install.jss.zsh
File metadata and controls
executable file
·217 lines (182 loc) · 6.5 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/zsh --no-rcs
# Jason Filice
# jfilice@csumb.edu
# Technology Support Services in IT
# California State University, Monterey Bay
# https://csumb.edu/it
#
# Purpose: moves and cleans up files installed in a current user directory by Pro Tools installer
# Version: 1.0
# Tested with: Avid Pro Tools v.25.6 installer
#
# Requirements:
# - Must be run as root
# - macOS 10.15 or newer recommended
#
# ##### 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
# Enable tracing without trace output
{ set -x; } 2>/dev/null
# Disable tracing without trace output
# { set +x; } 2>/dev/null
# Script constants
readonly SCRIPT_NAME=$(/usr/bin/basename "$0")
readonly SCRIPT_DIR=$(/usr/bin/dirname "$0")
readonly TIMESTAMP=$(/bin/date +"%Y-%m-%d %H:%M:%S")
readonly IOPlatformUUID=$(/usr/sbin/ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}')
# File Structure Constants
readonly DIR_PERMS=755
readonly FILE_PERMS=644
# Function to log messages with timestamp
log_message() {
local level=$1
shift
echo "${TIMESTAMP} [${level}] $*"
}
# Function to log errors
log_error() {
log_message "ERROR" "$*" >&2
}
# Function to log info
log_info() {
log_message "INFO" "$*"
}
# trap for cleanup
cleanup() {
log_info "Performing cleanup..."
# Add cleanup actions if needed
# Delete /Users/root/ directory and files
# Clean up after the Avid installers. We do not want a /Users/root left behind
# If USERID was some other user, then we will just leave it behind.
if [[ -d "/Users/root" ]]; then
log_info "Cleaning up /Users/root directory..."
/bin/rm -fRx "/Users/root"
fi
}
trap 'cleanup' EXIT
# Function to check if script is running as root
check_root() {
if [[ $EUID -ne 0 ]]; then
log_error "This script must be run as root"
exit 1
fi
}
# Function to get macOS version
get_macos_version() {
local version
version=$(/usr/bin/sw_vers -productVersion)
echo "$version"
}
# Function to determine template location based on OS version
set_user_templ() {
local version=$1
local major minor
# Parse version string
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
if [[ $major -gt 10 ]] || [[ $major -eq 10 && $minor -ge 15 ]]; then
log_info "macOS version $version detected"
log_info "Setting User Template path: '/Library/User Template/Non_localized'"
USER_TEMPL='/Library/User Template/Non_localized'
else
log_info "macOS version $version detected"
log_info "Setting User Template path: '/System/Library/User Template/Non_localized'"
USER_TEMPL='/System/Library/User Template/Non_localized'
fi
}
# Function to create directory with proper permissions
create_directory() {
local dir="${1}"
if ! /bin/mkdir -pvm ${DIR_PERMS} "$dir"; then
log_error "Failed to create directory: $dir"
return 1
fi
}
# Function to copy files to the user template.
ditto_files() {
local SOURCEPATH="${1}"
local DESTINATIONPATH="${2}"
if [[ -e "${SOURCEPATH}" ]]; then
log_info "Copying ${SOURCEPATH} to ${DESTINATIONPATH}"
if ! /usr/bin/ditto --noacl --noqtn "${SOURCEPATH}" "${DESTINATIONPATH}"; then
log_error "Failed to copy ${SOURCEPATH}"
return 1
fi
else
log_info "Skipping source directory not found: ${SOURCEPATH}"
fi
}
# Main execution starts here
main() {
# Check if running as root
check_root
# Use similar method as the stupid Avid installer scripts to determine the userID (typically "root")
# Determine currently loggged in user because this is what the Avid installers use to create the user directory.
readonly loggedInUser=$(stat -f "%Su" /dev/console) 2>/dev/null
if [[ "${loggedInUser}" == "root" || "${loggedInUser}" == "" ]]; then
readonly USERID="root"
else
readonly USERID="${loggedInUser}"
fi
# Get and validate macOS version
local os_version
os_version=$(get_macos_version)
typeset -g USER_TEMPL
set_user_templ "$os_version"
log_info "User Template path: ${USER_TEMPL}"
# Not needed when we use ditto
# # Create directories
# log_info "Creating directories..."
# log_info "Creating directory: ${USER_TEMPL}/Documents/Pro Tools/Demo Sessions"
# create_directory "${USER_TEMPL}/Documents/Pro Tools/Demo Sessions" || exit 1
#
# log_info "Creating directory: ${USER_TEMPL}/Documents/Pro Tools/Demo Sketches"
# create_directory "${USER_TEMPL}/Documents/Pro Tools/Demo Sketches" || exit 1
# log_info "Creating directory: ${USER_TEMPL}/Library/Preferences/Avid"
# create_directory "${USER_TEMPL}/Library/Preferences/Avid" || exit 1
#
# ## Copy Pro Tools Installation files
# ## /Users/$USERID/Documents/Pro Tools/Demo Sessions/
if [[ -e "/Users/${USERID}/Documents/Pro Tools/Demo Sessions" ]]; then
log_info "Copying /Users/${USERID}/Documents/Pro Tools/Demo Sessions/ to ${USER_TEMPL}"
if ! /usr/bin/ditto --noacl --noqtn "/Users/${USERID}/Documents/Pro Tools/Demo Sessions" "${USER_TEMPL}/Documents/Pro Tools/Demo Sessions"; then
log_error "Failed to copy Demo Sessions"
return 1
fi
else
log_info "Skipping source directory not found: /Users/${USERID}/Documents/Pro Tools/Demo Sessions/"
fi
# ## /Users/$USERID/Documents/Pro Tools/Demo Sketches/
if [[ -e "/Users/${USERID}/Documents/Pro Tools/Demo Sketches" ]]; then
log_info "Copying /Users/${USERID}/Documents/Pro Tools/Demo Sketches/ to ${USER_TEMPL}"
if ! /usr/bin/ditto --noacl --noqtn "/Users/${USERID}/Documents/Pro Tools/Demo Sketches" "${USER_TEMPL}/Documents/Pro Tools/Demo Sketches"; then
log_error "Failed to copy Demo Sketches"
return 1
fi
else
log_info "Skipping source directory not found: /Users/${USERID}/Documents/Pro Tools/Demo Sketches/"
fi
# Set root ownership on target directories and files
log_info "Setting root ownership on ${USER_TEMPL}..."
if ! /usr/sbin/chown -fRP 0:0 "${USER_TEMPL}"
then
log_error "Failed to set ownership on: $USER_TEMPL"
return 1
fi
cleanup
}
log_info "Starting ${SCRIPT_NAME} script"
# Execute main function with error handling
if ! main; then
log_error "${SCRIPT_NAME} script failed to complete successfully"
exit 1
fi
log_info "${SCRIPT_NAME} script completed successfully"
exit 0