Merge remote-tracking branch 'origin/main' into integrate/rosetta
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
.PHONY: lint test build clean ci
|
.PHONY: lint test build clean ci
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
shellcheck unleash lib/*.sh 2>/dev/null || brew install shellcheck && shellcheck unleash lib/*.sh
|
python3 scripts/check-shell.py
|
||||||
bash -n unleash lib/*.sh
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
bats tests/*.bats
|
bats tests/*.bats
|
||||||
@@ -13,18 +12,6 @@ build:
|
|||||||
clean:
|
clean:
|
||||||
rm -f unleash-standalone.sh
|
rm -f unleash-standalone.sh
|
||||||
|
|
||||||
ci:
|
ci: lint test
|
||||||
@echo "=== ShellCheck ===" && \
|
@echo "=== Markdown ==="
|
||||||
for f in unleash lib/*.sh examples/*.sh; do \
|
npx markdownlint-cli '*.md' || true
|
||||||
[ -f "$$f" ] || continue; \
|
|
||||||
echo " $$f"; shellcheck -S warning "$$f" || fail=1; \
|
|
||||||
done && \
|
|
||||||
echo "=== Bash Syntax ===" && \
|
|
||||||
for f in unleash lib/*.sh examples/*.sh; do \
|
|
||||||
[ -f "$$f" ] || continue; \
|
|
||||||
bash -n "$$f" || fail=1; \
|
|
||||||
done && \
|
|
||||||
echo "=== Markdown ===" && \
|
|
||||||
npx markdownlint-cli '*.md' || true && \
|
|
||||||
echo "=== All checks done ===" && \
|
|
||||||
[ -z "$$fail" ] || exit 1
|
|
||||||
|
|||||||
@@ -475,6 +475,9 @@ MA copies user-level caches, preferences, and launch agents. Unleash handles thi
|
|||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
Run `make ci` with Bash, Python 3.9+, ShellCheck, and Bats (validated with Bats 1.12).
|
||||||
|
The test suite uses temporary volumes and inert macOS command fixtures; it does not validate behavior on real Mac hardware.
|
||||||
|
|
||||||
See CONTRIBUTING.md. PRs welcome, especially for:
|
See CONTRIBUTING.md. PRs welcome, especially for:
|
||||||
|
|
||||||
- New macOS version compatibility
|
- New macOS version compatibility
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ cat > "$OUT" << HEADER
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
VERSION="$VERSION"
|
VERSION="$VERSION"
|
||||||
|
SCRIPT_DIR="\$(cd "\$(dirname "\$0")" && pwd)"
|
||||||
|
SCRIPT_PATH="\$SCRIPT_DIR/\$(basename "\$0")"
|
||||||
HEADER
|
HEADER
|
||||||
|
|
||||||
for lib in colors config detect validate dscl suppress backup status heal firewall harden whitelist check monitor history doctor selfupdate uninstall report ma_detect demo vpn; do
|
for lib in colors config detect validate dscl suppress backup status launchd heal firewall harden whitelist check monitor history doctor selfupdate uninstall report ma_detect demo vpn; do
|
||||||
tail -n +1 "$SCRIPT_DIR/lib/$lib.sh" >> "$OUT"
|
tail -n +1 "$SCRIPT_DIR/lib/$lib.sh" >> "$OUT"
|
||||||
echo "" >> "$OUT"
|
echo "" >> "$OUT"
|
||||||
done
|
done
|
||||||
|
|||||||
+6
-5
@@ -32,7 +32,7 @@ log() {
|
|||||||
|
|
||||||
local ts
|
local ts
|
||||||
ts=$(date '+%H:%M:%S')
|
ts=$(date '+%H:%M:%S')
|
||||||
echo -e "${color}[${label}]${NC} ${msg}"
|
echo -e "${color}[${label}]${NC} ${msg}" >&2
|
||||||
|
|
||||||
if [ -n "$LOG_FILE" ]; then
|
if [ -n "$LOG_FILE" ]; then
|
||||||
echo "[${ts}] [${label}] ${msg}" >> "$LOG_FILE" 2>/dev/null || true
|
echo "[${ts}] [${label}] ${msg}" >> "$LOG_FILE" 2>/dev/null || true
|
||||||
@@ -40,7 +40,7 @@ log() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_exit() {
|
error_exit() {
|
||||||
log "ERROR" "$1" >&2
|
log "ERROR" "$1"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,8 @@ header() {
|
|||||||
local title="$1"
|
local title="$1"
|
||||||
local len="${#title}"
|
local len="${#title}"
|
||||||
local line
|
local line
|
||||||
line=$(printf '%*s' "$((len + 4))" | tr ' ' '═')
|
line=$(printf '%*s' "$((len + 4))" '')
|
||||||
|
line="${line// /═}"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${CYAN}╔${line}╗${NC}"
|
echo -e "${CYAN}╔${line}╗${NC}"
|
||||||
echo -e "${CYAN}║ ${title} ║${NC}"
|
echo -e "${CYAN}║ ${title} ║${NC}"
|
||||||
@@ -107,7 +108,7 @@ prompt_default() {
|
|||||||
local prompt_text="$2"
|
local prompt_text="$2"
|
||||||
local default="$3"
|
local default="$3"
|
||||||
local value
|
local value
|
||||||
read -p "${CYAN}${prompt_text}${NC} (default '${default}'): " value
|
read -r -p "${CYAN}${prompt_text}${NC} (default '${default}'): " value
|
||||||
value="${value:=$default}"
|
value="${value:=$default}"
|
||||||
eval "$var_name=\"$value\""
|
eval "$var_name=\"$value\""
|
||||||
}
|
}
|
||||||
@@ -115,6 +116,6 @@ prompt_default() {
|
|||||||
confirm() {
|
confirm() {
|
||||||
local prompt="$1"
|
local prompt="$1"
|
||||||
local response
|
local response
|
||||||
read -p "${prompt} (y/N): " response
|
read -r -p "${prompt} (y/N): " response
|
||||||
[[ "$response" =~ ^[Yy]$ ]]
|
[[ "$response" =~ ^[Yy]$ ]]
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-14
@@ -2,10 +2,9 @@ CONFIG_FILE="$HOME/.unleash.conf"
|
|||||||
|
|
||||||
load_config() {
|
load_config() {
|
||||||
[ -f "$CONFIG_FILE" ] || return 0
|
[ -f "$CONFIG_FILE" ] || return 0
|
||||||
|
local key value
|
||||||
while IFS='=' read -r key value; do
|
while IFS='=' read -r key value || [ -n "$key" ]; do
|
||||||
key="${key// /}"
|
key="${key// /}"
|
||||||
value="${value// /}"
|
|
||||||
[ -z "$key" ] && continue
|
[ -z "$key" ] && continue
|
||||||
case "$key" in
|
case "$key" in
|
||||||
WEBHOOK) DISCORD_WEBHOOK="$value" ;;
|
WEBHOOK) DISCORD_WEBHOOK="$value" ;;
|
||||||
@@ -15,18 +14,29 @@ load_config() {
|
|||||||
done < "$CONFIG_FILE"
|
done < "$CONFIG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
save_config() {
|
_rewrite_config() {
|
||||||
local key="$1"
|
local key="$1"
|
||||||
local value="$2"
|
local value="$2"
|
||||||
local tmp
|
local tmp
|
||||||
|
|
||||||
[ -f "$CONFIG_FILE" ] || touch "$CONFIG_FILE"
|
[ -f "$CONFIG_FILE" ] || touch "$CONFIG_FILE"
|
||||||
|
tmp=$(mktemp "${CONFIG_FILE}.XXXXXX") || return 1
|
||||||
if grep -q "^${key}=" "$CONFIG_FILE" 2>/dev/null; then
|
if ! UNLEASH_CONFIG_KEY="$key" UNLEASH_CONFIG_VALUE="$value" \
|
||||||
sed -i '' "s/^${key}=.*/${key}=${value}/" "$CONFIG_FILE"
|
UNLEASH_CONFIG_OPERATION="${3:-set}" awk '
|
||||||
else
|
BEGIN { key=ENVIRON["UNLEASH_CONFIG_KEY"]; value=ENVIRON["UNLEASH_CONFIG_VALUE"];
|
||||||
echo "${key}=${value}" >> "$CONFIG_FILE"
|
operation=ENVIRON["UNLEASH_CONFIG_OPERATION"] }
|
||||||
|
index($0, key "=")==1 { if (!found++ && operation=="set") print key "=" value; next }
|
||||||
|
{ print }
|
||||||
|
END { if (!found && operation=="set") print key "=" value }
|
||||||
|
' "$CONFIG_FILE" > "$tmp"; then
|
||||||
|
rm -f "$tmp"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
mv "$tmp" "$CONFIG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
save_config() {
|
||||||
|
local key="$1" value="$2"
|
||||||
|
_rewrite_config "$key" "$value" || return 1
|
||||||
success "Saved $key to $CONFIG_FILE"
|
success "Saved $key to $CONFIG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,8 +53,8 @@ cmd_config() {
|
|||||||
cat "$CONFIG_FILE" | sed 's/^/ /'
|
cat "$CONFIG_FILE" | sed 's/^/ /'
|
||||||
;;
|
;;
|
||||||
set)
|
set)
|
||||||
local key="$3"
|
local key="${3:-}"
|
||||||
local value="$4"
|
local value="${4:-}"
|
||||||
[ -z "$key" ] || [ -z "$value" ] && {
|
[ -z "$key" ] || [ -z "$value" ] && {
|
||||||
info "Usage: ./unleash config set KEY VALUE"
|
info "Usage: ./unleash config set KEY VALUE"
|
||||||
info "Keys: WEBHOOK, LOG_LEVEL (verbose), LOG_FILE"
|
info "Keys: WEBHOOK, LOG_LEVEL (verbose), LOG_FILE"
|
||||||
@@ -53,10 +63,10 @@ cmd_config() {
|
|||||||
save_config "$key" "$value"
|
save_config "$key" "$value"
|
||||||
;;
|
;;
|
||||||
unset)
|
unset)
|
||||||
local key="$3"
|
local key="${3:-}"
|
||||||
[ -z "$key" ] && { info "Usage: ./unleash config unset KEY"; return 1; }
|
[ -z "$key" ] && { info "Usage: ./unleash config unset KEY"; return 1; }
|
||||||
if [ -f "$CONFIG_FILE" ]; then
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
sed -i '' "/^${key}=/d" "$CONFIG_FILE"
|
_rewrite_config "$key" "" unset || return 1
|
||||||
success "Removed $key from config"
|
success "Removed $key from config"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|||||||
+7
-6
@@ -31,8 +31,9 @@ resolve_data_volume() {
|
|||||||
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
||||||
warn "Auto-detection failed. Available disks:"
|
warn "Auto-detection failed. Available disks:"
|
||||||
diskutil list >&2
|
diskutil list >&2
|
||||||
echo ""
|
echo "" >&2
|
||||||
read -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
[ -t 0 ] || error_exit "Cannot select a Data volume without a terminal."
|
||||||
|
read -r -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
||||||
id="${id#/dev/}"
|
id="${id#/dev/}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -50,14 +51,14 @@ resolve_data_volume() {
|
|||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
info "Not mounted — mounting..."
|
info "Not mounted — mounting..."
|
||||||
diskutil mount "$data_dev" 2>/dev/null || true
|
diskutil mount "$data_dev" >&2 || true
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
warn "FileVault-locked — need to unlock."
|
warn "FileVault-locked — need to unlock."
|
||||||
echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2
|
echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2
|
||||||
diskutil apfs unlockVolume "$data_dev" 2>/dev/null \
|
diskutil apfs unlockVolume "$data_dev" >&2 \
|
||||||
|| error_exit "Failed to unlock. Re-run with valid credentials."
|
|| error_exit "Failed to unlock. Re-run with valid credentials."
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
@@ -87,9 +88,9 @@ detect_system_volume() {
|
|||||||
resolve_target_volumes() {
|
resolve_target_volumes() {
|
||||||
local base_name data_name
|
local base_name data_name
|
||||||
|
|
||||||
read -p "Enter target system volume name (default 'Macintosh HD'): " base_name
|
read -r -p "Enter target system volume name (default 'Macintosh HD'): " base_name
|
||||||
base_name="${base_name:=Macintosh HD}"
|
base_name="${base_name:=Macintosh HD}"
|
||||||
read -p "Enter target data volume name (default 'Macintosh HD - Data'): " data_name
|
read -r -p "Enter target data volume name (default 'Macintosh HD - Data'): " data_name
|
||||||
data_name="${data_name:=Macintosh HD - Data}"
|
data_name="${data_name:=Macintosh HD - Data}"
|
||||||
|
|
||||||
local sys_path="/Volumes/$base_name"
|
local sys_path="/Volumes/$base_name"
|
||||||
|
|||||||
+2
-2
@@ -9,10 +9,10 @@ cmd_discord_bot_install() {
|
|||||||
local token="${1:-}"
|
local token="${1:-}"
|
||||||
local channel_id="${2:-}"
|
local channel_id="${2:-}"
|
||||||
if [ -z "$token" ]; then
|
if [ -z "$token" ]; then
|
||||||
read -p "Discord Bot Token: " token
|
read -r -p "Discord Bot Token: " token
|
||||||
fi
|
fi
|
||||||
if [ -z "$channel_id" ]; then
|
if [ -z "$channel_id" ]; then
|
||||||
read -p "Discord Channel ID: " channel_id
|
read -r -p "Discord Channel ID: " channel_id
|
||||||
fi
|
fi
|
||||||
if [ -z "$token" ] || [ -z "$channel_id" ]; then
|
if [ -z "$token" ] || [ -z "$channel_id" ]; then
|
||||||
error_exit "Token and channel ID are required"
|
error_exit "Token and channel ID are required"
|
||||||
|
|||||||
+23
-13
@@ -7,7 +7,8 @@ pf_backup_anchor() {
|
|||||||
local root="$1"
|
local root="$1"
|
||||||
local anchor_file="${root}${FIREWALL_ANCHOR_DIR}/${FIREWALL_ANCHOR}"
|
local anchor_file="${root}${FIREWALL_ANCHOR_DIR}/${FIREWALL_ANCHOR}"
|
||||||
[ ! -f "$anchor_file" ] && return 0
|
[ ! -f "$anchor_file" ] && return 0
|
||||||
local backup="${anchor_file}.backup.$(date +%s)"
|
local backup
|
||||||
|
backup="${anchor_file}.backup.$(date +%s)"
|
||||||
cp "$anchor_file" "$backup" && info "Backed up pf anchor: $backup"
|
cp "$anchor_file" "$backup" && info "Backed up pf anchor: $backup"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,7 +16,8 @@ pf_backup_conf() {
|
|||||||
local root="$1"
|
local root="$1"
|
||||||
local pf_conf="${root}${FIREWALL_CONF}"
|
local pf_conf="${root}${FIREWALL_CONF}"
|
||||||
[ ! -f "$pf_conf" ] && return 0
|
[ ! -f "$pf_conf" ] && return 0
|
||||||
local backup="${pf_conf}.backup.$(date +%s)"
|
local backup
|
||||||
|
backup="${pf_conf}.backup.$(date +%s)"
|
||||||
cp "$pf_conf" "$backup" && info "Backed up pf.conf: $backup"
|
cp "$pf_conf" "$backup" && info "Backed up pf.conf: $backup"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,10 +53,7 @@ ANCHOR
|
|||||||
if grep -q "com.unleash" "$pf_conf" 2>/dev/null; then
|
if grep -q "com.unleash" "$pf_conf" 2>/dev/null; then
|
||||||
info "pf.conf already has Unleash anchor"
|
info "pf.conf already has Unleash anchor"
|
||||||
else
|
else
|
||||||
echo "" >> "$pf_conf"
|
printf '\n%s\n%s\n%s\n' "# Added by unleash — MDM block" "$anchor_line" "$load_line" >> "$pf_conf"
|
||||||
echo "# Added by unleash — MDM block" >> "$pf_conf"
|
|
||||||
echo "$anchor_line" >> "$pf_conf"
|
|
||||||
echo "$load_line" >> "$pf_conf"
|
|
||||||
success "pf.conf updated"
|
success "pf.conf updated"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -79,8 +78,11 @@ ANCHOR
|
|||||||
|
|
||||||
step "Loading pf rules..."
|
step "Loading pf rules..."
|
||||||
if command -v pfctl &>/dev/null; then
|
if command -v pfctl &>/dev/null; then
|
||||||
pfctl -e -f "$pf_conf" 2>/dev/null && success "pf enabled and rules loaded" \
|
if pfctl -e -f "$pf_conf" 2>/dev/null; then
|
||||||
|| warn "pfctl failed — try: sudo pfctl -e -f $pf_conf"
|
success "pf enabled and rules loaded"
|
||||||
|
else
|
||||||
|
warn "pfctl failed — try: sudo pfctl -e -f $pf_conf"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
warn "pfctl not available"
|
warn "pfctl not available"
|
||||||
fi
|
fi
|
||||||
@@ -105,8 +107,14 @@ remove_pf_mdm_block() {
|
|||||||
|
|
||||||
local pf_conf="${root}${FIREWALL_CONF}"
|
local pf_conf="${root}${FIREWALL_CONF}"
|
||||||
if [ -f "$pf_conf" ]; then
|
if [ -f "$pf_conf" ]; then
|
||||||
sed -i '' '/# Added by unleash/d' "$pf_conf" 2>/dev/null || true
|
local tmp_conf
|
||||||
sed -i '' '/com\.unleash/d' "$pf_conf" 2>/dev/null || true
|
tmp_conf=$(mktemp "${pf_conf}.XXXXXX") || return 1
|
||||||
|
if ! cp -p "$pf_conf" "$tmp_conf" \
|
||||||
|
|| ! sed '/# Added by unleash/d; /com\.unleash/d' "$pf_conf" > "$tmp_conf" \
|
||||||
|
|| ! mv "$tmp_conf" "$pf_conf"; then
|
||||||
|
rm -f "$tmp_conf"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
success "pf.conf cleaned"
|
success "pf.conf cleaned"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -124,9 +132,11 @@ pf_status() {
|
|||||||
if command -v pfctl &>/dev/null; then
|
if command -v pfctl &>/dev/null; then
|
||||||
pfctl -si 2>/dev/null | grep -E "Status|Enabled" || echo " pf not enabled"
|
pfctl -si 2>/dev/null | grep -E "Status|Enabled" || echo " pf not enabled"
|
||||||
echo ""
|
echo ""
|
||||||
pfctl -a "$FIREWALL_ANCHOR" -s rules 2>/dev/null \
|
if pfctl -a "$FIREWALL_ANCHOR" -s rules 2>/dev/null; then
|
||||||
&& info "Unleash MDM anchor rules:" \
|
info "Unleash MDM anchor rules:"
|
||||||
|| info "No Unleash MDM anchor loaded"
|
else
|
||||||
|
info "No Unleash MDM anchor loaded"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
warn "pfctl not available"
|
warn "pfctl not available"
|
||||||
fi
|
fi
|
||||||
|
|||||||
+18
-10
@@ -14,8 +14,11 @@ harden_live_os() {
|
|||||||
local installed
|
local installed
|
||||||
installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
if [ "$installed" -gt 0 ]; then
|
if [ "$installed" -gt 0 ]; then
|
||||||
sudo profiles -D -F 2>/dev/null && success "Forced profile removal" \
|
if sudo profiles -D -F 2>/dev/null; then
|
||||||
|| warn "Profile removal failed"
|
success "Forced profile removal"
|
||||||
|
else
|
||||||
|
warn "Profile removal failed"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
info "No installed profiles to remove"
|
info "No installed profiles to remove"
|
||||||
fi
|
fi
|
||||||
@@ -24,8 +27,8 @@ harden_live_os() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
step "Cleaning user LaunchAgents..."
|
step "Cleaning user LaunchAgents..."
|
||||||
local home
|
local home users_root="${1:-}/Users"
|
||||||
for home in /Users/*/; do
|
for home in "$users_root/"*/; do
|
||||||
[ -d "$home/Library/LaunchAgents" ] || continue
|
[ -d "$home/Library/LaunchAgents" ] || continue
|
||||||
local cleaned=0
|
local cleaned=0
|
||||||
for agent in "$home/Library/LaunchAgents/"*; do
|
for agent in "$home/Library/LaunchAgents/"*; do
|
||||||
@@ -35,8 +38,11 @@ harden_live_os() {
|
|||||||
cleaned=$((cleaned + 1))
|
cleaned=$((cleaned + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
[ "$cleaned" -gt 0 ] && success "$(basename "$home"): removed $cleaned agent(s)" \
|
if [ "$cleaned" -gt 0 ]; then
|
||||||
|| info "$(basename "$home"): clean"
|
success "$(basename "$home"): removed $cleaned agent(s)"
|
||||||
|
else
|
||||||
|
info "$(basename "$home"): clean"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
step "Flushing DNS cache..."
|
step "Flushing DNS cache..."
|
||||||
@@ -70,9 +76,11 @@ harden_live_os() {
|
|||||||
|
|
||||||
step "Disabling iCloud Private Relay (DoH source)..."
|
step "Disabling iCloud Private Relay (DoH source)..."
|
||||||
if command -v defaults &>/dev/null; then
|
if command -v defaults &>/dev/null; then
|
||||||
sudo defaults write /Library/Preferences/com.apple.networkextensions.plist PrivateRelayEnabled -bool false 2>/dev/null \
|
if sudo defaults write /Library/Preferences/com.apple.networkextensions.plist PrivateRelayEnabled -bool false 2>/dev/null; then
|
||||||
&& success "Private Relay disabled" \
|
success "Private Relay disabled"
|
||||||
|| info "Private Relay not configurable (expected on some configs)"
|
else
|
||||||
|
info "Private Relay not configurable (expected on some configs)"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@@ -96,5 +104,5 @@ harden_status() {
|
|||||||
launchctl list 2>/dev/null | grep -iE "mdm|managed|enrollment|activation" || info "None loaded"
|
launchctl list 2>/dev/null | grep -iE "mdm|managed|enrollment|activation" || info "None loaded"
|
||||||
|
|
||||||
step "Running MDM processes..."
|
step "Running MDM processes..."
|
||||||
ps aux 2>/dev/null | grep -iE "mdm|managedclient|activation" | grep -v grep || info "None running"
|
pgrep -il "mdm|managedclient|activation" 2>/dev/null || info "None running"
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-10
@@ -70,11 +70,7 @@ install_persist_launchdaemon() {
|
|||||||
root="$(_persist_mount_root "$data_mount")"
|
root="$(_persist_mount_root "$data_mount")"
|
||||||
|
|
||||||
local unleash_src
|
local unleash_src
|
||||||
if [ -n "$SCRIPT_DIR" ]; then
|
unleash_src=$(_launchd_script_path)
|
||||||
unleash_src="$SCRIPT_DIR/unleash"
|
|
||||||
else
|
|
||||||
unleash_src="$(cd "$(dirname "$0")" && pwd)/unleash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
step "Installing LaunchDaemon for boot-time persistence..."
|
step "Installing LaunchDaemon for boot-time persistence..."
|
||||||
|
|
||||||
@@ -93,8 +89,8 @@ install_persist_launchdaemon() {
|
|||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/bin/bash</string>
|
<string>/bin/bash</string>
|
||||||
<string>-c</string>
|
<string>${unleash_src}</string>
|
||||||
<string>${unleash_src} heal</string>
|
<string>heal</string>
|
||||||
</array>
|
</array>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
@@ -117,9 +113,11 @@ install_persist_launchdaemon() {
|
|||||||
|
|
||||||
step "Loading LaunchDaemon..."
|
step "Loading LaunchDaemon..."
|
||||||
if command -v launchctl &>/dev/null; then
|
if command -v launchctl &>/dev/null; then
|
||||||
launchctl load "$plist_path" 2>/dev/null \
|
if launchctl load "$plist_path" 2>/dev/null; then
|
||||||
&& success "LaunchDaemon loaded (will run on next boot)" \
|
success "LaunchDaemon loaded (will run on next boot)"
|
||||||
|| info "LaunchDaemon will load on next boot"
|
else
|
||||||
|
info "LaunchDaemon will load on next boot"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
info "launchctl not available (expected in Recovery) — will load on next boot"
|
info "launchctl not available (expected in Recovery) — will load on next boot"
|
||||||
fi
|
fi
|
||||||
|
|||||||
+4
-2
@@ -1,7 +1,8 @@
|
|||||||
show_history() {
|
show_history() {
|
||||||
header "Unleash Event History"
|
header "Unleash Event History"
|
||||||
|
|
||||||
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
local log_dir="${1:-/var/log}"
|
||||||
|
local logs=("$log_dir/unleash-monitor.log" "$log_dir/unleash-heal.log" "$log_dir/unleash-monitor.err")
|
||||||
local found=false
|
local found=false
|
||||||
|
|
||||||
for logfile in "${logs[@]}"; do
|
for logfile in "${logs[@]}"; do
|
||||||
@@ -34,7 +35,8 @@ show_history() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear_history() {
|
clear_history() {
|
||||||
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
local log_dir="${1:-/var/log}"
|
||||||
|
local logs=("$log_dir/unleash-monitor.log" "$log_dir/unleash-heal.log" "$log_dir/unleash-monitor.err")
|
||||||
for logfile in "${logs[@]}"; do
|
for logfile in "${logs[@]}"; do
|
||||||
if [ -f "$logfile" ]; then
|
if [ -f "$logfile" ]; then
|
||||||
: > "$logfile"
|
: > "$logfile"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
_launchd_script_path() {
|
||||||
|
local script_path="${SCRIPT_PATH:-}"
|
||||||
|
if [ -z "$script_path" ]; then
|
||||||
|
script_path="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
|
||||||
|
fi
|
||||||
|
printf '%s' "$script_path" | sed 's/&/\&/g; s/</\</g; s/>/\>/g'
|
||||||
|
}
|
||||||
+18
-11
@@ -1,3 +1,11 @@
|
|||||||
|
_has_matching_path() {
|
||||||
|
local path
|
||||||
|
for path in "$@"; do
|
||||||
|
[ ! -e "$path" ] || return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
detect_configurator_enrollment() {
|
detect_configurator_enrollment() {
|
||||||
local data_mount="${1:-}"
|
local data_mount="${1:-}"
|
||||||
|
|
||||||
@@ -80,8 +88,13 @@ detect_migration_assistant() {
|
|||||||
|
|
||||||
local user_agents="$home/Library/LaunchAgents"
|
local user_agents="$home/Library/LaunchAgents"
|
||||||
if [ -d "$user_agents" ]; then
|
if [ -d "$user_agents" ]; then
|
||||||
local found
|
local found=0 agent
|
||||||
found=$(ls "$user_agents" 2>/dev/null | grep -ciE "mdm|enrollment|managed" || true)
|
for agent in "$user_agents/"*; do
|
||||||
|
[ -f "$agent" ] || continue
|
||||||
|
if printf '%s\n' "${agent##*/}" | grep -qiE 'mdm|enrollment|managed'; then
|
||||||
|
found=$((found + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
if [ "$found" -gt 0 ]; then
|
if [ "$found" -gt 0 ]; then
|
||||||
ma_indicators=$((ma_indicators + found))
|
ma_indicators=$((ma_indicators + found))
|
||||||
details="$details $user: $found MDM LaunchAgent(s)\n"
|
details="$details $user: $found MDM LaunchAgent(s)\n"
|
||||||
@@ -90,9 +103,7 @@ detect_migration_assistant() {
|
|||||||
|
|
||||||
local prefs="$home/Library/Preferences"
|
local prefs="$home/Library/Preferences"
|
||||||
if [ -d "$prefs" ]; then
|
if [ -d "$prefs" ]; then
|
||||||
local mdm_prefs
|
if _has_matching_path "$prefs"/com.apple.mdm* "$prefs"/com.apple.ManagedClient*; then
|
||||||
mdm_prefs=$(ls "$prefs"/com.apple.mdm* "$prefs"/com.apple.ManagedClient* 2>/dev/null | head -3 || true)
|
|
||||||
if [ -n "$mdm_prefs" ]; then
|
|
||||||
ma_indicators=$((ma_indicators + 1))
|
ma_indicators=$((ma_indicators + 1))
|
||||||
details="$details $user: MDM preference files\n"
|
details="$details $user: MDM preference files\n"
|
||||||
fi
|
fi
|
||||||
@@ -106,16 +117,12 @@ detect_migration_assistant() {
|
|||||||
|
|
||||||
local caches="$home/Library/Caches"
|
local caches="$home/Library/Caches"
|
||||||
if [ -d "$caches" ]; then
|
if [ -d "$caches" ]; then
|
||||||
local enrollment_cache
|
if _has_matching_path "$caches"/com.apple.enrollment*; then
|
||||||
enrollment_cache=$(ls "$caches"/com.apple.enrollment* 2>/dev/null | head -3 || true)
|
|
||||||
if [ -n "$enrollment_cache" ]; then
|
|
||||||
ma_indicators=$((ma_indicators + 1))
|
ma_indicators=$((ma_indicators + 1))
|
||||||
details="$details $user: enrollment cache files\n"
|
details="$details $user: enrollment cache files\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local mdmd_cache
|
if _has_matching_path "$caches"/com.apple.mdm*; then
|
||||||
mdmd_cache=$(ls "$caches"/com.apple.mdm* 2>/dev/null | head -3 || true)
|
|
||||||
if [ -n "$mdmd_cache" ]; then
|
|
||||||
ma_indicators=$((ma_indicators + 1))
|
ma_indicators=$((ma_indicators + 1))
|
||||||
details="$details $user: MDM cache files\n"
|
details="$details $user: MDM cache files\n"
|
||||||
fi
|
fi
|
||||||
|
|||||||
+10
-12
@@ -4,11 +4,7 @@ install_monitor_launchdaemon() {
|
|||||||
[ -n "$data_mount" ] && root="$data_mount"
|
[ -n "$data_mount" ] && root="$data_mount"
|
||||||
|
|
||||||
local unleash_src
|
local unleash_src
|
||||||
if [ -n "$SCRIPT_DIR" ]; then
|
unleash_src=$(_launchd_script_path)
|
||||||
unleash_src="$SCRIPT_DIR/unleash"
|
|
||||||
else
|
|
||||||
unleash_src="$(cd "$(dirname "$0")" && pwd)/unleash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
step "Installing monitor LaunchDaemon..."
|
step "Installing monitor LaunchDaemon..."
|
||||||
|
|
||||||
@@ -26,8 +22,8 @@ install_monitor_launchdaemon() {
|
|||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/bin/bash</string>
|
<string>/bin/bash</string>
|
||||||
<string>-c</string>
|
<string>${unleash_src}</string>
|
||||||
<string>${unleash_src} monitor</string>
|
<string>monitor</string>
|
||||||
</array>
|
</array>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
@@ -47,9 +43,11 @@ PLIST
|
|||||||
success "Monitor LaunchDaemon: $plist_path"
|
success "Monitor LaunchDaemon: $plist_path"
|
||||||
|
|
||||||
if command -v launchctl &>/dev/null; then
|
if command -v launchctl &>/dev/null; then
|
||||||
launchctl load "$plist_path" 2>/dev/null \
|
if launchctl load "$plist_path" 2>/dev/null; then
|
||||||
&& success "Monitor loaded (starts at boot)" \
|
success "Monitor loaded (starts at boot)"
|
||||||
|| info "Will load on next boot"
|
else
|
||||||
|
info "Will load on next boot"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +168,7 @@ monitor_mdm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop_monitor() {
|
stop_monitor() {
|
||||||
local pidfile="/tmp/unleash-monitor.pid"
|
local pidfile="${1:-/tmp/unleash-monitor.pid}"
|
||||||
if [ -f "$pidfile" ]; then
|
if [ -f "$pidfile" ]; then
|
||||||
local pid
|
local pid
|
||||||
pid=$(cat "$pidfile")
|
pid=$(cat "$pidfile")
|
||||||
@@ -187,7 +185,7 @@ stop_monitor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
monitor_status() {
|
monitor_status() {
|
||||||
local pidfile="/tmp/unleash-monitor.pid"
|
local pidfile="${1:-/tmp/unleash-monitor.pid}"
|
||||||
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
||||||
echo -e "${GRN}Monitor running (PID $(cat "$pidfile"))${NC}"
|
echo -e "${GRN}Monitor running (PID $(cat "$pidfile"))${NC}"
|
||||||
tail -5 /var/log/unleash-monitor.log 2>/dev/null || echo " (no log entries yet)"
|
tail -5 /var/log/unleash-monitor.log 2>/dev/null || echo " (no log entries yet)"
|
||||||
|
|||||||
+3
-3
@@ -9,7 +9,7 @@ cmd_predict() {
|
|||||||
serial="${1:-}"
|
serial="${1:-}"
|
||||||
fi
|
fi
|
||||||
if [ -z "$serial" ]; then
|
if [ -z "$serial" ]; then
|
||||||
read -p "Enter serial number (or press Enter to skip): " serial
|
read -r -p "Enter serial number (or press Enter to skip): " serial
|
||||||
fi
|
fi
|
||||||
if [ -z "$serial" ]; then
|
if [ -z "$serial" ]; then
|
||||||
info "No serial provided. Run: ./unleash predict <serial>"
|
info "No serial provided. Run: ./unleash predict <serial>"
|
||||||
@@ -33,7 +33,8 @@ H4C:School District Managed
|
|||||||
VMW:VMware Workspace ONE
|
VMW:VMware Workspace ONE
|
||||||
M5K:Addigy Managed
|
M5K:Addigy Managed
|
||||||
W4P:Kandji Managed
|
W4P:Kandji Managed
|
||||||
ORGS)
|
ORGS
|
||||||
|
)
|
||||||
|
|
||||||
local match
|
local match
|
||||||
match=$(echo "$known_orgs" | grep "^$serial_prefix:" || true)
|
match=$(echo "$known_orgs" | grep "^$serial_prefix:" || true)
|
||||||
@@ -49,6 +50,5 @@ ORGS)
|
|||||||
info "The device may be from a smaller org or not organizationally enrolled."
|
info "The device may be from a smaller org or not organizationally enrolled."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local check_url="https://billing.c.apple.com/check?sn=${serial}"
|
|
||||||
info "For definitive ownership: https://checkcoverage.apple.com"
|
info "For definitive ownership: https://checkcoverage.apple.com"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
CMD_SUGGEST=""
|
|
||||||
|
|
||||||
known_orgs() {
|
known_orgs() {
|
||||||
cat << 'ORGS'
|
cat << 'ORGS'
|
||||||
|
|||||||
+11
-7
@@ -30,10 +30,11 @@ generate_report() {
|
|||||||
step "Installed Profiles"
|
step "Installed Profiles"
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
local count
|
local count
|
||||||
count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
count="${count:-0}"
|
||||||
if [ "$count" -gt 0 ]; then
|
if [ "$count" -gt 0 ]; then
|
||||||
echo " $count profile(s) installed"
|
echo " $count profile(s) installed"
|
||||||
sudo profiles -C -output=xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" \
|
sudo profiles -C -output stdout-xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" \
|
||||||
| sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
| sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
||||||
else
|
else
|
||||||
echo " No profiles installed"
|
echo " No profiles installed"
|
||||||
@@ -78,7 +79,8 @@ generate_report() {
|
|||||||
step "Hosts Block"
|
step "Hosts Block"
|
||||||
if grep -q "iprofiles.apple.com" /private/etc/hosts 2>/dev/null; then
|
if grep -q "iprofiles.apple.com" /private/etc/hosts 2>/dev/null; then
|
||||||
local blocked
|
local blocked
|
||||||
blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || echo 0)
|
blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || true)
|
||||||
|
blocked="${blocked:-0}"
|
||||||
echo " $blocked domain(s) blocked in /etc/hosts"
|
echo " $blocked domain(s) blocked in /etc/hosts"
|
||||||
else
|
else
|
||||||
echo " No block entries found"
|
echo " No block entries found"
|
||||||
@@ -87,9 +89,9 @@ generate_report() {
|
|||||||
|
|
||||||
step "Running MDM Processes"
|
step "Running MDM Processes"
|
||||||
local procs
|
local procs
|
||||||
procs=$(ps aux 2>/dev/null | grep -iE "mdm|managedclient|activation" | grep -v grep || true)
|
procs=$(pgrep -il "mdm|managedclient|activation" 2>/dev/null || true)
|
||||||
if [ -n "$procs" ]; then
|
if [ -n "$procs" ]; then
|
||||||
echo "$procs" | awk '{print " " $11 " (PID " $2 ")"}'
|
echo "$procs" | awk '{print " " $2 " (PID " $1 ")"}'
|
||||||
else
|
else
|
||||||
echo " None"
|
echo " None"
|
||||||
fi
|
fi
|
||||||
@@ -117,7 +119,8 @@ generate_report_json() {
|
|||||||
|
|
||||||
local profile_count=0
|
local profile_count=0
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
profile_count="${profile_count:-0}"
|
||||||
fi
|
fi
|
||||||
report="${report} \"installed_profiles\": $profile_count,\n"
|
report="${report} \"installed_profiles\": $profile_count,\n"
|
||||||
|
|
||||||
@@ -147,7 +150,8 @@ generate_report_json() {
|
|||||||
report="${report} },\n"
|
report="${report} },\n"
|
||||||
|
|
||||||
local hosts_blocked=0
|
local hosts_blocked=0
|
||||||
hosts_blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || echo 0)
|
hosts_blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || true)
|
||||||
|
hosts_blocked="${hosts_blocked:-0}"
|
||||||
report="${report} \"hosts_blocked\": $hosts_blocked\n"
|
report="${report} \"hosts_blocked\": $hosts_blocked\n"
|
||||||
|
|
||||||
report="${report}}"
|
report="${report}}"
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ do_self_update() {
|
|||||||
fi
|
fi
|
||||||
end_ok; echo " Latest: v$latest_tag"
|
end_ok; echo " Latest: v$latest_tag"
|
||||||
|
|
||||||
if [ "v$latest_tag" = "$(echo "v$VERSION")" ]; then
|
if [ "v$latest_tag" = "v$VERSION" ]; then
|
||||||
success "Already up to date (v$VERSION)"
|
success "Already up to date (v$VERSION)"
|
||||||
rm -rf "$tmp_dir"
|
rm -rf "$tmp_dir"
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
+30
-15
@@ -37,7 +37,8 @@ check_mdm_status() {
|
|||||||
else
|
else
|
||||||
echo -e " ${YEL}(none)${NC}"
|
echo -e " ${YEL}(none)${NC}"
|
||||||
fi
|
fi
|
||||||
local count; count=$(echo "$matches" | grep -c . 2>/dev/null || echo 0)
|
local count; count=$(echo "$matches" | grep -c . 2>/dev/null || true)
|
||||||
|
count="${count:-0}"
|
||||||
echo -e " ${CYAN}Total: $count of 13 expected domains blocked${NC}"
|
echo -e " ${CYAN}Total: $count of 13 expected domains blocked${NC}"
|
||||||
else
|
else
|
||||||
echo -e " ${YEL}(hosts not found)${NC}"
|
echo -e " ${YEL}(hosts not found)${NC}"
|
||||||
@@ -79,6 +80,16 @@ check_mdm_status() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_mdm_agent_names() {
|
||||||
|
local agent
|
||||||
|
for agent in "$1/"*; do
|
||||||
|
[ -f "$agent" ] || continue
|
||||||
|
if printf '%s\n' "${agent##*/}" | grep -qiE 'mdm|enrollment|managed'; then
|
||||||
|
printf '%s\n' "${agent##*/}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
deep_status() {
|
deep_status() {
|
||||||
if [ "${1:-}" = "--json" ]; then
|
if [ "${1:-}" = "--json" ]; then
|
||||||
deep_status_json
|
deep_status_json
|
||||||
@@ -89,10 +100,11 @@ deep_status() {
|
|||||||
step "Installed Configuration Profiles"
|
step "Installed Configuration Profiles"
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
local profile_count
|
local profile_count
|
||||||
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
profile_count="${profile_count:-0}"
|
||||||
if [ "$profile_count" -gt 0 ]; then
|
if [ "$profile_count" -gt 0 ]; then
|
||||||
warn "$profile_count profile(s) installed:"
|
warn "$profile_count profile(s) installed:"
|
||||||
sudo profiles -C -output=xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" | sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
sudo profiles -C -output stdout-xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" | sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
||||||
else
|
else
|
||||||
info "No configuration profiles installed"
|
info "No configuration profiles installed"
|
||||||
fi
|
fi
|
||||||
@@ -127,10 +139,10 @@ deep_status() {
|
|||||||
for home in /Users/*/; do
|
for home in /Users/*/; do
|
||||||
[ -d "$home/Library/LaunchAgents" ] || continue
|
[ -d "$home/Library/LaunchAgents" ] || continue
|
||||||
local user_agents
|
local user_agents
|
||||||
user_agents=$(ls "$home/Library/LaunchAgents/" 2>/dev/null | grep -iE "mdm|enrollment|managed" || true)
|
user_agents=$(_mdm_agent_names "$home/Library/LaunchAgents")
|
||||||
if [ -n "$user_agents" ]; then
|
if [ -n "$user_agents" ]; then
|
||||||
echo -e " ${YEL}$(basename "$home"):${NC}"
|
echo -e " ${YEL}$(basename "$home"):${NC}"
|
||||||
echo "$user_agents" | sed 's/^/ /'
|
while IFS= read -r agent; do printf ' %s\n' "$agent"; done <<< "$user_agents"
|
||||||
found=$((found + 1))
|
found=$((found + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -139,9 +151,9 @@ deep_status() {
|
|||||||
|
|
||||||
step "MDM LaunchDaemons (System)"
|
step "MDM LaunchDaemons (System)"
|
||||||
local sys_agents
|
local sys_agents
|
||||||
sys_agents=$(ls /Library/LaunchDaemons/ 2>/dev/null | grep -iE "mdm|enrollment|managed" || true)
|
sys_agents=$(_mdm_agent_names /Library/LaunchDaemons)
|
||||||
if [ -n "$sys_agents" ]; then
|
if [ -n "$sys_agents" ]; then
|
||||||
echo "$sys_agents" | sed 's/^/ /'
|
while IFS= read -r agent; do printf ' %s\n' "$agent"; done <<< "$sys_agents"
|
||||||
else
|
else
|
||||||
info "No MDM LaunchDaemons found"
|
info "No MDM LaunchDaemons found"
|
||||||
fi
|
fi
|
||||||
@@ -149,9 +161,9 @@ deep_status() {
|
|||||||
|
|
||||||
step "Running MDM Processes"
|
step "Running MDM Processes"
|
||||||
local procs
|
local procs
|
||||||
procs=$(ps aux 2>/dev/null | grep -iE "mdm|managedclient|activation" | grep -v grep || true)
|
procs=$(pgrep -il "mdm|managedclient|activation" 2>/dev/null || true)
|
||||||
if [ -n "$procs" ]; then
|
if [ -n "$procs" ]; then
|
||||||
echo "$procs" | awk '{print " " $11 " (PID " $2 ")"}'
|
echo "$procs" | awk '{print " " $2 " (PID " $1 ")"}'
|
||||||
else
|
else
|
||||||
info "No MDM processes running"
|
info "No MDM processes running"
|
||||||
fi
|
fi
|
||||||
@@ -173,8 +185,12 @@ deep_status() {
|
|||||||
|
|
||||||
step "Overall Assessment"
|
step "Overall Assessment"
|
||||||
local risk="LOW"
|
local risk="LOW"
|
||||||
[ "$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)" -gt 0 ] && risk="MEDIUM"
|
local cfg="/private/var/db/ConfigurationProfiles/Settings"
|
||||||
ps aux 2>/dev/null | grep -qiE "mdm|managedclient" && risk="HIGH"
|
local installed
|
||||||
|
installed=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
installed="${installed:-0}"
|
||||||
|
[ "$installed" -gt 0 ] && risk="MEDIUM"
|
||||||
|
pgrep -i "mdm|managedclient" >/dev/null 2>&1 && risk="HIGH"
|
||||||
[ -f "$cfg/.cloudConfigRecordFound" ] && risk="CRITICAL"
|
[ -f "$cfg/.cloudConfigRecordFound" ] && risk="CRITICAL"
|
||||||
|
|
||||||
case "$risk" in
|
case "$risk" in
|
||||||
@@ -193,7 +209,8 @@ deep_status_json() {
|
|||||||
|
|
||||||
local profile_count=0
|
local profile_count=0
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
profile_count="${profile_count:-0}"
|
||||||
fi
|
fi
|
||||||
json="${json} \"profile_count\": $profile_count,\n"
|
json="${json} \"profile_count\": $profile_count,\n"
|
||||||
|
|
||||||
@@ -211,9 +228,7 @@ deep_status_json() {
|
|||||||
json="${json} \"mdm_certificates\": $mdm_certs,\n"
|
json="${json} \"mdm_certificates\": $mdm_certs,\n"
|
||||||
|
|
||||||
local running_procs=0
|
local running_procs=0
|
||||||
running_procs=$(ps aux 2>/dev/null | grep -ciE "mdm|managedclient|activation" || true)
|
running_procs=$(pgrep -il "mdm|managedclient|activation" 2>/dev/null | awk 'END {print NR}' || true)
|
||||||
running_procs=$((running_procs - 1))
|
|
||||||
[ "$running_procs" -lt 0 ] && running_procs=0
|
|
||||||
json="${json} \"running_mdm_processes\": $running_procs,\n"
|
json="${json} \"running_mdm_processes\": $running_procs,\n"
|
||||||
|
|
||||||
local risk="LOW"
|
local risk="LOW"
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
PB=/usr/libexec/PlistBuddy
|
PB="${PB:-/usr/libexec/PlistBuddy}"
|
||||||
|
|
||||||
suppress_enrollment() {
|
suppress_enrollment() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
@@ -146,6 +146,7 @@ full_bypass_mode() {
|
|||||||
echo ""
|
echo ""
|
||||||
step "Creating temporary admin account"
|
step "Creating temporary admin account"
|
||||||
|
|
||||||
|
local realName
|
||||||
prompt_default realName "Full name" "Apple"
|
prompt_default realName "Full name" "Apple"
|
||||||
|
|
||||||
local username
|
local username
|
||||||
|
|||||||
+2
-2
@@ -20,7 +20,7 @@ prompt_username() {
|
|||||||
local var_name="$1"
|
local var_name="$1"
|
||||||
local value
|
local value
|
||||||
while true; do
|
while true; do
|
||||||
read -p "Username (default 'Apple'): " value
|
read -r -p "Username (default 'Apple'): " value
|
||||||
value="${value:=Apple}"
|
value="${value:=Apple}"
|
||||||
if msg=$(validate_username "$value"); then
|
if msg=$(validate_username "$value"); then
|
||||||
eval "$var_name=\"$value\""
|
eval "$var_name=\"$value\""
|
||||||
@@ -35,7 +35,7 @@ prompt_password() {
|
|||||||
local var_name="$1"
|
local var_name="$1"
|
||||||
local value
|
local value
|
||||||
while true; do
|
while true; do
|
||||||
read -p "Password (default '1234'): " value
|
read -r -p "Password (default '1234'): " value
|
||||||
value="${value:=1234}"
|
value="${value:=1234}"
|
||||||
if msg=$(validate_password "$value"); then
|
if msg=$(validate_password "$value"); then
|
||||||
eval "$var_name=\"$value\""
|
eval "$var_name=\"$value\""
|
||||||
|
|||||||
+6
-6
@@ -58,14 +58,14 @@ RULES
|
|||||||
if grep -q "vpn-kill" "$pf_conf" 2>/dev/null; then
|
if grep -q "vpn-kill" "$pf_conf" 2>/dev/null; then
|
||||||
info "pf.conf already has VPN kill-switch anchor"
|
info "pf.conf already has VPN kill-switch anchor"
|
||||||
else
|
else
|
||||||
echo "" >> "$pf_conf"
|
printf '\n%s\n%s\n%s\n' "# Added by unleash — VPN kill-switch (prevents MDM leaks)" "$anchor_line" "$load_line" >> "$pf_conf"
|
||||||
echo "# Added by unleash — VPN kill-switch (prevents MDM leaks)" >> "$pf_conf"
|
|
||||||
echo "$anchor_line" >> "$pf_conf"
|
|
||||||
echo "$load_line" >> "$pf_conf"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pfctl -e -f "$pf_conf" 2>/dev/null && success "VPN kill-switch active" \
|
if pfctl -e -f "$pf_conf" 2>/dev/null; then
|
||||||
|| warn "pfctl failed"
|
success "VPN kill-switch active"
|
||||||
|
else
|
||||||
|
warn "pfctl failed"
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
info "What this does:"
|
info "What this does:"
|
||||||
|
|||||||
+7
-7
@@ -11,7 +11,7 @@ install_selective_block() {
|
|||||||
local anchor_file="${anchor_dir}/com.unleash.selective"
|
local anchor_file="${anchor_dir}/com.unleash.selective"
|
||||||
mkdir -p "$anchor_dir"
|
mkdir -p "$anchor_dir"
|
||||||
|
|
||||||
> "$anchor_file"
|
: > "$anchor_file"
|
||||||
|
|
||||||
for d in $MDM_BLOCKLIST; do
|
for d in $MDM_BLOCKLIST; do
|
||||||
for ip in $(host -t a "$d" 2>/dev/null | awk '/has address/{print $NF}'); do
|
for ip in $(host -t a "$d" 2>/dev/null | awk '/has address/{print $NF}'); do
|
||||||
@@ -33,10 +33,7 @@ install_selective_block() {
|
|||||||
if grep -q "com.unleash.selective" "$pf_conf" 2>/dev/null; then
|
if grep -q "com.unleash.selective" "$pf_conf" 2>/dev/null; then
|
||||||
info "pf.conf already has selective anchor"
|
info "pf.conf already has selective anchor"
|
||||||
else
|
else
|
||||||
echo "" >> "$pf_conf"
|
printf '\n%s\n%s\n%s\n' "# Added by unleash — selective MDM block (iCloud-safe)" "$anchor_line" "$load_line" >> "$pf_conf"
|
||||||
echo "# Added by unleash — selective MDM block (iCloud-safe)" >> "$pf_conf"
|
|
||||||
echo "$anchor_line" >> "$pf_conf"
|
|
||||||
echo "$load_line" >> "$pf_conf"
|
|
||||||
success "pf.conf updated with selective rules"
|
success "pf.conf updated with selective rules"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -56,8 +53,11 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v pfctl &>/dev/null; then
|
if command -v pfctl &>/dev/null; then
|
||||||
pfctl -e -f "$pf_conf" 2>/dev/null && success "pf rules loaded (iCloud should work)" \
|
if pfctl -e -f "$pf_conf" 2>/dev/null; then
|
||||||
|| warn "pfctl failed"
|
success "pf rules loaded (iCloud should work)"
|
||||||
|
else
|
||||||
|
warn "pfctl failed"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Check modules in their shared Bash context without executing the application."""
|
||||||
|
import json
|
||||||
|
import pathlib
|
||||||
|
import re
|
||||||
|
import shlex
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
root = pathlib.Path(__file__).resolve().parents[1]
|
||||||
|
for tool in ("bash", "shellcheck"):
|
||||||
|
if not shutil.which(tool):
|
||||||
|
sys.exit(f"{tool} is required; install it before running make lint")
|
||||||
|
|
||||||
|
entrypoint = root / "unleash"
|
||||||
|
source = entrypoint.read_text()
|
||||||
|
loader = re.search(r"^for _lib in ([a-z_ ]+); do\n.*?^done$", source, re.M | re.S)
|
||||||
|
if not loader:
|
||||||
|
sys.exit("Cannot identify the module loader in unleash")
|
||||||
|
modules = [root / "lib" / (name + ".sh") for name in loader[1].split()]
|
||||||
|
if set(modules) != set((root / "lib").glob("*.sh")):
|
||||||
|
sys.exit("The module loader and library files do not match")
|
||||||
|
|
||||||
|
# Literal sources let ShellCheck follow shared globals and report module locations.
|
||||||
|
# Keep the loader's line count so dispatcher diagnostics retain their real lines.
|
||||||
|
literal_sources = "; ".join("source " + shlex.quote(str(path)) for path in modules)
|
||||||
|
context = source[:loader.start()] + literal_sources
|
||||||
|
context += "\n" * loader[0].count("\n") + source[loader.end():]
|
||||||
|
examples = sorted((root / "examples").glob("*.sh"))
|
||||||
|
failed = False
|
||||||
|
for path in [entrypoint, *modules, *examples, root / "unleash-standalone.sh"]:
|
||||||
|
result = subprocess.run(["bash", "-n", str(path)], check=False)
|
||||||
|
failed |= result.returncode != 0
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".sh") as temporary:
|
||||||
|
temporary.write(context)
|
||||||
|
temporary.flush()
|
||||||
|
result = subprocess.run([
|
||||||
|
"shellcheck", "--shell=bash", "--external-sources", "--check-sourced",
|
||||||
|
"--format=json", temporary.name, *map(str, examples), str(root / "unleash-standalone.sh"),
|
||||||
|
], capture_output=True, text=True, check=False)
|
||||||
|
if result.stderr:
|
||||||
|
print(result.stderr, file=sys.stderr, end="")
|
||||||
|
failed |= result.returncode != 0
|
||||||
|
findings = json.loads(result.stdout or "[]")
|
||||||
|
seen = set()
|
||||||
|
for finding in findings:
|
||||||
|
path = finding["file"]
|
||||||
|
if path == temporary.name:
|
||||||
|
path = str(entrypoint)
|
||||||
|
key = (path, finding["line"], finding["column"], finding["code"])
|
||||||
|
if key in seen:
|
||||||
|
continue
|
||||||
|
seen.add(key)
|
||||||
|
print(f"{path}:{finding['line']}:{finding['column']}: "
|
||||||
|
f"{finding['level']} SC{finding['code']}: {finding['message']}")
|
||||||
|
sys.exit(1 if failed else 0)
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Inert macOS command fixtures; mutable plist operations stay in the suite root."""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import pathlib
|
||||||
|
import plistlib
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
name = pathlib.Path(sys.argv[0]).name
|
||||||
|
args = sys.argv[1:]
|
||||||
|
root = pathlib.Path(os.environ["UNLEASH_TEST_ROOT"]).resolve()
|
||||||
|
with (root / "platform-calls.jsonl").open("a") as log:
|
||||||
|
log.write(json.dumps([name, *args]) + "\n")
|
||||||
|
|
||||||
|
def fixture_path(value):
|
||||||
|
path = pathlib.Path(value).resolve()
|
||||||
|
active_test = pathlib.Path(os.environ["BATS_TEST_TMPDIR"]).resolve()
|
||||||
|
if not (path.is_relative_to(root) or path.is_relative_to(active_test)):
|
||||||
|
sys.exit(f"Fixture refused path outside the suite: {path}")
|
||||||
|
return path
|
||||||
|
|
||||||
|
if name == "sudo":
|
||||||
|
if len(args) >= 2 and ((args[0] == "profiles" and args[1] in ("-C", "status"))
|
||||||
|
or (args[0] == "security" and args[1] == "find-identity")):
|
||||||
|
sys.exit(subprocess.call([str(pathlib.Path(sys.argv[0]).with_name(args[0])), *args[1:]]))
|
||||||
|
elif name == "profiles":
|
||||||
|
if args[:1] == ["-C"]:
|
||||||
|
sys.stdout.buffer.write(plistlib.dumps([]))
|
||||||
|
sys.exit(0)
|
||||||
|
if args[:1] == ["status"]:
|
||||||
|
print("MDM enrollment: No")
|
||||||
|
sys.exit(0)
|
||||||
|
elif name == "security" and args[:1] == ["find-identity"]:
|
||||||
|
sys.exit(0)
|
||||||
|
elif name == "plutil" and args[:4] == ["-convert", "xml1", "-o", "-"]:
|
||||||
|
sys.stdout.buffer.write(plistlib.dumps(plistlib.loads(fixture_path(args[-1]).read_bytes())))
|
||||||
|
sys.exit(0)
|
||||||
|
elif name == "PlistBuddy":
|
||||||
|
path = fixture_path(args[-1])
|
||||||
|
data = plistlib.loads(path.read_bytes())
|
||||||
|
command = shlex.split(args[1])
|
||||||
|
action = command[0]
|
||||||
|
key = command[1].lstrip(":") if len(command) > 1 else None
|
||||||
|
if action == "Print":
|
||||||
|
if key:
|
||||||
|
print(str(data[key]).lower())
|
||||||
|
else:
|
||||||
|
sys.stdout.buffer.write(plistlib.dumps(data))
|
||||||
|
sys.exit(0)
|
||||||
|
if action == "Add" and key in data:
|
||||||
|
sys.exit(1)
|
||||||
|
if action == "Set" and key not in data:
|
||||||
|
sys.exit(1)
|
||||||
|
if action in ("Add", "Set"):
|
||||||
|
data[key] = command[-1] == "true"
|
||||||
|
elif action == "Delete":
|
||||||
|
data.pop(key, None)
|
||||||
|
else:
|
||||||
|
sys.exit(97)
|
||||||
|
path.write_bytes(plistlib.dumps(data))
|
||||||
|
sys.exit(0)
|
||||||
|
elif name == "launchctl" and args[:1] in (["load"], ["unload"]):
|
||||||
|
fixture_path(args[-1])
|
||||||
|
sys.exit(0)
|
||||||
|
elif name == "host" and args[:2] == ["-t", "a"]:
|
||||||
|
print(f"{args[2]} has address 203.0.113.10")
|
||||||
|
sys.exit(0)
|
||||||
|
elif name == "dscl":
|
||||||
|
fixture_path(args[1])
|
||||||
|
sys.exit(1)
|
||||||
|
elif name in ("diskutil", "pgrep", "pkill", "curl", "pfctl", "host"):
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(f"Blocked platform operation in test: {name} {' '.join(args)}", file=sys.stderr)
|
||||||
|
sys.exit(97)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
setup_suite() {
|
||||||
|
local suite_dir
|
||||||
|
suite_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
export UNLEASH_TEST_ROOT="$BATS_SUITE_TMPDIR"
|
||||||
|
export TMPDIR="$UNLEASH_TEST_ROOT/tmp"
|
||||||
|
local mock_bin="$UNLEASH_TEST_ROOT/bin"
|
||||||
|
mkdir -p "$TMPDIR" "$mock_bin"
|
||||||
|
local tool
|
||||||
|
for tool in sudo diskutil profiles security launchctl pfctl pkill pgrep killall \
|
||||||
|
dscacheutil defaults curl host plutil PlistBuddy dscl fdesetup chflags \
|
||||||
|
osascript ioreg ifconfig systemextensionsctl networksetup; do
|
||||||
|
cp "$suite_dir/helpers/platform.py" "$mock_bin/$tool"
|
||||||
|
chmod +x "$mock_bin/$tool"
|
||||||
|
done
|
||||||
|
export PATH="$mock_bin:$PATH"
|
||||||
|
export PB="$mock_bin/PlistBuddy"
|
||||||
|
export VERSION=2.0.0
|
||||||
|
export SCRIPT_DIR="$suite_dir/.."
|
||||||
|
export LIB_DIR="$SCRIPT_DIR/lib"
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
run_cli() {
|
||||||
|
local script="$1"; shift
|
||||||
|
local definitions="$BATS_TEST_TMPDIR/${script##*/}.functions"
|
||||||
|
sed '/^main "\$@"$/d' "$script" > "$definitions"
|
||||||
|
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
|
||||||
|
source "$1"
|
||||||
|
shift
|
||||||
|
load_config() { :; }
|
||||||
|
is_root() { return 1; }
|
||||||
|
is_recovery() { return 1; }
|
||||||
|
cmd_interactive_normal() { printf "interactive verbose=%s\n" "$VERBOSE"; }
|
||||||
|
main "$@"
|
||||||
|
' "$script" "$definitions" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_capture() {
|
||||||
|
local script="$1"; shift
|
||||||
|
local definitions="$BATS_TEST_TMPDIR/${script##*/}.functions"
|
||||||
|
sed '/^main "\$@"$/d' "$script" > "$definitions"
|
||||||
|
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
|
||||||
|
source "$1"
|
||||||
|
shift
|
||||||
|
load_config() { :; }
|
||||||
|
cmd_config() {
|
||||||
|
printf "dry=%s verbose=%s log=<%s>\nargc=%s\n" "$DRY_RUN" "$VERBOSE" "$LOG_FILE" "$#"
|
||||||
|
printf "<%s>\n" "$@"
|
||||||
|
}
|
||||||
|
main "$@"
|
||||||
|
' "$script" "$definitions" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "optional CLI arguments reach usage or privilege guards under nounset" {
|
||||||
|
local entrypoint
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
local script="$BATS_TEST_DIRNAME/../$entrypoint"
|
||||||
|
run_cli "$script" audit
|
||||||
|
[ "$status" -ne 0 ]; [[ "$output" == *"Audit needs sudo"* ]]
|
||||||
|
run_cli "$script" --log-file
|
||||||
|
[ "$status" -ne 0 ]; [[ "$output" == *"--log-file requires a path"* ]]
|
||||||
|
run_cli "$script" monitor --webhook
|
||||||
|
[ "$status" -ne 0 ]; [[ "$output" == *"--webhook requires a URL"* ]]
|
||||||
|
run_cli "$script" config set
|
||||||
|
[ "$status" -ne 0 ]; [[ "$output" == *"Usage: ./unleash config set KEY VALUE"* ]]
|
||||||
|
run_cli "$script" config unset
|
||||||
|
[ "$status" -ne 0 ]; [[ "$output" == *"Usage: ./unleash config unset KEY"* ]]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "CLI values retain spaces quotes empty strings and literal shell syntax" {
|
||||||
|
local entrypoint value
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
for value in 'a b $(printf injected) "quoted"' ''; do
|
||||||
|
run_capture "$BATS_TEST_DIRNAME/../$entrypoint" config set LOG_FILE "$value"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
local expected
|
||||||
|
expected=$(printf 'dry=false verbose=false log=<>\nargc=4\n<config>\n<set>\n<LOG_FILE>\n<%s>' "$value")
|
||||||
|
[ "$output" = "$expected" ]
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "global flags around the command persist in the command shell" {
|
||||||
|
local entrypoint
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
run_capture "$BATS_TEST_DIRNAME/../$entrypoint" --dry-run config --verbose set LOG_FILE value --log-file 'a b.log'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == 'dry=true verbose=true log=<a b.log>'* ]]
|
||||||
|
[[ "$output" == *'argc=4'* ]]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "global flags without a command preserve an empty argument list" {
|
||||||
|
local entrypoint
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
run_cli "$BATS_TEST_DIRNAME/../$entrypoint" --verbose
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" = 'interactive verbose=true' ]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "CLI option terminator preserves values that look like global options" {
|
||||||
|
local entrypoint
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
run_capture "$BATS_TEST_DIRNAME/../$entrypoint" config set LOG_LEVEL -- --verbose
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == 'dry=false verbose=false log=<>'* ]]
|
||||||
|
[[ "$output" == *'<--verbose>' ]]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "log-file rejects an empty path or another option as its missing value" {
|
||||||
|
local entrypoint value
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
for value in '' --dry-run; do
|
||||||
|
run_cli "$BATS_TEST_DIRNAME/../$entrypoint" --log-file "$value" version
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"--log-file requires a path"* ]]
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
# Tests for colors.sh - run with: bats tests/test_colors.bats
|
# Tests for colors.sh - run with: bats tests/test_colors.bats
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
bats_require_minimum_version 1.5.0
|
||||||
load '../lib/colors.sh'
|
load '../lib/colors.sh'
|
||||||
TEST_LOG=$(mktemp)
|
TEST_LOG=$(mktemp)
|
||||||
}
|
}
|
||||||
@@ -39,3 +40,40 @@ teardown() {
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
echo "$output" | grep -q "Test Title"
|
echo "$output" | grep -q "Test Title"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "header draws a valid Unicode border for the title width" {
|
||||||
|
run header Mac
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"╔═══════╗"* ]]
|
||||||
|
[[ "$output" == *"╚═══════╝"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "diagnostics use stderr without contaminating helper return values" {
|
||||||
|
local source_file
|
||||||
|
for source_file in lib/colors.sh unleash-standalone.sh; do
|
||||||
|
run --separate-stderr bash -u -c '
|
||||||
|
source <(sed "/^error_exit()/,\$d" "$1")
|
||||||
|
volume_path() {
|
||||||
|
log INFO "Locating Data volume"
|
||||||
|
log OK "Data volume found"
|
||||||
|
printf "%s\n" "/Volumes/Work Data"
|
||||||
|
}
|
||||||
|
result=$(volume_path)
|
||||||
|
printf "%s\n" "$result"
|
||||||
|
' bash "$BATS_TEST_DIRNAME/../$source_file"
|
||||||
|
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" = "/Volumes/Work Data" ]
|
||||||
|
[[ "$stderr" == *"Locating Data volume"* ]]
|
||||||
|
[[ "$stderr" == *"Data volume found"* ]]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "diagnostics still reach the log file when stdout is captured" {
|
||||||
|
LOG_FILE="$TEST_LOG"
|
||||||
|
local result
|
||||||
|
result=$(log WARN "Review the selected volume" 2>/dev/null)
|
||||||
|
|
||||||
|
[ -z "$result" ]
|
||||||
|
grep -q 'Review the selected volume' "$TEST_LOG"
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,3 +35,22 @@ teardown() {
|
|||||||
run grep -c "KEY=new" "$CONFIG_FILE"
|
run grep -c "KEY=new" "$CONFIG_FILE"
|
||||||
[ "$output" -eq 1 ]
|
[ "$output" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "config preserves spaces and literal replacement characters" {
|
||||||
|
local value='/tmp/Unleash logs/quoted "name" & \tail'
|
||||||
|
save_config LOG_FILE old
|
||||||
|
save_config LOG_FILE "$value"
|
||||||
|
LOG_FILE=''
|
||||||
|
load_config
|
||||||
|
[ "$LOG_FILE" = "$value" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "config unset preserves other keys" {
|
||||||
|
save_config WEBHOOK 'https://example.com/a?x=1&y=2'
|
||||||
|
save_config LOG_LEVEL verbose
|
||||||
|
run cmd_config config unset LOG_LEVEL
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
run grep -c '^LOG_LEVEL=' "$CONFIG_FILE"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
grep -q '^WEBHOOK=https://example.com/a?x=1&y=2$' "$CONFIG_FILE"
|
||||||
|
}
|
||||||
|
|||||||
+10
-10
@@ -5,14 +5,11 @@ setup() {
|
|||||||
load '../lib/detect.sh'
|
load '../lib/detect.sh'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "is_root returns true when EUID is 0" {
|
@test "is_root reports whether the effective user is root" {
|
||||||
[ "$EUID" -eq 0 ] && skip "Already root"
|
local expected=1
|
||||||
[ "$EUID" -ne 0 ] && skip "Not root"
|
[ "$EUID" -ne 0 ] || expected=0
|
||||||
}
|
run is_root
|
||||||
|
[ "$status" -eq "$expected" ]
|
||||||
@test "is_root returns false when EUID is not 0" {
|
|
||||||
[ "$EUID" -ne 0 ] && skip "Not root (expected)"
|
|
||||||
[ "$EUID" -eq 0 ] && skip "Is root"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "is_recovery returns false in normal environment" {
|
@test "is_recovery returns false in normal environment" {
|
||||||
@@ -26,6 +23,9 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "resolve_data_volume errors on non-existent device" {
|
@test "resolve_data_volume errors on non-existent device" {
|
||||||
run resolve_data_volume 2>/dev/null || true
|
read() { echo PROMPT_WAS_REACHED; return 1; }
|
||||||
[ "$status" -eq 0 ]
|
run resolve_data_volume </dev/null
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"Cannot select a Data volume without a terminal"* ]]
|
||||||
|
[[ "$output" != *"PROMPT_WAS_REACHED"* ]]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,14 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "harden_live_os exits cleanly" {
|
@test "harden_live_os exits cleanly" {
|
||||||
run harden_live_os 2>/dev/null || true
|
mkdir -p "$BATS_TEST_TMPDIR/Users/test/Library/LaunchAgents"
|
||||||
|
local agents="$BATS_TEST_TMPDIR/Users/test/Library/LaunchAgents"
|
||||||
|
echo mdm > "$agents/enrollment.plist"
|
||||||
|
echo normal > "$agents/normal.plist"
|
||||||
|
run harden_live_os "$BATS_TEST_TMPDIR"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
[ ! -f "$agents/enrollment.plist" ]
|
||||||
|
[ -f "$agents/normal.plist" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "harden_status exits cleanly" {
|
@test "harden_status exits cleanly" {
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "show_history exits cleanly with no logs" {
|
@test "show_history exits cleanly with no logs" {
|
||||||
run show_history 2>/dev/null || true
|
run show_history "$BATS_TEST_TMPDIR"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "clear_history does not error with no logs" {
|
@test "clear_history does not error with no logs" {
|
||||||
run clear_history 2>/dev/null || true
|
echo event > "$BATS_TEST_TMPDIR/unleash-monitor.log"
|
||||||
|
run clear_history "$BATS_TEST_TMPDIR"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
[ ! -s "$BATS_TEST_TMPDIR/unleash-monitor.log" ]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
PROJECT="$BATS_TEST_TMPDIR/project"
|
||||||
|
mkdir -p "$PROJECT/scripts" "$PROJECT/lib"
|
||||||
|
cp "$BATS_TEST_DIRNAME/../scripts/check-shell.py" "$PROJECT/scripts/"
|
||||||
|
cat > "$PROJECT/unleash" <<'SH'
|
||||||
|
#!/bin/bash
|
||||||
|
for _lib in sample; do
|
||||||
|
source "lib/$_lib.sh"
|
||||||
|
done
|
||||||
|
sample
|
||||||
|
SH
|
||||||
|
printf 'sample() { :; }\n' > "$PROJECT/lib/sample.sh"
|
||||||
|
printf '#!/bin/bash\n' > "$PROJECT/unleash-standalone.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "lint reports sourced module findings without executing the application" {
|
||||||
|
export LINT_TEST_MARKER="$BATS_TEST_TMPDIR/app-executed"
|
||||||
|
printf 'sample() { echo $missing; }\n: > "$LINT_TEST_MARKER"\n' > "$PROJECT/lib/sample.sh"
|
||||||
|
run python3 "$PROJECT/scripts/check-shell.py"
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"lib/sample.sh:1:"* ]]
|
||||||
|
[[ "$output" == *"SC2086"* ]]
|
||||||
|
[ ! -f "$LINT_TEST_MARKER" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "lint checks syntax in every library" {
|
||||||
|
printf 'sample() {\n' > "$PROJECT/lib/sample.sh"
|
||||||
|
run python3 "$PROJECT/scripts/check-shell.py"
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"sample.sh"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "lint does not install tools after an analysis failure" {
|
||||||
|
cp "$BATS_TEST_DIRNAME/../Makefile" "$PROJECT/Makefile"
|
||||||
|
local mock_bin="$BATS_TEST_TMPDIR/lint-bin"
|
||||||
|
mkdir -p "$mock_bin"
|
||||||
|
ln -s "$(command -v python3)" "$mock_bin/python3"
|
||||||
|
ln -s "$(command -v bash)" "$mock_bin/bash"
|
||||||
|
printf '#!/bin/sh\nprintf "[]"\nexit 1\n' > "$mock_bin/shellcheck"
|
||||||
|
export TEST_BREW_MARKER="$BATS_TEST_TMPDIR/brew-called"
|
||||||
|
printf '#!/bin/sh\n: > "$TEST_BREW_MARKER"\n' > "$mock_bin/brew"
|
||||||
|
chmod +x "$mock_bin/shellcheck" "$mock_bin/brew"
|
||||||
|
run env PATH="$mock_bin" "$(command -v make)" -C "$PROJECT" lint
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[ ! -f "$TEST_BREW_MARKER" ]
|
||||||
|
}
|
||||||
@@ -3,14 +3,26 @@
|
|||||||
setup() {
|
setup() {
|
||||||
load '../lib/colors.sh'
|
load '../lib/colors.sh'
|
||||||
load '../lib/ma_detect.sh'
|
load '../lib/ma_detect.sh'
|
||||||
|
mkdir -p "$BATS_TEST_TMPDIR/Users"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "detect_migration_assistant exits cleanly" {
|
@test "detect_migration_assistant exits cleanly" {
|
||||||
run detect_migration_assistant 2>/dev/null || true
|
run detect_migration_assistant "$BATS_TEST_TMPDIR"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "clean_ma_artifacts does not error without users" {
|
@test "clean_ma_artifacts does not error without users" {
|
||||||
run clean_ma_artifacts 2>/dev/null || true
|
run clean_ma_artifacts "$BATS_TEST_TMPDIR"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "migration audit detects enrollment and MDM cache directories" {
|
||||||
|
local caches="$BATS_TEST_TMPDIR/Users/test/Library/Caches"
|
||||||
|
mkdir -p "$caches/com.apple.enrollmenttool" "$caches/com.apple.mdm"
|
||||||
|
echo cached > "$caches/com.apple.enrollmenttool/record"
|
||||||
|
echo cached > "$caches/com.apple.mdm/record"
|
||||||
|
run detect_migration_assistant "$BATS_TEST_TMPDIR"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"enrollment cache files"* ]]
|
||||||
|
[[ "$output" == *"MDM cache files"* ]]
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
load '../lib/colors.sh'
|
load '../lib/colors.sh'
|
||||||
|
load '../lib/launchd.sh'
|
||||||
load '../lib/monitor.sh'
|
load '../lib/monitor.sh'
|
||||||
TEST_DIR=$(mktemp -d)
|
TEST_DIR=$(mktemp -d)
|
||||||
|
SCRIPT_PATH="$TEST_DIR/unleash"
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
@@ -11,12 +13,12 @@ teardown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "monitor_status exits cleanly when not running" {
|
@test "monitor_status exits cleanly when not running" {
|
||||||
run monitor_status 2>/dev/null || true
|
run monitor_status "$TEST_DIR/monitor.pid"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "stop_monitor exits cleanly when not running" {
|
@test "stop_monitor exits cleanly when not running" {
|
||||||
run stop_monitor 2>/dev/null || true
|
run stop_monitor "$TEST_DIR/monitor.pid"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
check_daemon_path() {
|
||||||
|
local installer="$1" action="$2" label="$3"
|
||||||
|
local entrypoint
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
local folder="$BATS_TEST_TMPDIR/$entrypoint/Tool Folder & <profile> \"quoted\""
|
||||||
|
local target="$BATS_TEST_TMPDIR/$entrypoint/Target"
|
||||||
|
local script="$folder/renamed standalone.sh"
|
||||||
|
local definitions="$BATS_TEST_TMPDIR/$entrypoint.functions"
|
||||||
|
mkdir -p "$folder" "$target/Library"
|
||||||
|
printf '#!/bin/bash\nprintf "ACTION=%%s\\n" "$1"\n' > "$script"
|
||||||
|
if [ "$entrypoint" = unleash ]; then
|
||||||
|
ln -s "$BATS_TEST_DIRNAME/../lib" "$folder/lib"
|
||||||
|
fi
|
||||||
|
sed '/^main "\$@"$/d' "$BATS_TEST_DIRNAME/../$entrypoint" > "$definitions"
|
||||||
|
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
|
||||||
|
unset SCRIPT_DIR SCRIPT_PATH
|
||||||
|
source "$1"
|
||||||
|
expected="$2/Library/LaunchDaemons"
|
||||||
|
mkdir() {
|
||||||
|
[ "$#" -eq 2 ] && [ "$1" = -p ] && [ "$2" = "$expected" ] || return 97
|
||||||
|
command mkdir "$@"
|
||||||
|
}
|
||||||
|
"$3" "$2"
|
||||||
|
' "$script" "$definitions" "$target" "$installer"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
run python3 - "$target/Library/LaunchDaemons/$label.plist" "$script" "$action" <<'PY'
|
||||||
|
import plistlib,subprocess,sys
|
||||||
|
with open(sys.argv[1],'rb') as source:
|
||||||
|
data=plistlib.load(source)
|
||||||
|
expected=['/bin/bash',sys.argv[2],sys.argv[3]]
|
||||||
|
assert data['ProgramArguments']==expected, data['ProgramArguments']
|
||||||
|
result=subprocess.run(expected,capture_output=True,text=True,timeout=5)
|
||||||
|
assert result.returncode==0, result.stderr
|
||||||
|
assert result.stdout=='ACTION='+sys.argv[3]+'\n', result.stdout
|
||||||
|
PY
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "persistence invokes renamed scripts with spaces and XML text literally" {
|
||||||
|
check_daemon_path install_persist_launchdaemon heal com.unleash.heal
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "monitor invokes renamed scripts with spaces and XML text literally" {
|
||||||
|
check_daemon_path install_monitor_launchdaemon monitor com.unleash.monitor
|
||||||
|
}
|
||||||
@@ -26,3 +26,47 @@ teardown() {
|
|||||||
run deep_status_json 2>/dev/null || true
|
run deep_status_json 2>/dev/null || true
|
||||||
echo "$output" | grep -q "}"
|
echo "$output" | grep -q "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "deep_status_json counts a single matching process without subtracting it" {
|
||||||
|
profiles() {
|
||||||
|
if [ "$1" = -C ]; then echo '<key>ProfileDisplayName</key>';
|
||||||
|
else echo 'MDM enrollment: No'; fi
|
||||||
|
}
|
||||||
|
sudo() { "$@"; }
|
||||||
|
pgrep() { echo '42 mdmclient'; }
|
||||||
|
ps() { echo 'test 42 0.0 0.0 1 1 ? S 00:00 0:00 mdmclient'; }
|
||||||
|
run deep_status_json
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
echo "$output" | python3 -c 'import json,sys; assert json.load(sys.stdin)["running_mdm_processes"] == 1'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "text audit completes with zero profiles under nounset" {
|
||||||
|
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
|
||||||
|
source "$1/lib/colors.sh"
|
||||||
|
source "$1/lib/status.sh"
|
||||||
|
pf_status() { :; }
|
||||||
|
deep_status
|
||||||
|
' bash "$BATS_TEST_DIRNAME/.."
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"Risk:"* ]]
|
||||||
|
[[ "$output" != *"integer expression expected"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "audit and report JSON contain numeric zero counts under nounset" {
|
||||||
|
local module function_name field
|
||||||
|
for module in status report; do
|
||||||
|
if [ "$module" = status ]; then function_name=deep_status_json; field=profile_count;
|
||||||
|
else function_name=generate_report_json; field=installed_profiles; fi
|
||||||
|
run "${UNLEASH_TEST_SHELL:-bash}" -u -c '
|
||||||
|
source "$1/lib/colors.sh"
|
||||||
|
source "$1/lib/$2.sh"
|
||||||
|
grep() {
|
||||||
|
if [ "${1:-}" = -c ] && [ "${3:-}" = /private/etc/hosts ]; then echo 0; return 1; fi
|
||||||
|
command grep "$@"
|
||||||
|
}
|
||||||
|
"$3"
|
||||||
|
' bash "$BATS_TEST_DIRNAME/.." "$module" "$function_name"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
echo "$output" | python3 -c 'import json,sys; data=json.load(sys.stdin); assert data[sys.argv[1]] == 0; assert data.get("hosts_blocked",0) == 0' "$field"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,14 +34,21 @@ teardown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "suppress_enrollment disables daemons" {
|
@test "suppress_enrollment disables daemons" {
|
||||||
|
TEST_DIR="$BATS_TEST_TMPDIR/volume"
|
||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
suppress_enrollment "$TEST_DIR" 2>/dev/null || true
|
suppress_enrollment "$TEST_DIR" 2>/dev/null || true
|
||||||
local ldp="$TEST_DIR/private/var/db/com.apple.xpc.launchd/disabled.plist"
|
local ldp="$TEST_DIR/private/var/db/com.apple.xpc.launchd/disabled.plist"
|
||||||
[ -f "$ldp" ]
|
[ -f "$ldp" ]
|
||||||
run /usr/libexec/PlistBuddy -c "Print :com.apple.ManagedClient.enroll" "$ldp" 2>/dev/null
|
run "$PB" -c "Print :com.apple.ManagedClient.enroll" "$ldp"
|
||||||
[ "$output" = "true" ]
|
[ "$output" = "true" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "PlistBuddy fixture rejects writes outside the test suite" {
|
||||||
|
run "$PB" -c 'Add :test bool true' "$BATS_TEST_DIRNAME/../README.md"
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"Fixture refused path outside the suite"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
@test "dry-run mode does not write files" {
|
@test "dry-run mode does not write files" {
|
||||||
DRY_RUN=true
|
DRY_RUN=true
|
||||||
suppress_enrollment "$TEST_DIR" 2>/dev/null || true
|
suppress_enrollment "$TEST_DIR" 2>/dev/null || true
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
check_volume_output() {
|
||||||
|
local mode="$1" entrypoint
|
||||||
|
bats_require_minimum_version 1.5.0
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
local script="$BATS_TEST_DIRNAME/../$entrypoint"
|
||||||
|
local target="$BATS_TEST_TMPDIR/$entrypoint/Data volume"
|
||||||
|
mkdir -p "$target/private/var/db/dslocal/nodes/Default"
|
||||||
|
run --separate-stderr bash -u -c '
|
||||||
|
source <(sed '\''/^main "\$@"$/d'\'' "$1")
|
||||||
|
target="$2"; mode="$3"; mounted="$4"
|
||||||
|
diskutil() {
|
||||||
|
case "$*" in
|
||||||
|
"apfs list") echo "+-- Volume disk5s1 (Data)" ;;
|
||||||
|
"info /dev/disk5s1")
|
||||||
|
if [ -f "$mounted" ]; then printf "Mount Point: %s\n" "$target";
|
||||||
|
else echo "Mount Point: Not mounted"; fi ;;
|
||||||
|
"mount /dev/disk5s1")
|
||||||
|
echo "Mount attempt diagnostic"
|
||||||
|
[ "$mode" != locked ] || return 1
|
||||||
|
touch "$mounted" ;;
|
||||||
|
"apfs unlockVolume /dev/disk5s1")
|
||||||
|
echo "Unlocking any cryptographic user"
|
||||||
|
echo "Unlocked and mounted APFS Volume"
|
||||||
|
touch "$mounted" ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
resolve_data_volume
|
||||||
|
' "$script" "$script" "$target" "$mode" "$BATS_TEST_TMPDIR/$entrypoint.mounted"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" = "$target" ]
|
||||||
|
[[ "$stderr" == *"Mount attempt diagnostic"* ]]
|
||||||
|
if [ "$mode" = locked ]; then
|
||||||
|
[[ "$stderr" == *"Unlocked and mounted APFS Volume"* ]]
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "mount diagnostics stay out of the selected Data volume path" {
|
||||||
|
check_volume_output unmounted
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "FileVault unlock diagnostics stay out of the selected Data volume path" {
|
||||||
|
check_volume_output locked
|
||||||
|
}
|
||||||
@@ -4,9 +4,10 @@ set -euo pipefail
|
|||||||
VERSION="2.0.0"
|
VERSION="2.0.0"
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
SCRIPT_PATH="$SCRIPT_DIR/$(basename "$0")"
|
||||||
LIB_DIR="$SCRIPT_DIR/lib"
|
LIB_DIR="$SCRIPT_DIR/lib"
|
||||||
|
|
||||||
for _lib in colors config detect validate dscl suppress backup status heal firewall harden whitelist check monitor history doctor selfupdate uninstall report ma_detect demo vpn init suggest remediate telemetry predict discord; do
|
for _lib in colors config detect validate dscl suppress backup status launchd heal firewall harden whitelist check monitor history doctor selfupdate uninstall report ma_detect demo vpn init suggest remediate telemetry predict discord; do
|
||||||
_lib_path="$LIB_DIR/$_lib.sh"
|
_lib_path="$LIB_DIR/$_lib.sh"
|
||||||
if [ -f "$_lib_path" ]; then
|
if [ -f "$_lib_path" ]; then
|
||||||
source "$_lib_path"
|
source "$_lib_path"
|
||||||
@@ -222,6 +223,7 @@ cmd_dualboot() {
|
|||||||
echo ""
|
echo ""
|
||||||
step "Creating admin account on target"
|
step "Creating admin account on target"
|
||||||
|
|
||||||
|
local realName
|
||||||
prompt_default realName "Full name" "Apple"
|
prompt_default realName "Full name" "Apple"
|
||||||
local username
|
local username
|
||||||
prompt_username username
|
prompt_username username
|
||||||
@@ -236,9 +238,7 @@ cmd_dualboot() {
|
|||||||
begin "Blocking domains"
|
begin "Blocking domains"
|
||||||
local hosts_file="$data_path/private/etc/hosts"
|
local hosts_file="$data_path/private/etc/hosts"
|
||||||
[ -f "$hosts_file" ] || touch "$hosts_file"
|
[ -f "$hosts_file" ] || touch "$hosts_file"
|
||||||
echo "0.0.0.0 deviceenrollment.apple.com" >>"$hosts_file"
|
printf '%s\n' "0.0.0.0 deviceenrollment.apple.com" "0.0.0.0 mdmenrollment.apple.com" "0.0.0.0 iprofiles.apple.com" >>"$hosts_file"
|
||||||
echo "0.0.0.0 mdmenrollment.apple.com" >>"$hosts_file"
|
|
||||||
echo "0.0.0.0 iprofiles.apple.com" >>"$hosts_file"
|
|
||||||
end_ok
|
end_ok
|
||||||
|
|
||||||
begin "Resetting config profiles"
|
begin "Resetting config profiles"
|
||||||
@@ -372,7 +372,9 @@ cmd_monitor() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
install|uninstall) args+=("$1"); shift ;;
|
install|uninstall) args+=("$1"); shift ;;
|
||||||
--webhook) webhook="$2"; shift 2 ;;
|
--webhook)
|
||||||
|
if [ $# -lt 2 ] || [ -z "$2" ]; then error_exit "--webhook requires a URL"; fi
|
||||||
|
webhook="$2"; shift 2 ;;
|
||||||
*) args+=("$1"); shift ;;
|
*) args+=("$1"); shift ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -532,22 +534,29 @@ cmd_interactive_normal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_global_opts() {
|
parse_global_opts() {
|
||||||
local args=()
|
PARSED_ARGS=()
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--verbose) VERBOSE=true; shift ;;
|
--verbose) VERBOSE=true; shift ;;
|
||||||
--dry-run) DRY_RUN=true; shift ;;
|
--dry-run) DRY_RUN=true; shift ;;
|
||||||
--log-file) LOG_FILE="$2"; shift 2 ;;
|
--log-file)
|
||||||
*) args+=("$1"); shift ;;
|
if [ $# -lt 2 ] || [ -z "$2" ]; then error_exit "--log-file requires a path"; fi
|
||||||
|
case "$2" in --*) error_exit "--log-file requires a path" ;; esac
|
||||||
|
LOG_FILE="$2"; shift 2 ;;
|
||||||
|
--) shift; PARSED_ARGS+=("$@"); break ;;
|
||||||
|
*) PARSED_ARGS+=("$1"); shift ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
set -- "${args[@]}"
|
|
||||||
echo "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
load_config
|
load_config
|
||||||
eval "set -- $(parse_global_opts "$@")"
|
parse_global_opts "$@"
|
||||||
|
if [ "${PARSED_ARGS[0]+present}" = present ]; then
|
||||||
|
set -- "${PARSED_ARGS[@]}"
|
||||||
|
else
|
||||||
|
set --
|
||||||
|
fi
|
||||||
|
|
||||||
# Per-command help
|
# Per-command help
|
||||||
if [ "${2:-}" = "--help" ] || [ "${2:-}" = "-h" ]; then
|
if [ "${2:-}" = "--help" ] || [ "${2:-}" = "-h" ]; then
|
||||||
@@ -564,7 +573,7 @@ main() {
|
|||||||
firewall|fw) cmd_firewall ;;
|
firewall|fw) cmd_firewall ;;
|
||||||
firewall-off|fw-off) cmd_firewall_off ;;
|
firewall-off|fw-off) cmd_firewall_off ;;
|
||||||
harden) cmd_harden ;;
|
harden) cmd_harden ;;
|
||||||
audit) cmd_audit "$2" ;;
|
audit) cmd_audit "${2:-}" ;;
|
||||||
whitelist|wl) cmd_whitelist ;;
|
whitelist|wl) cmd_whitelist ;;
|
||||||
backup) cmd_backup ;;
|
backup) cmd_backup ;;
|
||||||
restore) cmd_restore ;;
|
restore) cmd_restore ;;
|
||||||
@@ -582,13 +591,13 @@ main() {
|
|||||||
version|-v|--version) cmd_version ;;
|
version|-v|--version) cmd_version ;;
|
||||||
init) cmd_init ;;
|
init) cmd_init ;;
|
||||||
suggest) cmd_suggest ;;
|
suggest) cmd_suggest ;;
|
||||||
remediate) cmd_remediate "$2" ;;
|
remediate) cmd_remediate "${2:-}" ;;
|
||||||
predict) cmd_predict "$2" ;;
|
predict) cmd_predict "${2:-}" ;;
|
||||||
telemetry) telemetry_opt_in "$2" ;;
|
telemetry) telemetry_opt_in "${2:-}" ;;
|
||||||
demo) run_demo ;;
|
demo) run_demo ;;
|
||||||
update) do_self_update ;;
|
update) do_self_update ;;
|
||||||
uninstall) do_uninstall ;;
|
uninstall) do_uninstall ;;
|
||||||
report) generate_report "$2" ;;
|
report) generate_report "${2:-}" ;;
|
||||||
config) cmd_config "$@" ;;
|
config) cmd_config "$@" ;;
|
||||||
vpn-kill) vpn_kill_install "$@" ;;
|
vpn-kill) vpn_kill_install "$@" ;;
|
||||||
vpn-kill-remove) vpn_kill_remove ;;
|
vpn-kill-remove) vpn_kill_remove ;;
|
||||||
@@ -600,7 +609,7 @@ main() {
|
|||||||
install_monitor_launchdaemon ""
|
install_monitor_launchdaemon ""
|
||||||
success "Reinstall complete"
|
success "Reinstall complete"
|
||||||
;;
|
;;
|
||||||
discord-bot) cmd_discord_bot_install "$2" "$3" ;;
|
discord-bot) cmd_discord_bot_install "${2:-}" "${3:-}" ;;
|
||||||
discord-bot-stop) cmd_discord_bot_stop ;;
|
discord-bot-stop) cmd_discord_bot_stop ;;
|
||||||
discord-bot-status) cmd_discord_bot_status ;;
|
discord-bot-status) cmd_discord_bot_status ;;
|
||||||
help|-h|--help) show_help; exit 0 ;;
|
help|-h|--help) show_help; exit 0 ;;
|
||||||
|
|||||||
+211
-138
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
VERSION="2.0.0"
|
VERSION="2.0.0"
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
SCRIPT_PATH="$SCRIPT_DIR/$(basename "$0")"
|
||||||
RED='\033[1;31m'
|
RED='\033[1;31m'
|
||||||
GRN='\033[1;32m'
|
GRN='\033[1;32m'
|
||||||
BLU='\033[1;34m'
|
BLU='\033[1;34m'
|
||||||
@@ -35,7 +37,7 @@ log() {
|
|||||||
|
|
||||||
local ts
|
local ts
|
||||||
ts=$(date '+%H:%M:%S')
|
ts=$(date '+%H:%M:%S')
|
||||||
echo -e "${color}[${label}]${NC} ${msg}"
|
echo -e "${color}[${label}]${NC} ${msg}" >&2
|
||||||
|
|
||||||
if [ -n "$LOG_FILE" ]; then
|
if [ -n "$LOG_FILE" ]; then
|
||||||
echo "[${ts}] [${label}] ${msg}" >> "$LOG_FILE" 2>/dev/null || true
|
echo "[${ts}] [${label}] ${msg}" >> "$LOG_FILE" 2>/dev/null || true
|
||||||
@@ -43,7 +45,7 @@ log() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_exit() {
|
error_exit() {
|
||||||
log "ERROR" "$1" >&2
|
log "ERROR" "$1"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +73,8 @@ header() {
|
|||||||
local title="$1"
|
local title="$1"
|
||||||
local len="${#title}"
|
local len="${#title}"
|
||||||
local line
|
local line
|
||||||
line=$(printf '%*s' "$((len + 4))" | tr ' ' '═')
|
line=$(printf '%*s' "$((len + 4))" '')
|
||||||
|
line="${line// /═}"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${CYAN}╔${line}╗${NC}"
|
echo -e "${CYAN}╔${line}╗${NC}"
|
||||||
echo -e "${CYAN}║ ${title} ║${NC}"
|
echo -e "${CYAN}║ ${title} ║${NC}"
|
||||||
@@ -110,7 +113,7 @@ prompt_default() {
|
|||||||
local prompt_text="$2"
|
local prompt_text="$2"
|
||||||
local default="$3"
|
local default="$3"
|
||||||
local value
|
local value
|
||||||
read -p "${CYAN}${prompt_text}${NC} (default '${default}'): " value
|
read -r -p "${CYAN}${prompt_text}${NC} (default '${default}'): " value
|
||||||
value="${value:=$default}"
|
value="${value:=$default}"
|
||||||
eval "$var_name=\"$value\""
|
eval "$var_name=\"$value\""
|
||||||
}
|
}
|
||||||
@@ -118,7 +121,7 @@ prompt_default() {
|
|||||||
confirm() {
|
confirm() {
|
||||||
local prompt="$1"
|
local prompt="$1"
|
||||||
local response
|
local response
|
||||||
read -p "${prompt} (y/N): " response
|
read -r -p "${prompt} (y/N): " response
|
||||||
[[ "$response" =~ ^[Yy]$ ]]
|
[[ "$response" =~ ^[Yy]$ ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,10 +129,9 @@ CONFIG_FILE="$HOME/.unleash.conf"
|
|||||||
|
|
||||||
load_config() {
|
load_config() {
|
||||||
[ -f "$CONFIG_FILE" ] || return 0
|
[ -f "$CONFIG_FILE" ] || return 0
|
||||||
|
local key value
|
||||||
while IFS='=' read -r key value; do
|
while IFS='=' read -r key value || [ -n "$key" ]; do
|
||||||
key="${key// /}"
|
key="${key// /}"
|
||||||
value="${value// /}"
|
|
||||||
[ -z "$key" ] && continue
|
[ -z "$key" ] && continue
|
||||||
case "$key" in
|
case "$key" in
|
||||||
WEBHOOK) DISCORD_WEBHOOK="$value" ;;
|
WEBHOOK) DISCORD_WEBHOOK="$value" ;;
|
||||||
@@ -139,18 +141,29 @@ load_config() {
|
|||||||
done < "$CONFIG_FILE"
|
done < "$CONFIG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
save_config() {
|
_rewrite_config() {
|
||||||
local key="$1"
|
local key="$1"
|
||||||
local value="$2"
|
local value="$2"
|
||||||
local tmp
|
local tmp
|
||||||
|
|
||||||
[ -f "$CONFIG_FILE" ] || touch "$CONFIG_FILE"
|
[ -f "$CONFIG_FILE" ] || touch "$CONFIG_FILE"
|
||||||
|
tmp=$(mktemp "${CONFIG_FILE}.XXXXXX") || return 1
|
||||||
if grep -q "^${key}=" "$CONFIG_FILE" 2>/dev/null; then
|
if ! UNLEASH_CONFIG_KEY="$key" UNLEASH_CONFIG_VALUE="$value" \
|
||||||
sed -i '' "s/^${key}=.*/${key}=${value}/" "$CONFIG_FILE"
|
UNLEASH_CONFIG_OPERATION="${3:-set}" awk '
|
||||||
else
|
BEGIN { key=ENVIRON["UNLEASH_CONFIG_KEY"]; value=ENVIRON["UNLEASH_CONFIG_VALUE"];
|
||||||
echo "${key}=${value}" >> "$CONFIG_FILE"
|
operation=ENVIRON["UNLEASH_CONFIG_OPERATION"] }
|
||||||
|
index($0, key "=")==1 { if (!found++ && operation=="set") print key "=" value; next }
|
||||||
|
{ print }
|
||||||
|
END { if (!found && operation=="set") print key "=" value }
|
||||||
|
' "$CONFIG_FILE" > "$tmp"; then
|
||||||
|
rm -f "$tmp"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
mv "$tmp" "$CONFIG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
save_config() {
|
||||||
|
local key="$1" value="$2"
|
||||||
|
_rewrite_config "$key" "$value" || return 1
|
||||||
success "Saved $key to $CONFIG_FILE"
|
success "Saved $key to $CONFIG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +180,8 @@ cmd_config() {
|
|||||||
cat "$CONFIG_FILE" | sed 's/^/ /'
|
cat "$CONFIG_FILE" | sed 's/^/ /'
|
||||||
;;
|
;;
|
||||||
set)
|
set)
|
||||||
local key="$3"
|
local key="${3:-}"
|
||||||
local value="$4"
|
local value="${4:-}"
|
||||||
[ -z "$key" ] || [ -z "$value" ] && {
|
[ -z "$key" ] || [ -z "$value" ] && {
|
||||||
info "Usage: ./unleash config set KEY VALUE"
|
info "Usage: ./unleash config set KEY VALUE"
|
||||||
info "Keys: WEBHOOK, LOG_LEVEL (verbose), LOG_FILE"
|
info "Keys: WEBHOOK, LOG_LEVEL (verbose), LOG_FILE"
|
||||||
@@ -177,10 +190,10 @@ cmd_config() {
|
|||||||
save_config "$key" "$value"
|
save_config "$key" "$value"
|
||||||
;;
|
;;
|
||||||
unset)
|
unset)
|
||||||
local key="$3"
|
local key="${3:-}"
|
||||||
[ -z "$key" ] && { info "Usage: ./unleash config unset KEY"; return 1; }
|
[ -z "$key" ] && { info "Usage: ./unleash config unset KEY"; return 1; }
|
||||||
if [ -f "$CONFIG_FILE" ]; then
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
sed -i '' "/^${key}=/d" "$CONFIG_FILE"
|
_rewrite_config "$key" "" unset || return 1
|
||||||
success "Removed $key from config"
|
success "Removed $key from config"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -223,8 +236,9 @@ resolve_data_volume() {
|
|||||||
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
|
||||||
warn "Auto-detection failed. Available disks:"
|
warn "Auto-detection failed. Available disks:"
|
||||||
diskutil list >&2
|
diskutil list >&2
|
||||||
echo ""
|
echo "" >&2
|
||||||
read -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
[ -t 0 ] || error_exit "Cannot select a Data volume without a terminal."
|
||||||
|
read -r -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
|
||||||
id="${id#/dev/}"
|
id="${id#/dev/}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -242,14 +256,14 @@ resolve_data_volume() {
|
|||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
info "Not mounted — mounting..."
|
info "Not mounted — mounting..."
|
||||||
diskutil mount "$data_dev" 2>/dev/null || true
|
diskutil mount "$data_dev" >&2 || true
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
|
||||||
warn "FileVault-locked — need to unlock."
|
warn "FileVault-locked — need to unlock."
|
||||||
echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2
|
echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2
|
||||||
diskutil apfs unlockVolume "$data_dev" 2>/dev/null \
|
diskutil apfs unlockVolume "$data_dev" >&2 \
|
||||||
|| error_exit "Failed to unlock. Re-run with valid credentials."
|
|| error_exit "Failed to unlock. Re-run with valid credentials."
|
||||||
mount_pt=$(_mount_point)
|
mount_pt=$(_mount_point)
|
||||||
fi
|
fi
|
||||||
@@ -279,9 +293,9 @@ detect_system_volume() {
|
|||||||
resolve_target_volumes() {
|
resolve_target_volumes() {
|
||||||
local base_name data_name
|
local base_name data_name
|
||||||
|
|
||||||
read -p "Enter target system volume name (default 'Macintosh HD'): " base_name
|
read -r -p "Enter target system volume name (default 'Macintosh HD'): " base_name
|
||||||
base_name="${base_name:=Macintosh HD}"
|
base_name="${base_name:=Macintosh HD}"
|
||||||
read -p "Enter target data volume name (default 'Macintosh HD - Data'): " data_name
|
read -r -p "Enter target data volume name (default 'Macintosh HD - Data'): " data_name
|
||||||
data_name="${data_name:=Macintosh HD - Data}"
|
data_name="${data_name:=Macintosh HD - Data}"
|
||||||
|
|
||||||
local sys_path="/Volumes/$base_name"
|
local sys_path="/Volumes/$base_name"
|
||||||
@@ -315,7 +329,7 @@ prompt_username() {
|
|||||||
local var_name="$1"
|
local var_name="$1"
|
||||||
local value
|
local value
|
||||||
while true; do
|
while true; do
|
||||||
read -p "Username (default 'Apple'): " value
|
read -r -p "Username (default 'Apple'): " value
|
||||||
value="${value:=Apple}"
|
value="${value:=Apple}"
|
||||||
if msg=$(validate_username "$value"); then
|
if msg=$(validate_username "$value"); then
|
||||||
eval "$var_name=\"$value\""
|
eval "$var_name=\"$value\""
|
||||||
@@ -330,7 +344,7 @@ prompt_password() {
|
|||||||
local var_name="$1"
|
local var_name="$1"
|
||||||
local value
|
local value
|
||||||
while true; do
|
while true; do
|
||||||
read -p "Password (default '1234'): " value
|
read -r -p "Password (default '1234'): " value
|
||||||
value="${value:=1234}"
|
value="${value:=1234}"
|
||||||
if msg=$(validate_password "$value"); then
|
if msg=$(validate_password "$value"); then
|
||||||
eval "$var_name=\"$value\""
|
eval "$var_name=\"$value\""
|
||||||
@@ -409,7 +423,7 @@ add_to_filevault() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
PB=/usr/libexec/PlistBuddy
|
PB="${PB:-/usr/libexec/PlistBuddy}"
|
||||||
|
|
||||||
suppress_enrollment() {
|
suppress_enrollment() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
@@ -555,6 +569,7 @@ full_bypass_mode() {
|
|||||||
echo ""
|
echo ""
|
||||||
step "Creating temporary admin account"
|
step "Creating temporary admin account"
|
||||||
|
|
||||||
|
local realName
|
||||||
prompt_default realName "Full name" "Apple"
|
prompt_default realName "Full name" "Apple"
|
||||||
|
|
||||||
local username
|
local username
|
||||||
@@ -729,7 +744,8 @@ check_mdm_status() {
|
|||||||
else
|
else
|
||||||
echo -e " ${YEL}(none)${NC}"
|
echo -e " ${YEL}(none)${NC}"
|
||||||
fi
|
fi
|
||||||
local count; count=$(echo "$matches" | grep -c . 2>/dev/null || echo 0)
|
local count; count=$(echo "$matches" | grep -c . 2>/dev/null || true)
|
||||||
|
count="${count:-0}"
|
||||||
echo -e " ${CYAN}Total: $count of 13 expected domains blocked${NC}"
|
echo -e " ${CYAN}Total: $count of 13 expected domains blocked${NC}"
|
||||||
else
|
else
|
||||||
echo -e " ${YEL}(hosts not found)${NC}"
|
echo -e " ${YEL}(hosts not found)${NC}"
|
||||||
@@ -771,6 +787,16 @@ check_mdm_status() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_mdm_agent_names() {
|
||||||
|
local agent
|
||||||
|
for agent in "$1/"*; do
|
||||||
|
[ -f "$agent" ] || continue
|
||||||
|
if printf '%s\n' "${agent##*/}" | grep -qiE 'mdm|enrollment|managed'; then
|
||||||
|
printf '%s\n' "${agent##*/}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
deep_status() {
|
deep_status() {
|
||||||
if [ "${1:-}" = "--json" ]; then
|
if [ "${1:-}" = "--json" ]; then
|
||||||
deep_status_json
|
deep_status_json
|
||||||
@@ -781,10 +807,11 @@ deep_status() {
|
|||||||
step "Installed Configuration Profiles"
|
step "Installed Configuration Profiles"
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
local profile_count
|
local profile_count
|
||||||
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
profile_count="${profile_count:-0}"
|
||||||
if [ "$profile_count" -gt 0 ]; then
|
if [ "$profile_count" -gt 0 ]; then
|
||||||
warn "$profile_count profile(s) installed:"
|
warn "$profile_count profile(s) installed:"
|
||||||
sudo profiles -C -output=xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" | sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
sudo profiles -C -output stdout-xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" | sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
||||||
else
|
else
|
||||||
info "No configuration profiles installed"
|
info "No configuration profiles installed"
|
||||||
fi
|
fi
|
||||||
@@ -819,10 +846,10 @@ deep_status() {
|
|||||||
for home in /Users/*/; do
|
for home in /Users/*/; do
|
||||||
[ -d "$home/Library/LaunchAgents" ] || continue
|
[ -d "$home/Library/LaunchAgents" ] || continue
|
||||||
local user_agents
|
local user_agents
|
||||||
user_agents=$(ls "$home/Library/LaunchAgents/" 2>/dev/null | grep -iE "mdm|enrollment|managed" || true)
|
user_agents=$(_mdm_agent_names "$home/Library/LaunchAgents")
|
||||||
if [ -n "$user_agents" ]; then
|
if [ -n "$user_agents" ]; then
|
||||||
echo -e " ${YEL}$(basename "$home"):${NC}"
|
echo -e " ${YEL}$(basename "$home"):${NC}"
|
||||||
echo "$user_agents" | sed 's/^/ /'
|
while IFS= read -r agent; do printf ' %s\n' "$agent"; done <<< "$user_agents"
|
||||||
found=$((found + 1))
|
found=$((found + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -831,9 +858,9 @@ deep_status() {
|
|||||||
|
|
||||||
step "MDM LaunchDaemons (System)"
|
step "MDM LaunchDaemons (System)"
|
||||||
local sys_agents
|
local sys_agents
|
||||||
sys_agents=$(ls /Library/LaunchDaemons/ 2>/dev/null | grep -iE "mdm|enrollment|managed" || true)
|
sys_agents=$(_mdm_agent_names /Library/LaunchDaemons)
|
||||||
if [ -n "$sys_agents" ]; then
|
if [ -n "$sys_agents" ]; then
|
||||||
echo "$sys_agents" | sed 's/^/ /'
|
while IFS= read -r agent; do printf ' %s\n' "$agent"; done <<< "$sys_agents"
|
||||||
else
|
else
|
||||||
info "No MDM LaunchDaemons found"
|
info "No MDM LaunchDaemons found"
|
||||||
fi
|
fi
|
||||||
@@ -841,9 +868,9 @@ deep_status() {
|
|||||||
|
|
||||||
step "Running MDM Processes"
|
step "Running MDM Processes"
|
||||||
local procs
|
local procs
|
||||||
procs=$(ps aux 2>/dev/null | grep -iE "mdm|managedclient|activation" | grep -v grep || true)
|
procs=$(pgrep -il "mdm|managedclient|activation" 2>/dev/null || true)
|
||||||
if [ -n "$procs" ]; then
|
if [ -n "$procs" ]; then
|
||||||
echo "$procs" | awk '{print " " $11 " (PID " $2 ")"}'
|
echo "$procs" | awk '{print " " $2 " (PID " $1 ")"}'
|
||||||
else
|
else
|
||||||
info "No MDM processes running"
|
info "No MDM processes running"
|
||||||
fi
|
fi
|
||||||
@@ -865,8 +892,12 @@ deep_status() {
|
|||||||
|
|
||||||
step "Overall Assessment"
|
step "Overall Assessment"
|
||||||
local risk="LOW"
|
local risk="LOW"
|
||||||
[ "$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)" -gt 0 ] && risk="MEDIUM"
|
local cfg="/private/var/db/ConfigurationProfiles/Settings"
|
||||||
ps aux 2>/dev/null | grep -qiE "mdm|managedclient" && risk="HIGH"
|
local installed
|
||||||
|
installed=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
installed="${installed:-0}"
|
||||||
|
[ "$installed" -gt 0 ] && risk="MEDIUM"
|
||||||
|
pgrep -i "mdm|managedclient" >/dev/null 2>&1 && risk="HIGH"
|
||||||
[ -f "$cfg/.cloudConfigRecordFound" ] && risk="CRITICAL"
|
[ -f "$cfg/.cloudConfigRecordFound" ] && risk="CRITICAL"
|
||||||
|
|
||||||
case "$risk" in
|
case "$risk" in
|
||||||
@@ -885,7 +916,8 @@ deep_status_json() {
|
|||||||
|
|
||||||
local profile_count=0
|
local profile_count=0
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
profile_count="${profile_count:-0}"
|
||||||
fi
|
fi
|
||||||
json="${json} \"profile_count\": $profile_count,\n"
|
json="${json} \"profile_count\": $profile_count,\n"
|
||||||
|
|
||||||
@@ -903,9 +935,7 @@ deep_status_json() {
|
|||||||
json="${json} \"mdm_certificates\": $mdm_certs,\n"
|
json="${json} \"mdm_certificates\": $mdm_certs,\n"
|
||||||
|
|
||||||
local running_procs=0
|
local running_procs=0
|
||||||
running_procs=$(ps aux 2>/dev/null | grep -ciE "mdm|managedclient|activation" || true)
|
running_procs=$(pgrep -il "mdm|managedclient|activation" 2>/dev/null | awk 'END {print NR}' || true)
|
||||||
running_procs=$((running_procs - 1))
|
|
||||||
[ "$running_procs" -lt 0 ] && running_procs=0
|
|
||||||
json="${json} \"running_mdm_processes\": $running_procs,\n"
|
json="${json} \"running_mdm_processes\": $running_procs,\n"
|
||||||
|
|
||||||
local risk="LOW"
|
local risk="LOW"
|
||||||
@@ -918,6 +948,14 @@ deep_status_json() {
|
|||||||
echo -e "$json"
|
echo -e "$json"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_launchd_script_path() {
|
||||||
|
local script_path="${SCRIPT_PATH:-}"
|
||||||
|
if [ -z "$script_path" ]; then
|
||||||
|
script_path="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
|
||||||
|
fi
|
||||||
|
printf '%s' "$script_path" | sed 's/&/\&/g; s/</\</g; s/>/\>/g'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
heal_suppress() {
|
heal_suppress() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
@@ -990,11 +1028,7 @@ install_persist_launchdaemon() {
|
|||||||
root="$(_persist_mount_root "$data_mount")"
|
root="$(_persist_mount_root "$data_mount")"
|
||||||
|
|
||||||
local unleash_src
|
local unleash_src
|
||||||
if [ -n "$SCRIPT_DIR" ]; then
|
unleash_src=$(_launchd_script_path)
|
||||||
unleash_src="$SCRIPT_DIR/unleash"
|
|
||||||
else
|
|
||||||
unleash_src="$(cd "$(dirname "$0")" && pwd)/unleash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
step "Installing LaunchDaemon for boot-time persistence..."
|
step "Installing LaunchDaemon for boot-time persistence..."
|
||||||
|
|
||||||
@@ -1013,8 +1047,8 @@ install_persist_launchdaemon() {
|
|||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/bin/bash</string>
|
<string>/bin/bash</string>
|
||||||
<string>-c</string>
|
<string>${unleash_src}</string>
|
||||||
<string>${unleash_src} heal</string>
|
<string>heal</string>
|
||||||
</array>
|
</array>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
@@ -1037,9 +1071,11 @@ install_persist_launchdaemon() {
|
|||||||
|
|
||||||
step "Loading LaunchDaemon..."
|
step "Loading LaunchDaemon..."
|
||||||
if command -v launchctl &>/dev/null; then
|
if command -v launchctl &>/dev/null; then
|
||||||
launchctl load "$plist_path" 2>/dev/null \
|
if launchctl load "$plist_path" 2>/dev/null; then
|
||||||
&& success "LaunchDaemon loaded (will run on next boot)" \
|
success "LaunchDaemon loaded (will run on next boot)"
|
||||||
|| info "LaunchDaemon will load on next boot"
|
else
|
||||||
|
info "LaunchDaemon will load on next boot"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
info "launchctl not available (expected in Recovery) — will load on next boot"
|
info "launchctl not available (expected in Recovery) — will load on next boot"
|
||||||
fi
|
fi
|
||||||
@@ -1072,7 +1108,8 @@ pf_backup_anchor() {
|
|||||||
local root="$1"
|
local root="$1"
|
||||||
local anchor_file="${root}${FIREWALL_ANCHOR_DIR}/${FIREWALL_ANCHOR}"
|
local anchor_file="${root}${FIREWALL_ANCHOR_DIR}/${FIREWALL_ANCHOR}"
|
||||||
[ ! -f "$anchor_file" ] && return 0
|
[ ! -f "$anchor_file" ] && return 0
|
||||||
local backup="${anchor_file}.backup.$(date +%s)"
|
local backup
|
||||||
|
backup="${anchor_file}.backup.$(date +%s)"
|
||||||
cp "$anchor_file" "$backup" && info "Backed up pf anchor: $backup"
|
cp "$anchor_file" "$backup" && info "Backed up pf anchor: $backup"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1080,7 +1117,8 @@ pf_backup_conf() {
|
|||||||
local root="$1"
|
local root="$1"
|
||||||
local pf_conf="${root}${FIREWALL_CONF}"
|
local pf_conf="${root}${FIREWALL_CONF}"
|
||||||
[ ! -f "$pf_conf" ] && return 0
|
[ ! -f "$pf_conf" ] && return 0
|
||||||
local backup="${pf_conf}.backup.$(date +%s)"
|
local backup
|
||||||
|
backup="${pf_conf}.backup.$(date +%s)"
|
||||||
cp "$pf_conf" "$backup" && info "Backed up pf.conf: $backup"
|
cp "$pf_conf" "$backup" && info "Backed up pf.conf: $backup"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1116,10 +1154,7 @@ ANCHOR
|
|||||||
if grep -q "com.unleash" "$pf_conf" 2>/dev/null; then
|
if grep -q "com.unleash" "$pf_conf" 2>/dev/null; then
|
||||||
info "pf.conf already has Unleash anchor"
|
info "pf.conf already has Unleash anchor"
|
||||||
else
|
else
|
||||||
echo "" >> "$pf_conf"
|
printf '\n%s\n%s\n%s\n' "# Added by unleash — MDM block" "$anchor_line" "$load_line" >> "$pf_conf"
|
||||||
echo "# Added by unleash — MDM block" >> "$pf_conf"
|
|
||||||
echo "$anchor_line" >> "$pf_conf"
|
|
||||||
echo "$load_line" >> "$pf_conf"
|
|
||||||
success "pf.conf updated"
|
success "pf.conf updated"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -1144,8 +1179,11 @@ ANCHOR
|
|||||||
|
|
||||||
step "Loading pf rules..."
|
step "Loading pf rules..."
|
||||||
if command -v pfctl &>/dev/null; then
|
if command -v pfctl &>/dev/null; then
|
||||||
pfctl -e -f "$pf_conf" 2>/dev/null && success "pf enabled and rules loaded" \
|
if pfctl -e -f "$pf_conf" 2>/dev/null; then
|
||||||
|| warn "pfctl failed — try: sudo pfctl -e -f $pf_conf"
|
success "pf enabled and rules loaded"
|
||||||
|
else
|
||||||
|
warn "pfctl failed — try: sudo pfctl -e -f $pf_conf"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
warn "pfctl not available"
|
warn "pfctl not available"
|
||||||
fi
|
fi
|
||||||
@@ -1170,8 +1208,14 @@ remove_pf_mdm_block() {
|
|||||||
|
|
||||||
local pf_conf="${root}${FIREWALL_CONF}"
|
local pf_conf="${root}${FIREWALL_CONF}"
|
||||||
if [ -f "$pf_conf" ]; then
|
if [ -f "$pf_conf" ]; then
|
||||||
sed -i '' '/# Added by unleash/d' "$pf_conf" 2>/dev/null || true
|
local tmp_conf
|
||||||
sed -i '' '/com\.unleash/d' "$pf_conf" 2>/dev/null || true
|
tmp_conf=$(mktemp "${pf_conf}.XXXXXX") || return 1
|
||||||
|
if ! cp -p "$pf_conf" "$tmp_conf" \
|
||||||
|
|| ! sed '/# Added by unleash/d; /com\.unleash/d' "$pf_conf" > "$tmp_conf" \
|
||||||
|
|| ! mv "$tmp_conf" "$pf_conf"; then
|
||||||
|
rm -f "$tmp_conf"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
success "pf.conf cleaned"
|
success "pf.conf cleaned"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1189,9 +1233,11 @@ pf_status() {
|
|||||||
if command -v pfctl &>/dev/null; then
|
if command -v pfctl &>/dev/null; then
|
||||||
pfctl -si 2>/dev/null | grep -E "Status|Enabled" || echo " pf not enabled"
|
pfctl -si 2>/dev/null | grep -E "Status|Enabled" || echo " pf not enabled"
|
||||||
echo ""
|
echo ""
|
||||||
pfctl -a "$FIREWALL_ANCHOR" -s rules 2>/dev/null \
|
if pfctl -a "$FIREWALL_ANCHOR" -s rules 2>/dev/null; then
|
||||||
&& info "Unleash MDM anchor rules:" \
|
info "Unleash MDM anchor rules:"
|
||||||
|| info "No Unleash MDM anchor loaded"
|
else
|
||||||
|
info "No Unleash MDM anchor loaded"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
warn "pfctl not available"
|
warn "pfctl not available"
|
||||||
fi
|
fi
|
||||||
@@ -1213,8 +1259,11 @@ harden_live_os() {
|
|||||||
local installed
|
local installed
|
||||||
installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
if [ "$installed" -gt 0 ]; then
|
if [ "$installed" -gt 0 ]; then
|
||||||
sudo profiles -D -F 2>/dev/null && success "Forced profile removal" \
|
if sudo profiles -D -F 2>/dev/null; then
|
||||||
|| warn "Profile removal failed"
|
success "Forced profile removal"
|
||||||
|
else
|
||||||
|
warn "Profile removal failed"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
info "No installed profiles to remove"
|
info "No installed profiles to remove"
|
||||||
fi
|
fi
|
||||||
@@ -1223,8 +1272,8 @@ harden_live_os() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
step "Cleaning user LaunchAgents..."
|
step "Cleaning user LaunchAgents..."
|
||||||
local home
|
local home users_root="${1:-}/Users"
|
||||||
for home in /Users/*/; do
|
for home in "$users_root/"*/; do
|
||||||
[ -d "$home/Library/LaunchAgents" ] || continue
|
[ -d "$home/Library/LaunchAgents" ] || continue
|
||||||
local cleaned=0
|
local cleaned=0
|
||||||
for agent in "$home/Library/LaunchAgents/"*; do
|
for agent in "$home/Library/LaunchAgents/"*; do
|
||||||
@@ -1234,8 +1283,11 @@ harden_live_os() {
|
|||||||
cleaned=$((cleaned + 1))
|
cleaned=$((cleaned + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
[ "$cleaned" -gt 0 ] && success "$(basename "$home"): removed $cleaned agent(s)" \
|
if [ "$cleaned" -gt 0 ]; then
|
||||||
|| info "$(basename "$home"): clean"
|
success "$(basename "$home"): removed $cleaned agent(s)"
|
||||||
|
else
|
||||||
|
info "$(basename "$home"): clean"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
step "Flushing DNS cache..."
|
step "Flushing DNS cache..."
|
||||||
@@ -1269,9 +1321,11 @@ harden_live_os() {
|
|||||||
|
|
||||||
step "Disabling iCloud Private Relay (DoH source)..."
|
step "Disabling iCloud Private Relay (DoH source)..."
|
||||||
if command -v defaults &>/dev/null; then
|
if command -v defaults &>/dev/null; then
|
||||||
sudo defaults write /Library/Preferences/com.apple.networkextensions.plist PrivateRelayEnabled -bool false 2>/dev/null \
|
if sudo defaults write /Library/Preferences/com.apple.networkextensions.plist PrivateRelayEnabled -bool false 2>/dev/null; then
|
||||||
&& success "Private Relay disabled" \
|
success "Private Relay disabled"
|
||||||
|| info "Private Relay not configurable (expected on some configs)"
|
else
|
||||||
|
info "Private Relay not configurable (expected on some configs)"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@@ -1295,7 +1349,7 @@ harden_status() {
|
|||||||
launchctl list 2>/dev/null | grep -iE "mdm|managed|enrollment|activation" || info "None loaded"
|
launchctl list 2>/dev/null | grep -iE "mdm|managed|enrollment|activation" || info "None loaded"
|
||||||
|
|
||||||
step "Running MDM processes..."
|
step "Running MDM processes..."
|
||||||
ps aux 2>/dev/null | grep -iE "mdm|managedclient|activation" | grep -v grep || info "None running"
|
pgrep -il "mdm|managedclient|activation" 2>/dev/null || info "None running"
|
||||||
}
|
}
|
||||||
|
|
||||||
MDM_BLOCKLIST="mdmenrollment.apple.com deviceenrollment.apple.com iprofiles.apple.com"
|
MDM_BLOCKLIST="mdmenrollment.apple.com deviceenrollment.apple.com iprofiles.apple.com"
|
||||||
@@ -1311,7 +1365,7 @@ install_selective_block() {
|
|||||||
local anchor_file="${anchor_dir}/com.unleash.selective"
|
local anchor_file="${anchor_dir}/com.unleash.selective"
|
||||||
mkdir -p "$anchor_dir"
|
mkdir -p "$anchor_dir"
|
||||||
|
|
||||||
> "$anchor_file"
|
: > "$anchor_file"
|
||||||
|
|
||||||
for d in $MDM_BLOCKLIST; do
|
for d in $MDM_BLOCKLIST; do
|
||||||
for ip in $(host -t a "$d" 2>/dev/null | awk '/has address/{print $NF}'); do
|
for ip in $(host -t a "$d" 2>/dev/null | awk '/has address/{print $NF}'); do
|
||||||
@@ -1333,10 +1387,7 @@ install_selective_block() {
|
|||||||
if grep -q "com.unleash.selective" "$pf_conf" 2>/dev/null; then
|
if grep -q "com.unleash.selective" "$pf_conf" 2>/dev/null; then
|
||||||
info "pf.conf already has selective anchor"
|
info "pf.conf already has selective anchor"
|
||||||
else
|
else
|
||||||
echo "" >> "$pf_conf"
|
printf '\n%s\n%s\n%s\n' "# Added by unleash — selective MDM block (iCloud-safe)" "$anchor_line" "$load_line" >> "$pf_conf"
|
||||||
echo "# Added by unleash — selective MDM block (iCloud-safe)" >> "$pf_conf"
|
|
||||||
echo "$anchor_line" >> "$pf_conf"
|
|
||||||
echo "$load_line" >> "$pf_conf"
|
|
||||||
success "pf.conf updated with selective rules"
|
success "pf.conf updated with selective rules"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -1356,8 +1407,11 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v pfctl &>/dev/null; then
|
if command -v pfctl &>/dev/null; then
|
||||||
pfctl -e -f "$pf_conf" 2>/dev/null && success "pf rules loaded (iCloud should work)" \
|
if pfctl -e -f "$pf_conf" 2>/dev/null; then
|
||||||
|| warn "pfctl failed"
|
success "pf rules loaded (iCloud should work)"
|
||||||
|
else
|
||||||
|
warn "pfctl failed"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1504,11 +1558,7 @@ install_monitor_launchdaemon() {
|
|||||||
[ -n "$data_mount" ] && root="$data_mount"
|
[ -n "$data_mount" ] && root="$data_mount"
|
||||||
|
|
||||||
local unleash_src
|
local unleash_src
|
||||||
if [ -n "$SCRIPT_DIR" ]; then
|
unleash_src=$(_launchd_script_path)
|
||||||
unleash_src="$SCRIPT_DIR/unleash"
|
|
||||||
else
|
|
||||||
unleash_src="$(cd "$(dirname "$0")" && pwd)/unleash"
|
|
||||||
fi
|
|
||||||
|
|
||||||
step "Installing monitor LaunchDaemon..."
|
step "Installing monitor LaunchDaemon..."
|
||||||
|
|
||||||
@@ -1526,8 +1576,8 @@ install_monitor_launchdaemon() {
|
|||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/bin/bash</string>
|
<string>/bin/bash</string>
|
||||||
<string>-c</string>
|
<string>${unleash_src}</string>
|
||||||
<string>${unleash_src} monitor</string>
|
<string>monitor</string>
|
||||||
</array>
|
</array>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
@@ -1547,9 +1597,11 @@ PLIST
|
|||||||
success "Monitor LaunchDaemon: $plist_path"
|
success "Monitor LaunchDaemon: $plist_path"
|
||||||
|
|
||||||
if command -v launchctl &>/dev/null; then
|
if command -v launchctl &>/dev/null; then
|
||||||
launchctl load "$plist_path" 2>/dev/null \
|
if launchctl load "$plist_path" 2>/dev/null; then
|
||||||
&& success "Monitor loaded (starts at boot)" \
|
success "Monitor loaded (starts at boot)"
|
||||||
|| info "Will load on next boot"
|
else
|
||||||
|
info "Will load on next boot"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1670,7 +1722,7 @@ monitor_mdm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop_monitor() {
|
stop_monitor() {
|
||||||
local pidfile="/tmp/unleash-monitor.pid"
|
local pidfile="${1:-/tmp/unleash-monitor.pid}"
|
||||||
if [ -f "$pidfile" ]; then
|
if [ -f "$pidfile" ]; then
|
||||||
local pid
|
local pid
|
||||||
pid=$(cat "$pidfile")
|
pid=$(cat "$pidfile")
|
||||||
@@ -1687,7 +1739,7 @@ stop_monitor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
monitor_status() {
|
monitor_status() {
|
||||||
local pidfile="/tmp/unleash-monitor.pid"
|
local pidfile="${1:-/tmp/unleash-monitor.pid}"
|
||||||
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
||||||
echo -e "${GRN}Monitor running (PID $(cat "$pidfile"))${NC}"
|
echo -e "${GRN}Monitor running (PID $(cat "$pidfile"))${NC}"
|
||||||
tail -5 /var/log/unleash-monitor.log 2>/dev/null || echo " (no log entries yet)"
|
tail -5 /var/log/unleash-monitor.log 2>/dev/null || echo " (no log entries yet)"
|
||||||
@@ -1699,7 +1751,8 @@ monitor_status() {
|
|||||||
show_history() {
|
show_history() {
|
||||||
header "Unleash Event History"
|
header "Unleash Event History"
|
||||||
|
|
||||||
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
local log_dir="${1:-/var/log}"
|
||||||
|
local logs=("$log_dir/unleash-monitor.log" "$log_dir/unleash-heal.log" "$log_dir/unleash-monitor.err")
|
||||||
local found=false
|
local found=false
|
||||||
|
|
||||||
for logfile in "${logs[@]}"; do
|
for logfile in "${logs[@]}"; do
|
||||||
@@ -1732,7 +1785,8 @@ show_history() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear_history() {
|
clear_history() {
|
||||||
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
local log_dir="${1:-/var/log}"
|
||||||
|
local logs=("$log_dir/unleash-monitor.log" "$log_dir/unleash-heal.log" "$log_dir/unleash-monitor.err")
|
||||||
for logfile in "${logs[@]}"; do
|
for logfile in "${logs[@]}"; do
|
||||||
if [ -f "$logfile" ]; then
|
if [ -f "$logfile" ]; then
|
||||||
: > "$logfile"
|
: > "$logfile"
|
||||||
@@ -1925,7 +1979,7 @@ do_self_update() {
|
|||||||
fi
|
fi
|
||||||
end_ok; echo " Latest: v$latest_tag"
|
end_ok; echo " Latest: v$latest_tag"
|
||||||
|
|
||||||
if [ "v$latest_tag" = "$(echo "v$VERSION")" ]; then
|
if [ "v$latest_tag" = "v$VERSION" ]; then
|
||||||
success "Already up to date (v$VERSION)"
|
success "Already up to date (v$VERSION)"
|
||||||
rm -rf "$tmp_dir"
|
rm -rf "$tmp_dir"
|
||||||
return 0
|
return 0
|
||||||
@@ -2108,10 +2162,11 @@ generate_report() {
|
|||||||
step "Installed Profiles"
|
step "Installed Profiles"
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
local count
|
local count
|
||||||
count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
count="${count:-0}"
|
||||||
if [ "$count" -gt 0 ]; then
|
if [ "$count" -gt 0 ]; then
|
||||||
echo " $count profile(s) installed"
|
echo " $count profile(s) installed"
|
||||||
sudo profiles -C -output=xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" \
|
sudo profiles -C -output stdout-xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" \
|
||||||
| sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
| sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
||||||
else
|
else
|
||||||
echo " No profiles installed"
|
echo " No profiles installed"
|
||||||
@@ -2156,7 +2211,8 @@ generate_report() {
|
|||||||
step "Hosts Block"
|
step "Hosts Block"
|
||||||
if grep -q "iprofiles.apple.com" /private/etc/hosts 2>/dev/null; then
|
if grep -q "iprofiles.apple.com" /private/etc/hosts 2>/dev/null; then
|
||||||
local blocked
|
local blocked
|
||||||
blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || echo 0)
|
blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || true)
|
||||||
|
blocked="${blocked:-0}"
|
||||||
echo " $blocked domain(s) blocked in /etc/hosts"
|
echo " $blocked domain(s) blocked in /etc/hosts"
|
||||||
else
|
else
|
||||||
echo " No block entries found"
|
echo " No block entries found"
|
||||||
@@ -2165,9 +2221,9 @@ generate_report() {
|
|||||||
|
|
||||||
step "Running MDM Processes"
|
step "Running MDM Processes"
|
||||||
local procs
|
local procs
|
||||||
procs=$(ps aux 2>/dev/null | grep -iE "mdm|managedclient|activation" | grep -v grep || true)
|
procs=$(pgrep -il "mdm|managedclient|activation" 2>/dev/null || true)
|
||||||
if [ -n "$procs" ]; then
|
if [ -n "$procs" ]; then
|
||||||
echo "$procs" | awk '{print " " $11 " (PID " $2 ")"}'
|
echo "$procs" | awk '{print " " $2 " (PID " $1 ")"}'
|
||||||
else
|
else
|
||||||
echo " None"
|
echo " None"
|
||||||
fi
|
fi
|
||||||
@@ -2195,7 +2251,8 @@ generate_report_json() {
|
|||||||
|
|
||||||
local profile_count=0
|
local profile_count=0
|
||||||
if command -v profiles &>/dev/null; then
|
if command -v profiles &>/dev/null; then
|
||||||
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||||
|
profile_count="${profile_count:-0}"
|
||||||
fi
|
fi
|
||||||
report="${report} \"installed_profiles\": $profile_count,\n"
|
report="${report} \"installed_profiles\": $profile_count,\n"
|
||||||
|
|
||||||
@@ -2225,7 +2282,8 @@ generate_report_json() {
|
|||||||
report="${report} },\n"
|
report="${report} },\n"
|
||||||
|
|
||||||
local hosts_blocked=0
|
local hosts_blocked=0
|
||||||
hosts_blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || echo 0)
|
hosts_blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || true)
|
||||||
|
hosts_blocked="${hosts_blocked:-0}"
|
||||||
report="${report} \"hosts_blocked\": $hosts_blocked\n"
|
report="${report} \"hosts_blocked\": $hosts_blocked\n"
|
||||||
|
|
||||||
report="${report}}"
|
report="${report}}"
|
||||||
@@ -2233,6 +2291,14 @@ generate_report_json() {
|
|||||||
echo -e "$report"
|
echo -e "$report"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_has_matching_path() {
|
||||||
|
local path
|
||||||
|
for path in "$@"; do
|
||||||
|
[ ! -e "$path" ] || return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
detect_configurator_enrollment() {
|
detect_configurator_enrollment() {
|
||||||
local data_mount="${1:-}"
|
local data_mount="${1:-}"
|
||||||
|
|
||||||
@@ -2315,8 +2381,13 @@ detect_migration_assistant() {
|
|||||||
|
|
||||||
local user_agents="$home/Library/LaunchAgents"
|
local user_agents="$home/Library/LaunchAgents"
|
||||||
if [ -d "$user_agents" ]; then
|
if [ -d "$user_agents" ]; then
|
||||||
local found
|
local found=0 agent
|
||||||
found=$(ls "$user_agents" 2>/dev/null | grep -ciE "mdm|enrollment|managed" || true)
|
for agent in "$user_agents/"*; do
|
||||||
|
[ -f "$agent" ] || continue
|
||||||
|
if printf '%s\n' "${agent##*/}" | grep -qiE 'mdm|enrollment|managed'; then
|
||||||
|
found=$((found + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
if [ "$found" -gt 0 ]; then
|
if [ "$found" -gt 0 ]; then
|
||||||
ma_indicators=$((ma_indicators + found))
|
ma_indicators=$((ma_indicators + found))
|
||||||
details="$details $user: $found MDM LaunchAgent(s)\n"
|
details="$details $user: $found MDM LaunchAgent(s)\n"
|
||||||
@@ -2325,9 +2396,7 @@ detect_migration_assistant() {
|
|||||||
|
|
||||||
local prefs="$home/Library/Preferences"
|
local prefs="$home/Library/Preferences"
|
||||||
if [ -d "$prefs" ]; then
|
if [ -d "$prefs" ]; then
|
||||||
local mdm_prefs
|
if _has_matching_path "$prefs"/com.apple.mdm* "$prefs"/com.apple.ManagedClient*; then
|
||||||
mdm_prefs=$(ls "$prefs"/com.apple.mdm* "$prefs"/com.apple.ManagedClient* 2>/dev/null | head -3 || true)
|
|
||||||
if [ -n "$mdm_prefs" ]; then
|
|
||||||
ma_indicators=$((ma_indicators + 1))
|
ma_indicators=$((ma_indicators + 1))
|
||||||
details="$details $user: MDM preference files\n"
|
details="$details $user: MDM preference files\n"
|
||||||
fi
|
fi
|
||||||
@@ -2341,16 +2410,12 @@ detect_migration_assistant() {
|
|||||||
|
|
||||||
local caches="$home/Library/Caches"
|
local caches="$home/Library/Caches"
|
||||||
if [ -d "$caches" ]; then
|
if [ -d "$caches" ]; then
|
||||||
local enrollment_cache
|
if _has_matching_path "$caches"/com.apple.enrollment*; then
|
||||||
enrollment_cache=$(ls "$caches"/com.apple.enrollment* 2>/dev/null | head -3 || true)
|
|
||||||
if [ -n "$enrollment_cache" ]; then
|
|
||||||
ma_indicators=$((ma_indicators + 1))
|
ma_indicators=$((ma_indicators + 1))
|
||||||
details="$details $user: enrollment cache files\n"
|
details="$details $user: enrollment cache files\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local mdmd_cache
|
if _has_matching_path "$caches"/com.apple.mdm*; then
|
||||||
mdmd_cache=$(ls "$caches"/com.apple.mdm* 2>/dev/null | head -3 || true)
|
|
||||||
if [ -n "$mdmd_cache" ]; then
|
|
||||||
ma_indicators=$((ma_indicators + 1))
|
ma_indicators=$((ma_indicators + 1))
|
||||||
details="$details $user: MDM cache files\n"
|
details="$details $user: MDM cache files\n"
|
||||||
fi
|
fi
|
||||||
@@ -2548,14 +2613,14 @@ RULES
|
|||||||
if grep -q "vpn-kill" "$pf_conf" 2>/dev/null; then
|
if grep -q "vpn-kill" "$pf_conf" 2>/dev/null; then
|
||||||
info "pf.conf already has VPN kill-switch anchor"
|
info "pf.conf already has VPN kill-switch anchor"
|
||||||
else
|
else
|
||||||
echo "" >> "$pf_conf"
|
printf '\n%s\n%s\n%s\n' "# Added by unleash — VPN kill-switch (prevents MDM leaks)" "$anchor_line" "$load_line" >> "$pf_conf"
|
||||||
echo "# Added by unleash — VPN kill-switch (prevents MDM leaks)" >> "$pf_conf"
|
|
||||||
echo "$anchor_line" >> "$pf_conf"
|
|
||||||
echo "$load_line" >> "$pf_conf"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pfctl -e -f "$pf_conf" 2>/dev/null && success "VPN kill-switch active" \
|
if pfctl -e -f "$pf_conf" 2>/dev/null; then
|
||||||
|| warn "pfctl failed"
|
success "VPN kill-switch active"
|
||||||
|
else
|
||||||
|
warn "pfctl failed"
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
info "What this does:"
|
info "What this does:"
|
||||||
@@ -2813,6 +2878,7 @@ cmd_dualboot() {
|
|||||||
echo ""
|
echo ""
|
||||||
step "Creating admin account on target"
|
step "Creating admin account on target"
|
||||||
|
|
||||||
|
local realName
|
||||||
prompt_default realName "Full name" "Apple"
|
prompt_default realName "Full name" "Apple"
|
||||||
local username
|
local username
|
||||||
prompt_username username
|
prompt_username username
|
||||||
@@ -2827,9 +2893,7 @@ cmd_dualboot() {
|
|||||||
begin "Blocking domains"
|
begin "Blocking domains"
|
||||||
local hosts_file="$data_path/private/etc/hosts"
|
local hosts_file="$data_path/private/etc/hosts"
|
||||||
[ -f "$hosts_file" ] || touch "$hosts_file"
|
[ -f "$hosts_file" ] || touch "$hosts_file"
|
||||||
echo "0.0.0.0 deviceenrollment.apple.com" >>"$hosts_file"
|
printf '%s\n' "0.0.0.0 deviceenrollment.apple.com" "0.0.0.0 mdmenrollment.apple.com" "0.0.0.0 iprofiles.apple.com" >>"$hosts_file"
|
||||||
echo "0.0.0.0 mdmenrollment.apple.com" >>"$hosts_file"
|
|
||||||
echo "0.0.0.0 iprofiles.apple.com" >>"$hosts_file"
|
|
||||||
end_ok
|
end_ok
|
||||||
|
|
||||||
begin "Resetting config profiles"
|
begin "Resetting config profiles"
|
||||||
@@ -2963,7 +3027,9 @@ cmd_monitor() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
install|uninstall) args+=("$1"); shift ;;
|
install|uninstall) args+=("$1"); shift ;;
|
||||||
--webhook) webhook="$2"; shift 2 ;;
|
--webhook)
|
||||||
|
if [ $# -lt 2 ] || [ -z "$2" ]; then error_exit "--webhook requires a URL"; fi
|
||||||
|
webhook="$2"; shift 2 ;;
|
||||||
*) args+=("$1"); shift ;;
|
*) args+=("$1"); shift ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -3123,22 +3189,29 @@ cmd_interactive_normal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_global_opts() {
|
parse_global_opts() {
|
||||||
local args=()
|
PARSED_ARGS=()
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--verbose) VERBOSE=true; shift ;;
|
--verbose) VERBOSE=true; shift ;;
|
||||||
--dry-run) DRY_RUN=true; shift ;;
|
--dry-run) DRY_RUN=true; shift ;;
|
||||||
--log-file) LOG_FILE="$2"; shift 2 ;;
|
--log-file)
|
||||||
*) args+=("$1"); shift ;;
|
if [ $# -lt 2 ] || [ -z "$2" ]; then error_exit "--log-file requires a path"; fi
|
||||||
|
case "$2" in --*) error_exit "--log-file requires a path" ;; esac
|
||||||
|
LOG_FILE="$2"; shift 2 ;;
|
||||||
|
--) shift; PARSED_ARGS+=("$@"); break ;;
|
||||||
|
*) PARSED_ARGS+=("$1"); shift ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
set -- "${args[@]}"
|
|
||||||
echo "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
load_config
|
load_config
|
||||||
eval "set -- $(parse_global_opts "$@")"
|
parse_global_opts "$@"
|
||||||
|
if [ "${PARSED_ARGS[0]+present}" = present ]; then
|
||||||
|
set -- "${PARSED_ARGS[@]}"
|
||||||
|
else
|
||||||
|
set --
|
||||||
|
fi
|
||||||
|
|
||||||
# Per-command help
|
# Per-command help
|
||||||
if [ "${2:-}" = "--help" ] || [ "${2:-}" = "-h" ]; then
|
if [ "${2:-}" = "--help" ] || [ "${2:-}" = "-h" ]; then
|
||||||
@@ -3155,7 +3228,7 @@ main() {
|
|||||||
firewall|fw) cmd_firewall ;;
|
firewall|fw) cmd_firewall ;;
|
||||||
firewall-off|fw-off) cmd_firewall_off ;;
|
firewall-off|fw-off) cmd_firewall_off ;;
|
||||||
harden) cmd_harden ;;
|
harden) cmd_harden ;;
|
||||||
audit) cmd_audit "$2" ;;
|
audit) cmd_audit "${2:-}" ;;
|
||||||
whitelist|wl) cmd_whitelist ;;
|
whitelist|wl) cmd_whitelist ;;
|
||||||
backup) cmd_backup ;;
|
backup) cmd_backup ;;
|
||||||
restore) cmd_restore ;;
|
restore) cmd_restore ;;
|
||||||
@@ -3173,13 +3246,13 @@ main() {
|
|||||||
version|-v|--version) cmd_version ;;
|
version|-v|--version) cmd_version ;;
|
||||||
init) cmd_init ;;
|
init) cmd_init ;;
|
||||||
suggest) cmd_suggest ;;
|
suggest) cmd_suggest ;;
|
||||||
remediate) cmd_remediate "$2" ;;
|
remediate) cmd_remediate "${2:-}" ;;
|
||||||
predict) cmd_predict "$2" ;;
|
predict) cmd_predict "${2:-}" ;;
|
||||||
telemetry) telemetry_opt_in "$2" ;;
|
telemetry) telemetry_opt_in "${2:-}" ;;
|
||||||
demo) run_demo ;;
|
demo) run_demo ;;
|
||||||
update) do_self_update ;;
|
update) do_self_update ;;
|
||||||
uninstall) do_uninstall ;;
|
uninstall) do_uninstall ;;
|
||||||
report) generate_report "$2" ;;
|
report) generate_report "${2:-}" ;;
|
||||||
config) cmd_config "$@" ;;
|
config) cmd_config "$@" ;;
|
||||||
vpn-kill) vpn_kill_install "$@" ;;
|
vpn-kill) vpn_kill_install "$@" ;;
|
||||||
vpn-kill-remove) vpn_kill_remove ;;
|
vpn-kill-remove) vpn_kill_remove ;;
|
||||||
@@ -3191,7 +3264,7 @@ main() {
|
|||||||
install_monitor_launchdaemon ""
|
install_monitor_launchdaemon ""
|
||||||
success "Reinstall complete"
|
success "Reinstall complete"
|
||||||
;;
|
;;
|
||||||
discord-bot) cmd_discord_bot_install "$2" "$3" ;;
|
discord-bot) cmd_discord_bot_install "${2:-}" "${3:-}" ;;
|
||||||
discord-bot-stop) cmd_discord_bot_stop ;;
|
discord-bot-stop) cmd_discord_bot_stop ;;
|
||||||
discord-bot-status) cmd_discord_bot_status ;;
|
discord-bot-status) cmd_discord_bot_status ;;
|
||||||
help|-h|--help) show_help; exit 0 ;;
|
help|-h|--help) show_help; exit 0 ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user