index.js
function buildControlFile (tempPath, definition, callback) {
  var self = this

  var author = ''
  if (definition.package.author) {
    author = typeof definition.package.author === 'string'
      ? definition.package.author
      : definition.package.author.name + ' <' + definition.package.author.email + '>'
  }

  self.controlFile = {
    Package: definition.info.name || definition.package.name,
    Version: definition.package.version + '-' + (definition.info.rev || '1'),
    'Installed-Size': Math.ceil(self.pkgSize / 1024),
    Section: 'misc',
    Priority: 'optional',
    Architecture: definition.info.arch || 'all',
    Depends: definition.info.depends || 'lsb-base (>= 3.2)',
    Maintainer: author
  }

  // optional items
  if (definition.package.license) {
    self.controlFile.License = definition.package.license
  }

  // optional items
  if (definition.package.homepage) {
    self.controlFile.Homepage = definition.package.homepage
  }

  self.controlFile.Description = definition.package.description + '\n ' +
    (definition.info.name || definition.package.name) +
    ': ' + definition.package.description

  // create the control file
  async.parallel([
    function createControlFile (prlDone) {
      var controlHeader = ''
      async.forEachOf(self.controlFile, function (value, key, done) {
        controlHeader += key + ': ' + value + '\n'
        done()
      }, function (err) {
        if (err) {
          debug('could not write control file')
          return prlDone(err)
        }

        self.control.entry({name: './control'}, controlHeader, prlDone)
      })
    }, function createHashFile (prlDone) {
      var fileContent = ''
      for (var i = 0; i < self.filesMd5.length; i++) {
        fileContent += self.filesMd5[i].md5 + '  ' + self.filesMd5[i].path.replace(/^\W*/, '') + '\n'
      }
      self.control.entry({name: './md5sums'}, fileContent, prlDone)
    }, function addScripts (prlDone) {
      async.forEachOf(definition.info.scripts, function (path, scriptName, doneScript) {
        debug('processing script ', path)
        async.waterfall([
          fs.access.bind(fs, path, fs.F_OK),
          fs.stat.bind(fs, path),
          function readFile (stats, wtfDone) {
            fs.readFile(path, function (err, data) {
              wtfDone(err, stats, data)
            })
          },
          function addScript (stats, data, wtfDone) {
            debug('adding script ', scriptName)
            self.control.entry({
              name: './' + scriptName,
              size: stats.size,
              mode: parseInt('755', 8)
            }, data, wtfDone)
          }
        ], doneScript)
      }, prlDone)
    }
  ], function (err) {
    if (err) {
      debug('could not write control tarball')
      return callback(err)
    }

    debug('successfully created control file')

    self.control.finalize()

    var file = fs.createWriteStream(path.join(tempPath, 'control.tar.gz'))
    file.on('finish', callback)

    var compress = zlib.createGzip()
    compress.pipe(file)
    self.control.pipe(compress)
  })
}
function buildControlFile (tempPath, definition, callback) {
  var self = this

  var author = ''
  if (definition.package.author) {
    author = typeof definition.package.author === 'string'
      ? definition.package.author
      : definition.package.author.name + ' <' + definition.package.author.email + '>'
  }

  self.controlFile = {
    Package: definition.info.name || definition.package.name,
    Version: definition.package.version + '-' + (definition.info.rev || '1'),
    'Installed-Size': Math.ceil(self.pkgSize / 1024),
    Section: 'misc',
    Priority: 'optional',
    Architecture: definition.info.arch || 'all',
    Depends: definition.info.depends || 'lsb-base (>= 3.2)',
    Maintainer: author
  }

  // optional items
  if (definition.package.license) {
    self.controlFile.License = definition.package.license
  }

  // optional items
  if (definition.package.homepage) {
    self.controlFile.Homepage = definition.package.homepage
  }

  self.controlFile.Description = definition.package.description + '\n ' +
    (definition.info.name || definition.package.name) +
    ': ' + definition.package.description

  // create the control file
  async.parallel([
    function createControlFile (prlDone) {
      var controlHeader = ''
      async.forEachOf(self.controlFile, function (value, key, done) {
        controlHeader += key + ': ' + value + '\n'
        done()
      }, function (err) {
        if (err) {
          debug('could not write control file')
          return prlDone(err)
        }

        self.control.entry({name: './control'}, controlHeader, prlDone)
      })
    }, function createHashFile (prlDone) {
      var fileContent = ''
      for (var i = 0; i < self.filesMd5.length; i++) {
        fileContent += self.filesMd5[i].md5 + '  ' + self.filesMd5[i].path.replace(/^\W*/, '') + '\n'
      }
      self.control.entry({name: './md5sums'}, fileContent, prlDone)
    }, function addScripts (prlDone) {
      async.forEachOf(definition.info.scripts, function (path, scriptName, doneScript) {
        debug('processing script ', path)
        async.waterfall([
          fs.access.bind(fs, path, fs.F_OK),
          fs.stat.bind(fs, path),
          function readFile (stats, wtfDone) {
            fs.readFile(path, function (err, data) {
              wtfDone(err, stats, data)
            })
          },
          function addScript (stats, data, wtfDone) {
            debug('adding script ', scriptName)
            self.control.entry({
              name: './' + scriptName,
              size: stats.size,
              mode: parseInt('755', 8)
            }, data, wtfDone)
          }
        ], doneScript)
      }, prlDone)
    }
  ], function (err) {
    if (err) {
      debug('could not write control tarball')
      return callback(err)
    }

    debug('successfully created control file')

    self.control.finalize()

    var file = fs.createWriteStream(path.join(tempPath, 'control.tar.gz'))
    file.on('finish', callback)

    var compress = zlib.createGzip()
    compress.pipe(file)
    self.control.pipe(compress)
  })
}
function buildControlFile ( tempPath , definition , callback ) { var self = this var author = '' if ( definition . package . author ) { author = typeof definition . package . author === 'string' ? definition . package . author : definition . package . author . name + ' <' + definition . package . author . email + '>' } self . controlFile = { Package : definition . info . name || definition . package . name , Version : definition . package . version + '-' + ( definition . info . rev || '1' ) , 'Installed-Size' : Math . ceil ( self . pkgSize / 1024 ) , Section : 'misc' , Priority : 'optional' , Architecture : definition . info . arch || 'all' , Depends : definition . info . depends || 'lsb-base (>= 3.2)' , Maintainer : author } // optional items if ( definition . package . license ) { self . controlFile . License = definition . package . license } // optional items if ( definition . package . homepage ) { self . controlFile . Homepage = definition . package . homepage } self . controlFile . Description = definition . package . description + '\n ' + ( definition . info . name || definition . package . name ) + ': ' + definition . package . description // create the control file async . parallel ( [ function createControlFile ( prlDone ) { var controlHeader = '' async . forEachOf ( self . controlFile , function ( value , key , done ) { controlHeader += key + ': ' + value + '\n' done ( ) } , function ( err ) { if ( err ) { debug ( 'could not write control file' ) return prlDone ( err ) } self . control . entry ( { name : './control' } , controlHeader , prlDone ) } ) } , function createHashFile ( prlDone ) { var fileContent = '' for ( var i = 0 ; i < self . filesMd5 . length ; i ++ ) { fileContent += self . filesMd5 [ i ] . md5 + '  ' + self . filesMd5 [ i ] . path . replace ( / ^\W* / , '' ) + '\n' } self . control . entry ( { name : './md5sums' } , fileContent , prlDone ) } , function addScripts ( prlDone ) { async . forEachOf ( definition . info . scripts , function ( path , scriptName , doneScript ) { debug ( 'processing script ' , path ) async . waterfall ( [ fs . access . bind ( fs , path , fs . F_OK ) , fs . stat . bind ( fs , path ) , function readFile ( stats , wtfDone ) { fs . readFile ( path , function ( err , data ) { wtfDone ( err , stats , data ) } ) } , function addScript ( stats , data , wtfDone ) { debug ( 'adding script ' , scriptName ) self . control . entry ( { name : './' + scriptName , size : stats . size , mode : parseInt ( '755' , 8 ) } , data , wtfDone ) } ] , doneScript ) } , prlDone ) } ] , function ( err ) { if ( err ) { debug ( 'could not write control tarball' ) return callback ( err ) } debug ( 'successfully created control file' ) self . control . finalize ( ) var file = fs . createWriteStream ( path . join ( tempPath , 'control.tar.gz' ) ) file . on ( 'finish' , callback ) var compress = zlib . createGzip ( ) compress . pipe ( file ) self . control . pipe ( compress ) } ) }
Build the control part of the .deb package.
Build the control part of the . deb package .