From 2cf1c085c3110a86a14c4239d24516bd3b2586d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=85=89-k?= <36470587+kxgx@users.noreply.github.com> Date: Sat, 11 Jan 2025 08:48:25 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20install.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/install.sh | 54 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/bin/install.sh b/bin/install.sh index 22224b3..85c55d9 100644 --- a/bin/install.sh +++ b/bin/install.sh @@ -10,6 +10,8 @@ fi DEFAULT_LANG="en_US.UTF-8" # 检查是否使用中国镜像源 USE_CN_MIRROR=false +# 控制调试输出 +DEBUG=false # 解析命令行参数 while [ "$#" -gt 0 ]; do @@ -20,6 +22,9 @@ while [ "$#" -gt 0 ]; do --cn) USE_CN_MIRROR=true ;; + --debug) + DEBUG=true + ;; *) echo "未知参数: $1" exit 1 @@ -49,6 +54,13 @@ 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,11 +91,10 @@ fi # 更新源列表函数 update_sources_list() { local version=$1 - sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak - if [ $? -ne 0 ]; then - echo "备份源列表失败" >&2 - exit 1 + if [ "$DEBUG" = true ]; then + echo "正在更新版本 $version 的源列表" fi + 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" @@ -92,6 +103,9 @@ update_sources_list() { # 安装包函数 install_packages() { + if [ "$DEBUG" = true ]; then + echo "正在安装软件包..." + fi if ! sudo apt-get update; then echo "更新源列表失败" >&2 exit 1 @@ -108,18 +122,20 @@ install_packages() { # 安装pip包函数 install_pip_packages() { - if ! sudo pip3 --version > /dev/null 2>&1; then - echo "pip3 不可用,请安装 python3-pip" >&2 - exit 1 + if [ "$DEBUG" = true ]; then + echo "正在安装pip软件包..." fi if ! sudo pip3 install -i $PIPY_MIRROR spidev borax pillow requests; then - echo "pip软件包安装失败" >&2 - exit 1 -fi + echo "pip软件包安装包失败" >&2 + exit 1 + fi } # 复制服务文件并设置为开机启动 setup_service() { + if [ "$DEBUG" = true ]; then + echo "正在设置墨水屏时钟服务..." + fi if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then cd ~ if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then @@ -130,7 +146,9 @@ setup_service() { chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh" chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh" else - echo "墨水屏时钟仓库文件夹已存在,跳过克隆" + if [ "$DEBUG" = true ]; then + echo "墨水屏时钟仓库文件夹已存在,跳过克隆" + fi fi SERVICE_PATH="raspi_e-Paper.service" @@ -159,6 +177,10 @@ setup_service() { # 主逻辑 # 检测是否是Debian系统 if [ -f /etc/debian_version ]; then + if [ "$DEBUG" = true ]; then + echo "检测到Debian系统" + fi + # 提取版本号的小数点前的部分 if ! MAJOR_VERSION=$(echo $DEBIAN_VERSION | cut -d '.' -f 1); then echo "无法提取Debian版本号" >&2 @@ -167,15 +189,25 @@ if [ -f /etc/debian_version ]; then # 检测是否是Raspberry Pi系统 if is_raspberry_pi; then + if [ "$DEBUG" = true ]; then + echo "检测到Raspberry Pi系统" + fi + # 根据版本号的小数点前的部分执行不同的命令 case "$MAJOR_VERSION" in 11) + if [ "$DEBUG" = true ]; then + echo "执行Debian 11 (Bullseye) 相关操作" + fi update_sources_list "bullseye" install_packages install_pip_packages setup_service ;; 12) + if [ "$DEBUG" = true ]; then + echo "执行Debian 12 (Bookworm) 相关操作" + fi update_sources_list "bookworm" install_packages install_pip_packages