Skip to content

Commit 31fc669

Browse files
committed
Add macOS US House software lifecycle script
1 parent 1a8b105 commit 31fc669

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
ACTION="${1:-status}"
5+
VENDOR="${2:-all}"
6+
PACKAGE="${3:-}"
7+
8+
command -v brew >/dev/null 2>&1 || {
9+
echo "ERROR: Homebrew is required. Install it from https://brew.sh/" >&2
10+
exit 1
11+
}
12+
13+
microsoft=(
14+
"edge|--cask microsoft-edge"
15+
"vscode|--cask visual-studio-code"
16+
"powershell|--cask powershell"
17+
"dotnet|dotnet"
18+
"teams|--cask microsoft-teams"
19+
"onedrive|--cask onedrive"
20+
)
21+
apple=(
22+
"apple-music|--cask apple-music"
23+
)
24+
25+
resolve() {
26+
local vendor="$1" package="$2" entry name args
27+
local -n catalog="$vendor"
28+
for entry in "${catalog[@]}"; do
29+
name="${entry%%|*}"; args="${entry#*|}"
30+
if [[ "$name" == "$package" ]]; then
31+
printf '%s\n' "$args"
32+
return 0
33+
fi
34+
done
35+
return 1
36+
}
37+
38+
list_catalog() {
39+
printf '%s\n' '[microsoft]' edge vscode powershell dotnet teams onedrive
40+
printf '%s\n' '[apple]' apple-music
41+
}
42+
43+
if [[ "$ACTION" == "list" ]]; then list_catalog; exit 0; fi
44+
45+
if [[ "$VENDOR" == "all" ]]; then vendors=(microsoft apple); else vendors=("$VENDOR"); fi
46+
47+
run_one() {
48+
local spec="$1"
49+
# shellcheck disable=SC2206
50+
local args=( $spec )
51+
case "$ACTION" in
52+
install) brew install "${args[@]}" ;;
53+
update) brew upgrade "${args[@]}" ;;
54+
remove) brew uninstall "${args[@]}" ;;
55+
status) brew list --versions "${args[@]}" || true ;;
56+
repair) brew reinstall "${args[@]}" ;;
57+
*) echo "ERROR: unsupported action: $ACTION" >&2; exit 2 ;;
58+
esac
59+
}
60+
61+
if [[ "$ACTION" == "upgrade-all" ]]; then
62+
brew update
63+
brew upgrade
64+
exit 0
65+
fi
66+
67+
for vendor in "${vendors[@]}"; do
68+
if [[ -n "$PACKAGE" ]]; then
69+
spec="$(resolve "$vendor" "$PACKAGE")" || continue
70+
run_one "$spec"
71+
else
72+
echo "No package specified. Use 'list' or provide a package alias." >&2
73+
exit 2
74+
fi
75+
done
76+
77+
echo "US House macOS software operation complete."

0 commit comments

Comments
 (0)