Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
160 lines (143 sloc) 5.71 KB
#!/bin/bash
#
# Dedicated Hamster time tracker machine
# --------------------------------------
# Version: 0.2 (2016/10/04)
# Description: Installs Arch from a live ISO and configures Hamster in a lightweight
# environment to autostart at boot.
# Tested on VirtualBox 5.1.6 within a Arch Linux 4.7.2 virtual guest.
# Requires 256MB memory and precisely 8GB disk (due to automatic
# partitioning) and a network that gives out IPv4 DHCP leases with WAN
# connectivity.
# Author(s): Ricky Burgin
# License: MIT License
### CONFIGURABLE SECTION ###
DISK="sda"
NAMESERVER="8.8.8.8"
DEF_KEYMAP="gb" # 'us' for the Americans
DEF_LANG="en_GB.UTF-8" # en_US.UTF-8 for Americans
TZ="GB" # Can also use 'CET', 'EST', 'GMT', 'UTC'. See /usr/share/zoneinfo for more options
NEWHOSTNAME="hamster.local"
### END ###
echo "Setting resolver..."
# Shouldn't be necessary, but experienced an instance where networking was brought up but nameservers were not received via DHCP and written to resolv.conf
# Should not matter post-installation as hamster does not require networking
echo "nameserver ${NAMESERVER}" > /etc/resolv.conf
timedatectl set-ntp true
# sda1 is /boot, sda2 is swapspace, sda3 is /
PARTITIONING=$(cat <<EOF
label: dos
label-id: 0xd471aed7
device: /dev/$DISK
unit: sectors
/dev/${DISK}1 : start= 2048, size= 409600, type=83
/dev/${DISK}2 : start= 411648, size= 1048576, type=83
/dev/${DISK}3 : start= 1460224, size= 15316992, type=83
EOF
)
echo "Partitioning disks..."
echo "${PARTITIONING}" > /tmp/disk.layout
sfdisk /dev/${DISK} < /tmp/disk.layout
mkfs.ext4 /dev/${DISK}1
mkswap /dev/${DISK}2
mkfs.ext4 /dev/${DISK}3
swapon /dev/${DISK}2
mount /dev/${DISK}3 /mnt
mkdir /mnt/boot
mount /dev/${DISK}1 /mnt/boot
echo "Bootstrapping root partition..."
pacstrap /mnt base
cp /etc/resolv.conf /mnt/etc/resolv.conf
genfstab -U /mnt >> /mnt/etc/fstab
NETCONF=$(cat <<EOF
[Match]
Name=en*
[Network]
DHCP=ipv4
EOF
)
BASHPROFILE=$(cat <<EOF
if [ -z "$DISPLAY" ] && [ "$(fgconsole)" -eq 1 ]; then
exec startx
fi
EOF
)
XINITRC="exec openbox-session"
AUTOSTART="setxkbmap ${DEF_KEYMAP} &\nxset -dpms s off\nxset s off\nhamster &\n/usr/bin/VBoxClient-all &"
AUTOLOGIN=$(cat <<EOF
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
After=systemd-user-sessions.service plymouth-quit-wait.service
# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes
# IgnoreOnIsolate causes issues with sulogin, if someone isolates
# rescue.target or starts rescue.service from multi-user.target or
# graphical.target.
Conflicts=rescue.service
Before=rescue.service
# On systems without virtual consoles, don't start any getty. Note
# that serial gettys are covered by serial-getty@.service, not this
# unit.
ConditionPathExists=/dev/tty0
[Service]
# the VT is cleared by TTYVTDisallocate
ExecStart=-/sbin/agetty --autologin hamster --noclear %I $TERM
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes
# Unset locale for the console getty since the console has problems
# displaying some internationalized messages.
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
[Install]
WantedBy=getty.target
DefaultInstance=tty1
EOF
)
echo "Adding hamster user..."
arch-chroot /mnt /bin/bash -c "useradd -m hamster; mkdir -p /home/hamster/.config/openbox"
echo "Configuring autologin, keyboard map, window manager start script and netconfig..."
echo "${AUTOLOGIN}" > "/mnt/etc/systemd/system/getty.target.wants/getty\@tty1.service"
echo "${XINITRC}" > /mnt/home/hamster/.xinitrc
echo -e "${AUTOSTART}" > /mnt/home/hamster/.config/openbox/autostart
echo "${NETCONF}" > /mnt/etc/systemd/network/default.network
echo "${BASHPROFILE}" >> /mnt/home/hamster/.bash_profile
arch-chroot /mnt /bin/bash -c "chown -R hamster:hamster /home/hamster"
echo "Setting timezone..."
arch-chroot /mnt /bin/bash -c "ln -s /usr/share/zoneinfo/${TZ} /etc/localtime; hwclock --systohc"
echo "Setting locale..."
arch-chroot /mnt /bin/bash -c "echo LANG=${DEF_LANG} > /etc/locale.conf"
echo "Setting hostname..."
arch-chroot /mnt /bin/bash -c "echo \"${NEWHOSTNAME}\" > /etc/hostname"
echo "Enabling network service and installing additional required packages..."
read -p "Just hit enter when asked to enter a selection, then when asked to enter a number select '1' for libx264 and '2' for virtualbox-guest-modules-arch. Hit enter to continue..."
# This could use improvement to make it totally non-interactive
arch-chroot /mnt /bin/bash -c "pacman -Syy; pacman -S arandr gnome xorg xorg-xinit virtualbox-guest-utils xterm openbox hamster-time-tracker xf86-video-intel mesa-libgl xorg-server xorg-utils xorg-server-utils grub wget vim obconf"
echo "Enabling services..."
arch-chroot /mnt /bin/bash -c "systemctl enable systemd-networkd.service; systemctl enable vboxservice.service"
echo "Installing bootloader..."
arch-chroot /mnt /bin/bash -c "grub-install /dev/${DISK}; grub-mkconfig -o /boot/grub/grub.cfg"
read -p "Done. Hit enter to reboot"
cd
sync
umount /mnt/boot
umount /mnt
reboot