S.A.S.I. - SuSE Automated Script Installer

S.A.S.I. - SuSE Automated Script Installer was written to allow the easy installation of one or more script and/or text files on a target PC system. If the target system has a user that has trouble placing several required script files, some as root or if you want to automate the creation of several scripts, located in several different places while you still remember how to do so, then the S.A.S.I. bash script file is for you. For instance I have used it to create please_try_again’s VirtualBox driver module replacement script and configuration file. Two files are placed in different /etc folders as root, one is marked executable with a symlink created on it. Just imagine a single script that when run, does this automatically for you and easy as pie.

Each script or text file that S.A.S.I. will create for you automatically can be located in different locations, each script or text file can be designated as a system file, requiring the root user password and each script or text file can have one or two custom commands executed on them after the file is created, such as marking it executable when the file is a script. The following script just creates two dummy script files files in two different locations as an example of what this script can be used to do. To create the S.A.S.I. script, copy and past the text in the following code block into your favorite text editor and save it as the file called sasi in the ~/bin folder (/home/username/bin/sasi):

#!/bin/bash

#: Title       : sasi
#: Date Created: Wed Sep 7 18:35:31 CDT 2011
#: Last Edit   : Fri Sep 9 17:00:31 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.00
#: Description : Multiple Script File Installed
#: Options     : None (Do Not Enter any Options)

TITLE="S.A.S.I. - SuSE Automated Script Installer - Version 1.0"

#
# Written for the openSUSE forums on Friday September 9, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file sasi in the folder ~/bib (/home/username/bin).
# This script must be marked executable to be used.  Please run 
# the following Terminal command: chmod +x ~/bin/sasi
#

declare -a Sysfile
declare -a File
declare -a Folder
declare -a Cmd1
declare -a Cmd2

#
# Required Script/Text File Creation Information goes here *******************
#

# Number of Script/Text Files To Create 

Files=2

# Script/Text File #1 Header Information

Sysfile 1 ]="true"
File 1 ]="test1"
Folder 1 ]="/usr/local/bin"
Cmd1 1 ]="chmod +x /usr/local/bin/test1"
Cmd2 1 ]=""

# Script/Text File Header #2 Information

Sysfile 2 ]="false"
File 2 ]="test2"
Folder 2 ]="$HOME/bin"
Cmd1 2 ]="chmod +x $HOME/bin/test2"
Cmd2 2 ]=""

#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#

function show_gpl {
echo ""
echo "sasi is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}

#
# This is where the entire text/script files are placed **********************
#

function fileoutput {

if  $Files -eq 1 ] ; then

cat >> "${Folder 1 ]}/${File 1 ]}" << "EOFTEXT"
#!/bin/bash
#
# This is the first text/script file******************************************
#
#

# Script or Text File 1 would go here

exit 0

# End Of Script
#
# This is the end of the first text/script file*******************************
#
EOFTEXT
fi

if  $Files -eq 2 ] ; then

cat >> "${Folder 2 ]}/${File 2 ]}" << "EOFTEXT"
#!/bin/bash
#
# This is the second text/script file******************************************
#
#

# Script or Text File 2 would go here

exit 0

# End Of Script
#
# This is the end of the second text/script file******************************
#
EOFTEXT
fi
}

#
# Main Program Begins Here ***************************************************
#

if  "$1" == "" ] ; then
clear
echo $TITLE
echo
echo "Please Wait .... while $Files file(s) are being Created ..."
  while  $Files -gt 0 ] ; do
    if  "${Sysfile$Files]}" == "true" ]; then
      echo
      sudo $0 $Files
    else
      echo
      $0 $Files
    fi
    let Files=Files-1
  done
  show_gpl
else
  Files=$1
  echo
  echo The File "${Folder $Files ]}/${File $Files ]} status is being Examined!"
  echo
# Does the Folder Exist?
  if  -d "${Folder $Files ]}" ]] ; then
# Does the File Exist before we create it?
    if  ! -e "${Folder$Files]}/${File$Files]}" ] ; then
      fileoutput
# Does the File Exist After we created it?
      if  -e "${Folder$Files]}/${File$Files]}" ] ; then
# Execute the required commands, if any
    ${Cmd1$Files]}
    ${Cmd2$Files]}
    echo "The File ${Folder$Files]}/${File$Files]} Was Written!"
      else
    echo "The File ${Folder$Files]}/${File$Files]} Was NOT Written!"
      fi
    else
      echo "The File ${Folder$Files]}/${File$Files]} Already Existed!"
    fi
  else
      echo "The Folder Name of ${Folder $Files ]} did not Exist!"
  fi
fi

exit 0

# End Of Script

After you have saved the S.A.S.I. bash script file, open up a terminal session and run the following command:

chmod +x ~/bin/sasi

If you run this script as is, you will end up with two test scripts test1 & test2, test1 located in /usr/local/bin and test2 in ~/bin as an example of what the S.A.S.I. bash script can do. If you run it a second time, after creating the two dummy scrips, you will be informed that they already exist. Now get the script now, but look for a future task for it to do for you. You got to change the contents of the file to be useful and you most likely will want to rename sasi to represent what it will do for you.

If you have any suggestions for S.A.S.I. bash script file, just let me know. Good luck and Happy scripting!

Thank You,

Here is an example of how S.A.S.I. - SuSE Automated Script Installer can be used. In this case, I modified sasi to create two files, one is a script called modautocompile and the other a configuration file called modautocompil.conf, both written by please_try_again. I saved this script as vboxautocompile in my ~/bin folder and marked it executable. When run, the two aforementioned files are created in /etc/rc.d and /etc. modautocompile is marked executable and then has insserv run on it while the other file is just a configuration file and nothing else is done to it.

#!/bin/bash

