Compare commits

..

3 commits

2 changed files with 51 additions and 103 deletions

View file

@ -1,107 +1,59 @@
#!/bin/bash #!/usr/bin/env sh
perror() {
# cd to the local VNC directory, exit if it fails >&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*"
cd "${HOME}/.vnc" || exit 5
# Variable
verbs="start status stop restart help"
# echo bold text
echobf() {
printf '\033[1m%s\033[0m\n' "$*"
} }
# Print an error message error_usage() {
print_error() { perror "invalid usage"
( >&2 usage
printf '\033[1;31m%s\033[0m ' "ERROR:"
echobf "$*" exit 1
) > /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'
} }
# Show a help message start() {
public_help() {
local name
name="$(basename "$0")"
cat << EOF
${name} - Start a VNC server
Usage:
${name} ${verbs// /|}
EOF
}
# Show the same help with an error
error_help() {
print_error "Invalid usage"
>&2 public_help
return 1
}
# Start the VNC server
public_start() {
if ! is_running; then if ! is_running; then
set -e set -- vncserver \
vncserver \ -localhost -alwaysshared \
-xstartup ./xstartup \ -securitytypes none
-localhost \ [ -x ~/.vnc/xstartup ] && set -- "$@" -xstartup ~/.vnc/xstartup
-alwaysshared \
-securitytypes none \ "$@"
-nocursor \
-geometry 1600x900
else else
error "The VNC server is already running!" 4 perror "server already started"
return 2
fi fi
} }
# Check if the server is running stop() {
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 if is_running; then
vncserver -kill :1 vncserver -kill :1
else else
error "The VNC server is not running!" 3 perror "server is not running"
return 2
fi fi
} }
# Restart the VNC server status() {
public_restart() { if is_running; then
public_stop printf '\033[1;32m*\033[0m \033[1m%s\n' "the server is running"
public_start else
printf '\033[1;31m*\033[0m \033[1m%s\n' "the server is not running"
fi
} }
# Parse argument case "$1" in
if [ -n "$1" ]; then ""|status) status ;;
arg="$1" start) start ;;
else stop) stop ;;
arg=status restart)
fi stop
start
# Main switch ;;
if echo "$verbs" | tr ' ' '\n' | grep -q "$arg"; then *)
"public_${arg}" error_usage
else ;;
error_help esac
fi

View file

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