#!/bin/sh # Start AIDE in init, scan or update mode # # You must have in /etc/fstab lines, describing mountpoints, specified # in aidecontrol.conf file (usbdevmp parameter) # # Your system must include lines nesessary to mount USB Flashdrives # (see man umass(4)) # # Your /etc/usbd.conf must include lines, similar below (see man usbd.conf) # BEWARE! vendor, product and release codes can be DIFFERENT from these! # For obtain correct values for vendor, product and release start usbd in # debug mode, insert USB Flashdrive and store values, obtained by usbd. # ## Generic USB Flash drive (umass0) #device "USB Flash Drive" # devname "umass[0-9]+" # vendor 0x058f # product 0x9380 # release 0x0100 # attach "/sbin/mount /mnt/umass" # # Written by CityCat 24.08.2004 # BSD License. Copyright (C) by Rashid N. "CityCat" Achilov # $Id: aidestart,v 1.1.1.1 2008/01/20 21:10:58 shelton Exp $ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin # Usage printing function usage() { cat << !EOM AIDEStart, an AIDE databases starting script. Version 1.7 Usage: aidestart {-h | -i | -c | -u | -m} [-f config file] [-n] [-5] -h - this (very useful) help screen -i - initialize AIDE database -c - check system against database -u - update an old database -m - compare databases -f - specifies configuration file name and path [default /usr/local/etc/aidecontrol.conf] -n - do not umount flashrive at finish -5 - script will run on 5.x branch !EOM } # Loading current base from Flashdrive loadbase() { $aidepath/rm -f $adbnam $aidepath/cp $aidebase/$adbnam.bz2 $adbnam.bz2 $aidepath/chown $abowner:$abgroup $adbnam.bz2 $aidepath/chmod $abmode $adbnam.bz2 $aidepath/bzip2 -d -q $adbnam.bz2 } # Clean junk files junkclean() { rm -f $tmpdir/umount rm -f $tmpdir/camcontrol } # Initial values mode="compare" config="/usr/local/etc/aidecontrol.conf" umfldrv="yes" onfive="no" # Parse a command line args=`getopt n5hicumf: $*`; if [ $? -ne 0 ]; then usage exit 20 fi set -- $args for i in $args do case "$i" in -h) usage exit;; -i) mode="init"; shift;; -c) mode="check"; shift;; -u) mode="update"; shift;; -m) mode="compare"; shift;; -n) umfldrv="no"; shift;; -5) onfive="yes"; shift;; -f) config="$2"; shift; shift;; --) shift; break;; esac done # Suck configuration file if [ -e $config ]; then . $config else echo "Configuration file $config does not exist" exit fi # Fallback, when $starthost didn't specified if [ $starthost = "--SET-HERE--" ]; then echo "StartHost value does not specified in $config file, exiting" exit fi # Mount USB Flashdrive with latest database copy and AIDE binary itself, # statically linked while [ 1 ] do echo "Insert USB Flashdrive in device $usbdev and press any key when ready..." read kbd # Check availability of USB Flashdrive usbdevmp=`mount | grep $usbdev | awk '{print $3}'` if [ ! -z "$usbdevmp" ]; then echo "USB Flashdrive succesfully mounted on $usbdev" break else echo "Problems in mounting USB Flashdrive on $usbdev" exit fi done # Here lies a statically linked AIDE binary. We set path to it, depend # from OS version, but not assumed any data from box! if [ $onfive = "yes" ]; then aidepath="$usbdevmp/bin5" else aidepath="$usbdevmp/bin" fi aidebase="$usbdevmp/$starthost" cd $startdir case "$mode" in # Init mode was selected init) $aidepath/aide --init $aidepath/chown $abowner:$abgroup $adbnam.new $aidepath/chmod $abmode $adbnam.new $aidepath/mv $adbnam.new $adbnam ;; # Check mode was selected. Copy file from Flashdrive and delete after # checking check) loadbase $aidepath/aide --check $aidepath/less report.aide $aidepath/rm -f $adbnam ;; # Check database and update mode was selected update) loadbase $aidepath/aide --update $aidepath/less report.aide $aidepath/chown $abowner:$abgroup $adbnam.new $aidepath/chmod $abmode $adbnam.new $aidepath/rm -f $adbnam $aidepath/mv $adbnam.new $adbnam ;; # Compare two bases mode was selected compare) loadbase $aidepath/aide --compare $aidepath/less report.aide ;; esac # Umount flashdrive, when does not set inverse command if [ $umfldrv = "yes" ]; then # Copy umount and camcontrol binaries to temp directory to use it later $aidepath/cp $aidepath/umount $tmpdir $aidepath/cp $aidepath/camcontrol $tmpdir # Memorize device, mounted into this mount point mpdev=`mount | grep -e "$usbdevmp " | awk '{print substr($1,6,3)}'` $tmpdir/umount $usbdevmp status=$? # Check unmounting status and warn user, when unsuccesful if [ $status -ne 0 ]; then echo "USB Flashdrive unmounting on device $usbdev failed, return code is $status" else echo "USB Flashdrive was succesfully unmounted" # Do search installed device and take info umdrive=`camcontrol devlist | grep -e "($mpdev"` # Search bus (search "scbusX", than select X from string) umbus=`echo $umdrive | awk '{print substr($0,index($0,"scbus"),6)}'` umdig=`echo $umbus | awk '{print substr($1,6)}'` # Similar way search target umtarget=`echo $umdrive | awk '{print substr($0,index($0,"target") + 7,1)}'` umlun=`echo $umdrive | awk '{print substr($0,index($0,"lun") + 4,1)}'` $tmpdir/camcontrol eject $umdig:$umtarget:$umlun fi junkclean fi