Compare commits

..

No commits in common. "d1ed4ae184f60254fde7fd46598e9d11aa04123b" and "cb3fc72d2b2684573a08062fc53c96d1bb1d2ef5" have entirely different histories.

2 changed files with 103 additions and 51 deletions

View file

@ -1,59 +1,107 @@
#!/usr/bin/env sh #!/bin/bash
perror() {
>&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*" # 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() { # Print an error message
perror "invalid usage" print_error() {
>&2 usage (
printf '\033[1;31m%s\033[0m ' "ERROR:"
exit 1 echobf "$*"
) > /dev/stderr
} }
# Print an error and exit
error() {
print_error "$1"
shift
exit "$1"
}
# Check if the VNC server is running
is_running() { is_running() {
vncserver -list | grep -q '^:1' vncserver -list | grep -q '^:1'
} }
start() { # Show a help message
if ! is_running; then public_help() {
set -- vncserver \ local name
-localhost -alwaysshared \ name="$(basename "$0")"
-securitytypes none cat << EOF
[ -x ~/.vnc/xstartup ] && set -- "$@" -xstartup ~/.vnc/xstartup ${name} - Start a VNC server
"$@" Usage:
else ${name} ${verbs// /|}
perror "server already started" EOF
return 2
fi
} }
stop() { # Show the same help with an error
if is_running; then error_help() {
vncserver -kill :1 print_error "Invalid usage"
else >&2 public_help
perror "server is not running" return 1
return 2
fi
} }
status() { # Start the VNC server
if is_running; then public_start() {
printf '\033[1;32m*\033[0m \033[1m%s\n' "the server is running" if ! is_running; then
else set -e
printf '\033[1;31m*\033[0m \033[1m%s\n' "the server is not running" vncserver \
fi -xstartup ./xstartup \
-localhost \
-alwaysshared \
-securitytypes none \
-nocursor \
-geometry 1600x900
else
error "The VNC server is already running!" 4
fi
} }
case "$1" in # Check if the server is running
""|status) status ;; public_status() {
start) start ;; if is_running; then
stop) stop ;; echobf "The VNC server is running."
restart) tail "./$(cat /proc/sys/kernel/hostname):1.log" | sed 's/^/\t/g'
stop else
start echobf "The VNC server is not running."
;; fi
*) }
error_usage
;; # Stop the VNC server
esac 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

View file

@ -1,11 +1,15 @@
#!/usr/bin/env sh #!/bin/sh -xe
cd || exit
[ -z "$DBUS_SESSION_BUS_ADDRESS" ] && \ self="$(readlink -f "$0")"
exec dbus-launch --exit-with-session -- "$0" "$@" cd
[ -z "$SSH_AGENT_PID" ] && \ if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
exec ssh-agent -- "$0" "$@" exec dbus-launch --exit-with-session "$self" "$@"
fi
if [ -z "$SSH_AGENT_PID" ]; then
exec ssh-agent "$self" "$@"
fi
xfwm4 & xfwm4 &
artix-pipewire-launcher restart & artix-pipewire-launcher restart &