Elementary OS 0.4 Loki desktop customization – automated

Elementary OS - Featured Image

This guide is a continuation on Elementary OS initial customization tutorial where I explained what I consider are tasks to be made after you installed a minimal Elementary OS on your computer or a virtual machine. I strongly advise to check out that guide as this one is just a brief overview of the actions performed assembled into a bash script which will automate all the work described in mentioned guide.

Prerequisites

Before you start with Elementary OS automated customization, I strongly advise you check out my guide about preseeding .

A minimal installation of Elementary OS 0.4 Loki is required to successfully complete this guide. You can set it up by following Elementary OS 0.4 Loki desktop installation guide on this website. A virtual machine image in VMDK format is also available for download here. If you decide to download and use an image, please read the guidelines on download page to set it up right. With minimal installation of Elementary OS in place, all you need to do is download automate script here. To download the script you will need to install wget to get it directly to your machine. Wget is also needed for some tasks performed by the script itself so execute the following to install it:

sudo apt-get update
sudo apt-get install --no-install-recommends wget

With wget in place, execute the following in your Terminal:

cd
wget http://www.zacks.eu/wp-content/uploads/files/eos_loki/eos_autoinstall.tar.gz
tar xzvf eos_autoinstall.tar.gz

A script is now present in your home folder, so all you need to do now is to execute it:

sudo ./eos_autoinstall.sh

Elementary OS automate script – Overview

Now that you have your bare metal machine ready and script in place, all you need to do is run the script and wait for it to finish. You can open the script in a text editor and see what tasks it will perform or you can read the explanations here. Script is divided in couple of blocks each performing specific tasks and as such I’ll try and explain it here. First block will handle environment a bit and set up software update catalog:

## Variables
echo -n "Please enter your username (user you log in with): "
read USER_NAME

## Modify fstab
DISK_ID=$(lsblk -io NAME,TYPE,MOUNTPOINT | grep -v "[SWAP]" | grep disk | awk '{print $1;}')
DISK_TYPE=$(cat /sys/block/"$DISK_ID"/queue/rotational)
if [ "$DISK_TYPE" = "1" ];
then
echo "Modifying fstab for rotational disk"
sed -i 's/errors=remount-ro/errors=remount-ro,noatime/g' /etc/fstab
sed -i 's/defaults/defaults,noatime/g' /etc/fstab
else
echo "Modifying fstab for SSD disk"
sed -i 's/errors=remount-ro/errors=remount-ro,noatime,discard/g' /etc/fstab
sed -i 's/defaults/defaults,noatime,discard/g' /etc/fstab
fi

## Update grub, environment and debconf
sed -i 's/GRUB_HIDDEN_TIMEOUT=0/# GRUB_HIDDEN_TIMEOUT=0/;s/^GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/GRUB_CMDLINE_LINUX_DEFAULT=""/;s/^#GRUB_DISABLE_RECOVERY="true"/GRUB_DISABLE_RECOVERY="true"/' /etc/default/grub
sed -i 's/^#FSCKFIX=no/FSCKFIX=yes/g' /etc/default/rcS
update-grub
update-locale LC_MESSAGES=POSIX
update-locale LC_LANGUAGE=en_US.UTF-8
export LC_MESSAGES=POSIX
export LC_LANGUAGE=en_US.UTF-8
echo -e "debconf debconf/frontend select Noninteractive\ndebconf debconf/priority select critical" | debconf-set-selections

## Set up debconf display and basic software repositories
rm /etc/alternatives/newt-palette
ln -s /etc/newt/palette.original /etc/alternatives/newt-palette
echo -n > /etc/apt/sources.list
echo -e "deb http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ xenial-backports main universe multiverse restricted
deb http://archive.canonical.com/ubuntu xenial partner" > /etc/apt/sources.list

## Update catalog and setup aptitude
apt-get update
apt-get install --no-install-recommends -y aptitude
aptitude update -q2

