2010-11-30

Debian Cgit nginx + simpleCGI

aptitude install nginx gitosis git-core
get cgit and build:http://hjemli.net/git/cgit/
cpan FCGI, FCGI::ProcManager,Socket


setup cgit
vi /etc/cgitrc
virtual-root=/
cache-size=1000
enable-index-links=1
enable-log-filecount=1
enable-log-linecount=1
max-stats=quarter
root-title=tknv git repositories
root-desc=tracking the tknv development
root-readme=/var/www/htdocs/about.html
snapshots=tar.gz tar.bz2 zip
mimetype.gif=image/gif
mimetype.html=text/html
mimetype.jpg=image/jpeg
mimetype.jpeg=image/jpeg
mimetype.pdf=application/pdf
mimetype.png=image/png
mimetype.svg=image/svg+xml
repo.url=SuperEngine
repo.path=/srv/gitosis/repositories/SuperEngine.git
repo.desc=SuperEngine Control SU
repo.owner=tknv@foo.wiz
view raw cgitrc hosted with ❤ by GitHub



setup gitosis


refs1:http://gebi.supersized.org/archives/4-Installing-gitosis-on-debian.html
refs:2:http://dora.bk.tsukuba.ac.jp/~takeuchi/index.php?%A5%D7%A5%ED%A5%B0%A5%E9%A5%DF%A5%F3%A5%B0%2Fgitosis%20%A4%CB%A4%E8%A4%EB%20git%20%A5%B5%A1%BC%A5%D0%A1%BC%A4%CE%B4%C9%CD%FD
refs3:http://phichyudebow.blogspot.com/2010/07/cgit-on-debian-apache2.html

setup nginx
vi /etc/nginx/site-available/default
server {
listen 80;
# Serve static files
location ~* ^.+\.(css|png|ico)$ {
root /var/www/htdocs;
expires 30d;
}
if (!-f $request_filename) {
rewrite ^/([^?/]+/[^?]*)?(?:\?(.*))?$ /cgit.cgi?url=$1&$2 last;
}
location / {
gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped
fastcgi_pass unix:/var/run/nginx/cgiwrap-dispatch.sock;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
}
access_log /var/log/nginx/cgit/transfer/access_log combined;
error_log /var/log/nginx/cgit/error/error_log warn;
}



setup SimpleCGI:refs:http://wiki.nginx.org/SimpleCGI
vi /usr/local/bin/cgiwrap-fcgi.pl
#!perl
use FCGI;
use Socket;
use FCGI::ProcManager;
sub shutdown { FCGI::CloseSocket($socket); exit; }
sub restart { FCGI::CloseSocket($socket); &main; }
use sigtrap 'handler', \&shutdown, 'normal-signals';
use sigtrap 'handler', \&restart, 'HUP';
require 'syscall.ph';
use POSIX qw(setsid);
END() { }
BEGIN() { }
{
no warnings;
*CORE::GLOBAL::exit = sub { die "fakeexit\nrc=" . shift() . "\n"; };
};
eval q{exit};
if ($@) {
exit unless $@ =~ /^fakeexit/;
}
&main;
sub daemonize() {
chdir '/' or die "Can't chdir to /: $!";
defined( my $pid = fork ) or die "Can't fork: $!";
exit if $pid;
setsid() or die "Can't start a new session: $!";
umask 0;
}
sub main {
$proc_manager = FCGI::ProcManager->new( {n_processes => 5} );
$socket = FCGI::OpenSocket( "/var/run/nginx/cgiwrap-dispatch.sock", 10 )
; #use UNIX sockets - user running this script must have w access to the 'nginx' folder!!
$request =
FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket,
&FCGI::FAIL_ACCEPT_ON_INTR );
$proc_manager->pm_manage();
if ($request) { request_loop() }
FCGI::CloseSocket($socket);
}
sub request_loop {
while ( $request->Accept() >= 0 ) {
$proc_manager->pm_pre_dispatch();
#processing any STDIN input from WebServer (for CGI-POST actions)
$stdin_passthrough = '';
{ no warnings; $req_len = 0 + $req_params{'CONTENT_LENGTH'}; };
if ( ( $req_params{'REQUEST_METHOD'} eq 'POST' ) && ( $req_len != 0 ) ) {
my $bytes_read = 0;
while ( $bytes_read < $req_len ) {
my $data = '';
my $bytes = read( STDIN, $data, ( $req_len - $bytes_read ) );
last if ( $bytes == 0 || !defined($bytes) );
$stdin_passthrough .= $data;
$bytes_read += $bytes;
}
}
#running the cgi app
if (
( -x $req_params{SCRIPT_FILENAME} ) && #can I execute this?
( -s $req_params{SCRIPT_FILENAME} ) && #Is this file empty?
( -r $req_params{SCRIPT_FILENAME} ) #can I read this file?
) {
pipe( CHILD_RD, PARENT_WR );
pipe( PARENT_ERR, CHILD_ERR );
my $pid = open( CHILD_O, "-|" );
unless ( defined($pid) ) {
print("Content-type: text/plain\r\n\r\n");
print "Error: CGI app returned no output - Executing $req_params{SCRIPT_FILENAME} failed !\n";
next;
}
$oldfh = select(PARENT_ERR);
$| = 1;
select(CHILD_O);
$| = 1;
select($oldfh);
if ( $pid > 0 ) {
close(CHILD_RD);
close(CHILD_ERR);
print PARENT_WR $stdin_passthrough;
close(PARENT_WR);
$rin = $rout = $ein = $eout = '';
vec( $rin, fileno(CHILD_O), 1 ) = 1;
vec( $rin, fileno(PARENT_ERR), 1 ) = 1;
$ein = $rin;
$nfound = 0;
while ( $nfound = select( $rout = $rin, undef, $ein = $eout, 10 ) ) {
die "$!" unless $nfound != -1;
$r1 = vec( $rout, fileno(PARENT_ERR), 1 ) == 1;
$r2 = vec( $rout, fileno(CHILD_O), 1 ) == 1;
$e1 = vec( $eout, fileno(PARENT_ERR), 1 ) == 1;
$e2 = vec( $eout, fileno(CHILD_O), 1 ) == 1;
if ($r1) {
while ( $bytes = read( PARENT_ERR, $errbytes, 4096 ) ) {
print STDERR $errbytes;
}
if ($!) {
$err = $!;
die $!;
vec( $rin, fileno(PARENT_ERR), 1 ) = 0
unless ( $err == EINTR or $err == EAGAIN );
}
}
if ($r2) {
while ( $bytes = read( CHILD_O, $s, 4096 ) ) {
print $s;
}
if ( !defined($bytes) ) {
$err = $!;
die $!;
vec( $rin, fileno(CHILD_O), 1 ) = 0
unless ( $err == EINTR or $err == EAGAIN );
}
}
last if ( $e1 || $e2 );
}
close CHILD_RD;
close PARENT_ERR;
waitpid( $pid, 0 );
} else {
foreach $key ( keys %req_params ) {
$ENV{$key} = $req_params{$key};
}
# cd to the script's local directory
if ( $req_params{SCRIPT_FILENAME} =~ /^(.*)\/[^\/] +$/ ) {
chdir $1;
}
close(PARENT_WR);
#close(PARENT_ERR);
close(STDIN);
close(STDERR);
#fcntl(CHILD_RD, F_DUPFD, 0);
syscall( &SYS_dup2, fileno(CHILD_RD), 0 );
syscall( &SYS_dup2, fileno(CHILD_ERR), 2 );
#open(STDIN, "<&CHILD_RD");
exec( $req_params{SCRIPT_FILENAME} );
die("exec failed");
}
} else {
print("Content-type: text/plain\r\n\r\n");
print "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process.\n";
}
}
}
view raw cgiwrap-fcgi.pl hosted with ❤ by GitHub



