/// <summary> /// Closes and writes the control archive to the package. /// </summary> private void WriteControl() { tarWriter.Close(); gzStream.Close(); gzBuffer.Seek(0, SeekOrigin.Begin); arWriter.WriteFile(gzBuffer, "control.tar.gz", DateTime.UtcNow); gzBuffer.Close(); }
void Build() { int debberVer = 0; ini.GetValue("debber", "debber-version", ref debberVer); if (debberVer != 1) { throw new Exception("File requires a newer debber version. Please update!"); } string binVer = ini.ReadSetting("debber", "debian-binary"); if (binVer != "2.0") { throw new Exception("Invalid or unknown debian version!"); } packageVersion = SemanticVersion.Parse(ini.ReadSetting("package", "version")); packageName = ini.ReadSetting("package", "name"); packageFile = ini.ReadSetting("package", "output").Replace("{NAME}", packageName).Replace("{VERSION}", packageVersion.ToString()); FileSystem.TouchFile(packageFile); SystemConsole.WriteLine("Create <cyan>data.tar.gz<default>..."); byte[] data_tar_gz; using (MemoryStream ms = new MemoryStream()) { TarWriter tarFile = new TarWriter(ms, true); foreach (string line in ini.ReadSection("data.tgz", true)) { string[] parts = line.Split(':'); if (parts.Length < 2) { continue; } switch (parts[0].Trim()) { case "directory": PackDirectory(tarFile, parts[1]); break; case "file": PackFiles(tarFile, parts); break; default: throw new Exception(string.Format("Invalid setting {0} at [data.tgz]!", line)); } } tarFile.Close(); data_tar_gz = ms.ToArray(); } SystemConsole.WriteLine("Create <cyan>control.tar.gz<default>..."); byte[] control_tar_gz; using (MemoryStream tarStream = new MemoryStream()) { TarWriter tarFile = new TarWriter(tarStream, true); WriteControlFile(tarFile, "control", 640); #region md5sums using (MemoryStream ms = new MemoryStream()) { DataWriter writer = new DataWriter(ms); foreach (KeyValuePair <string, string> md5sum in md5sums) { writer.Write(md5sum.Value); writer.Write(" "); writer.Write(md5sum.Key); writer.Write("\n"); } writer.Close(); SystemConsole.WriteLine(" file: <cyan>md5sums"); tarFile.AddFile("md5sums", ms.ToArray()); } #endregion WriteControlFile(tarFile, "conffiles", 640); WriteControlFile(tarFile, "preinst", 700); WriteControlFile(tarFile, "postinst", 700); WriteControlFile(tarFile, "prerm", 700); WriteControlFile(tarFile, "postrm", 700); tarFile.Close(); control_tar_gz = tarStream.ToArray(); } using (MemoryStream ms = new MemoryStream()) { var arFile = ArFile.CreateNewAr(ms); arFile.WriteHeader(ArHeader.CreateFile("debian-binary", 4)); arFile.WriteData(Encoding.ASCII.GetBytes("2.0\n")); arFile.WriteHeader(ArHeader.CreateFile("control.tar.gz", control_tar_gz.Length)); arFile.WriteData(control_tar_gz); arFile.WriteHeader(ArHeader.CreateFile("data.tar.gz", data_tar_gz.Length)); arFile.WriteData(data_tar_gz); arFile.Close(); File.WriteAllBytes(packageFile, ms.ToArray()); SystemConsole.WriteLine("Completed <green>{0}<default> ...", packageFile); } }