Difference between revisions of "Auto Update Script"
(Created page with "As of version 0.912 the ubermix has a network auto update script installed by default - prior versions include it as part of the default simple updates files (see [[About_the_def...") |
|||
Line 3: | Line 3: | ||
The default auto update script is in the user's home folder and is called ".network-autostart". Linux hides all files that begin with a ".", so you won't see it in any of the file browsing tools. The script doesn't do anything out of the box - it is essentially disabled. To edit it, open a terminal by pressing "ctrl-alt-t" and type "gedit .network-autostart". Your file will look something like the following: | The default auto update script is in the user's home folder and is called ".network-autostart". Linux hides all files that begin with a ".", so you won't see it in any of the file browsing tools. The script doesn't do anything out of the box - it is essentially disabled. To edit it, open a terminal by pressing "ctrl-alt-t" and type "gedit .network-autostart". Your file will look something like the following: | ||
− | <nowiki>#!/bin/bash | + | <nowiki>#!/bin/bash |
logger -p user.info "Network Autostart Script Starting" | logger -p user.info "Network Autostart Script Starting" | ||
if [ "`/sbin/ifconfig | grep -v lo | grep Link -A1 | grep inet `" ]; then | if [ "`/sbin/ifconfig | grep -v lo | grep Link -A1 | grep inet `" ]; then | ||
Line 20: | Line 20: | ||
Save the changes, and your device will be ready to self-update. Below is a sample script to install on the web server (for the devices to download): | Save the changes, and your device will be ready to self-update. Below is a sample script to install on the web server (for the devices to download): | ||
− | <nowiki>#!/bin/bash | + | <nowiki>#!/bin/bash |
# Variables Section | # Variables Section |
Revision as of 14:14, 16 December 2011
As of version 0.912 the ubermix has a network auto update script installed by default - prior versions include it as part of the default simple updates files (see About_the_default_simple_updates_files_on_the_key). This script offers the capability to apply updates to a any number of devices whenever they connect to the network. The functionality of the auto update script is quite simple and effective, as follows: when a network connection is established, the device retrieves another script file from a web server (any web server will do) and executes it. In that script, you can pull down and install files and updates and apply them to all of your devices. The script makes maintaining devices quite easy, so we would recommend configuring it for installations of any size, even if you don't know for sure that you will use it.
The default auto update script is in the user's home folder and is called ".network-autostart". Linux hides all files that begin with a ".", so you won't see it in any of the file browsing tools. The script doesn't do anything out of the box - it is essentially disabled. To edit it, open a terminal by pressing "ctrl-alt-t" and type "gedit .network-autostart". Your file will look something like the following:
#!/bin/bash logger -p user.info "Network Autostart Script Starting" if [ "`/sbin/ifconfig | grep -v lo | grep Link -A1 | grep inet `" ]; then logger -p user.info "An interface is up" # if [ -z `pgrep pidgin` ]; then # logger -p user.info "Loading Pidgin" # pidgin & # fi # sudo wget http://mirror.saugus.k12.ca.us/une1104/update.sh -O /root/update.sh # sudo chmod +x /root/update.sh # sudo /root/update.sh fi
Note that lines that start with a hash mark (#) are disabled. Toward the top of the file are some examples of starting programs when an interface comes up. Near the end there is a line that begins with "wget", which contains the web address for the script file. Change this address to point to one of your web servers and remove the hash marks from the start of the the "wget" line and the two lines after it. You don't have to actually have a script on your web server to make this change, the script won't do anything if it can't download one.
Save the changes, and your device will be ready to self-update. Below is a sample script to install on the web server (for the devices to download):
#!/bin/bash # Variables Section # # Set the WEBSERVER to the url location of the we server storing your updates. # DO NOT use a trailing slash WEBSERVER="http://webserver.yourdistrict.k12.ca.us/ubermix-updates" REBOOT=false # Functions Section # # Contains functions used by the script to handle updates. Do not delete. standardInstall() { # Performs a standard download and install of a file. Extracts any .tar.gz # file, making the assumption that the archive was prepared to be installed # from the root (/). Automatically installs any .deb using dpkg. # All files to download must have an accompanying md5 checksum file with # the same name+.md5 on the web server. To create this file, simply change # to the file's directory on the web server and do: # # md5sum [filename] >[filename.md5] # # Function expects either 2 or 3 parameters in the following order: # 1. name of file # 2. name of checkfile # 3. (optional) destination directory # # There can be no spaces in any parameter that are not escaped with a \ # The purpose of the checkfile is to simply create a file in /root/ that # is used as a flag to indicate that the update has been installed (so that # already installed files don't get reinstalled every time. # # Function returns 0 on successful install, 1 for errors or already installed FILE=$1 CKFILE=$2 RESULT=0 DESTDIR="/root/" if [ -n $3 ]; then if [ -d $3 ]; then DESTDIR=$3 fi fi if [ ! -e "/root/.$CKFILE" ]; then wget "$WEBSERVER/$FILE" -O "$DESTDIR/$FILE" wget "$WEBSERVER/$FILE.md5" -O "/root/$FILE.md5" if [ -s "$DESTDIR/$FILE" ]; then if [ "$(md5sum $DESTDIR/$FILE | cut -d\ -f1)" = "$(cat /root/$FILE.md5 | cut -d\ -f1)" ]; then if `echo $1 | grep -q tar.gz`; then tar -xzvf $DESTDIR/$FILE -C / >>/tmp/update.log rm -f $DESTDIR/$FILE fi if `echo $1 | grep -q tgz`; then tar -xzvf $DESTDIR/$FILE -C / >>/tmp/update.log rm -f $DESTDIR/$FILE fi if `echo $1 | grep -q .deb`; then dpkg -i $DESTDIR/$FILE >>/tmp/update.log fi touch /root/.$CKFILE echo "$CKFILE update applied" >>/tmp/update.log rm -f /root/$FILE.md5 else RESULT=1 fi else RESULT=1 fi else RESULT=1 fi return $RESULT } # Main Updates Section. # # Add your updates here. See notes for standardInstall function above for # details on how to use it #Example #standardInstall showid.tar.gz showid_update if $REBOOT; then xmessage "An important update has occured. Your netbook is restarting." & >>/tmp/update.log sleep 5 reboot fi
This script automates much of the update process. Read the comments in the script for details.