Skip to content

Commit

Permalink
deterministic function order
Browse files Browse the repository at this point in the history
  • Loading branch information
roperzh committed Oct 3, 2024
1 parent aa7ec28 commit 2f0ec90
Show file tree
Hide file tree
Showing 21 changed files with 400 additions and 372 deletions.
12 changes: 10 additions & 2 deletions server/mdm/maintainedapps/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,17 @@ func (s *scriptBuilder) String() string {
}

if len(s.functions) > 0 {
for _, fn := range s.functions {
// write functions, order them alphabetically to produce deterministic
// scripts.
script.WriteString("# functions\n")
keys := make([]string, 0, len(s.functions))
for name := range s.functions {
keys = append(keys, name)
}
sort.Strings(keys)
for _, name := range keys {
script.WriteString("\n")
script.WriteString(fn)
script.WriteString(s.functions[name])
script.WriteString("\n")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# variables
APPDIR="/Applications/"
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions

trash() {
local logged_in_user="$1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

# variables
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


remove_launchctl_service() {
local service="$1"
Expand Down Expand Up @@ -48,44 +87,6 @@ remove_launchctl_service() {
done
}

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


trash() {
local logged_in_user="$1"
local target_file="$2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

# variables
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


remove_launchctl_service() {
local service="$1"
Expand Down Expand Up @@ -48,44 +87,6 @@ remove_launchctl_service() {
done
}

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


trash() {
local logged_in_user="$1"
local target_file="$2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# variables
APPDIR="/Applications/"
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions

trash() {
local logged_in_user="$1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

# variables
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


remove_launchctl_service() {
local service="$1"
Expand Down Expand Up @@ -48,44 +87,6 @@ remove_launchctl_service() {
done
}

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


trash() {
local logged_in_user="$1"
local target_file="$2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,45 @@
# variables
APPDIR="/Applications/"
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


remove_launchctl_service() {
local service="$1"
Expand Down Expand Up @@ -49,44 +88,6 @@ remove_launchctl_service() {
done
}

quit_application() {
local bundle_id="$1"
local timeout_duration=10

# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi

echo "Quitting application '$bundle_id'..."

# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done

if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}


trash() {
local logged_in_user="$1"
local target_file="$2"
Expand Down
Loading

0 comments on commit 2f0ec90

Please sign in to comment.