19 Commits

Author SHA1 Message Date
星光-k
b3c8a76fe4 Update install.sh 2025-01-11 22:53:59 +08:00
星光-k
8fb2b0f172 Update install.sh 2025-01-11 22:47:58 +08:00
星光-k
40c96f8ace Update install.sh 2025-01-11 22:31:18 +08:00
星光-k
815383483d Update install.sh 2025-01-11 22:20:30 +08:00
星光-k
3062abb70b Update install.sh 2025-01-11 22:15:10 +08:00
星光-k
f15da42496 Update install.sh 2025-01-11 22:05:56 +08:00
星光-k
85fdea4341 Update install.sh 2025-01-11 21:59:19 +08:00
星光-k
c759882f51 Update install.sh 2025-01-11 21:35:43 +08:00
星光-k
e81aeba0fe Update install.sh 2025-01-11 21:33:27 +08:00
星光-k
ad571d0125 更新 install.sh 2025-01-11 09:55:24 +00:00
星光-k
f457537872 更新 install.sh 2025-01-11 09:50:56 +00:00
星光-k
8c2ff1d533 更新 install.sh 2025-01-11 09:14:37 +00:00
星光-k
2cf1c085c3 更新 install.sh 2025-01-11 08:48:25 +00:00
星光-k
d6a7e5e725 更新 install.sh 2025-01-11 07:10:21 +00:00
星光-k
6313770d3f 更新 install.sh 2025-01-11 06:57:15 +00:00
星光-k
17f0215e9d 更新 install.sh 2025-01-11 06:37:41 +00:00
星光-k
f5b2ef3518 更新 install.sh 2025-01-11 06:34:54 +00:00
星光-k
febff6fe78 更新 install.sh 2025-01-11 06:26:28 +00:00
星光-k
58f6a8f48d 更新 install.sh 2025-01-11 04:15:51 +00:00

View File

@@ -54,13 +54,6 @@ if ! sudo dpkg-reconfigure --frontend=noninteractive locales; then
exit 1
fi
# 如果需要调试输出
debug() {
if [ "$DEBUG" = true ]; then
echo "$@"
fi
}
# Debian版本相关命令
DEBIAN_VERSION=$(cat /etc/debian_version)
@@ -79,29 +72,73 @@ DEBIAN_SECURITY_MIRROR="http://security.debian.org/"
PI_SUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh"
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock.git"
PIPY_MIRROR="https://pypi.org/simple"
# 修改 Raspberry Pi 特定源链接
RASPBERRY_PI_SOURCE_DEBIAN11="https://archive.raspberrypi.org/debian/"
RASPBERRY_PI_SOURCE_DEBIAN12="https://archive.raspberrypi.com/debian/"
# 如果使用中国镜像源,则更新链接变量
if [ "$USE_CN_MIRROR" = true ]; then
DEBIAN_MIRROR="https://mirrors.cernet.edu.cn/debian/"
DEBIAN_SECURITY_MIRROR="https://mirrors.cernet.edu.cn/debian-security"
DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian/"
DEBIAN_SECURITY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian-security"
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock.git"
PIPY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
# 使用中国镜像源时Raspberry Pi 特定源链接保持不变
RASPBERRY_PI_SOURCE_DEBIAN11="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/"
RASPBERRY_PI_SOURCE_DEBIAN12="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/"
fi
# 更新源列表函数
update_sources_list() {
local version=$1
debug "正在更新版本 $version 的源列表"
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
{
echo "deb $DEBIAN_MIRROR $version main contrib non-free"
echo "# deb-src $DEBIAN_MIRROR $version main contrib non-free"
} | sudo tee /etc/apt/sources.list > /dev/null
local debian_mirror_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list | head -1)
local raspberry_pi_source_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list.d/raspi.list | head -1)
# 检查并替换 Debian 源
if [ "$debian_mirror_in_use" != "$DEBIAN_MIRROR" ]; then
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
{
if [ "$version" = "bookworm" ]; then
echo "deb $DEBIAN_MIRROR $version main contrib non-free non-free-firmware"
echo "# deb-src $DEBIAN_MIRROR $version main contrib non-free non-free-firmware"
echo "deb $DEBIAN_MIRROR $version-updates main contrib non-free non-free-firmware"
echo "# deb-src $DEBIAN_MIRROR $version-updates main contrib non-free non-free-firmware"
echo "deb $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free non-free-firmware"
echo "# deb-src $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free non-free-firmware"
else
echo "deb $DEBIAN_MIRROR $version main contrib non-free"
echo "# deb-src $DEBIAN_MIRROR $version main contrib non-free"
echo "deb $DEBIAN_MIRROR $version-updates main contrib non-free"
echo "# deb-src $DEBIAN_MIRROR $version-updates main contrib non-free"
echo "deb $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free"
echo "# deb-src $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free"
fi
} | sudo tee /etc/apt/sources.list > /dev/null
else
echo "Debian 源链接已更新,跳过替换" >&2
fi
# 检查并替换 Raspberry Pi 特定源
if [ "$version" == "bullseye" ]; then
RASPBERRY_PI_SOURCE=$RASPBERRY_PI_SOURCE_DEBIAN11
elif [ "$version" == "bookworm" ]; then
RASPBERRY_PI_SOURCE=$RASPBERRY_PI_SOURCE_DEBIAN12
else
echo "未知的Debian版本: $version" >&2
exit 1
fi
if [ "$raspberry_pi_source_in_use" != "$RASPBERRY_PI_SOURCE$version" ]; then
if [ -f "/etc/apt/sources.list.d/raspi.list" ]; then
sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
fi
echo "deb $RASPBERRY_PI_SOURCE $version main" | sudo tee /etc/apt/sources.list.d/raspi.list > /dev/null
else
echo "Raspberry Pi 源链接已更新,跳过替换" >&2
fi
}
# 安装包函数
install_packages() {
debug "正在安装软件包..."
if ! sudo apt-get update; then
echo "更新源列表失败" >&2
exit 1
@@ -118,54 +155,61 @@ install_packages() {
# 安装pip包函数
install_pip_packages() {
debug "正在安装pip软件包..."
if ! sudo pip3 install -i $PIPY_MIRROR spidev borax pillow requests; then
echo "pip软件包安装失败" >&2
exit 1
if ! sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests; then
echo "pip软件包安装包失败" >&2
fi
}
# 复制服务文件并设置为开机启动
setup_service() {
debug "正在设置墨水屏时钟服务..."
if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then
cd ~
if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then
echo "克隆墨水屏时钟仓库失败" >&2
exit 1
fi
# 设置start.sh和clean.sh脚本的执行权限
chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh"
chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh"
fi
local service_path="raspi_e-Paper.service"
local service1_path="e-Paper_clean.service"
local service_file_path="$HOME/2.13-Ink-screen-clock/bin/$service_path"
local service1_file_path="$HOME/2.13-Ink-screen-clock/bin/$service1_path"
SERVICE_PATH="raspi_e-Paper.service"
SERVICE1_PATH="e-Paper_clean.service"
SERVICE_FILE_PATH="$HOME/2.13-Ink-screen-clock/bin/$SERVICE_PATH"
SERVICE1_FILE_PATH="$HOME/2.13-Ink-screen-clock/bin/$SERVICE1_PATH"
if [ -f "$SERVICE_FILE_PATH" ] && [ -f "$SERVICE1_FILE_PATH" ]; then
# 复制服务文件到 systemd 目录
if sudo cp "$SERVICE_FILE_PATH" /etc/systemd/system/ && sudo cp "$SERVICE1_FILE_PATH" /etc/systemd/system/; then
# 重载 systemd 管理器配置
sudo systemctl daemon-reload
# 启动服务
sudo systemctl enable $SERVICE_PATH
sudo systemctl enable $SERVICE1_PATH
sudo systemctl start $SERVICE_PATH
# 检查墨水屏时钟仓库是否存在
if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then
cd ~
if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then
echo "克隆墨水屏时钟仓库失败" >&2
exit 1
fi
# 设置start.sh和clean.sh脚本的执行权限
chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh"
chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh"
else
echo "复制服务文件失败" >&2
echo "墨水屏时钟仓库文件夹已存在,跳过克隆"
fi
# 检查服务文件是否存在
if [ -f "$service_file_path" ] && [ -f "$service1_file_path" ]; then
# 检查服务是否已经启用
if ! systemctl is-enabled $service_path &>/dev/null && ! systemctl is-enabled $service1_path &>/dev/null; then
# 复制服务文件到 systemd 目录
if sudo cp "$service_file_path" /etc/systemd/system/ && sudo cp "$service1_file_path" /etc/systemd/system/; then
# 重载 systemd 管理器配置
sudo systemctl daemon-reload
# 启动服务
sudo systemctl enable $service_path
sudo systemctl enable $service1_path
sudo systemctl start $service_path
else
echo "复制服务文件失败" >&2
exit 1
fi
else
echo "服务文件已存在并启用,跳过复制"
fi
else
echo "服务文件不存在于路径: $service_file_path$service1_file_path" >&2
exit 1
fi
else
echo "服务文件不存在于路径: $SERVICE_FILE_PATH$SERVICE1_FILE_PATH" >&2
exit 1
fi
}
# 主逻辑
# 检测是否是Debian系统
if [ -f /etc/debian_version ]; then
debug "检测到Debian系统"
echo "检测到Debian系统"
# 提取版本号的小数点前的部分
if ! MAJOR_VERSION=$(echo $DEBIAN_VERSION | cut -d '.' -f 1); then
@@ -175,19 +219,19 @@ if [ -f /etc/debian_version ]; then
# 检测是否是Raspberry Pi系统
if is_raspberry_pi; then
debug "检测到Raspberry Pi系统"
echo "检测到Raspberry Pi系统"
# 根据版本号的小数点前的部分执行不同的命令
case "$MAJOR_VERSION" in
11)
debug "执行Debian 11 (Bullseye) 相关操作"
echo "执行Debian 11 (Bullseye) 相关操作"
update_sources_list "bullseye"
install_packages
install_pip_packages
setup_service
;;
12)
debug "执行Debian 12 (Bookworm) 相关操作"
echo "执行Debian 12 (Bookworm) 相关操作"
update_sources_list "bookworm"
install_packages
install_pip_packages