The Ops Community

Joseph D. Marhee
Joseph D. Marhee

Posted on

Setting up an Alpine Linux Desktop Workstation

Setting up a desktop workstation using Alpine Linux for me typically just requires two components, if I'm on a laptop, a Wi-Fi connection, and a desktop environment (in this case XFCE). For the sake of simplicity, I have written some scripts that automate components from the Alpine Linux documentation.

You'll need two scripts, first wireless_net.sh, which will look like this:

#!/bin/bash

# Automates <https://wiki.alpinelinux.org/wiki/Connecting_to_a_wireless_access_point>

function pkgs() {
    apk --update add \
    wireless-tools \
    wpa_supplicant
}

function configIface() {
    if [ "$(ip link | awk '{print $2}' | grep wlan0 | wc -l)" = "1" ]; then \
        echo "OK"
    else
        echo "wlan0 not found"
        exit 1
    fi

    ip link set wlan0 up
}

function connectNetwork() {
    if [ ! ${SSID} ]; then
        read -p "WiFi Network SSID: " SSID
    fi
    if [ ! ${WIFI_PASS} ]; then
        read -sp "WiFI Pass: " WIFI_PASS
    fi

    wpa_passphrase "$SSID" "$WIFI_PASS" > /etc/wpa_supplicant/wpa_supplicant.conf
    wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf && \
    udhcpc -i wlan0 && \
    ip addr show wlan0

    if [ ! ${CONNECT_ON_BOOT} ]; then
        read -p "Connect to ${SSID} on boot? [y/n] " CONNECT_ON_BOOT
    fi

    if [ "$CONNECT_ON_BOOT" = "y" ]; 
        rc-update add wpa_supplicant boot ; \   
        rc-update add wpa_cli boot
    fi
}

pkgs && \
configIface && \
connectNetwork
Enter fullscreen mode Exit fullscreen mode

and desktop.sh, which looks like:

#!/bin/bash

# Automates <https://wiki.alpinelinux.org/wiki/XFCE_Setup>

function update_repos() {
    for r in $(grep community /etc/apk/repositories); do echo $(echo $r | sed -e 's|#||g') | tee -a /etc/apk/repositories; done && \
    apk update
}

function pkgs() {

    echo "Use xf86-video-modesetting for Qemu/KVM guests.
Tip: Probably for KVM/Qemu guests you want to use qxl Video and Display Spice. For this purpose install xf86-video-qxl on guest and run a Spice client on the host

Use xf86-video-vmware and xf86-video-vboxvideo for Virtualbox/VMware guests.
Tip: If you want to run XFCE in an Oracle VM Virtual Box, you need to install the VirtualBox guest additions as well. They contain parts of the driver, without them, XFCE won't start.

Use xf86-video-fbdev for Hyper-V guests.
Tip: If you use Hyper-V, you should install the Hyper-V guest services as well."

    if [ ! ${DRIVER} ]; then
        read -p "Which video driver? (i.e. intel, vmware) " DRIVER
    fi

    setup-xorg-base xfce4 xfce4-terminal lightdm-gtk-greeter xfce-polkit xfce4-screensaver consolekit2 dbus-x11 sudo && \

    if [ "$(apk search xf86-video-$DRIVER | wc -l)" = "0" ]; then
        echo "Invalid driver specified" ;
        exit 1
    else
        apk --update add xf86-video-$DRIVER
    fi

    apk add xf86-input-synaptics ; \
    apk add xf86-input-mouse xf86-input-keyboard kbd
}

function config_user(){
    if [ ! ${USER} ]; then
        read -p "Username: " USER
    fi

    if [ ! ${PASSWORD} ]; then
        read -sp "Password: " PASSWORD
    fi

    adduser --quiet --disabled-password --shell /bin/ash --home /home/$USER --gecos "User" $USER && \
    echo "$USER:$PASSWORD" | chpasswd && \
    echo "$USER   ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers
}

function svcs() {
    rc-service dbus start && \
    rc-update add dbus && \
    rc-service lightdm start && \
    rc-update add lightdm && \
    apk add faenza-icon-theme gvfs-fuse gvfs-smb
}

update_repos && \
pkgs && \
config_user && \
svcs
Enter fullscreen mode Exit fullscreen mode

To configure the wifi connection, run the script using the following arguments:

SSID="mynetwork" WIFI_PASS="p@$$w0rd" CONNECT_ON_BOOT="y" ./wireless_net.sh 
Enter fullscreen mode Exit fullscreen mode

which is just the network SSID, the password, and your connection preference for boot.

For the desktop, environment, it will also configure a non-root user, who will have passwordless-sudo capability:

USER="me" PASS="s3cr3t" DRIVER="modesetting" ./desktop.sh
Enter fullscreen mode Exit fullscreen mode

The modesetting value for DRIVER will need to match your system (i.e. vmware, intel, etc.) For virtualized envrionments, the script notes the following:

"Use xf86-video-modesetting for Qemu/KVM guests.
Tip: Probably for KVM/Qemu guests you want to use qxl Video and Display Spice. For this purpose install xf86-video-qxl on guest and run a Spice client on the host
Use xf86-video-vmware and xf86-video-vboxvideo for Virtualbox/VMware guests.
Tip: If you want to run XFCE in an Oracle VM Virtual Box, you need to install the VirtualBox guest additions as well. They contain parts of the driver, without them, XFCE won't start.
Use xf86-video-fbdev for Hyper-V guests.
Tip: If you use Hyper-V, you should install the Hyper-V guest services as well."

After rebooting, the system should come online with your XFCE environment loaded and your Wi-Fi connection active if set when you ran the driver, otherwise, run the script again when you wish to connect.

The scripts can be found here on Github:

Alpine Linux Workstation Setup

These scripts configure the basics for my Alpine Linux workstation.

Configure Wireless Network

The wireless_net.sh script configures a Wifi client.

Usage

This requires SSID, WIFI_PASS, and CONNECT_ON_BOOT, if not provided like so:

SSID="mynetwork" WIFI_PASS="p@$$w0rd" CONNECT_ON_BOOT="y" ./wireless_net.sh 
Enter fullscreen mode Exit fullscreen mode

otherwise, you'll be prompted as the script runs.

Configure XFCE Desktop

This script configures an administrative user, installs the desktop environment, and configures services for startup.

Usage

This requires USER, PASS, and DRIVER (for your chipset, i.e. intel, or vmware):

USER="me" PASS="s3cr3t" DRIVER="modesetting" ./desktop.sh
Enter fullscreen mode Exit fullscreen mode

If not provided, you will be prompted as the script runs.

Note for Virtualized Guests

Per the Alpine Linux documentation:

Use xf86-video-modesetting for Qemu/KVM guests Tip: Probably for KVM/Qemu guests you want to use qxl Video and Display

Discussion (0)