海运的博客

N1盒子/arm64下cups使用兄弟打印机Brother HL-2260D的问题

发布时间:September 18, 2022 // 分类: // No Comments

x86/x64下安装打印机驱动,model name输入为:HL-2260D

wget https://d.brother-movie.com/driver/1480/linux-brprinter-installer-2.2.3-1.gz
gunzip linux-brprinter-installer-2.2.3-1.gz 
bash linux-brprinter-installer-2.2.3-1 

安装程序内包含二进制x86程序,在arm下安装会提示错误:

/opt/brother/Printers/HL2260D/inf/braddprinter: Exec format error  

可以在一台空闲x86上安装cups,然后通过usbip将n1下usb打印机桥接x86上管理。
n1内核为5.3,已编译usbip模块,下载linux-tool提取usbip管理工具:

apt download linux-raspi-tools-5.4.0-1035_5.4.0-1035.38_arm64.deb
dpkg -X linux-raspi-tools-5.4.0-1035_5.4.0-1035.38_arm64.deb linux-tools
cp linux-tools/usr/lib/linux-raspi-tools-5.4.0-1035/usbipd /usr/local/bin/
cp linux-tools/usr/lib/linux-raspi-tools-5.4.0-1035/usbip /usr/local/bin/
apt install usb.ids
mkdir /usr/share/hwdata/
ln -s /var/lib/usbutils/usb.ids /usr/share/hwdata//usb.ids

服务端使用:

modprobe usbip-core
modprobe usbip-host
modprobe vhci-hcd
/usr/local/bin/usbipd -D
/usr/local/bin/usbip list --local
/usr/local/bin/usbip bind --busid=1-2

service:

[Unit]
Description=usbip server
After=network.target


[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/usr/local/bin/usbipd
ExecStartPost=/usr/local/bin/usbip bind --busid=1-2

[Install]
WantedBy=multi-user.target

udev规则当usb插入时自动bind到usbip:

ACTION=="add" SUBSYSTEM=="usb" ATTRS{idVendor}=="04f9" ATTRS{idProduct}=="006d" RUN+="/usr/local/bin/usbip bind --busid=1-2"

如果内核无usbip支持,可通过第三方程序配置usbip服务端:

apt install libusb-1.0-0-dev
git clone https://github.com/raydudu/usbipd-libusb.git
cd 
mkdir usbipd-libusb/build
cd usbipd-libusb/build
cmake .. && make
./usbip_libusb -D 

x86 debian下挂载远程usb:

apt install usbip
modprobe vhci_hcd
usbip list -r 192.168.1.1
usbip attach -r 192.168.1.1 -b 1-2

自动usbip attach:

#!/bin/bash
set -x
while true; do
  if /usr/sbin/usbip port|grep -q "Brother" > /dev/null 2>&1; then
  else
    if /usr/sbin/usbip list -r 192.168.1.1|grep -q "Brother" &> /dev/null; then
      echo `date` 'start connect' >> /tmp/usbipd_log.txt
      /usr/sbin/usbip attach -r 192.168.1.1 -b 1-2
    else
      echo 'no exportable'
    fi
  fi
  sleep 10
done

客户端关闭时需detach,不然重接连接时需在服务端unbind:

usbip detach --port 00
usbip unbind --busid=1-2

service:

[Unit]
Description=usbip client
 
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/usr/sbin/usbip detach --port 00
 
[Install]
WantedBy=multi-user.target

在使用过程中如果出现以下错误:

usblp0: removed 
usblp 1-2: usblp0: USB Bidirectional printer dev 

禁用usblp并重启:

echo 'blacklist usblp' >> /etc/modprobe.d/usblp-blacklist.conf

apt源也有第三方兄弟打印机驱动,但是无hl-2260d版,不过使用其它型号也能正常使用。

apt install foomatic-db 
#或者
apt install printer-driver-brlaser

pve减少对ssd硬盘的写入量

发布时间:July 28, 2022 // 分类: // No Comments

禁用pve-ha-crm和pve-ha-lrm服务:

systemctl stop pve-ha-lrm.service pve-ha-crm.service
systemctl disable pve-ha-lrm.service pve-ha-crm.service

修改/etc/default/rrdcached:

#添加
WRITE_TIMEOUT=3600
FLUSH_TIMEOUT=7200
#注释此行
##JOURNAL_PATH=/var/lib/rrdcached/journal/

修改/etc/init.d/rrdcached变量RRDCACHED_OPTIONS处添加:

${FLUSH_TIMEOUT:+-f ${FLUSH_TIMEOUT}} \

重启rrdcached:

systemctl daemon-reload 
systemctl restart rrdcached.service 

https://forum.proxmox.com/threads/reducing-rrdcached-writes.64473/
https://pastebin.com/437dN33v
https://forum.proxmox.com/threads/pmxcfs-writing-to-disk-all-the-time.35828/

使用PaddleOCR图片文字识别

发布时间:July 21, 2022 // 分类: // No Comments

安装paddleocr:

apt install python3-pip libgl1
pip3 install paddlepaddle paddleocr

paddleocr cli使用:

paddleocr --image_dir test.jpg --lang ch --show_log False --det_db_unclip_ratio 2.5

python使用:

from paddleocr import PaddleOCR

ocr = PaddleOCR(use_angle_cls=True, lang="ch", det_db_score_mode="slow", show_log=False, use_gpu=False, det_db_unclip_ratio=2.5) 

img_path = 'test.jpg'
result = ocr.ocr(img_path, cls=True)
txts = [line[1][0] for line in result]
print(*txts)

如遇到错:

AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import)

