#!/bin/bash # ************************************************************ # AltEPG Project Source Code Version Control # $FileID: git::build/installTivo.bash $ # $Revision: altepg1.0c root 2011-09-17 23:39:32 +0100 Finalising altepg1.0c $ # Description: AltEPG Installer # ************************************************************ # install script expects to find the software to be installed in the current directory # mode=$1 if [ -n "$mode" ]; then if [ "$mode" = "build" ]; then GIT_ROOT="../.." INSTALL_ROOT="." else echo "Unrecognised mode : $mode" exit 1 fi fi SYSTEM=$(uname -r) SYSNAME=$(uname -n) if [ -z "${SYSTEM##*TiVo*}" ]; then SYS=TIVO LOGFILE="/var/log/install.log" MOUNT="mount" TIVO_ROOT="" HACKDIR=/var/hack elif [ "$SYSNAME" = "Knoppix" ]; then SYS=BUILD LOGFILE="install.log" MOUNT=":" TIVO_ROOT="/mnt/tivoRoot" HACKDIR=$TIVO_ROOT/hack mkdir -p "$TIVO_ROOT" else SYS=OTHER LOGFILE="install.log" MOUNT=":" TIVO_ROOT="/tmp/tivoRoot" HACKDIR=$TIVO_ROOT/hack mkdir -p "$TIVO_ROOT" fi putlog() { if [ -n "${1##DEBUG:*}" -o "$DEBUG" = 1 ]; then echo "$(date +%Y-%m-%d:%H:%M:%S): $1" >>"$LOGFILE" echo "$(date +%Y-%m-%d:%H:%M:%S): $1" fi } installFiles() { if [ "$mode" = "build" ]; then while read line; do operation="${line%% *}" if [ "$operation" != "D" ]; then file="${line##* }" source="$GIT_ROOT/$file" target="$INSTALL_ROOT/$file" putlog "Copying '$source' to '$target'" basedir=$(dirname "$target") mkdir -p "$basedir" cp -v "$source" "$target" fi done return fi ecount=0 $MOUNT -o remount,rw / displaceDir="$TIVO_ROOT/var/tmp/displacedFiles" mkdir -p "$displaceDir" while read line; do operation="${line%% *}" file="${line##* }" if [ -z "${line##* *}" ]; then putlog "DEBUG: LINE=$line, op=$operation file=$file" fi partition="${file%%/*}" if [ "$partition" = "root" ]; then pathname="$TIVO_ROOT/${file#*/}" else pathname="$TIVO_ROOT/$partition/${file#*/}" fi if [ "$operation" = "A" -o "$operation" = "M" ]; then if [ "$operation" = "A" ]; then putlog "INFO: Installing new file $file to partition $partition as $pathname" else putlog "INFO: Installing new version of file $file to partition $partition as $pathname" fi if [ ! -f "$file" ]; then putlog "ERROR: $file not present in installation kit" error=1 else if [ -f "$pathname" ]; then if [ "$operation" = "A" ]; then putlog "WARNING: $pathname already exists, moving to $displaceDir" else putlog "INFO: $pathname found, moving old version to $displaceDir" fi cp -p "$pathname" "$displaceDir" rm -f "$pathname" elif [ "$operation" = "M" ]; then putlog "WARNING: $pathname not found in existing system" fi dir=${pathname%/*} putlog "DEBUG: target dir=$dir; copying $file to $pathname" if [ ! -d "$dir" ]; then mkdir -p "$dir" fi cp -p "$file" "$pathname" if [ -f "$pathname" ]; then putlog "INFO: $pathname installed" else putlog "ERROR: $pathname not installed" error=1 fi fi elif [ "$operation" = "D" ]; then putlog "INFO: Deleting $pathname" if [ -f "$pathname" ]; then putlog "INFO: $pathname found, moving old version to $displaceDir" cp -p "$pathname" "$displaceDir" rm -f "$pathname" if [ ! -f "$pathname" ]; then putlog "INFO: $pathname deleted" else putlog "ERROR: $pathname deletion failed" error=1 fi else putlog "WARNING: $pathname not found" fi elif [ "$operation" = "E" ]; then if [ "$SYS" = "TIVO" ]; then putlog "INFO: Executing $file" chmod 755 ./$file ./$file if [ $? != 0 ]; then putlog "ERROR: Failed to execute $file (error=$?)" error=1 fi else ecount=$[ecount+1] eprefix=$[ecount+100] base="$[ecount+100]_$(basename '$file')" phasenum=2 pathname="$TIVO_ROOT/var/persist/$base.phase$phasenum" putlog "INFO: Copying $file to $pathname for execution on tivo boot" cp -p "$file" "$pathname" if [ -f "$pathname" ]; then putlog "INFO: $pathname installed" else putlog "ERROR: $pathname not installed" error=1 fi fi elif [ "$operation" = "H" ]; then if [ ! -f "$file" ]; then putlog "ERROR: $file not present in installation kit" error=1 elif [ -z "${file##*.tgz}" ]; then putlog "INFO: Installing package $file to $HACKDIR" gzip -df "$file" tarfile=${file%%.tgz}.tar here=$PWD cd "$HACKDIR" if [ "$SYS" = "BUILD" ]; then tar xvf "$here/$tarfile" else cpio --unconditional --format=tar -i <"$here/$tarfile" 2>/dev/null fi cd "$here" else putlog "ERROR: Don't know how to install $file (file type isn't .tgz)" fi elif [ -z "${operation##\#*}" ]; then : # ignore comment lines else putlog "ERROR: Unrecognised operation '$operation', ignored" error=1 fi done $MOUNT -o remount,ro / } error=0 installFiles