31 Commits

Author SHA1 Message Date
星光-k
29de2a7d77 Update install.sh 2025-01-12 01:47:10 +08:00
星光-k
b6422c9afa Update install.sh 2025-01-12 01:39:08 +08:00
星光-k
9be8d1ac22 Update e-Paper_clean.service 2025-01-12 01:12:08 +08:00
星光-k
3d724ac527 Update clean.sh 2025-01-12 01:01:16 +08:00
星光-k
35facc30f0 Update clean.sh 2025-01-12 01:00:55 +08:00
星光-k
af205dc591 Update clean.sh 2025-01-12 00:58:42 +08:00
星光-k
ef387ebf4b Update e-Paper_clean.service 2025-01-12 00:28:27 +08:00
星光-k
6ac8e7d4b7 Update raspi_e-Paper.service 2025-01-12 00:26:59 +08:00
星光-k
a869fc1911 Update e-Paper_clean.service 2025-01-12 00:03:53 +08:00
星光-k
a2e657a182 Update README.md 2025-01-11 23:47:42 +08:00
星光-k
a29377cfa7 Update README.md 2025-01-11 23:46:05 +08:00
星光-k
08111ca4fa Update e-Paper_clean.service 2025-01-11 23:19:42 +08:00
星光-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
5 changed files with 114 additions and 61 deletions

View File

@@ -1,8 +1,9 @@
# 墨水屏展示当前时间及天气数据
首先感谢上游https://github.com/Seek-Huang/2.13-Ink-screen-clock 的代码仓库
本项目复刻自[Seek-Huang](https://github.com/Seek-Huang/2.13-Ink-screen-clock)的代码仓库
并在此基础上进行改进
## 本仓库已添加一键安装部署脚本
## 本仓库已添加[一键安装部署脚本](https://github.com/kxgx/2.13-Ink-screen-clock#%E4%BD%BF%E7%94%A8%E8%84%9A%E6%9C%AC%E7%9B%B4%E6%8E%A5%E5%AE%89%E8%A3%85%E6%8E%A8%E8%8D%90)
注意:请先配置完需要的硬件以及系统配置操作再运行脚本
## API说明:
@@ -29,7 +30,7 @@
ps:如果没有使用此模块则需要更改代码内容,以避免运行出错。
以上可能python脚本已解决
ps:代码里需要nc命令需要安装netcat安装内容已集成到“需要安装的软件和依赖https://github.com/kxgx/2.13-Ink-screen-clock#%E9%9C%80%E8%A6%81%E5%AE%89%E8%A3%85%E7%9A%84%E8%BD%AF%E4%BB%B6%E5%92%8C%E4%BE%9D%E8%B5%96
ps:代码里需要nc命令需要安装netcat安装内容已集成到“[需要安装的软件和依赖](https://github.com/kxgx/2.13-Ink-screen-clock#%E9%9C%80%E8%A6%81%E5%AE%89%E8%A3%85%E7%9A%84%E8%BD%AF%E4%BB%B6%E5%92%8C%E4%BE%9D%E8%B5%96)"
### 墨水屏2.13inch e-Paper HAT+硬件连接
连接树莓派的时候,可以直接将板子插到树莓派的 40PIN 排针上去,注意对好引脚。

View File

@@ -5,6 +5,14 @@ dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir=${dir%/*}
screen_name="clean_screen"
service_name="raspi_e-Paper.service"
hold_time_seconds=5 # 设置维持时间例如300秒5分钟
# 创建一个新的screen会话并运行Python脚本
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/clean-info.log 2>&1
# 等待维持时间
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
sleep $hold_time_seconds
# 停止raspi_e-Paper服务
echo "正在停止$service_name服务..."
@@ -16,5 +24,4 @@ for pid in $pids; do
screen -S $pid -X quit
done
# 创建一个新的screen会话并运行Python脚本
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/clean-info.log 2>&1
echo "脚本运行完成服务已停止screen会话已结束。"

View File

@@ -8,7 +8,7 @@ Before=reboot.target
Type=oneshot
ExecStart=/bin/bash /root/2.13-Ink-screen-clock/bin/clean.sh
RemainAfterExit=yes
TimeoutSec=5s
TimeoutSec=5
[Install]
WantedBy=shutdown.target

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
@@ -110,7 +147,7 @@ install_packages() {
echo "系统更新失败" >&2
exit 1
fi
if ! sudo apt-get install -y git pigpio raspi-config netcat gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential screen; then
if ! sudo apt-get install -y git pigpio raspi-config netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential screen; then
echo "软件包安装失败" >&2
exit 1
fi
@@ -118,54 +155,62 @@ install_packages() {
# 安装pip包函数
install_pip_packages() {
debug "正在安装pip软件包..."
if ! sudo pip3 install -i $PIPY_MIRROR spidev borax pillow requests; then
echo "pip软件包安装失败" >&2
if ! sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests --break-system-packages; then
echo "pip软件包安装包失败" >&2
exit 1
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 +220,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

View File

@@ -1,11 +1,11 @@
[Unit]
Description=Raspi e-Paper Service
After=network-online.target
After=network.target
[Service]
Type=forking
# 等待网络完全启动
#ExecStartPre=systemd-networkd-wait-online --timeout=30
ExecStartPre=/bin/bash -c 'until ping -c1 baidu.com &>/dev/null; do sleep 1; done'
ExecStart=/root/2.13-Ink-screen-clock/bin/start.sh
ExecStop=/usr/bin/screen -S main_screen -X quit
Restart=on-failure