#!/bin/sh
echo this is not actually a script
exit 1

# this will create an Alpine 3.9 VirtualBox VM
# with WebGL sort-of-working in Firefox and Chrome
# (firefox-esr is the least glitchy in the single test i have w)
#
# in VirtualBox v6.0+ you get OpenGL and pretty decent performance:
#   vm settings >> display >> graphics controller = VMSVGA
#   vm settings >> display >> [x] Enable 3D Acceleration
#
# in older VirtualBox versions you only get the old vbox driver
# so it does multimedia okay-ish but no OpenGL or WebGL


# start by installing Alpine!
# when asked, use disk "sda" in "sys" mode
ROOTFS=btrfs SWAP_SIZE=0 setup-alpine


# if you enabled sshd, you'll probably get stuck during startup
# due to low entropy. Fix that by typing random letters for a bit,
# then install haveged so it doesn't happen again :p
apk add haveged
service haveged start
rc-update add haveged


# enable the v3.9/community repo by uncommenting it
vi /etc/apk/repositories


# create yourself a user account
adduser -u 1000 ed


# the Xfce4 version in Alpine 3.9 is kinda buggy,
# but the following themes work correctly when combined
# (if you want a dark theme, add gnome-themes-standard)
apk add xfce4 xfce4-terminal lxdm mesa-dri-vmwgfx \
  greybird-themes faenza-icon-theme adwaita-icon-theme \
  urxvt geany


# if you are running VirtualBox v5.x or older,
apk add virtualbox-guest-modules-vanilla
# endif :p


# grant yourself permission to do multimedia stuff
for g in audio video ping; do addgroup ed $g; done


# we need modesetting before we can continue
sed -i 's/ nomodeset//' /boot/extlinux.conf
reboot


# install the required xf86 packages
setup-xorg-base


# set Xfce to autostart
rc-update add dbus
rc-update add lxdm


# done!
reboot


# if xfce4-terminal fails to start,
# fix it with ALT-F2 urxvt and then
apk add gsettings-desktop-schemas


# when you reach the login prompt after the reboot,
# change the bottom-right dropdown to "Xfce Session"
#
# you can enable autologin after one successful regular login
# (replace 'ed' with your username)
cd /etc/lxdm
echo [base] >> lxdm.conf
echo autologin=ed >> lxdm.conf


# if you want audio, turn up the volume (pgup/pgdn)
# and unmute (M-key) the "Master" and "PCM" mixers:
apk add alsa-utils
alsamixer


# test video/audio playback
apk add mpv
mpv -fs -ss 20 https://ocv.me/stuff/railgun.mkv
# (if that lags, turn off subtitles with the V-key)


# btw, (probably) due to an Xfce race condition,
# sometimes your theme will fail to load...
# "it can't be helped" :)


# and finally a VirtuaBox trick:
# you can use the ssd trim command to purge deleted files from the
# disk image (which reduces the disk space used on your host machine),
# but you'll have to enable it by shutting down all VMs and closing
# VirtualBox itself before editing $VMNAME.vbox (an XML file).
#
# locate the <AttachedDevice> tag which contains nonrotational="true"
# and add the following new attribute:  discard="true"
#
# then start the VM and issue a trim command:
fstrim -v /
