|
#!/bin/bash |
|
# |
|
# TigerVNC Installer Script |
|
# ----------------------- |
|
# This script installs and configures TigerVNC server or client |
|
# based on the provided argument. |
|
# |
|
# Usage: ./tigervnc_install.sh [server|client] |
|
|
|
# Constants |
|
DEFAULT_PASSWORD="password" |
|
|
|
# Usage information |
|
usage() { |
|
echo "Usage: $0 [server|client]" |
|
echo " server - Install and configure TigerVNC server" |
|
echo " client - Install and configure TigerVNC client" |
|
exit 1 |
|
} |
|
|
|
# Check if argument is provided |
|
if [ $# -ne 1 ]; then |
|
usage |
|
fi |
|
|
|
install_server() { |
|
echo "Installing TigerVNC server..." |
|
|
|
# Determine package manager and install tigervnc server |
|
if command -v apt-get &> /dev/null; then |
|
apt-get update |
|
apt-get install -y xfce4 xfce4-goodies |
|
apt-get install -y tigervnc-standalone-server tigervnc-common tigervnc-xorg-extension |
|
else |
|
echo "Unsupported package manager. Please install TigerVNC server manually." |
|
exit 1 |
|
fi |
|
|
|
# Create necessary directories |
|
mkdir -p $HOME/.vnc |
|
|
|
# Set up VNC password |
|
echo "Setting up default VNC password..." |
|
echo "$DEFAULT_PASSWORD" | tigervncpasswd -f > $HOME/.vnc/passwd |
|
chmod 600 $HOME/.vnc/passwd # Restrict permissions to owner only |
|
echo "Default VNC password set successfully." |
|
|
|
# Create a basic xstartup file if it doesn't exist |
|
if [ ! -f $HOME/.vnc/xstartup ]; then |
|
cat > $HOME/.vnc/xstartup << 'EOF' |
|
#!/bin/sh |
|
# Start up the standard system desktop |
|
unset SESSION_MANAGER |
|
unset DBUS_SESSION_BUS_ADDRESS |
|
/usr/bin/startxfce4 |
|
EOF |
|
chmod +x $HOME/.vnc/xstartup |
|
fi |
|
|
|
# Create systemd service file for VNC |
|
# Consider whether running as root or regular user |
|
if [ "$(id -u)" -eq 0 ]; then |
|
# For root user |
|
cat > /etc/systemd/system/[email protected] << 'EOF' |
|
[Unit] |
|
Description=TigerVNC service |
|
After=syslog.target network.target |
|
|
|
[Service] |
|
Type=simple |
|
User=root |
|
Group=root |
|
WorkingDirectory=/root |
|
|
|
PIDFile=/root/.vnc/%H:590%i.pid |
|
ExecStartPre=-/bin/sh -c "/usr/bin/tigervncserver -kill :%i > /dev/null 2>&1" |
|
ExecStart=/usr/bin/tigervncserver -fg -depth 24 -geometry 1920x1080 -localhost no :%i |
|
ExecStop=/usr/bin/tigervncserver -kill :%i |
|
|
|
[Install] |
|
WantedBy=multi-user.target |
|
EOF |
|
|
|
systemctl daemon-reload |
|
systemctl enable [email protected] |
|
systemctl start [email protected] |
|
else |
|
# For regular user |
|
mkdir -p $HOME/.config/systemd/user |
|
cat > $HOME/.config/systemd/user/[email protected] << 'EOF' |
|
[Unit] |
|
Description=TigerVNC service |
|
After=syslog.target network.target |
|
|
|
[Service] |
|
Type=simple |
|
User=%u |
|
Group=%u |
|
WorkingDirectory=%h |
|
|
|
PIDFile=%h/.vnc/%H:590%i.pid |
|
ExecStartPre=-/bin/sh -c "/usr/bin/tigervncserver -kill :%i > /dev/null 2>&1" |
|
ExecStart=/usr/bin/tigervncserver -fg -depth 24 -geometry 1920x1080 -localhost no :%i |
|
ExecStop=/usr/bin/tigervncserver -kill :%i |
|
|
|
[Install] |
|
WantedBy=multi-user.target |
|
EOF |
|
|
|
systemctl --user daemon-reload |
|
systemctl --user enable [email protected] |
|
systemctl --user start [email protected] |
|
fi |
|
|
|
echo "TigerVNC server installed and configured successfully." |
|
echo "The server is now running on display :1 (port 5901)" |
|
echo "Make sure your firewall allows connections to port 5901" |
|
} |
|
|
|
install_client() { |
|
echo "Installing TigerVNC client..." |
|
|
|
# Determine package manager and install tigervnc client |
|
if command -v apt-get &> /dev/null; then |
|
apt-get update |
|
apt-get install -y tigervnc-viewer |
|
else |
|
echo "Unsupported package manager. Please install TigerVNC client manually." |
|
exit 1 |
|
fi |
|
|
|
# Create .vnc directory |
|
mkdir -p $HOME/.vnc |
|
|
|
echo "TigerVNC client installed successfully." |
|
echo |
|
echo "Configuration Instructions:" |
|
echo "--------------------------" |
|
echo "- Copy the server's password file:" |
|
echo " $ scp -rp <server-user>@<server-ip>:~/.vnc/passwd $HOME/.vnc/passwd.<server-user>" |
|
echo |
|
echo "- Connection methods:" |
|
echo " 1. Direct connection:" |
|
echo " $ vncviewer localhost::5901 -via <server-user>@<server-ip> -passwd $HOME/.vnc/passwd.<server-user>" |
|
echo |
|
echo " 2. SSH tunnel:" |
|
echo " $ ssh -Y -L 5901:localhost:5901 <server-user>@<server-ip>" # Terminal 1 |
|
echo " $ vncviewer localhost::5901 -passwd $HOME/.vnc/passwd.<server-user>" # Terminal 2 |
|
} |
|
|
|
# Main script logic |
|
case "$1" in |
|
server) |
|
install_server |
|
;; |
|
client) |
|
install_client |
|
;; |
|
*) |
|
usage |
|
;; |
|
esac |
|
|
|
exit 0 |