aktualisiert
This commit is contained in:
862
SyncPOD
862
SyncPOD
@@ -1,862 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
# (c) 2002 Armin Obersteiner <armin@xos.net>
|
||||
# License: GPL v2
|
||||
|
||||
use MP3::Info;
|
||||
use Unicode::String qw( latin1 utf16 );
|
||||
use Shell qw ( find gzip );
|
||||
use Getopt::Std;
|
||||
use File::Copy;
|
||||
use Filesys::DiskFree;
|
||||
|
||||
use Data::Dumper qw (Dumper);
|
||||
|
||||
use strict;
|
||||
|
||||
my $version="0.68";
|
||||
|
||||
#
|
||||
# options & config
|
||||
#
|
||||
|
||||
my %opt;
|
||||
getopts("fcnh",\%opt);
|
||||
|
||||
if($opt{h}) {
|
||||
print <<"EOF";
|
||||
$0 [-c] [-f] [Search Pattern 1] [Search Pattern 2] ...
|
||||
|
||||
-c create: create directory structure on plain ipod before syncing
|
||||
(default: you get a warning if there is no ipod structure)
|
||||
|
||||
-f force: rename ipod and use it with $0 before syncing
|
||||
(default: an unknown ipod stays untouched)
|
||||
|
||||
-n name check: checks mp3 names for possible illegal characters
|
||||
|
||||
Search Patterns: for each search pattern a playlist is created
|
||||
(case insensitive)
|
||||
EOF
|
||||
exit;
|
||||
}
|
||||
|
||||
my $buffer = 5*1024*1024; # leave some MB free for iTunesDB
|
||||
|
||||
my @required = qw ( SYNCMODE PLAYLISTDIR IPODDIR BACKUPDIR );
|
||||
|
||||
my $rc=readrc("$ENV{HOME}/.ipod/config",\@required);
|
||||
|
||||
#print Dumper($rc);
|
||||
|
||||
|
||||
#
|
||||
# check ipod name
|
||||
#
|
||||
|
||||
my ($ipod_name, $real_name, $computer_name)=get_ipodname($rc->{IPODDIR});
|
||||
unless($ipod_name) {
|
||||
die "IPOD dir not found: $rc->{IPODDIR}" unless $opt{c};
|
||||
}
|
||||
|
||||
#
|
||||
# check ipod dirs (recreate them if necessary)
|
||||
#
|
||||
|
||||
mkdir "$rc->{IPODDIR}/iPod_Control",0755 unless(-d "$rc->{IPODDIR}/iPod_Control");
|
||||
mkdir "$rc->{IPODDIR}/iPod_Control/Music",0755 unless(-d "$rc->{IPODDIR}/iPod_Control/Music");
|
||||
mkdir "$rc->{IPODDIR}/iPod_Control/iTunes",0755 unless(-d "$rc->{IPODDIR}/iPod_Control/iTunes");
|
||||
mkdir "$rc->{IPODDIR}/iPod_Control/Device",0755 unless(-d "$rc->{IPODDIR}/iPod_Control/Device");
|
||||
for(0..19) {
|
||||
my $d=sprintf "%.2d",$_;
|
||||
mkdir "$rc->{IPODDIR}/iPod_Control/Music/F$d",0755 unless(-d "$rc->{IPODDIR}/iPod_Control/Music/F$d");
|
||||
}
|
||||
|
||||
unless($opt{c}) {
|
||||
print STDERR "IPOD name: $ipod_name\n";
|
||||
print STDERR "Synced by: $real_name\n";
|
||||
print STDERR "Synced on: $computer_name\n";
|
||||
|
||||
if($rc->{WRITEDEVICEINFO} && !$opt{f}) {
|
||||
my $exit=0;
|
||||
unless($rc->{IPODNAME} eq $ipod_name) {
|
||||
$exit=1;
|
||||
print STDERR "Your IPOD name: $rc->{IPODNAME}\n";
|
||||
}
|
||||
unless($rc->{REALNAME} eq $real_name) {
|
||||
$exit=1;
|
||||
print STDERR "Your real name: $rc->{REALNAME}\n";
|
||||
}
|
||||
unless($rc->{COMPUTERNAME} eq $computer_name) {
|
||||
$exit=1;
|
||||
print STDERR "Your computer: $rc->{COMPUTERNAME}\n";
|
||||
}
|
||||
die "names mismatch, use -f to override" if $exit;
|
||||
}
|
||||
print STDERR "\n";
|
||||
}
|
||||
|
||||
#
|
||||
# write ipod name
|
||||
#
|
||||
|
||||
if($rc->{WRITEDEVICEINFO}) {
|
||||
set_ipodname(
|
||||
$rc->{IPODDIR},$rc->{BACKUPDIR},
|
||||
$rc->{IPODNAME},$rc->{REALNAME},$rc->{COMPUTERNAME}
|
||||
);
|
||||
$ipod_name=$rc->{IPODNAME};
|
||||
}
|
||||
|
||||
#
|
||||
# check for songs
|
||||
#
|
||||
|
||||
my %songs;
|
||||
my %check;
|
||||
|
||||
my $dir;
|
||||
$dir=$rc->{IPODDIR}."/iPod_Control/Music";
|
||||
$dir=$rc->{SYNCDIR} if($rc->{SYNCMODE} >= 2);
|
||||
|
||||
my %tosync;
|
||||
if(($rc->{SYNCLIST}) && ($rc->{SYNCMODE} == 2)) {
|
||||
open IN,$rc->{SYNCLIST} or die "all-playlist: $rc->{SYNCLIST} not found";
|
||||
while(<IN>) {
|
||||
chomp;
|
||||
$tosync{$_}=1;
|
||||
}
|
||||
close IN;
|
||||
}
|
||||
|
||||
my @mp3s;
|
||||
if(($rc->{SYNCMODE} == 3)) {
|
||||
my @pl=find("$rc->{PLAYLISTDIR}/* 2>/dev/null");
|
||||
my %test;
|
||||
|
||||
for my $p (@pl) {
|
||||
chomp $p;
|
||||
my ($n) = $p =~ /.*\/(.*?)$/;
|
||||
open IN,$p or die "playlist: $p could not be opened";
|
||||
while(<IN>) {
|
||||
unless($test{$_}) {
|
||||
push @mp3s,$_;
|
||||
$test{$_}=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@mp3s=find($dir);
|
||||
}
|
||||
|
||||
for(@mp3s) {
|
||||
chomp $_;
|
||||
next unless(/\.(m|M)(p|P)3$/);
|
||||
my $name=$_;
|
||||
|
||||
if(keys %tosync) {
|
||||
next unless($tosync{$name});
|
||||
}
|
||||
|
||||
if($opt{n}) {
|
||||
die "illegal character in filename [$name]\n" unless ($name =~ /^[A-Za-z0-9\.\-_\/\,]+$/);
|
||||
}
|
||||
|
||||
s/\://g;
|
||||
s/.*\///g;
|
||||
$songs{$name}{name}=$_;
|
||||
if($rc->{SYNCMODE} >= 2) {
|
||||
$songs{$name}{dir}="F".hash($_);
|
||||
} else {
|
||||
($songs{$name}{dir}) = $name =~ /\/(F\d\d)\//;
|
||||
}
|
||||
|
||||
{
|
||||
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
||||
$atime,$mtime,$ctime,$blksize,$blocks) = stat($name);
|
||||
$songs{$name}{size}=$size;
|
||||
$songs{$name}{date}=$mtime;
|
||||
}
|
||||
|
||||
my $tag;
|
||||
$tag = get_mp3tag($name) unless($rc->{ALWAYSTEMPLATES});
|
||||
|
||||
my ($artist,$album,$title,$order,$_dummy_);
|
||||
|
||||
if($tag) {
|
||||
# print Dumper($tag);
|
||||
# YEAR ARTIST COMMENT TRACKNUM TITLE ALBUM GENRE
|
||||
$artist=$tag->{ARTIST};
|
||||
$album=$tag->{ALBUM};
|
||||
$title=$tag->{TITLE};
|
||||
$order=$tag->{TRACKNUM};
|
||||
$order=$1 if($order =~ /(\d+)\s*\//);
|
||||
|
||||
} else {
|
||||
for(sort {length($b) <=> length($a)} keys %{$rc->{FILETEMPLATES}}) {
|
||||
if(my @x = $name =~ /$_/) {
|
||||
my $c=0;
|
||||
for my $x (@x) {
|
||||
#print "\$$rc->{FILETEMPLATES}->{$_}->[$c]=\"$x\";\n";
|
||||
eval "\$$rc->{FILETEMPLATES}->{$_}->[$c]=\"$x\";";
|
||||
die "eval error: $@" if($@);
|
||||
$c++;
|
||||
}
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unless($title) {
|
||||
die "no title found in: $name";
|
||||
}
|
||||
|
||||
$title =~ s/_/ /g;
|
||||
$artist =~ s/_/ /g;
|
||||
$album =~ s/_/ /g;
|
||||
|
||||
$songs{$name}{title}=$title;
|
||||
$songs{$name}{artist}="";
|
||||
$songs{$name}{album}="";
|
||||
$songs{$name}{order}=0;
|
||||
$songs{$name}{artist}=$artist if $artist;
|
||||
$songs{$name}{album}=$album if $album;
|
||||
$songs{$name}{order}=$order if $order;
|
||||
|
||||
my $info = get_mp3info ($name);
|
||||
|
||||
$songs{$name}{size}=$info->{SIZE};
|
||||
$songs{$name}{bitrate}=$info->{BITRATE};
|
||||
$songs{$name}{duration}=int($info->{SECS}*1000);
|
||||
$songs{$name}{vbr}=$info->{VBR};
|
||||
|
||||
#print Dumper($info);
|
||||
|
||||
my $n=$songs{$name}{dir}."/".$songs{$name}{name};
|
||||
unless($check{$n}) {
|
||||
$check{$n}=1;
|
||||
} else {
|
||||
die "songname: $songs{$name}{name} not unique";
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# deleting unwanted songs
|
||||
#
|
||||
|
||||
my %known;
|
||||
for(keys %songs) {
|
||||
$known{$songs{$_}{name}}=1;
|
||||
}
|
||||
|
||||
#print Dumper(\%known);
|
||||
|
||||
my @ipod = find ("$rc->{IPODDIR}/iPod_Control/Music");
|
||||
my @todel;
|
||||
for(@ipod) {
|
||||
next unless (/\.mp3$/i);
|
||||
chomp;
|
||||
|
||||
my ($name) = $_ =~ /\/([^\/]+\.mp3)$/i;
|
||||
unless($known{$name}) {
|
||||
push @todel,$_;
|
||||
}
|
||||
}
|
||||
|
||||
my $del;
|
||||
if($rc->{DELETEASK} && @todel) {
|
||||
for(@todel) {
|
||||
print "del: $_\n";
|
||||
}
|
||||
print "Do you really want to delete this songs? (y/N) ";
|
||||
my $in=<STDIN>;
|
||||
chomp $in;
|
||||
$del=1 if($in =~ /^y$/i);
|
||||
} else {
|
||||
$del=1;
|
||||
}
|
||||
|
||||
if($del) {
|
||||
for(@todel) {
|
||||
print STDERR "deleting: $_\n";
|
||||
unlink($_);
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# copy songs
|
||||
#
|
||||
|
||||
my $main_sl="";
|
||||
my $main_pl="";
|
||||
my $index=500;
|
||||
|
||||
#print Dumper(\%songs);
|
||||
|
||||
my $df = new Filesys::DiskFree;
|
||||
|
||||
SONGS: for my $song (keys %songs) {
|
||||
my $attr;
|
||||
my $out="";
|
||||
my $attr_c=3;
|
||||
|
||||
if($rc->{SYNCMODE} >= 2) {
|
||||
my $to = "$rc->{IPODDIR}/iPod_Control/Music/$songs{$song}{dir}/$songs{$song}{name}";
|
||||
#my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
||||
# $atime,$mtime,$ctime,$blksize,$blocks) = stat($to);
|
||||
#$size=0 unless $size;
|
||||
#print "checking: $song [$songs{$song}{size}] -> $to [$size]\n";
|
||||
#if($size != $songs{$song}{size}) {
|
||||
|
||||
unless(-e $to) {
|
||||
print STDERR "syncing: $songs{$song}{name}\n";
|
||||
# cp "\"$song\" \"$to\"";
|
||||
|
||||
$df->df();
|
||||
my $free=$df->avail($rc->{IPODDIR});
|
||||
|
||||
if($free-$songs{$song}{size}-$buffer>0) {
|
||||
copy($song,$to);
|
||||
} else {
|
||||
print STDERR "no space availiable for: $songs{$song}{name} [$songs{$song}{size}]\n";
|
||||
delete $songs{$song};
|
||||
next SONGS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$songs{$song}{index}=$index;
|
||||
|
||||
$out.=create_mhod($songs{$song}{title},1);
|
||||
|
||||
if($songs{$song}{artist}) {
|
||||
$attr_c++;
|
||||
$out.=create_mhod($songs{$song}{artist},4);
|
||||
}
|
||||
if($songs{$song}{album}) {
|
||||
$attr_c++;
|
||||
$out.=create_mhod($songs{$song}{album},3);
|
||||
}
|
||||
|
||||
$out.=create_mhod("MPEG audio file",6);
|
||||
$out.=create_mhod(":iPod_Control:Music:".$songs{$song}{dir}.":".$songs{$song}{name},2);
|
||||
|
||||
$out=create_mhit(
|
||||
$attr_c,length($out),$index,$songs{$song}{vbr},
|
||||
$songs{$song}{date},$songs{$song}{size},
|
||||
$songs{$song}{duration},$songs{$song}{order},
|
||||
$songs{$song}{bitrate}
|
||||
).$out;
|
||||
|
||||
$main_sl.=$out;
|
||||
|
||||
$main_pl.=create_mhod_mhip($songs{$song}{index});
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
#print Dumper(\%songs);
|
||||
|
||||
my %playlists;
|
||||
my @pl=find("$rc->{PLAYLISTDIR}/* 2>/dev/null");
|
||||
|
||||
for my $p (@pl) {
|
||||
chomp $p;
|
||||
my ($n) = $p =~ /.*\/(.*?)$/;
|
||||
open IN,$p or die "playlist: $p could not be opened";
|
||||
while(<IN>) {
|
||||
my $song=$_;
|
||||
chomp $song;
|
||||
|
||||
unless($songs{$song}) {
|
||||
print STDERR "ignoring song in playlist [$p], [$song] does not exist in syncdir or ipod full\n";
|
||||
} else {
|
||||
$playlists{$n}{raw}.=create_mhod_mhip($songs{$song}{index});
|
||||
$playlists{$n}{count}++;
|
||||
}
|
||||
}
|
||||
close IN;
|
||||
}
|
||||
|
||||
#
|
||||
# creating search pattern playlists
|
||||
#
|
||||
|
||||
for my $pattern (@ARGV) {
|
||||
my @list;
|
||||
for(keys %songs) {
|
||||
push @list,$songs{$_}{index} if($_ =~ /$pattern/i);
|
||||
}
|
||||
unless(@list) {
|
||||
print STDERR "nothing for searchpattern: $pattern found\n";
|
||||
} else {
|
||||
my ($name)=$pattern=~/(\S\S\S+)/;
|
||||
unless(length($name)>=3) {
|
||||
$name=$pattern;
|
||||
$name =~ s/[^A-Za-z0-9]//g;
|
||||
}
|
||||
for(@list) {
|
||||
$playlists{$name}{raw}.=create_mhod_mhip($_);
|
||||
$playlists{$name}{count}++;
|
||||
}
|
||||
print STDERR @list." songs for searchpattern: $pattern found\n";
|
||||
}
|
||||
}
|
||||
|
||||
#print Dumper(\%playlists);
|
||||
|
||||
#
|
||||
# build the pieces together
|
||||
#
|
||||
|
||||
my $output;
|
||||
|
||||
my $song_c=keys %songs;
|
||||
|
||||
print STDERR "\nFound songs: $song_c\n";
|
||||
|
||||
my $tmp=create_mhlt($song_c).$main_sl;
|
||||
$main_sl=create_mhsd(96+length($tmp),1).$tmp;
|
||||
|
||||
print STDERR "Songlist created\n";
|
||||
|
||||
my $pl_c=keys %playlists;
|
||||
|
||||
print STDERR "\nFound additional playlists: $pl_c\n";
|
||||
|
||||
$tmp=create_mhlp($pl_c+1).create_playlist_main($ipod_name,$song_c).$main_pl;
|
||||
print STDERR "\nMain playlist created: $song_c songs\n\n";
|
||||
|
||||
for(keys %playlists) {
|
||||
$tmp.=create_playlist($_,$playlists{$_}{count}).$playlists{$_}{raw};
|
||||
print STDERR "Playlist \"$_\" created: $playlists{$_}{count} songs\n";
|
||||
}
|
||||
|
||||
$main_pl=create_mhsd(96+length($tmp),2).$tmp;
|
||||
|
||||
|
||||
$output=create_mhbd(104+length($main_sl.$main_pl)).$main_sl.$main_pl;
|
||||
|
||||
# backup old iTunesDB
|
||||
if(-e "$rc->{IPODDIR}/iPod_Control/iTunes/iTunesDB") {
|
||||
my $t=time();
|
||||
copy("$rc->{IPODDIR}/iPod_Control/iTunes/iTunesDB","$rc->{BACKUPDIR}/iTunesDB_$t");
|
||||
gzip("$rc->{BACKUPDIR}/iTunesDB_$t");
|
||||
}
|
||||
|
||||
open OUT,">".$rc->{IPODDIR}."/iPod_Control/iTunes/iTunesDB" or die "cannot write iTunesDB";
|
||||
print OUT $output;
|
||||
close OUT;
|
||||
|
||||
print STDERR "\niTunesDB created.\n";
|
||||
exit;
|
||||
# END
|
||||
|
||||
|
||||
#
|
||||
# internal subroutines
|
||||
#
|
||||
|
||||
sub create_mhbd {
|
||||
my ($size) = @_;
|
||||
|
||||
my $r= "mhbd";
|
||||
$r.= pack "V",104;
|
||||
$r.= pack "V",$size;
|
||||
$r.= pack "V",1;
|
||||
$r.= pack "V",1;
|
||||
$r.= pack "V",2;
|
||||
for(1..20) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
sub create_mhlp {
|
||||
my ($count) = @_;
|
||||
|
||||
my $r= "mhlp";
|
||||
$r.= pack "V",92;
|
||||
$r.= pack "V",$count;
|
||||
for(1..20) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
sub create_playlist {
|
||||
my ($name,$anz) = @_;
|
||||
|
||||
my $ipod_name=create_mhod($name,1);
|
||||
|
||||
my $r= "mhyp";
|
||||
$r.= pack "V",108;
|
||||
$r.= pack "V",108+648+length($ipod_name)+$anz*(76+44);
|
||||
$r.= pack "V",2;
|
||||
$r.= pack "V",$anz;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",3088620292;
|
||||
$r.= pack "V",2317718671;
|
||||
$r.= pack "V",3655876446;
|
||||
for(1..18) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
$r.= "mhod";
|
||||
$r.= pack "V",24;
|
||||
$r.= pack "V",648;
|
||||
$r.= pack "V",100;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",12714187; # ?? 12714187
|
||||
$r.= pack "V",26215000;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",65736;
|
||||
$r.= pack "V",1; # ?? 1
|
||||
$r.= pack "V",6; # ?? 6
|
||||
$r.= pack "V",0; # ?? 0
|
||||
$r.= pack "V",2555905; # ?? 2555905
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",13107202;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",3276813;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",8192004;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",8192003;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",5242888;
|
||||
for(1..107) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",140;
|
||||
for(1..19) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r.$ipod_name;
|
||||
}
|
||||
|
||||
sub create_playlist_main {
|
||||
my ($name,$anz) = @_;
|
||||
|
||||
my $ipod_name=create_mhod($name,1);
|
||||
|
||||
my $r= "mhyp";
|
||||
$r.= pack "V",108;
|
||||
$r.= pack "V",108+648+length($ipod_name)+$anz*(76+44);
|
||||
$r.= pack "V",2;
|
||||
$r.= pack "V",$anz;
|
||||
$r.= pack "V",1;
|
||||
$r.= pack "V",3087491191;
|
||||
$r.= pack "V",837788566;
|
||||
$r.= pack "V",62365;
|
||||
for(1..18) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
$r.= "mhod";
|
||||
$r.= pack "V",24;
|
||||
$r.= pack "V",648;
|
||||
$r.= pack "V",100;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",13172927; # ?? 12714187
|
||||
$r.= pack "V",26215000;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",65736;
|
||||
$r.= pack "V",5; # ?? 1
|
||||
$r.= pack "V",6; # ?? 6
|
||||
$r.= pack "V",3; # ?? 0
|
||||
$r.= pack "V",1179649; # ?? 2555905
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",13107202;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",3276813;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",8192004;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",8192003;
|
||||
for(1..3) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",5242888;
|
||||
for(1..107) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
$r.= pack "V",140;
|
||||
for(1..19) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r.$ipod_name;
|
||||
}
|
||||
|
||||
sub create_mhod_mhip {
|
||||
my ($ref) = @_;
|
||||
|
||||
my $r= "mhip";
|
||||
$r.= pack "V",76;
|
||||
$r.= pack "V",76;
|
||||
$r.= pack "V",1;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",$ref-1;
|
||||
$r.= pack "V",$ref;
|
||||
$r.= pack "V",3088619525;
|
||||
for(1..11) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
$r.="mhod";
|
||||
$r.= pack "V",24;
|
||||
$r.= pack "V",44;
|
||||
$r.= pack "V",100;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",$ref-1;
|
||||
for(1..4) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
sub create_mhsd {
|
||||
my ($size,$type) = @_;
|
||||
|
||||
my $r="mhsd";
|
||||
$r.= pack "V",96;
|
||||
$r.= pack "V",$size;
|
||||
$r.= pack "V",$type;
|
||||
for(1..20) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
sub create_mhlt {
|
||||
my ($count) = @_;
|
||||
|
||||
my $r="mhlt";
|
||||
$r.= pack "V",92;
|
||||
$r.= pack "V",$count;
|
||||
for(1..20) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
sub create_mhit {
|
||||
my ($arttr_c,$attr_s,$index,$vbr,$date,$size,$dur,$order,$bitrate) = @_;
|
||||
|
||||
my $r="mhit";
|
||||
$r.= pack "V",156;
|
||||
$r.= pack "V",156+$attr_s;
|
||||
$r.= pack "V",$arttr_c;
|
||||
$r.= pack "V",$index;
|
||||
$r.= pack "V",1;
|
||||
$r.= pack "V",0;
|
||||
my $type=256;
|
||||
$type+=1 if($vbr);
|
||||
$r.= pack "V",$type;
|
||||
$r.= pack "V",$date+2082844800;
|
||||
$r.= pack "V",$size;
|
||||
$r.= pack "V",$dur;
|
||||
$r.= pack "V",$order;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",0;
|
||||
$r.= pack "V",$bitrate;
|
||||
$r.= pack "V",2890137600;
|
||||
for(1..23) {
|
||||
$r.= pack "V",0;
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
sub create_mhod {
|
||||
my ($string,$type) = @_;
|
||||
my $len=length($string);
|
||||
|
||||
my $r="mhod";
|
||||
$r.= pack "V",24;
|
||||
$r.= pack "V",(40+2*$len);
|
||||
$r.= pack "V",$type;
|
||||
$r.= pack "V2",0;
|
||||
$r.= pack "V",1;
|
||||
$r.= pack "V",(2*$len);
|
||||
$r.= pack "V2",0;
|
||||
|
||||
my $u=latin1($string);
|
||||
$u->byteswap;
|
||||
$r.= $u->utf16;
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
sub set_ipodname {
|
||||
my ($dev,$backup,$name,$real,$cpu)=@_;
|
||||
$dev.="/iPod_Control/iTunes/DeviceInfo";
|
||||
|
||||
my $file;
|
||||
|
||||
for(1..384) {
|
||||
$file.=pack "V",0;
|
||||
}
|
||||
|
||||
my $l=length($name);
|
||||
substr($file,0,2)=pack "v",$l;
|
||||
my $u=latin1($name);
|
||||
$u->byteswap;
|
||||
substr($file,2,$l*2)=$u->utf16;
|
||||
|
||||
$l=length($real);
|
||||
substr($file,512,2)=pack "v",$l;
|
||||
$u=latin1($real);
|
||||
$u->byteswap;
|
||||
substr($file,514,$l*2)=$u->utf16;
|
||||
|
||||
$l=length($cpu);
|
||||
substr($file,1024,2)=pack "v",$l;
|
||||
$u=latin1($cpu);
|
||||
$u->byteswap;
|
||||
substr($file,1026,$l*2)=$u->utf16;
|
||||
|
||||
if(-e $dev) {
|
||||
my $t=time();
|
||||
copy($dev,"$backup/DeviceInfo_$t");
|
||||
gzip("$backup/DeviceInfo_$t");
|
||||
}
|
||||
open IPOD,">$dev" or die "cannot write DeviceInfo";
|
||||
print IPOD $file;
|
||||
close IPOD;
|
||||
}
|
||||
|
||||
sub get_ipodname {
|
||||
my $dev=shift;
|
||||
$dev.="/iPod_Control/iTunes/DeviceInfo";
|
||||
my $file;
|
||||
my $buff;
|
||||
|
||||
open IPOD,$dev or return undef;
|
||||
while (read(IPOD, $buff, 8 * 2**10)) {
|
||||
$file.=$buff;
|
||||
}
|
||||
close IPOD;
|
||||
|
||||
my $l=unpack "v",substr($file,0,2);
|
||||
my $s=substr($file,2,$l*2);
|
||||
my $u=utf16($s);
|
||||
$u->byteswap;
|
||||
my $name=$u->latin1;
|
||||
|
||||
$l=unpack "v",substr($file,512,2);
|
||||
$s=substr($file,514,$l*2);
|
||||
$u=utf16($s);
|
||||
$u->byteswap;
|
||||
my $realname=$u->latin1;
|
||||
|
||||
$l=unpack "v",substr($file,1024,2);
|
||||
$s=substr($file,1026,$l*2);
|
||||
$u=utf16($s);
|
||||
$u->byteswap;
|
||||
my $computername=$u->latin1;
|
||||
|
||||
return ($name,$realname,$computername);
|
||||
}
|
||||
|
||||
sub hash {
|
||||
my $string=shift;
|
||||
my $key;
|
||||
|
||||
my $len=length($string);
|
||||
|
||||
for(my $j=$len-1 ; $j>1 ; $j--) {
|
||||
$key+=ord(substr($string,$j,1));
|
||||
}
|
||||
|
||||
return sprintf "%.2d",(substr($key,length($key)-2,2) % 20);
|
||||
}
|
||||
|
||||
sub readrc {
|
||||
my $file = shift;
|
||||
my $req = shift;
|
||||
my $rc;
|
||||
|
||||
my $sub;
|
||||
|
||||
open IN,$file or die "cannot open rc file: $file";
|
||||
while(<IN>) {
|
||||
next if /^\s*$/;
|
||||
next if /^\s*#/;
|
||||
|
||||
if(/^\s*(\S+)\s*=\s*(.*?)\s*$/) {
|
||||
my $k=$1;
|
||||
my $n=$2;
|
||||
($n) = $n =~ /^\"(.*?)\"$/ if($n =~ /\"/);
|
||||
unless($sub) {
|
||||
$rc->{$k}=$n;
|
||||
} else {
|
||||
($k) = $k =~ /^\"(.*?)\"$/ if($k =~ /\"/);
|
||||
my @n=split /,/,$n;
|
||||
for(@n) {
|
||||
s/^\s+//g;
|
||||
s/\s+$//g;
|
||||
s/^\"//;
|
||||
s/\"$//;
|
||||
}
|
||||
$rc->{$sub}->{$k}=\@n;
|
||||
}
|
||||
} elsif (/^\s*(\S+)\s*\{/) {
|
||||
$sub=$1;
|
||||
} elsif (/^\s*}/) {
|
||||
$sub=undef;
|
||||
}
|
||||
}
|
||||
|
||||
if($rc->{SYNCMODE} == 2) {
|
||||
push @$req,"SYNCDIR";
|
||||
}
|
||||
if($rc->{WRITEDEVICEINFO} == 1) {
|
||||
push @$req,("IPODNAME","REALNAME","COMPUTERNAME");
|
||||
}
|
||||
if($rc->{ALWAYSTEMPLATES} == 1) {
|
||||
push @$req,"FILETEMPLATES";
|
||||
}
|
||||
|
||||
for my $d (keys %$rc) {
|
||||
if($d =~ /DIR$/) {
|
||||
$rc->{$d} =~ s/\~/$ENV{HOME}/;
|
||||
}
|
||||
}
|
||||
$rc->{SYNCLIST} =~ s/\~/$ENV{HOME}/ if $rc->{SYNCLIST};
|
||||
|
||||
for(@$req) {
|
||||
die "RC PARAMETER: $_ not found" unless($rc->{$_});
|
||||
}
|
||||
return $rc;
|
||||
}
|
||||
@@ -11,15 +11,17 @@ sudo dirvish-expire
|
||||
sudo dirvish-runall
|
||||
|
||||
# GPS
|
||||
sudo rsync -vxae --progress --delete --exclude 'garmin/' /dat/gps/ $bakdir/gps/
|
||||
gpsdir=/dat/docu/gps/
|
||||
sudo rsync -vxae --progress --delete --exclude 'garmin/' $gpsdir $bakdir/gps/
|
||||
|
||||
# vdr Struktur der Aufnahmen
|
||||
sudo -u vdr rsync -vxae --progress --delete --exclude '[0-9][0-9][0-9].vdr' --exclude '[0-9][0-9][0-9][0-9][0-9].ts' /media/nas/video/vdr/ $bakdir/video/
|
||||
|
||||
videodir=/dat/video/vdr/
|
||||
sudo -u vdr rsync -vxae --progress --delete --exclude '[0-9][0-9][0-9].vdr' --exclude '[0-9][0-9][0-9][0-9][0-9].ts' $videodir $bakdir/video/
|
||||
|
||||
srcdir=/dat/src
|
||||
echo "#!/bin/bash" > /tmp/backuphelp
|
||||
echo "dstdir=\$(dirname \$1)" >> /tmp/backuphelp
|
||||
echo "mkdir -p \$bakdir/git\$dstdir" >> /tmp/backuphelp
|
||||
echo "rsync -vxa --progress --delete \$1 \$bakdir/git\$dstdir" >> /tmp/backuphelp
|
||||
find /home/marc/ -type d -name .git -exec bash -x /tmp/backuphelp {} \;
|
||||
find $srcdir -type d -name .git -exec bash -x /tmp/backuphelp {} \;
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#!/bin/sh
|
||||
REPOSITORY=pi@vdrpi:/media/hdext/borg
|
||||
REPOSITORY=pi@kodi:/media/hdext/borg
|
||||
PREFIX=nasdat
|
||||
|
||||
borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
$REPOSITORY::'nasdat-{now:%Y-%m-%d}' \
|
||||
/dat/books \
|
||||
/dat/audio \
|
||||
/dat/docu/Foto \
|
||||
/dat/docu/ \
|
||||
/dat/bak/db \
|
||||
--exclude 'tmp' \
|
||||
--exclude '*/tmp' \
|
||||
--exclude '*.iso' \
|
||||
--exclude '/podcast/cache' \
|
||||
--exclude '/run'
|
||||
--exclude '/dat/docu/dropbox' \
|
||||
--exclude '/dat/docu/A' \
|
||||
--exclude '/dat/docu/E' \
|
||||
|
||||
|
||||
|
||||
@@ -20,5 +22,5 @@ borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
# archives of THIS machine. The '{hostname}-' prefix is very important to
|
||||
# limit prune's operation to this machine's archives and not apply to
|
||||
# other machine's archives also.
|
||||
borg prune -v $REPOSITORY --prefix 'nasdat-' \
|
||||
borg prune -v --stats $REPOSITORY --prefix 'nasdat-' \
|
||||
--keep-daily=7 --keep-weekly=4 --keep-monthly=20
|
||||
@@ -21,5 +21,5 @@ borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
# archives of THIS machine. The '{hostname}-' prefix is very important to
|
||||
# limit prune's operation to this machine's archives and not apply to
|
||||
# other machine's archives also.
|
||||
borg prune -v $REPOSITORY --prefix $PREFIX- \
|
||||
borg prune -v --stats $REPOSITORY --prefix $PREFIX- \
|
||||
--keep-daily=7 --keep-weekly=4 --keep-monthly=20
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/bin/sh
|
||||
REPOSITORY=pi@vdrpi:/media/hdext/borg
|
||||
REPOSITORY=pi@kodi:/media/hdext/borg
|
||||
|
||||
if [ "$1" != "--prune" ]; then
|
||||
borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
$REPOSITORY::'{hostname}-{now:%Y-%m-%d}' \
|
||||
/ \
|
||||
--exclude '*/tmp/*' \
|
||||
--exclude '*/tmpfile/*' \
|
||||
--exclude '/var/tmp/*' \
|
||||
--exclude '/var/crash/*' \
|
||||
--exclude '*/.cache/*' \
|
||||
@@ -12,7 +14,7 @@ borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
--exclude '*/.ccache/*' \
|
||||
--exclude '*/mlocate.db*' \
|
||||
--exclude '/run'
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
@@ -20,5 +22,5 @@ borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
# archives of THIS machine. The '{hostname}-' prefix is very important to
|
||||
# limit prune's operation to this machine's archives and not apply to
|
||||
# other machine's archives also.
|
||||
borg prune -v $REPOSITORY --prefix '{hostname}-' \
|
||||
borg prune -v --stats $REPOSITORY --prefix '{hostname}-' \
|
||||
--keep-daily=7 --keep-weekly=4 --keep-monthly=20
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
REPOSITORY=pi@vdrpi:/media/hdext/borg
|
||||
REPOSITORY=pi@kodi:/media/hdext/borg
|
||||
PREFIX=nassrc
|
||||
|
||||
borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
@@ -8,11 +8,17 @@ borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
--exclude '*/tmp/*' \
|
||||
--exclude '*/.build*/' \
|
||||
--exclude '*/build*/' \
|
||||
--exclude '*/rpi-build*/' \
|
||||
--exclude '*/dest*/' \
|
||||
--exclude '*/cache*' \
|
||||
--exclude '*/.cache/*' \
|
||||
--exclude '*/.ccache/*' \
|
||||
--exclude '*/subtree-cache/*' \
|
||||
--exclude '*/sstate*' \
|
||||
--exclude '*/dl/*' \
|
||||
--exclude '*/downloads/*' \
|
||||
--exclude '*/sourcemirror/*' \
|
||||
--exclude '*/yocto-dl-sources.git/*' \
|
||||
--exclude '*.o' \
|
||||
--exclude '*.ko' \
|
||||
--exclude '*.so' \
|
||||
@@ -30,5 +36,5 @@ borg create -v --stats --progress --compression zlib --one-file-system \
|
||||
# archives of THIS machine. The '{hostname}-' prefix is very important to
|
||||
# limit prune's operation to this machine's archives and not apply to
|
||||
# other machine's archives also.
|
||||
borg prune -v $REPOSITORY --prefix 'nassrc-' \
|
||||
borg prune -v --stats $REPOSITORY --prefix 'nassrc-' \
|
||||
--keep-daily=7 --keep-weekly=4 --keep-monthly=20
|
||||
8
bakdb
8
bakdb
@@ -1,5 +1,11 @@
|
||||
# !/bin/sh
|
||||
db=$1
|
||||
pw=$2
|
||||
file=/dat/bak/db/${db}_`date +"%Y%m%d"`.sqlbak
|
||||
bakdir=/dat/bak/db
|
||||
file=$bakdir/${db}_`date +"%Y%m%d"`.sqlbak
|
||||
mysqldump --lock-tables --user root -p"$pw" $db > $file
|
||||
|
||||
find $bakdir -size 0 -exec rm {} \;
|
||||
ls -1tr $bakdir/${db}_* | head -n -5 | xargs -d '\n' rm -f --
|
||||
#find /dat/bak/db -name "${db}_*" -mtime +5 -exec rm {} \;
|
||||
|
||||
|
||||
13
cleanowrtrepo.sh
Normal file
13
cleanowrtrepo.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders dl --delete-files dl --no-blob-protection owrttest
|
||||
cd owrttest
|
||||
git reflog expire --expire=now --all && git gc --prune=now --aggressive
|
||||
du -sh
|
||||
cd ..
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders scripts --no-blob-protection owrttest
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders target --no-blob-protection owrttest
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders toolchain --no-blob-protection owrttest
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders tools --no-blob-protection owrttest
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders docs --no-blob-protection owrttest
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders include --no-blob-protection owrttest
|
||||
java -jar ~/bin/bfg-1.12.14.jar --delete-folders timing_log_received_sent_correlator --no-blob-protection owrttest
|
||||
|
||||
1
dropboxstart.sh
Normal file
1
dropboxstart.sh
Normal file
@@ -0,0 +1 @@
|
||||
HOME=/home/nas/.dropbox-mhde dropbox start -i
|
||||
3
fv
3
fv
@@ -11,7 +11,8 @@ lstr2dir () {
|
||||
local lstrtime=$(echo $lstr | awk '{print $3}' | awk -F@ '{print $1}')
|
||||
}
|
||||
|
||||
svdrpsend -p2001 LSTR | grep -i "$name" | sed "s/^[0-9-]* //g" > ${tempfile}_1.tmp
|
||||
#svdrpsend -p2001 LSTR | grep -i "$name" | sed "s/^[0-9-]* //g" > ${tempfile}_1.tmp
|
||||
svdrpsend LSTR | grep -i "$name" | sed "s/^[0-9-]* //g" > ${tempfile}_1.tmp
|
||||
|
||||
|
||||
(
|
||||
|
||||
15
fvl
Executable file
15
fvl
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
videodir=/dat/video/vdr
|
||||
vdrdb=/tmp/vdr.db
|
||||
|
||||
tofind=$1
|
||||
|
||||
files=$(locate -d $vdrdb -i $1 | grep -v .rec)
|
||||
|
||||
for f in $files; do
|
||||
if [ -d $f ]; then
|
||||
#echo $f
|
||||
du -sh $f
|
||||
fi
|
||||
done
|
||||
25
git-dir2repo
Normal file
25
git-dir2repo
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
if (( $# < 3 ))
|
||||
then
|
||||
echo "Usage: $0 </path/to/repo/> <directory/to/extract/> <newName>"
|
||||
echo
|
||||
echo "Example: $0 /Projects/42.git first/answer/ firstAnswer"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
clone=$PWD/${3}Clone
|
||||
newN=$PWD/${3}
|
||||
git clone --no-hardlinks file://$1 ${clone}
|
||||
cd ${clone}
|
||||
|
||||
git filter-branch --subdirectory-filter $2 --prune-empty --tag-name-filter cat -- --all
|
||||
cd -
|
||||
git clone file://${clone} ${newN}
|
||||
cd ${newN}
|
||||
|
||||
git reflog expire --expire=now --all
|
||||
git repack -ad
|
||||
git gc --prune=now
|
||||
|
||||
2797
git-imerge
Executable file
2797
git-imerge
Executable file
File diff suppressed because it is too large
Load Diff
234
git-mv-test
Normal file
234
git-mv-test
Normal file
@@ -0,0 +1,234 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script builds on the excellent work by Lucas Jenß, described in his blog
|
||||
# post "Integrating a submodule into the parent repository", but automates the
|
||||
# entire process and cleans up a few other corner cases.
|
||||
# https://x3ro.de/2013/09/01/Integrating-a-submodule-into-the-parent-repository.html
|
||||
|
||||
function usage(){
|
||||
echo "Usage: $0 <submodule-name> [<submodule-branch>]"
|
||||
echo "Merge a single branch of <submodule-name> into a repo, retaining file history."
|
||||
echo "If provided then <submodule-branch> will be merged, otherwise master."
|
||||
echo ""
|
||||
echo "options:"
|
||||
echo " -h, --help Print this message"
|
||||
echo " -v, --verbose Display verbose output"
|
||||
}
|
||||
|
||||
function abort {
|
||||
echo "$(tput setaf 1)$1$(tput sgr0)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function request_confirmation {
|
||||
read -p "$(tput setaf 4)$1 (y/n) $(tput sgr0)"
|
||||
[ "$REPLY" == "y" ] || abort "Aborted!"
|
||||
}
|
||||
|
||||
function warn() {
|
||||
cat << EOF
|
||||
This script will convert your "${sub}" git submodule into
|
||||
a simple subdirectory in the parent repository while retaining all
|
||||
contents, file history and its own submodules.
|
||||
|
||||
The script will:
|
||||
* delete the ${sub} submodule configuration from .gitmodules and
|
||||
.git/config and commit it.
|
||||
* rewrite the entire history of the ${sub} submodule so that all
|
||||
paths are prefixed by ${path}.
|
||||
This ensures that git log will correctly follow the original file
|
||||
history.
|
||||
* merge the submodule into its parent repository and commit it.
|
||||
* reinstate any of the submodule's own submodules as part of the parent
|
||||
repository
|
||||
|
||||
NOTE: This script might completely garble your repository, so PLEASE apply
|
||||
this only to a fresh clone of the repository where it does not matter if
|
||||
the repo is destroyed. It would be wise to keep a backup clone of your
|
||||
repository, so that you can reconstitute it if need be. You have been
|
||||
warned. Use at your own risk.
|
||||
|
||||
EOF
|
||||
|
||||
request_confirmation "Do you want to proceed?"
|
||||
}
|
||||
|
||||
function git_version_lte() {
|
||||
OP_VERSION=$(printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' '\n' | head -n 4))
|
||||
GIT_VERSION=$(git version)
|
||||
GIT_VERSION=$(printf "%03d%03d%03d%03d" $(echo "${GIT_VERSION#git version }" | sed -E "s/([0-9.]*).*/\1/" | tr '.' '\n' | head -n 4))
|
||||
echo -e "${GIT_VERSION}\n${OP_VERSION}" | sort | head -n1
|
||||
[ ${GIT_VERSION} -le ${OP_VERSION} ]
|
||||
}
|
||||
|
||||
# Convert a url to an absolute url
|
||||
#
|
||||
# Parameters:
|
||||
# $1: The url to check
|
||||
# $2: The base url to use if $1 is a relative path
|
||||
#
|
||||
# Returns an absolute url
|
||||
function absolute_url {
|
||||
local url=$1
|
||||
local base=$2
|
||||
|
||||
if [[ $url =~ \.\. ]]; then
|
||||
echo "$base/$(basename $url)"
|
||||
else
|
||||
echo $url
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
warn
|
||||
|
||||
if [ "${verbose}" == "true" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Remove submodule and commit
|
||||
#git config -f .gitmodules --remove-section "submodule.${sub}"
|
||||
#if git config -f .git/config --get "submodule.${sub}.url"; then
|
||||
# git config -f .git/config --remove-section "submodule.${sub}"
|
||||
#fi
|
||||
#rm -rf "${path}"
|
||||
#git add -A .
|
||||
#git commit -m "Remove submodule ${sub}"
|
||||
#rm -rf ".git/modules/${sub}"
|
||||
|
||||
# Rewrite submodule history
|
||||
local tmpdir="$(mktemp -d -t submodule-rewrite-XXXXXX)"
|
||||
git clone -b "${branch}" "${url}" "${tmpdir}"
|
||||
pushd "${tmpdir}"
|
||||
local tab="$(printf '\t')"
|
||||
local filter="git ls-files -s | sed \"s:${tab}:${tab}${path}/:\" | GIT_INDEX_FILE=\${GIT_INDEX_FILE}.new git update-index --index-info && mv \${GIT_INDEX_FILE}.new \${GIT_INDEX_FILE} || true"
|
||||
git filter-branch --index-filter "${filter}" HEAD
|
||||
popd
|
||||
|
||||
# Merge in rewritten submodule history
|
||||
git remote add "${sub}" "${tmpdir}"
|
||||
git fetch "${sub}"
|
||||
|
||||
if git_version_lte 2.8.4
|
||||
then
|
||||
# Previous to git 2.9.0 the parameter would yield an error
|
||||
ALLOW_UNRELATED_HISTORIES=""
|
||||
else
|
||||
# From git 2.9.0 this parameter is required
|
||||
ALLOW_UNRELATED_HISTORIES="--allow-unrelated-histories"
|
||||
fi
|
||||
|
||||
git merge -s ours --no-commit ${ALLOW_UNRELATED_HISTORIES} "${sub}/${branch}"
|
||||
rm -rf tmpdir
|
||||
|
||||
# Add submodule content
|
||||
git clone -b "${branch}" "${url}" "${path}"
|
||||
|
||||
# Transfer its own submodules to the parent
|
||||
#add_submod_cmds=""
|
||||
#if [ -f ${path}/.gitmodules ]; then
|
||||
# sub_names=$(git config -f ${path}/.gitmodules --get-regex path | sed 's/.* \(.*\)$/\1/g')
|
||||
|
||||
# for sub_name in ${sub_names}; do
|
||||
# sub_branch=$(git config -f ${path}/.gitmodules --get "submodule.${sub_name}.branch") || true
|
||||
# [ -n "${sub_branch}" ] && sub_branch="-b ${sub_branch}"
|
||||
# sub_path=$(git config -f ${path}/.gitmodules --get "submodule.${sub_name}.path")
|
||||
# sub_url=$(git config -f ${path}/.gitmodules --get "submodule.${sub_name}.url")
|
||||
|
||||
# # remove the sub-submodule (which should be empty) and cache the command to reinstate it
|
||||
# rmdir ${path}/${sub_path}
|
||||
# add_submod_cmds="$add_submod_cmds git submodule add ${sub_branch} --name ${sub_name} -- ${sub_url} ${path}/${sub_path} ; "
|
||||
# done
|
||||
#fi
|
||||
|
||||
rm -rf "${path}/.git"
|
||||
#"${path}/.gitmodules"
|
||||
git add "${path}"
|
||||
#if [ -n "${add_submod_cmds}" ]; then
|
||||
# bash -c "${add_submod_cmds}"
|
||||
#fi
|
||||
|
||||
git commit -m "Merge submodule contents for ${sub}/${branch}"
|
||||
#git config -f .git/config --remove-section "remote.${sub}"
|
||||
|
||||
set +x
|
||||
echo "$(tput setaf 2)Submodule merge complete. Push changes after review.$(tput sgr0)"
|
||||
}
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
declare verbose=false
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
(-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
(-v|--verbose)
|
||||
verbose=true
|
||||
;;
|
||||
(*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
declare sub="${1:-}"
|
||||
declare url="${2:-}"
|
||||
declare branch="${3:-master}"
|
||||
|
||||
if [ -z "${sub}" ]; then
|
||||
>&2 echo "Error: No submodule specified"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
|
||||
if [ -n "${1:-}" ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -n "${1:-}" ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -n "${1:-}" ]; then
|
||||
>&2 echo "Error: Unknown option: ${1:-}"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ -d ".git" ]; then
|
||||
>&2 echo "Error: No git repository found. Must be run from the root of a git repository"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#declare path="$(git config -f .gitmodules --get "submodule.${sub}.path")"
|
||||
declare path=$sub
|
||||
#declare superproject_dir="$(dirname $(git config --get remote.origin.url))"
|
||||
#declare url=$(absolute_url $(git config -f .gitmodules --get "submodule.${sub}.url") $superproject_dir)
|
||||
|
||||
|
||||
if [ -z "${path}" ]; then
|
||||
>&2 echo "Error: Submodule not found: ${sub}"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#if [ -z "${superproject_dir}" ]; then
|
||||
# >&2 echo "Error: Could not determine the remote origin for this superproject: ${superproject_dir}"
|
||||
# usage
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
#if ! [ -d "${path}" ]; then
|
||||
# >&2 echo "Error: Submodule path not found: ${path}"
|
||||
# usage
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
main
|
||||
25
git-remove-history
Executable file
25
git-remove-history
Executable file
@@ -0,0 +1,25 @@
|
||||
!/bin/bash
|
||||
set -o errexit
|
||||
|
||||
# Author: David Underhill
|
||||
# Script to permanently delete files/folders from your git repository. To use
|
||||
# it, cd to your repository's root and then run the script with a list of paths
|
||||
# you want to delete, e.g., git-delete-history path1 path2
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# make sure we're at the root of git repo
|
||||
if [ ! -d .git ]; then
|
||||
echo "Error: must run this script from the root of a git repository"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# remove all paths passed as arguments from the history of the repo
|
||||
files=$@
|
||||
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD
|
||||
|
||||
# remove the temporary history git-filter-branch otherwise leaves behind for a long time
|
||||
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
|
||||
|
||||
226
git-submodule-rewrite
Executable file
226
git-submodule-rewrite
Executable file
@@ -0,0 +1,226 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script builds on the excellent work by Lucas Jenß, described in his blog
|
||||
# post "Integrating a submodule into the parent repository", but automates the
|
||||
# entire process and cleans up a few other corner cases.
|
||||
# https://x3ro.de/2013/09/01/Integrating-a-submodule-into-the-parent-repository.html
|
||||
|
||||
function usage(){
|
||||
echo "Usage: $0 <submodule-name> [<submodule-branch>]"
|
||||
echo "Merge a single branch of <submodule-name> into a repo, retaining file history."
|
||||
echo "If provided then <submodule-branch> will be merged, otherwise master."
|
||||
echo ""
|
||||
echo "options:"
|
||||
echo " -h, --help Print this message"
|
||||
echo " -v, --verbose Display verbose output"
|
||||
}
|
||||
|
||||
function abort {
|
||||
echo "$(tput setaf 1)$1$(tput sgr0)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function request_confirmation {
|
||||
read -p "$(tput setaf 4)$1 (y/n) $(tput sgr0)"
|
||||
[ "$REPLY" == "y" ] || abort "Aborted!"
|
||||
}
|
||||
|
||||
function warn() {
|
||||
cat << EOF
|
||||
This script will convert your "${sub}" git submodule into
|
||||
a simple subdirectory in the parent repository while retaining all
|
||||
contents, file history and its own submodules.
|
||||
|
||||
The script will:
|
||||
* delete the ${sub} submodule configuration from .gitmodules and
|
||||
.git/config and commit it.
|
||||
* rewrite the entire history of the ${sub} submodule so that all
|
||||
paths are prefixed by ${path}.
|
||||
This ensures that git log will correctly follow the original file
|
||||
history.
|
||||
* merge the submodule into its parent repository and commit it.
|
||||
* reinstate any of the submodule's own submodules as part of the parent
|
||||
repository
|
||||
|
||||
NOTE: This script might completely garble your repository, so PLEASE apply
|
||||
this only to a fresh clone of the repository where it does not matter if
|
||||
the repo is destroyed. It would be wise to keep a backup clone of your
|
||||
repository, so that you can reconstitute it if need be. You have been
|
||||
warned. Use at your own risk.
|
||||
|
||||
EOF
|
||||
|
||||
request_confirmation "Do you want to proceed?"
|
||||
}
|
||||
|
||||
function git_version_lte() {
|
||||
OP_VERSION=$(printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' '\n' | head -n 4))
|
||||
GIT_VERSION=$(git version)
|
||||
GIT_VERSION=$(printf "%03d%03d%03d%03d" $(echo "${GIT_VERSION#git version }" | sed -E "s/([0-9.]*).*/\1/" | tr '.' '\n' | head -n 4))
|
||||
echo -e "${GIT_VERSION}\n${OP_VERSION}" | sort | head -n1
|
||||
[ ${GIT_VERSION} -le ${OP_VERSION} ]
|
||||
}
|
||||
|
||||
# Convert a url to an absolute url
|
||||
#
|
||||
# Parameters:
|
||||
# $1: The url to check
|
||||
# $2: The base url to use if $1 is a relative path
|
||||
#
|
||||
# Returns an absolute url
|
||||
function absolute_url {
|
||||
local url=$1
|
||||
local base=$2
|
||||
|
||||
if [[ $url =~ \.\. ]]; then
|
||||
echo "$base/$(basename $url)"
|
||||
else
|
||||
echo $url
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
warn
|
||||
|
||||
if [ "${verbose}" == "true" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Remove submodule and commit
|
||||
git config -f .gitmodules --remove-section "submodule.${sub}"
|
||||
if git config -f .git/config --get "submodule.${sub}.url"; then
|
||||
git config -f .git/config --remove-section "submodule.${sub}"
|
||||
fi
|
||||
rm -rf "${path}"
|
||||
git add -A .
|
||||
git commit -m "Remove submodule ${sub}"
|
||||
rm -rf ".git/modules/${sub}"
|
||||
|
||||
# Rewrite submodule history
|
||||
local tmpdir="$(mktemp -d -t submodule-rewrite-XXXXXX)"
|
||||
git clone -b "${branch}" "${url}" "${tmpdir}"
|
||||
pushd "${tmpdir}"
|
||||
local tab="$(printf '\t')"
|
||||
local filter="git ls-files -s | sed \"s:${tab}:${tab}${path}/:\" | GIT_INDEX_FILE=\${GIT_INDEX_FILE}.new git update-index --index-info && mv \${GIT_INDEX_FILE}.new \${GIT_INDEX_FILE} || true"
|
||||
git filter-branch --index-filter "${filter}" HEAD
|
||||
popd
|
||||
|
||||
# Merge in rewritten submodule history
|
||||
git remote add "${sub}" "${tmpdir}"
|
||||
git fetch "${sub}"
|
||||
|
||||
if git_version_lte 2.8.4
|
||||
then
|
||||
# Previous to git 2.9.0 the parameter would yield an error
|
||||
ALLOW_UNRELATED_HISTORIES=""
|
||||
else
|
||||
# From git 2.9.0 this parameter is required
|
||||
ALLOW_UNRELATED_HISTORIES="--allow-unrelated-histories"
|
||||
fi
|
||||
|
||||
git merge -s ours --no-commit ${ALLOW_UNRELATED_HISTORIES} "${sub}/${branch}"
|
||||
rm -rf tmpdir
|
||||
|
||||
# Add submodule content
|
||||
git clone -b "${branch}" "${url}" "${path}"
|
||||
|
||||
# Transfer its own submodules to the parent
|
||||
add_submod_cmds=""
|
||||
if [ -f ${path}/.gitmodules ]; then
|
||||
sub_names=$(git config -f ${path}/.gitmodules --get-regex path | sed 's/.* \(.*\)$/\1/g')
|
||||
|
||||
for sub_name in ${sub_names}; do
|
||||
sub_branch=$(git config -f ${path}/.gitmodules --get "submodule.${sub_name}.branch") || true
|
||||
[ -n "${sub_branch}" ] && sub_branch="-b ${sub_branch}"
|
||||
sub_path=$(git config -f ${path}/.gitmodules --get "submodule.${sub_name}.path")
|
||||
sub_url=$(git config -f ${path}/.gitmodules --get "submodule.${sub_name}.url")
|
||||
|
||||
# remove the sub-submodule (which should be empty) and cache the command to reinstate it
|
||||
rmdir ${path}/${sub_path}
|
||||
add_submod_cmds="$add_submod_cmds git submodule add ${sub_branch} --name ${sub_name} -- ${sub_url} ${path}/${sub_path} ; "
|
||||
done
|
||||
fi
|
||||
|
||||
rm -rf "${path}/.git" "${path}/.gitmodules"
|
||||
git add "${path}"
|
||||
if [ -n "${add_submod_cmds}" ]; then
|
||||
bash -c "${add_submod_cmds}"
|
||||
fi
|
||||
|
||||
git commit -m "Merge submodule contents for ${sub}/${branch}"
|
||||
git config -f .git/config --remove-section "remote.${sub}"
|
||||
|
||||
set +x
|
||||
echo "$(tput setaf 2)Submodule merge complete. Push changes after review.$(tput sgr0)"
|
||||
}
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
declare verbose=false
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
(-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
(-v|--verbose)
|
||||
verbose=true
|
||||
;;
|
||||
(*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
declare sub="${1:-}"
|
||||
declare branch="${2:-master}"
|
||||
|
||||
if [ -z "${sub}" ]; then
|
||||
>&2 echo "Error: No submodule specified"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
|
||||
if [ -n "${1:-}" ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -n "${1:-}" ]; then
|
||||
>&2 echo "Error: Unknown option: ${1:-}"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ -d ".git" ]; then
|
||||
>&2 echo "Error: No git repository found. Must be run from the root of a git repository"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
declare path="$(git config -f .gitmodules --get "submodule.${sub}.path")"
|
||||
declare superproject_dir="$(dirname $(git config --get remote.origin.url))"
|
||||
declare url=$(absolute_url $(git config -f .gitmodules --get "submodule.${sub}.url") $superproject_dir)
|
||||
|
||||
if [ -z "${path}" ]; then
|
||||
>&2 echo "Error: Submodule not found: ${sub}"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${superproject_dir}" ]; then
|
||||
>&2 echo "Error: Could not determine the remote origin for this superproject: ${superproject_dir}"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ -d "${path}" ]; then
|
||||
>&2 echo "Error: Submodule path not found: ${path}"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
main
|
||||
@@ -1,15 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
fhemdir=/home/marc/src/fhem
|
||||
fhem_mirror=$fhemdir/fhem-git
|
||||
myfhem=$fhemdir/my
|
||||
fhemdir=/dat/src/haus
|
||||
#fhem_mirror=$fhemdir/fhem-sf/code
|
||||
fhem_mirror=$fhemdir//fhem-svn
|
||||
|
||||
cd $fhem_mirror
|
||||
git svn rebase
|
||||
#git merge remotes/git-svn
|
||||
git push github master
|
||||
#cd $myfhem
|
||||
#git fetch origin
|
||||
#git push github master
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
LOGFILE=/tmp/podcatcher.log
|
||||
podcastdir=/dat/audio/podcast
|
||||
|
||||
set -x
|
||||
sleep
|
||||
sleep 1
|
||||
#swapon /dat/tmp/swap.img
|
||||
svdrpsend MESG "Podcasts aktualisieren-gestarted"
|
||||
cd /mp3/podcast
|
||||
#svdrpsend MESG "Podcasts aktualisieren-gestarted"
|
||||
cd $podcastdir
|
||||
echo "start ----------------------------" >> $LOGFILE
|
||||
date >> $LOGFILE
|
||||
./catch.sh >> $LOGFILE 2>&1
|
||||
svdrpsend MESG "Podcasts aktualisiert"
|
||||
./catch2.sh >> $LOGFILE 2>&1
|
||||
#svdrpsend MESG "Podcasts aktualisiert"
|
||||
#swapoff /dat/tmp/swap.img
|
||||
|
||||
2528
podcatcher
Executable file
2528
podcatcher
Executable file
File diff suppressed because it is too large
Load Diff
874
repo
Executable file
874
repo
Executable file
@@ -0,0 +1,874 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# repo default configuration
|
||||
#
|
||||
import os
|
||||
REPO_URL = os.environ.get('REPO_URL', None)
|
||||
if not REPO_URL:
|
||||
REPO_URL = 'https://gerrit.googlesource.com/git-repo'
|
||||
REPO_REV = 'stable'
|
||||
|
||||
# Copyright (C) 2008 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# increment this whenever we make important changes to this script
|
||||
VERSION = (1, 22)
|
||||
|
||||
# increment this if the MAINTAINER_KEYS block is modified
|
||||
KEYRING_VERSION = (1, 2)
|
||||
MAINTAINER_KEYS = """
|
||||
|
||||
Repo Maintainer <repo@android.kernel.org>
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Version: GnuPG v1.4.2.2 (GNU/Linux)
|
||||
|
||||
mQGiBEj3ugERBACrLJh/ZPyVSKeClMuznFIrsQ+hpNnmJGw1a9GXKYKk8qHPhAZf
|
||||
WKtrBqAVMNRLhL85oSlekRz98u41H5si5zcuv+IXJDF5MJYcB8f22wAy15lUqPWi
|
||||
VCkk1l8qqLiuW0fo+ZkPY5qOgrvc0HW1SmdH649uNwqCbcKb6CxaTxzhOwCgj3AP
|
||||
xI1WfzLqdJjsm1Nq98L0cLcD/iNsILCuw44PRds3J75YP0pze7YF/6WFMB6QSFGu
|
||||
aUX1FsTTztKNXGms8i5b2l1B8JaLRWq/jOnZzyl1zrUJhkc0JgyZW5oNLGyWGhKD
|
||||
Fxp5YpHuIuMImopWEMFIRQNrvlg+YVK8t3FpdI1RY0LYqha8pPzANhEYgSfoVzOb
|
||||
fbfbA/4ioOrxy8ifSoga7ITyZMA+XbW8bx33WXutO9N7SPKS/AK2JpasSEVLZcON
|
||||
ae5hvAEGVXKxVPDjJBmIc2cOe7kOKSi3OxLzBqrjS2rnjiP4o0ekhZIe4+ocwVOg
|
||||
e0PLlH5avCqihGRhpoqDRsmpzSHzJIxtoeb+GgGEX8KkUsVAhbQpUmVwbyBNYWlu
|
||||
dGFpbmVyIDxyZXBvQGFuZHJvaWQua2VybmVsLm9yZz6IYAQTEQIAIAUCSPe6AQIb
|
||||
AwYLCQgHAwIEFQIIAwQWAgMBAh4BAheAAAoJEBZTDV6SD1xl1GEAn0x/OKQpy7qI
|
||||
6G73NJviU0IUMtftAKCFMUhGb/0bZvQ8Rm3QCUpWHyEIu7kEDQRI97ogEBAA2wI6
|
||||
5fs9y/rMwD6dkD/vK9v4C9mOn1IL5JCPYMJBVSci+9ED4ChzYvfq7wOcj9qIvaE0
|
||||
GwCt2ar7Q56me5J+byhSb32Rqsw/r3Vo5cZMH80N4cjesGuSXOGyEWTe4HYoxnHv
|
||||
gF4EKI2LK7xfTUcxMtlyn52sUpkfKsCpUhFvdmbAiJE+jCkQZr1Z8u2KphV79Ou+
|
||||
P1N5IXY/XWOlq48Qf4MWCYlJFrB07xjUjLKMPDNDnm58L5byDrP/eHysKexpbakL
|
||||
xCmYyfT6DV1SWLblpd2hie0sL3YejdtuBMYMS2rI7Yxb8kGuqkz+9l1qhwJtei94
|
||||
5MaretDy/d/JH/pRYkRf7L+ke7dpzrP+aJmcz9P1e6gq4NJsWejaALVASBiioqNf
|
||||
QmtqSVzF1wkR5avZkFHuYvj6V/t1RrOZTXxkSk18KFMJRBZrdHFCWbc5qrVxUB6e
|
||||
N5pja0NFIUCigLBV1c6I2DwiuboMNh18VtJJh+nwWeez/RueN4ig59gRTtkcc0PR
|
||||
35tX2DR8+xCCFVW/NcJ4PSePYzCuuLvp1vEDHnj41R52Fz51hgddT4rBsp0nL+5I
|
||||
socSOIIezw8T9vVzMY4ArCKFAVu2IVyBcahTfBS8q5EM63mONU6UVJEozfGljiMw
|
||||
xuQ7JwKcw0AUEKTKG7aBgBaTAgT8TOevpvlw91cAAwUP/jRkyVi/0WAb0qlEaq/S
|
||||
ouWxX1faR+vU3b+Y2/DGjtXQMzG0qpetaTHC/AxxHpgt/dCkWI6ljYDnxgPLwG0a
|
||||
Oasm94BjZc6vZwf1opFZUKsjOAAxRxNZyjUJKe4UZVuMTk6zo27Nt3LMnc0FO47v
|
||||
FcOjRyquvgNOS818irVHUf12waDx8gszKxQTTtFxU5/ePB2jZmhP6oXSe4K/LG5T
|
||||
+WBRPDrHiGPhCzJRzm9BP0lTnGCAj3o9W90STZa65RK7IaYpC8TB35JTBEbrrNCp
|
||||
w6lzd74LnNEp5eMlKDnXzUAgAH0yzCQeMl7t33QCdYx2hRs2wtTQSjGfAiNmj/WW
|
||||
Vl5Jn+2jCDnRLenKHwVRFsBX2e0BiRWt/i9Y8fjorLCXVj4z+7yW6DawdLkJorEo
|
||||
p3v5ILwfC7hVx4jHSnOgZ65L9s8EQdVr1ckN9243yta7rNgwfcqb60ILMFF1BRk/
|
||||
0V7wCL+68UwwiQDvyMOQuqkysKLSDCLb7BFcyA7j6KG+5hpsREstFX2wK1yKeraz
|
||||
5xGrFy8tfAaeBMIQ17gvFSp/suc9DYO0ICK2BISzq+F+ZiAKsjMYOBNdH/h0zobQ
|
||||
HTHs37+/QLMomGEGKZMWi0dShU2J5mNRQu3Hhxl3hHDVbt5CeJBb26aQcQrFz69W
|
||||
zE3GNvmJosh6leayjtI9P2A6iEkEGBECAAkFAkj3uiACGwwACgkQFlMNXpIPXGWp
|
||||
TACbBS+Up3RpfYVfd63c1cDdlru13pQAn3NQy/SN858MkxN+zym86UBgOad2
|
||||
=CMiZ
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
Conley Owens <cco3@android.com>
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Version: GnuPG v1.4.11 (GNU/Linux)
|
||||
|
||||
mQENBFHRvc8BCADFg45Xx/y6QDC+T7Y/gGc7vx0ww7qfOwIKlAZ9xG3qKunMxo+S
|
||||
hPCnzEl3cq+6I1Ww/ndop/HB3N3toPXRCoN8Vs4/Hc7by+SnaLFnacrm+tV5/OgT
|
||||
V37Lzt8lhay1Kl+YfpFwHYYpIEBLFV9knyfRXS/428W2qhdzYfvB15/AasRmwmor
|
||||
py4NIzSs8UD/SPr1ihqNCdZM76+MQyN5HMYXW/ALZXUFG0pwluHFA7hrfPG74i8C
|
||||
zMiP7qvMWIl/r/jtzHioH1dRKgbod+LZsrDJ8mBaqsZaDmNJMhss9g76XvfMyLra
|
||||
9DI9/iFuBpGzeqBv0hwOGQspLRrEoyTeR6n1ABEBAAG0H0NvbmxleSBPd2VucyA8
|
||||
Y2NvM0BhbmRyb2lkLmNvbT6JATgEEwECACIFAlHRvc8CGwMGCwkIBwMCBhUIAgkK
|
||||
CwQWAgMBAh4BAheAAAoJEGe35EhpKzgsP6AIAJKJmNtn4l7hkYHKHFSo3egb6RjQ
|
||||
zEIP3MFTcu8HFX1kF1ZFbrp7xqurLaE53kEkKuAAvjJDAgI8mcZHP1JyplubqjQA
|
||||
xvv84gK+OGP3Xk+QK1ZjUQSbjOpjEiSZpRhWcHci3dgOUH4blJfByHw25hlgHowd
|
||||
a/2PrNKZVcJ92YienaxxGjcXEUcd0uYEG2+rwllQigFcnMFDhr9B71MfalRHjFKE
|
||||
fmdoypqLrri61YBc59P88Rw2/WUpTQjgNubSqa3A2+CKdaRyaRw+2fdF4TdR0h8W
|
||||
zbg+lbaPtJHsV+3mJC7fq26MiJDRJa5ZztpMn8su20gbLgi2ShBOaHAYDDi5AQ0E
|
||||
UdG9zwEIAMoOBq+QLNozAhxOOl5GL3StTStGRgPRXINfmViTsihrqGCWBBUfXlUE
|
||||
OytC0mYcrDUQev/8ToVoyqw+iGSwDkcSXkrEUCKFtHV/GECWtk1keyHgR10YKI1R
|
||||
mquSXoubWGqPeG1PAI74XWaRx8UrL8uCXUtmD8Q5J7mDjKR5NpxaXrwlA0bKsf2E
|
||||
Gp9tu1kKauuToZhWHMRMqYSOGikQJwWSFYKT1KdNcOXLQF6+bfoJ6sjVYdwfmNQL
|
||||
Ixn8QVhoTDedcqClSWB17VDEFDFa7MmqXZz2qtM3X1R/MUMHqPtegQzBGNhRdnI2
|
||||
V45+1Nnx/uuCxDbeI4RbHzujnxDiq70AEQEAAYkBHwQYAQIACQUCUdG9zwIbDAAK
|
||||
CRBnt+RIaSs4LNVeB/0Y2pZ8I7gAAcEM0Xw8drr4omg2fUoK1J33ozlA/RxeA/lJ
|
||||
I3KnyCDTpXuIeBKPGkdL8uMATC9Z8DnBBajRlftNDVZS3Hz4G09G9QpMojvJkFJV
|
||||
By+01Flw/X+eeN8NpqSuLV4W+AjEO8at/VvgKr1AFvBRdZ7GkpI1o6DgPe7ZqX+1
|
||||
dzQZt3e13W0rVBb/bUgx9iSLoeWP3aq/k+/GRGOR+S6F6BBSl0SQ2EF2+dIywb1x
|
||||
JuinEP+AwLAUZ1Bsx9ISC0Agpk2VeHXPL3FGhroEmoMvBzO0kTFGyoeT7PR/BfKv
|
||||
+H/g3HsL2LOB9uoIm8/5p2TTU5ttYCXMHhQZ81AY
|
||||
=AUp4
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
"""
|
||||
|
||||
GIT = 'git' # our git command
|
||||
MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version
|
||||
repodir = '.repo' # name of repo's private directory
|
||||
S_repo = 'repo' # special repo repository
|
||||
S_manifests = 'manifests' # special manifest repository
|
||||
REPO_MAIN = S_repo + '/main.py' # main script
|
||||
MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
|
||||
GITC_CONFIG_FILE = '/gitc/.config'
|
||||
GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
|
||||
|
||||
|
||||
import errno
|
||||
import optparse
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
else:
|
||||
import imp
|
||||
import urllib2
|
||||
urllib = imp.new_module('urllib')
|
||||
urllib.request = urllib2
|
||||
urllib.error = urllib2
|
||||
|
||||
|
||||
def _print(*objects, **kwargs):
|
||||
sep = kwargs.get('sep', ' ')
|
||||
end = kwargs.get('end', '\n')
|
||||
out = kwargs.get('file', sys.stdout)
|
||||
out.write(sep.join(objects) + end)
|
||||
|
||||
|
||||
# Python version check
|
||||
ver = sys.version_info
|
||||
if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
|
||||
_print('error: Python version %s unsupported.\n'
|
||||
'Please use Python 2.6 - 2.7 instead.'
|
||||
% sys.version.split(' ')[0], file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
home_dot_repo = os.path.expanduser('~/.repoconfig')
|
||||
gpg_dir = os.path.join(home_dot_repo, 'gnupg')
|
||||
|
||||
extra_args = []
|
||||
init_optparse = optparse.OptionParser(usage="repo init -u url [options]")
|
||||
|
||||
# Logging
|
||||
group = init_optparse.add_option_group('Logging options')
|
||||
group.add_option('-q', '--quiet',
|
||||
dest="quiet", action="store_true", default=False,
|
||||
help="be quiet")
|
||||
|
||||
# Manifest
|
||||
group = init_optparse.add_option_group('Manifest options')
|
||||
group.add_option('-u', '--manifest-url',
|
||||
dest='manifest_url',
|
||||
help='manifest repository location', metavar='URL')
|
||||
group.add_option('-b', '--manifest-branch',
|
||||
dest='manifest_branch',
|
||||
help='manifest branch or revision', metavar='REVISION')
|
||||
group.add_option('-m', '--manifest-name',
|
||||
dest='manifest_name',
|
||||
help='initial manifest file', metavar='NAME.xml')
|
||||
group.add_option('--mirror',
|
||||
dest='mirror', action='store_true',
|
||||
help='create a replica of the remote repositories '
|
||||
'rather than a client working directory')
|
||||
group.add_option('--reference',
|
||||
dest='reference',
|
||||
help='location of mirror directory', metavar='DIR')
|
||||
group.add_option('--depth', type='int', default=None,
|
||||
dest='depth',
|
||||
help='create a shallow clone with given depth; see git clone')
|
||||
group.add_option('--archive',
|
||||
dest='archive', action='store_true',
|
||||
help='checkout an archive instead of a git repository for '
|
||||
'each project. See git archive.')
|
||||
group.add_option('-g', '--groups',
|
||||
dest='groups', default='default',
|
||||
help='restrict manifest projects to ones with specified '
|
||||
'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
|
||||
metavar='GROUP')
|
||||
group.add_option('-p', '--platform',
|
||||
dest='platform', default="auto",
|
||||
help='restrict manifest projects to ones with a specified '
|
||||
'platform group [auto|all|none|linux|darwin|...]',
|
||||
metavar='PLATFORM')
|
||||
|
||||
|
||||
# Tool
|
||||
group = init_optparse.add_option_group('repo Version options')
|
||||
group.add_option('--repo-url',
|
||||
dest='repo_url',
|
||||
help='repo repository location', metavar='URL')
|
||||
group.add_option('--repo-branch',
|
||||
dest='repo_branch',
|
||||
help='repo branch or revision', metavar='REVISION')
|
||||
group.add_option('--no-repo-verify',
|
||||
dest='no_repo_verify', action='store_true',
|
||||
help='do not verify repo source code')
|
||||
|
||||
# Other
|
||||
group = init_optparse.add_option_group('Other options')
|
||||
group.add_option('--config-name',
|
||||
dest='config_name', action="store_true", default=False,
|
||||
help='Always prompt for name/e-mail')
|
||||
|
||||
|
||||
def _GitcInitOptions(init_optparse_arg):
|
||||
init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]")
|
||||
g = init_optparse_arg.add_option_group('GITC options')
|
||||
g.add_option('-f', '--manifest-file',
|
||||
dest='manifest_file',
|
||||
help='Optional manifest file to use for this GITC client.')
|
||||
g.add_option('-c', '--gitc-client',
|
||||
dest='gitc_client',
|
||||
help='The name of the gitc_client instance to create or modify.')
|
||||
|
||||
_gitc_manifest_dir = None
|
||||
|
||||
|
||||
def get_gitc_manifest_dir():
|
||||
global _gitc_manifest_dir
|
||||
if _gitc_manifest_dir is None:
|
||||
_gitc_manifest_dir = ''
|
||||
try:
|
||||
with open(GITC_CONFIG_FILE, 'r') as gitc_config:
|
||||
for line in gitc_config:
|
||||
match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
|
||||
if match:
|
||||
_gitc_manifest_dir = match.group('gitc_manifest_dir')
|
||||
except IOError:
|
||||
pass
|
||||
return _gitc_manifest_dir
|
||||
|
||||
|
||||
def gitc_parse_clientdir(gitc_fs_path):
|
||||
"""Parse a path in the GITC FS and return its client name.
|
||||
|
||||
@param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR.
|
||||
|
||||
@returns: The GITC client name
|
||||
"""
|
||||
if gitc_fs_path == GITC_FS_ROOT_DIR:
|
||||
return None
|
||||
if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR):
|
||||
manifest_dir = get_gitc_manifest_dir()
|
||||
if manifest_dir == '':
|
||||
return None
|
||||
if manifest_dir[-1] != '/':
|
||||
manifest_dir += '/'
|
||||
if gitc_fs_path == manifest_dir:
|
||||
return None
|
||||
if not gitc_fs_path.startswith(manifest_dir):
|
||||
return None
|
||||
return gitc_fs_path.split(manifest_dir)[1].split('/')[0]
|
||||
return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0]
|
||||
|
||||
|
||||
class CloneFailure(Exception):
|
||||
|
||||
"""Indicate the remote clone of repo itself failed.
|
||||
"""
|
||||
|
||||
|
||||
def _Init(args, gitc_init=False):
|
||||
"""Installs repo by cloning it over the network.
|
||||
"""
|
||||
if gitc_init:
|
||||
_GitcInitOptions(init_optparse)
|
||||
opt, args = init_optparse.parse_args(args)
|
||||
if args:
|
||||
init_optparse.print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
url = opt.repo_url
|
||||
if not url:
|
||||
url = REPO_URL
|
||||
extra_args.append('--repo-url=%s' % url)
|
||||
|
||||
branch = opt.repo_branch
|
||||
if not branch:
|
||||
branch = REPO_REV
|
||||
extra_args.append('--repo-branch=%s' % branch)
|
||||
|
||||
if branch.startswith('refs/heads/'):
|
||||
branch = branch[len('refs/heads/'):]
|
||||
if branch.startswith('refs/'):
|
||||
_print("fatal: invalid branch name '%s'" % branch, file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
|
||||
try:
|
||||
if gitc_init:
|
||||
gitc_manifest_dir = get_gitc_manifest_dir()
|
||||
if not gitc_manifest_dir:
|
||||
_print('fatal: GITC filesystem is not available. Exiting...',
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
gitc_client = opt.gitc_client
|
||||
if not gitc_client:
|
||||
gitc_client = gitc_parse_clientdir(os.getcwd())
|
||||
if not gitc_client:
|
||||
_print('fatal: GITC client (-c) is required.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
client_dir = os.path.join(gitc_manifest_dir, gitc_client)
|
||||
if not os.path.exists(client_dir):
|
||||
os.makedirs(client_dir)
|
||||
os.chdir(client_dir)
|
||||
if os.path.exists(repodir):
|
||||
# This GITC Client has already initialized repo so continue.
|
||||
return
|
||||
|
||||
os.mkdir(repodir)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
_print('fatal: cannot make %s directory: %s'
|
||||
% (repodir, e.strerror), file=sys.stderr)
|
||||
# Don't raise CloneFailure; that would delete the
|
||||
# name. Instead exit immediately.
|
||||
#
|
||||
sys.exit(1)
|
||||
|
||||
_CheckGitVersion()
|
||||
try:
|
||||
if NeedSetupGnuPG():
|
||||
can_verify = SetupGnuPG(opt.quiet)
|
||||
else:
|
||||
can_verify = True
|
||||
|
||||
dst = os.path.abspath(os.path.join(repodir, S_repo))
|
||||
_Clone(url, dst, opt.quiet)
|
||||
|
||||
if can_verify and not opt.no_repo_verify:
|
||||
rev = _Verify(dst, branch, opt.quiet)
|
||||
else:
|
||||
rev = 'refs/remotes/origin/%s^0' % branch
|
||||
|
||||
_Checkout(dst, branch, rev, opt.quiet)
|
||||
except CloneFailure:
|
||||
if opt.quiet:
|
||||
_print('fatal: repo init failed; run without --quiet to see why',
|
||||
file=sys.stderr)
|
||||
raise
|
||||
|
||||
|
||||
def ParseGitVersion(ver_str):
|
||||
if not ver_str.startswith('git version '):
|
||||
return None
|
||||
|
||||
num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
|
||||
to_tuple = []
|
||||
for num_str in num_ver_str.split('.')[:3]:
|
||||
if num_str.isdigit():
|
||||
to_tuple.append(int(num_str))
|
||||
else:
|
||||
to_tuple.append(0)
|
||||
return tuple(to_tuple)
|
||||
|
||||
|
||||
def _CheckGitVersion():
|
||||
cmd = [GIT, '--version']
|
||||
try:
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
except OSError as e:
|
||||
_print(file=sys.stderr)
|
||||
_print("fatal: '%s' is not available" % GIT, file=sys.stderr)
|
||||
_print('fatal: %s' % e, file=sys.stderr)
|
||||
_print(file=sys.stderr)
|
||||
_print('Please make sure %s is installed and in your path.' % GIT,
|
||||
file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
|
||||
ver_str = proc.stdout.read().strip()
|
||||
proc.stdout.close()
|
||||
proc.wait()
|
||||
|
||||
ver_act = ParseGitVersion(ver_str)
|
||||
if ver_act is None:
|
||||
_print('error: "%s" unsupported' % ver_str, file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
|
||||
if ver_act < MIN_GIT_VERSION:
|
||||
need = '.'.join(map(str, MIN_GIT_VERSION))
|
||||
_print('fatal: git %s or later required' % need, file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
|
||||
|
||||
def NeedSetupGnuPG():
|
||||
if not os.path.isdir(home_dot_repo):
|
||||
return True
|
||||
|
||||
kv = os.path.join(home_dot_repo, 'keyring-version')
|
||||
if not os.path.exists(kv):
|
||||
return True
|
||||
|
||||
kv = open(kv).read()
|
||||
if not kv:
|
||||
return True
|
||||
|
||||
kv = tuple(map(int, kv.split('.')))
|
||||
if kv < KEYRING_VERSION:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def SetupGnuPG(quiet):
|
||||
try:
|
||||
os.mkdir(home_dot_repo)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
_print('fatal: cannot make %s directory: %s'
|
||||
% (home_dot_repo, e.strerror), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
os.mkdir(gpg_dir, stat.S_IRWXU)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
_print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror),
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
env = os.environ.copy()
|
||||
env['GNUPGHOME'] = gpg_dir.encode()
|
||||
|
||||
cmd = ['gpg', '--import']
|
||||
try:
|
||||
proc = subprocess.Popen(cmd,
|
||||
env=env,
|
||||
stdin=subprocess.PIPE)
|
||||
except OSError as e:
|
||||
if not quiet:
|
||||
_print('warning: gpg (GnuPG) is not available.', file=sys.stderr)
|
||||
_print('warning: Installing it is strongly encouraged.', file=sys.stderr)
|
||||
_print(file=sys.stderr)
|
||||
return False
|
||||
|
||||
proc.stdin.write(MAINTAINER_KEYS)
|
||||
proc.stdin.close()
|
||||
|
||||
if proc.wait() != 0:
|
||||
_print('fatal: registering repo maintainer keys failed', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
_print()
|
||||
|
||||
fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
|
||||
fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n')
|
||||
fd.close()
|
||||
return True
|
||||
|
||||
|
||||
def _SetConfig(local, name, value):
|
||||
"""Set a git configuration option to the specified value.
|
||||
"""
|
||||
cmd = [GIT, 'config', name, value]
|
||||
if subprocess.Popen(cmd, cwd=local).wait() != 0:
|
||||
raise CloneFailure()
|
||||
|
||||
|
||||
def _InitHttp():
|
||||
handlers = []
|
||||
|
||||
mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
||||
try:
|
||||
import netrc
|
||||
n = netrc.netrc()
|
||||
for host in n.hosts:
|
||||
p = n.hosts[host]
|
||||
mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
|
||||
mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
|
||||
except: # pylint: disable=bare-except
|
||||
pass
|
||||
handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
|
||||
handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
|
||||
|
||||
if 'http_proxy' in os.environ:
|
||||
url = os.environ['http_proxy']
|
||||
handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
|
||||
if 'REPO_CURL_VERBOSE' in os.environ:
|
||||
handlers.append(urllib.request.HTTPHandler(debuglevel=1))
|
||||
handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
|
||||
urllib.request.install_opener(urllib.request.build_opener(*handlers))
|
||||
|
||||
|
||||
def _Fetch(url, local, src, quiet):
|
||||
if not quiet:
|
||||
_print('Get %s' % url, file=sys.stderr)
|
||||
|
||||
cmd = [GIT, 'fetch']
|
||||
if quiet:
|
||||
cmd.append('--quiet')
|
||||
err = subprocess.PIPE
|
||||
else:
|
||||
err = None
|
||||
cmd.append(src)
|
||||
cmd.append('+refs/heads/*:refs/remotes/origin/*')
|
||||
cmd.append('refs/tags/*:refs/tags/*')
|
||||
|
||||
proc = subprocess.Popen(cmd, cwd=local, stderr=err)
|
||||
if err:
|
||||
proc.stderr.read()
|
||||
proc.stderr.close()
|
||||
if proc.wait() != 0:
|
||||
raise CloneFailure()
|
||||
|
||||
|
||||
def _DownloadBundle(url, local, quiet):
|
||||
if not url.endswith('/'):
|
||||
url += '/'
|
||||
url += 'clone.bundle'
|
||||
|
||||
proc = subprocess.Popen(
|
||||
[GIT, 'config', '--get-regexp', 'url.*.insteadof'],
|
||||
cwd=local,
|
||||
stdout=subprocess.PIPE)
|
||||
for line in proc.stdout:
|
||||
m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
|
||||
if m:
|
||||
new_url = m.group(1)
|
||||
old_url = m.group(2)
|
||||
if url.startswith(old_url):
|
||||
url = new_url + url[len(old_url):]
|
||||
break
|
||||
proc.stdout.close()
|
||||
proc.wait()
|
||||
|
||||
if not url.startswith('http:') and not url.startswith('https:'):
|
||||
return False
|
||||
|
||||
dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
|
||||
try:
|
||||
try:
|
||||
r = urllib.request.urlopen(url)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code in [401, 403, 404]:
|
||||
return False
|
||||
_print('fatal: Cannot get %s' % url, file=sys.stderr)
|
||||
_print('fatal: HTTP error %s' % e.code, file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
except urllib.error.URLError as e:
|
||||
_print('fatal: Cannot get %s' % url, file=sys.stderr)
|
||||
_print('fatal: error %s' % e.reason, file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
try:
|
||||
if not quiet:
|
||||
_print('Get %s' % url, file=sys.stderr)
|
||||
while True:
|
||||
buf = r.read(8192)
|
||||
if buf == '':
|
||||
return True
|
||||
dest.write(buf)
|
||||
finally:
|
||||
r.close()
|
||||
finally:
|
||||
dest.close()
|
||||
|
||||
|
||||
def _ImportBundle(local):
|
||||
path = os.path.join(local, '.git', 'clone.bundle')
|
||||
try:
|
||||
_Fetch(local, local, path, True)
|
||||
finally:
|
||||
os.remove(path)
|
||||
|
||||
|
||||
def _Clone(url, local, quiet):
|
||||
"""Clones a git repository to a new subdirectory of repodir
|
||||
"""
|
||||
try:
|
||||
os.mkdir(local)
|
||||
except OSError as e:
|
||||
_print('fatal: cannot make %s directory: %s' % (local, e.strerror),
|
||||
file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
|
||||
cmd = [GIT, 'init', '--quiet']
|
||||
try:
|
||||
proc = subprocess.Popen(cmd, cwd=local)
|
||||
except OSError as e:
|
||||
_print(file=sys.stderr)
|
||||
_print("fatal: '%s' is not available" % GIT, file=sys.stderr)
|
||||
_print('fatal: %s' % e, file=sys.stderr)
|
||||
_print(file=sys.stderr)
|
||||
_print('Please make sure %s is installed and in your path.' % GIT,
|
||||
file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
if proc.wait() != 0:
|
||||
_print('fatal: could not create %s' % local, file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
|
||||
_InitHttp()
|
||||
_SetConfig(local, 'remote.origin.url', url)
|
||||
_SetConfig(local,
|
||||
'remote.origin.fetch',
|
||||
'+refs/heads/*:refs/remotes/origin/*')
|
||||
if _DownloadBundle(url, local, quiet):
|
||||
_ImportBundle(local)
|
||||
_Fetch(url, local, 'origin', quiet)
|
||||
|
||||
|
||||
def _Verify(cwd, branch, quiet):
|
||||
"""Verify the branch has been signed by a tag.
|
||||
"""
|
||||
cmd = [GIT, 'describe', 'origin/%s' % branch]
|
||||
proc = subprocess.Popen(cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
cwd=cwd)
|
||||
cur = proc.stdout.read().strip()
|
||||
proc.stdout.close()
|
||||
|
||||
proc.stderr.read()
|
||||
proc.stderr.close()
|
||||
|
||||
if proc.wait() != 0 or not cur:
|
||||
_print(file=sys.stderr)
|
||||
_print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
|
||||
m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
|
||||
if m:
|
||||
cur = m.group(1)
|
||||
if not quiet:
|
||||
_print(file=sys.stderr)
|
||||
_print("info: Ignoring branch '%s'; using tagged release '%s'"
|
||||
% (branch, cur), file=sys.stderr)
|
||||
_print(file=sys.stderr)
|
||||
|
||||
env = os.environ.copy()
|
||||
env['GNUPGHOME'] = gpg_dir.encode()
|
||||
|
||||
cmd = [GIT, 'tag', '-v', cur]
|
||||
proc = subprocess.Popen(cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
cwd=cwd,
|
||||
env=env)
|
||||
out = proc.stdout.read()
|
||||
proc.stdout.close()
|
||||
|
||||
err = proc.stderr.read()
|
||||
proc.stderr.close()
|
||||
|
||||
if proc.wait() != 0:
|
||||
_print(file=sys.stderr)
|
||||
_print(out, file=sys.stderr)
|
||||
_print(err, file=sys.stderr)
|
||||
_print(file=sys.stderr)
|
||||
raise CloneFailure()
|
||||
return '%s^0' % cur
|
||||
|
||||
|
||||
def _Checkout(cwd, branch, rev, quiet):
|
||||
"""Checkout an upstream branch into the repository and track it.
|
||||
"""
|
||||
cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
|
||||
if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
|
||||
raise CloneFailure()
|
||||
|
||||
_SetConfig(cwd, 'branch.default.remote', 'origin')
|
||||
_SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)
|
||||
|
||||
cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
|
||||
if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
|
||||
raise CloneFailure()
|
||||
|
||||
cmd = [GIT, 'read-tree', '--reset', '-u']
|
||||
if not quiet:
|
||||
cmd.append('-v')
|
||||
cmd.append('HEAD')
|
||||
if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
|
||||
raise CloneFailure()
|
||||
|
||||
|
||||
def _FindRepo():
|
||||
"""Look for a repo installation, starting at the current directory.
|
||||
"""
|
||||
curdir = os.getcwd()
|
||||
repo = None
|
||||
|
||||
olddir = None
|
||||
while curdir != '/' \
|
||||
and curdir != olddir \
|
||||
and not repo:
|
||||
repo = os.path.join(curdir, repodir, REPO_MAIN)
|
||||
if not os.path.isfile(repo):
|
||||
repo = None
|
||||
olddir = curdir
|
||||
curdir = os.path.dirname(curdir)
|
||||
return (repo, os.path.join(curdir, repodir))
|
||||
|
||||
|
||||
class _Options(object):
|
||||
help = False
|
||||
|
||||
|
||||
def _ParseArguments(args):
|
||||
cmd = None
|
||||
opt = _Options()
|
||||
arg = []
|
||||
|
||||
for i in range(len(args)):
|
||||
a = args[i]
|
||||
if a == '-h' or a == '--help':
|
||||
opt.help = True
|
||||
|
||||
elif not a.startswith('-'):
|
||||
cmd = a
|
||||
arg = args[i + 1:]
|
||||
break
|
||||
return cmd, opt, arg
|
||||
|
||||
|
||||
def _Usage():
|
||||
gitc_usage = ""
|
||||
if get_gitc_manifest_dir():
|
||||
gitc_usage = " gitc-init Initialize a GITC Client.\n"
|
||||
|
||||
_print(
|
||||
"""usage: repo COMMAND [ARGS]
|
||||
|
||||
repo is not yet installed. Use "repo init" to install it here.
|
||||
|
||||
The most commonly used repo commands are:
|
||||
|
||||
init Install repo in the current working directory
|
||||
""" + gitc_usage +
|
||||
""" help Display detailed help on a command
|
||||
|
||||
For access to the full online help, install repo ("repo init").
|
||||
""", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _Help(args):
|
||||
if args:
|
||||
if args[0] == 'init':
|
||||
init_optparse.print_help()
|
||||
sys.exit(0)
|
||||
elif args[0] == 'gitc-init':
|
||||
_GitcInitOptions(init_optparse)
|
||||
init_optparse.print_help()
|
||||
sys.exit(0)
|
||||
else:
|
||||
_print("error: '%s' is not a bootstrap command.\n"
|
||||
' For access to online help, install repo ("repo init").'
|
||||
% args[0], file=sys.stderr)
|
||||
else:
|
||||
_Usage()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _NotInstalled():
|
||||
_print('error: repo is not installed. Use "repo init" to install it here.',
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _NoCommands(cmd):
|
||||
_print("""error: command '%s' requires repo to be installed first.
|
||||
Use "repo init" to install it here.""" % cmd, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _RunSelf(wrapper_path):
|
||||
my_dir = os.path.dirname(wrapper_path)
|
||||
my_main = os.path.join(my_dir, 'main.py')
|
||||
my_git = os.path.join(my_dir, '.git')
|
||||
|
||||
if os.path.isfile(my_main) and os.path.isdir(my_git):
|
||||
for name in ['git_config.py',
|
||||
'project.py',
|
||||
'subcmds']:
|
||||
if not os.path.exists(os.path.join(my_dir, name)):
|
||||
return None, None
|
||||
return my_main, my_git
|
||||
return None, None
|
||||
|
||||
|
||||
def _SetDefaultsTo(gitdir):
|
||||
global REPO_URL
|
||||
global REPO_REV
|
||||
|
||||
REPO_URL = gitdir
|
||||
proc = subprocess.Popen([GIT,
|
||||
'--git-dir=%s' % gitdir,
|
||||
'symbolic-ref',
|
||||
'HEAD'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
REPO_REV = proc.stdout.read().strip()
|
||||
proc.stdout.close()
|
||||
|
||||
proc.stderr.read()
|
||||
proc.stderr.close()
|
||||
|
||||
if proc.wait() != 0:
|
||||
_print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main(orig_args):
|
||||
cmd, opt, args = _ParseArguments(orig_args)
|
||||
|
||||
repo_main, rel_repo_dir = None, None
|
||||
# Don't use the local repo copy, make sure to switch to the gitc client first.
|
||||
if cmd != 'gitc-init':
|
||||
repo_main, rel_repo_dir = _FindRepo()
|
||||
|
||||
wrapper_path = os.path.abspath(__file__)
|
||||
my_main, my_git = _RunSelf(wrapper_path)
|
||||
|
||||
cwd = os.getcwd()
|
||||
if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()):
|
||||
_print('error: repo cannot be used in the GITC local manifest directory.'
|
||||
'\nIf you want to work on this GITC client please rerun this '
|
||||
'command from the corresponding client under /gitc/',
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if not repo_main:
|
||||
if opt.help:
|
||||
_Usage()
|
||||
if cmd == 'help':
|
||||
_Help(args)
|
||||
if not cmd:
|
||||
_NotInstalled()
|
||||
if cmd == 'init' or cmd == 'gitc-init':
|
||||
if my_git:
|
||||
_SetDefaultsTo(my_git)
|
||||
try:
|
||||
_Init(args, gitc_init=(cmd == 'gitc-init'))
|
||||
except CloneFailure:
|
||||
shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True)
|
||||
sys.exit(1)
|
||||
repo_main, rel_repo_dir = _FindRepo()
|
||||
else:
|
||||
_NoCommands(cmd)
|
||||
|
||||
if my_main:
|
||||
repo_main = my_main
|
||||
|
||||
ver_str = '.'.join(map(str, VERSION))
|
||||
me = [sys.executable, repo_main,
|
||||
'--repo-dir=%s' % rel_repo_dir,
|
||||
'--wrapper-version=%s' % ver_str,
|
||||
'--wrapper-path=%s' % wrapper_path,
|
||||
'--']
|
||||
me.extend(orig_args)
|
||||
me.extend(extra_args)
|
||||
try:
|
||||
os.execv(sys.executable, me)
|
||||
except OSError as e:
|
||||
_print("fatal: unable to start %s" % repo_main, file=sys.stderr)
|
||||
_print("fatal: %s" % e, file=sys.stderr)
|
||||
sys.exit(148)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if ver[0] == 3:
|
||||
_print('warning: Python 3 support is currently experimental. YMMV.\n'
|
||||
'Please use Python 2.6 - 2.7 instead.',
|
||||
file=sys.stderr)
|
||||
main(sys.argv[1:])
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
srcdir=/dat/audio/auto
|
||||
# sudo mount -o uid=marc /dev/sdt1 /media/hdext
|
||||
rsync -a --no-o --no-p --no-g -L --modify-window 1 --stats --delete --progress /mp3/auto/ /media/hdext/
|
||||
rsync -a --no-o --no-p --no-g -L --modify-window 1 --stats --delete --progress $srcdir /media/hdext/
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# So sehen die Dateien aus:
|
||||
# http://www.taz.de/cgi-bin/digiabo/2007_04_17_HTM.zip
|
||||
|
||||
TAZDIR=/media/nas/books/taz
|
||||
TAZDIR=/dat/books/taz
|
||||
TAZUSER=103450
|
||||
TAZPASSWD=oxculo
|
||||
TAZTYPE=.pdf
|
||||
@@ -74,4 +74,4 @@ do
|
||||
done
|
||||
|
||||
# Sync to Dropbox
|
||||
bash /home/marc/bin/tazsync.sh
|
||||
bash $HOME/bin/tazsync.sh
|
||||
|
||||
10
tazsync.sh
10
tazsync.sh
@@ -1,8 +1,8 @@
|
||||
|
||||
daysback=10
|
||||
daysback=22
|
||||
|
||||
srcdir=/dat/books/taz
|
||||
dstdir=/home/marc/Dropbox-ipad/taz
|
||||
dstdir=/dat/docu/sync/taz
|
||||
tmpdir=/tmp
|
||||
|
||||
[ -d $dstdir ] || exit
|
||||
@@ -15,10 +15,14 @@ find . -type f | sort> $tmpdir/alt.lst
|
||||
cd $srcdir
|
||||
find . -mtime -$daysback -name "*.epub" | sort > $tmpdir/new.lst
|
||||
|
||||
rsync --files-from=$tmpdir/new.lst . $dstdir/
|
||||
#exit
|
||||
|
||||
diff $tmpdir/new.lst $tmpdir/all.lst | grep "^<" | sed "s/^< //" > $tmpdir/added.lst
|
||||
rsync --files-from=$tmpdir/added.lst --progress . $dstdir/
|
||||
|
||||
cd $dstdir
|
||||
|
||||
|
||||
cat $tmpdir/alt.lst $tmpdir/new.lst | sort -u > $tmpdir/all.lst
|
||||
cat $tmpdir/all.lst
|
||||
cat $tmpdir/new.lst
|
||||
|
||||
16
vdr-reload.sh
Normal file
16
vdr-reload.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
sudo service vdr stop
|
||||
cd ~/src/vdr/dvbsky-current
|
||||
sudo make rmmod
|
||||
sudo make rmmod
|
||||
sudo rmmod cx2341x
|
||||
sudo rmmod v4l2_common
|
||||
sudo rmmod videobuf2_core
|
||||
sudo rmmod videobuf2_v4l2
|
||||
sudo rmmod videobuf2_core
|
||||
sudo make rmmod
|
||||
|
||||
sudo modprobe cx2341x cx23885 videobuf2_v4l2 cx25840 videobuf2_v4l2 videobuf2_core
|
||||
sudo service vdr start
|
||||
|
||||
54
vdr2mp3.rb
Normal file
54
vdr2mp3.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
require 'fileutils'
|
||||
|
||||
def split_all(path)
|
||||
head, tail = File.split(path)
|
||||
return [tail] if head == '.' || tail == '/'
|
||||
return [head, tail] if head == '/'
|
||||
return split_all(head) + [tail]
|
||||
end
|
||||
|
||||
|
||||
vidroot="/dat/video/vdr"
|
||||
outdir="/dat/audio/vdr"
|
||||
recdir=vidroot+"/"+ARGV.at(0)
|
||||
#puts "p:#{p}"
|
||||
|
||||
# aus videopfad extraieren
|
||||
dirsplitted=split_all(recdir)
|
||||
if dirsplitted.length >= 2
|
||||
namedir=dirsplitted.at(-2).gsub("%", "")
|
||||
datedir=dirsplitted.at(-1)
|
||||
end
|
||||
#puts "dn:#{namedir}"
|
||||
|
||||
# Titel und Datum aus Infofile holen
|
||||
infofile=recdir+"/info"
|
||||
infofile=recdir+"/info.vdr" unless File.exists?(infofile)
|
||||
puts "infofile:#{infofile}"
|
||||
title=open(infofile).grep(/^\s*T/).to_s.gsub("T","")
|
||||
tim=open(infofile).grep(/^\s*E/).to_s.split(" ").at(2)
|
||||
t=Time.at(tim.to_i)
|
||||
#puts "time:#{t.to_s}"
|
||||
#puts "tim:#{tim}"
|
||||
|
||||
#Zielverzeichnisbaum anlegen
|
||||
outdir=outdir+"/"+namedir
|
||||
Dir::mkdir(outdir) unless File.exists?(outdir)
|
||||
outdir=outdir+"/"+datedir
|
||||
Dir::mkdir(outdir) unless File.exists?(outdir)
|
||||
# Infofile kopieren
|
||||
FileUtils.cp(infofile, outdir)
|
||||
|
||||
# Kommando zum konvertieren
|
||||
recfile=recdir+"/00001.ts"
|
||||
recfile=recdir+"/001.vdr" unless File.exists?(recfile)
|
||||
title=title.to_s.strip
|
||||
bitrate="128k"
|
||||
samplerate="44100"
|
||||
outfile=outdir+"/"+namedir+".mp3"
|
||||
author="vdr"
|
||||
yr=t.year
|
||||
cmd="avconv -i #{recfile} -acodec libmp3lame -f mp3 -metadata title='#{title}' -metadata author=#{author} -metadata year=#{yr} -ss 00:00:00 -ab #{bitrate} -ar #{samplerate} -threads auto #{outfile}"
|
||||
puts "cmd:#{cmd}"
|
||||
exec(cmd)
|
||||
puts "Fertig."
|
||||
18
vdr2mp3.sh
Normal file
18
vdr2mp3.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
outfile=$1.mp3
|
||||
|
||||
|
||||
[ -z $vdrts ] && vdrts=00001.ts
|
||||
[ -z $outfile ] && outfile="out.mp3"
|
||||
|
||||
title=""
|
||||
author=""
|
||||
year=$(date "+%Y")
|
||||
album="vdr"
|
||||
|
||||
|
||||
avconv -i $vdrts -acodec libmp3lame -f mp3 -metadata title=$title -metadata author=$author -metadata year=$year -metadata album=$album -ss 00:\
|
||||
00:00 -ab 128k -ar 44100 -threads auto $outfile
|
||||
|
||||
|
||||
|
||||
|
||||
28
zeitsync.sh
Normal file
28
zeitsync.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
daysback=40
|
||||
|
||||
srcdir=/dat/books/zeit
|
||||
dstdir=/dat/docu/sync/zeit
|
||||
tmpdir=/tmp
|
||||
|
||||
[ -d $dstdir ] || exit
|
||||
[ -d $srcdir ] || exit
|
||||
[ -d $tmpdir ] || exit
|
||||
|
||||
cd $dstdir
|
||||
find . -type f | sort> $tmpdir/alt.lst
|
||||
|
||||
cd $srcdir
|
||||
find . -mtime -$daysback -name "*.epub" | sort > $tmpdir/new.lst
|
||||
|
||||
|
||||
rsync --files-from=$tmpdir/new.lst --progress . $dstdir/
|
||||
|
||||
cd $dstdir
|
||||
|
||||
|
||||
cat $tmpdir/alt.lst $tmpdir/new.lst | sort -u > $tmpdir/all.lst
|
||||
cat $tmpdir/all.lst
|
||||
cat $tmpdir/new.lst
|
||||
diff $tmpdir/new.lst $tmpdir/all.lst | grep "^>" | sed "s/^> //" | xargs rm
|
||||
# $rmfiles
|
||||
Reference in New Issue
Block a user