Skip to content

Commit

Permalink
xdict.sh 调试01
Browse files Browse the repository at this point in the history
---
&& rm -f $tmpDir/novncHtml*.htm

su - headless -c "wget https://m3.8js.net//20210522/tashanhe-shiqishune.mp3";

chmod 777 -R $tmpDir #for xvncXX's use

 margin-bottom: 3px;

notes

f

mkdir -p /tmp/.headless; pa="/tmp/.headless/pulse-$port.pa"

tmpDir; sed -i "$line2 r $tmpDir/novncHtml$N.htm" /usr/local/novnc/index.html

ADD_HERE

sdf

fix match; supervisorctl update

sdf

update

VNC_INIT="" \

|grep -v "^#\|^$"

sort -u

sdf

# echo "</br>" >> /usr/local/novnc/index.html

COPY --from=files2 / /

s

 | $name1

/usr/local/webhook/scripts/

up

indexName

echo "</br>" >> /usr/local/novnc/index.html

fix

up caller

merge

pretty, sort -u

novnc: one line

= > |

judgeLock
  • Loading branch information
huapox authored and sam committed Mar 21, 2022
1 parent b333aeb commit 75cf222
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 61 deletions.
8 changes: 5 additions & 3 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FROM scratch as files
COPY --from=Xvnc /usr/lib64/xorg/protocol.txt /usr/lib64/xorg/protocol.txt
COPY --from=bin2 /src/webhookd /usr/local/webhook/webhookd


FROM scratch as files2
# COPY --chown=root:root ./src
ADD src/dot /etc/skel
ADD src/etc /etc
Expand Down Expand Up @@ -132,12 +132,14 @@ ENV \
# TODO: setRange; 再由客户端自行指定所要的端口;
VNC_OFFSET=0 \
VNC_LIMIT=1 \
VNC_INIT="23=mate,25=xfce,26=flux" \
# VNC_INIT="21=gnome,22=plama,23=mate,24=cinna,25=xfce,26=flux" \
VNC_INIT="" \
# VNC_INIT="23|mate,24|cinna,25|xfce,26|flux" \
# VNC_INIT="21|gnome,22|plama,23|mate,24|cinna,25|xfce,26|flux" \
# L=zh_CN \
TZ=Asia/Shanghai

COPY --from=files / /
COPY --from=files2 / /
RUN bash /xconf.sh "param|${AUDIO}" "param|${FULL}"
# /home/headless/.config权限..
COPY --chown=headless:headless src/f/.config/emp${FULL} /home/headless/.config/
Expand Down
7 changes: 4 additions & 3 deletions src/index.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<div style="margin-top: 8px; margin-left: 22px;">
VNC_PASS: <input type="password" id="password" maxlength="20" value="headless" style="width: 80%;" />
</div>
<ul style="margin-top: 8px;">
<ul style="margin-top: 8px; margin-bottom: 3px;">
<li><a id="audioLink" target="_blank" href=":9222">Audio Broadcast</a></li>
</ul>
<script>
Expand All @@ -82,11 +82,12 @@
</script>
<div style="height:70%; overflow:auto;">
<ul style="margin-top: 8px;">
<!-- ADD_HERE -->
<!-- <li><a href="javascript:void(0);" onclick="openVnc('display10')">display0</a></li> -->
<!-- <li><a target="_blank" href="/vnc.html?path=websockify/?token=display10&password=xx">display0</a></li>
<li><a target="_blank" href="/vnc_lite.html?path=websockify/?token=display10&password=xx">display0-lite</a></li>
<li></li>
<li></li> -->
</ul>
</div>
</div>
</body> -->
</body>
5 changes: 3 additions & 2 deletions src/xconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AUDIO=$(echo $1|sed "s/param|//g")
FULL=$(echo $2|sed "s/param|//g")
# RUN=
echo -e "AUDIO=$AUDIO\nFULL=$FULL"
rm -f /xconf.sh #del first, then execute?: avoid nonFULL's exit.
rm -f /xconf.sh /xdict.sh #del first, then execute?: avoid nonFULL's exit.

