Search My Blog

Tuesday, June 1, 2010

Linux Tip: Using a Shell Script to Set Up Your Computer : IT News Today

Linux Tip: Using a Shell Script to Set Up Your Computer

1

Linux is full of some amazing tweaks that go far and beyond other operating systems. Last week I wrote about using scripts to simplify shell commands, and today I’m going to take that a step further, but it takes a little bit more leg work.

A while back, when I used to write for Linux.com, I wrote about writing scripts to configure your system after a fresh Linux install. The concept was difficult to explain, and editing restrictions kept me from going the direction I wanted to. Not only that, but that was a very long time ago and I think the idea is worth brining up again.

After installing Linux, the first thing anyone does is install all their favorite programs. There are so many, it can be hard to remember them all, and it can be a time consuming process. That’s the first part of this script, installing all your favorite stuff. After installation, keep a list of all the packages you install in a text file as you install them. If you already have a running Linux system, it is possible to export a list of installed packages. Here are examples for Arch and Ubuntu:

Arch:

pacman -Qq > packages.txt

Ubuntu:

dpkg –get-selections > packages.txt

With all of the packages listed that you want to install, you’re ready to make the first part of your script. Prefix the list of packages with your distributions install command, as well as the script header, and save it as “packages.sh”. Now we have a decent script. Here is what mine looks like in Ubuntu:

#!/bin/bash
# init
sudo apt-get install chromium neverball wesnoth wesnoth-ei wesnoth-httt wesnoth-music wesnoth-trow wesnoth-ttb wesnoth-utbs xgalaga bum totem-xine xine-ui fb-music-high frozen-bubble fceu libdvdcss2 w64codecs gstreamer0.10-ffmpeg gstreamer0.10-fluendo-mp3 gstreamer0.10-gnonlin gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly gstreamer0.10-sdl ia32-libs ia32-libs-sdl lib32ncurses5-dev vorbis-tools samba libavahi-compat-howl0 ia32-libs-gtk lib32asound2 gsfonts-x11 easytag build-essential kdf tk8.4 kdevelop alien-arena alien-arena-data blobwars nexuiz nexuiz-data nexuiz-music qt4-designer gstreamer0.10-plugins-ugly-multiverse kq pidgin thunderbird firefox unison unison-gtk sdlmame zenity juk audacious audacious-plugins gimp virtualbox-3.0 kdenlive digikam openssh-server ssh p7zip kfind playonlinux extremetuxracer unrar supertux

Please note that I’ve not actually used Ubuntu in a while, so the list of packages above may have changed and was presented for example purposes only. Regardless, you can now use that script to bulk install all of your favorite packages after installing Linux, without having to remember them all. You can launch the script as follows:

sh packages.sh

So with that script created, just install Linux, and run the script. You’ll have all of your favorite packages set up for you after running it. The fun doesn’t stop there, though. Any post-install command you normally execute can be added to. For example, if you install any third party repositories, you can add them to the script as well. Here is a command for adding the Medibuntu repository in Ubuntu:

sudo wget –output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get –quiet update && sudo apt-get –yes –quiet –allow-unauthenticated install medibuntu-keyring && sudo apt-get –quiet update

Here is another one I use, this one is for adding the Virtualbox repository in Ubuntu:

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

echo “deb http://download.virtualbox.org/virtualbox/debian lucid non-free” | sudo tee -a /etc/apt/sources.list

sudo apt-get install virtualbox-3.2

Now we’ve extended our script quite a bit further. Now, it installs all of your favorite packages, addes the Medibuntu repository, and then adds the Virtualbox repository and installs Virtualbox. Our theoretical script now looks like this:

#!/bin/bash
# init
sudo apt-get install chromium neverball wesnoth wesnoth-ei wesnoth-httt wesnoth-music wesnoth-trow wesnoth-ttb wesnoth-utbs xgalaga bum totem-xine xine-ui fb-music-high frozen-bubble fceu libdvdcss2 w64codecs gstreamer0.10-ffmpeg gstreamer0.10-fluendo-mp3 gstreamer0.10-gnonlin gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly gstreamer0.10-sdl ia32-libs ia32-libs-sdl lib32ncurses5-dev vorbis-tools samba libavahi-compat-howl0 ia32-libs-gtk lib32asound2 gsfonts-x11 easytag build-essential kdf tk8.4 kdevelop alien-arena alien-arena-data blobwars nexuiz nexuiz-data nexuiz-music qt4-designer gstreamer0.10-plugins-ugly-multiverse kq pidgin thunderbird firefox unison unison-gtk sdlmame zenity juk audacious audacious-plugins gimp virtualbox-3.0 kdenlive digikam openssh-server ssh p7zip kfind playonlinux extremetuxracer unrar supertux

sudo wget –output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get –quiet update && sudo apt-get –yes –quiet –allow-unauthenticated install medibuntu-keyring && sudo apt-get –quiet update

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

echo “deb http://download.virtualbox.org/virtualbox/debian lucid non-free” | sudo tee -a /etc/apt/sources.list

sudo apt-get install virtualbox-3.2

The idea here is to write down everything you do when you install Linux, so that way you can easily replicate all of your settings into your new install. That is why the script I written for this article is meaningless to you, since the packages and things you set up on your Linux install would be completely original. What to take from this is that setting up an install script can make it easier to set up your computers next time, or even painless to replicate the setup of one box to others.

You can set up your own script to do anything you want and you can take this as far as you like. You can do anything from copying over customized Xorg and Samba config files, to restoring your personal data files from a backup server to your home directory. Try it out!


Jeremy is a Certified IT Technician that blogs at ITNewsToday.com in his spare time. He has over ten years of industry experience, and studies the IT industry every single day. Jeremy has become an open source enthusiast over time and is studying for his Linux+ certification. He lives in Waterford MI with his wife Krystal and son Alan.

If you enjoyed this article, please consider buying him a pepsi.

Go there...
http://www.itnewstoday.com/?p=1354

This is a great article and almost... just what I have been looking for. Almost because... I'm building two Fedora Systems right now. I will be back at my Debian Systems soon though. I have been using FSlint to save a list of my installed Packages after I get a system built up the way I like it. It Takes me about two months of daily use to get there. I usually end up with... well this Fedora 11 system I using right now has 2421 packages in it. But it's just a temporary setup I installed to work on a broken Fedora 12 System on another HD in this Box. After I save my package list. I then open it up in Open Office's Calc App and delete the "file size" Column. Then I open the file in Open Office Writer and use the Finding and Replacing Paragraph Returns and Tabs features to get rid of all those Returns and Tabs, leaving only spaces. Up to now I have been just adding "yum -y install --skip-broken" to the beginning of my lists and then I copy and past them into the Terminal after I su as root. This works well, except some of the apps don't get installed that way and it takes up to 10 minutes for a all that text to past into the Terminal Window. The first time I did it. I thought it wasn't working. But I had learned this technique from the folks of the ArtistX Linux Distro. Their first offering had you install Debian etch and then use the Apps List on their Web Site to install all the Apps. They didn't mention the copy and past thing. I just tried it out, because I don't type very accurately and the list was long. It worked great on ArtistX, so I started doing it in my Fedora Systems. I periodically save an Apps list file with FSLint in case I have any problems with an install or later want to duplicate it. I want to get into Building Linux Systems for other people and really need to streamline my process. I've built one Fedora 11 Remix of my own with Kikstart and Revisor. But, like you said, you have to remember all of the many Apps that you want to install and put them into the Apps List in order to build the Distro you want to end up with. I can't Remember why I walked into the other Room... much less the Names of 2500 or so, Apps!:O AnyWay...;) back to your method... You didn't mention Fedora and I'm trying to figure out the Commands to save an Apps List text file on this Fedora System. I can't use FSlint right now, because something I did hosed the file permissions in my Home Dir or SELinux did it for me or maybe even a Shhhh... (don't tell) virus:O And I can't figure out what or where the problem is. My Apps can't access my home dirs and they hang up. At least some of them can't, unless I am able to change to / first and then navigate to my /home/don/ Documents folder, etc... So, I'm just going to re-install Fedora on this Partition. I Divided this HD into enough Partitions so that I can keep my files on a permanent Partition and then be able to Re-install my OS without loosing my Files. That's one thing I really like about Debian. The Install App gives you that option and makes it as painless as possible in the GUI Installation. I had to figure my own way to this in Fedora. I just divided the HD in two with one small Partition, well really Blank Space at the beginning and then Partitioned the rest as EXT3 for my files or Backup files in this case. Then I install Fedora in the Blank Space at the beginning using the default options. So, back to making an Apps List text file... I tried a few combination's like, "rpm –get-selections > packages.txt". But all I got was a blank text file. I do most everything with GUI Apps, since I can't type commands accurately, unless I can copy and paste them, that is... So, I know very few Linux commands. Just some basic ones. I searched around for the command to do this, but found nothing. Can anyone tell me the right command to make my Apps List the quick and easy way, like you do? Also I always install some more Repos, like... RPMFusion, free and nonfree and RPMForge. I have been trying to add them to my Kickstart file and couldn't figure out the syntax for that either. So I would like to add it to my Fedora Install Script. Can anyone give me the syntax for that too?

Thanks,

Don

3 comments:

Dileep Malayanur said...

Hi nice post for a command line assistance in getting around with linux. Check for more related linux articles @ Stark Solutions

Dileep Malayanur said...

Hi Don,
Thanks for considering my post about auto mounting partitions. In the 'Mount file system for internal drives' try the option as 'Admin Authentication (keep indefinitely)'. Please let me know if this does/doesn't help I have an alternate solution with fstab I will post it for you soon.

Don's Deals Blog said...

Thanks for the help. I found an article on how to auto mount an LVM using fstab. It has detailed instructions with commands to run in Terminal to make it work. I posted it on my Blog too. I set the Fedora 12 System I'm building that way, since I have 2 Fedora Systems Fedora 12 and Fedora 12 64bit, on 2 Separate Partitions on that Computer. Now I can use my Backups Apps in Automatic mode and backup to the other LVM's. The Fedora 11 System is now Fedora 13 and I'm just now getting my Apps set up on it. I will need to Auto mount my ext3 File System on my Backup Drive when I get to it. I can't find our original posts on your Blog. There's no search on it... So, I'm replying here on my Blog in hopes that you will come back sometime. I'll try looking again later for your instructions, when I get back to setting up my ext3 Backup Drive.

Thanks,

Don