#: Title       : S.A.S.I. - SuSE Automated Script Installer
#: Date Created: Wed Sep 7 18:35:31 CDT 2011
#: Last Edit   : Fri Sep 9 20:27:31 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.01
#: Description : Multiple Script File Installed
#: Options     : None (Do Not Enter any Options)

TITLE="S.A.S.I. - SuSE Automated Script Installer - Version 1.01"

#
# Written for the openSUSE forums on Friday September 9, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file sasi in the folder ~/bib (/home/username/bin).
# This script must be marked executable to be used.  Please run 
# the following Terminal command: chmod +x ~/bin/sasi
#

declare -a Sysfile
declare -a File
declare -a Folder
declare -a Cmd1
declare -a Cmd2

#
# Required Script/Text File Creation Information goes here *******************
#

# Number of Script/Text Files To Create 

Files=2

# Script/Text File #1 Header Information

Sysfile[ 1 ]="true"
File[ 1 ]="modautocompile"
Folder[ 1 ]="/etc/rc.d"
Cmd1[ 1 ]="chmod +x /etc/rc.d/modautocompile"
Cmd2[ 1 ]="/sbin/insserv /etc/rc.d/modautocompile"

# Script/Text File Header #2 Information

Sysfile[ 2 ]="true"
File[ 2 ]="modautocompile.conf"
Folder[ 2 ]="/etc"
Cmd1[ 2 ]=""
Cmd2[ 2 ]=""

#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#

function show_gpl {
echo ""
echo "sasi is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}

#
# This is where the entire text/script files are placed **********************
#

function fileoutput {

if [ $Files -eq 1 ] ; then

cat >> "${Folder[ 1 ]}/${File[ 1 ]}" << "EOFTEXT"
#! /bin/sh
# Linux kernel module init script

#: Title       : modautocompile
#: Date Created: Sat Oct 16 06:00:29 PDT 2010
#: Last Edit   : Sat Oct 16 06:00:29 PDT 2010
#: Author      : please_try_again
#: Version     : 1.0
#: Description : Automatically recompile modules after kernel update


# chkconfig: 35 30 70
# description: recompile modules
#
### BEGIN INIT INFO
# Provides:       modautocompile 
# Required-Start: $syslog
# Required-Stop:
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: recomppile kernel modules
### END INIT INFO

# Define the modules you want to autorecompile in the file /etc/modautocompile.conf
# or in the file specified by the variable CFG below
CFG=/etc/modautocompile.conf

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# /etc/modautocompile.conf example 
# kernel modules to autocompile after kernel update
# module          command
# vboxdrv         service vboxdrv setup
# fglrx           /usr/bin/fglrx-kernel-build.sh
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH

start()
{

# check if $CFG exist
if [ ! -e $CFG ] ; then
    echo $CFG not found
    exit 1
fi

# parse /etc/modautocompile.conf
eval `awk 'BEGIN { I=-1 } ; !/^#/ { if ( NF ) { MOD=$1 ; I++ ; $1="" ; sub(/ /, "", $0) ;  printf "MOD[%i]=%s; CMD[%i]=\"%s\";",  I, MOD, I, $0 } }' $CFG`

# exit if no modules defined in /etc/modautocompile.conf

if [ ${#MOD
[li]} -eq 0 ] ; then[/li]    exit 2
fi

# kernel modules dir
MDIR=/lib/modules/$(uname -r)

i=0
while [ $i -lt ${#MOD
[li]} ] ; do[/li]    mod=${MOD[$i]}
    cmd=${CMD[$i]}
    unset mof    
    if [ "x$mod"!="x" -a "x$cmd"!="x" ] ; then
        mod=${mod}.ko
        mof=`find $MDIR -name $mod`
        if [ "$mof" == "" ] ; then
            echo " - compiling module $mod"
            $cmd
        fi
    fi
    let i++
done
}

case "$1" in
start)
    start
    ;;
esac

exit 0


EOFTEXT
fi

if [ $Files -eq 2 ] ; then

cat >> "${Folder[ 2 ]}/${File[ 2 ]}" << "EOFTEXT"
# kernel modules to autocompile after kernel update
# name              command
vboxdrv             service vboxdrv setup

EOFTEXT
fi
}

#
# Main Program Begins Here ***************************************************
#

if [ "$1" == "" ] ; then
clear
echo $TITLE
echo
echo "Please Wait .... while $Files file(s) are being Created ..."
  while [ $Files -gt 0 ] ; do
    if [ "${Sysfile[$Files]}" == "true" ]; then
      echo
      sudo $0 $Files
    else
      echo
      $0 $Files
    fi
    let Files=Files-1
  done
  show_gpl
else
  Files=$1
  echo
  echo The File "${Folder[ $Files ]}/${File[ $Files ]} status is being Examined!"
  echo
# Does the Folder Exist?
  if [[ -d "${Folder[ $Files ]}" ]] ; then
# Does the File Exist before we create it?
    if [ ! -e "${Folder[$Files]}/${File[$Files]}" ] ; then
      fileoutput
# Does the File Exist After we created it?
      if [ -e "${Folder[$Files]}/${File[$Files]}" ] ; then
# Execute the required commands, if any
    ${Cmd1[$Files]}
    ${Cmd2[$Files]}
    echo "The File ${Folder[$Files]}/${File[$Files]} Was Written!"
      else
    echo "The File ${Folder[$Files]}/${File[$Files]} Was NOT Written!"
      fi
    else
      echo "The File ${Folder[$Files]}/${File[$Files]} Already Existed!"
    fi
  else
      echo "The Folder Name of ${Folder[ $Files ]} did not Exist!"
  fi
fi

exit 0

# End Of Script

This is just one example of what you could use the S.A.S.I. - SuSE Automated Script Installer bash script file for.

Thank You,