将下面代码写成bash脚本即.sh文件
使用./运行
不可以直接用,需要将下面涉及用户名和组的地方改成自己的
set -e
# https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-20-04
sudo apt update
sudo apt install xfce4 xfce4-goodies
sudo apt install language-pack-zh* chinese* fonts-wqy-microhei fonts-noto-color-emoji
sudo apt install tightvncserver
vncserver && vncserver -kill :1
XSTARTUP_CFG="/home/HwHiAiUser/.vnc/xstartup"
if [ ! -f "${XSTARTUP_CFG}.bak" ]; then
mv $XSTARTUP_CFG "${XSTARTUP_CFG}.bak"
fi
cat <<EOF > $XSTARTUP_CFG
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
EOF
chmod +x $XSTARTUP_CFG
VNC_SERVICE="/etc/systemd/system/vncserver@.service"
cat << EOF | sudo tee $VNC_SERVICE
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=HwHiAiUser
Group=HwHiAiUser
WorkingDirectory=/home/HwHiAiUser
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/bin/bash -c "sleep 10s && /usr/bin/vncserver -depth 24 -geometry 1280x800 :%i"
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable vncserver@0.service
sudo systemctl start vncserver@0
sudo systemctl status vncserver@0