82 Commits

Author SHA1 Message Date
星光-k
b688062ca4 Update main.py 2025-01-13 02:30:00 +08:00
星光-k
d63d12de38 Update README.md 2025-01-12 21:41:51 +08:00
星光-k
9ef97ab7a2 Update install.sh 2025-01-12 21:32:30 +08:00
星光-k
6651491941 Update install.sh 2025-01-12 21:24:22 +08:00
星光-k
d498dad18f Update install.sh 2025-01-12 21:07:11 +08:00
星光-k
2bd8dc0bc6 Update install.sh 2025-01-12 21:04:03 +08:00
星光-k
7873004d74 Update install.sh 2025-01-12 20:57:55 +08:00
星光-k
a5eec2e9a3 Update install.sh 2025-01-12 20:26:49 +08:00
星光-k
a8059bac56 Update README.md 2025-01-12 17:06:41 +08:00
星光-k
a80e3a2722 Update README.md 2025-01-12 17:06:05 +08:00
星光-k
c60fccb210 Update README.md 2025-01-12 17:05:24 +08:00
星光-k
53e1845ce4 Update README.md 2025-01-12 17:04:29 +08:00
星光-k
3844f71943 Add files via upload 2025-01-12 09:03:30 +00:00
星光-k
b2336dcbfb Update clean.sh 2025-01-12 16:52:01 +08:00
星光-k
5a976157c2 Rename clean-info.log to info-clean.log 2025-01-12 16:42:51 +08:00
星光-k
b6866ee2b9 Update clean.sh 2025-01-12 16:39:55 +08:00
星光-k
32565ef2f5 Update clean.sh 2025-01-12 16:36:58 +08:00
星光-k
0c4282ebc9 Update start.sh 2025-01-12 16:33:04 +08:00
星光-k
f8b2c1b332 Update install.sh 2025-01-12 16:25:59 +08:00
星光-k
5b5dace7d3 Update install.sh 2025-01-12 16:22:08 +08:00
星光-k
04ab97f5b6 Update clean.sh 2025-01-12 16:21:45 +08:00
星光-k
0565fd6cf5 Update start.sh 2025-01-12 16:18:33 +08:00
星光-k
173d7eba78 Update main.py 2025-01-12 15:51:00 +08:00
星光-k
28895e7188 Update clean.sh 2025-01-12 14:55:53 +08:00
星光-k
8a4ba07f5b Update e-Paper_clean.service 2025-01-12 14:55:35 +08:00
星光-k
ecaa4006ce Update e-Paper_clean.service 2025-01-12 14:55:24 +08:00
星光-k
c5a3ef0dcf Update main.py 2025-01-12 14:52:18 +08:00
星光-k
99c2bb3152 Update main.py 2025-01-12 14:45:24 +08:00
星光-k
533e76d536 Update main.py 2025-01-12 14:08:23 +08:00
星光-k
26ee5bf6e7 Update main.py 2025-01-12 14:07:17 +08:00
星光-k
a710b293b6 Update main.py 2025-01-12 13:53:03 +08:00
星光-k
3a90a36ffa 更新 main.py 2025-01-12 05:34:51 +00:00
星光-k
fdd3e6008a 更新 main.py 2025-01-12 05:31:35 +00:00
星光-k
e3fd070e3c 更新 install.sh 2025-01-12 04:51:02 +00:00
星光-k
5e353f68f6 更新 install.sh 2025-01-12 04:48:42 +00:00
星光-k
6e0646612b 更新 install.sh 2025-01-12 04:46:09 +00:00
星光-k
d2b4073c98 更新 install.sh 2025-01-12 04:42:44 +00:00
星光-k
9fb1ef0c6b 更新 install.sh 2025-01-12 04:42:03 +00:00
星光-k
7c39658cdf 更新 install.sh 2025-01-12 04:35:34 +00:00
星光-k
6628fc01e2 更新 install.sh 2025-01-12 04:31:59 +00:00
星光-k
b505f9a61d 更新 install.sh 2025-01-12 04:26:12 +00:00
星光-k
7db25e5136 更新 install.sh 2025-01-12 04:22:31 +00:00
星光-k
9e28156c65 更新 install.sh 2025-01-12 04:13:48 +00:00
星光-k
1be7856992 更新 install.sh 2025-01-12 04:06:31 +00:00
星光-k
368ed919dd 更新 install.sh 2025-01-12 03:59:40 +00:00
星光-k
7a9108134a 更新 install.sh 2025-01-12 03:50:32 +00:00
星光-k
1aa62fb894 更新 install.sh 2025-01-12 03:46:47 +00:00
星光-k
d5ff700884 更新 install.sh 2025-01-12 03:21:28 +00:00
星光-k
c56bd3784e 更新 install.sh 2025-01-12 03:19:48 +00:00
星光-k
597790d4ad 更新 install.sh 2025-01-12 03:17:07 +00:00
星光-k
e8011c7282 更新 install.sh 2025-01-12 03:14:12 +00:00
星光-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
9 changed files with 470 additions and 400 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说明: ## API说明:
@@ -29,7 +30,7 @@
ps:如果没有使用此模块则需要更改代码内容,以避免运行出错。 ps:如果没有使用此模块则需要更改代码内容,以避免运行出错。
以上可能python脚本已解决 以上可能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+硬件连接 ### 墨水屏2.13inch e-Paper HAT+硬件连接
连接树莓派的时候,可以直接将板子插到树莓派的 40PIN 排针上去,注意对好引脚。 连接树莓派的时候,可以直接将板子插到树莓派的 40PIN 排针上去,注意对好引脚。
@@ -63,23 +64,25 @@ sudo reboot
```Bash ```Bash
--zh 设置系统语言为zh_CN,UTF-8 --zh 设置系统语言为zh_CN,UTF-8
--cn 替换apt镜像源为中国镜像源 --cn 替换apt镜像源为中国镜像源
--gitcn 克隆中国仓库
--debug 输出详细信息 --debug 输出详细信息
``` ```
###
```Bash ```Bash
#国源默认设置 #国源默认设置
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
``` ```
```Bash ```Bash
#国内源--cn设置 #中国源全参数设置(不使用--debug参数)
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn
``` ```
```Bash ```Bash
#默认源默认设置 #默认源默认设置
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
``` ```
```Bash ```Bash
#默认源--cn设置 #中国源全参数设置(不使用--debug参数)
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn
``` ```
## 需要安装的软件和依赖: ## 需要安装的软件和依赖:
@@ -111,4 +114,5 @@ sudo apt-get update && sudo apt install -y git && sudo apt-get install -y python
特别注意: 特别注意:
在代码文件第三十三行,此次代码需要更改,否则将展示默认城市天气数据 在代码文件第三十三行,此次代码需要更改,否则将展示默认城市天气数据
![image](https://raw.githubusercontent.com/huanglinsd/2.13-Ink-screen-clock/main/pic/IMG_1245.JPG) # 效果展示
![image](https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/pic/1736672578025.jpg)

View File

@@ -1,20 +1,27 @@
#!/bin/bash #!/bin/bash
f_name=clean.py f_name="clean.py"
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir=${dir%/*} logdir="${dir}/log"
screen_name="clean_screen"
service_name="raspi_e-Paper.service" service_name="raspi_e-Paper.service"
hold_time_seconds=3 # 设置维持时间例如300秒5分钟
# 停止raspi_e-Paper服务 # 停止raspi_e-Paper服务
echo "正在停止$service_name服务..." echo "正在停止$service_name服务..."
sudo systemctl stop $service_name sudo systemctl stop "$service_name"
# 查找并结束所有与指定screen_name相关的screen会话 # 确保日志目录存在
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}') mkdir -p "${logdir}"
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 pids=$(pgrep -f "$dir/$f_name")
if [ -n "$pids" ]; then
kill -9 $pids
fi
# 使用nohup在后台运行Python脚本并将输出重定向到日志文件
nohup /usr/bin/python3 -u "$dir/$f_name" > "${logdir}/info-clean.log" 2>&1 &
# 等待维持时间
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
sleep $hold_time_seconds

View File

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

View File

@@ -12,6 +12,8 @@ DEFAULT_LANG="en_US.UTF-8"
USE_CN_MIRROR=false USE_CN_MIRROR=false
# 控制调试输出 # 控制调试输出
DEBUG=false DEBUG=false
# 检查是否使用中国git仓库
USE_CN_GIT=false
# 解析命令行参数 # 解析命令行参数
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
@@ -22,6 +24,9 @@ while [ "$#" -gt 0 ]; do
--cn) --cn)
USE_CN_MIRROR=true USE_CN_MIRROR=true
;; ;;
--gitcn)
USE_CN_GIT=true
;;
--debug) --debug)
DEBUG=true DEBUG=true
;; ;;
@@ -33,33 +38,58 @@ while [ "$#" -gt 0 ]; do
shift shift
done done
# 获取当前语言环境变量
CURRENT_LANG=$(locale | grep LANG | sed 's/.*=//')
# 打印当前语言环境变量
echo "当前语言环境: $CURRENT_LANG"
# 设置语言环境 # 设置语言环境
export LANG=$DEFAULT_LANG if [ "$CURRENT_LANG" != "$DEFAULT_LANG" ]; then
export LC_ALL=$DEFAULT_LANG echo "当前语言环境不是 $DEFAULT_LANG,将进行设置"
# 如果 locale.gen 中不存在,则添加到 locale.gen # 设置新的语言环境变量
if ! grep -q "^$DEFAULT_LANG UTF-8" /etc/locale.gen; then export LANG=$DEFAULT_LANG
echo "$DEFAULT_LANG UTF-8" | sudo tee -a /etc/locale.gen export LC_ALL=$DEFAULT_LANG
fi
# 生成 locale # 检查 locale.gen 中是否已存在 DEFAULT_LANG
if ! sudo locale-gen; then found=0
echo "生成 locale 失败" >&2 while read -r line; do
exit 1 if [[ "$line" == "$DEFAULT_LANG UTF-8" ]]; then
fi found=1
break
fi
done < /etc/locale.gen
# 重新配置 locales if [ $found -eq 0 ]; then
if ! sudo dpkg-reconfigure --frontend=noninteractive locales; then # 如果不存在,则添加到 locale.gen
echo "重新配置 locales 失败" >&2 echo "$DEFAULT_LANG UTF-8" | sudo tee -a /etc/locale.gen
exit 1 # 确保 locale.gen 被正确更新
fi if [ $? -ne 0 ]; then
echo "无法更新 locale.gen 文件" >&2
# 如果需要调试输出 exit 1
debug() { fi
if [ "$DEBUG" = true ]; then else
echo "$@" echo "语言环境 $DEFAULT_LANG 已在 locale.gen 中设置,跳过添加"
fi fi
}
# 生成 locale
if ! sudo locale-gen; then
# 如果生成失败,打印错误消息并退出
echo "生成 locale 失败" >&2
exit 1
fi
# 更新 locale 配置
if ! sudo update-locale LANG=$DEFAULT_LANG; then
echo "更新 locale 配置失败" >&2
exit 1
fi
echo "语言环境设置完成"
else
echo "当前语言环境已经是 $DEFAULT_LANG,跳过设置"
fi
# Debian版本相关命令 # Debian版本相关命令
DEBIAN_VERSION=$(cat /etc/debian_version) DEBIAN_VERSION=$(cat /etc/debian_version)
@@ -77,40 +107,85 @@ is_raspberry_pi() {
DEBIAN_MIRROR="http://deb.debian.org/debian/" DEBIAN_MIRROR="http://deb.debian.org/debian/"
DEBIAN_SECURITY_MIRROR="http://security.debian.org/" DEBIAN_SECURITY_MIRROR="http://security.debian.org/"
PI_SUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh" 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" 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 if [ "$USE_CN_MIRROR" = true ]; then
DEBIAN_MIRROR="https://mirrors.cernet.edu.cn/debian/" DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian/"
DEBIAN_SECURITY_MIRROR="https://mirrors.cernet.edu.cn/debian-security" 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" 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
# 定义仓库链接变量
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock.git"
# 如果使用中国仓库,则更新链接变量
if [ "$USE_CN_GIT" = true ]; then
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock.git"
fi fi
# 更新源列表函数 # 更新源列表函数
update_sources_list() { update_sources_list() {
local version=$1 local version=$1
debug "正在更新版本 $version 的源列表" local debian_mirror_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list | head -1)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak local raspberry_pi_source_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list.d/raspi.list | head -1)
{
echo "deb $DEBIAN_MIRROR $version main contrib non-free" # 检查并替换 Debian 源
echo "# deb-src $DEBIAN_MIRROR $version main contrib non-free" if [ "$debian_mirror_in_use" != "$DEBIAN_MIRROR" ]; then
} | sudo tee /etc/apt/sources.list > /dev/null 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() { install_packages() {
debug "正在安装软件包..."
if ! sudo apt-get update; then if ! sudo apt-get update; then
echo "更新源列表失败" >&2 echo "更新源列表失败" >&2
exit 1 exit 1
fi fi
if ! sudo apt-get upgrade -y; then if ! sudo apt-get install -y git pigpio netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential; then
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
echo "软件包安装失败" >&2 echo "软件包安装失败" >&2
exit 1 exit 1
fi fi
@@ -118,54 +193,65 @@ install_packages() {
# 安装pip包函数 # 安装pip包函数
install_pip_packages() { install_pip_packages() {
debug "正在安装pip软件包..." if ! sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests; then
if ! sudo pip3 install -i $PIPY_MIRROR spidev borax pillow requests; then echo "pip软件包安装包失败如果是最新版系统" >&2
echo "pip软件包安装失败" >&2 echo "请手动运行sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests --break-system-packages" >&2
exit 1 exit 1
fi fi
} }
# 复制服务文件并设置为开机启动 # 复制服务文件并设置为开机启动
setup_service() { setup_service() {
debug "正在设置墨水屏时钟服务..." local service_path="raspi_e-Paper.service"
if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then local service1_path="e-Paper_clean.service"
cd ~ local service_file_path="$HOME/2.13-Ink-screen-clock/bin/$service_path"
if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then local service1_file_path="$HOME/2.13-Ink-screen-clock/bin/$service1_path"
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
SERVICE_PATH="raspi_e-Paper.service" # 检查墨水屏时钟仓库是否存在
SERVICE1_PATH="e-Paper_clean.service" if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then
SERVICE_FILE_PATH="$HOME/2.13-Ink-screen-clock/bin/$SERVICE_PATH" echo "正在克隆仓库"
SERVICE1_FILE_PATH="$HOME/2.13-Ink-screen-clock/bin/$SERVICE1_PATH" cd ~
if [ -f "$SERVICE_FILE_PATH" ] && [ -f "$SERVICE1_FILE_PATH" ]; then if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then
# 复制服务文件到 systemd 目录 echo "克隆仓库失败" >&2
if sudo cp "$SERVICE_FILE_PATH" /etc/systemd/system/ && sudo cp "$SERVICE1_FILE_PATH" /etc/systemd/system/; then exit 1
# 重载 systemd 管理器配置 fi
sudo systemctl daemon-reload # 设置start.sh和clean.sh脚本的执行权限
# 启动服务 chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh"
sudo systemctl enable $SERVICE_PATH chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh"
sudo systemctl enable $SERVICE1_PATH
sudo systemctl start $SERVICE_PATH
else 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
echo "正在复制服务文件并启用服务"
# 复制服务文件到 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 exit 1
fi fi
else
echo "服务文件不存在于路径: $SERVICE_FILE_PATH$SERVICE1_FILE_PATH" >&2
exit 1
fi
} }
# 主逻辑 # 主逻辑
# 检测是否是Debian系统 # 检测是否是Debian系统
if [ -f /etc/debian_version ]; then if [ -f /etc/debian_version ]; then
debug "检测到Debian系统" echo "检测到Debian$DEBIAN_VERSION系统"
# 提取版本号的小数点前的部分 # 提取版本号的小数点前的部分
if ! MAJOR_VERSION=$(echo $DEBIAN_VERSION | cut -d '.' -f 1); then if ! MAJOR_VERSION=$(echo $DEBIAN_VERSION | cut -d '.' -f 1); then
@@ -175,19 +261,19 @@ if [ -f /etc/debian_version ]; then
# 检测是否是Raspberry Pi系统 # 检测是否是Raspberry Pi系统
if is_raspberry_pi; then if is_raspberry_pi; then
debug "检测到Raspberry Pi系统" echo "检测到Raspberry Pi系统"
# 根据版本号的小数点前的部分执行不同的命令 # 根据版本号的小数点前的部分执行不同的命令
case "$MAJOR_VERSION" in case "$MAJOR_VERSION" in
11) 11)
debug "执行Debian 11 (Bullseye) 相关操作" echo "执行Debian 11 (Bullseye) 相关操作"
update_sources_list "bullseye" update_sources_list "bullseye"
install_packages install_packages
install_pip_packages install_pip_packages
setup_service setup_service
;; ;;
12) 12)
debug "执行Debian 12 (Bookworm) 相关操作" echo "执行Debian 12 (Bookworm) 相关操作"
update_sources_list "bookworm" update_sources_list "bookworm"
install_packages install_packages
install_pip_packages install_pip_packages

View File

@@ -32,7 +32,7 @@ def Local_strong_brush(): #局部强制刷新显示
i = i + 1 i = i + 1
def getWeath(city='101060111'): #天气函数,下载json天气至本地 def getWeath(city='101060111'): #天气函数,下载json天气至本地
headers = { headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 Edg/94.0.992.50', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'Referer':'http://www.weather.com.cn/' 'Referer':'http://www.weather.com.cn/'
} }
response = requests.get('http://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers) response = requests.get('http://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers)
@@ -66,25 +66,8 @@ def Memory_footprint():#显示内存占用百分比
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk')) return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk'))
def CPU_usage(): #显示CPU占用百分比 def CPU_usage(): #显示CPU占用百分比
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())))) return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))))
def power_battery(): def power_battery():#获取当前电池电量
try: return(str(int(subprocess.check_output(u"echo \"get battery\" | nc -q 0 127.0.0.1 8423|awk -F':' '{print int($2)}'", shell = True ).decode('gbk')))+u'%')
# 获取电池电量
battery_percentage = subprocess.check_output(
"echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print $2}'",
shell=True,
text=True
).strip()
# 检查电量信息
if not battery_percentage:
return "无效"
# 返回电量百分比
return f"{int(battery_percentage)}%"
except Exception as e:
# 返回错误信息
return "失败"
# 打印电量信息 # 打印电量信息
print(power_battery()) print(power_battery())
def Bottom_edge(): #在图片中添加底边内容 def Bottom_edge(): #在图片中添加底边内容
@@ -141,10 +124,6 @@ def Weather(): #在图片中添加天气内容
def Basic_refresh(): #全刷函数 def Basic_refresh(): #全刷函数
logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容 logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容
epd.init()
epd.Clear(0xFF)
epd.init()
epd.Clear(0xFF)
global get_date_var global get_date_var
get_date_var=get_date() #记录开始数据 get_date_var=get_date() #记录开始数据
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕 draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕

View File

@@ -1,11 +1,11 @@
[Unit] [Unit]
Description=Raspi e-Paper Service Description=Raspi e-Paper Service
After=network-online.target After=network.target
[Service] [Service]
Type=forking 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 ExecStart=/root/2.13-Ink-screen-clock/bin/start.sh
ExecStop=/usr/bin/screen -S main_screen -X quit ExecStop=/usr/bin/screen -S main_screen -X quit
Restart=on-failure Restart=on-failure

View File

@@ -1,15 +1,10 @@
#!/bin/bash #!/bin/bash
f_name=main.py f_name=main.py
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir=${dir%/*} logdir=${dir%/*}
screen_name="main_screen" pid=`ps -ef |grep $dir/$f_name | grep -v grep |awk '{print $2}'`
for id in $pid
# 查找并结束所有与指定screen_name相关的screen会话 do
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}') kill -9 $id
for pid in $pids; do
screen -S $pid -X quit
done done
nohup /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1 &
# 创建一个新的screen会话并运行Python脚本
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1

BIN
pic/1736672578025.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 MiB