WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Extension server: dynamic contruction of info.lst  (Read 3141 times)

Offline helander

  • Full Member
  • ***
  • Posts: 183
Extension server: dynamic contruction of info.lst
« on: July 03, 2009, 04:48:32 PM »
I was planning on using the web site I rent on a commercial hosting company as an extension server.
This service allows me to produce dynamic content based on PHP, so I thought I would use that to dynamically create the content of the "info.lst" files based on what files are stored on the server.

It turns out that the only way I could have PHP generated content is if the requested file has a name that ends with .php.

This does not match the name of "info.lst", so my question is if it would somehow be possible for TC to request the "info.lst" file via another name, e.g "info.php"?

/Lars

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Extension server: dynamic contruction of info.lst
« Reply #1 on: July 03, 2009, 04:54:05 PM »
You could edit the source of appbrowser for your purpose:
ftp://ftp.ibiblio.org/pub/linux/distributions/tinycorelinux/2.x/release/src/fltk_projects/appbrowser/

AFAIK appbrowser is the only app using info.lst.
The only barriers that can stop you are the ones you create yourself.

Offline helander

  • Full Member
  • ***
  • Posts: 183
Re: Extension server: dynamic contruction of info.lst
« Reply #2 on: July 03, 2009, 05:27:38 PM »
Thanks.

I might have come across a "simpler" solution. It still needs to be tested :).

By searching thru the appbrowser binary ($ strings /usr/bin/appbrowser ) I found the following statement

    /usr/bin/tce-fetch.sh info.lst

Since tce-fetch is a fairly small shell script, I think it would be quite easy to modify this so when
fetching info.lst from my repository it would instead fetch info.php and then rename it to info.lst.

Looks promising.


Another idea I had was to have the ability to have multiple repositories available in /opt/.tcrc and have another file ponting out which repository to use. Then you could just update that file if you wanted to switch active repository.

Are other programs apart from /usr/bin/tce-fetch.sh using the content of /opt/.tcrc ?

I know that cpanel does since it allows you to change its content, but I can live with that and edit the file in other ways.

/Lars

Offline helander

  • Full Member
  • ***
  • Posts: 183
Re: Extension server: dynamic contruction of info.lst
« Reply #3 on: July 03, 2009, 07:09:25 PM »
I was able to create a working solution.

It consists of:

  • A slightly modified version of /usr/bin/tce-fetch.sh
  • Adding an optional element (called Infofile) to /opt/.tcrc

In addition I have also produced a very simple PHP script (info.php) that works well on my server.

Here are the pieces:

/opt/.tcrc
Code: [Select]
Mirror: lars-helander.name/tc/2.x
Protocol: http
Repository: tcz
Infofile: info.php

tce-fetch.sh
Code: [Select]
#!/bin/sh
#(c) Robert Shingledecker 2004-2008
#
#. /etc/init.d/tc-functions
#
if [ -n "$2" ] ; then
  sed -i "/Repository:/s/tc[e-z]/$2"/ /opt/.tcrc
else
  case $1 in
    *.tce* ) sed -i 's/tcz/tce/g' /opt/.tcrc ;;
    *.tcz* ) sed -i 's/tce/tcz/g' /opt/.tcrc ;;
  esac
fi
MIRROR=`awk '/Mirror/ {print $2}' /opt/.tcrc`
PROTOCOL=`awk '/Protocol/ {print $2}' /opt/.tcrc`
REPOSITORY=`awk '/Repository/ {print $2}' /opt/.tcrc`
[ -f "$1" ] && rm -f "$1"
if [ "$1" = "info.lst" ] ; then
  INFOFILE=`awk '/Infofile/ {print $2}' /opt/.tcrc`
  [ -z $INFOFILE ] && INFOFILE=$1
  busybox wget -q "$PROTOCOL"://"$MIRROR"/"$REPOSITORY"/"$INFOFILE"
  mv $INFOFILE info.lst
else
  busybox wget -q "$PROTOCOL"://"$MIRROR"/"$REPOSITORY"/"$1"
fi

info.php
Code: [Select]
<?php

$path 
substr($_SERVER['SCRIPT_FILENAME'], 0,
    
strrpos($_SERVER['SCRIPT_FILENAME'], '/') + 1);

$files = array();

$dir dir($path);
while (
$entry $dir->read()) {
    if ((
substr($entry, -4) == '.tce')) {
        
$files[] = $entry;
    }
    if ((
substr($entry, -5) == '.tcel')) {
        
$files[] = $entry;
    }
    if ((
substr($entry, -5) == '.tcem')) {
        
$files[] = $entry;
    }
    if ((
substr($entry, -4) == '.tcz')) {
        
$files[] = $entry;
    }
    if ((
substr($entry, -5) == '.tczl')) {
        
$files[] = $entry;
    }
    if ((
substr($entry, -5) == '.tczm')) {
        
$files[] = $entry;
    }
}
$dir->close();

sort($files);
foreach (
$files as $file) {
  
printf'%s' "\n" $file);
}
?>



/Lars

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Extension server: dynamic contruction of info.lst
« Reply #4 on: July 04, 2009, 04:17:25 AM »
Pretty nice. By renaming it to info.lst after download appbrowser can still be used unmodified, and can clean it up afterwards.

About the php script - extensions with both modules and libraries are valid, so adding tcelm,tceml,tczml,tczlm file extensions would be needed for full compliance. Currently there seems to be only one such extension, but better be safe than sorry ;)
The only barriers that can stop you are the ones you create yourself.

Offline helander

  • Full Member
  • ***
  • Posts: 183
Re: Extension server: dynamic contruction of info.lst
« Reply #5 on: July 04, 2009, 05:50:42 AM »
Pretty nice. By renaming it to info.lst after download appbrowser can still be used unmodified, and can clean it up afterwards.

About the php script - extensions with both modules and libraries are valid, so adding tcelm,tceml,tczml,tczlm file extensions would be needed for full compliance. Currently there seems to be only one such extension, but better be safe than sorry ;)

Thanks for pointing out the need to support the "combined" extensions.

Next little project is likely a tool that allows me to easily switch between different mirrors.

/Lars

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: Extension server: dynamic contruction of info.lst
« Reply #6 on: July 04, 2009, 10:40:17 AM »
Sorry, I don't get it. Serving static files is always faster than having the server constantly generate them and then serve them.
10+ Years Contributing to Linux Open Source Projects.