-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsources.sh
executable file
·76 lines (67 loc) · 2.11 KB
/
sources.sh
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
#!/usr/bin/env bash
# sudo bash <(curl -Lso- https://sh.vps.dance/sources.sh) debian11
# sudo bash <(curl -Lso- https://sh.vps.dance/sources.sh) debian12
# sudo bash <(curl -Lso- https://sh.vps.dance/sources.sh) aliyun
sources_list="/etc/apt/sources.list"
name=$( tr '[:upper:]' '[:lower:]' <<<"$1" )
debian_sources() {
local version=$1
local codename=""
local components="main"
case "$version" in
"11"|"debian11")
codename="bullseye"
;;
"12"|"debian12")
codename="bookworm"
components="main non-free-firmware"
;;
esac
backup_sources
(
echo "deb http://deb.debian.org/debian $codename $components"
echo "deb-src http://deb.debian.org/debian $codename $components"
echo "deb http://security.debian.org/debian-security $codename-security $components"
echo "deb-src http://security.debian.org/debian-security $codename-security $components"
echo "deb http://deb.debian.org/debian $codename-updates $components"
echo "deb-src http://deb.debian.org/debian $codename-updates $components"
# echo "deb http://deb.debian.org/debian $codename-backports $components"
# echo "deb-src http://deb.debian.org/debian $codename-backports $components"
) > $sources_list
}
aliyun() {
backup_sources
sed -i -E 's#https?://[^/]+/debian#https://mirrors.aliyun.com/debian#g' $sources_list
sed -i -E 's#https?://[^/]+/debian-security#https://mirrors.aliyun.com/debian-security#g' $sources_list
}
backup_sources() {
# add timestamp to backup file
local timestamp=$(date +%Y%m%d_%H%M%S)
cp $sources_list{,."$timestamp".bak}
echo "Backup created: $sources_list.$timestamp.bak"
}
upgrade_tips() {
echo "Please run:"
echo "apt update -y && apt upgrade -y && apt autoremove -y && apt autoclean -y"
echo "cat /etc/os-release"
}
sources_tips() {
echo "cat $sources_list"
}
main() {
if [[ "$name" == "debian11" ]]; then
debian_sources "11"
upgrade_tips
elif [[ "$name" == "debian12" ]]; then
debian_sources "12"
upgrade_tips
elif [[ "$name" == "aliyun" ]]; then
aliyun
sources_tips
else
echo "Error: not supported."
exit 1
fi
# echo "Done."
}
main