## Set aptitude configuration
if [ -f /home/"$USER_NAME"/.aptitude/config ];
then
echo "Aptitude configuration file is present"
else
mkdir /home/"$USER_NAME"/.aptitude
touch /home/"$USER_NAME"/.aptitude/config
chown -R "$USER_NAME". /home/"$USER_NAME"/.aptitude
fi
cat <<EOF > /home/"$USER_NAME"/.aptitude/config
aptitude "";
aptitude::Delete-Unused-Pattern "";
aptitude::UI "";
aptitude::UI::Advance-On-Action "true";
EOF

## Download, extract and initialize initial upgrade preseed packages
LOCALEPURGE_NOPURGE=$(locale | grep "LANG=" | rev | cut -d"=" -f1 | rev)
wget http://www.zacks.eu/wp-content/uploads/files/eos_loki/eos_software.preseed.tar.gz
tar xzvf eos_software.preseed.tar.gz
sed -i "/nopurge/ s/$/ $LOCALEPURGE_NOPURGE/" eos_software.preseed
cat eos_software.preseed | debconf-set-selections

Second block will handle initial system upgrade, old kernel and headers removal, set additional repos and install some system utilities:

## Initial system upgrade and old kernel/headers removal
aptitude forget-new
aptitude full-upgrade --purge -y | tee -a "upgrade.log"
dpkg -l | grep linux-image-extra-4 | tr -s " " | cut -d" " -f2 | sort -r | tail -n +2 | xargs aptitude purge -y | tee -a "upgrade.log"
dpkg -l | grep linux-image-4 | tr -s " " | cut -d" " -f2 | sort -r | tail -n +2 | xargs aptitude purge -y | tee -a "upgrade.log"
dpkg -l | grep linux-headers-4 | tr -s " " | cut -d" " -f2 | sort -r | tail -n +3 | tr "\n" " " | xargs aptitude purge -y | tee -a "upgrade.log"
aptitude install -y linux-image-generic-hwe-16.04 linux-headers-generic-hwe-16.04
aptitude clean
update-grub

## Reinstall DKMS dependet packages
SEARCH_REINSTALL_DKMS=$(grep "Module:" upgrade.log | awk '{print $2;}')
REINSTALL_DKMS=$(dpkg -l | grep "$SEARCH_REINSTALL_DKMS" | awk '{print $2}')
aptitude reinstall "$REINSTALL_DKMS"

## Install memtest86+ and build-essentials
aptitude install -R -y memtest86+ build-essential

## Set additional repos and install utilities
curl -s https://s3.amazonaws.com/download.draios.com/DRAIOS-GPG-KEY.public | apt-key add -
curl -s -o /etc/apt/sources.list.d/draios.list http://download.draios.com/stable/deb/draios.list
wget -q https://dl.google.com/linux/linux_signing_key.pub -O- | apt-key add -
echo -e "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
echo -e "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/oracle-java.list
aptitude update
aptitude install -R -y openssh-server safecat sharutils lynx zip unzip lrzip pbzip2 p7zip p7zip-full rar pigz unrar \
acpid inotify-tools sysfsutils dstat htop lsscsi iotop itop nmap ifstat iftop tcptrack whois atop mcelog zram-config sysstat \
gpm localepurge mc screen vim smartmontools lm-sensors ethtool apt-file sysdig

## Utilities post-install steps
apt-file update
sed -i 's/^#startup_message/startup_message/g' /etc/screenrc

Third block in this script will remove unwanted software, reinstall some Elementary OS standard software and install a regular software we will use in our day to day operations:

