Home

Advertisement

Nov. 13th, 2007

Mirror

Fun with Shell Scripts... OR Sagacious Simplification of Plug-in Development

A little background...

Previously when I made plug-ins for Anathema I adhered to the following process:

    Open directory with plugin-fragment.xml.
  1. Select contents of directory.
  2. Compress selection into a ZIP archive.
  3. Change extension to .jar.
  4. Copy JAR to computer downstairs (This machine has VMWare and Windows.)
  5. Run downstairs to use computer.
  6. Open JAR in with 7-zip.
  7. Remove meta-data from JAR. (e.g. .DS_Store, thumbs.db, etc.)
  8. Post JAR for downloading


The average time it took: 8+ minutes.

Now when I make plug-in's for Anathema:

    Open Terminal.
  1. Type sh makeJar.sh
  2. Type name of directory containing plug-in components.
  3. Post JAR for downloading.


The average time it now takes: -1 minute.

makeJar.sh


#!/bin/bash

function createJar {
  printf "Copying files to temporary directory..."
  cp -R $plugDirect pluginTemp ;
  printf "\n Removing meta-data from files..."
  rm -rf $( find pluginTemp -type d -name .svn ) ;
  rm -f $( find pluginTemp -type f -name .DS_Store ) ;
  cd pluginTemp ;
  printf "\n Making $plugDirect.jar..." ;
  jar cf ../$plugDirect.jar * ;
  cd .. ;
  printf "Removing temporary directory..."
  rm -rdf pluginTemp ;
  printf "\n" ;
  printf "\n $plugDirect.jar is finished. \n Look in \'$( pwd )\' for the file." ;
  printf "\n" ;
}

function testDirect {
  if [ -d "$plugDirect" ] ; then
    testJar ;
  else
    read -p "The $plugDirect directory does not exist.  Try again? (y/n)  " noDirect ; 
    if [ $noDirect == "y" ] ; then
      read -p "Please re-ener the directory containing plug-in files:  " plugDirect ;
      testDirect ;
    fi
  fi
}

function testJar {
  if [ ! -f "$plugDirect.jar" ] ; then
    testTemp ;
  else
    read -p "$plugDirect.jar already exists.  Overwrite? (y/n)  " overwriteJar ;
    if [ $overwriteJar == "y" ] ; then
      rm -rdf $plugDirect.jar ;
      testJar ;
    fi
  fi
}

function testTemp {
  if [ ! -d "pluginTemp" ] ; then
    createJar ;
  else
    read -p "pluginTemp already exists.  Overwrite?  (y/n)  " overwriteTemp ;
    if [ $overwriteTemp == "y" ] ; then
      rm -rdf pluginTemp ;
      testTemp ;
    fi
  fi
}

cd /Users/pauladams/Documents/Development/Anathema ;
read -p "Please enter the directory containing the plug-in files:  " plugDirect ;
printf "\n" ;
testDirect ;


Is anyone aware of a way to force characters into the lower case? Y -> y OR N -> n

Sep. 14th, 2007

Seashore

New version of my script...

Currently, I’m trying to “bullet proof” (eliminate most potential pitfalls) my script. I’ve added to my script the ability to detect network connectivity (no point in doing online updates if your not online). If it is not found, it will bring up the various network interfaces.

##############################################################################
## This work is licensed under the Creative Commons Attribution-Share Alike ##
## 3.0 United States License. To view a copy of this license, visit         ##
## http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to    ##
## Creative Commons, 171 Second Street, Suite 300, San Francisco,           ##
## California, 94105, USA.                                                  ##
##                                                                          ##
##              risoUpdate.sh Copyright Paul R. Adams, 2007                 ##
##############################################################################

#!/bin/bash

#-- First, replace the current updates.log file with the date.  Second,
#   ask for the administrative password (which is required for software
#   updates and the potential reboot).  Third, export an environmental
#   variable that elminiates any pesky dialog boxes.  Fourth, activate
#   scheduled downloads and append any output (stout and sterr) to the
#   the updates.log file.  Finally, start OS X version specific code bits. --#

date > /tmp/updates.log 2>&1 ;
read -p “Please enter the administration password:  “ Password
export COMMAND_LINE_INSTALL=1 ;
softwareupdate --schedule on >> /tmp/updates.log 2>&1 ;

if [ “$(sw_vers -productVersion | cut -c 1-4)” == “10.4” ] ;
  # -- If OS is 10.4, reset ignored updates. -- #
  then softwareupdate --reset-ignored >> /tmp/updates.log 2>&1 ;
  # -- If OS is 10.3, reset ignored updates. -- #
  else softwareupdate --ignored remove -a >> /tmp/updates.log 2>&1 ;
fi

# -- Do the various network interfaces have IP addresses -- #

if [ -z “$(ifconfig en0 | grep inet)” ] ; 
  then en0_up=”no” ;
  else en0_up=”yes” ;
