Thursday, August 26, 2010

Linux Shell Scripts

Linux is tricky. It would be nice to make a simple package that I could bundle everything from a project into one easy install. But a quick look at the man pages and this is beyond the comprehension of mere mortals. So the next best approach is to knock up a script which automates an install. But how do you check that a package that you require is installed? This is what I came up with. It has some problems like you'd have to adjust the grep for other packages like minicom, which put up different packaging messages. There must be a better way to do this?


echo "Checking that dfu-programmer is installed"
dpkg-query -s dfu-programmer | grep not-installed
if [ "$?" == "1" ]; then
echo "dfu-programmer is installed"
else
echo "dfu-programmer missing"
apt-get install dfu-programmer
fi