add seed timer & re-org
This commit is contained in:
parent
a3cd2f0fdd
commit
563ad690c2
9 changed files with 131 additions and 0 deletions
122
scripts/bash/toggle-ota.sh
Executable file
122
scripts/bash/toggle-ota.sh
Executable file
|
|
@ -0,0 +1,122 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# toggle_apple_updates.sh
|
||||
# Toggles Apple OTA update domains in /etc/hosts between blocked and unblocked.
|
||||
|
||||
HOSTS_FILE="/etc/hosts"
|
||||
|
||||
APPLE_DOMAINS=(
|
||||
"swscan.apple.com"
|
||||
"swdownload.apple.com"
|
||||
"swcdn.apple.com"
|
||||
"swdist.apple.com"
|
||||
"appldnld.apple.com"
|
||||
"mesu.apple.com"
|
||||
"gdmf.apple.com"
|
||||
)
|
||||
|
||||
BLOCK_IP="0.0.0.0"
|
||||
SECTION_COMMENT="# Block OTA"
|
||||
|
||||
# ── Colours ──────────────────────────────────────────────────────────────────
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
BOLD='\033[1m'
|
||||
RESET='\033[0m'
|
||||
|
||||
# ── Banner ────────────────────────────────────────────────────────────────────
|
||||
echo ""
|
||||
echo -e "${BOLD}+----------------------------------------------+${RESET}"
|
||||
echo -e "${BOLD}| Apple OTA Update Toggle Utility |${RESET}"
|
||||
echo -e "${BOLD}+----------------------------------------------+${RESET}"
|
||||
echo ""
|
||||
|
||||
# ── Root warning ──────────────────────────────────────────────────────────────
|
||||
echo -e "${YELLOW}⚠ WARNING: This script modifies ${HOSTS_FILE}.${RESET}"
|
||||
echo -e "${YELLOW} Root (administrator) privileges are required.${RESET}"
|
||||
echo ""
|
||||
|
||||
# ── Authenticate via sudo ─────────────────────────────────────────────────────
|
||||
echo -e "${CYAN}Please enter your password to continue:${RESET}"
|
||||
sudo -v 2>/dev/null
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo -e "${RED}✖ Authentication failed or was cancelled. Exiting.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# ── Detect current state ──────────────────────────────────────────────────────
|
||||
# Check if the first domain is currently blocked (present and uncommented)
|
||||
FIRST_DOMAIN="${APPLE_DOMAINS[0]}"
|
||||
if sudo grep -qE "^${BLOCK_IP}[[:space:]]+${FIRST_DOMAIN}" "${HOSTS_FILE}"; then
|
||||
CURRENT_STATE="blocked"
|
||||
else
|
||||
CURRENT_STATE="unblocked"
|
||||
fi
|
||||
|
||||
CURRENT_STATE_UPPER=$(echo "${CURRENT_STATE}" | tr '[:lower:]' '[:upper:]')
|
||||
echo -e " Current state: ${BOLD}Apple updates are ${CURRENT_STATE_UPPER}${RESET}"
|
||||
echo ""
|
||||
|
||||
# ── Toggle ────────────────────────────────────────────────────────────────────
|
||||
if [[ "${CURRENT_STATE}" == "blocked" ]]; then
|
||||
# ── UNBLOCK: comment out the block section ────────────────────────────────
|
||||
echo -e "${CYAN}→ Unblocking Apple update domains...${RESET}"
|
||||
|
||||
# Comment out the section header and each domain line
|
||||
sudo sed -i '.bak' "s|^${SECTION_COMMENT}$|#${SECTION_COMMENT}|g" "${HOSTS_FILE}"
|
||||
for domain in "${APPLE_DOMAINS[@]}"; do
|
||||
sudo sed -i '.bak' "s|^${BLOCK_IP}[[:space:]][[:space:]]*${domain}|# ${BLOCK_IP} ${domain}|g" "${HOSTS_FILE}"
|
||||
done
|
||||
|
||||
NEW_STATE="UNBLOCKED"
|
||||
STATE_COLOR="${GREEN}"
|
||||
STATE_MSG="Apple software updates are now ${GREEN}${BOLD}ENABLED${RESET}."
|
||||
STATE_DETAIL="Your Mac can reach Apple's update servers normally."
|
||||
|
||||
else
|
||||
# ── BLOCK: uncomment or add the block section ─────────────────────────────
|
||||
echo -e "${CYAN}→ Blocking Apple update domains...${RESET}"
|
||||
|
||||
# Uncomment lines that were previously commented out by this script
|
||||
sudo sed -i '.bak' "s|^#${SECTION_COMMENT}$|${SECTION_COMMENT}|g" "${HOSTS_FILE}"
|
||||
for domain in "${APPLE_DOMAINS[@]}"; do
|
||||
# If the commented-out version exists, uncomment it
|
||||
if sudo grep -qE "^#[[:space:]]*${BLOCK_IP}[[:space:]]+${domain}" "${HOSTS_FILE}"; then
|
||||
sudo sed -i '.bak' "s|^#[[:space:]]*${BLOCK_IP}[[:space:]][[:space:]]*${domain}|${BLOCK_IP} ${domain}|g" "${HOSTS_FILE}"
|
||||
# If the domain isn't present at all, append the block section
|
||||
elif ! sudo grep -qE "${domain}" "${HOSTS_FILE}"; then
|
||||
# Append section header if it doesn't exist
|
||||
if ! sudo grep -q "^${SECTION_COMMENT}$" "${HOSTS_FILE}"; then
|
||||
echo "" | sudo tee -a "${HOSTS_FILE}" > /dev/null
|
||||
echo "${SECTION_COMMENT}" | sudo tee -a "${HOSTS_FILE}" > /dev/null
|
||||
fi
|
||||
echo "${BLOCK_IP} ${domain}" | sudo tee -a "${HOSTS_FILE}" > /dev/null
|
||||
fi
|
||||
done
|
||||
|
||||
NEW_STATE="BLOCKED"
|
||||
STATE_COLOR="${RED}"
|
||||
STATE_MSG="Apple software updates are now ${RED}${BOLD}BLOCKED${RESET}."
|
||||
STATE_DETAIL="Your Mac cannot reach Apple's update servers."
|
||||
fi
|
||||
|
||||
# ── Result ────────────────────────────────────────────────────────────────────
|
||||
echo ""
|
||||
echo -e "${BOLD}+----------------------------------------------+${RESET}"
|
||||
printf "${BOLD}|${RESET} New state: ${STATE_COLOR}%-33s${RESET}${BOLD}|${RESET}\n" "${NEW_STATE}"
|
||||
echo -e "${BOLD}+----------------------------------------------+${RESET}"
|
||||
echo ""
|
||||
echo -e " ${STATE_MSG}"
|
||||
echo -e " ${STATE_DETAIL}"
|
||||
echo ""
|
||||
echo -e " Domains affected:"
|
||||
for domain in "${APPLE_DOMAINS[@]}"; do
|
||||
echo -e " ${STATE_COLOR}•${RESET} ${domain}"
|
||||
done
|
||||
echo ""
|
||||
echo -e " A backup of your previous hosts file was saved as:"
|
||||
echo -e " ${BOLD}${HOSTS_FILE}.bak${RESET}"
|
||||
echo ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue