## Setup

### Install base dependencies

```bash
sudo apt update
sudo apt install xfce4 xfce4-goodies
sudo apt install tightvncserver
```

### Setup VNC server

- Set password
```bash
vncserver
vncserver -kill :1
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
```

- Create `xstartup` file
```bash
vim ~/.vnc/xstartup
```

```bash
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
```

- Make it executable
```bash
chmod +x ~/.vnc/xstartup
```

- Restart the VNC server
```bash
vncserver -localhost
```

### Running VNC as a System Service

- Create systemd file
```bash
sudo vim /etc/systemd/system/vncserver@.service
```

```service
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu

PIDFile=/home/ubuntu/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target
```

- Make the system aware of the new unit file
```bash
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
```

- Reload vncserver
```bash
vncserver -kill :1
sudo systemctl start vncserver@1
sudo systemctl status vncserver@1
```

### Install contiki dependencies
```bash
sudo apt-get install build-essential binutils-msp430 gcc-msp430 msp430-libc msp430mcu mspdebug openjdk-8-jdk openjdk-8-jre ant libncurses5-dev lib32ncurses5 gdb-multiarch

sudo apt-get install avr-libc gcc-avr
```

## Select java version
Option 2: `/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java`
```bash
sudo update-alternatives --config java
```

## Install contiki
```bash
git clone --recurse-submodules --branch 3.0 https://github.com/contiki-os/contiki
```

## Connecting to the VNC Desktop Securely
- Open ssh tunel
```bash
ssh -L 5901:127.0.0.1:5901 -C -N -i ~/.ssh/AWS_PEM AWS_PUBLIC_DNS
```
- Open Screen Sharing (macos) using `localhost:5901`

## References 
- https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-20-04