diff options
author | Erich Eckner <git@eckner.net> | 2015-10-26 13:58:35 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2015-10-26 15:19:04 +0100 |
commit | e92f46e2a7c2966c12241f5a56f476a9d44af4c8 (patch) | |
tree | 5efa5f8056b298a50b095cd5fc5816db845ae423 /gitupdateunit.pas | |
parent | bce9c94943cc80889f37b9aac042b76ee154557d (diff) | |
download | units-e92f46e2a7c2966c12241f5a56f476a9d44af4c8.tar.xz |
neue Datei: gitupdateunit.pas
Diffstat (limited to 'gitupdateunit.pas')
-rw-r--r-- | gitupdateunit.pas | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/gitupdateunit.pas b/gitupdateunit.pas new file mode 100644 index 0000000..37d3409 --- /dev/null +++ b/gitupdateunit.pas @@ -0,0 +1,67 @@ +unit gitupdateunit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils; + +implementation + +uses + baseunix, process, systemunit, lowlevelunit; + +var + updated: boolean; + myDir,baseDir, + output,tmpFile: string; + args: array of string; + +initialization + updated:=false; + + myDir:=extractFilePath(paramstr(0)); + baseDir:=extractFilePath(leftStr(myDir,length(myDir)-1)); + + tmpFile:=''; + + output:=''; + setlength(args,1); + args[0]:='pull'; + if runCommandInDir(myDir,'/usr/bin/git',args,output) then begin + updated:=updated or (output<>'Already up-to-date.'#10); + if runCommandInDir(baseDir+'units','/usr/bin/git',args,output) then begin + updated:=updated or (output<>'Already up-to-date.'#10); + if updated then begin + setlength(args,4); + args[0]:='-Fu../units'; + args[1]:='-Mobjpas'; + tmpFile:=myDir+extractFileName(paramstr(0)); + if fileexists(tmpFile+'.lpr') then + args[2]:=tmpFile+'.lpr' + else + args[2]:=tmpFile+'.pas'; + tmpFile:=mkTemp('/tmp/fpc.XXXXXX'); + args[3]:='-o'+tmpFile; + if runCommandInDir(myDir,'/usr/bin/fpc',args,output) then begin + setlength(args,2); + args[0]:=tmpFile; + args[1]:=paramstr(0); + if runCommand('/usr/bin/sha512sum',args,output) then begin + baseDir:=erstesArgument(output,#10); + if erstesArgument(baseDir)<>erstesArgument(output) then begin + deletefile(paramstr(0)); + if runCommand('/usr/bin/mv',args,output) then + fpExecVe(paramstr(0),argv,envp); + end; + end; + end; + end; + end; + end; + if (tmpFile<>'') and fileexists(tmpFile) then + deletefile(tmpFile); + setlength(args,0); +end. + |