home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
tusportal.tus.k12.pa.us
/
tusportal.tus.k12.pa.us.tar
/
tusportal.tus.k12.pa.us
/
Wyse
/
latest-image.raw
/
0.img
/
usr
/
sbin
/
thinclient-include
< prev
next >
Wrap
Text File
|
2012-08-08
|
5KB
|
201 lines
#======================================
# importFile
#--------------------------------------
function importFile {
# /.../
# import the config.<MAC> style format. the function
# will export each entry of the file as variable into
# the current shell environment
# ----
IFS="
"
while read line;do
[ "x${line:0:1}" = "x#" ] && continue
key=`echo "$line" | cut -d '=' -f1`
item=`echo "$line" | cut -d '=' -f2- | tr -d "\'" | tr -d "\""`
if [ -z "$key" ] || [ -z "$item" ];then
continue
fi
eval export "$key\=\"$item\""
done
}
function LocalUpdate ()
{
echo $UPDATE_URL | grep "^file:///" > /dev/null
return $?
}
function getLocalsrcPatch ()
{
echo $1 | sed "s#^file://##g"
}
function fetch ()
{
src=$1
dest=$2
if LocalUpdate; then
localsrcpatch=`getLocalsrcPatch $src`
cp $localsrcpatch $dest
retval=$?
else
local CURL_OPTIONS
local CURL_TIMEOUT=$(/usr/sbin/thinclient-config --get-curl-timeout)
if [ -n "$CURL_TIMEOUT" ]; then
CURL_OPTIONS=( --connect-timeout $CURL_TIMEOUT )
else
CURL_OPTIONS=( --connect-timeout 10 )
fi
if [ "$UPDATE_REQUIRES_AUTH" = "yes" ]; then
UPDATE_USER=$(/usr/sbin/thinclient-config --get-update-user)
UPDATE_PASSWORD=$(/usr/sbin/thinclient-config --get-update-password)
CURL_OPTIONS+=( -u "$UPDATE_USER:$UPDATE_PASSWORD" )
fi
curl -g -k -f "${CURL_OPTIONS[@]}" -o $dest -# $src 2>&1
retval=$?
fi
return $retval
}
function fetchAddonDirectory ()
{
directoryUrl="${ADDONS_URL}/directory"
directoryFile=`mktemp`
if ! fetch $directoryUrl $directoryFile >/dev/null 2>&1; then
echo "Failed to download add-on directory file" >> /dev/stderr
return 1
fi
dos2unix --quiet $directoryFile
echo $directoryFile
}
function getRpmName()
{
echo $1 | sed "s/\(.*\)-\(.*\)-\(.*\)\..*\.rpm/\\1/"
}
function getRpmVersion()
{
echo $1 | sed "s/\(.*\)-\(.*\)-\(.*\)\..*\.rpm/\\2-\\3/"
}
function isAddonAvailable ()
{
name=$1
availableName=`getRpmName $name`
installedVersion=`rpm -q --queryformat "%{VERSION}-%{RELEASE}\n" $availableName 2>/dev/null`
if [ -z "$installedVersion" ]; then
echo "WARNING: Unable to determine version for '$availableName'" >/dev/stderr
return 1
fi
availableVersion=`getRpmVersion $name`
if [ -z "$availableVersion" ]; then
echo "WARNING: Unable to determine version for '$name'" >/dev/stderr
return 1
fi
if [ "$availableVersion" = "$installedVersion" ]; then
return 1
fi
return 0
}
function NeedImageUpdate()
{
LATEST_IMAGE_PATH="/latest-image.raw"
LATEST_IMAGE_INFO_PATH="${LATEST_IMAGE_PATH}.info"
infoFile="/tmp/image-info"
if ! fetch "${UPDATE_URL}/${LATEST_IMAGE_INFO_PATH}" $infoFile >/dev/null 2>&1; then
# Failed to download latest image information
return 1
fi
importFile < $infoFile
if [ -z "$IMAGE_VERSION_HASH" ]; then
# Failed to get available image version hash
return 1
elif [ -z "$IMAGE_SIZE" ]; then
# WARNING: Failed to get available image size
return 1
elif [ -z "$IMAGE_MD5SUM" ]; then
# Failed to get available image MD5 sum
return 1
fi
currentHash=`cat /read-only/.profile | grep versionHash | sed -e "s/versionHash=\(.*\)/\\1/" 2>/dev/null`
if [ "$IMAGE_VERSION_HASH" != "$currentHash" ]; then
# no need to do more check if version is not same
return 0
fi
if [ ! -f /read-write/.raw.info ] ; then
# no info file, no update
return 1
fi
currentRawHash=`cat /read-write/.raw.info | grep IMAGE_VERSION_HASH | cut -d'=' -f2 2>/dev/null`
currentRawMD5=`cat /read-write/.raw.info | grep IMAGE_MD5SUM | cut -d'=' -f2 2>/dev/null`
# info file corrupt?
[ "$currentRawHash" = "$currentHash" -a "$IMAGE_MD5SUM" != "$currentRawMD5" ]
return $?
}
function NeedAddonUpdate()
{
ADDONS_URL="${UPDATE_URL}/addons"
if ! availableAddons=$(fetchAddonDirectory); then
return 1
fi
installedAddons=`rpm -qa --queryformat "%{NAME}\n" 2>/dev/null`
tmpFile=`mktemp`
echo "$(echo "$installedAddons" | tr ' ' '\n')" > $tmpFile
updatedAddons=`grep -Ff $tmpFile $availableAddons`
rm -fr $tmpFile
if [ -z "$updatedAddons" ]; then
return 1
fi
for updatedAddon in $updatedAddons; do
if ! isAddonAvailable $updatedAddon; then
# No update for add-on '$installed' is available
continue
fi
return 0
done
return 1
}
function NeedUpdate()
{
. /etc/sysconfig/thinclient
if [ -z "$UPDATE_URL" ]; then
# No update url is specified.
return 1
fi
if [ -z "$UPDATE_MODE" ]; then
# No update mode is specified.
return 1
fi
if [ x"$FORCE_IMAGE_UPDATE" = xyes ]; then
return 0
fi
if [ "$UPDATE_MODE" = "image" ] || [ "$UPDATE_MODE" = "both" ] && NeedImageUpdate; then
return 0
fi
if [ "$UPDATE_MODE" = "addons" ] || [ "$UPDATE_MODE" = "both" ] && NeedAddonUpdate; then
return 0
fi
return 1
}