Fresh Starts

I have a tendency to play around with my system, which has been both very good and very bad for me. On one hand, I have learned so much from tinkering and inspecting files and breaking things, that I probably would not have otherwise learned. On the other hand, I do occasionally break the system beyond repair, which requires a fresh start and a couple hours of time to run the installation and follow up with re-setting all of my configurations. Since I tend to do this quite a bit, I figured it would be a good idea to just go ahead and automate this process. I have a small set of programs that I always need, and a small set of configuration files to go with them. By automating the installation and configuration of them, I give myself a lot more free time since I don’t have to manage these processes myself. Not to mention, this puts me in a good spot for upgrade time, which is about every 3 years for Debian. Each time a new release comes out, my post-installation setup will only take me about 5 minutes of actual attention required.

I’ve split the scripts into two different ones: one is to download the various programs that I want, and the other is to back up my configuration files and store them elsewhere. First, here’s the installation script:

[code lang=”bash”]#!/bin/bash

# Set paths for various commands needed in script

# Fix the sources for apt-get
echo <<EOF > /etc/apt/sources.list

# deb cdrom:[Debian GNU/Linux 8.4.0 _Jessie_ – Official amd64 xfce-CD Binary-1 20160402-14:44]/ jessie main

#deb cdrom:[Debian GNU/Linux 8.4.0 _Jessie_ – Official amd64 xfce-CD Binary-1 20160402-14:44]/ jessie main

deb jessie main non-free contrib
deb-src jessie main non-free contrib

deb jessie/updates main
deb-src jessie/updates main

# jessie-updates, previously known as ‘volatile’
deb jessie-updates main
deb-src jessie-updates main

# Grab some tools needed for Docker install
$APTGET update
$APTGET install -y apt-transport-https ca-certificates curl

cd $HOME/Downloads

# Install Dropbox

# Install Google Chrome

# Install Skype
$DPKG –add-architecture i386

# Install Atom Editor

# Install Slack

# Install Moka Icon theme

# Install Telegram
$WGET && $TAR -xvf tsetup.0.9.49.tar.xz -C /opt/ && $LN -s /opt/Telegram/Telegram /usr/bin/Telegram
$RM tsetup.0.9.49.tar.xz

# Install PHPStorm
cd $HOME
$WGET && $TAR -xvf PhpStorm-2016.1.1.tar.gz -C $HOME/
$RM PhpStorm-2016.1.1.tar.gz

# Add Spotify to source list
$APTKEY adv –keyserver hkp:// –recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886
echo deb stable non-free | $TEE /etc/apt/sources.list.d/spotify.list

# Set up Docker Install
$APTKEY adv –keyserver hkp:// –recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb debian-jessie main" > /etc/apt/sources.list.d/docker.list
$GROUPADD docker
$USERMOD -aG docker,sudo billy

# Install all of the deb packages
$DPKG -i $HOME/Downloads/*.deb

# Update sources and install other software not already installed along with dependencies for the deb packages
$APTGET update
$APTGET -f install -y vim tmux spotify-client git openvpn zsh docker-engine

# Install Docker Compose
$CURL -L`$UNAME -s`-`$UNAME -m` > /usr/local/bin/docker-compose
$CHMOD +x /usr/local/bin/docker-compose

# Clean up
$RM $HOME/Downloads/*.deb[/code]

For obvious reasons, this script must be run as root or with sudo. This grabs all the basic software I need in addition to the base install to get me up and running for work and play. Next up, for the configuration backup script:

[code lang=”bash”]#!/bin/bash


# Move to the home dir
cd /home/billy

# Create the tar archive of the config files
echo "Creating tar archive…"
$TAR -cjf home.tar.bz2 \
.atom \
.bashrc \
.config/Atom \
.config/Skype \
.config/Slack \
.config/spotify \
.gitconfig \
.PhpStorm2016.1 \
.purple \
.Skype \
.ssh \
telegram.desktop \
.TelegramDesktop \
.themes/White \
.vim* \
.zshrc \

if [ $? -eq 0 ]; then
echo "OK"
echo "FAILED: $?"

# Upload archive to server
echo "Uploading archive to remote server…"
$SCP home.tar.bz2
echo "Backup complete"

This is a tad bit shorter, but it basically grabs all the configuration files that I wouldn’t want to lose, stores them in a bzipped2 tar archive, and then uploads them to a remote server. When I need to restore them, I simply pull down the tar file and decompress it in my home directory, automatically setting most of my configuration settings. This is not an exhaustive list by any means, and I still need to take some time to find some other configuration files without bloat, such as for Google Chrome for example. This also doesn’t grab my configuration for cinnamon, my DE of choice, nor any custom key bindings. I still have a little more to do to perfect it, but this gets about 90% of it for me, so that’s good enough for now. I’d also like to modify it a bit to not only manage the backups, but also the restoration.

So, these are my scripts! Got anything better? Any ideas on how I can improve these? Please share, either in the comments or via email. I love feedback and contructive criticism.