06 November 2005

Jebus. I hate shell scripts!

Yes, shell scripts make thing easier. A script will do want I don't want to remember to do. A script will speed up things to allow more time for Farking...

But it takes some time to write the damned things...

Here's the script I had to write for a job interview:


I would also like to see a shell script written in BASH that builds a
Solaris software package lets say proftpd 1.2.10. The build should start
from the canoical source available at :


ftp://ftp.proftpd.org/distrib/source/proftpd-1.2.10.tar.gz

Include all patches necessary to compile the application. Apply the patches
and create the package. No need to worry about error handling.


the script:

#
# Package creation script - 05NOV05 w.b.
# Portable code for universal package creation. I still
# need to tweak some of the commands, but this file
# downloads source, configures, makes, packages,
# and archives Solaris packages.
#
# location variables
#
pkg_stage="/tmp/pkgtmp"
installdir="/opt/proftpd" # this may be defunct now
pkguid="proftpd"
pkgroot="proftpd-1.2.10"
#
# make/config varibles
#
prefix="--prefix=/usr"
sysconfig="--sysconfdir=/etc"
localstate="--localstatedir=/var/run"
modules="--with-modules=mod_readme:mod_ratio"
#
# pkginfo variables
#
pkg="GNUproftpd"
pkgname="GNUproftpd - Proftpd daemon"
pkgfile="GNUproftpd.1.2.10.x86.5.9"
pkgfile2="GNUproftpd.1.2.10.x86.5.9.pkg.tgz"
version="1.2.10"
arch="x86"
classes="none"
category="utility"
vendor="GNU - proftpd.org"
datestamp="$(date)"
basedir="/"
#

# source/ftp varibles
#
anonpass="$LOGNAME@$(hostname)"
server="ftp.proftpd.org"
filename="/distrib/source/proftpd-1.2.10.tar.gz"
basefile="/tmp/$(basename $filename)"
#
echo "### Start package creation"
#
#
# daemon user creation
#
echo " "
echo "### Creating UID & GID"
groupadd -g 460 $pkguid &&
useradd -c '$pkguid' -d $installdir -g $pkguid \
-s /bin/false -u 460 $pkguid &&
#
mkdir $pkg_stage
cd /tmp/
#
# ftp code
#
echo "### Downloading $basefile from server $server"
#
# for some reason the ftp function isn't grabbing the full file.
# In order to deliver a finished script, I am using curl.
# I would like go back and resolve this problem later.
#
#ftp -n /tmp/files
#
cat /tmp/files | pkgproto $pkg_stage= > /tmp/Prototype
#
# pkginfo handling here
#
cd /tmp/
#
rm -rf pkginfo
touch pkginfo
echo "PKG=$pkg" >> pkginfo
echo "NAME=$pkgname" >> pkginfo
echo "VERSION=$version" >> pkginfo
echo "ARCH=$arch" >> pkginfo
echo "CLASSES=$classes" >> pkginfo
echo "CATEGORY=$category" >> pkginfo
echo "VENDOR=$vendor" >> pkginfo
echo "PSTAMP=$datestamp" >> pkginfo
echo "BASEDIR=$basedir" >> pkginfo
#
echo "i pkginfo" >> Prototype
#
# solaris package creation
#
echo "### Create Solaris Package: $pkg"
#
pkgmk -o -r / -d /tmp -f Prototype
#
pkgtrans -s /tmp $pkgfile.pkg
#
# Compress package
#
echo " "
echo "### Gzipping /tmp/$pkgfile into /tmp/$pkgfile2"
/usr/bin/tar -cf - /tmp/$pkgfile.pkg | gzip -9c > /tmp/$pkgfile2
#
# file cleanup & archive
#
mkdir /opt/pkgs/$pkgroot
cp -R /tmp/Prototype /tmp/pkginfo $pkg_stage /tmp/$pkgfile2 \
$basefile /opt/pkgs/$pkgroot
rm -r /tmp/files /tmp/Prototype /tmp/pkginfo /tmp/$pkg \
$pkg_stage /tmp/$pkgfile.pkg $basefile $pkgroot /tmp/$pkgfile2
#
echo "### Package complete: $pkg stored in /opt/pkg/$pkgroot"
#
exit 0

It needs some work, but it still functions well...

0 comments: