Conditional command IF ELSE

Here is a little different example. This script does one of two commands based on the presence of an argument. It displays a sorted list of installed packages using dpkg (for systems that use that particular type of package management). If an argument is passed, it will only include packages that contain that search argument. Otherwise it will include them all.

#!/bin/bash
criteria=”$1″
# If criteria is not specified, show all
if [[ $criteria = “” ]]; then
dpkg –get-selections | grep -v deinstall | sort | less
else
dpkg –get-selections | grep -v deinstall | grep -i “$criteria” | sort | less
fi

Setting a default if an argument isn’t passed

In doing some bash scripting… I use some simple scripts to automate commands so I don’t have to type in (or remember) all the parameters. This script uses the du command to show me the disk usage on directories. The depth parameter specifies how deep in the path to go when reporting. I wanted the script to function correctly without an argument. So my solution was to test for the argument and use a default value if it’s not present. Without a default value, this command would produce an error.

#!/bin/bash
depth=”$1″
# If depth is not specified, default to zero
if [[ $depth = “” ]]; then
depth=”0″
fi
du -mc -d$depth –apparent-size * | sort -nr | less

Backup script using rsync

Here’s a cute little backup script I wrote. Just a little smarts to suit my particular situation. But I did learn how to prompt for a parameter and do a case statement. The rsync command is a very powerful backup tool. On this particular backup drive (Lacie) I have two sets of backups… (/backup1/ and /backup2/). This script prompts me for which one I want to use and does the right thing. I’m also using an exclude list in the form of a txt file to omit browser caches and the like.

#!/bin/bash
read -p “Backup number (1/2)?” choice
case “$choice” in
1 ) echo “1”;;
2 ) echo “2”;;
* ) echo “Failure to communicate, try again.”;exit 1;;
esac
path=”/home/”
pathfrom=”$path.”
pathto=”/media/Lacie/backup$choice$path.”
rsync -avAX –delete –exclude-from ‘/usr/local/bin/backup-exclude.txt’ “$pathfrom” “$pathto”

Thank you psychocats

After installing Ubuntu and completely removing Unity in favor of the standard Gnome3 desktop, I found Gnome to be not so much to my liking. But there is a great resource available to those who have installed one of the flavors of Ubuntu (Ubuntu, Lubuntu, Xubuntu, Kubuntu). With one big honkin’ command, you can switch from one of those flavors to the other. And this site provides the necessary stuff.

So… not liking Gnome3 that much? Just issue this one big command string and walla! You’re now running Xubuntu! Yes, that is exactly what I did. Worked peachy. And it was almost entirely painless. It’s really just a matter of removing some packages and installing others. All the underlying configuration stays put. All I really had to do is setup the Xfce panels the way I wanted them.

See the big problem I’m having is that there are just far too many choices in the Linux world… and they’re all FREE. So there is no limit to the things one can try. It only costs time. Could be it’s time to just leave things alone for awhile and use my time for something else.

Now that I’m back on Ubuntu I’m starting to read all these things about Canonical trying to force their own display server (Mir) on the rest of the Linux community. The problem is, because Canonical produces the most popular Linux distribution (Ubuntu), they probably have more leverage than they should on the direction of Linux as a whole. The Linux community is already fragmented enough without this kind of bullying.

But it makes me want to stay far away from Ubuntu and it’s derivatives (now that I have just installed one). Gah! I just can’t win. Although I have no compelling reason to make a hasty decision (and spend more time distro-hopping). I’m sure what I have installed will work well for me for several years, if I want it to. And it will be officially supported until April 2015.

Choke!

One funny thing happened yesterday evening. Typically when I switch distros, I keep my desktop and laptop machines in sync and switch them both. That has proven to be valuable. As I was configuring my laptop last night… I was changing ownership of the /var/www directory and I messed up big time and changed the permissions recursively of everything in /var. Holy cow!

Of course that’s a big deal because many of the critical running processes keep track of their status using /var and they sort of need the right permissions to access their control stuff. Took me a few hours to straighten that out. And having two identical installations allowed me to compare the broken one with the non-broken one and correct the ownership.

Next thing to try…

So, I got a brain-storm in the middle of the night (night before last).

First… Ubuntu being the most popular distro, there are advantages to running it in spite of the fact that the Linux geeks who think they are all that look down on it. I don’t mind getting my hands dirty to get things working in Linux and I can pretty much solve whatever problems come up. But at the end of the day, the quicker the path is to looking good and functioning well, the better life is.

There is also an advantage to running the LTS (long-term support) versions of Ubuntu. LTS versions are released every 2 years and officially supported for 5 years. Their other versions which are released every 6 months are only supported for 9 months. I was going to switch to the LTS version awhile back, but the installer for the last LTS release (12.04) does not support LVM (which I was using). So it wasn’t going to work.

However, night before last I was able to get my native Linux backup solution working. With an external hard drive formatted ext4 and some rsync goodness, I had three copies of all my files. The time was ripe… so I re-partitioned my drives getting rid of LVM. Now I was able to install 12.04 (and proceeded to do so).

I also looked into removing the Unity junk from Ubuntu. It turns out that it’s not that hard to remove Unity and go with the standard Gnome3 desktop. So that’s exactly what I did, and it’s all working great. FYI, most of the main Linux distributions (like Fedora and Debian) default to the Gnome desktop. And most the apps I use are Gnome or GTK-based.

So in theory… I should not need to make another change until April of 2014 when the next LTS version of Ubuntu is scheduled to ship. Unless of course I find another excuse.  🙂

One big advantage to running a mainstream Linux distribution… there is tons of support on the net. Pretty much any technical question I come up with can be answered with a quick web search. That rocks!

Attitude

Well, after hanging out in the Debian IRC channels for a few days, I grew rather tired of the major attitude I was observing. Ok… Debian has been around a long time and it’s not as easy to run as say Ubuntu. But that doesn’t mean you have the right to be rude to people that run something else.

They referred to Ubuntu as “linux with training wheels”. Ok, whatever. Yes, I had Debian on both my machines and it was running fine. But the Debian folks are way too principled for their own good. They deliberately omit a lot of extremely useful and necessary software and drivers from their distribution because it doesn’t fit their particular strict definition of “free” and non-proprietary. This causes much unnecessary inconvenience.

Personally, I’m not running Linux because I want to be a communist. I could not care less about those sorts of principles that are put higher in priority above the need for things to actually function.

So I decided, screw the attitude. I’m going back to Lubuntu. Ok, maybe it has training wheels, but it looks a HELL of a lot better than Debian does. I could have tweaked Debian for six months to get it to look as good as Lubuntu does on DAY ONE.

This whole idea that you are somehow cooler and more elite because you run something that takes more work and knowledge to run is a bit of a fallacy. You may be cooler, but I HAVE A LOT MORE FREE TIME! LOL. AND MY SYSTEM JUST WORKS! So who is smarter?

Ok. Thanks for letting me get that off my chest. I love Linux. And I run it because it’s fun. Not for bragging rights. I run a distro that is pretty easy to set up. That’s ok. Instead of taking months to get everything right, I have two systems up and running perfectly with all my software in less than 24 hours.

Here we go again

So, after installing CrunchBang… I started hanging out in the Debian chat channels. I figured that CrunchBang was based directly on Debian… so for all practical purposes, any advice or support for Debian would also pertain to CrunchBang.

But, when I mentioned CrunchBang in the #debian channel, I was told in no uncertain terms that CrunchBang != Debian. And they refused to even talk to me (in spite of the fact that I wasn’t actually seeking support).

So… that evening I wiped my two systems and installed Debian proper. They won’t support something “based” on Debian, so I’ll just run Debian itself and then I can avail myself of the community support.

After installing Debian, I was surprised to discover that the default Debian desktop environment is Gnome. I was totally expecting something more light-weight. A bit disappointing. Then I thought, hey… why can’t I just install a few additional desktop environments along side Gnome and play around? The oh-so-kind folks in the #debian channel assured me that would be a piece of cake.

And piece of cake it was. Up until the point where I checked out the available programs in the Gnome GUI and saw four different file managers, several image viewers, and duplicates of just about every type of program and utility that came pre-installed. You see, each desktop environment normally gets paired with different programs to fulfill particular functions. So I essentially ended up with three or four programs in each category that did essentially the same thing. Bogus!

I proceeded to wipe both systems (yet again). I reinstalled Debian on both, but this time I decided to stick to only one desktop environment. I chose Xfce for my desktop machine and LXDE for my laptop.

So they’re both installed and running perfectly. But holy cow, this is getting old. After all this screwing around I am actually considering going back to Ubuntu or a supported flavor of Ubuntu. Ubuntu is the most popular. But when it comes to “mainstream”… Ubuntu is pretty much for newbies, while Fedora and Debian are the two heavy hitters for people who don’t need their hands held.

As good as CrunchBang was… I don’t really like the idea of running something that is “almost” Debian. Or something that is “based on” a mainstream distro… but comes without any real support from that originating distro’s community (think red-headed step-child).

identd

Well, I installed CrunchBang Linux about nine days ago on both my machines and I am still absolutely loving it. Totally awesome.

I had some trouble getting identd (auth) working. Turns out my router was blocking ident requests. It’s not that uncommon I guess. I wanted to run an identd so that IRC would not hang for 30 seconds during logon. Plus I’d rather not have the little squiggly thing you get by your name when you don’t use identd that pretty much says (I’m too stoopid to know how to setup identd).

So… my wife (being the way cool wife that she is) ok’d an unplanned $60 expenditure for a new Netgear WNR3500Lv2 router. The selling point of this router is that it supports “open” third-party firmware like DD-WRT and Tomato. This firmware completely replaces the stock firmware (sort of like rooting your phone and installing a custom ROM). It’s like having a router on freaking steroids. Gives you all sorts of way cool features.

So, after installing a recent build of the Tomato firmware, boom… identd is all working and happy. Yay!

But now I have another problem. All of a sudden DALnet (the IRC network) is complaining about me running an “open proxy”. I don’t even know what an open proxy is. But I guess it’s a big security risk and they don’t want insecure machines on their network. So I’m effectively banned from their network until I can figure out what the problem is.

I’m not sure if that’s caused by my router or my web server (lighttpd). But it’s probably one or the other. I’ll have to do more research.

CrunchBang

Several days ago I had recently installed Fedora 19 on my machines. There was really nothing wrong with Fedora that prompted me to make another change. But I was really considering giving Debian a try. I’ve run Debian before, many moons ago. It’s one of the oldest surviving Linux distributions and very well-respected for it’s stability.

Now there are a lot of distributions that are based on Debian. Not only that, but Ubuntu is based on Debian. And there are a ton of distributions based on Ubuntu. So Debian is sort of the granddaddy. I had downloaded several new ISOs. I had Debian, I had Arch Linux, and I had CrunchBang.

Decisions decisions. Arch Linux is a lot of work. Fun, but still… a lot of work. It’s almost like a “roll your own” kind of thing. Debian might also be a bit of work, because I’d have to choose all the packages I’d need. And then I’d have to make them all work together.

But CrunchBang was interesting. It is directly based on Debian and it features the Openbox window manager. The CrunchBang folks really only add two things… 1) they choose the various necessary components to go with Openbox so that it will give basic functionality that most people require… and 2) they provide a nice default configuration for said Openbox and components. The result is an extremely light-weight Linux system that is the minimalist’s dream.

Seriously, I’ve been running it for four or five days now and I am totally in love. I think my “distro-hopping” days are over. I have CrunchBang on both of my machines and it’s working flawlessly.

It did take a little work in some areas. But it wasn’t bad. I plugged in my Canon digital camera… and it wasn’t recognized. Most complete Linux desktop environments provide that functionality, but Openbox isn’t actually a “desktop environment”, it’s simply a window manager. That’s why it’s so nice that the CrunchBang folks put all the various pieces together. Once I tracked down the pieces necessary, I was able to talk to my Canon camera just fine.

The thing about most other distributions (or operating systems in general) is that right after installing them, I find myself needing to start uninstalling all the needless garbage they add to it. And often times removing all that junk is way harder than just picking a minimalist distribution and adding to it.