forked from programming101dev/setup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·112 lines (98 loc) · 2.28 KB
/
update.sh
File metadata and controls
executable file
·112 lines (98 loc) · 2.28 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
#!/usr/bin/env bash
# update-system.sh, unified updater for macOS, Linux distros, and FreeBSD
set -euo pipefail
IFS=$' \t\n'
die() { printf "Error: %s\n" "$*" >&2; exit 1; }
need_cmd() { command -v "$1" >/dev/null 2>&1 || die "required command not found: $1"; }
update_macos() {
echo "Detected macOS."
if command -v brew >/dev/null 2>&1; then
echo "Updating Homebrew packages..."
brew update
brew upgrade
else
echo "Homebrew not found, skipping."
fi
echo "Running macOS Software Update..."
need_cmd sudo
sudo softwareupdate --install --all
}
update_apt_like() {
echo "Updating with APT..."
need_cmd sudo
sudo apt-get update
sudo apt-get -y dist-upgrade
}
update_dnf_like() {
echo "Updating with DNF..."
need_cmd sudo
sudo dnf upgrade --refresh -y
}
update_pacman_like() {
echo "Updating with Pacman..."
need_cmd sudo
sudo pacman -Syu --noconfirm
}
update_manjaro() {
echo "Detected Manjaro."
update_pacman_like
if command -v yay >/dev/null 2>&1; then
echo "Updating AUR packages with yay..."
yay -Syu --noconfirm
fi
}
update_freebsd() {
echo "Detected FreeBSD."
need_cmd sudo
echo "Updating FreeBSD base system..."
sudo freebsd-update fetch
sudo freebsd-update install
echo "Updating packages..."
sudo pkg update
sudo pkg upgrade -y
}
update_linux() {
if [[ -f /etc/os-release ]]; then
# shellcheck source=/dev/null
. /etc/os-release
else
die "cannot detect Linux distribution, /etc/os-release missing"
fi
# Normalize IDs for routing.
distro_id="${ID:-}"
distro_like="${ID_LIKE:-}"
case "$distro_id" in
ubuntu|kali|debian)
update_apt_like
;;
fedora)
update_dnf_like
;;
manjaro)
update_manjaro
;;
arch)
update_pacman_like
;;
*)
case "$distro_like" in
*debian*) update_apt_like ;;
*rhel*|*fedora*) update_dnf_like ;;
*arch*) update_pacman_like ;;
*)
die "unsupported Linux distribution: ${distro_id:-unknown} (ID_LIKE='${distro_like:-unset}')"
;;
esac
;;
esac
}
main() {
os="$(uname -s)"
case "$os" in
Darwin) update_macos ;;
Linux) update_linux ;;
FreeBSD) update_freebsd ;;
*) die "unsupported operating system: $os" ;;
esac
}
main "$@"