Skip to content

Commit 30dd429

Browse files
authored
Merge pull request #171 from mofeng-git/dev
Dev
2 parents 6f4cf12 + f900c4b commit 30dd429

File tree

10 files changed

+171
-81
lines changed

10 files changed

+171
-81
lines changed

build/Dockerfile

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ FROM python:3.11.11-slim-bookworm
44

55
LABEL maintainer="mofeng654321@hotmail.com"
66

7+
ARG TARGETARCH
8+
79
COPY --from=builder /tmp/lib/* /tmp/lib/
810
COPY --from=builder /tmp/ustreamer/ustreamer /tmp/ustreamer/ustreamer-dump /usr/bin/janus /usr/bin/
911
COPY --from=builder /tmp/wheel/*.whl /tmp/wheel/
1012
COPY --from=builder /tmp/ustreamer/libjanus_ustreamer.so /usr/lib/ustreamer/janus/
1113
COPY --from=builder /usr/lib/janus/transports/* /usr/lib/janus/transports/
12-
13-
ARG TARGETARCH
14+
COPY --from=builder /tmp/arm64-libs.tar.gz* /tmp/
15+
RUN if [ ${TARGETARCH} = arm64 ] && [ -f /tmp/arm64-libs.tar.gz ]; then \
16+
cd / && tar -xzf /tmp/arm64-libs.tar.gz && rm -f /tmp/arm64-libs.tar.gz; \
17+
fi
1418

1519
ENV PYTHONDONTWRITEBYTECODE=1 \
1620
PYTHONUNBUFFERED=1 \
@@ -41,32 +45,38 @@ RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.lis
4145
libwebsockets17 \
4246
libnss3 \
4347
libasound2 \
48+
libdrm2 \
49+
libx264-164 \
50+
libyuv0 \
4451
nano \
4552
unzip \
46-
libavcodec59 \
47-
libavformat59 \
48-
libavutil57 \
49-
libswscale6 \
50-
libavfilter8 \
51-
libavdevice59 \
52-
&& if [ ${TARGETARCH} != arm ] && [ ${TARGETARCH} != arm64 ]; then \
53-
apt-get install -y --no-install-recommends \
54-
ffmpeg \
55-
vainfo \
56-
libva2 \
57-
libva-drm2 \
58-
libva-x11-2 \
59-
libdrm2 \
60-
mesa-va-drivers \
61-
mesa-vdpau-drivers \
62-
intel-media-va-driver \
63-
i965-va-driver; \
64-
fi \
65-
&& if [ ${TARGETARCH} = arm ] || [ ${TARGETARCH} = arm64 ]; then \
66-
apt-get install -y --no-install-recommends \
67-
v4l-utils \
68-
libv4l-0; \
69-
fi \
53+
&& case ${TARGETARCH} in \
54+
amd64) \
55+
apt-get install -y --no-install-recommends \
56+
libavcodec59 libavformat59 libavutil57 \
57+
libswscale6 libavfilter8 libavdevice59 \
58+
ffmpeg vainfo \
59+
libva2 libva-drm2 libva-x11-2 \
60+
mesa-va-drivers mesa-vdpau-drivers \
61+
intel-media-va-driver i965-va-driver \
62+
;; \
63+
arm) \
64+
apt-get install -y --no-install-recommends \
65+
libavcodec59 libavformat59 libavutil57 \
66+
libswscale6 libavfilter8 libavdevice59 \
67+
v4l-utils libv4l-0 \
68+
;; \
69+
arm64) \
70+
apt-get install -y --no-install-recommends \
71+
v4l-utils libv4l-0 \
72+
libstdc++6 \
73+
libva2 libva-drm2 libva-x11-2 \
74+
libvdpau1 ocl-icd-libopencl1 \
75+
;; \
76+
*) \
77+
echo "Unsupported architecture: ${TARGETARCH}" && exit 1 \
78+
;; \
79+
esac \
7080
&& cp /tmp/lib/* /lib/*-linux-*/ \
7181
&& pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check /tmp/wheel/*.whl \
7282
&& pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check pyfatfs \
@@ -89,7 +99,8 @@ RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.lis
8999
&& touch /run/kvmd/ustreamer.sock \
90100
&& apt clean \
91101
&& rm -rf /var/lib/apt/lists/* \
92-
&& rm -rf /tmp/lib /tmp/wheel
102+
&& rm -rf /tmp/lib /tmp/wheel \
103+
&& ustreamer -v
93104

94105
COPY testenv/fakes/vcgencmd scripts/kvmd* /usr/bin/
95106
COPY extras/ /usr/share/kvmd/extras/

build/Dockerfile-stage-0

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,36 @@ RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.lis
4949
libusb-1.0-0-dev \
5050
libldap2-dev \
5151
libsasl2-dev \
52-
ffmpeg \
53-
libavcodec-dev \
54-
libavformat-dev \
55-
libavutil-dev \
56-
libswscale-dev \
57-
libavfilter-dev \
58-
libavdevice-dev \
59-
vainfo \
60-
libva-dev \
61-
libva-drm2 \
62-
libva-x11-2 \
6352
libdrm-dev \
6453
mesa-va-drivers \
6554
mesa-vdpau-drivers \
6655
v4l-utils \
6756
libv4l-dev \
57+
&& if [ ${TARGETARCH} != arm64 ]; then \
58+
apt-get install -y --no-install-recommends \
59+
ffmpeg \
60+
libavcodec-dev \
61+
libavformat-dev \
62+
libavutil-dev \
63+
libswscale-dev \
64+
libavfilter-dev \
65+
libavdevice-dev; \
66+
fi \
6867
&& if [ ${TARGETARCH} != arm ] && [ ${TARGETARCH} != arm64 ]; then \
6968
apt-get install -y --no-install-recommends \
69+
vainfo \
70+
libva-dev \
71+
libva-drm2 \
72+
libva-x11-2 \
7073
intel-media-va-driver \
7174
i965-va-driver; \
7275
fi \
76+
&& if [ ${TARGETARCH} = arm64 ]; then \
77+
apt-get install -y --no-install-recommends \
78+
ninja-build \
79+
zlib1g-dev \
80+
libswresample-dev; \
81+
fi \
7382
&& apt clean \
7483
&& rm -rf /var/lib/apt/lists/*
7584

@@ -94,12 +103,18 @@ RUN --security=insecure pip config set global.index-url https://pypi.tuna.tsingh
94103
pycparser pyelftools pyghmi pygments pyparsing pyotp qrcode requests \
95104
semantic-version setproctitle six spidev tabulate urllib3 wrapt xlib \
96105
yarl pyserial pyyaml zstandard supervisor pyfatfs pyserial python-periphery \
97-
python-ldap python-pam pyrad pyudev pyusb luma.oled pyserial-asyncio
106+
python-ldap python-pam pyrad pyudev pyusb luma.oled pyserial-asyncio \
107+
&& rm -rf /root/.cache/pip/* /tmp/pip-* \
108+
&& if [ ${TARGETARCH} = arm ]; then \
109+
umount /root/.cargo 2>/dev/null || true \
110+
&& rm -rf /root/.cargo /root/rustup-init.sh; \
111+
fi
98112

99-
# 编译 python vedev库
113+
# 编译 python evdev库
100114
RUN git clone --depth=1 https://github.com/gvalkov/python-evdev.git /tmp/python-evdev \
101115
&& cd /tmp/python-evdev \
102-
&& python3 setup.py bdist_wheel --dist-dir /tmp/wheel/
116+
&& python3 setup.py bdist_wheel --dist-dir /tmp/wheel/ \
117+
&& rm -rf /tmp/python-evdev
103118

104119
# 编译安装 libnice、libsrtp、libwebsockets 和 janus-gateway
105120
RUN git clone --depth=1 https://gitlab.freedesktop.org/libnice/libnice /tmp/libnice \
@@ -111,14 +126,14 @@ RUN git clone --depth=1 https://gitlab.freedesktop.org/libnice/libnice /tmp/libn
111126
&& tar xf libsrtp-2.2.0.tar.gz \
112127
&& cd libsrtp-2.2.0 \
113128
&& ./configure --prefix=/usr --enable-openssl \
114-
&& make shared_library -j && make install \
129+
&& make shared_library -j$(nproc) && make install \
115130
&& cd /tmp \
116131
&& rm -rf /tmp/libsrtp* \
117-
&& git clone --depth=1 https://libwebsockets.org/repo/libwebsockets /tmp/libwebsockets \
132+
&& git clone --depth=1 https://github.com/warmcat/libwebsockets /tmp/libwebsockets \
118133
&& cd /tmp/libwebsockets \
119134
&& mkdir build && cd build \
120135
&& cmake -DLWS_MAX_SMP=1 -DLWS_WITHOUT_EXTENSIONS=0 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" .. \
121-
&& make -j && make install \
136+
&& make -j$(nproc) && make install \
122137
&& cd /tmp \
123138
&& rm -rf /tmp/libwebsockets \
124139
&& git clone --depth=1 https://github.com/meetecho/janus-gateway.git /tmp/janus-gateway \
@@ -127,19 +142,40 @@ RUN git clone --depth=1 https://gitlab.freedesktop.org/libnice/libnice /tmp/libn
127142
&& ./configure --enable-static --enable-websockets --enable-plugin-audiobridge \
128143
--disable-data-channels --disable-rabbitmq --disable-mqtt --disable-all-plugins \
129144
--disable-all-loggers --prefix=/usr \
130-
&& make -j && make install \
145+
&& make -j$(nproc) && make install \
131146
&& cd /tmp \
132147
&& rm -rf /tmp/janus-gateway
133148

149+
# 编译 Rockchip MPP、RGA 和 FFmpeg(仅 arm64)
150+
RUN if [ ${TARGETARCH} = arm64 ]; then \
151+
git clone -b jellyfin-mpp --depth=1 https://github.com/nyanmisaka/mpp.git /tmp/rkmpp \
152+
&& mkdir -p /tmp/rkmpp/rkmpp_build && cd /tmp/rkmpp/rkmpp_build \
153+
&& cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TEST=OFF .. \
154+
&& make -j$(nproc) \
155+
&& make install \
156+
&& git clone -b jellyfin-rga --depth=1 https://github.com/nyanmisaka/rk-mirrors.git /tmp/rkrga \
157+
&& cd /tmp/ \
158+
&& meson setup rkrga rkrga_build --prefix=/usr --libdir=lib --buildtype=release -Dcpp_args=-fpermissive -Dlibdrm=false -Dlibrga_demo=false \
159+
&& meson configure rkrga_build > /dev/null \
160+
&& ninja -C rkrga_build install \
161+
&& git clone --depth=1 https://github.com/nyanmisaka/ffmpeg-rockchip.git /tmp/ffmpeg-rockchip \
162+
&& cd /tmp/ffmpeg-rockchip \
163+
&& ./configure --prefix=/usr --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga \
164+
--enable-libv4l2 --enable-libx264 --enable-shared --disable-programs \
165+
--disable-doc --disable-htmlpages --disable-manpages --disable-network --disable-protocols \
166+
--disable-decoders --disable-debug --disable-alsa \
167+
&& make -j$(nproc) \
168+
&& make install \
169+
&& rm -rf /tmp/rkmpp /tmp/rkrga /tmp/ffmpeg-rockchip; \
170+
fi
171+
134172
# 编译 ustreamer
135-
RUN echo "Building ustreamer with timestamp cache bust" \
136-
&& sed --in-place --expression 's|^#include "refcount.h"$|#include "../refcount.h"|g' /usr/include/janus/plugins/plugin.h \
137-
&& TIMESTAMP=$(date +%s%N) \
138-
&& git clone --depth=1 https://github.com/mofeng-git/ustreamer /tmp/ustreamer-${TIMESTAMP} \
139-
&& make -j WITH_PYTHON=1 WITH_JANUS=1 WITH_FFMPEG=1 -C /tmp/ustreamer-${TIMESTAMP} \
140-
&& /tmp/ustreamer-${TIMESTAMP}/ustreamer -v \
141-
&& cp /tmp/ustreamer-${TIMESTAMP}/python/dist/*.whl /tmp/wheel/ \
142-
&& mv /tmp/ustreamer-${TIMESTAMP} /tmp/ustreamer
173+
RUN sed --in-place --expression 's|^#include "refcount.h"$|#include "../refcount.h"|g' /usr/include/janus/plugins/plugin.h \
174+
&& git clone --depth=1 https://github.com/mofeng-git/ustreamer /tmp/ustreamer \
175+
&& make -j$(nproc) WITH_PYTHON=1 WITH_JANUS=1 WITH_FFMPEG=1 -C /tmp/ustreamer \
176+
&& /tmp/ustreamer/ustreamer -v \
177+
&& /tmp/ustreamer/ustreamer-dump -v \
178+
&& cp /tmp/ustreamer/python/dist/*.whl /tmp/wheel/
143179

144180
# 复制必要的库文件
145181
RUN mkdir /tmp/lib \
@@ -148,4 +184,11 @@ RUN mkdir /tmp/lib \
148184
libevent-*.so.* libjpeg.so.* libyuv.so.* libnice.so.* \
149185
/tmp/lib/ \
150186
&& find /usr/lib -name "libsrtp2.so.*" -exec cp {} /tmp/lib/ \; \
151-
&& find /usr/lib -name "libwebsockets.so.*" -exec cp {} /tmp/lib/ \;
187+
&& find /usr/lib -name "libwebsockets.so.*" -exec cp {} /tmp/lib/ \; \
188+
&& if [ ${TARGETARCH} = arm64 ]; then \
189+
find /usr/lib -name "libav*.so.*" -exec cp {} /tmp/lib/ \; \
190+
&& find /usr/lib -name "libsw*.so.*" -exec cp {} /tmp/lib/ \; \
191+
&& find /usr/lib -name "libpostproc.so.*" -exec cp {} /tmp/lib/ \; \
192+
&& find /usr/lib -name "librockchip*" -exec cp {} /tmp/lib/ \; \
193+
&& find /usr/lib -name "librga.so.*" -exec cp {} /tmp/lib/ \; ; \
194+
fi

build/functions/install.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ install_base_packages() {
108108
iptables network-manager curl kmod libmicrohttpd12 libjansson4 libssl3 \\
109109
libsofia-sip-ua0 libglib2.0-0 libopus0 libogg0 libcurl4 libconfig9 \\
110110
python3-pip net-tools libavcodec59 libavformat59 libavutil57 libswscale6 \\
111-
libavfilter8 libavdevice59 v4l-utils libv4l-0 && \\
111+
libavfilter8 libavdevice59 v4l-utils libv4l-0 nano unzip && \\
112112
apt clean && \\
113113
rm -rf /var/lib/apt/lists/*
114114
"
@@ -180,9 +180,8 @@ configure_system() {
180180
cat /One-KVM/configs/os/udev/v2-hdmiusb-rpi4.rules > /etc/udev/rules.d/99-kvmd.rules && \\
181181
echo 'libcomposite' >> /etc/modules && \\
182182
mv /usr/local/bin/kvmd* /usr/bin/ || echo '信息:/usr/local/bin/kvmd* 未找到或移动失败,可能已在/usr/bin' && \\
183-
cp /One-KVM/configs/os/services/* /etc/systemd/system/ && \\
183+
cp -r /One-KVM/configs/os/services/* /etc/systemd/system/ && \\
184184
cp /One-KVM/configs/os/tmpfiles.conf /usr/lib/tmpfiles.d/ && \\
185-
mv /etc/kvmd/supervisord.conf /etc/supervisord.conf && \\
186185
chmod +x /etc/update-motd.d/* || echo '警告:chmod /etc/update-motd.d/* 失败' && \\
187186
echo 'kvmd ALL=(ALL) NOPASSWD: /etc/kvmd/custom_atx/gpio.sh' >> /etc/sudoers && \\
188187
echo 'kvmd ALL=(ALL) NOPASSWD: /etc/kvmd/custom_atx/usbrelay_hid.sh' >> /etc/sudoers && \\
@@ -203,14 +202,16 @@ install_webterm() {
203202
local ttyd_arch="$arch"
204203

205204
if [ "$arch" = "armhf" ]; then
206-
ttyd_arch="armv7"
205+
ttyd_arch="armhf"
207206
elif [ "$arch" = "amd64" ]; then
208-
ttyd_arch="x86_64" # ttyd 通常用 x86_64
207+
ttyd_arch="x86_64"
208+
elif [ "$arch" = "aarch64" ]; then
209+
ttyd_arch="aarch64"
209210
fi
210211

211212
echo "信息:在 chroot 环境中下载并安装 ttyd ($ttyd_arch)..."
212213
run_in_chroot "
213-
curl -L https://gh.llkk.cc/https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.${ttyd_arch} -o /usr/bin/ttyd && \\
214+
curl -L https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.${ttyd_arch} -o /usr/bin/ttyd && \\
214215
chmod +x /usr/bin/ttyd && \\
215216
mkdir -p /home/kvmd-webterm && \\
216217
chown kvmd-webterm /home/kvmd-webterm

build/init.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,26 @@ if [ ! -f /etc/kvmd/.init_flag ]; then
7171

7272
# 设置用户名和密码
7373
if [ ! -z "$USERNAME" ] && [ ! -z "$PASSWORD" ]; then
74+
# 设置自定义用户名和密码
7475
if python -m kvmd.apps.htpasswd del admin \
75-
&& echo "$PASSWORD" | python -m kvmd.apps.htpasswd set -i "$USERNAME" \
76+
&& echo "$PASSWORD" | python -m kvmd.apps.htpasswd add -i "$USERNAME" \
7677
&& echo "$PASSWORD -> $USERNAME:$PASSWORD" > /etc/kvmd/vncpasswd \
7778
&& echo "$USERNAME:$PASSWORD -> $USERNAME:$PASSWORD" > /etc/kvmd/ipmipasswd; then
7879
log_info "用户凭据设置成功"
7980
else
8081
log_error "用户凭据设置失败"
8182
exit 1
8283
fi
84+
elif [ ! -z "$PASSWORD" ] && [ -z "$USERNAME" ]; then
85+
# 只设置密码,保持admin用户名
86+
if echo "$PASSWORD" | python -m kvmd.apps.htpasswd set -i "admin" \
87+
&& echo "$PASSWORD -> admin:$PASSWORD" > /etc/kvmd/vncpasswd \
88+
&& echo "admin:$PASSWORD -> admin:$PASSWORD" > /etc/kvmd/ipmipasswd; then
89+
log_info "admin 用户密码设置成功"
90+
else
91+
log_error "admin 用户密码设置失败"
92+
exit 1
93+
fi
8394
else
8495
log_warn "未设置 USERNAME 和 PASSWORD 环境变量,使用默认值(admin/admin)"
8596
fi
@@ -210,8 +221,8 @@ EOF
210221
fi
211222

212223
if [ ! -z "$VIDEOFORMAT" ]; then
213-
if sed -i "s/format=mjpeg/format=$VIDFORMAT/g" /etc/kvmd/override.yaml; then
214-
log_info "视频输入格式已设置为 $VIDFORMAT"
224+
if sed -i "s/--format=mjpeg/--format=$VIDEOFORMAT/g" /etc/kvmd/override.yaml; then
225+
log_info "视频输入格式已设置为 $VIDEOFORMAT"
215226
fi
216227
fi
217228

@@ -221,6 +232,19 @@ EOF
221232
fi
222233
fi
223234

235+
# 设置WEB端口
236+
if [ ! -z "$HTTPPORT" ]; then
237+
if sed -i "s/port: 8080/port: $HTTPPORT/g" /etc/kvmd/override.yaml; then
238+
log_info "HTTP 端口已设置为 $HTTPPORT"
239+
fi
240+
fi
241+
242+
if [ ! -z "$HTTPSPORT" ]; then
243+
if sed -i "s/port: 4430/port: $HTTPSPORT/g" /etc/kvmd/override.yaml; then
244+
log_info "HTTPS 端口已设置为 $HTTPSPORT"
245+
fi
246+
fi
247+
224248

225249
touch /etc/kvmd/.init_flag
226250
log_info "初始化配置完成"

web/kvm/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,6 @@
719719
</tr>
720720
</table>
721721
</div>
722-
<div class="hidden" id="msd-uploading-sub">
723-
<hr>
724-
</div>
725722
<div class="hidden" id="msd-uploading-sub">
726723
<table class="kv">
727724
<tr>

web/kvm/navbar-msd.pug

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ li.right.feature-disabled#msd-dropdown
4747
{title: "Flash", value: "0"},
4848
]) Drive #[a(target="_blank" href="https://docs.pikvm.org/msd") mode]:
4949
td &nbsp;
50-
+menu_switch_td2("msd-rw-switch", false, false) Writable:
50+
+menu_switch_td2("msd-rw-switch", false, false, "msd-rw-switch") Writable:
5151
tr
5252
td(i18n="drive_file_display") Files:
5353
td
@@ -79,8 +79,6 @@ li.right.feature-disabled#msd-dropdown
7979
tr.hidden#msd-new-part
8080
td(i18n="drive_upload_partition") Upload partition:
8181
td(width="100%") #[select#msd-new-part-selector]
82-
div(id="msd-uploading-sub" class="hidden")
83-
hr
8482

8583
.hidden#msd-uploading-sub
8684
table.kv

web/share/i18n/i18n_en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"drive_unpackage_files":"Unpackage files from image",
123123
"drive_image_files":"Image Files",
124124
"drive_normal_files":"Normal Files",
125+
"drive_writable":"Writable:",
125126

126127
"atx-ask-switch":"Ask click confirmation",
127128
"hid-recorder-loop-switch":"Infinite loop playback",

web/share/i18n/i18n_zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"drive_unpackage_files":"从镜像文件解压文件",
123123
"drive_image_files":"镜像文件模式",
124124
"drive_normal_files":"普通文件模式",
125+
"drive_writable":"可写:",
125126

126127

127128

0 commit comments

Comments
 (0)