@@ -42,35 +42,61 @@ CURRENT_USER=$(whoami)
4242HOSTNAME_LOWER=" $( tr ' [:upper:]' ' [:lower:]' <<< " ${SERVER_NAME}" ) "
4343LOG_FILE=" ${HOME} /.local/state/${HOSTNAME_LOWER} -operator-login.log"
4444PROGRESS_LOG_FILE=" ${HOME} /.local/state/${HOSTNAME_LOWER} -operator-login-progress.log"
45+ PROGRESS_INDICATOR_PID=" "
4546
46- # Ensure log directory exists
47+ # Ensure log directories exist
4748mkdir -p " $( dirname " ${LOG_FILE} " ) "
49+ mkdir -p " $( dirname " ${PROGRESS_LOG_FILE} " ) "
50+
51+ # Logging function
52+ log () {
53+ local timestamp
54+ timestamp=$( date ' +%Y-%m-%d %H:%M:%S' )
55+ echo " [${timestamp} ] $* " | tee -a " ${LOG_FILE} "
56+ }
57+
58+ # Check ProgressIndicator availability
59+ if command -v ProgressIndicator > /dev/null 2>&1 ; then
60+ log " ProgressIndicator available - GUI progress will be shown"
61+ else
62+ log " ProgressIndicator not available - using log-only progress tracking"
63+ fi
64+
65+ # Start ProgressIndicator if available and not already running
66+ start_progress () {
67+ if command -v ProgressIndicator > /dev/null 2>&1 ; then
68+ if [[ -z " ${PROGRESS_INDICATOR_PID} " ]] || ! kill -0 " ${PROGRESS_INDICATOR_PID} " 2> /dev/null; then
69+ ProgressIndicator --watchfile=" ${PROGRESS_LOG_FILE} " &
70+ PROGRESS_INDICATOR_PID=$!
71+ if kill -0 " ${PROGRESS_INDICATOR_PID} " 2> /dev/null; then
72+ log " Started ProgressIndicator (PID: ${PROGRESS_INDICATOR_PID} )"
73+ else
74+ log " Warning: Failed to start ProgressIndicator GUI"
75+ PROGRESS_INDICATOR_PID=" "
76+ fi
77+ fi
78+ fi
79+ }
4880
4981# Progress Indicator function
5082# wraps log()
5183progress () {
52- if command -v ProgressIndicator; then
53- # tool is installed; else just skip to log()
54- local timestamp
55- timestamp=$( date ' +%Y-%m-%d %H:%M:%S' )
56- echo " [${timestamp} ] $* " | tee -a " ${PROGRESS_LOG_FILE} "
57- if ! pgrep -f ProgressIndicator; then
58- # tool is not already running; launch watching PROGRESS_LOG_FILE
59- ProgressIndicator --watchfile=" ${PROGRESS_LOG_FILE} "
60- fi
61- fi
84+ start_progress
85+ local timestamp
86+ timestamp=$( date ' +%Y-%m-%d %H:%M:%S' )
87+ echo " [${timestamp} ] $* " | tee -a " ${PROGRESS_LOG_FILE} "
6288 log " $* "
6389}
6490
6591stop_progress () {
66- pkill -f ProgressIndicator 2> /dev/null || true
67- }
68-
69- # Logging function
70- log () {
71- local timestamp
72- timestamp= $( date ' +%Y-%m-%d %H:%M:%S ' )
73- echo " [ ${timestamp} ] $* " | tee -a " ${LOG_FILE} "
92+ if [[ -n " ${PROGRESS_INDICATOR_PID} " ]] && kill -0 " ${PROGRESS_INDICATOR_PID} " 2> /dev/null; then
93+ kill " ${PROGRESS_INDICATOR_PID} " 2> /dev/null || true
94+ wait " ${PROGRESS_INDICATOR_PID} " 2> /dev/null || true
95+ PROGRESS_INDICATOR_PID= " "
96+ log " Stopped ProgressIndicator "
97+ fi
98+ # Fallback cleanup
99+ pkill -f " ProgressIndicator.* ${PROGRESS_LOG_FILE} " 2> /dev/null || true
74100}
75101
76102# Wait for network mount
@@ -264,15 +290,15 @@ setup_iterm2_preferences() {
264290 # Verify that import actually worked by checking for a key preference
265291 if defaults read com.googlecode.iterm2 " Default Bookmark Guid" > /dev/null 2>&1 ; then
266292 progress " ✅ Successfully imported and verified iTerm2 preferences"
267- log " Preferences will be active when iTerm2 is next launched"
293+ progress " Preferences will be active when iTerm2 is next launched"
268294 else
269295 progress " ⚠️ Import command succeeded but preferences verification failed"
270- log " iTerm2 preferences may not have been properly imported"
296+ progress " iTerm2 preferences may not have been properly imported"
271297 fi
272298 else
273299 progress " ❌ Failed to import iTerm2 preferences"
274- log " Check that preferences file is valid: ${preferences_file} "
275- log " You can manually import by opening iTerm2 > Preferences > Profiles > Other Actions > Import JSON Profiles"
300+ progress " Check that preferences file is valid: ${preferences_file} "
301+ progress " You can manually import by opening iTerm2 > Preferences > Profiles > Other Actions > Import JSON Profiles"
276302 fi
277303}
278304
@@ -296,7 +322,7 @@ unload_launchagent() {
296322 operator_config_dir=" $( dirname " ${CONFIG_FILE} " ) "
297323 if mv " ${launch_agents_dir} /${launch_agent} " " ${operator_config_dir} " ; then
298324 progress " Moved LaunchAgent to ${operator_config_dir} "
299- log " (Move back to ${launch_agents_dir} to re-run on next login)"
325+ progress " (Move back to ${launch_agents_dir} to re-run on next login)"
300326 else
301327 progress " Warning: Failed to rename LaunchAgent; it will probably reload on next login"
302328 fi
0 commit comments