Skip to content

Instantly share code, notes, and snippets.

@bgyarfas
Last active April 8, 2022 17:17
Show Gist options
  • Save bgyarfas/41470dd3045519786793bad1fc744b14 to your computer and use it in GitHub Desktop.
Save bgyarfas/41470dd3045519786793bad1fc744b14 to your computer and use it in GitHub Desktop.
Script to setup vino on a Jetson.
#!/bin/bash
# Script for remotely setting up VNC on a Jetson TX2 running Jetpack 4.6 over ssh
# You can run the script in a one shot with the following command
# sudo apt -y install curl && sudo /bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/bgyarfas/41470dd3045519786793bad1fc744b14/raw/b7bbb04929bc764194e27d419c7cbae58bbd9508/setup_vino.sh)"
if [[ $EUID -ne 0 ]]; then
echo "$0 is not running as root. Try using sudo."
exit 2
fi
file=/usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml
if ! grep -q "<key name='enabled' type='b'>" $file; then
echo -n "Adding enabled key to $file..."
sed '/^[[:space:]]*<\/key>/r'<(
echo "<key name='enabled' type='b'>"
echo "<summary>Enable remote access to the desktop</summary>"
echo "<description>"
echo "If true, allows remote access to the desktop via the RFB"
echo "protocol. Users on remote machines may then connect to the"
echo "desktop using a VNC viewer."
echo "</description>"
echo "<default>true</default>"
echo "</key>"
) -i -- $file
echo "Done!"
else
echo "$file already contains enabled key..."
fi
autostart_dir=$HOME/.config/autostart
if [ ! -d $autostart_dir ]; then
echo "Creating autostart directory $autostart_dir..."
mkdir -p $autostart_dir
fi
vino_autostart=$autostart_dir/vino-server.desktop
if [ ! -f $vino_autostart ]; then
echo "Adding $vino_autostart..."
cat <<EOT >> $vino_autostart
[Desktop Entry]
Type=Application
Exec=/usr/lib/vino/vino-server
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Vino
Name=Vino
Comment[en_US]=
Comment=
EOT
chown $SUDO_USER:$SUDO_USER $vino_autostart
else
echo "Already have $vino_autostart..."
fi
# Read Password
echo ""
echo "Enter a new VNC password..."
while :
do
echo -n New VNC Password:
read -s password_1
echo
# Read Password Again
echo -n Re-enter new VNC password:
read -s password_2
echo
if [[ "$password_1" != "$password_2" ]]; then
echo "Passwords don't match! Try again..."
else
break
fi
done
gsettings set org.gnome.Vino require-encryption false
gsettings set org.gnome.Vino prompt-enabled false
gsettings set org.gnome.Vino enabled true
gsettings set org.gnome.Vino authentication-methods "['vnc']"
gsettings set org.gnome.Vino view-only false
gsettings set org.gnome.Vino vnc-password $(echo -n "$password_1"|base64)
echo "Setup complete!"
echo ""
echo "Restart the system and re-login and VNC should be accessible at $HOSTNAME.local..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment