Gerrards Cross Computer Club

ICY BOX 4220 - How Scripts Work

Return to support page home

Page updated 21 July 2008

Contents

  1. ICY BOX 4220 - How Scripts Work
    1. Contents
    2. Overview
    3. /etc/rc.pkg.start 
      1. Initialisation
      2. Install New Packages
    4. /etc/rc.pkg.staThere is a minor issue with the box in that the disk drives should stop when they are not being usedrt
      1. Execute init Files in package folders
      2. Listing of /etc/rc.pkg.start
    5. /etc/rc.pkg.start

Overview

This page descibes the essential part of the boot process and how this updates the system with new packages. The iniialisation script can call user scripts located on a share on the RAID array.

/etc/rc.pkg.start 

Note that any line befining with a # symbol is a comment.

The first line starts with a special, and vital, comment - the string #!/bin/sh is a special character sequence that must be present before a text file is treated as a script. The UNIX file permissions must also have the EXCUTE bit set for them to be executed as if they are programs.

This script is divided into three sections.

Initialisation

This sets up some PATH entries which enable commands to be called without specifying the full filepath name.

It then ensures that the new_software folder exists in the /public/applications folder on the RAID. If it does not exist it will be created and the folder permissions on /public/applications/new_software and /public/applications set to include the execute bit. In fact is sets Read/Write/Execute for Owner, Group and Other users. These are the commands chmod 777.

Install New Packages

The script now tests for new package

/etc/rc.pkg.staThere is a minor issue with the box in that the disk drives should stop when they are not being usedrt

s which the user will place in the public share /public/applications/new_software. These must be in .tgz format. Ther can be more than one.

The script extracts the contents of each installation package and places it in a folder created within the /pubic/applications folder.

The script then deletes the .tgz files in /public/applications/new_software folder and any folders contrined within that folder.

Execute init Files in package folders

This script is divided into three sections.

The script then goes through all the folders within /public/applications and looks for a file called init. If oe is found it is executed.

Listing of /etc/rc.pkg.start

#!/bin/sh -
#
# This script checks if the $HD_MNT_POINT/public/applications dir exists and
# then extracts new pkgs and run there init-scripts
# After a pkg was installed it will be removed
#soro-arch01> cat /etc/rc.pkg.start
#!/bin/sh -
#<table summary="Heading">
  <tbody>
    <tr>
      <td><img src="../images/gxcclogo.gif"
 alt="Gerrards Cross Computer Club" border="0" height="82"
 width="200"></td>
      <td>
      <h1 class="pageheading">Backup Solutions - Hardware
and Software</h1>
      <p><a href="../index.html"><img
 style="border: 0px solid ; width: 56px; height: 20px;"
 alt="Return to support page home" src="../images/btnBack.gif"></a></p>
      <p class="updated">Page updated 21 July 2008</p>
      </td>
    </tr>
  </tbody>
</table>

# This script checks if the $HD_MNT_POINT/public/applications dir exists and
# then extracts There is a minor issue with the box in that the disk drives should stop when they are not being usednew pkgs and run there init-scripts
# After a pkg was installed it will be removed
#
HOME=/
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/hddapp/bin:/usr/hddapp/sbin:/usr/local/bin:/usr/local/sbin
export HOME PATH

. /etc/rc.conf

#
# save $1 aka the harddisk mountpoint
HD_MNT_POINT=$1This script is divided into three sections.
There is a minor issue with the box in that the disk drives should stop when they are not being used
# make sure all the needed dirs existThis script is divided into three sections.
if [ ! -d  $HD_MNT_POINT/public/applications/new_software ]; then
        mkdir -p $HD_MNT_POINT/public/applications/new_software
        chmod 777 $HD_MNT_POINT/public/applications/new_software
        chmod 777 $HD_MNT_POINT/public/applications
fi

CWD=`pwd`
# test for archives in the new_software dir
pkgs=`ls $HD_MNT_POINT/public/applications/new_software/*.tgz 2> /dev/null`
if [ ${#pkgs} -ge 1 ]; then
        cd $HD_MNT_POINT/public/applications
        echo "archive in new_software found"
        # for every archiv found
        for i in ./new_software/*.tgz; do
                echo "testing if $i already exists"
                archivename=${i##*/}
                # check if a dir below applications exists
                if [ ! -d ${archivename%.*} ]; then
                        #if not extract the archive
                        echo "installing ${archivename%.*}"
                        tar -xzf ./$i
                else
           

/etc/rc.pkg.start

             echo "${archivename%.*} already exists skip"
                There is a minor issue with the box in that the disk drives should stop when they are not being usedfi
        done
        # go back to where we started
        cd $CWD
elseThis script is divided into three sections.
      This script is divided into three sections.  echo "no new pkgs found"
fi

# delete everything in $HD_MNT_POINT/public/applications/new_software/
rm -rf $HD_MNT_POINT/public/applications/new_software/*

#
# now exec the init-scripts
init=`ls $HD_MNT_POINT/public/applications/*/init 2> /dev/null`
if [ ${#init} -ge 1 ]; then
        echo "found some init scripts"
        cd $HD_MNT_POINT/public/applications
        for i in `ls ./*/init`; do
                # run the init script in background
                echo "running: $i"
                ./$i
        done
fi


echo "done"
cd $CWD