#!/bin/bash
echo <<THIS_IS_NOT_A_SCRIPT

   replace yournick with your account name
   
   textmode install guide stops at line 63,
   graphical install guide stops at line 150,
   remainder is convenience and visual tweaks which
   turns into https://ocv.me/doc/alpine/res/xfce.png

   ver.2 (2019-03-10)
   └─ minor adjustments and clarifications

   ver.1 (2018-07-29)
   └─ first version

THIS_IS_NOT_A_SCRIPT
exit 1


# change shell to bash
bash
vim /etc/passwd
# change /bin/ash to /bin/bash


# make yourself a user account
adduser -u 1000 -s /bin/bash yournick
# and add yourself to these groups:
# audio video abuild ping www-data
for g in audio video abuild ping; do addgroup yournick $g; done


# if uefi with extlinux:
# take a backup of /boot in case the config gets overwritten
cd /boot
cp -pv extlinux.conf{,.01}
cp -pv EFI/boot/syslinux.cfg{,.01}




# in case you forgot to set up wifi during setup-alpine,
# or in case your wifi has a unique name such as 👌
#
# the name must be provided as plain text (meaning unescaped unicode),
# so there's two options
#
# 1) do this over putty and paste the name as-is, for example 👌
SSID="👌"
#
# 2) figure out the UTF8 encoding so you can use printf to unescape it;
#    on a unix machine with a GUI you could obtain \xf0\x9f\x91\x8c using:
#    printf 👌 | hexdump -ve '1/1 "%02x"' | sed -r 's/(..)/\\x\1/g'
SSID="$(printf '\xf0\x9f\x91\x8c')"
#
# either way define $SSID somehow and...
mount /dev/sda1 /media/floppy
cd /media/floppy/apks/x86_64
apk add wpa_supplicant-2.* dbus-libs-1.* libnl3-3.* pcsc-lite-libs-1.* wireless-tools-*
ip link set wlan0 up
iwlist wlan0 scanning
iwconfig wlan0 essid "$SSID"
wpa_passphrase "$SSID" > /etc/wpa_supplicant/wpa_supplicant.conf


# connecting to the wifi
ip link set wlan0 up
wpa_supplicant -Dwext -iwlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf &
udhcpc -i wlan0 &  # after a couple seconds




# installing updates
apk update
apk upgrade -a
ip link set wlan0 down
# reboot if kernel was upgraded


# install some essential software
apk add bash bzip2 chrony coreutils cryptsetup diffutils dosfstools e2fsprogs e2fsprogs-extra findutils grep gzip htop iputils less lm_sensors lshw man mc mosh nano ncdu net-tools nmap-ncat openssh p7zip pigz pm-utils powertop pv py-virtualenv python python3 rsync smartmontools socat strace sudo syslinux tar tmux tmux-doc upower util-linux vim weechat wget wireless-tools wpa_supplicant xz zip


# install some less essential software
apk add alpine-sdk autoconf automake axel cdrkit cmake dropbear exiftool ezstream ffmpeg g++ gdb imagemagick iptables irssi mpv nginx nmap ntfs-3g pciutils php7-fpm pngquant qemu qemu-img qemu-system-x86_64 rtorrent sshfs 


# OPTIONAL 1: fancy bootloader (syslinux only, not grub)
#
# when saving your own jpg in gimp, open the advanced options
# and make sure that Optimize is ON, and Progressive is OFF
#
cd /boot/EFI/boot
wget https://ocv.me/doc/alpine/res/alp_1366.jpg
echo <<CHANGES_IN_SYSLINUX_CFG

remove:
	DEFAULT menu.c32
	PROMPT 0

add:
	DEFAULT vesamenu.c32
	PROMPT 0

	MENU RESOLUTION 1366 768
	MENU BACKGROUND /EFI/boot/alp_1366.jpg

	MENU COLOR title  1;37;44 #ffffffff #00000000 none
	MENU COLOR unsel    37;44 #ccffffff #00000000 none
	MENU COLOR hotkey 1;37;44 #ffffffff #00000000 none
	MENU COLOR sel    7;37;44 #ffffffff #66000000 none
	MENU COLOR hotsel 7;37;44 #ffffffff #aa000000 none
	MENU COLOR disabled 37;44 #ccffffff #00000000 none

CHANGES_IN_SYSLINUX_CFG
vim syslinux.cfg


# OPTIONAL 2: fancy bashrc
wget https://ocv.me/dot/.bashrc
echo '[[ -s $HOME/.bashrc ]] && . $HOME/.bashrc' > ~/.profile


########################################################################
########################################################################
##
##   I N S T A L L I N G   X F C E
##
########################################################################
########################################################################

# first,
# make sure you do not have "nomodeset" in your bootloader config,
# depending on bootloader (grub/extlinux) and config (bios/uefi) see:
#   /boot/extlinux.conf
#   /boot/EFI/boot/syslinux.cfg
#   TODO: grub bios
#   TODO: grub uefi
#
# you must reboot to have the removal of nomodeset take effect


# uncomment v3.10/community
vim /etc/apk/repositories


# this assumes you're on a laptop, otherwise see
# http://wiki.alpinelinux.org/wiki/XFCE_Setup
setup-xorg-base
apk add xfce4{,-terminal} lxdm xf86-input-{keyboard,mouse,synaptics} acpi


# pick and install a video driver that suits you
# (setup-xorg-base tries to do this but doesn't always succeed)
apk search xf86-video | sort
apk add xf86-video-intel


# alpine 3.9 ships with an unreleased version of Xfce for some reason;
# working dark themes: adwaita-dark (in package gnome-themes-standard)
# working bright themes: greybird, adwaita, raleigh
# faenza+awaita together form a working icon collection
# (choose greybird and the regular faenza icons in settings)
apk add greybird-themes faenza-icon-theme adwaita-icon-theme


# add services to autostart + start them now
rc-update add dbus
service dbus start
service lxdm start


# if you got a login screen,
# notice the dropdown boxes in the bottom left:
# to enable login, choose Desktop: Xfce Session
#
# after one successful login,
# you can have Xfce start automatically + enable autologin
# (replace 'ed' with your username):
cd /etc/lxdm
echo [base] >> lxdm.conf
echo autologin=ed >> lxdm.conf
rc-update add lxdm


# otoh, if starting Xfce failed, first try rebooting :)
#
# if still no dice, check the logs to see what went wrong
grep -E 'WW|EE' /var/log/Xorg.0.log

# you might get lucky by doing an
Xorg -configure
mv ~/xorg.conf.new /etc/X11/xorg.conf
service lxdm restart


# if you made it into the Xfce desktop however,
# you can stop reading any time.


########################################################################
########################################################################
##
##   T H E   E N D
##
########################################################################
########################################################################


# but here's some additional tweaks if you're interested
#
# it'll end up looking kinda like this:
# https://ocv.me/doc/alpine/res/xfce.png


# install nice-to-haves
apk add audacity chromium conky dbus feh feh-doc firefox-esr galculator geany geany-plugins gimp gtk-vnc gucharmap gvncviewer hexchat libxcb lxdm mousepad mumble setxkbmap terminus-font ttf-dejavu ttf-droid udev wine xclip xdotool xeyes xscreensaver xset sudo alsa-utils ntfs-3g mpv ffmpeg smartmontools e2fsprogs-extra


# install fonts:
# xfce gets buggy on window titles with runes you don't have fonts for
apk add unifont
# TODO: add better fonts


# adjust some xfce settings
echo <<XFCE_TWEAKS

  Applications >> Settings >> Settings Manager
     
  Mouse/Touchpad
  └─Touchpad
    ├─Tap touchpad to click
    └─Enable horizontal scrolling

  Keyboard
  ├─Layout
  │ └─Edit
  │   └─English (US)
  │     └─English (intl., with AltGr deadkeys)
  │
  ├─Behavior
  │ ├─Repeat delay: 300
  │ └─Repeat speed: 30
  │
  └─Application Shortcuts
	│
	├─Command: xfce4-terminal --maximize
	├─Hotkey:  ctrl-alt-T
	│
	├─Command: xfce4-screenshooter -f -m -s /home/yournick/Pictures/ss
	├─Hotkey:  printscreen
	│
	├─Command: xfce4-screenshooter -r -m -s /home/yournick/Pictures/ss
	├─Hotkey:  shift-printscreen
	│
	├─Command: xfce4-screenshooter -w -m -s /home/yournick/Pictures/ss
	└─Hotkey:  ctrl-printscreen

  Screensaver
  ├─Mode: Blank Screen Only
  └─Advanced
	├─Image manipulation
	│ └─Grab desktop images: No
	│
	└─Power Management Enabled
	  ├─Standby after: 10 minutes
	  ├─Suspend after: 12 minutes
	  ├─Off after:     13 minutes
	  └─Quick poweroff in blank-only mode: Yes

  Panel
  ├─Panel 2
  │ └─Just delete it with [X] top right
  │
  └─Panel 1
    ├─Display
    │ └─Lock panel: Off
    │   ...drag the panel down to the bottom of the screen...
    │   Lock panel: On
    │ 
    └─Items
      ├─Applications Menu           (properties button far right)
      │ ├─Show button title: No
      │ └─Icon
      │   ├─Select icon from: All icons
      │   └─Icon: application-x-ms-dos-executable  :)
      │
      ├─Window Buttons
      │ └─Show flat buttons: Yes
      │ 
      ├─Workspace Switcher
      │ └─Number of rows: 2
      │ └─Switch workspace with mouse wheel: No
      │ 
      ├─Notification Area
      │ └─Show Border: No
      │
      └─Add widget: Audio Mixer

  Window Manager Tweaks
  └─Compositor
    └─Enable display composition: No
      
      (a few machines get better performance
       with this enabled, try for yourself)
  
  Power manager
  ├─General
  │ ├─When laptop lid is closed
  │ │ ├─On battery: Suspend
  │ │ └─Plugged in: Lock screen
  │ │
  │ ├─Handle display brightness keys: On
  │ ├─Status notifications: On
  │ └─System tray icon: On
  │
  └─System
    ├─Critical battery power level: 20
    └─On critical battery power: Ask
  
  Session and Startup
  └─Application Autostart
    └─Add
      ├─Name: conky
      ├─Desc: status bar
      └─Cmd:  sudo /usr/bin/conky

XFCE_TWEAKS


# if you added conky above, open a root terminal and:
cd; wget https://ocv.me/dot/.conkyrc
echo 'yournick ALL=(ALL) NOPASSWD: /usr/bin/conky ""' >> /etc/sudoers
#
# that will grant xfce access to starting conky (without arguments)
# as root which is necessary to retrieve battery info
#
# if you have a small screen and left-aligned the taskbar
# edit /root/.conkyrc and adjust xftfont and minimum_size


# better terminal colors
sudo wget https://ocv.me/dot/xfce4-terminalrc -O /usr/share/xfce4/terminal/colorschemes/bifrost.theme

