From 0a4fd2cbdcc60aa03b97a5dc5de47dd7ed4696a4 Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Mon, 1 May 2023 00:11:01 +0200 Subject: [PATCH] Nouveau script vncctl ; Nouveau script xstartup.turbovnc --- bin/vncctl | 97 +++++++++++++++++++++++++++++++------------ bin/xstartup.turbovnc | 4 ++ 2 files changed, 74 insertions(+), 27 deletions(-) create mode 100755 bin/xstartup.turbovnc diff --git a/bin/vncctl b/bin/vncctl index da9790f..bfe67a5 100755 --- a/bin/vncctl +++ b/bin/vncctl @@ -1,33 +1,76 @@ -#!/bin/bash +#!/bin/sh + +# cd to the local VNC directory, exit if it fails +cd "${HOME}/.vnc" || exit 6 # Variables -declare -a vncctl -systemctl=systemctl -systemd_unit=vncserver -verb="${1:-status}"; shift -display="${1:-1}" ; shift +file_base="./$(hostname):1." -# Prepending sudo if necessary -case "$verb" in - start|restart|stop) - sudo=sudo +error() { + >&2 printf '\033[1;31m%s\033[0m %s\n' "ERROR:" "$1" + shift + exit "$1" +} + +help() { + name="$(basename "$0")" + cat << EOF +${name} - Start a VNC server + +Usage: + ${name} start|status|stop|help +EOF +} + +usage() { + >&2 help + error "Invalid usage: ${1}" 1 +} + +is_running() { + vncserver -list | grep -q '^:1' +} + +start() { + if ! is_running; then + vncserver + else + error "The VNC server is already running!" 5 + fi +} + +status() { + log_f="${file_base}log" + if is_running; then + tail -f "$log_f" + else + error "The VNC server is not running!" 4 + fi +} + +stop() { + if is_running; then + vncserver -kill :1 + else + error "The VNC server is not running!" 3 + fi +} + +# Argument parsing +set -e; trap 'set +e; error "$error" "$?"' EXIT +error="You must give an argument" +[ -n "$1" ]; arg="$1"; shift +unset error +set +e; trap - EXIT + + +# Main case statement +case "$arg" in + start|status|stop|help) + "$arg" + ;; + *) + usage "Invalid argument \"$arg\"" ;; esac -# Command building -[[ -n $sudo ]] && vncctl+=("$sudo") -vncctl+=( - "$systemctl" - "$@" - "$verb" - "${systemd_unit}@:${display}" -) - -# Debug -#echo "${vncctl[@]}" -#exit 0 - -# Command execution -set -xe -"${vncctl[@]}" - diff --git a/bin/xstartup.turbovnc b/bin/xstartup.turbovnc new file mode 100755 index 0000000..5b63f1c --- /dev/null +++ b/bin/xstartup.turbovnc @@ -0,0 +1,4 @@ +#!/bin/sh +artix-pipewire-loader & +exec xfwm4 +