#!/bin/bash

# Download dependencies and extras.
apt-get update && apt-get install --yes xfce4 xfce4-terminal mousepad \
    default-jre firefox-esr \
    sqlmap

# Download OWASP ZAP.
zap_version="2.12.0"
echo "Downloading ZAP ${zap_version} package (this may take a minute) ..."
wget --progress dot:giga -O- \
    "https://github.com/zaproxy/zaproxy/releases/download/v${zap_version}/ZAP_${zap_version}_Linux.tar.gz" \
    | tar -xzf -

# Prepare the menu item entry in the Desktop Environment.
mkdir -p .local/share/applications .icons/hicolor
wget --quiet -O .icons/hicolor/zap.png https://avatars0.githubusercontent.com/u/6716868
cat <<EOF > .local/share/applications/ZAP.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=ZAP
Exec=ZAP_${zap_version}/zap.sh
Icon=/home/vagrant/.icons/hicolor/zap.png
Categories=
EOF

# Automatically start XFCE graphical Desktop Environment on login.
cat <<EOF > .bash_profile
#!/bin/bash
if systemctl -q is-active graphical.target && [[ ! \$DISPLAY && \$XDG_VTNR -eq 1 ]]; then
    exec startx
fi
EOF

# Ensure the `vagrant` user can log in via console.
echo "vagrant:vagrant" | chpasswd

chown -R vagrant:vagrant ./
