Compare commits
No commits in common. "d1ed4ae184f60254fde7fd46598e9d11aa04123b" and "cb3fc72d2b2684573a08062fc53c96d1bb1d2ef5" have entirely different histories.
d1ed4ae184
...
cb3fc72d2b
2 changed files with 103 additions and 51 deletions
138
bin/headlessvnc
138
bin/headlessvnc
|
@ -1,59 +1,107 @@
|
|||
#!/usr/bin/env sh
|
||||
perror() {
|
||||
>&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*"
|
||||
#!/bin/bash
|
||||
|
||||
# cd to the local VNC directory, exit if it fails
|
||||
cd "${HOME}/.vnc" || exit 5
|
||||
|
||||
# Variable
|
||||
verbs="start status stop restart help"
|
||||
|
||||
# echo bold text
|
||||
echobf() {
|
||||
printf '\033[1m%s\033[0m\n' "$*"
|
||||
}
|
||||
|
||||
error_usage() {
|
||||
perror "invalid usage"
|
||||
>&2 usage
|
||||
|
||||
exit 1
|
||||
# Print an error message
|
||||
print_error() {
|
||||
(
|
||||
printf '\033[1;31m%s\033[0m ' "ERROR:"
|
||||
echobf "$*"
|
||||
) > /dev/stderr
|
||||
}
|
||||
|
||||
# Print an error and exit
|
||||
error() {
|
||||
print_error "$1"
|
||||
shift
|
||||
exit "$1"
|
||||
}
|
||||
|
||||
# Check if the VNC server is running
|
||||
is_running() {
|
||||
vncserver -list | grep -q '^:1'
|
||||
vncserver -list | grep -q '^:1'
|
||||
}
|
||||
|
||||
start() {
|
||||
if ! is_running; then
|
||||
set -- vncserver \
|
||||
-localhost -alwaysshared \
|
||||
-securitytypes none
|
||||
[ -x ~/.vnc/xstartup ] && set -- "$@" -xstartup ~/.vnc/xstartup
|
||||
# Show a help message
|
||||
public_help() {
|
||||
local name
|
||||
name="$(basename "$0")"
|
||||
cat << EOF
|
||||
${name} - Start a VNC server
|
||||
|
||||
"$@"
|
||||
else
|
||||
perror "server already started"
|
||||
return 2
|
||||
fi
|
||||
Usage:
|
||||
${name} ${verbs// /|}
|
||||
EOF
|
||||
}
|
||||
|
||||
stop() {
|
||||
if is_running; then
|
||||
vncserver -kill :1
|
||||
else
|
||||
perror "server is not running"
|
||||
return 2
|
||||
fi
|
||||
# Show the same help with an error
|
||||
error_help() {
|
||||
print_error "Invalid usage"
|
||||
>&2 public_help
|
||||
return 1
|
||||
}
|
||||
|
||||
status() {
|
||||
if is_running; then
|
||||
printf '\033[1;32m*\033[0m \033[1m%s\n' "the server is running"
|
||||
else
|
||||
printf '\033[1;31m*\033[0m \033[1m%s\n' "the server is not running"
|
||||
fi
|
||||
# Start the VNC server
|
||||
public_start() {
|
||||
if ! is_running; then
|
||||
set -e
|
||||
vncserver \
|
||||
-xstartup ./xstartup \
|
||||
-localhost \
|
||||
-alwaysshared \
|
||||
-securitytypes none \
|
||||
-nocursor \
|
||||
-geometry 1600x900
|
||||
else
|
||||
error "The VNC server is already running!" 4
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
""|status) status ;;
|
||||
start) start ;;
|
||||
stop) stop ;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
error_usage
|
||||
;;
|
||||
esac
|
||||
# Check if the server is running
|
||||
public_status() {
|
||||
if is_running; then
|
||||
echobf "The VNC server is running."
|
||||
tail "./$(cat /proc/sys/kernel/hostname):1.log" | sed 's/^/\t/g'
|
||||
else
|
||||
echobf "The VNC server is not running."
|
||||
fi
|
||||
}
|
||||
|
||||
# Stop the VNC server
|
||||
public_stop() {
|
||||
if is_running; then
|
||||
vncserver -kill :1
|
||||
else
|
||||
error "The VNC server is not running!" 3
|
||||
fi
|
||||
}
|
||||
|
||||
# Restart the VNC server
|
||||
public_restart() {
|
||||
public_stop
|
||||
public_start
|
||||
}
|
||||
|
||||
# Parse argument
|
||||
if [ -n "$1" ]; then
|
||||
arg="$1"
|
||||
else
|
||||
arg=status
|
||||
fi
|
||||
|
||||
# Main switch
|
||||
if echo "$verbs" | tr ' ' '\n' | grep -q "$arg"; then
|
||||
"public_${arg}"
|
||||
else
|
||||
error_help
|
||||
fi
|
||||
|
||||
|
|
16
vnc/xstartup
16
vnc/xstartup
|
@ -1,11 +1,15 @@
|
|||
#!/usr/bin/env sh
|
||||
cd || exit
|
||||
#!/bin/sh -xe
|
||||
|
||||
[ -z "$DBUS_SESSION_BUS_ADDRESS" ] && \
|
||||
exec dbus-launch --exit-with-session -- "$0" "$@"
|
||||
self="$(readlink -f "$0")"
|
||||
cd
|
||||
|
||||
[ -z "$SSH_AGENT_PID" ] && \
|
||||
exec ssh-agent -- "$0" "$@"
|
||||
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
|
||||
exec dbus-launch --exit-with-session "$self" "$@"
|
||||
fi
|
||||
|
||||
if [ -z "$SSH_AGENT_PID" ]; then
|
||||
exec ssh-agent "$self" "$@"
|
||||
fi
|
||||
|
||||
xfwm4 &
|
||||
artix-pipewire-launcher restart &
|
||||
|
|
Loading…
Reference in a new issue