-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProTools25_Plugins_001_Pre-Install.jss.zsh
More file actions
executable file
·252 lines (213 loc) · 7.63 KB
/
ProTools25_Plugins_001_Pre-Install.jss.zsh
File metadata and controls
executable file
·252 lines (213 loc) · 7.63 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/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 target directories prior to installing Avid Pro Tools v.25.6 plugins
# Version: 1.0
# Tested with: Avid Pro Tools v.25.6 plugins installers
#
# 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")
# 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() {
local exit_code=${1:-$?}
if [[ $exit_code -ne 0 ]]; then
log_error "Script failed with exit code: $exit_code"
fi
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 USERIDHOME was some other user, then we will just leave it behind.
if [[ -e "/Users/root" ]]; then
log_info "Cleaning up /Users/root directory..."
/bin/rm -fRx "/Users/root"
fi
if [[ -n ${loggedInUser} ]] && [[ -n ${IOPlatformUUID} ]] && [[ -e "/private/tmp/${loggedInUser}_${IOPlatformUUID}" ]]; then
log_info "Cleaning up /private/tmp/${loggedInUser}_${IOPlatformUUID} directory..."
/bin/rm -fRx "/private/tmp/${loggedInUser}_${IOPlatformUUID}"
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 get IOPlatformUUID
get_UUID() {
local UUID
UUID=$(/usr/sbin/ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}')
echo "$UUID"
}
# Function to create directory with proper permissions
create_directory() {
local dir=${1}
log_info "Creating directory: ${dir}"
if ! $(/bin/mkdir -pv -m ${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 SOURCEDIRNAME=$(/usr/bin/dirname "${SOURCEPATH}")
local SOURCEBASENAME=$(/usr/bin/basename "${SOURCEPATH}")
local DESTINATIONPATH=${2}
local DESTINATIONDIRECTORY=$(/usr/bin/dirname "${DESTINATIONPATH}")
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 path not found: ${SOURCEPATH}"
fi
}
# Function to move files back to their original path after copying or moving files to user template
move_files() {
local SOURCEPATH=${1}
local SOURCEDIRNAME=$(/usr/bin/dirname "${SOURCEPATH}")
local SOURCEBASENAME=$(/usr/bin/basename "${SOURCEPATH}")
local DESTINATIONPATH=${2}
local DESTINATIONDIRECTORY=$(/usr/bin/dirname "${DESTINATIONPATH}")
if [[ -e "${SOURCEPATH}" ]]
then
log_info "Moving ${SOURCEPATH} to ${DESTINATIONPATH}"
if ! /usr/bin/ditto --noacl --noqtn "${SOURCEPATH}" "${DESTINATIONPATH}"
then
log_error "Failed to move ${SOURCEPATH}"
return 1
fi
if ! /bin/rm -fRx "${SOURCEPATH}"
then
log_error "Failed to move ${SOURCEPATH}"
return 1
fi
else
log_info "Skipping source path not found: ${SOURCEPATH}"
fi
}
# Main execution starts here
main() {
readonly IOPlatformUUID=$(get_UUID)
# determine template location based on OS version
local version=$(get_macos_version)
local major minor
local USER_TEMPL
# 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'"
readonly 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'"
readonly USER_TEMPL="/System/Library/User Template/Non_localized"
fi
log_info "User Template path: ${USER_TEMPL}"
# Check if running as root
if ! check_root; then
return 1
fi
# 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.
# $homedir = $ENV{'HOME'}
# $userid = basename($homedir)
# return $userid;
readonly loggedInUser=$(stat -f "%Su" /dev/console 2>/dev/null)
if [[ "${loggedInUser}" == "root" || "${loggedInUser}" == "" ]]; then
readonly USERIDHOME_Avid="/Users/root"
readonly USERIDHOME_REAL="$(/usr/bin/dscl . -read /Users/root NFSHomeDirectory | awk '{print $NF}' 2>/dev/null)"
else
readonly USERIDHOME_Avid="/Users/${loggedInUser}"
readonly USERIDHOME_REAL="$(/usr/bin/dscl . -read /Users/${loggedInUser} NFSHomeDirectory | awk '{print $NF}' 2>/dev/null)"
fi
# remove any files already in /Users/root
cleanup
#
# ## Move files to temporary ${IOPlatformUUID} location
move_files "${USERIDHOME_REAL}/Music/K-Devices/Presets" "/private/tmp/${loggedInUser}_${IOPlatformUUID}/Music/K-Devices/Presets"
move_files "${USERIDHOME_Avid}/Library/Audio/Presets" "/private/tmp/${loggedInUser}_${IOPlatformUUID}/Library/Audio/Presets"
move_files "${USERIDHOME_Avid}/Documents/Pro Tools/Plug-In Settings" "/private/tmp/${loggedInUser}_${IOPlatformUUID}/Documents/Pro Tools/Plug-In Settings"
move_files "${USERIDHOME_Avid}/Documents/Pro Tools/Track Presets" "/private/tmp/${loggedInUser}_${IOPlatformUUID}/Documents/Pro Tools/Track Presets"
move_files "${USERIDHOME_Avid}/Library/Preferences/Avid/" "/private/tmp/${loggedInUser}_${IOPlatformUUID}/Library/Preferences/Avid/"
if [[ $(ls "${USERIDHOME_Avid}"/Library/Preferences/com.airmusictech.*.plist 2>/dev/null) ]]
then
for tmp_plist in "${USERIDHOME_Avid}"/Library/Preferences/com.airmusictech.*.plist
do
if [[ -f "$tmp_plist" ]]
then
move_files "$tmp_plist" "/private/tmp/${loggedInUser}_${IOPlatformUUID}/Library/Preferences/"
fi
done
fi
# hide temporary ${IOPlatformUUID} location
if [[ -e "/private/tmp/${loggedInUser}_${IOPlatformUUID}" ]]
then
/usr/bin/chflags -fxR hidden "/private/tmp/${loggedInUser}_${IOPlatformUUID}"
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