This commit is contained in:
luk
2026-07-18 21:32:08 +08:00
parent 209c0785da
commit bb1e42cf2a
2 changed files with 72 additions and 2 deletions

70
debian-update.sh Normal file
View File

@@ -0,0 +1,70 @@
#!/bin/bash
## "curl -s https://git.tic.cc/opx/sysconfig/raw/branch/main/debian-update.sh | bash"
echo "Update the current Debian major version to the next newer major version. For instance, update 11 to 12, or 12 to 13"
echo "Usage: this.sh"
echo "Example: this.sh"
if [ -f /etc/debian_version ]; then
OsTypeNow="Debian"
OsVersionNow=`cat /etc/debian_version 2>/dev/null`
OsMajorVersionNow=`echo $OsVersionNow | cut -d '.' -f 1`
# elif [ -f /etc/ubuntu_version ]; then
# OsTypeNow="Ubuntu"
# OsVersionNow=`cat /etc/ubuntu_version 2>/dev/null`
else
echo "Unsupported OS. Only Debian can be updated."
exit 1
fi
echo Current OS: $OsTypeNow $OsVersionNow
# set CodeNameNow and CodeNameNext based on the current version
if [ "$OsTypeNow" = "Debian" ]; then
if [ "$OsMajorVersionNow" = "11" ]; then
CodeNameNow="bullseye"
CodeNameNext="bookworm"
elif [ "$OsMajorVersionNow" = "12" ]; then
CodeNameNow="bookworm"
CodeNameNext="trixie"
else
echo "Unsupported Debian version: $OsVersionNow"
exit 1
fi
else
echo "Unsupported OS type: $OsTypeNow"
exit 1
fi
echo "Are you sure to update $OsTypeNow $CodeNameNow to $CodeNameNext?"
echo " [y] Yes, update now"
echo " [anything else] No, cancel update"
read -r answer
if [ "$answer" != "y" ]; then
echo "Update canceled."
exit 0
fi
# 检查并解除包锁定(有锁定会导致升级失败)
apt-mark showhold | grep -v "^$" && apt-mark unhold $(apt-mark showhold)
# 更新11系统至最新版本
apt update && apt upgrade -y
apt full-upgrade -y # 处理依赖与内核升级
apt --purge autoremove -y # 清理无用包
apt clean # 清空APT缓存
# 替换bullseye为bookworm覆盖主配置与子目录
sed -i "s/$CodeNameNow/$CodeNameNext/g" /etc/apt/sources.list
sed -i "s/$CodeNameNow/$CodeNameNext/g" /etc/apt/sources.list.d/*.list
apt update
# 先最小升级(仅更新包,不安装/删除新包)
apt upgrade --without-new-pkgs -y
# 完整升级(处理依赖、内核替换、包移除)
apt full-upgrade -y
apt --purge autoremove -y
apt clean
echo "Updated! You can reboot now."

View File

@@ -153,9 +153,9 @@ elif [ -f /etc/ubuntu_version ]; then
MYOSVERSION=Ubt`cat /etc/ubuntu_version 2>/dev/null` MYOSVERSION=Ubt`cat /etc/ubuntu_version 2>/dev/null`
fi fi
if [ "$color_prompt" = yes ]; then if [ "$color_prompt" = yes ]; then
PS1='<\[\033[$PSTYLE;${PTYPE}2m\]\t\[\033[00m\] \[\033[$PSTYLE;${PTYPE}5m\]\u\[\033[00m\] @\[\033[$PSTYLE;${PTYPE}1m\]\h\[\033[00m\] #\[\033[$PSTYLE;${PTYPE}6m\]$MYIPPUB\[\033[00m\] ^\[\033[$PSTYLE;${PTYPE}5m\]$(uname -m),$(uname),$MYOSVERSION\[\033[00m\] %\[\033[$PSTYLE;${PTYPE}2m\]\w/\[\033[00m\]>\n[\[\033[05;${PTYPE}4m\]\W/\[\033[00m\]] ' PS1='<\[\033[$PSTYLE;${PTYPE}2m\]\t\[\033[00m\] \[\033[$PSTYLE;${PTYPE}5m\]\u\[\033[00m\] @\[\033[$PSTYLE;${PTYPE}1m\]\h\[\033[00m\] =\[\033[$PSTYLE;${PTYPE}6m\]$MYIPPUB\[\033[00m\] #\[\033[$PSTYLE;${PTYPE}5m\]$(uname -m),$(uname),$MYOSVERSION\[\033[00m\] \[\033[$PSTYLE;${PTYPE}2m\]\w/\[\033[00m\]>\n[\[\033[05;34m\]\W/\[\033[00m\]] '
else else
PS1='<\t \u @\h #$MYIPPUB ^$(uname -m),$(uname),$MYOSVERSION %\w/>\n[\W/] ' # \w shows absolute path, \W shows current folder. PS1='<\t \u @\h =$MYIPPUB #$(uname -m),$(uname),$MYOSVERSION \w/>\n[\W/] ' # \w shows absolute path, \W shows current folder.
fi fi
unset color_prompt force_color_prompt unset color_prompt force_color_prompt