mirror of
https://github.com/Cateners/tiny_computer.git
synced 2026-05-20 16:35:47 +08:00
getifaddrs fix
This commit is contained in:
@@ -85,6 +85,7 @@ class Util {
|
||||
//int vip = 0 用户等级,vip免广告,你要改吗?(ToT)
|
||||
//bool isStickyKey = true 终端ctrl, shift, alt键是否粘滞
|
||||
//String defaultFFmpegCommand 默认推流命令
|
||||
//bool reinstallBootstrap = false 下次启动是否重装引导包
|
||||
//? int bootstrapVersion: 启动包版本
|
||||
//String[] containersInfo: 所有容器信息(json)
|
||||
//{name, boot:"\$DATA_DIR/bin/proot ...", vnc:"startnovnc", vncUrl:"...", commands:[{name:"更新和升级", command:"apt update -y && apt upgrade -y"},
|
||||
@@ -108,6 +109,8 @@ class Util {
|
||||
case "termFontScale" : return b ? G.prefs.getDouble(key)! : (value){G.prefs.setDouble(key, value); return value;}(1.0);
|
||||
case "vip" : return b ? G.prefs.getInt(key)! : (value){G.prefs.setInt(key, value); return value;}(0);
|
||||
case "isStickyKey" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(true);
|
||||
case "reinstallBootstrap" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
|
||||
case "getifaddrsBridge" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
|
||||
case "defaultFFmpegCommand" : return b ? G.prefs.getString(key)! : (value){G.prefs.setString(key, value); return value;}("-hide_banner -an -max_delay 1000000 -r 30 -f android_camera -camera_index 0 -i 0:0 -vf scale=iw/2:-1 -rtsp_transport udp -f rtsp rtsp://127.0.0.1:8554/stream");
|
||||
case "containersInfo" : return G.prefs.getStringList(key)!;
|
||||
case "adsBonus" : return b ? G.prefs.getStringList(key)! : (value){G.prefs.setStringList(key, value); return value;}([].cast<String>());
|
||||
@@ -377,6 +380,7 @@ class D {
|
||||
{"name": "F10", "key": TerminalKey.f10},
|
||||
{"name": "F11", "key": TerminalKey.f11},
|
||||
{"name": "F12", "key": TerminalKey.f12},
|
||||
|
||||
];
|
||||
|
||||
//看广告可以获得的奖励。
|
||||
@@ -405,6 +409,8 @@ class D {
|
||||
|
||||
};
|
||||
|
||||
static const String boot = "\$DATA_DIR/bin/proot -H --change-id=1000:1000 --pwd=/home/tiny --rootfs=\$CONTAINER_DIR --mount=/system --mount=/apex --kill-on-exit --mount=/storage:/storage --sysvipc -L --link2symlink --mount=/proc:/proc --mount=/dev:/dev --mount=\$CONTAINER_DIR/tmp:/dev/shm --mount=/dev/urandom:/dev/random --mount=/proc/self/fd:/dev/fd --mount=/proc/self/fd/0:/dev/stdin --mount=/proc/self/fd/1:/dev/stdout --mount=/proc/self/fd/2:/dev/stderr --mount=/dev/null:/dev/tty0 --mount=/dev/null:/proc/sys/kernel/cap_last_cap --mount=/storage/self/primary:/media/sd --mount=\$DATA_DIR/share:/home/tiny/公共 --mount=\$DATA_DIR/tiny:/home/tiny/.local/share/tiny --mount=/storage/self/primary/Fonts:/usr/share/fonts/wpsm --mount=/storage/self/primary/AppFiles/Fonts:/usr/share/fonts/yozom --mount=/system/fonts:/usr/share/fonts/androidm --mount=/storage/self/primary/Pictures:/home/tiny/图片 --mount=/storage/self/primary/Music:/home/tiny/音乐 --mount=/storage/self/primary/Movies:/home/tiny/视频 --mount=/storage/self/primary/Download:/home/tiny/下载 --mount=/storage/self/primary/DCIM:/home/tiny/照片 --mount=/storage/self/primary/Documents:/home/tiny/文档 --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/.tmoe-container.stat:/proc/stat --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/.tmoe-container.version:/proc/version --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/bus:/proc/bus --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/buddyinfo:/proc/buddyinfo --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/cgroups:/proc/cgroups --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/consoles:/proc/consoles --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/crypto:/proc/crypto --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/devices:/proc/devices --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/diskstats:/proc/diskstats --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/execdomains:/proc/execdomains --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/fb:/proc/fb --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/filesystems:/proc/filesystems --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/interrupts:/proc/interrupts --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/iomem:/proc/iomem --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/ioports:/proc/ioports --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/kallsyms:/proc/kallsyms --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/keys:/proc/keys --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/key-users:/proc/key-users --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/kpageflags:/proc/kpageflags --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/loadavg:/proc/loadavg --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/locks:/proc/locks --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/misc:/proc/misc --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/modules:/proc/modules --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/pagetypeinfo:/proc/pagetypeinfo --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/partitions:/proc/partitions --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/sched_debug:/proc/sched_debug --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/softirqs:/proc/softirqs --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/timer_list:/proc/timer_list --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/uptime:/proc/uptime --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/vmallocinfo:/proc/vmallocinfo --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/vmstat:/proc/vmstat --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/zoneinfo:/proc/zoneinfo /usr/bin/env -i HOSTNAME=TINY HOME=/home/tiny USER=tiny TERM=xterm-256color SDL_IM_MODULE=fcitx XMODIFIERS=@im=fcitx QT_IM_MODULE=fcitx GTK_IM_MODULE=fcitx TMOE_CHROOT=false TMOE_PROOT=true TMPDIR=/tmp MOZ_FAKE_NO_SANDBOX=1 DISPLAY=:4 PULSE_SERVER=tcp:127.0.0.1:4718 LANG=zh_CN.UTF-8 SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games \$EXTRA_OPT /bin/bash -l";
|
||||
|
||||
static final ButtonStyle commandButtonStyle = OutlinedButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: const Size(0, 0),
|
||||
@@ -441,6 +447,10 @@ class G {
|
||||
static String streamingOutput = "";
|
||||
static late Pty streamServerPty;
|
||||
static ValueNotifier<int> pageIndex = ValueNotifier(0); //主界面索引
|
||||
static ValueNotifier<bool> terminalPageChange = ValueNotifier(true); //更改值,用于刷新小键盘
|
||||
static ValueNotifier<bool> bannerAdsChange = ValueNotifier(true); //更改值,用于刷新banner广告
|
||||
static ValueNotifier<bool> bootTextChange = ValueNotifier(true); //更改值,用于刷新启动命令
|
||||
static ValueNotifier<String> updateText = ValueNotifier("小小电脑"); //加载界面的说明文字
|
||||
|
||||
|
||||
static late SharedPreferences prefs;
|
||||
@@ -532,6 +542,8 @@ class Workflow {
|
||||
Util.createDirFromString("${G.dataPath}/tmp");
|
||||
//给proot的tmp文件夹,虽然我不知道为什么proot要这个
|
||||
Util.createDirFromString("${G.dataPath}/proot_tmp");
|
||||
//给pulseaudio的tmp文件夹
|
||||
Util.createDirFromString("${G.dataPath}/pulseaudio_tmp");
|
||||
//解压后得到bin文件夹和libexec文件夹
|
||||
//bin存放了proot, pulseaudio, tar等
|
||||
//libexec存放了proot loader
|
||||
@@ -539,6 +551,12 @@ class Workflow {
|
||||
"assets/assets.zip",
|
||||
"${G.dataPath}/assets.zip",
|
||||
);
|
||||
//patch.tar.gz存放了tiny文件夹
|
||||
//里面是一些补丁,会被挂载到~/.local/share/tiny
|
||||
await Util.copyAsset(
|
||||
"assets/patch.tar.gz",
|
||||
"${G.dataPath}/patch.tar.gz",
|
||||
);
|
||||
//dddd
|
||||
await Util.copyAsset(
|
||||
"assets/busybox",
|
||||
@@ -549,19 +567,24 @@ class Workflow {
|
||||
export DATA_DIR=${G.dataPath}
|
||||
cd \$DATA_DIR
|
||||
chmod +x busybox
|
||||
\$DATA_DIR/busybox unzip assets.zip
|
||||
\$DATA_DIR/busybox unzip -o assets.zip
|
||||
chmod -R +x bin/*
|
||||
chmod -R +x libexec/proot/*
|
||||
chmod 1777 tmp
|
||||
ln -s \$DATA_DIR/busybox \$DATA_DIR/bin/xz
|
||||
\$DATA_DIR/busybox rm -rf assets.zip
|
||||
ln -sf \$DATA_DIR/busybox \$DATA_DIR/bin/xz
|
||||
ln -sf \$DATA_DIR/busybox \$DATA_DIR/bin/gzip
|
||||
\$DATA_DIR/bin/tar zxf patch.tar.gz
|
||||
\$DATA_DIR/busybox rm -rf assets.zip patch.tar.gz
|
||||
""");
|
||||
}
|
||||
|
||||
//初次启动要做的事情
|
||||
static Future<void> initForFirstTime() async {
|
||||
//首先设置bootstrap
|
||||
G.updateText.value = "正在安装引导包";
|
||||
await setupBootstrap();
|
||||
|
||||
G.updateText.value = "正在复制容器系统";
|
||||
//存放容器的文件夹0和存放硬链接的文件夹.l2s
|
||||
Util.createDirFromString("${G.dataPath}/containers/0/.l2s");
|
||||
//这个是容器rootfs,被split命令分成了xa*
|
||||
@@ -572,6 +595,7 @@ ln -s \$DATA_DIR/busybox \$DATA_DIR/bin/xz
|
||||
await Util.copyAsset("assets/$name", "${G.dataPath}/$name");
|
||||
}
|
||||
//-J
|
||||
G.updateText.value = "正在安装容器系统";
|
||||
await Util.execute(
|
||||
"""
|
||||
export DATA_DIR=${G.dataPath}
|
||||
@@ -604,11 +628,12 @@ done
|
||||
//$DATA_DIR是数据文件夹, $CONTAINER_DIR是容器根目录
|
||||
await G.prefs.setStringList("containersInfo", ["""{
|
||||
"name":"Debian Bookworm",
|
||||
"boot":"\$DATA_DIR/bin/proot -H --change-id=1000:1000 --pwd=/home/tiny --rootfs=\$CONTAINER_DIR --mount=/system --mount=/apex --kill-on-exit --mount=/storage:/storage --sysvipc -L --link2symlink --mount=/proc:/proc --mount=/dev:/dev --mount=\$CONTAINER_DIR/tmp:/dev/shm --mount=/dev/urandom:/dev/random --mount=/proc/self/fd:/dev/fd --mount=/proc/self/fd/0:/dev/stdin --mount=/proc/self/fd/1:/dev/stdout --mount=/proc/self/fd/2:/dev/stderr --mount=/dev/null:/dev/tty0 --mount=/dev/null:/proc/sys/kernel/cap_last_cap --mount=/storage/self/primary:/media/sd --mount=\$DATA_DIR/share:/home/tiny/公共 --mount=/storage/self/primary/Fonts:/usr/share/fonts/wpsm --mount=/storage/self/primary/AppFiles/Fonts:/usr/share/fonts/yozom --mount=/system/fonts:/usr/share/fonts/androidm --mount=/storage/self/primary/Pictures:/home/tiny/图片 --mount=/storage/self/primary/Music:/home/tiny/音乐 --mount=/storage/self/primary/Movies:/home/tiny/视频 --mount=/storage/self/primary/Download:/home/tiny/下载 --mount=/storage/self/primary/DCIM:/home/tiny/照片 --mount=/storage/self/primary/Documents:/home/tiny/文档 --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/.tmoe-container.stat:/proc/stat --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/.tmoe-container.version:/proc/version --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/bus:/proc/bus --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/buddyinfo:/proc/buddyinfo --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/cgroups:/proc/cgroups --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/consoles:/proc/consoles --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/crypto:/proc/crypto --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/devices:/proc/devices --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/diskstats:/proc/diskstats --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/execdomains:/proc/execdomains --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/fb:/proc/fb --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/filesystems:/proc/filesystems --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/interrupts:/proc/interrupts --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/iomem:/proc/iomem --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/ioports:/proc/ioports --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/kallsyms:/proc/kallsyms --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/keys:/proc/keys --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/key-users:/proc/key-users --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/kpageflags:/proc/kpageflags --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/loadavg:/proc/loadavg --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/locks:/proc/locks --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/misc:/proc/misc --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/modules:/proc/modules --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/pagetypeinfo:/proc/pagetypeinfo --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/partitions:/proc/partitions --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/sched_debug:/proc/sched_debug --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/softirqs:/proc/softirqs --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/timer_list:/proc/timer_list --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/uptime:/proc/uptime --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/vmallocinfo:/proc/vmallocinfo --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/vmstat:/proc/vmstat --mount=\$CONTAINER_DIR/usr/local/etc/tmoe-linux/proot_proc/zoneinfo:/proc/zoneinfo /usr/bin/env -i HOSTNAME=TINY HOME=/home/tiny USER=tiny TERM=xterm-256color SDL_IM_MODULE=fcitx XMODIFIERS=@im=fcitx QT_IM_MODULE=fcitx GTK_IM_MODULE=fcitx TMOE_CHROOT=false TMOE_PROOT=true TMPDIR=/tmp MOZ_FAKE_NO_SANDBOX=1 DISPLAY=:4 PULSE_SERVER=tcp:127.0.0.1:4718 LANG=zh_CN.UTF-8 SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games \$EXTRA_OPT /bin/bash -l",
|
||||
"boot":"${D.boot}",
|
||||
"vnc":"startnovnc &",
|
||||
"vncUrl":"http://localhost:36082/vnc.html?host=localhost&port=36082&autoconnect=true&resize=remote&password=12345678",
|
||||
"commands":${jsonEncode(D.commands)}
|
||||
}"""]);
|
||||
G.updateText.value = "安装完成";
|
||||
}
|
||||
|
||||
static Future<void> initData() async {
|
||||
@@ -634,6 +659,13 @@ done
|
||||
}
|
||||
G.currentContainer = Util.getGlobal("defaultContainer") as int;
|
||||
|
||||
//是否需要重新安装引导包?
|
||||
if (Util.getGlobal("reinstallBootstrap")) {
|
||||
G.updateText.value = "正在重新安装引导包";
|
||||
await setupBootstrap();
|
||||
G.prefs.setBool("reinstallBootstrap", false);
|
||||
}
|
||||
|
||||
G.termFontScale.value = Util.getGlobal("termFontScale") as double;
|
||||
|
||||
G.controller = WebViewController()..setJavaScriptMode(JavaScriptMode.unrestricted);
|
||||
@@ -684,23 +716,24 @@ done
|
||||
//pulseaudio还需要一个文件夹放配置,这里用share
|
||||
G.audioPty!.write(const Utf8Encoder().convert("""
|
||||
export DATA_DIR=${G.dataPath}
|
||||
cd \$DATA_DIR/..
|
||||
export TMPDIR=\$PWD/cache
|
||||
cd \$DATA_DIR
|
||||
export HOME=\$DATA_DIR/share
|
||||
export LD_LIBRARY_PATH=\$DATA_DIR/bin
|
||||
\$DATA_DIR/busybox sed "s/4713/${Util.getGlobal("defaultAudioPort") as int}/g" \$DATA_DIR/bin/pulseaudio.conf > \$DATA_DIR/bin/pulseaudio.conf.tmp
|
||||
\$DATA_DIR/bin/pulseaudio -F \$DATA_DIR/bin/pulseaudio.conf.tmp
|
||||
TMPDIR=\$DATA_DIR/pulseaudio_tmp HOME=\$DATA_DIR/pulseaudio_tmp XDG_CONFIG_HOME=\$DATA_DIR/pulseaudio_tmp LD_LIBRARY_PATH=\$DATA_DIR/bin \$DATA_DIR/bin/pulseaudio -F \$DATA_DIR/bin/pulseaudio.conf.tmp
|
||||
exit
|
||||
"""));
|
||||
await G.audioPty?.exitCode;
|
||||
}
|
||||
|
||||
static Future<void> launchCurrentContainer() async {
|
||||
String extraOpt = "";
|
||||
if (Util.getGlobal("getifaddrsBridge")) {
|
||||
Util.execute("${G.dataPath}/bin/getifaddrs_bridge_server ${G.dataPath}/containers/${G.currentContainer}/tmp/.getifaddrs-bridge");
|
||||
extraOpt += "LD_PRELOAD=/home/tiny/.local/share/tiny/extra/getifaddrs_bridge_client_lib.so ";
|
||||
}
|
||||
Util.termWrite(
|
||||
"""
|
||||
export DATA_DIR=${G.dataPath}
|
||||
export CONTAINER_DIR=\$DATA_DIR/containers/${G.currentContainer}
|
||||
export EXTRA_OPT="$extraOpt"
|
||||
#export PROOT_L2S_DIR=\$DATA_DIR/containers/0/.l2s
|
||||
cd \$DATA_DIR
|
||||
export PROOT_TMP_DIR=\$DATA_DIR/proot_tmp
|
||||
|
||||
Reference in New Issue
Block a user