mirror of
https://github.com/kxgx/2.13-Ink-screen-clock.git
synced 2026-03-26 08:59:44 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5436cba3d0 | ||
|
|
70d1b3d710 | ||
|
|
6fa3fe1407 | ||
|
|
cd6fc91cda | ||
|
|
60272f75ea | ||
|
|
faf0e2f505 | ||
|
|
863e9b2f5d | ||
|
|
d523a31006 | ||
|
|
9d4895fca4 | ||
|
|
e7f71c699e | ||
|
|
419f44be7e |
95
app/app.py
95
app/app.py
@@ -1,95 +0,0 @@
|
||||
from flask import Flask, render_template, request, send_from_directory
|
||||
import os
|
||||
import re
|
||||
|
||||
app = Flask(__name__, template_folder='webui', static_url_path='', static_folder='webui')
|
||||
FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'pic') # 字体文件夹路径
|
||||
|
||||
def list_font_files(font_dir):
|
||||
try:
|
||||
return os.listdir(font_dir)
|
||||
except Exception as e:
|
||||
print(f"Error listing font files: {e}")
|
||||
return [] # 返回空列表以避免迭代错误
|
||||
|
||||
def update_main_py_font_names(font_names):
|
||||
main_py_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'main.py')
|
||||
try:
|
||||
with open(main_py_path, 'r') as file:
|
||||
content = file.read()
|
||||
|
||||
# 为每个字体变量定义正则表达式模式
|
||||
patterns = {
|
||||
'font01': re.compile(r"(?<=font01\s*=\s*ImageFont\.truetype\(\s*os\.path\.join\(picdir,\s*)'[^']+'(?=\s*,\s*20\s*\))"),
|
||||
'font02': re.compile(r"(?<=font02\s*=\s*ImageFont\.truetype\(\s*os\.path\.join\(picdir,\s*)'[^']+'(?=\s*,\s*15\s*\))"),
|
||||
'font03': re.compile(r"(?<=font03\s*=\s*ImageFont\.truetype\(\s*os\.path\.join\(picdir,\s*)'[^']+'(?=\s*,\s*38\s*\))"),
|
||||
'font04': re.compile(r"(?<=font04\s*=\s*ImageFont\.truetype\(\s*os\.path\.join\(picdir,\s*)'[^']+'(?=\s*,\s*10\s*\))"),
|
||||
'font05': re.compile(r"(?<=font05\s*=\s*ImageFont\.truetype\(\s*os\.path\.join\(picdir,\s*)'[^']+'(?=\s*,\s*12\s*\))"),
|
||||
'font06': re.compile(r"(?<=font06\s*=\s*ImageFont\.truetype\(\s*os\.path\.join\(picdir,\s*)'[^']+'(?=\s*,\s*13\s*\))"),
|
||||
}
|
||||
|
||||
# 使用正则表达式替换字体文件名
|
||||
for font_var, font_name in font_names.items():
|
||||
pattern = patterns.get(font_var)
|
||||
if pattern:
|
||||
# 确保字体文件名被正确地转义
|
||||
safe_font_name = re.escape(font_name)
|
||||
content = pattern.sub(f"'{safe_font_name}'", content)
|
||||
|
||||
with open(main_py_path, 'w') as file:
|
||||
file.write(content)
|
||||
except Exception as e:
|
||||
print(f"Error updating main.py: {e}")
|
||||
return False
|
||||
return True
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
font_files = list_font_files(FONT_DIR)
|
||||
return render_template('index.html', font_files=font_files)
|
||||
|
||||
@app.route('/upload', methods=['POST'])
|
||||
def upload():
|
||||
if 'font_file' not in request.files:
|
||||
return '没有文件部分'
|
||||
file = request.files['font_file']
|
||||
if file.filename == '':
|
||||
return '没有选择文件'
|
||||
if file:
|
||||
filename = os.path.join(FONT_DIR, file.filename)
|
||||
file.save(filename)
|
||||
return '文件已上传成功'
|
||||
|
||||
@app.route('/update_font_names')
|
||||
def update_font_names():
|
||||
font_files = list_font_files(FONT_DIR)
|
||||
return render_template('update_font_names.html', font_files=font_files)
|
||||
|
||||
@app.route('/save_font_names', methods=['POST'])
|
||||
def save_font_names():
|
||||
# 获取表单数据
|
||||
font_names = {
|
||||
'font01': request.form.get('font01'),
|
||||
'font02': request.form.get('font02'),
|
||||
'font03': request.form.get('font03'),
|
||||
'font04': request.form.get('font04'),
|
||||
'font05': request.form.get('font05'),
|
||||
'font06': request.form.get('font06'),
|
||||
}
|
||||
|
||||
# 更新 main.py 中的字体文件名
|
||||
if update_main_py_font_names(font_names):
|
||||
return '字体文件名已保存'
|
||||
else:
|
||||
return '保存字体文件名时发生错误', 500
|
||||
|
||||
@app.route('/fonts/<filename>')
|
||||
def fonts(filename):
|
||||
return send_from_directory(FONT_DIR, filename)
|
||||
|
||||
if not os.path.exists(FONT_DIR):
|
||||
os.makedirs(FONT_DIR)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 绑定到0.0.0.0,允许远程访问
|
||||
app.run(host='0.0.0.0', port=80, debug=False)
|
||||
@@ -1,23 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>字体上传和管理</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>上传字体文件</h1>
|
||||
<form method="post" action="/upload" enctype="multipart/form-data">
|
||||
<input type="file" name="font_file">
|
||||
<input type="submit" value="上传">
|
||||
</form>
|
||||
|
||||
<h2>已上传的字体文件:</h2>
|
||||
<ul>
|
||||
{% for font_file in font_files %}
|
||||
<li>{{ font_file }}</li>
|
||||
{% else %}
|
||||
<li>没有找到字体文件。</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,26 +0,0 @@
|
||||
<!-- update_font_names.html -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>更新字体文件名</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>更新字体文件名</h1>
|
||||
<form method="post" action="/save_font_names">
|
||||
<label for="font01">字体文件名 01:</label>
|
||||
<input type="text" id="font01" name="font01"><br>
|
||||
<label for="font02">字体文件名 02:</label>
|
||||
<input type="text" id="font02" name="font02"><br>
|
||||
<label for="font03">字体文件名 03:</label>
|
||||
<input type="text" id="font03" name="font03"><br>
|
||||
<label for="font04">字体文件名 04:</label>
|
||||
<input type="text" id="font04" name="font04"><br>
|
||||
<label for="font05">字体文件名 05:</label>
|
||||
<input type="text" id="font05" name="font05"><br>
|
||||
<label for="font06">字体文件名 06:</label>
|
||||
<input type="text" id="font06" name="font06"><br>
|
||||
<input type="submit" value="保存">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
112
bin/install.sh
112
bin/install.sh
@@ -18,6 +18,8 @@ USE_CN_GIT=false
|
||||
USE_PISUGAR_WIFI_CONF=false
|
||||
# 检查是否安装pisugar-power-manager
|
||||
USE_PISUGAR_POWER_MANAGER=false
|
||||
# 检查是否安装webui
|
||||
#INSTALL_WEBUI=false
|
||||
|
||||
# 解析命令行参数
|
||||
while [ "$#" -gt 0 ]; do
|
||||
@@ -37,6 +39,9 @@ while [ "$#" -gt 0 ]; do
|
||||
--pisugar-power-manager)
|
||||
USE_PISUGAR_POWER_MANAGER=true
|
||||
;;
|
||||
# --webui)
|
||||
# INSTALL_WEBUI=true
|
||||
# ;;
|
||||
--version)
|
||||
if [ -z "$2" ]; then
|
||||
echo "错误: --version 参数后需要跟版本号"
|
||||
@@ -121,25 +126,14 @@ is_raspberry_pi() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 定义链接变量
|
||||
DEBIAN_MIRROR="http://deb.debian.org/debian/"
|
||||
DEBIAN_SECURITY_MIRROR="http://security.debian.org/"
|
||||
PISUGAR_WIFI_CONF_URL="https://cdn.pisugar.com/PiSugar-wificonfig/script/install.sh"
|
||||
PISUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh"
|
||||
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.tuna.tsinghua.edu.cn/debian/"
|
||||
# 使用中国镜像源
|
||||
DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian"
|
||||
DEBIAN_SECURITY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian-security"
|
||||
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
|
||||
RASPBERRY_PI_SOURCE_DEBIAN11="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi"
|
||||
RASPBERRY_PI_SOURCE_DEBIAN12="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi"
|
||||
|
||||
|
||||
# 定义仓库链接变量
|
||||
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock"
|
||||
@@ -155,6 +149,7 @@ update_sources_list() {
|
||||
local raspberry_pi_source_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list.d/raspi.list | head -1)
|
||||
|
||||
# 检查并替换 Debian 源
|
||||
if [ "$USE_CN_MIRROR" = true ]; then
|
||||
if [ "$debian_mirror_in_use" != "$DEBIAN_MIRROR" ]; then
|
||||
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
|
||||
{
|
||||
@@ -196,12 +191,13 @@ update_sources_list() {
|
||||
else
|
||||
echo "Raspberry Pi 源链接已更新,跳过替换" >&2
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 安装包函数
|
||||
install_packages() {
|
||||
echo "正在更新源列表"
|
||||
if ! sudo apt-get -q -y update; then
|
||||
if ! sudo apt-get -q update; then
|
||||
echo "更新源列表失败" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -294,6 +290,86 @@ install_pisugar-wifi-conf() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 如果指定了--webui参数,则添加Nginx配置
|
||||
install_webui() {
|
||||
if [ "$INSTALL_WEBUI" = true ]; then
|
||||
WEBUI_FILE="/root/2.13-Ink-screen-clock/webui"
|
||||
NGINX_WEBUI_FILE="/var/www/html"
|
||||
echo "正在安装并配置webui"
|
||||
echo "正在安装软件包"
|
||||
if ! sudo apt-get update && sudo apt-get -q -y install nginx php7.4-fpm; then
|
||||
echo "软件包安装失败" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "正在复制webui文件"
|
||||
if ! sudo cp -r "$WEBUI_FILE" "$NGINX_WEBUI_FILE"; then
|
||||
echo "webui文件复制失败" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "正在修改nginx配置文件"
|
||||
# 定义Nginx主配置文件的路径
|
||||
NGINX_CONFIG_PATH="/etc/nginx/nginx.conf"
|
||||
NGINX_CONFIG_BAK="$NGINX_CONFIG_PATH.bak"
|
||||
|
||||
# 备份现有的Nginx配置文件
|
||||
cp "$NGINX_CONFIG_PATH" "$NGINX_CONFIG_BAK"
|
||||
echo "已备份现有Nginx配置文件到 $NGINX_CONFIG_BAK"
|
||||
|
||||
# 定义文件路径变量
|
||||
WEBROOT_PATH="$NGINX_WEBUI_FILE"
|
||||
CGI_BIN_PATH="$WEBROOT_PATH/cgi-bin"
|
||||
CGI_PASS="127.0.0.1:9000" # 根据您的CGI服务器配置
|
||||
|
||||
# 定义要添加的服务器配置
|
||||
SERVER_CONFIG="
|
||||
server {
|
||||
listen 80;
|
||||
server_name 0.0.0.0;
|
||||
|
||||
location / {
|
||||
root $WEBROOT_PATH;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
location /save.py {
|
||||
include snippets/fastcgi-php.conf;
|
||||
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据您的PHP版本进行调整
|
||||
fastcgi_param SCRIPT_FILENAME \$document_root/save.py;
|
||||
add_header X-Robots-Tag \"noindex,noarchive,nosnippet,nofollow\";
|
||||
auth_basic \"Restricted Content\";
|
||||
auth_basic_user_file /etc/nginx/.htpasswd; # 确保您有.htpasswd文件用于基本认证
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
# 检查是否已经存在类似的server配置
|
||||
if ! grep -q 'server_name 0.0.0.0;' "$NGINX_CONFIG_PATH"; then
|
||||
# 如果不存在,将配置添加到http块中
|
||||
awk -v config="$SERVER_CONFIG" '
|
||||
/http {/ {
|
||||
print
|
||||
print config
|
||||
next
|
||||
}
|
||||
1
|
||||
' "$NGINX_CONFIG_PATH" > temp && mv temp "$NGINX_CONFIG_PATH"
|
||||
else
|
||||
echo "服务器配置已存在,未进行修改"
|
||||
fi
|
||||
|
||||
# 测试Nginx配置
|
||||
nginx -t
|
||||
|
||||
# 如果配置测试成功,则重启Nginx
|
||||
if [ $? -eq 0 ]; then
|
||||
systemctl restart nginx
|
||||
echo "Nginx配置已成功应用并重启"
|
||||
else
|
||||
echo "Nginx配置测试失败,请检查配置文件"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 主逻辑
|
||||
# 检测是否是Debian系统
|
||||
if [ -f /etc/debian_version ]; then
|
||||
@@ -317,6 +393,7 @@ if [ -f /etc/debian_version ]; then
|
||||
install_packages
|
||||
install_pip_packages
|
||||
setup_service
|
||||
#install_webui
|
||||
install_pisugar-wifi-conf
|
||||
install_pisugar-power-manager
|
||||
;;
|
||||
@@ -326,6 +403,7 @@ if [ -f /etc/debian_version ]; then
|
||||
install_packages
|
||||
install_pip_packages
|
||||
setup_service
|
||||
#install_webui
|
||||
install_pisugar-wifi-conf
|
||||
install_pisugar-power-manager
|
||||
;;
|
||||
|
||||
@@ -252,4 +252,4 @@ epd.init()
|
||||
epd.Clear(0xFF) # 清除屏幕内容
|
||||
epd.sleep() # 使屏幕进入休眠状态
|
||||
epd2in13_V4.epdconfig.module_exit() # 清理资源
|
||||
exit()
|
||||
exit()
|
||||
@@ -96,4 +96,4 @@ except Exception as e:
|
||||
exit()
|
||||
|
||||
# 脚本正常结束后的清理操作
|
||||
exit()
|
||||
exit()
|
||||
9
webui/default.min.css
vendored
Normal file
9
webui/default.min.css
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/*!
|
||||
Theme: Default
|
||||
Description: Original highlight.js style
|
||||
Author: (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
|
||||
Maintainer: @highlightjs/core-team
|
||||
Website: https://highlightjs.org/
|
||||
License: see project LICENSE
|
||||
Touched: 2021
|
||||
*/pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}
|
||||
1213
webui/highlight.min.js
vendored
Normal file
1213
webui/highlight.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
40
webui/index.html
Normal file
40
webui/index.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ace-editor@1.4.12/css/ace.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/ace-editor@1.4.12/js/ace.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>编辑 main.py</title>
|
||||
<style>
|
||||
#editor {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
font-family: monospace;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>编辑 main.py</h1>
|
||||
<form action="/save.py" method="post">
|
||||
<div id="editor"><?php echo file_get_contents('/root/2.13-Ink-screen-clock/bin/main.py'); ?></div>
|
||||
<input type="hidden" name="content" id="hidden-content">
|
||||
<br>
|
||||
<input type="submit" value="保存">
|
||||
</form>
|
||||
<script>
|
||||
// 初始化 Ace Editor
|
||||
var editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.getSession().setMode("ace/mode/python");
|
||||
editor.setValue(<?php echo json_encode(file_get_contents($filePath)); ?>);
|
||||
|
||||
// 在表单提交前将编辑器内容赋值给隐藏的textarea
|
||||
document.querySelector('form').addEventListener('submit', function() {
|
||||
document.getElementById('hidden-content').value = editor.getValue();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
23
webui/save.py
Normal file
23
webui/save.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
|
||||
# 设置文件路径
|
||||
file_path = '/root/2.13-Ink-screen-clock/bin/main.py'
|
||||
|
||||
# 读取POST数据
|
||||
content_length = int(os.environ.get('CONTENT_LENGTH', 0))
|
||||
content = sys.stdin.read(content_length)
|
||||
|
||||
# 保存文件
|
||||
try:
|
||||
with open(file_path, 'w') as file:
|
||||
file.write(content)
|
||||
response = "<h1>文件保存成功!</h1>"
|
||||
except Exception as e:
|
||||
response = "<h1>文件保存失败:{}</h1>".format(e)
|
||||
|
||||
# 返回响应
|
||||
print("Content-Type: text/html")
|
||||
print()
|
||||
print(response)
|
||||
Reference in New Issue
Block a user