## Remove unwanted software
aptitude purge -y noise audience libtimezonemap1 sbsigntool apparmor brltty ufw ed nano gnome-orca onboard onboard-data apport \
whoopsie toshset epiphany-browser epiphany-browser-data pantheon-mail pantheon-online-accounts-plugin-fastmail pantheon-online-accounts-plugin-mail \
appcenter apport-gtk elementary-standard switchboard-plug-gcc-color switchboard-plug-gcc-sound switchboard-plug-gcc-wacom unity-control-center \
gir1.2-webkit2-4.0 language-pack-bg language-pack-ca language-pack-cs language-pack-da language-pack-hu language-pack-id language-pack-ja \
language-pack-ko language-pack-nb language-pack-nl language-pack-pl language-pack-sv language-pack-th language-pack-tr language-pack-uk \
language-pack-vi language-pack-zh-hant language-pack-gnome-bg language-pack-gnome-ca language-pack-gnome-cs language-pack-gnome-da \
language-pack-gnome-hu language-pack-gnome-id language-pack-gnome-ja language-pack-gnome-ko language-pack-gnome-nb language-pack-gnome-nl \
language-pack-gnome-pl language-pack-gnome-sv language-pack-gnome-th language-pack-gnome-tr language-pack-gnome-uk language-pack-gnome-vi \
language-pack-gnome-zh-hant language-pack-gnome-bg-base language-pack-gnome-ca-base language-pack-gnome-cs-base language-pack-gnome-da-base \
language-pack-gnome-hu-base language-pack-gnome-id-base language-pack-gnome-ja-base language-pack-gnome-ko-base language-pack-gnome-nb-base \
language-pack-gnome-nl-base language-pack-gnome-pl-base language-pack-gnome-sv-base language-pack-gnome-th-base language-pack-gnome-tr-base \
language-pack-gnome-uk-base language-pack-gnome-vi-base language-pack-gnome-zh-hant-base gir1.2-json-1.0 gir1.2-soup-2.4 language-pack-bg-base \
language-pack-ca-base language-pack-cs-base language-pack-da-base language-pack-hu-base language-pack-id-base language-pack-ja-base language-pack-ko-base \
language-pack-nb-base language-pack-nl-base language-pack-pl-base language-pack-sv-base language-pack-th-base language-pack-tr-base language-pack-uk-base \
language-pack-vi-base language-pack-zh-hant-base libatkmm-1.6-1v5 libcairomm-1.0-1v5 libglibmm-2.4-1v5 libido3-0.1-0 libmircommon5 libpangomm-1.4-1v5

## Reinstall Elementary OS standard meta-package
aptitude install -y -R btrfs-tools busybox-static cryptsetup-bin dmeventd dmsetup dnsutils elementary-os-overlay friendly-recovery ftp \
hdparm info iputils-tracepath irqbalance jfsutils lshw lsof ltrace lvm2 mlocate mtr-tiny powermgmt-base rsync strace tcpdump telnet time \
ubuntu-release-upgrader-core update-manager-core

## Install regular software
aptitude install -R -y filezilla firefox google-chrome-stable oracle-java8-installer oracle-java8-set-default skype thunderbird transmission \
libreoffice-calc libreoffice-impress libreoffice-writer brasero clementine gmtp browser-plugin-vlc dconf-editor gdebi gparted flashplugin-installer \
ttf-mscorefonts-installer gstreamer0.10-nice gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer1.0-fluendo-mp3 gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-base:i386 ubuntu-restricted-extras libav-tools xine-plugin

## Display hidden auto-start entries
sed -i 's/NoDisplay=true/NoDisplay=false/g' /etc/xdg/autostart/*.desktop

Final script block will finish all tasks, perform a cleanup and inform you that your system is ready for usage and reboot your computer to apply all settings:

## Clean up
aptitude clean
rm eos_autoinstall.tar.gz
rm eos_software.preseed.tar.gz
rm eos_software.preseed
rm upgrade.log

## Adjust profile history settings
sed -i 's/^HISTSIZE=1000/HISTSIZE=5000/g' /home/"$USER_NAME"/.bashrc
sed -i 's/^HISTFILESIZE=2000/HISTFILESIZE=10000/g' /home/"$USER_NAME"/.bashrc
sed -i '/^HISTFILESIZE=10000/a \HISTTIMEFORMAT="%d/%m/%y %T "' /home/"$USER_NAME"/.bashrc
chown "$USER_NAME". /home/"$USER_NAME"/.bashrc

## Set debconf to full details for future installations
echo -e "debconf debconf/frontend select Dialog\ndebconf debconf/priority select low" | debconf-set-selections

## Reboot
echo "Installation is now finished, your machine will reboot to apply new settings. Please remove this script after reboot is complete. !!!DO NOT RUN IT AGAIN!!!"
sleep 10
shutdown -r now

So there you have it. Instead of wasting certain amount of time, with a script like this, everything is done in a few minutes. Enjoy your Elementary OS and thank you for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *