Sharedwww / t42 / fakexOpen in CoCalc
#! /bin/sh

# Modified version of function from swsusp2 script "hibernate".
# by William Stein
# GPL, etc. 2004.

SWSUSP_LEAVE_X_BEFORE_SUSPEND="nvidia"
VERBOSE="/tmp/verbose"

SwitchToX() {
    if [ "$SWSUSP_LEAVE_X_BEFORE_SUSPEND" = "nvidia" ]; then
	export XAUTHORITY=/tmp/.Xauthority-swsusp-fake-x-server
        export HOME=/dev/shm
        xauth 2> $VERBOSE 1> $VERBOSE <<EOF
add :3 . 00
generate :3.0 .
EOF
        if [ -x /usr/bin/X11/xmessage -a "$DISTRIB" != "Gentoo" ] ;then
            xinit /usr/bin/X11/xmessage -font huge -display :3.0 -center -timeout 2 "  Xserver for restoring video acceleration.  " -- :3
        else
            xinit /bin/false -- :3 2> $VERBOSE 1> $VERBOSE
        fi
        xauth 2> $VERBOSE 1> $VERBOSE <<EOF
remove :3
remove :3.0
EOF
    fi

    test $SWSUSP_LEAVE_X_BEFORE_SUSPEND != "no" && echo -e "\033[1;32m * \033[0mSwitching back to X..." | $LOGCMD > $VERBOSE

    # if fgconsole is available, the original VT will be stored in this var
    if [ "$ORIGINAL_VT" != "" ]; then
        chvt "$ORIGINAL_VT"
    else
        echo "Original virtual terminal not memorized (trying 7)"
        chvt 7
    fi
    
    return $?
}

SwitchToX