#!/bin/bash # ************************************************************ # AltEPG Project Source Code Version Control # $FileID: git::root/hack/bin/tivo_install.bash $ # $Revision: altepg1.0c root 2011-09-17 23:39:32 +0100 Finalising altepg1.0c $ # Description: tivo_install : generic installer. # ************************************************************ # when run with no command line arguments, this installer will look for installation kits in /var/packages, and will unzip and install them. # when run with a command line argument, the installer will download the specified package and then install it. # if this script's filename is of the form: tivo_install_(packagename).bash then it behaves as if (packagename) were a command line argument DEBUG=0 if [ "$1" = -d ]; then DEBUG=1 shift fi export DEBUG SYSTEM=$(uname -r) SYSNAME=$(uname -n) if [ -z "${SYSTEM##*TiVo*}" ]; then SYS=TIVO MOUNT="mount" TIVO_ROOT="" ALTEPG_SERVER="194.1.151.205" elif [ "$SYSNAME" = "Knoppix" ]; then SYS=BUILD MOUNT=":" TIVO_ROOT="/mnt/tivoRoot" mkdir -p "$TIVO_ROOT" mkdir -p "$TIVO_ROOT/var/log" ALTEPG_SERVER="icon" ALTEPG_SERVER="194.1.151.205" else SYS=OTHER MOUNT=":" TIVO_ROOT="/tmp/tivoRoot" mkdir -p "$TIVO_ROOT" mkdir -p "$TIVO_ROOT/var/log" ALTEPG_SERVER="icon" ALTEPG_SERVER="194.1.151.205" fi LOGFILE="$TIVO_ROOT/var/log/install.log" 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 } # pre-requisites : must have updated version of libc.so, and $LD_LIBRARY_PATH defined do_prerequisites() { libdir="$TIVO_ROOT/var/hack/lib" if [ -h "$TIVO_ROOT/var/hack" ]; then # if symlink, then guess dereference libdir="$TIVO_ROOT/hack/lib" fi if [ -z "$LD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH=$libdir fi if [ -n "${LD_LIBRARY_PATH##*$libdir*}" ]; then LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$libdir" fi export LD_LIBRARY_PATH if [ ! -f "$libdir/libc.so" ]; then mkdir -p $libdir if [ ! -f "$PACKAGE_DIR/libc.so.gz" ]; then if [ "$SYS" = "TIVO" ]; then /tvbin/http_get -U "http://$ALTEPG_SERVER:80/tivo-static/software/prerequisites/libc.so.gz" -D "$PACKAGE_DIR" -T 0 -C 0 else echo wget -q "http://$ALTEPG_SERVER/tivo-static/software/prerequisites/libc.so.gz" -O "$PACKAGE_DIR/libc.so.gz" wget -q "http://$ALTEPG_SERVER/tivo-static/software/prerequisites/libc.so.gz" -O "$PACKAGE_DIR/libc.so.gz" fi if [ $? != 0 ]; then rm -f "$PACKAGE_DIR/libc.so.gz" fi fi if [ -f "$PACKAGE_DIR/libc.so.gz" ]; then gzip -df "$PACKAGE_DIR/libc.so.gz" fi if [ -f "$PACKAGE_DIR/libc.so" ]; then cp -p "$PACKAGE_DIR/libc.so" $libdir fi fi if [ ! -f "$libdir/libc.so" ]; then putlog "ERROR: prerequisites not satisified - can't install" exit 1 fi putlog "INFO: prerequisites complete" } INSTALL_DIR=$TIVO_ROOT/var/install PACKAGE_DIR=$TIVO_ROOT/var/packages mkdir -p $PACKAGE_DIR mkdir -p $INSTALL_DIR mkdir -p $TIVO_ROOT/var/tmp cd $TIVO_ROOT/var/tmp do_prerequisites package_to_install=$1 if [ -z "${0##*tivo_install_*.bash}" ]; then front=${0%%.bash} package_to_install=${front##*tivo_install_} fi if [ -n "$package_to_install" ]; then if [ "$SYS" = "TIVO" ]; then /tvbin/http_get -U "http://$ALTEPG_SERVER:80/tivo-static/software/available_packages" -D "$TIVO_ROOT/var/tmp" -T 0 -C 0 else wget -q "http://$ALTEPG_SERVER/tivo-static/software/available_packages" -O available_packages fi if [ $? != 0 -o ! -f "available_packages" ]; then putlog "ERROR: unable to retrieve available packages list from server" exit 1 fi packageFound=$(grep "^$package_to_install " available_packages) if [ -z "$packageFound" ]; then echo "Package '$package_to_install' not found - choose from:" cat available_packages exit 1 fi cd $PACKAGE_DIR packageFile="${package_to_install}_install.gz" if [ "$SYS" = "TIVO" ]; then /tvbin/http_get -U "http://$ALTEPG_SERVER:80/tivo-static/software/packages/$packageFile" -D "$PACKAGE_DIR" -T 0 -C 0 else wget "http://$ALTEPG_SERVER/tivo-static/software/packages/$packageFile" -O $packageFile fi if [ $? != 0 -o ! -f "$packageFile" ]; then putlog "ERROR: unable to retreive $packageFile from server" exit 1 fi putlog "INFO: $packageFile downloaded from server $ALTEPG_SERVER" fi putlog "INFO: Starting Install" error=0 installed=0 cd $PACKAGE_DIR putlog "INFO: Installing packages from $PACKAGE_DIR" for file in *; do if [ -z "${file##*_install.gz}" ]; then echo "testing $file" if [ -z "$package_to_install" -o "$file" = "$packageFile" ]; then gzip -df "$file" file=${file%%.gz} putlog "INFO: Installing $file" cd $INSTALL_DIR rm -fR $INSTALL_DIR/* if [ "$SYS" = "BUILD" ]; then tar xvf "$PACKAGE_DIR/$file" # tar xvf "$PACKAGE_DIR/$file" >/dev/null 2>/dev/null else cpio --format=tar -i <"$PACKAGE_DIR/$file" >/dev/null 2>/dev/null fi if [ -d "$file" ]; then cd "$file" if [ -f "install.bash" ]; then ./install.bash installed=1 else putlog "ERROR: package $file has no installation script" error=1 fi fi cd $PACKAGE_DIR fi fi done if [ $installed = 0 ]; then putlog "ERROR: No package(s) installed" exit 1 else putlog "INFO: Install Complete (error=$error)" exit $error fi