Skip to content

Commit

Permalink
Merge pull request #15 from hazcod/feat/new
Browse files Browse the repository at this point in the history
feat(maclaunch): add periodic, logouthook, emond
  • Loading branch information
hazcod authored Apr 23, 2021
2 parents 3cd00ab + 82ae6c5 commit 3a68f1d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ It does **not** alter the contents in any way or moves the file, so it should wo

The name you provide can either be specific to that service or function as a filter to work on multiple services simultaneously.

It can also use the environment variable `ML_SYSTEM=no` to skip anything system-related item.

## Installation

Installation can be done straight from [my Homebrew tap](https://github.com/hazcod/homebrew-hazcod) via `brew install hazcod/homebrew-hazcod/maclaunch` or just copy `maclaunch.sh` to your filesystem.
Expand All @@ -54,6 +56,8 @@ To list all your services: `maclaunch list`

To list all enabled services: `maclaunch list enabled`

To list all enabled services, ignoring internal ones: `ML_SYSTEM=no maclaunch list enabled`

To list all disabled services: `maclaunch list disabled`

To list all your services including system services: `maclaunch list system`
Expand Down
92 changes: 87 additions & 5 deletions maclaunch.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

startup_dirs=(/Library/LaunchAgents /Library/LaunchDaemons ~/Library/LaunchAgents ~/Library/LaunchDaemons)
startup_dirs=(/Library/LaunchAgents /Library/LaunchDaemons ~/Library/LaunchAgents ~/Library/LaunchDaemons /etc/emond.d/rules/)
system_dirs=(/System/Library/LaunchAgents /System/Library/LaunchDaemons)

RED='\033[0;31m'
Expand All @@ -13,6 +13,10 @@ BOLD='\033[1m'
#--------------------------------------------------------------------------------------------------------------------------------------
#

function isSystemItemsDisabled() {
[[ "${ML_SYSTEM}" == "no" ]]
}

function join_by { local IFS="$1"; shift; echo "$*"; }

function usage {
Expand Down Expand Up @@ -76,9 +80,69 @@ function listCronJobs {
done
}

function listPeriodic() {
local filter="$1"

if isSystemItemsDisabled; then
return
fi

find /etc/periodic -type f | while IFS= read -r name; do
mode="daily"

if [[ ${name} =~ /etc/periodic/weekly ]]; then
mode="weekly"
elif [[ ${name} =~ /etc/periodic/monthly ]]; then
mode="monthly"
fi

if [ -n "$filter" ] && ! [[ "$name" =~ $filter ]]; then
continue
fi

echo -e "${BOLD}> ${name}${NC}"
echo -e " Type : periodic"
echo -e " User : $(whoami)"
echo -e " Launch: ${YELLOW}${mode}${NC}"
echo " File : ${name}"
done
}

function enablePeriodic() {
local filter="$1"

find /etc/periodic -type f | while IFS= read -r name; do

if [ -n "$filter" ] && ! [[ "$name" =~ $filter ]]; then
continue
fi

echo -e "${BOLD}${YELLOW}Warning: enable individual periodic scripts in /etc/defaults/periodic.conf${NC}"
return
done
}

function disablePeriodic() {
local filter="$1"

find /etc/periodic -type f | while IFS= read -r name; do

if [ -n "$filter" ] && ! [[ "$name" =~ $filter ]]; then
continue
fi

echo -e "${BOLD}${YELLOW}Warning: disable individual periodic scripts in /etc/defaults/periodic.conf${NC}"
return
done
}

function listKernelExtensions {
local filter="$1"

if isSystemItemsDisabled; then
return
fi

getKernelExtensions | while IFS= read -r kextLine; do

kextLoaded="$(echo "$kextLine" | cut -d ' ' -f 3)"
Expand Down Expand Up @@ -257,15 +321,26 @@ function listLaunchItems {

# add system dirs too if we supplied the system parameter
if [ "$filter" == "system" ]; then
itemDirectories=("${itemDirectories[@]}" "${system_dirs[@]}")
filter=""
if ! isSystemItemsDisabled; then
itemDirectories=("${itemDirectories[@]}" "${system_dirs[@]}")
filter=""
fi
fi

# login hooks
if loginhooks=$(defaults read com.apple.loginwindow LoginHook 2>/dev/null); then
if loginHooks=$(defaults read com.apple.loginwindow LoginHook 2>/dev/null); then
echo -e "${RED}${BOLD}Warning: you have Login Hooks!${NC}"
echo -e "${RED}Remove them (with sudo) from /var/root/Library/Preferences/com.apple.loginwindow"
echo -e "${loginhooks}${NC}"
echo -e "${loginHooks}${NC}"
echo
echo
fi

# logout hooks
if logoutHooks=$(defaults read com.apple.loginwindow LogoutHook 2>/dev/null); then
echo -e "${RED}${BOLD}Warning: you have Login Hooks!${NC}"
echo -e "${RED}Remove them (with sudo) from /var/root/Library/Preferences/com.apple.loginwindow"
echo -e "${logoutHooks}${NC}"
echo
echo
fi
Expand Down Expand Up @@ -315,6 +390,10 @@ function listLaunchItems {
fi

load_items=("${GREEN}${BOLD}disabled")

# check if enabled is set to false in the plist
elif echo "${content}" | tr -d '\n' | tr -d '\t' | tr -d ' ' | grep -q 'enabled</key><false'; then
load_items=("${GREEN}${BOLD}disabled")

# if it's not disabled, list the startup triggers
else
Expand Down Expand Up @@ -469,6 +548,7 @@ case "$1" in
listLaunchItems "$1" "$2"
listKernelExtensions "$2"
listSystemExtensions "$2"
listPeriodic "$2"
;;

"disable")
Expand All @@ -479,6 +559,7 @@ case "$1" in
disableLaunchItems "$2"
disableKernelExtensions "$2"
disableSystemExtensions "$2"
disablePeriodic "$2"
;;

"enable")
Expand All @@ -489,6 +570,7 @@ case "$1" in
enableLaunchItems "$2"
enableKernelExtensions "$2"
enableSystemExtensions "$2"
enablePeriodic "$2"
;;

*)
Expand Down

0 comments on commit 3a68f1d

Please sign in to comment.