.Start
perl /usr/local/bin/cgiwrap-fcgi.pl
bind/listen error: -> mkdir /var/run/nginx/
chmod 0666 /var/run/nginx/cgiwrap-dispatch.sock
/etc/init.d/nginx restart

2010-11-19

Bravo external display

Andoird Bravo external display






I build kernel cm-kernel 2.6.35.4 with USB host,Displaylink driver and aufs.
then my aim is use directvnc on extend monitor(usb-hosted displaylink dev).
But can not open /dev/tty0.
Does anyone know how fix it ?


by theway mplayer can play mp4 video on extend monitor from bravo device.

Forked kernel(ccyrowski/cm-kernel->defer/cm-kernel->teamdesire/cm-kernel)
then -> tknv / cm-kernel.
and modify.
+ USB host patch from sven.killig:http://sven.killig.de/android/N1/2.2/usb_host/
+ aufs from http://aufs.sourceforge.net/
+ udlfb from http://git.plugable.com/gitphp/index.php?p=udlfb&a=summary
+ Native and Chroot Debian from http://www.telesphoreo.org/pipermail/g1-hackers/2008-November/000032.html

This ROM Based on DeFroST6.0C.
How to
1.download:[ROM]:http://firestorage.jp/download/e05648f28bcd0a7582c102b3c7792b050d621dbf
2.download:native Debian set:http://firestorage.jp/download/2ba5aaebf241f4968592fbc83ffbb2020dbd83af
uncompress zip and put all in SDcard(same dir hierarchie)
3.put all download file to SDcard
4.Flash ROM to 1 ROM image(pls. backup your origin ROM)
5.Connect your USB devices,Should Powered USB hub,Displaylink USB monitor,USB keyboard(for easy input) and what ever you like.
6.Boot your bravo
7.Need gscript.apk or input your self for loading modules.
7a.from gscript:
  • load 01-ld-usb-cores -- wait loading modules and init device.
  • load 02-ld-usb-hid -- wait loading modules and init device until keyboard work etc.
  • load 03-ld-udlfb -- wait loading modules and init monitor,when active monitor show green panel.
7b.from terminal emu:
be root
  • # sh /sdcard/gscript/01-ld-usb-cores.sh.sh
  • # sh /sdcard/gscript/02-ld-usb-hid.sh.sh
  • # sh /sdcard/gscript/03-ld-udlfb.sh.sh
8.Set Debian system from terminal emu
be root
# sh /sdcard/set-deb.sh
9.Set Framebuffer env from terminal emu
Maybe already Debian system ovelay on Android linux.
# export FRAMEBUFFER=/dev/graphics/fb1
# mplayer
Then should can see video on external display.

Now I am going to fork kernel, I need help fixing can not open /dev/tty0 for running directvnc on external monitor from Android.

In the ROM there is dvd driver etc. I did not test it,Because I do not have it.
WARNING: No Guarantee,No responsibility.

P.S.
apt-get is can not use at Native Debian on Android.
If you want use apt-get, please below way.
Run debian in chroot, use /sdcard/chroot-set-deb.sh at 8 of "HOW to" sequence.
# sh /sdcard/chroot-set-deb.sh
from here in chroot.
# mount -t devpts devpts /dev/pts
# mount -t proc proc /proc
# mount -t sysfs sysfs /sys

BCM4321 on Latitude D430

At kernel 3 find wireless hardware lspci | grep -i wireless  check using current kernel module with PCI bus address lspci -vv -s 0c:...