Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
152 lines (134 loc) · 5.48 KB
/
Copy pathinstall.sh
File metadata and controls
152 lines (134 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# MacUp installer — free & open source · https://github.com/CDAVIO/MacUp-Cleaner-CDAV.IO
# Copyright (c) 2026 cdav.io · GPL-3.0 · https://github.com/CDAVIO/MacUp-Cleaner-CDAV.IO
#
# curl -fsSL https://raw.githubusercontent.com/CDAVIO/MacUp-Cleaner-CDAV.IO/main/install.sh | bash
#
# What it does: copies MacUp into ~/.macup and adds the `macup` command.
# No admin password, nothing runs in the background, nothing is sent anywhere.
# Remove it any time with: macup uninstall
#
# Everything lives inside main(), called on the last line, so a partly
# downloaded script never runs.
set -euo pipefail
MACUP_REPO="CDAVIO/MacUp-Cleaner-CDAV.IO"
MACUP_BRANCH="${MACUP_BRANCH:-main}"
# Files and folders that make up an installed MacUp (nothing else is copied).
MACUP_PARTS="macup VERSION LICENSE THIRD_PARTY_NOTICES.md lib engine bin"
say() { printf ' %s\n' "$*"; }
ok() { printf ' \033[38;5;220m✓\033[0m %s\n' "$*"; }
fail() { printf ' \033[31m✕\033[0m %s\n' "$*" >&2; exit 1; }
# fetch_source DIR → prints the folder that holds the MacUp sources.
fetch_source() {
local tmp="$1" src
if [ -n "${MACUP_SOURCE:-}" ]; then
# Local folder (used by the tests and for offline installs).
[ -d "$MACUP_SOURCE" ] || fail "MACUP_SOURCE is not a folder: $MACUP_SOURCE"
printf '%s' "$MACUP_SOURCE"
return
fi
command -v curl >/dev/null 2>&1 || fail "curl is missing."
curl -fsSL --retry 2 --connect-timeout 15 \
"https://codeload.github.com/$MACUP_REPO/tar.gz/refs/heads/$MACUP_BRANCH" \
-o "$tmp/macup.tar.gz" || fail "Could not download MacUp from GitHub. Check your internet connection."
mkdir "$tmp/src"
tar -xzf "$tmp/macup.tar.gz" -C "$tmp/src" || fail "The download looks damaged. Please try again."
src="$(find "$tmp/src" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
[ -n "$src" ] || fail "The download looks empty. Please try again."
printf '%s' "$src"
}
# is_macup_dir DIR → true if DIR is an earlier MacUp install.
is_macup_dir() { [ -f "$1/macup" ] && [ -f "$1/VERSION" ] && [ -d "$1/lib" ]; }
# pick_bin_dir → a folder on PATH where we can add the `macup` link without a password.
pick_bin_dir() {
local d
if [ -n "${MACUP_BIN_DIR:-}" ]; then printf '%s' "$MACUP_BIN_DIR"; return; fi
for d in /opt/homebrew/bin /usr/local/bin; do
if [ -d "$d" ] && [ -w "$d" ]; then
case ":$PATH:" in *":$d:"*) printf '%s' "$d"; return ;; esac
fi
done
printf '%s' "$HOME/.local/bin"
}
# add_to_path DIR → adds DIR to PATH for new Terminal windows (only if missing).
add_to_path() {
local dir="$1" line rc shown
case ":$PATH:" in *":$dir:"*) return 1 ;; esac
case "$dir" in
"$HOME"/*) shown="\$HOME/${dir#"$HOME"/}" ;;
*) shown="$dir" ;;
esac
line="export PATH=\"$shown:\$PATH\" # added by MacUp"
# zsh reads ~/.zshrc in every interactive window (login or not), so new
# Terminal, VS Code and iTerm windows all find `macup`.
case "${SHELL:-/bin/zsh}" in
*/bash) set -- "$HOME/.bash_profile" ;;
*) set -- "$HOME/.zshrc" ;;
esac
for rc in "$@"; do
if ! grep -qs '# added by MacUp' "$rc"; then
printf '\n%s\n' "$line" >> "$rc"
fi
done
return 0
}
main() {
local dest="$HOME/.macup" tmp src part new old bin link version path_added=0
[ -n "${HOME:-}" ] && [ -d "$HOME" ] || fail "HOME is not set."
[ "$(uname -s)" = "Darwin" ] || fail "MacUp runs on macOS only."
local major; major="$(sw_vers -productVersion 2>/dev/null | cut -d. -f1)"
[ "${major:-0}" -ge 13 ] 2>/dev/null || fail "MacUp needs macOS 13 Ventura or newer."
[ "$(id -u)" -ne 0 ] || fail "Please run the installer without sudo."
printf '\n \033[1m✦ MacUp\033[0m installer\n\n'
if [ -e "$dest" ] && ! is_macup_dir "$dest"; then
fail "$dest already exists and is not MacUp — move it away, then run the installer again."
fi
tmp="$(mktemp -d "${TMPDIR:-/tmp}/macup-install.XXXXXX")"
# shellcheck disable=SC2064
trap "rm -rf '$tmp'" EXIT
say "Downloading MacUp…"
src="$(fetch_source "$tmp")"
for part in macup VERSION lib/ui.sh lib/lang/en.sh engine/clean_mac.sh; do
[ -e "$src/$part" ] || fail "The download is incomplete ($part missing). Please try again."
done
version="$(tr -d '[:space:]' < "$src/VERSION")"
# Build the new copy next to the old one, then swap them in one step.
new="$HOME/.macup.new.$$"
old="$HOME/.macup.old.$$"
rm -rf "$new" "$old"
mkdir "$new"
for part in $MACUP_PARTS; do
[ -e "$src/$part" ] && cp -R "$src/$part" "$new/"
done
chmod 755 "$new/macup" "$new/engine/clean_mac.sh"
[ -f "$new/bin/macup-pdf" ] && chmod 755 "$new/bin/macup-pdf"
[ -e "$dest" ] && mv "$dest" "$old"
mv "$new" "$dest"
rm -rf "$old"
ok "Installed MacUp $version in ~/.macup"
bin="$(pick_bin_dir)"
mkdir -p "$bin"
link="$bin/macup"
if [ -e "$link" ] || [ -L "$link" ]; then
if [ -L "$link" ] && [ "$(readlink "$link")" = "$dest/macup" ]; then
:
else
fail "$link already exists and is not MacUp — remove it, then run the installer again."
fi
else
ln -s "$dest/macup" "$link"
fi
ok "Added the macup command ($link)"
if add_to_path "$bin"; then path_added=1; fi
if [ "$path_added" = "1" ]; then
# This window started before the PATH change, so it can't find `macup` yet.
printf '\n Start it now (in this window):\n\n'
printf ' \033[38;5;220m%s\033[0m\n\n' "$link"
say "From the next Terminal window on, just type: macup"
else
printf '\n Start it with:\n\n'
printf ' \033[38;5;220mmacup\033[0m\n'
fi
printf '\n'
}
main "$@"