OpenWrt 系列优化 3
apk
open wrt 从 24.10 之后就开始使用 apk 来作为 包管理器了。
这个改进非常好,如果你用过 Alpine,你会发现 这两个发行版越来越相似,他们都还有一个共性,就是非常轻量级,和节省资源。
apk 的 API 整体要更简洁,安装器相对 opkg 兼容性更强。比较关键的是,不用额外再记一套API了,我非常赞成 openwrt 对包管理器作出的改进。
OpenWrt recently switched to the "apk" package manager!
OPKG Command APK Equivalent Description
------------------------------------------------------------------
opkg install <pkg> apk add <pkg> Install a package
opkg remove <pkg> apk del <pkg> Remove a package
opkg upgrade apk upgrade Upgrade all packages
opkg files <pkg> apk info -L <pkg> List package contents
opkg list-installed apk info List installed packages
opkg update apk update Update package lists
opkg search <pkg> apk search <pkg> Search for packages
------------------------------------------------------------------
For more https://openwrt.org/docs/guide-user/additional-software/opkg-to-apk-cheatsheet
安装 dotnet 9.0
参考了 reddit 一个作者的安装脚本,当然 自己一步步执行会更稳妥。
https://www.reddit.com/r/linux/comments/1bqvgx5/howto_c_aspnet_and_net_core_on_openwrt/
首先安装 icu-full
# 更新源
apk update
# 安装之前先搜一下,也许你在用的时候,data的版本高于77了
apk search icu-full
# 这里搜到的完整名称是这个,那就安装这个
apk add icu-full-data77
可以保存这个脚本到 ~/dotnet-install.sh
, 也可以自己一步步执行(推荐)。
# Change this if the structure of the tar.gz archive ever changes
FILES_TO_BE_INSTALLED="*" # in a lot of archives, the install files are actaully in a subdir named after the package (package.tar.gz/package/* instead of package.tar.gz/*)
# Download URL (如果想安装其他版本,换掉这里的下载链接即可)
# 从这里找:https://dotnet.microsoft.com/zh-cn/download/dotnet/9.0
URL="https://builds.dotnet.microsoft.com/dotnet/Sdk/9.0.203/dotnet-sdk-9.0.203-linux-musl-arm64.tar.gz"
# Download and extract destination name
DOWNLOAD=dotnet
# Install path:
INSTALL="/usr/lib/dotnet"
# 这里在 普通路由器上可能会出问题,/tmp 分区是不够大的(下载~200M,解压缩~400M)。
# 可以换成 mkdir -p /root/tmp.dotnet && cd /root/tmp.dotnet
cd $(mktemp -d)
# Download and extract:
wget $URL -O "$DOWNLOAD.tar.gz"
mkdir $DOWNLOAD
tar -xzvf "$DOWNLOAD.tar.gz" -C $DOWNLOAD
# Install:
mkdir -p "$INSTALL"
cp -R \
./$DOWNLOAD/$FILES_TO_BE_INSTALLED \
$INSTALL
# chmod +x any files as necessary
export PATH="$PATH:$INSTALL:$INSTALL/tools"
echo "export PATH=\"\$PATH:$INSTALL:$INSTALL/tools\"" >> /etc/profile
dotnet --version
一些坑点
我之前好像用过官方的安装脚本,但是安装失败了,对比这次 总结了一下,主要原因有:
- 没有安装
icu-full
- 没有使用alpine的musl的预构建版
- reddit的老哥是选的
musl-x64
版本的,注意不要直接下载 - 普通的路由器一般都是
arm64
平台的, 而且 openwrt 用的 clib 是 musl,所以一定要选择Arm64 Alpine
的二进制文件
非常感谢这个老哥的安装脚本:https://www.reddit.com/r/linux/comments/1bqvgx5/howto_c_aspnet_and_net_core_on_openwrt/
dotnet 9.0 sdk 下载页面:https://dotnet.microsoft.com/zh-cn/download/dotnet/9.0
能做什么?
有了 dotnet sdk,可以运行和编译一些全平台的应用,例如 ASF(ArchiSteamFarm)。
ASF 在 Github上 预构建的版本,缺少支持了 musl,所以 目前只能用 generic 版本的。
ASF是一个运行时的C#应用程序。NET平台。这意味着ASF不是直接编译成在CPU上运行的机器代码,而是编译成需要CIL兼容的运行时才能执行的CIL。
这也意味着ASF没有特定的操作系统要求,因为它需要在该操作系统上工作运行时,而不是操作系统本身。
基础操作系统是Windows、Linux、macOS、BSD、索尼Playstation 4、任天堂Wii还是您的烤面包机都不重要,只要有一个 .net 环境就可以使用(使用generic包)。