WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: tce-find enclosed  (Read 1532 times)

Offline CentralWare

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 776
tce-find enclosed
« on: September 13, 2018, 12:49:43 PM »

Good morning everyone!
I've been working on piCore for the past week (head still banging against the wall!) so I decided to take a look at the 10beta to see if the problems were corrected in a newer firmware and not thinking, I was "shocked" (lol) to see extensions missing from the 10.x repo so it forced me to throw together a script to help tce-load out a bit.
Code: [Select]
#!/bin/sh
. /etc/init.d/tc-functions
clear


#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
#  This script is an EXTENSION to the existing tce-load functionality. This   #
#  app basically gives us the ability to back-port extensions which are not   #
#  yet available in the BETA repository.  The following settings allow us to  #
#  control how far back in history we want to allow this script to access as  #
#  well as whether or not we want to utilize the current beta repo as well.   #
#  This script ASSUMES tce-load [-wi] as its intended arguments               #
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
min_repo=5                      # Go back UP TO 5.x (incrementing NEW->OLD)   #
max_repo=                       # Leave empty to use the CURRENT version      #
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#


version=$(version | awk -F. '{print $1}');  KERNEL=$(uname -r)
if [ "${max_repo}" == "" ]; then max_repo=$version; fi
KHUNT=6; if [ ! "$(uname -r | grep v7)" == "" ]; then KHUNT=7; fi


TCE_DIR=/etc/sysconfig/tcedir; if [ ! -d $TCE_DIR ]; then echo "${RED}ERROR!${WHITE} Cannot locate TCEDIR${NORMAL}"; exit 1; fi
TCE_OPT=${TCE_DIR}/optional; if [ ! -d $TCE_OPT ]; then echo "${RED}ERROR!${WHITE} Cannot locate TCEDIR/optional${NORMAL}"; exit 1; fi
TMP=/tmp/tce-find; sudo rm $TMP -fR >/dev/null 2>&1
TMP_OPT=/tmp/tce-save; sudo rm $TMP_OPT -fR; mkdir -p $TMP_OPT >/dev/null 2>&1


HOST="$(cat /opt/tcemirror)"
#HOST="http://tinycorelinux.net/"
if [ ! "${HOST: -1}" == "/" ]; then HOST="${HOST}/"; fi
REPO="${HOST}-VERS-.x/armv${KHUNT}/tcz"


msg()
{
    mlen=$1; mmsg="${2}                                                                                      "
    echo "${mmsg:0:$mlen}"
}


updates=0
dl_dep()
{
    huntfor=$1
    huntfor=${huntfor//.tcz/}
    huntfor=${huntfor/-KERNEL/-$KERNEL}


    echo -n "Downloading ${YELLOW}$(msg 30 $huntfor)${NORMAL}"


    EXISTS=0
    if [ -f $TCE_OPT/${huntfor}.tcz.md5.txt ]; then EXISTS=1; fi
    if [ -f $TMP_OPT/${huntfor}.tcz.md5.txt ]; then EXISTS=1; fi


    if [ $EXISTS -ge 1 ]; then
        echo " -> ${YELLOW}already exists${NORMAL}"
    else
        mkdir -p $TMP; cd $TMP
        for CURCNT in $(seq $max_repo -1 $min_repo)
        do
            RP=${REPO//-VERS-/${CURCNT}}


            wget -q -O $TMP/testit $RP/${huntfor}.tcz.md5.txt >/dev/null 2>&1


            if [ -f $TMP/testit ]; then
                echo -n " -> ${WHITE}From Repo ${MAGENTA}${CURCNT}.x${NORMAL} "
                mv $TMP/testit $TMP_OPT/${huntfor}.tcz.md5.txt
updates=1
                wget -q -O $TMP_OPT/${huntfor}.tcz.info $RP/${huntfor}.tcz.info #>/dev/null 2>&1
                wget -q -O $TMP_OPT/${huntfor}.tcz.dep $RP/${huntfor}.tcz.dep >/dev/null 2>&1
                wget -q -O $TMP_OPT/${huntfor}.tcz $RP/${huntfor}.tcz >/dev/null 2>&1
                if [ ! -f $TMP_OPT/${huntfor}.tcz.dep ]; then touch $TMP_OPT/${huntfor}.tcz.dep; fi
                if [ ! -f $TMP_OPT/${huntfor}.tcz.info ]; then
                    echo "${RED}FAILED${NORMAL}"; exit 1
                else
                    echo "${GREEN}OK${NORMAL}"
                fi
                if [ -f $TMP_OPT/${huntfor}.tcz.dep ]; then
                    while read file
                    do
                        dl_dep $file
                    done < $TMP_OPT/${huntfor}.tcz.dep
                    break
                fi
            fi
        done
    fi
}


CMDLINE=$@


if [ "$CMDLINE" == "" ]; then
    echo "${WHITE}tce-find [${YELLOW}extension_name(s)${WHITE}] ${NORMAL}"
    echo "  Allows you to utilize former repository versions in a way tce-load does"
    echo "  for the current version. This script is only set up for download/install,"
    echo "  not on-demand or other tce-load-like options."
    exit 1
fi


onboot="$TCE_DIR/onboot.lst"
for file in $CMDLINE
do
    file=$(echo $file)               # Remove padding spaces, if any
    file=${file/.tcz/}               # Remove trailing .tcz extension if it was supplied
    file=${file/-KERNEL/-$KERNEL}    # Replace "KERNEL" string with the current kernel ID
    echo "${BLUE}Processing ${CYAN}$file${NORMAL}"
    if [ -f $TCE_OPT/${file}.tcz ]; then
        echo "${YELLOW}${huntfor} ${WHITE}already exists${NORMAL}"
    else
        dl_dep $file
    fi


done


## If we've made it this far, everything was successful! ##
if [ $updates -ge 1 ]; then
echo
echo "${BLUE}UPDATING SYSTEM.  PLEASE WAIT...${NORMAL}"
sudo mv $TMP_OPT/* $TCE_OPT/ >/dev/null 2>&1


for file in $CMDLINE
do
    file=$(echo $file)               # Remove padding spaces, if any
    file=${file/.tcz/}               # Remove trailing .tcz extension if it was supplied
    file=${file/-KERNEL/-$KERNEL}    # Replace "KERNEL" string with the current kernel ID


    test=$(cat $onboot | grep "${file}.tcz")
    if [ "${test}" == "" ]; then echo "${file}.tcz" >> $onboot; fi
    su -c "tce-load -i $file >/dev/null 2>&1" tc
done
fi
Mind you, it doesn't do miracles, but it allows you to find an extension in history (older repo versions) within the same armv6/armv7 platform and if all files and dependencies are located, install them accordingly.
Example:
tce-find php7
Finds the extension PHP7 in repo v9.x, many of its dependencies in v10.x and so on.  Since all of them are found, it installs them into the system as if it were done by tce-load -wi php7
« Last Edit: September 13, 2018, 01:05:43 PM by centralware »