Skip to content

Commit

Permalink
feat(vine): improve wayland support
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Nov 8, 2024
1 parent ec854fd commit 0ed05c7
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 60 deletions.
6 changes: 6 additions & 0 deletions templates/devel/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ fi
# Create User Password #
###########################################################

set +x
if [ "x${USER_PASSWORD}" != 'x' ]; then
echo -e "${USER_PASSWORD}\n${USER_PASSWORD}\n" |
sudo passwd "${USER_NAME}"
fi
unset USER_PASSWORD
set -x

###########################################################
# Change User Shell #
###########################################################

set +x
if [ "x${USER_SHELL}" != 'x' ]; then
chsh --shell "${USER_SHELL}" "${USER_NAME}"
fi
unset USER_SHELL
set -x

###########################################################
# Copy podman containers configuration file #
Expand Down
9 changes: 9 additions & 0 deletions templates/vine/desktop/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ RUN true \
# Update repositories
&& find /etc/apt/sources.list.d/ -type f -exec sh -c \
'mv "{}" "{}.bak" && envsubst < "{}.bak" >"{}" && rm "{}".bak' \; \
# Install apt-fast
&& add-apt-repository -y 'ppa:apt-fast/stable' \
&& apt-get update && apt-get install -y apt-fast \
&& echo debconf apt-fast/aptmanager string apt-get | debconf-set-selections \
&& echo debconf apt-fast/dlflag boolean true | debconf-set-selections \
&& echo debconf apt-fast/maxdownloads string 16 | debconf-set-selections \
# Cleanup
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -240,6 +246,8 @@ RUN apt-get update && apt-get install -y \
zsh-autosuggestions \
zsh-completions \
zsh-syntax-highlighting \
# Backup SSH Configuration
&& cp -r /etc/ssh /etc/.ssh \
# Cleanup
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -690,6 +698,7 @@ RUN mkdir -p /opt/public/ \
&& chown -R "${USER_UID}:${USER_GID}" /opt/public/

