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:
#!/bin/bash # Set paths for various commands needed in script APTGET=/usr/bin/apt-get APTKEY=/usr/bin/apt-key CHMOD=/bin/chmod CURL=/usr/bin/curl DPKG=/usr/bin/dpkg GROUPADD=/usr/sbin/groupadd HOME=/home/billy LN=/bin/ln PHP=/usr/bin/php RM=/bin/rm TAR=/bin/tar TEE=/usr/bin/tee UNAME=/bin/uname USERMOD=/usr/sbin/usermod WGET=/usr/bin/wget # 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 http://ftp.mx.debian.org/debian/ jessie main non-free contrib deb-src http://ftp.mx.debian.org/debian/ jessie main non-free contrib deb http://security.debian.org/ jessie/updates main deb-src http://security.debian.org/ jessie/updates main # jessie-updates, previously known as 'volatile' deb http://ftp.mx.debian.org/debian/ jessie-updates main deb-src http://ftp.mx.debian.org/debian/ jessie-updates main EOF # Grab some tools needed for Docker install $APTGET update $APTGET install -y apt-transport-https ca-certificates curl cd $HOME/Downloads # Install Dropbox $WGET https://www.dropbox.com/download?dl=packages/debian/dropbox_2015.10.28_amd64.deb # Install Google Chrome $WGET https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb # Install Skype $DPKG --add-architecture i386 $WGET https://download.skype.com/linux/skype-debian_18.104.22.168-1_i386.deb # Install Atom Editor $WGET https://atom-installer.github.com/v1.7.3/atom-amd64.deb?s=1461858699 # Install Slack $WGET https://downloads.slack-edge.com/linux_releases/slack-desktop-2.0.6-amd64.deb # Install Moka Icon theme $WGET https://bitbucket.org/2ion/moka-icon-theme/downloads/moka-icon-theme_201409-1-2_amd64.deb # Install Telegram $WGET https://updates.tdesktop.com/tlinux/tsetup.0.9.49.tar.xz && $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 https://d1opms6zj7jotq.cloudfront.net/webide/PhpStorm-2016.1.1.tar.gz && $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://keyserver.ubuntu.com:80 --recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886 echo deb http://repository.spotify.com stable non-free | $TEE /etc/apt/sources.list.d/spotify.list # Set up Docker Install $APTKEY adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo 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 https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`$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:
#!/bin/bash SCP=/usr/bin/scp TAR=/bin/tar # 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 \ /etc/openvpn/dh1.c117.sonassihosting.com* if [ $? -eq 0 ]; then echo "OK" else echo "FAILED: $?" exit(1) fi # Upload archive to server echo "Uploading archive to remote server..." $SCP home.tar.bz2 firstname.lastname@example.org: 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.