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

S.A.S.I. - SuSE Automated Script Installer (works with openSUSE 12.2) 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       : S.A.S.I. - SuSE Automated Script Installer
#: Date Created: Wed Sep  7 18:35:31 CDT 2011
#: Last Edit   : Sat Dec 17 11:34:00 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.03
#: Description : Multiple Script File Installed
#: Options     : None (Do Not Enter any Options)

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

#
# Written for the openSUSE forums on Saturday 17, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file sasi in the folder ~/bin (/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!"
      read -p "Do you wish to remove the old file now? (y/N): " CHOICE
      if  $CHOICE == [Yy] ]] ; then
      rm ${Folder$Files]}/${File$Files]}
      echo
      echo "The File ${Folder$Files]}/${File$Files]} was removed.  Please run $0 again."
      fi     
    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,

Blogs: asroot : Bash : Packet Filter : C.F.U. : GPU’s : fewrup : F.S.M. : H.I. : nVIDIA : LNVHW : N.S.F. : S.A.K.C. : MMCHECK
S.A.S.I. : S.C.L.U. : S.G.T.B. : S.K.I.M. : S.L.A.V.E. : S.L.R.C. : S.T.A.R.T. : S.U.F.F. : SYSEdit : systemd