# Add scripts
ADD ./config/weston.ini /etc/xdg/weston/weston.ini
ADD ./scripts /opt/scripts/
RUN chmod 0555 /opt/scripts/*

Expand Down
11 changes: 11 additions & 0 deletions templates/vine/desktop/config/weston.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[core]
xwayland=true

[shell]
# background-image=none
binding-modifier=super
client-side-decorations=true
locking=false
num-workspaces=1
# panel-location=none
startup-animation=none
16 changes: 16 additions & 0 deletions templates/vine/desktop/scripts/entrypoint-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@ export __ENV_HOME='/tmp/.openark-vine-env'
rm -rf "${__ENV_HOME}"
touch "${__ENV_HOME}"

# Assert home directory's permission
if sudo whoami >/dev/null; then
sudo mkdir -p "${HOME}/.local/share/containers/storage"
sudo chown "$(id -u):$(id -g)" \
"${HOME}/" \
"${HOME}/.local" \
"${HOME}/.local/share" \
"${HOME}/.local/share/containers" \
"${HOME}/.local/share/containers/storage"
fi

# Initialize rootless container xdg session
"$(dirname "$0")/init-desktop-xdg.sh"

# Initialize rootless container wayland session
"$(dirname "$0")/init-desktop-wayland.sh"

# Initialize rootless container ssh session
"$(dirname "$0")/init-desktop-ssh.sh"
unset USER_PASSWORD
unset USER_SHELL

# Initialize rootless container environment
"$(dirname "$0")/init-desktop-podman.sh"

Expand Down
18 changes: 18 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-display.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ source "${__ENV_HOME}"

# Configure screen size
function update_screen_size() {
echo "Finding displays..."
screens="$(xrandr --current | grep ' connected ' | awk '{print $1}')"
if [ "x${screens}" == "x" ]; then
echo 'Display not found!'
return
fi

for screen in $(echo -en "${screens}"); do
# Skip virtual displays
if echo "${screen}" | grep -Poqs '^None-[0-9-]+$'; then
xrandr --output "${screen}" --off || true
continue
fi

echo "Fixing screen to preferred (${screen})..."
xrandr --output "${screen}" --auto --preferred || true
done

echo "Configuring screen size..."
xrandr --auto || true

Expand Down
82 changes: 82 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-ssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
# Copyright (c) 2024 Ho Kim ([email protected]). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.

# Prehibit errors
set -e -o pipefail
# Verbose
set -x

# Test the sudo permission
if ! sudo whoami >/dev/null; then
exec true
fi

# Create SSH daemon home
if [ ! -d "/run/sshd" ]; then
sudo mkdir /run/sshd
fi

# Generate host SSH keys
if [ ! -f "/etc/ssh/ssh_host_ed25519_key.pub" ]; then
cp -r /etc/.ssh/* /etc/ssh
sudo ssh-keygen -q -A
fi

# Generate user SSH keys
if [ ! -f "${HOME}/.ssh/id_ed25519" ]; then
ssh-keygen -q -t ed25519 -f "${HOME}/.ssh/id_ed25519" -N ''
fi

# Change user password
set +x
if [ "x${USER_PASSWORD}" != 'x' ]; then
echo -e "${USER_PASSWORD}\n${USER_PASSWORD}\n" |
sudo -S passwd "$(whoami)"
fi
unset USER_PASSWORD
set -x

# Change user shell
set +x
if [ "x${USER_SHELL}" != 'x' ]; then
sudo chsh --shell "$(which "${USER_SHELL}")" "$(whoami)"
fi
unset USER_SHELL
set -x

# Copy hosts file
if [ -f "${HOME}/.hosts" ]; then
cat "${HOME}/.hosts" | sudo tee -a /etc/hosts >/dev/null
fi

# Propagate environment variables to the session
cat "${__ENV_HOME}" |
grep -Po '^export +\K.*$' |
sudo tee -a /etc/environment >/dev/null

# Share public environment variables
for env_key in $(
export |
grep -Po '^declare \-x \K[a-zA-Z0-9_]+'
); do
if [ "x${env_key}" = 'x' ]; then
continue
elif [ "x${env_key}" = 'xHOME' ]; then
continue
elif [ "x${env_key}" = 'xOLDPWD' ]; then
continue
elif [ "x${env_key}" = 'xPWD' ]; then
continue
elif [ "x${env_key}" = 'xSHLVL' ]; then
continue
elif echo "x${env_key}" | grep -q '^xUSER_'; then
continue
fi

echo "${env_key}=\"${!env_key}\"" | sudo tee -a /etc/environment >/dev/null
done

# Run SSH Server
sudo /usr/sbin/sshd -D &
65 changes: 42 additions & 23 deletions templates/vine/desktop/scripts/init-desktop-wayland.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,73 @@ set -x

# Configure environment variables
export DISPLAY="${DISPLAY:-:0}"
export WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}"

echo "export DISPLAY=\"${DISPLAY}\"" >>"${__ENV_HOME}"
# FIXME: Vulkan support is not stable on Wayland backend
# echo "export WAYLAND_DISPLAY=\"${WAYLAND_DISPLAY}\"" >>"${__ENV_HOME}"

# Create an empty X11 socket directory, if not exists
mkdir -p "/tmp/.X11-unix"

# Detect GPU Devices
if nvidia-smi >/dev/null 2>/dev/null; then
export VK_DRIVER_FILES="/usr/share/vulkan/icd.d/nvidia_icd.json"
export VK_ICD_FILENAMES="${VK_DRIVER_FILES}"

# Make these environment variables persistent
echo "export VK_DRIVER_FILES=\"${VK_DRIVER_FILES}\"" >>"${__ENV_HOME}"
echo "export VK_ICD_FILENAMES=\"${VK_ICD_FILENAMES}\"" >>"${__ENV_HOME}"
fi

# Create a xwayland session, if not exists
if [ ! -S "/tmp/.X11-unix/X$(echo $DISPLAY | grep -Po '[0-9]+$')" ]; then
if [ ! -S "/tmp/.X11-unix/X$(echo "${DISPLAY}" | grep -Po '[0-9]+$')" ]; then
# Configure environment variables
export WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}"
echo "export WAYLAND_DISPLAY=\"${WAYLAND_DISPLAY}\"" >>"${__ENV_HOME}"

# Configure wayland
WAYLAND_BACKEND_RDP='rdp-backend.so'
WAYLAND_BACKEND_VNC='vnc-backend.so'

WAYLAND_ARGS="${WAYLAND_ARGS} --shell=kiosk-shell.so"
# FIXME: Vulkan support is not stable on Wayland backend
# WAYLAND_ARGS="${WAYLAND_ARGS} --socket=${WAYLAND_DISPLAY}"
WAYLAND_ARGS="${WAYLAND_ARGS} --socket=${WAYLAND_DISPLAY}"
WAYLAND_ARGS="${WAYLAND_ARGS} --xwayland"
WAYLAND_BACKEND="${WAYLAND_BACKEND:-$WAYLAND_BACKEND_RDP}"
WAYLAND_BACKEND="${WAYLAND_BACKEND:-$WAYLAND_BACKEND_VNC}"
WAYLAND_TLS_HOME="${HOME}/.rdp"

# Configure RDP
# Detect backend kind
if [ "x${WAYLAND_BACKEND}" == "x${WAYLAND_BACKEND_RDP}" ]; then
WAYLAND_BACKEND_KIND='rdp'
elif [ "x${WAYLAND_BACKEND}" == "x${WAYLAND_BACKEND_VNC}" ]; then
WAYLAND_BACKEND_KIND='vnc'
else
WAYLAND_BACKEND_KIND=''
fi

# Configure remote backend
if [ "x${WAYLAND_BACKEND_KIND}" != 'x' ]; then
# Generate a TLS key pair
WAYLAND_RDP_TLS_HOME="${HOME}/.rdp"
if [ ! -f "${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.crt" ] ||
[ ! -f "${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.key" ]; then
mkdir -p "${WAYLAND_RDP_TLS_HOME}"
chmod 700 "${WAYLAND_RDP_TLS_HOME}"
winpr-makecert -rdp -path "${WAYLAND_RDP_TLS_HOME}" >/dev/null
if [ ! -f "${WAYLAND_TLS_HOME}/${HOSTNAME}.crt" ] ||
[ ! -f "${WAYLAND_TLS_HOME}/${HOSTNAME}.key" ]; then
mkdir -p "${WAYLAND_TLS_HOME}"
chmod 700 "${WAYLAND_TLS_HOME}"
winpr-makecert -rdp -path "${WAYLAND_TLS_HOME}" >/dev/null
fi

# Register the RDP TLS key pair
WAYLAND_ARGS="${WAYLAND_ARGS} --rdp-tls-cert ${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.crt"
WAYLAND_ARGS="${WAYLAND_ARGS} --rdp-tls-key ${WAYLAND_RDP_TLS_HOME}/${HOSTNAME}.key"
# Register the TLS key pair
WAYLAND_ARGS="${WAYLAND_ARGS} "--${WAYLAND_BACKEND_KIND}-tls-cert" ${WAYLAND_TLS_HOME}/${HOSTNAME}.crt"
WAYLAND_ARGS="${WAYLAND_ARGS} "--${WAYLAND_BACKEND_KIND}-tls-key" ${WAYLAND_TLS_HOME}/${HOSTNAME}.key"
fi

# Detect GPU Devices
if nvidia-smi >/dev/null 2>/dev/null; then
export __GLX_VENDOR_LIBRARY_NAME="nvidia"
export __NV_PRIME_RENDER_OFFLOAD="1"
export VK_DRIVER_FILES="/usr/share/vulkan/icd.d/nvidia_icd.json"
export VK_ICD_FILENAMES="${VK_DRIVER_FILES}"

# Make these environment variables persistent
echo "export __GLX_VENDOR_LIBRARY_NAME=\"${__GLX_VENDOR_LIBRARY_NAME}\"" >>"${__ENV_HOME}"
echo "export __NV_PRIME_RENDER_OFFLOAD=\"${__NV_PRIME_RENDER_OFFLOAD}\"" >>"${__ENV_HOME}"
echo "export VK_DRIVER_FILES=\"${VK_DRIVER_FILES}\"" >>"${__ENV_HOME}"
echo "export VK_ICD_FILENAMES=\"${VK_ICD_FILENAMES}\"" >>"${__ENV_HOME}"
fi

# Disable default weston terminal
if sudo whoami >/dev/null; then
sudo ln -sf /usr/bin/xfce4-terminal /usr/bin/weston-terminal
fi

weston --backend="${WAYLAND_BACKEND}" ${WAYLAND_ARGS} &
Expand Down
3 changes: 3 additions & 0 deletions templates/vine/desktop/scripts/init-desktop-xfce4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ unset __ENV_HOME
rm -rf "${HOME}/.cache/sessions/" || true

# Run desktop environment
if find "${XDG_RUNTIME_DIR}" -mindepth 1 -maxdepth 1 -name 'wayland-*' -type s | grep -q .; then
exec sleep infinity
fi
exec /usr/bin/dbus-launch --auto-syntax xfce4-session
Loading

0 comments on commit 0ed05c7

Please sign in to comment.