Commit e02dd192a00919f0aa49ce5298d21acbff8b96f9
- Diff rendering mode:
- inline
- side by side
lib/ipkinstall.pas
(10 / 28)
|   | |||
| 532 | 532 | end; | |
| 533 | 533 | end; | |
| 534 | 534 | ||
| 535 | if not pkg.UnpackFile('arcinfo.pin') then | ||
| 535 | if not pkg.UnpackControlFile('arcinfo.pin') then | ||
| 536 | 536 | begin | |
| 537 | 537 | MakeUsrRequest(rsExtractError + #10 + rsPkgDM + #10 + rsABLoad, rqError); | |
| 538 | 538 | Emergency_FreeAll(); | |
| … | … | ||
| 568 | 568 | IIconPath := cont.Icon; | |
| 569 | 569 | if IIconPath <> '' then | |
| 570 | 570 | begin | |
| 571 | pkg.UnpackFile(IIconPath); | ||
| 571 | pkg.UnpackControlFile(IIconPath); | ||
| 572 | 572 | IIconPath := CleanFilePath(pkg.WDir + IIconPath); | |
| 573 | 573 | end; | |
| 574 | 574 | ||
| … | … | ||
| 600 | 600 | for i := 0 to PkProfiles.Count - 1 do | |
| 601 | 601 | begin | |
| 602 | 602 | msg(StrSubst(rsFoundInstallProfileX, '%s', PkProfiles[PkProfiles.Count - 1])); | |
| 603 | pkg.UnpackFile('pkgdata/fileinfo-' + IntToStr(i) + '.id'); | ||
| 603 | pkg.UnpackControlFile('pkgdata/fileinfo-' + IntToStr(i) + '.id'); | ||
| 604 | 604 | end; | |
| 605 | 605 | ||
| 606 | 606 | IAppName := cont.AppName; | |
| … | … | ||
| 637 | 637 | FWizImage := GetDataFile('graphics/wizardimage.png'); | |
| 638 | 638 | if (FWizImage <> '') and (FWizImage[1] = '/') then | |
| 639 | 639 | begin | |
| 640 | pkg.UnpackFile(FWizImage); | ||
| 640 | pkg.UnpackControlFile(FWizImage); | ||
| 641 | 641 | if FileExists(pkg.WDir + FWizImage) then | |
| 642 | 642 | FWizImage := CleanFilePath(pkg.WDir + FWizImage); | |
| 643 | 643 | end; | |
| 644 | 644 | ||
| 645 | pkg.UnpackFile('preinst'); | ||
| 646 | pkg.UnpackFile('postinst'); | ||
| 647 | pkg.UnpackFile('prerm'); | ||
| 645 | pkg.UnpackControlFile('preinst'); | ||
| 646 | pkg.UnpackControlFile('postinst'); | ||
| 647 | pkg.UnpackControlFile('prerm'); | ||
| 648 | 648 | ExecA := '<disabled>'; | |
| 649 | 649 | ExecB := '<disabled>'; | |
| 650 | 650 | ExecX := '<disabled>'; | |
| … | … | ||
| 674 | 674 | Inc(i); | |
| 675 | 675 | end; | |
| 676 | 676 | ||
| 677 | i := 0; | ||
| 678 | while i <= Dependencies.Count - 1 do | ||
| 679 | begin | ||
| 680 | if StringReplace(Dependencies[i], ' ', '', [rfReplaceAll]) = '' then | ||
| 681 | Dependencies.Delete(i); | ||
| 682 | Inc(i); | ||
| 683 | end; | ||
| 684 | |||
| 685 | { if xnode.FindNode('pkcatalog')<>nil then | ||
| 686 | begin | ||
| 687 | z.ExtractFiles(ExtractFileName(xnode.FindNode('pkcatalog').NodeValue)); | ||
| 688 | Dependencies.Add('cat:'+lp+PkgName+xnode.FindNode('pkcatalog').NodeValue) | ||
| 689 | end;} | ||
| 690 | |||
| 691 | for i := 0 to Dependencies.Count - 1 do | ||
| 692 | if Dependencies[i][1] = '.' then | ||
| 693 | pkg.UnpackFile(Dependencies[i]); | ||
| 694 | |||
| 695 | 677 | msg('Profiles count is ' + IntToStr(PkProfiles.Count)); | |
| 696 | 678 | if PkProfiles.Count < 0 then | |
| 697 | 679 | begin | |
| … | … | ||
| 860 | 860 | cont := TIPKControl.Create(pkg.WDir + '/arcinfo.pin'); //Read IPK configuration | |
| 861 | 861 | cont.LangCode := GetLangID; //Set language code, so we get localized entries | |
| 862 | 862 | ||
| 863 | pkg.UnpackFile(cont.Binary); | ||
| 863 | pkg.UnpackDataFile(cont.Binary); | ||
| 864 | 864 | ||
| 865 | 865 | tmp := TStringList.Create; | |
| 866 | 866 | cont.GetInternalFilesSection(tmp); | |
| 867 | 867 | for i := 0 to tmp.Count - 1 do | |
| 868 | pkg.UnpackFile(tmp[i]); | ||
| 868 | pkg.UnpackDataFile(tmp[i]); | ||
| 869 | 869 | ||
| 870 | 870 | tmp.Free; | |
| 871 | 871 | WDir := pkg.WDir; | |
| … | … | ||
| 1119 | 1119 | ||
| 1120 | 1120 | ||
| 1121 | 1121 | //Unpack files directory | |
| 1122 | if not pkg.UnpackFile('files') then | ||
| 1122 | if not pkg.UnpackDataFile('files') then | ||
| 1123 | 1123 | begin | |
| 1124 | 1124 | MakeUsrRequest(rsExtractError, rqError); | |
| 1125 | 1125 | RollbackInstallation; |
src/cmdtools/ipkbuild.pas
(9 / 9)
|   | |||
| 372 | 372 | end; | |
| 373 | 373 | fc.Add(CleanFilePath(h + '/' + ExtractFileName(DeleteModifiers(fname)))); | |
| 374 | 374 | ||
| 375 | if not ipkpkg.AddFile(WDir + h + '/' + ExtractFileName(DeleteModifiers(fname))) then | ||
| 375 | if not ipkpkg.AddDataFile(WDir + h + '/' + ExtractFileName(DeleteModifiers(fname))) then | ||
| 376 | 376 | begin | |
| 377 | 377 | writeLn('error: '); | |
| 378 | 378 | writeln(' Could not add file "' + DeleteModifiers(fname) + '" to TAR archive.'); | |
| … | … | ||
| 606 | 606 | if prID <> '-1' then | |
| 607 | 607 | begin | |
| 608 | 608 | fc.SaveToFile(WDir + 'pkgdata/' + 'fileinfo-' + prID + '.id'); | |
| 609 | ipkpkg.AddFile(WDir + 'pkgdata/fileinfo-' + prID + '.id'); | ||
| 609 | ipkpkg.AddControlFile(WDir + 'pkgdata/fileinfo-' + prID + '.id'); | ||
| 610 | 610 | end; | |
| 611 | 611 | ||
| 612 | 612 | end; //End of file including | |
| … | … | ||
| 637 | 637 | FileCopy(h, WDir + 'pkgdata/' + 'packicon.png'); | |
| 638 | 638 | //!!! Should be changed to support more picture-filetypes | |
| 639 | 639 | control.Icon := '/pkgdata/' + 'packicon.png'; | |
| 640 | ipkpkg.AddFile(WDir + 'pkgdata/' + 'packicon.png'); | ||
| 640 | ipkpkg.AddControlFile(WDir + 'pkgdata/' + 'packicon.png'); | ||
| 641 | 641 | writeLn(' I: Icon included.'); | |
| 642 | 642 | end; | |
| 643 | 643 | end; //END <>nil | |
| … | … | ||
| 719 | 719 | if FileExists(ExtractFilePath(fi) + '/preinst') then | |
| 720 | 720 | begin | |
| 721 | 721 | FileCopy(ExtractFilePath(fi) + '/preinst', WDir + 'preinst'); | |
| 722 | ipkpkg.AddFile(WDir + 'preinst'); | ||
| 722 | ipkpkg.AddControlFile(WDir + 'preinst'); | ||
| 723 | 723 | ||
| 724 | 724 | writeLn(' I: Preinst script found.'); | |
| 725 | 725 | end; | |
| 726 | 726 | if FileExists(ExtractFilePath(fi) + '/postinst') then | |
| 727 | 727 | begin | |
| 728 | 728 | FileCopy(ExtractFilePath(fi) + '/postinst', WDir + 'postinst'); | |
| 729 | ipkpkg.AddFile(WDir + 'postinst'); | ||
| 729 | ipkpkg.AddControlFile(WDir + 'postinst'); | ||
| 730 | 730 | writeLn(' I: Postinst script found.'); | |
| 731 | 731 | end; | |
| 732 | 732 | if FileExists(ExtractFilePath(fi) + '/prerm') then | |
| 733 | 733 | begin | |
| 734 | 734 | FileCopy(ExtractFilePath(fi) + '/prerm', WDir + 'prerm'); | |
| 735 | ipkpkg.AddFile(WDir + 'prerm'); | ||
| 735 | ipkpkg.AddControlFile(WDir + 'prerm'); | ||
| 736 | 736 | writeLn(' I: Prerm script found.'); | |
| 737 | 737 | end; | |
| 738 | 738 | ||
| … | … | ||
| 747 | 747 | if not FileCopy(sl[i], WDir + 'locale/' + ExtractFileName(sl[i])) then | |
| 748 | 748 | RaiseCopyError(sl[i]); | |
| 749 | 749 | writeLn(' I: Include locale: ' + ExtractFileName(sl[i])); | |
| 750 | ipkpkg.AddFile(WDir + 'locale/' + ExtractFileName(sl[i])); | ||
| 750 | ipkpkg.AddControlFile(WDir + 'locale/' + ExtractFileName(sl[i])); | ||
| 751 | 751 | end; | |
| 752 | 752 | sl.Free; | |
| 753 | 753 | ||
| … | … | ||
| 786 | 786 | ExtractFileName(control.Binary)) then | |
| 787 | 787 | RaiseCopyError(control.Binary); | |
| 788 | 788 | ||
| 789 | ipkpkg.AddFile(WDir + 'files/' + ExtractFileName(control.Binary)); | ||
| 789 | ipkpkg.AddControlFile(WDir + 'files/' + ExtractFileName(control.Binary)); | ||
| 790 | 790 | control.Binary := '/files/' + ExtractFileName(control.Binary); | |
| 791 | 791 | end; | |
| 792 | 792 | end; | |
| … | … | ||
| 797 | 797 | ||
| 798 | 798 | control.SaveToFile(WDir + 'arcinfo.pin'); | |
| 799 | 799 | ||
| 800 | ipkpkg.AddFile(WDir + 'arcinfo.pin'); | ||
| 800 | ipkpkg.AddControlFile(WDir + 'arcinfo.pin'); | ||
| 801 | 801 | ||
| 802 | 802 | ipkpkg.Finalize; //Freeze the IPK package state | |
| 803 | 803 | files.Free; |
src/cmdtools/libuild.lpi
(7 / 2)
|   | |||
| 1 | 1 | <?xml version="1.0"?> | |
| 2 | 2 | <CONFIG> | |
| 3 | 3 | <ProjectOptions> | |
| 4 | <Version Value="7"/> | ||
| 4 | <Version Value="8"/> | ||
| 5 | 5 | <General> | |
| 6 | 6 | <SessionStorage Value="InProjectDir"/> | |
| 7 | 7 | <MainUnit Value="0"/> | |
| … | … | ||
| 47 | 47 | </Units> | |
| 48 | 48 | </ProjectOptions> | |
| 49 | 49 | <CompilerOptions> | |
| 50 | <Version Value="8"/> | ||
| 50 | <Version Value="9"/> | ||
| 51 | 51 | <Target> | |
| 52 | 52 | <Filename Value="../../build/libuild"/> | |
| 53 | 53 | </Target> | |
| … | … | ||
| 58 | 58 | <UnitOutputDirectory Value="../../build/$(TargetCPU)-$(TargetOS)"/> | |
| 59 | 59 | <LCLWidgetType Value="nogui"/> | |
| 60 | 60 | </SearchPaths> | |
| 61 | <Parsing> | ||
| 62 | <SyntaxOptions> | ||
| 63 | <UseAnsiStrings Value="False"/> | ||
| 64 | </SyntaxOptions> | ||
| 65 | </Parsing> | ||
| 61 | 66 | <Other> | |
| 62 | 67 | <CustomOptions Value="-dOpbCompat"/> | |
| 63 | 68 | <CompilerPath Value="$(CompPath)"/> |
src/ipkpackage11.pas
(152 / 96)
|   | |||
| 21 | 21 | interface | |
| 22 | 22 | ||
| 23 | 23 | uses | |
| 24 | Classes, FileUtil, GPGSign, LiUtils, LiTypes, SysUtils, TarArchive; | ||
| 24 | Unix, Classes, GPGSign, LiTypes, LiUtils, FileUtil, SysUtils, TarArchive; | ||
| 25 | 25 | ||
| 26 | 26 | type | |
| 27 | //** Creates IPK packages from preprocessed source files | ||
| 28 | 27 | ||
| 29 | 28 | { TLiPackager } | |
| 30 | 29 | ||
| 30 | //** Creates IPK packages from preprocessed source files | ||
| 31 | 31 | TLiPackager = class | |
| 32 | 32 | private | |
| 33 | 33 | OutFileName: String; | |
| 34 | 34 | pkrandom: String; | |
| 35 | basename: String; | ||
| 36 | mntar: TTarArchive; | ||
| 35 | wdir: String; | ||
| 36 | ctar, dtar: TTarArchive; | ||
| 37 | 37 | finalized: Boolean; | |
| 38 | 38 | bdir: String; | |
| 39 | maxbytes: Int64; | ||
| 39 | arcdata, arccontrol: String; | ||
| 40 | 40 | ||
| 41 | 41 | function RandomID: String; | |
| 42 | 42 | public | |
| 43 | 43 | constructor Create(aIPKFile: String); | |
| 44 | 44 | destructor Destroy; override; | |
| 45 | 45 | ||
| 46 | //** Add a new file to the IPK structure @return False if already finalized or other error | ||
| 47 | function AddFile(fname: String): Boolean; | ||
| 48 | //** Finalize the base file for signing | ||
| 49 | procedure Finalize; | ||
| 46 | //** Add new data to the IPK structure @return False if already finalized or other error | ||
| 47 | function AddDataFile(fname: String): Boolean; | ||
| 48 | //** Add a control file to the IPK structure @return False if already finalized or other error | ||
| 49 | function AddControlFile(fname: String): Boolean; | ||
| 50 | //** Finalize the package | ||
| 51 | function Finalize: Integer; | ||
| 50 | 52 | //** Sign the package | |
| 51 | 53 | function SignPackage: Boolean; | |
| 52 | 54 | //** Compress package and copy it to output @returns Success of operation | |
| … | … | ||
| 59 | 59 | property IPKFile: String read OutFileName write OutFileName; | |
| 60 | 60 | end; | |
| 61 | 61 | ||
| 62 | //** Unpacks IPK package structure | ||
| 63 | |||
| 64 | 62 | { TLiUnpacker } | |
| 65 | 63 | ||
| 64 | //** Unpacks IPK package structure | ||
| 66 | 65 | TLiUnpacker = class | |
| 67 | 66 | private | |
| 68 | 67 | ipkfile: String; | |
| … | … | ||
| 71 | 71 | constructor Create(aIPKFile: String); | |
| 72 | 72 | destructor Destroy; override; | |
| 73 | 73 | ||
| 74 | //** Prepare IPK tar file for extracting | ||
| 75 | procedure Prepare; | ||
| 74 | //** Prepare IPK tar file for installation & signature verifying | ||
| 75 | function Prepare: Boolean; | ||
| 76 | 76 | //** Verify signature (if there is any) | |
| 77 | 77 | function CheckSignature: TPkgSigState; | |
| 78 | //** Unpack file @returns Success of operation | ||
| 79 | function UnpackFile(fname: String): Boolean; | ||
| 78 | //** Unpack data file @returns Success of operation | ||
| 79 | function UnpackDataFile(fname: String): Boolean; | ||
| 80 | //** Unpack data file @returns Success of operation | ||
| 81 | function UnpackControlFile(fname: String): Boolean; | ||
| 80 | 82 | //** Unpacker's working dir | |
| 81 | 83 | property WDir: String read workdir; | |
| 82 | 84 | end; | |
| … | … | ||
| 105 | 105 | begin | |
| 106 | 106 | inherited Create; | |
| 107 | 107 | randomize; | |
| 108 | pkrandom := '-' + RandomID + RandomID + RandomID; | ||
| 109 | 108 | finalized := false; | |
| 110 | 109 | OutFileName := aIPKFile; | |
| 111 | basename := tmpdir + ExtractFileName(OutFileName) + pkrandom + '.tar'; | ||
| 112 | mntar := TTarArchive.Create; | ||
| 113 | mntar.Compression:=cmXZ; //IPK packages are XZ compressed | ||
| 114 | mntar.TarArchive := basename; | ||
| 110 | wdir := tmpdir + ChangeFileExt(ExtractFileName(OutFileName), '') + '-build/'; | ||
| 111 | ForceDirectories(wdir); | ||
| 112 | arcdata := wdir + 'data.tar.xz'; | ||
| 113 | arccontrol := wdir + 'control.tar.xz'; | ||
| 114 | |||
| 115 | ctar := TTarArchive.Create; | ||
| 116 | ctar.Compression := cmXZ; //Control Tar is always XZ compressed | ||
| 117 | ctar.TarArchive := arccontrol; | ||
| 118 | dtar := TTarArchive.Create; | ||
| 119 | dtar.Compression := cmXZ; | ||
| 120 | //Data Tar can have various compression methods (XZ by default) | ||
| 121 | dtar.TarArchive := arcdata; | ||
| 115 | 122 | end; | |
| 116 | 123 | ||
| 117 | 124 | destructor TLiPackager.Destroy; | |
| 118 | 125 | begin | |
| 119 | if not finalized then | ||
| 120 | mntar.Free; | ||
| 126 | ctar.Free; | ||
| 127 | dtar.Free; | ||
| 121 | 128 | inherited; | |
| 122 | 129 | end; | |
| 123 | 130 | ||
| … | … | ||
| 133 | 133 | Result := IntToStr(random(99)); | |
| 134 | 134 | end; | |
| 135 | 135 | ||
| 136 | function TLiPackager.AddFile(fname: String): Boolean; | ||
| 136 | function TLiPackager.AddDataFile(fname: String): Boolean; | ||
| 137 | 137 | begin | |
| 138 | 138 | if finalized then | |
| 139 | 139 | Result := false | |
| 140 | 140 | else | |
| 141 | 141 | begin | |
| 142 | mntar.BaseDir := bdir; | ||
| 143 | if mntar.AddFile(fname) = 0 then | ||
| 142 | dtar.BaseDir := bdir; | ||
| 143 | if dtar.AddFile(fname) = 0 then | ||
| 144 | 144 | Result := true | |
| 145 | 145 | else | |
| 146 | 146 | Result := false; | |
| 147 | 147 | end; | |
| 148 | 148 | end; | |
| 149 | 149 | ||
| 150 | procedure TLiPackager.Finalize; | ||
| 150 | function TLiPackager.AddControlFile(fname: String): Boolean; | ||
| 151 | 151 | begin | |
| 152 | if finalized then | ||
| 153 | Result := false | ||
| 154 | else | ||
| 155 | begin | ||
| 156 | ctar.BaseDir := bdir; | ||
| 157 | if ctar.AddFile(fname) = 0 then | ||
| 158 | Result := true | ||
| 159 | else | ||
| 160 | Result := false; | ||
| 161 | end; | ||
| 162 | end; | ||
| 163 | |||
| 164 | function TLiPackager.Finalize: Integer; | ||
| 165 | begin | ||
| 166 | Result := 0; | ||
| 167 | if finalized then | ||
| 168 | exit; | ||
| 169 | |||
| 152 | 170 | p_info('Finalizing package.'); | |
| 153 | if mntar.Finalize > 0 then | ||
| 154 | raise Exception.Create('Error while building package.'); | ||
| 155 | mntar.Free; | ||
| 171 | if ctar.Finalize > 0 then | ||
| 172 | raise Exception.Create('Error while creating control container!'); | ||
| 173 | if dtar.Finalize > 0 then | ||
| 174 | raise Exception.Create('Error while creating data container!'); | ||
| 175 | |||
| 156 | 176 | finalized := true; | |
| 157 | 177 | end; | |
| 158 | 178 | ||
| 159 | 179 | function TLiPackager.SignPackage: Boolean; | |
| 160 | 180 | var | |
| 161 | 181 | sign: TGPGSignWrapper; | |
| 162 | oldbase: String; | ||
| 163 | 182 | rs: Integer; | |
| 164 | 183 | begin | |
| 165 | 184 | Result := false; | |
| 166 | 185 | if (not Finalized) then | |
| 167 | 186 | raise Exception.Create('IPK file was not finalized before signing.'); | |
| 168 | 187 | ||
| 169 | oldbase := basename; | ||
| 188 | //Concat data to sign it | ||
| 189 | fpsystem(FindBinary('cat') + ' ' + ctar.TarArchive + ' ' + dtar.TarArchive + | ||
| 190 | ' > ' + wdir + 'combined.tmp'); | ||
| 191 | |||
| 170 | 192 | sign := TGPGSignWrapper.Create; | |
| 171 | sign.FileName := oldbase; | ||
| 193 | sign.FileName := wdir + 'combined.tmp'; | ||
| 172 | 194 | Result := true; | |
| 173 | if FileExistsUTF8(ExtractFilePath(oldbase) + '/signature.asc') then | ||
| 174 | DeleteFile(ExtractFilePath(oldbase) + '/signature.asc'); | ||
| 195 | if FileExistsUTF8(wdir + '_signature') then | ||
| 196 | DeleteFile(wdir + '_signature'); | ||
| 175 | 197 | ||
| 176 | if not sign.Signfile(ExtractFilePath(oldbase) + '/signature.asc') then | ||
| 198 | if not sign.Signfile(wdir + '_signature') then | ||
| 177 | 199 | begin | |
| 178 | 200 | Result := false; | |
| 179 | 201 | sign.Free; | |
| … | … | ||
| 203 | 203 | end; | |
| 204 | 204 | sign.Free; | |
| 205 | 205 | ||
| 206 | pkrandom := '-' + RandomID + RandomID + RandomID; | ||
| 207 | basename := tmpdir + ExtractFileName(OutFileName) + pkrandom + '.tar'; | ||
| 206 | DeleteFile(wdir + 'combined.tmp'); | ||
| 207 | end; | ||
| 208 | |||
| 209 | function TLiPackager.ProduceIPKPackage: Boolean; | ||
| 210 | var | ||
| 211 | mntar: TTarArchive; | ||
| 212 | basename: String; | ||
| 213 | begin | ||
| 214 | Result := true; | ||
| 215 | basename := basedir + ExtractFileName(OutFileName) + | ||
| 216 | RandomID + RandomID + RandomID + '.tar'; | ||
| 208 | 217 | mntar := TTarArchive.Create; | |
| 209 | mntar.Compression:=cmNone; //No compression here | ||
| 218 | mntar.Compression := cmNone; //Container Tar is not compressed | ||
| 210 | 219 | mntar.TarArchive := basename; | |
| 220 | mntar.BaseDir := wdir; | ||
| 211 | 221 | ||
| 212 | mntar.BaseDir := ExtractFilePath(oldbase); | ||
| 222 | if (not Finalized) then | ||
| 223 | raise Exception.Create('IPK file was not finalized.'); | ||
| 213 | 224 | ||
| 214 | RenameFile(oldbase, ExtractFilePath(oldbase) + '/content.tar'); | ||
| 215 | oldbase := ExtractFilePath(oldbase) + '/content.tar'; | ||
| 216 | |||
| 217 | rs := mntar.AddFile(oldbase); | ||
| 218 | if rs = 0 then | ||
| 225 | if mntar.AddFile(arccontrol) > 0 then | ||
| 219 | 226 | begin | |
| 220 | rs := mntar.AddFile(ExtractFilePath(oldbase) + 'signature.asc'); | ||
| 221 | if rs <> 0 then | ||
| 222 | raise Exception.Create('Error while combining signed package.'); | ||
| 223 | end | ||
| 224 | else | ||
| 225 | raise Exception.Create('Error while combining signed package.'); | ||
| 226 | mntar.Finalize; | ||
| 227 | mntar.Free; | ||
| 227 | Result := false; | ||
| 228 | exit; | ||
| 229 | end; | ||
| 230 | if mntar.AddFile(arcdata) > 0 then | ||
| 231 | begin | ||
| 232 | Result := false; | ||
| 233 | exit; | ||
| 234 | end; | ||
| 235 | if FileExists(wdir + '_signature') then | ||
| 236 | if mntar.AddFile(wdir + '_signature') > 0 then | ||
| 237 | begin | ||
| 238 | Result := false; | ||
| 239 | exit; | ||
| 240 | end; | ||
| 228 | 241 | ||
| 229 | DeleteFile(ExtractFilePath(oldbase) + 'signature.asc'); | ||
| 230 | DeleteFile(oldbase); | ||
| 231 | end; | ||
| 242 | if mntar.Finalize > 0 then | ||
| 243 | raise Exception.Create('Error while building package.'); | ||
| 232 | 244 | ||
| 233 | function TLiPackager.ProduceIPKPackage: Boolean; | ||
| 234 | begin | ||
| 235 | Result := true; | ||
| 236 | 245 | if FileExists(OutFileName) then | |
| 237 | 246 | Exception.Create('Output file already exists!'); | |
| 238 | if (not Finalized) then | ||
| 239 | raise Exception.Create('IPK file was not finalized.'); | ||
| 240 | 247 | ||
| 241 | if not finalized then mntar.Finalize; | ||
| 248 | mntar.Free; | ||
| 242 | 249 | ||
| 243 | FileCopy(basename,outfilename); | ||
| 250 | FileCopy(basename, outfilename); | ||
| 244 | 251 | DeleteFile(basename); | |
| 245 | 252 | end; | |
| 246 | 253 | ||
| … | … | ||
| 257 | 257 | begin | |
| 258 | 258 | inherited Create; | |
| 259 | 259 | ipkfile := aIPKFile; | |
| 260 | workdir := tmpdir + ExtractFileName(ipkfile) + '/'; | ||
| 261 | SysUtils.ForceDirectories(workdir); | ||
| 260 | workdir := tmpdir + ChangeFileExt(ExtractFileName(ipkfile),'') + '-install/'; | ||
| 261 | ForceDirectories(workdir); | ||
| 262 | 262 | signChecked := false; | |
| 263 | 263 | end; | |
| 264 | 264 | ||
| … | … | ||
| 267 | 267 | inherited; | |
| 268 | 268 | end; | |
| 269 | 269 | ||
| 270 | procedure TLiUnpacker.Prepare; | ||
| 270 | function TLiUnpacker.Prepare: Boolean; | ||
| 271 | var | ||
| 272 | mnarc: TTarArchive; | ||
| 271 | 273 | begin | |
| 274 | Result := true; | ||
| 272 | 275 | if not FileExists(ipkfile) then | |
| 273 | 276 | Exception.Create('IPK file does not exists!'); | |
| 274 | 277 | ||
| 275 | FileCopy(ipkfile, workdir+'ipktar.tar'); | ||
| 276 | //Some more praparation later... | ||
| 278 | FileCopy(ipkfile, workdir + 'ipktar.tar'); | ||
| 279 | mnarc := TTarArchive.Create; | ||
| 280 | mnarc.TarArchive := workdir + 'ipktar.tar'; | ||
| 281 | mnarc.Compression := cmNone; //Covering tar is not compressed | ||
| 282 | mnarc.BaseDir := workdir; | ||
| 283 | if mnarc.ExtractFile('*') > 0 then //Extract everything | ||
| 284 | Result := false; | ||
| 285 | mnarc.Free; | ||
| 286 | DeleteFile(workdir + 'ipktar.tar'); | ||
| 277 | 287 | end; | |
| 278 | 288 | ||
| 279 | 289 | function TLiUnpacker.CheckSignature: TPkgSigState; | |
| 280 | 290 | var | |
| 281 | mnarc: TTarArchive; | ||
| 282 | 291 | hasSignature: Boolean; | |
| 283 | 292 | sign: TGPGSignWrapper; | |
| 284 | 293 | res: Integer; | |
| 285 | 294 | begin | |
| 286 | 295 | hasSignature := false; | |
| 287 | mnarc := TTarArchive.Create; | ||
| 288 | mnarc.TarArchive := workdir + 'ipktar.tar'; | ||
| 289 | mnarc.Compression:=cmNone; //If we have a signature, covering tar is not compressed | ||
| 290 | mnarc.BaseDir := workdir; | ||
| 291 | 296 | ||
| 292 | 297 | Result := psNone; | |
| 293 | 298 | //Check if package has signature | |
| 294 | hasSignature := mnarc.FileInArchive('signature.asc'); | ||
| 299 | hasSignature := FileExists(workdir + '_signature'); | ||
| 295 | 300 | ||
| 296 | 301 | if hasSignature then | |
| 297 | 302 | begin | |
| 298 | res := mnarc.ExtractFile('signature.asc'); | ||
| 299 | res += mnarc.ExtractFile('content.tar'); | ||
| 300 | |||
| 301 | if res <> 0 then | ||
| 302 | begin | ||
| 303 | //!!! This should be done better! | ||
| 304 | raise Exception.Create('Could not verify signature!'); | ||
| 305 | end; | ||
| 306 | |||
| 307 | DeleteFile(workdir + 'ipktar.tar'); | ||
| 308 | RenameFile(workdir + 'content.tar', workdir + 'ipktar.tar'); | ||
| 303 | fpsystem(FindBinary('cat') + ' ' + workdir + 'control.tar.xz ' + workdir + 'data.tar.xz > ' + workdir + 'combined.tmp'); | ||
| 309 | 304 | Result := psUntrusted; | |
| 310 | 305 | //Now check signature | |
| 311 | 306 | sign := TGPGSignWrapper.Create; | |
| 312 | sign.FileName := workdir + 'ipktar.tar'; | ||
| 313 | if sign.Verify(workdir + 'signature.asc') then | ||
| 307 | sign.FileName := workdir + 'combined.tmp'; | ||
| 308 | if sign.Verify(workdir + '_signature') then | ||
| 314 | 309 | Result := psTrusted; | |
| 315 | 310 | sign.Free; | |
| 311 | DeleteFile(workdir + 'combined.tmp'); | ||
| 316 | 312 | end; | |
| 317 | mnarc.Free; | ||
| 318 | 313 | signChecked := true; | |
| 319 | 314 | end; | |
| 320 | 315 | ||
| 321 | function TLiUnpacker.UnpackFile(fname: String): Boolean; | ||
| 316 | function TLiUnpacker.UnpackDataFile(fname: String): Boolean; | ||
| 322 | 317 | var | |
| 323 | 318 | arc: TTarArchive; | |
| 324 | 319 | begin | |
| … | … | ||
| 326 | 326 | fname := CleanFilePath(fname); | |
| 327 | 327 | ||
| 328 | 328 | arc := TTarArchive.Create; | |
| 329 | arc.TarArchive := workdir + 'ipktar.tar'; | ||
| 329 | arc.TarArchive := workdir + 'data.tar.xz'; | ||
| 330 | 330 | arc.BaseDir := workdir; | |
| 331 | arc.Compression:=cmXZ; | ||
| 331 | arc.Compression := cmXZ; | ||
| 332 | 332 | //Create dir struct | |
| 333 | 333 | //ForceDirectories(ExtractFilePath(fdest)); | |
| 334 | //Check if package has signature | ||
| 335 | 334 | if arc.ExtractFile(fname) = 0 then | |
| 336 | 335 | Result := true; | |
| 337 | 336 | ||
| 338 | 337 | arc.Free; | |
| 339 | 338 | end; | |
| 340 | 339 | ||
| 340 | function TLiUnpacker.UnpackControlFile(fname: String): Boolean; | ||
| 341 | var | ||
| 342 | arc: TTarArchive; | ||
| 343 | begin | ||
| 344 | if not signChecked then | ||
| 345 | CheckSignature; | ||
| 346 | Result := false; | ||
| 347 | if length(fname) < 2 then | ||
| 348 | exit; | ||
| 349 | |||
| 350 | fname := CleanFilePath(fname); | ||
| 351 | arc := TTarArchive.Create; | ||
| 352 | arc.TarArchive := workdir + 'control.tar.xz'; | ||
| 353 | arc.BaseDir := workdir; | ||
| 354 | arc.Compression := cmXZ; | ||
| 355 | //Create dir struct | ||
| 356 | //ForceDirectories(ExtractFilePath(fdest)); | ||
| 357 | if arc.ExtractFile(fname) = 0 then | ||
| 358 | Result := true; | ||
| 359 | |||
| 360 | arc.Free; | ||
| 361 | end; | ||
| 362 | |||
| 341 | 363 | { TLiUpdateBit } | |
| 342 | 364 | ||
| 343 | 365 | constructor TLiUpdateBit.Create; | |
| 344 | 366 | begin | |
| 345 | 367 | inherited; | |
| 346 | 368 | xz := TTarArchive.Create; | |
| 347 | xz.Compression:=cmLZMA; | ||
| 369 | xz.Compression := cmLZMA; | ||
| 348 | 370 | end; | |
| 349 | 371 | ||
| 350 | 372 | destructor TLiUpdateBit.Destroy; | |
| … | … | ||
| 377 | 377 | ||
| 378 | 378 | procedure TLiUpdateBit.Compress(infile: String; outfile: String); | |
| 379 | 379 | begin | |
| 380 | xz.BaseDir:=ExtractFilePath(infile); | ||
| 381 | xz.TarArchive:=outfile; | ||
| 380 | xz.BaseDir := ExtractFilePath(infile); | ||
| 381 | xz.TarArchive := outfile; | ||
| 382 | 382 | xz.AddFile(infile); | |
| 383 | 383 | xz.Finalize; | |
| 384 | 384 | end; | |
| … | … | ||
| 386 | 386 | procedure TLiUpdateBit.Decompress(infile: String; outfile: String); | |
| 387 | 387 | begin | |
| 388 | 388 | //NEEDS WORK! | |
| 389 | xz.TarArchive:=infile; | ||
| 390 | xz.BaseDir:=ExtractFilePath(outfile); | ||
| 389 | xz.TarArchive := infile; | ||
| 390 | xz.BaseDir := ExtractFilePath(outfile); | ||
| 391 | 391 | xz.ExtractFile('*'); | |
| 392 | 392 | end; | |
| 393 | 393 |

