Skip to content

Instantly share code, notes, and snippets.

@datfaf
Forked from FurryHead/perlab.pl
Created August 17, 2011 17:43
Show Gist options
  • Save datfaf/1152112 to your computer and use it in GitHub Desktop.
Save datfaf/1152112 to your computer and use it in GitHub Desktop.
TinyCore Linux appbrowser written in perl, can be run from OSs other than TinyCore.
#!/usr/bin/perl -w
use warnings;
use strict;
use Term::ReadKey;
my $tce_mirror = "http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/";
my $tce_dir = `cat /opt/.tce_dir`;
$tce_dir = "./tce" if ($tce_dir eq "");
chomp $tce_dir;
mkdir $tce_dir if (! -d $tce_dir);
&cls;
sub cls {
system("clear");
}
sub displayFiles {
my ($ext) = @_;
chomp $ext;
print "Loading file list...";
system("wget -q ${tce_mirror}/3.x/tcz/${ext}.list -O - | less");
}
sub displayDeps {
my ($ext) = @_;
chomp $ext;
print "Loading dep list...";
system("wget -q ${tce_mirror}/3.x/tcz/${ext}.dep -O - | less");
}
sub displayInfo {
my ($ext) = @_;
chomp $ext;
print "Loading info...";
system("wget -q ${tce_mirror}/3.x/tcz/${ext}.info -O - | less");
}
sub search {
my ($query) = @_;
chomp $query;
my $fname = "tcz3x.cgi?$query";
open (my $f, "-|", "wget -q http://www.tinycorelinux.com/cgi-bin/$fname -O -");
my @lines = <$f>;
close $f;
my @results = grep(!/^ *\<.+\>/, @lines);
for (@results) { s/\.info//gi; }
my $output = "Results: (make note of the number) \n\n";
foreach my $i (0..$#results) {
$output .= " ${i}. $results[$i]";
}
open (my $o, "|-", "less");
print $o "$output";
close $o;
print "\n\nEnter selection (0 - ".$#results.") or (q)uit: ";
my $response = <STDIN>;
chomp $response;
if ($response eq "q") {
return;
}
while ($response < 0 or $response > $#results) {
print "\nInvalid selection. Enter selection (0 - ".$#results.") or (q)uit: ";
$response = <STDIN>;
chomp $response;
if ($response eq "q") {
return;
}
}
my $result = $results[$response];
chomp $result;
return $result;
}
sub provides {
my ($query) = @_;
chomp $query;
my $fname = "whatprovides3x.cgi?$query";
open (my $f, "-|", "wget -q http://www.tinycorelinux.com/cgi-bin/$fname -O -");
my @lines = <$f>;
close $f;
my @results = grep(!/^ *\<.+\>/, @lines);
for (@results) { s/\.list//gi; chomp; }
my $output = "The following provides $query: (make note of the number) \n\n";
foreach my $i (0..$#results) {
$output .= " ${i}. $results[$i]\n";
}
open (my $o, "|-", "less");
print $o "$output";
close $o;
print "\n\nEnter selection (0 - ".$#results.") or (q)uit: ";
my $response = <STDIN>;
chomp $response;
if ($response eq "q") {
return;
}
while ($response < 0 or $response > $#results) {
print "\nInvalid selection. Enter selection (0 - ".$#results.") or (q)uit: ";
$response = <STDIN>;
chomp $response;
if ($response eq "q") {
return;
}
}
my $result = $results[$response];
chomp $result;
return $result;
}
sub get_file {
my ($f) = @_;
chomp $f;
if (! -d $tce_dir."/optional") {
mkdir $tce_dir."/optional";
}
system("wget -nv ${tce_mirror}/3.x/tcz/$f -O ${tce_dir}/optional/$f");
}
sub get_package {
my ($pkg) = @_;
chomp $pkg;
get_file($pkg);
get_file($pkg.".md5.txt");
get_file($pkg.".dep");
}
sub onDemand {
my ($pkg) = @_;
chomp $pkg;
get_package($pkg);
if (! -d $tce_dir."/ondemand") {
mkdir $tce_dir."/ondemand";
}
(my $on = $pkg) =~ s/\.tcz//i;
open (my $f, ">", $tce_dir."/ondemand/".$on);
print $f <<EOF
#!/bin/sh
SAVE_ARGS=\$*
2>/dev/null read TCEDIR < /opt/.tce_dir || exit 1
if [ ! -e /usr/local/tce.installed/$on ]; then
tce-load -is \$TCEDIR/optional/$pkg
fi
EOF
;
close $f;
chmod "0755", "${tce_dir}/ondemand/$on";
}
sub onBoot {
my ($pkg) = @_;
chomp $pkg;
get_package($pkg);
open (my $f, ">>", $tce_dir."/onboot.lst");
print $f "$pkg\n";
close $f;
}
while (1) {
print "S)earch, P)rovides, or Q)uit: ";
ReadMode 4;
my $r = ReadKey(0);
ReadMode 0;
$r =~ s/[A-Z]/[a-z]/g;
if ($r eq "s") {
cls;
print "Enter search term, e.g. browser: ";
my $query = <STDIN>;
chomp $query;
my $return = search $query;
if (defined $return) {
displayInfo $return;
SSTART:
print "I)nstall O)nDemand D)epends F)iles or C)ancel: ";
ReadMode 4;
my $k = ReadKey(0);
ReadMode 0;
$k =~ s/[A-Z]/[a-z]/g;
if ($k eq "i") {
onBoot $return;
} elsif ($k eq "o") {
onDemand $return;
} elsif ($k eq "d") {
displayDeps $return;
goto SSTART;
} elsif ($k eq "f") {
displayFiles $return;
goto SSTART;
} elsif ($k eq "c") {
print "\n";
next;
} else {
print "\nInvalid option.\n";
goto SSTART;
}
}
} elsif ($r eq "p") {
cls;
print "Enter search term, e.g. iwconfig: ";
my $query = <STDIN>;
chomp $query;
my $return = provides $query;
if (defined $return) {
displayInfo $return;
PSTART:
print "I)nstall O)nDemand D)epends F)iles or C)ancel: ";
ReadMode 4;
my $k = ReadKey(0);
ReadMode 0;
$k =~ s/[A-Z]/[a-z]/g;
if ($k eq "i") {
onBoot $return;
} elsif ($k eq "o") {
onDemand $return;
} elsif ($k eq "d") {
displayDeps $return;
goto PSTART;
} elsif ($k eq "f") {
displayFiles $return;
goto PSTART;
} elsif ($k eq "c") {
print "\n";
next;
} else {
print "\nInvalid option.\n";
goto SSTART;
}
}
} elsif ($r eq "q") {
print "\n";
exit;
} else {
print "Invalid option.\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment