auto commit on 2019-07-05 18:23 master
authorKilian Saffran <ksaffran@dks.lu>
Fri, 5 Jul 2019 16:23:10 +0000 (18:23 +0200)
committerKilian Saffran <ksaffran@dks.lu>
Fri, 5 Jul 2019 16:23:10 +0000 (18:23 +0200)
bin/encode_base64.pl
bin/githelper.pl
bin/githelpermac.pl [new file with mode: 0644]
bin/solanagit.pl [new file with mode: 0644]

index b4e5208..e0e4535 100644 (file)
@@ -1,12 +1,23 @@
-#!/usr/bin/perl
+#!C:\Strawberry\perl\bin\perl.exe
 
 use strict;
 use URI::Encode;
 use MIME::Base64; 
-my $str='';
+my $infile='C:\Users\ksaff\Pictures\Apps\juridig\logo-juridig_h100.png';
+my $outfile='C:\Users\ksaff\Pictures\Apps\juridig\logo-juridig_h100.b64.txt';
 
-my $b64 = MIME::Base64::decode_base64($str);
-open (FF,">encoded.txt");
+local $/=undef;
+my $raw = "";
+open (my $img,$infile);
+binmode $img;
+my $raw = <$img>;
+close($img);
+#
+my $b64 = MIME::Base64::encode_base64($raw);
+$b64 =~ s/\n//g;
+open (FF,">".$outfile);
+binmode(FF);
+print FF "data:image/png;base64,";
 print FF $b64;
 close(FF);
-print '=>'.$b64;
+#print '=>'.$b64;
index c4a93db..addf6e9 100644 (file)
@@ -1,4 +1,4 @@
-#!C:\Strawberry\perl\bin\perl.exe
+#!/usr/bin/env perl
 
 use strict;
 use File::Basename;
diff --git a/bin/githelpermac.pl b/bin/githelpermac.pl
new file mode 100644 (file)
index 0000000..60a5e2e
--- /dev/null
@@ -0,0 +1,95 @@
+#!/usr/bin/env perl
+
+use strict;
+use File::Basename;
+# use File::Find::Rule;
+# use Data::Dumper;
+use Getopt::Long;
+use Cwd;
+use POSIX qw (strftime);
+my $basepath = "/Volumes/Macintosh2 HD/backup/1-Neuer Server";
+my $logfile = "/Volumes/Macintosh2 HD/log/githelper.".strftime("%Y%m%d",localtime()).".log";
+open(LOG,">>".$logfile);
+# my @wksp = ($ENV{HOME}.'/Workspace',$ENV{HOME}.'/Workspace/Websites',$ENV{HOME}.'/Workspace/Apps');
+# if ($^O eq "MSWin32"){
+#   @wksp = ($ENV{USERPROFILE}.'/Workspace',$ENV{USERPROFILE}.'/Workspace/Websites',$ENV{HOME}.'/Workspace/Apps');
+#   $wksp[0] =~ s/\\/\//g;
+#   $wksp[1] =~ s/\\/\//g;
+#   $wksp[2] =~ s/\\/\//g;
+# }
+my $get = 0;
+my $set = 0;
+my $check = 0;
+GetOptions("get" => \$get,"set" => \$set, "check" => \$check);
+#print $wksp."\n";
+#print ."\n";
+my $git='/usr/local/bin/git';
+if ($check == 1){
+        my @testgit = `find "$basepath" -type d -depth 2`;
+        foreach my $t (@testgit){
+                chomp($t);
+                if (($t =~ /^$basepath\/.=/) && (! -d $t.'/.git')){
+                        if (basename($t) =~ /^\w+\d\d\d\d\w+/ ){
+                                chdir($t) or die "cannot change dir to '$t'!";
+                                print LOG "automated git init: '$t'\n";
+                                my $ret = `$git init`;
+                                print LOG $ret."\n";
+                        }else {
+                                print LOG "Needs MANUAL git init: '$t'\n";
+                        }
+                }
+
+        }
+}
+
+if ($get == 1){
+  my @rep = `find "$basepath" -type d -depth 3 -name ".git"`;
+  foreach my $r (@rep){
+    chomp($r);
+    $r = dirname($r);
+    if (! -d $r.'/.git'){
+        print LOG "$r: Nothing to do! Not a GIT-Repository!\n";
+        next();
+    }
+    print LOG "repo:sitory ".$r."!\n";
+    chdir($r) or die "cannot change dir to '$r'!";
+    #print "CWD:".getcwd()."\n";
+    my $ret = `$git status`;
+    #my $ret = `git pull`;
+    print LOG $ret."\n---\n";
+  }
+}
+if ($set == 1){
+my @rep = `find "$basepath" -type d -depth 3 -name ".git"`;
+foreach my $r (@rep){
+  chomp($r);
+  $r = dirname($r);
+  if (! -d $r.'/.git'){
+    print LOG "$r: Nothing to do! Not a GIT-Repository!\n";
+    next();
+  }
+  chdir($r) or die "cannot change dir to '$r'!";
+  my $ret = `$git status`;
+  if ($ret =~ /nothing to commit, working tree clean/){
+    print LOG "repository ".basename($r)." OK!\n";
+    next;
+  } elsif (($ret =~ /Changes not staged for commit/) || ($ret =~ /Untracked files/)){
+    print LOG "repository ".basename($r)." changes to add,commit and push!\n";
+    my $add = `$git add -A`;
+    print LOG "Data Added:".$add."\n";
+    my $msg = "Version ".strftime("%Y-%m-%d %H:%M",localtime());
+    my $commit = `$git commit -m "$msg"`;
+    print LOG "Data Commited:".$commit."\n";
+    #my $push = `$git push`;
+    #if ($push =~ /\!\s\[rejected\]/){
+    #  my $pull = `git pull`;
+    #  print "Data pulled:".$pull."\n";
+    #  $push = `git push`;
+    #  print "Data pushed:".$push."\n";
+    #}
+    $ret = `$git status`;
+    print LOG $ret."\n---\n";
+  }
+}
+}
+close(LOG);
diff --git a/bin/solanagit.pl b/bin/solanagit.pl
new file mode 100644 (file)
index 0000000..aad072e
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+
+use strict;
+use POSIX;
+use File::Basename;
+use utf8;
+use lib (dirname($0));
+#use URL::Encode qw(url_encode);
+use CGI::Util qw(escape);
+
+my $config = { basesource => "/Volumes/Macintosh2 HD/Backup/1-Neuer Server", defaultlevel => 2,  exclude => ['Z-outils'] };
+my $todaydate = POSIX::strftime('%Y-%m-%d',localtime);
+chdir $config->{basesource};
+#print getcwd()."\n";
+my $deflevel = $config->{defaultlevel};
+my $strdirs = `find . -type d -depth $deflevel | grep -v ".git"`;
+my @dirs = split("\n",$strdirs);
+foreach my $d (@dirs){
+        chdir($config->{basesource});
+        $d = substr($d,2);
+        chdir($d);
+        #print getcwd()."\n";
+        if (($d =~ /^\./) || ($d =~ /\/\./)){
+                next;
+        }
+        if ($d =~ /^Z-outils/){
+                #print "$d excluded!\n";
+                next;
+        }
+
+        my @x = grep(/$d/,@{$config->{exclude}});
+        if (scalar(@x) > 0){
+        #       print "$d EXCLUDED!\n";
+                next;
+        }
+        if (! -d '.git'){
+        #       print "init git\n";
+                system ('git init');
+                system ('echo "'.basename($d).'" > .git/description' );
+                system ('git config --global core.autocrlf false');
+
+        }
+        my $gitfiles = `git ls-files`;
+        my @files = split("\n",$gitfiles);
+        foreach my $f (@files){
+                if (! -e $f){
+                        system ('git rm "'.$f.'"');
+                }
+         }
+        #print "git add files\n";
+        system('git add .');
+        #print "git commit files\n";
+        system('git commit -a -m "'.$todaydate.'"');
+}
+# chdir dirname($0);
+# my $project_list_cmd = 'find "'.$config->{basesource}.'" -type d -name ".git"';
+# my $prlists = `$project_list_cmd`;
+# my @pr = split("\n",$prlists);
+
+# open (GWP,">".dirname($0).'/web/gitweb_projects.conf') or die "Cannot write file!\n";
+# my $basedir = $config->{basesource}.'/';
+# foreach my $p (@pr){
+#       if ($p ne ""){
+#               my $x = substr($p,length($basedir));
+##              print $x."\n";
+#               print GWP escape($x).' '.$ENV{USER}."\n";
+#       }
+# }
+
+# close(GWP);