# xrdp-link
$RUN export xrdp=/usr/local/xrdp; \
Expand Down Expand Up @@ -41,7 +41,8 @@ $RUN echo "welcome! HeadlessBox." > /etc/motd \
mkdir -p /usr/share/man/man1/; \
su - headless -c "mkdir -p /home/headless/.config/plank/dock1/launchers"; \
# rm -f /home/headless/.config/plank/dock1/launchers/*.dockitem;
cd /tmp/; wget https://m3.8js.net//20210522/tashanhe-shiqishune.mp3;
su - headless -c "wget https://m3.8js.net//20210522/tashanhe-shiqishune.mp3";
# cd /tmp/; wget https://m3.8js.net//20210522/tashanhe-shiqishune.mp3;

##AUDIO###########################
# Setup D-Bus; ;
Expand Down
77 changes: 53 additions & 24 deletions src/xdict.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/bin/bash
cur=$(cd "$(dirname "$0")"; pwd)

# curl -s "localhost:8000/xdict?act=add&id=21&name=gnome"
echo "id=$id, name=$name"

# VNC_OFFSET=0 VNC_LIMIT=1 ##指定X的范围start.. end(off+limit) ###start0号默认用于headless
# local N=$(expr $i + $VNC_OFFSET)
function oneVnc(){
Expand All @@ -29,7 +26,7 @@ function oneVnc(){
environment=DISPLAY=:$N,HOME=/home/$user1
priority=35
user=$user1
command=/xvnc.sh $N
command=/xvnc.sh xvnc $N
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
Expand All @@ -38,7 +35,7 @@ redirect_stderr=true
environment=DISPLAY=:$N,HOME=/home/$user1
priority=36
user=$user1
command=/xrec.sh $N
command=/xvnc.sh xrec $N
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
Expand All @@ -54,20 +51,27 @@ password=askheadless
ip=127.0.0.1
port=$port1
chansrvport=DISPLAY($N)
""" > /tmp/xrdp-sesOne$N.conf
""" > $tmpDir/xrdp-sesOne$N.conf
# $N atLast
local line=$(cat /etc/xrdp/xrdp.ini |grep "^\[Local-sesman\]" -n |cut -d':' -f1)
echo "===line: $line=========================="
line=$(expr $line - 1)
# sed -i "${line}cchmod=0770" /etc/xrdp/xrdp.ini
sed -i "$line r /tmp/xrdp-sesOne$N.conf" /etc/xrdp/xrdp.ini
sed -i "$line r $tmpDir/xrdp-sesOne$N.conf" /etc/xrdp/xrdp.ini

# NOVNC
mkdir -p /etc/novnc
echo "display$N: 127.0.0.1:$port1" >> /etc/novnc/token.conf
echo "<li><a href=\"javascript:void(0);\" onclick=\"openVnc('display$N', 'vnc_lite')\">$N-$name1-lite</a></li>" >> /usr/local/novnc/index.html
echo "<li><a href=\"javascript:void(0);\" onclick=\"openVnc('display$N', 'vnc')\">$N-$name1-resize</a></li>" >> /usr/local/novnc/index.html
echo "<li></li>" >> /usr/local/novnc/index.html
# echo "<li>[<a href=\"javascript:void(0);\" onclick=\"openVnc('display$N', 'vnc')\">$N-resize</a>&nbsp;&nbsp; <a href=\"javascript:void(0);\" onclick=\"openVnc('display$N', 'vnc_lite')\">lite</a>] | $name1</li>" >> /usr/local/novnc/index.html
# # echo "<li><a href=\"javascript:void(0);\" onclick=\"openVnc('display$N', 'vnc')\">$N-$name1-resize</a></li>" >> /usr/local/novnc/index.html
# # echo "<li></li>" >> /usr/local/novnc/index.html
# # echo "</br>" >> /usr/local/novnc/index.html

echo "<li>[<a href=\"javascript:void(0);\" onclick=\"openVnc('display$N', 'vnc')\">$N-resize</a>&nbsp;&nbsp; <a href=\"javascript:void(0);\" onclick=\"openVnc('display$N', 'vnc_lite')\">lite</a>] | $name1</li>" >> $tmpDir/novncHtml$N.htm
local line2=$(cat /usr/local/novnc/index.html |grep "ADD_HERE" -n |cut -d':' -f1)
echo "===line2: $line2=========================="
line2=$(expr $line2 - 1)
sed -i "$line2 r $tmpDir/novncHtml$N.htm" /usr/local/novnc/index.html
}
# oneVnc

Expand All @@ -83,7 +87,7 @@ function doStart(){
sed -i "s^port=3389^port=${RDP_PORT}^g" /etc/xrdp/xrdp.ini
sed -i "s/EFRp 22/EFRp ${SSH_PORT}/g" /etc/supervisor/conf.d/xrdp.conf #sv.conf +dropbear

# # N0-headless ##+xrdp.ini >> 直接在dict.txt内指定了
# # N0-headless ##+xrdp.ini >> 直接在xdict.txt内指定了
# local N0=$(expr 0 + $VNC_OFFSET)
# mkdir -p /etc/novnc
# local port0=$(expr 5900 + $N0)
Expand All @@ -92,35 +96,60 @@ function doStart(){
# echo "<li><a href=\"javascript:void(0);\" onclick=\"openVnc('display$N0', 'vnc')\">$N0-headless-resize</a></li>" >> /usr/local/novnc/index.html
# echo "<li></li>" >> /usr/local/novnc/index.html

echo "$VNC_OFFSET|headless|xxJson" >> /usr/local/webhook/scripts/xdict.txt
# VNC_INIT
vnc_arr=(${VNC_INIT//,/ });
for i in "${!vnc_arr[@]}"; do
vnc=${vnc_arr[i]};
vnc=$(echo $vnc |sed "s/=/|/g") #trans
echo "init: $vnc"
echo "$vnc|xxJson" >> /usr/local/webhook/scripts/xdict.txt
done
lock=/.init_pass.lock
if [ ! -f "$lock" ]; then
echo "$VNC_OFFSET|headless|xxJson" >> /usr/local/webhook/scripts/xdict.txt
# VNC_INIT
vnc_arr=(${VNC_INIT//,/ });
# TODO: 按id去重
for i in "${!vnc_arr[@]}"; do
vnc=${vnc_arr[i]};
vnc=$(echo $vnc |sed "s/=/|/g") #trans = > |
echo "init: $vnc"
echo "$vnc|xxJson" >> /usr/local/webhook/scripts/xdict.txt
done
fi

cat $cur/xdict.txt |grep -v "^#\|^$" |while read one; do
tmpDir=/tmp/.headless; mkdir -p $tmpDir; chmod 777 -R $tmpDir #for xvncXX's use
cat $cur/xdict.txt |sort -u |grep -v "^#\|^$" |while read one; do
echo $one
id=$(echo $one |cut -d'|' -f1)
name=$(echo $one |cut -d'|' -f2)
oneVnc "$id" "$name"
done

echo -e "</ul>\n</div>\n</div>\n</body>" >> /usr/local/novnc/index.html
# echo -e "</ul>\n</div>\n</div>\n</body>" >> /usr/local/novnc/index.html
# view
rm -f /tmp/xrdp-sesOne*.conf
rm -f $tmpDir/xrdp-sesOne*.conf && rm -f $tmpDir/novncHtml*.htm
cat /etc/xrdp/xrdp.ini |grep "^\[Xvnc"
}

function errExit(){
echo "err: $1"
exit 1
}

case "$1" in
entry)
doStart
;;
*)
echo "oth.."
# curl -s "localhost:8000/xdict?act=add&id=21&name=gnome"
# curl -s "localhost:10083/xdict?id=31&name=test31"
echo "id=$id, name=$name"
test -z "$id" && errExit "id is empty"
test -z "$name" && errExit "name is empty"

# judge exist
match=$(cat $cur/xdict.txt |sort -u |grep -v "^#\|^$" |grep "^$id|")
! test -z "$match" && errExit "id allready exit in xdict.txt"

# setVNC
echo "$id|$name|xxJson" >> /usr/local/webhook/scripts/xdict.txt
oneVnc "$id" "$name"
# supervisorctl reread
supervisorctl update

# echo "oth.."
;;
esac
4 changes: 2 additions & 2 deletions src/xrdp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ redirect_stderr=true
# environment=DISPLAY=:_DISP_,HOME=/home/headless
# priority=35
# user=headless
# command=/xvnc.sh _DISP_
# command=/xvnc.sh xvnc _DISP_
# stdout_logfile=/dev/fd/1
# stdout_logfile_maxbytes=0
# redirect_stderr=true
# [program:xrec_DISP_-headless]
# environment=DISPLAY=:_DISP_,HOME=/home/headless
# priority=36
# user=headless
# command=/xrec.sh _DISP_
# command=/xvnc.sh xrec _DISP_
# stdout_logfile=/dev/fd/1
# stdout_logfile_maxbytes=0
# redirect_stderr=true
Expand Down
12 changes: 0 additions & 12 deletions src/xrec.sh

This file was deleted.

49 changes: 34 additions & 15 deletions src/xvnc.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
#!/bin/bash
offsetLimitIndex=$1
offsetLimitIndex=$2
offsetLimitIndex=${offsetLimitIndex:-99}
echo "offsetLimitIndex: $offsetLimitIndex"
BCS_PORT=${BCS_PORT:-9222}
indexName=$(cat /usr/local/webhook/scripts/xdict.txt |sort -u |grep -v "^#\|^$" |grep $offsetLimitIndex |cut -d'|' -f2)
echo "indexInfo: $offsetLimitIndex-$indexName, BCS_PORT: $BCS_PORT"

# PULSE#################################################
touch /var/run/dbus/system_bus_socket && chmod 777 /var/run/dbus/system_bus_socket; #>>pulse: conn dbus err.
# pulseaudio --exit-idle-time=-1 &
port=$(expr 4700 + $offsetLimitIndex) #4713
pa="/tmp/pulse-$port.pa"
cat /etc/pulse/default.pa > $pa; sed -i "s/4700/$port/g" $pa
pulseaudio --exit-idle-time=-1 -nF $pa &
function startXvnc(){
# PULSE#################################################
# touch /var/run/dbus/system_bus_socket && chmod 777 /var/run/dbus/system_bus_socket; #>>pulse: conn dbus err.
# pulseaudio --exit-idle-time=-1 &
port=$(expr 4700 + $offsetLimitIndex) #4713
mkdir -p /tmp/.headless; pa="/tmp/.headless/pulse-$port.pa"
cat /etc/pulse/default.pa > $pa; sed -i "s/4700/$port/g" $pa
pulseaudio --exit-idle-time=-1 -nF $pa &


# XRDP##################################################
#chansrv
export DISPLAY=:$offsetLimitIndex #:2
/usr/local/xrdp/sbin/xrdp-chansrv &
# XRDP##################################################
#chansrv
export DISPLAY=:$offsetLimitIndex #:2
/usr/local/xrdp/sbin/xrdp-chansrv &

# default: Xvnc :99 -BlacklistThreshold=5 -BlacklistTimeout=10
exec Xvnc -ac $DISPLAY -listen tcp -rfbauth=/etc/xrdp/vnc_pass -depth 16 -BlacklistThreshold=3 -BlacklistTimeout=1
# default: Xvnc :99 -BlacklistThreshold=5 -BlacklistTimeout=10
exec Xvnc -ac $DISPLAY -listen tcp -rfbauth=/etc/xrdp/vnc_pass -depth 16 -BlacklistThreshold=3 -BlacklistTimeout=1
}

case "$1" in
xvnc)
startXvnc
;;
xrec)
# go:recordmp3> go:record+lame > just parec+lame
url="localhost:$BCS_PORT/$offsetLimitIndex-$indexName.mp3?stream=true&advertise=true"
exec parec --format=s16le -d xrdp-sink.monitor |lame -r -ab 52 - - \
| curl -k -H "Transfer-Encoding: chunked" -X POST -T - "$url"
;;
*)
echo "please call with: xvnc.sh xvnc/xrec xx"
;;
esac

0 comments on commit 75cf222

Please sign in to comment.