起源
使用http在局域网中分享文件库可谓非常方便,以前在Linux中进行局域网文件分享使用的是woof,是一个用python写的脚本,前几天在开源社区看到了dufs,一个使用rust写的web文件共享服务。怀着对rust的憧憬,本文就从这里构建一个可以在开发板上使用的dufs。
开发板架构
使用RK平台的RK3568,aarch64 Linux系统
开源链接
https://github.com/sigoden/dufs
构建过程
由于之前已经有过rust交叉编译的经历,由于我使用的不是gun官方的工具链,所以工具链名称上会有所区别
创建默认构建配置
.cargo/config.toml
[build]
target = "aarch64-unknown-linux-gnu"
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
构建的过程发现在构建ring的过程中报错,原来是强行绑定了编译工具链名称,将所有的工具链全部重新命名:
mv aarch64-buildroot-linux-gnu-addr2line aarch64-linux-gnu-addr2line
mv aarch64-buildroot-linux-gnu-gcc.br_real aarch64-linux-gnu-gcc.br_real
mv aarch64-buildroot-linux-gnu-ar aarch64-linux-gnu-ar
mv aarch64-buildroot-linux-gnu-gcc-nm aarch64-linux-gnu-gcc-nm
mv aarch64-buildroot-linux-gnu-as aarch64-linux-gnu-as
mv aarch64-buildroot-linux-gnu-gcc-ranlib aarch64-linux-gnu-gcc-ranlib
mv aarch64-buildroot-linux-gnu-c++ aarch64-linux-gnu-c++
mv aarch64-buildroot-linux-gnu-gcov aarch64-linux-gnu-gcov
mv aarch64-buildroot-linux-gnu-c++.br_real aarch64-linux-gnu-c++.br_real
mv aarch64-buildroot-linux-gnu-gcov-dump aarch64-linux-gnu-gcov-dump
mv aarch64-buildroot-linux-gnu-cc aarch64-linux-gnu-cc
mv aarch64-buildroot-linux-gnu-gcov-tool aarch64-linux-gnu-gcov-tool
mv aarch64-buildroot-linux-gnu-cc.br_real aarch64-linux-gnu-cc.br_real
mv aarch64-buildroot-linux-gnu-gprof aarch64-linux-gnu-gprof
mv aarch64-buildroot-linux-gnu-c++filt aarch64-linux-gnu-c++filt
mv aarch64-buildroot-linux-gnu-ld aarch64-linux-gnu-ld
mv aarch64-buildroot-linux-gnu-cpp aarch64-linux-gnu-cpp
mv aarch64-buildroot-linux-gnu-ld.bfd aarch64-linux-gnu-ld.bfd
mv aarch64-buildroot-linux-gnu-cpp.br_real aarch64-linux-gnu-cpp.br_real
mv aarch64-buildroot-linux-gnu-lto-dump aarch64-linux-gnu-lto-dump
mv aarch64-buildroot-linux-gnu-elfedit aarch64-linux-gnu-elfedit
mv aarch64-buildroot-linux-gnu-nm aarch64-linux-gnu-nm
mv aarch64-buildroot-linux-gnu-g++ aarch64-linux-gnu-g++
mv aarch64-buildroot-linux-gnu-objcopy aarch64-linux-gnu-objcopy
mv aarch64-buildroot-linux-gnu-g++.br_real aarch64-linux-gnu-g++.br_real
mv aarch64-buildroot-linux-gnu-objdump aarch64-linux-gnu-objdump
mv aarch64-buildroot-linux-gnu-gcc aarch64-linux-gnu-gcc
mv aarch64-buildroot-linux-gnu-ranlib aarch64-linux-gnu-ranlib
mv aarch64-buildroot-linux-gnu-gcc-10.3.0 aarch64-linux-gnu-gcc-10.3.0
mv aarch64-buildroot-linux-gnu-readelf aarch64-linux-gnu-readelf
mv aarch64-buildroot-linux-gnu-gcc-10.3.0.br_real aarch64-linux-gnu-gcc-10.3.0.br_real
mv aarch64-buildroot-linux-gnu-size aarch64-linux-gnu-size
mv aarch64-buildroot-linux-gnu-gcc-ar aarch64-linux-gnu-gcc-ar
mv aarch64-buildroot-linux-gnu-strings aarch64-linux-gnu-strings
然后就可以轻松构建出可以在开发板上运行的程序了。
./dufs -h
Dufs is a distinctive utility file server - https://github.com/sigoden/dufs
Usage: dufs [OPTIONS] [serve_path]
Arguments:
[serve_path] Specific path to serve [default: .]
Options:
-b, --bind <addrs> Specify bind address or unix socket
-p, --port <port> Specify port to listen on [default: 5000]
--path-prefix <path> Specify a path prefix
--hidden <value> Hide paths from directory listings, separated by `,`
-a, --auth <rules> Add auth role
--auth-method <value> Select auth method [default: digest] [possible values: basic, digest]
-A, --allow-all Allow all operations
--allow-upload Allow upload files/folders
--allow-delete Allow delete files/folders
--allow-search Allow search files/folders
--allow-symlink Allow symlink to files/folders outside root directory
--allow-archive Allow zip archive generation
--enable-cors Enable CORS, sets `Access-Control-Allow-Origin: *`
--render-index Serve index.html when requesting a directory, returns 404 if not found index.html
--render-try-index Serve index.html when requesting a directory, returns directory listing if not found index.html
--render-spa Serve SPA(Single Page Application)
--assets <path> Use custom assets to override builtin assets
--tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS
--tls-key <path> Path to the SSL/TLS certificate's private key
--log-format <format> Customize http log format
--completions <shell> Print shell completion script for <shell> [possible values: bash, elvish, fish, powershell, zsh]
-h, --help Print help
-V, --version Print version
开启服务共享文件试试:
上传文件:
发现报错,仔细看工具上的提示信息,发现默认情况上载是关闭的。重新运行
./tools/dufs -p 6007 ./www/books/ --allow-all
打开所有功能,此时上载成功。
使用curl获取文件清单,然后使用jq工具进行格式化json,就可以得到我们想要看到的文件清单了。
curl http://xxxxxxxxxxxxxx:6007/ | grep DATA | awk -F '=' '{print $2}' | jq .
同时可以解析对应的json文件获取清单的同时,也可以使用curl/wget进行文件下载,在根目录下可以直接使用文件名进行下载。
发现工具自带了获取文件清单的功能,推荐大家尝试
curl 127.0.0.1:5000?json # output paths in json format