#!/bin/bash

set -o errexit

# NB: This script must be run with root privileges in order to have any effect!

CURRENT_VT=`/bin/fgconsole`

if [ "$CURRENT_VT" == "" ]
then
    echo "Unable to determine current virtual terminal." >&2
    exit 1
fi

if [ "$CURRENT_VT" -ne "1" ]
then
    chvt 1
else
    chvt 2
fi

sleep 2
chvt "$CURRENT_VT"
sleep 2

# make sure we switched back
END_VT=`/bin/fgconsole`
if [ "$END_VT" -ne "$CURRENT_VT" ]
then
    echo "didn't get back to the original VT" >&2
    exit 1
fi