安装指定版本opencv-python:

pip uninstall opencv-python
pip install opencv-python==4.5.5.64

https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/doc/doc_ch/inference_args.md

sftpgo为ftp/webdav添加支持软链接symlink目录和文件patch

发布时间:April 5, 2022 // 分类: // No Comments

之前有写为sftpgo添加匿名访问支持,还有个问题不能访问链接文件,基于sftpgo2.2.2修改制作了个patch以支持软链接,linux下测试通过,windows未测试。

diff -urN -x .git sftpgo/common/connection.go sftpgo3/common/connection.go
--- sftpgo/common/connection.go 2022-04-04 15:06:39.542187282 +0800
+++ sftpgo3/common/connection.go        2022-04-04 14:57:31.027102136 +0800
@@ -242,6 +242,27 @@
                c.Log(logger.LevelDebug, "error listing directory: %+v", err)
                return nil, c.GetFsError(fs, err)
        }
+       if c.protocol == ProtocolWebDAV || c.protocol == ProtocolFTP {
+               for k, file := range files {
+                       if file.Mode()&os.ModeSymlink != 0 {
+                               dst, err := os.Readlink(fsPath + "/" + file.Name())
+                               if err != nil {
+                                       c.Log(logger.LevelError, "error readlink: %#v error: %+v", fsPath+"/"+file.Name(), err)
+                                       continue
+                               }
+                               dstinfo, err := os.Stat(dst)
+                               if err != nil {
+                                       c.Log(logger.LevelError, "error stat: %#v error: %+v", dst, err)
+                                       continue
+                               }
+                               if dstinfo.IsDir() {
+                                       files[k] = vfs.NewFileInfo(file.Name(), true, 0, dstinfo.ModTime(), false)
+                               } else {
+                                       files[k] = vfs.NewFileInfo(file.Name(), false, dstinfo.Size(), dstinfo.ModTime(), false)
+                               }
+                       }
+               }
+       }
        return c.User.AddVirtualDirs(files, virtualPath), nil
 }
 
diff -urN -x .git sftpgo/ftpd/handler.go sftpgo3/ftpd/handler.go
--- sftpgo/ftpd/handler.go      2022-04-04 15:06:39.550187152 +0800
+++ sftpgo3/ftpd/handler.go     2022-04-04 14:55:41.368885080 +0800
@@ -14,7 +14,7 @@
        "github.com/drakkan/sftpgo/v2/common"
        "github.com/drakkan/sftpgo/v2/dataprovider"
        "github.com/drakkan/sftpgo/v2/logger"
-       "github.com/drakkan/sftpgo/v2/util"
+       //"github.com/drakkan/sftpgo/v2/util"
        "github.com/drakkan/sftpgo/v2/vfs"
 )
 
@@ -288,10 +288,12 @@
        if err != nil {
                return files, err
        }
-       if name != "/" {
-               files = util.PrependFileInfo(files, vfs.NewFileInfo("..", true, 0, time.Now(), false))
-       }
-       files = util.PrependFileInfo(files, vfs.NewFileInfo(".", true, 0, time.Now(), false))
+       /*
+               if name != "/" {
+                       files = util.PrependFileInfo(files, vfs.NewFileInfo("..", true, 0, time.Now(), false))
+               }
+               files = util.PrependFileInfo(files, vfs.NewFileInfo(".", true, 0, time.Now(), false))
+       */
        return files, nil
 }
 
diff -urN -x .git sftpgo/vfs/osfs.go sftpgo3/vfs/osfs.go
--- sftpgo/vfs/osfs.go  2022-04-04 15:06:39.574186762 +0800
+++ sftpgo3/vfs/osfs.go 2022-04-04 14:59:06.413551648 +0800
@@ -291,6 +291,7 @@
                virtualPath = strings.TrimPrefix(virtualPath, fs.mountPath)
        }
        r := filepath.Clean(filepath.Join(fs.rootDir, virtualPath))
+       return r, nil
        p, err := filepath.EvalSymlinks(r)
        if err != nil && !os.IsNotExist(err) {
                return "", err

1.修改vfs/osfs.go文件取消对链接目标的校验是否在家目录内,这时部分客户端已正常,因为sftpgo返回链接目录属性为l而非d,导致有的客户端将链接目录识别为文件。
2.修改common/connection.go文件是修改返回的链接目录/文件的属性为标准目录和文件。
参考:
https://github.com/drakkan/sftpgo/issues/336

sftpgo为ftp/webdav/sftp添加匿名anonymous访问

发布时间:April 5, 2022 // 分类: // No Comments

仅通过check_password_hook验证用户,用户信息使用web配置,将以下脚本保存为文件添加到sftpgo.json配置文件内check_password_hook参数。

#!/bin/bash -eu
#if [[ "${SFTPGO_AUTHD_USERNAME}" = "guest" ]] && [[ "${SFTPGO_AUTHD_PASSWORD}" = "pass" ]]; then
if [[ "${SFTPGO_AUTHD_USERNAME}" = "anonymous" ]] || [[ "${SFTPGO_AUTHD_USERNAME}" = "guest" ]]; then
cat <<EOF
{
  "status": 1
}
EOF
exit 0
fi

使用external_auth_hook外部验证用户并直接返回虚拟目录权限等信息:

#!/bin/bash -eu
if [[ "${SFTPGO_AUTHD_USERNAME}" = "anonymous" ]] || [[ "${SFTPGO_AUTHD_USERNAME}" = "guest" ]]; then
cat <<EOF
{
  "status": 1,
  "username": "${SFTPGO_AUTHD_USERNAME}",
  "home_dir": "/data/ftp",
  "permissions": {
    "/": ["list", "download"]
  },
  "virtual_folders": [
    {
      "name": "dir1",
      "mapped_path": "/data/dir1",
      "virtual_path": "/dir1"
    }, 
    {
      "name": "dir2",
      "mapped_path": "/data/dir2",
      "virtual_path": "/dir2"
    } 
  ]
}
EOF
fi

ftp/webdav匿名访问允许空密码patch:

diff -urN -x .git sftpgo2/ftpd/server.go sftpgo/ftpd/server.go
--- sftpgo2/ftpd/server.go      2022-04-05 18:55:25.959456839 +0800
+++ sftpgo/ftpd/server.go       2022-04-05 19:01:32.841334341 +0800
@@ -9,6 +9,7 @@
        "os"
        "path/filepath"
        "sync"
+        "strings"
 
        ftpserver "github.com/fclairamb/ftpserverlib"
 
@@ -182,6 +183,9 @@
 
 // AuthUser authenticates the user and selects an handling driver
 func (s *Server) AuthUser(cc ftpserver.ClientContext, username, password string) (ftpserver.ClientDriver, error) {
+       if len(strings.TrimSpace(password)) == 0 {
+               password = "guest"
+       }
        loginMethod := dataprovider.LoginMethodPassword
        if s.isTLSConnVerified(cc.ID()) {
                loginMethod = dataprovider.LoginMethodTLSCertificateAndPwd

diff -urN -x .git sftpgo2/webdavd/server.go sftpgo/webdavd/server.go
--- sftpgo2/webdavd/server.go   2022-04-05 18:55:25.995456233 +0800
+++ sftpgo/webdavd/server.go    2022-04-05 19:01:44.537140407 +0800
@@ -13,6 +13,7 @@
        "path/filepath"
        "runtime/debug"
        "time"
+        "strings"
 
        "github.com/go-chi/chi/v5/middleware"
        "github.com/rs/cors"
@@ -232,6 +233,9 @@
        var tlsCert *x509.Certificate
        loginMethod := dataprovider.LoginMethodPassword
        username, password, ok := r.BasicAuth()
+       if len(strings.TrimSpace(password)) == 0 {
+               password = "guest"
+       }
        if s.binding.isMutualTLSEnabled() && r.TLS != nil {
                if len(r.TLS.PeerCertificates) > 0 {
                        tlsCert = r.TLS.PeerCertificates[0]

参考:
https://github.com/drakkan/sftpgo/issues/373
https://github.com/drakkan/sftpgo/blob/main/docs/check-password-hook.md
https://github.com/drakkan/sftpgo/blob/main/docs/external-auth.md

分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
归档