fi

if [ -z “$(ifconfig en1 | grep inet)” ] ;
  then en1_up=”no” ;
  else en1_up=”yes” ;
fi

if [ -z “$ifconfig en2 | grep inet)” ] ;
  then en2_up=”no” ;
  else en2_up=”yes” ;
fi

# -- If none of the network interfaces have an IP address, bring up the 
#    network interfaces and acquire an IP address. -- #

if (( en0_up==no && en1_up==no && en2_up=no )) ;
  then echo $Password | sudo -S ifconfig en0 up >> /tmp/updates.log 2>&1 ;
  echo $Password | sudo -S ifconfig en1 up >> /tmp/updates.log 2>&1 ;
  echo $Password | sudo -S ifconfig en2 up >> /tmp/updates.log 2>&1 ;
fi

sleep 15 ;

#-- Install all available updates and append any output to updates.log.  Next,
#   update the “prebinding” information for OS X (optimizing step).  Finally,
#   reboot if grep finds “restart” in the updates.log file. -- #

echo $Password | sudo -S softwareupdate -i -a >> /tmp/updates.log 2>&1 ;
echo $Password | sudo -S update_prebinding -root / -force ;
cat /tmp/updates.log | grep restart && echo $Password | sudo -S reboot ;
Tags: , ,
Dent

Terminal hacking on OS X...

This is the current iteration of my OS X update script. When I “finish” it, I intend to see if it can be enabled as a cron job that runs on Wednesday morning to grab all the necessary updates. Anyone want to critique it?


#!/bin/bash
#
## -- The following code is common for the past 2 versions of OS X. -- ##
#
#-- First, replace the current updates.log file with the date. Second,
# ask for the administrative password (which is required for software
# updates and the potential reboot). Third, export an environmental
# variable that elminiates any pesky dialog boxes. Fourth, activate
# scheduled downloads and append any output (stout and sterr) to the
# the updates.log file. Finally, start OS X version specific code bits. --#
#
date > /tmp/updates.log 2>&1 ;
read -p “Please enter the administration password: “ Password
export COMMAND_LINE_INSTALL=1 ;
softwareupdate --schedule on >> /tmp/updates.log 2>&1 ;
#
## -- OS Version Specific Code -- ##
#
if ! [ “$(sw_vers -productVersion | cut -c 1-4)” == “10.4” ] ;
#
## -- OS X 10.3.x -- ##
#
#-- First, remove all updates from the “ignored” list and append any
# output (stout and sterr) to the log. Second, install all available
# updates and append output to the log. Third, read updates.log and
# search for “restart”, if found reboot. --#
#
then softwareupdate --ignored remove -a >> /tmp/updates.log 2>&1 ;
echo $Password | sudo -S softwareupdate -i -a >> /tmp/updates.log 2>&1 ;
cat /tmp/updates.log | grep restart && echo $Password | sudo -S reboot ;
#
## -- OS X 10.4.x -- ##
#
#-- See above comment, for information about what the following
# code does, customized for OS X 10.4.x. --#
#
else softwareupdate --reset-ignored >> /tmp/updates.log 2>&1 ;
echo $Password | sudo -S softwareupdate -i -a >> /tmp/updates.log 2>&1 ;
cat /tmp/updates.log | grep -m 1 restart && echo $Password | sudo -S reboot ;
fi


UPDATE(s): Apparently “-m 1” is not an option for the version of “grep” included with OS 10.3.x.
Tags: ,

Sep. 10th, 2007

Dent

Two completely unrelated topics: Unix Shells and Metroid.

One of the nice things about have an Apple Computer with OS X installed on it is the ability to use Unix tools, if you need to. Which for me is, apparently, most of the time. As of late, I’ve been tinkering with the various Unix shells and I have really liked ZSH. I like being able to, without any configuration, tab through various commands until I find the one that I was looking for. (ie. soft <tab> == softwareupdate) Although, not being a “life-long” user of Unix, I am still confused about the various configuration files (aka. .zprofile, .zshrc, .zshenv, etc).

From what I understand:

profile == Used for login shells.
rc == Used for interactive shells.

Which brings up a question about what things I should put into each file? For the moment, I have .bash_profile and .zprofile loading a common “environmental variable” file. While the .rc files loading shell specific options and modifications to environmental variables. Does anyone have some suggestions?

--

On another front, Metroid Prime 3: Corruption is awesome. I just managed to beat the game and I am just astounded by it’s goodness. Now, I’ve got to find a friend with it so I can trade “Friend Vouchers” so that I can get some more extras (need bumper stickers for my ship). Even though Metroid Prime 2: Echo’s was too hard for me to play (I got stuck at the “speed” boss), this game redeems them and makes me hope to see more Metroid games.
Tags: , ,

Advertisement

Customize