installer.coffee | |
|---|---|
| The | async = require "async"
fs = require "fs"
path = require "path"
{mkdirp} = require "./util"
{chown} = require "./util"
util = require "util" |
| Import the Eco templates for the | resolverSource = require "./templates/installer/resolver"
firewallSource = require "./templates/installer/cx.pow.firewall.plist"
daemonSource = require "./templates/installer/cx.pow.powd.plist" |
|
| class InstallerFile
constructor: (@path, source, @root = false, @mode = 0o644) ->
@source = source.trim() |
| Check to see whether the file actually needs to be installed. If
the file exists on the filesystem with the specified path and
contents, | isStale: (callback) ->
path.exists @path, (exists) =>
if exists
fs.readFile @path, "utf8", (err, contents) =>
if err
callback true
else
callback @source isnt contents.trim()
else
callback true |
| Create all the parent directories of the file's path, if
necessary, and then invoke | vivifyPath: (callback) =>
mkdirp path.dirname(@path), callback |
| Write the file's source to disk and invoke | writeFile: (callback) =>
fs.writeFile @path, @source, "utf8", callback |
| If the root flag is set for this file, change its ownership to the
| setOwnership: (callback) =>
if @root
chown @path, "root:wheel", callback
else
callback false |
| Set permissions on the installed file with | setPermissions: (callback) =>
fs.chmod @path, @mode, callback |
| Install a file asynchronously, first by making its parent directory, then writing it to disk, and finally setting its ownership and permission bits. | install: (callback) ->
async.series [
@vivifyPath,
@writeFile,
@setOwnership,
@setPermissions
], callback |
| The | module.exports = class Installer |
| Factory method that takes a | @getSystemInstaller: (@configuration) ->
files = [
new InstallerFile "/Library/LaunchDaemons/cx.pow.firewall.plist",
firewallSource(@configuration),
true
]
for domain in @configuration.domains
files.push new InstallerFile "/etc/resolver/#{domain}",
resolverSource(@configuration),
true
new Installer files |
| Factory method that takes a | @getLocalInstaller: (@configuration) ->
new Installer [
new InstallerFile "#{process.env.HOME}/Library/LaunchAgents/cx.pow.powd.plist",
daemonSource(@configuration)
] |
| Create an installer for a set of files. | constructor: (@files = []) -> |
| Invoke | getStaleFiles: (callback) ->
async.select @files, (file, proceed) ->
file.isStale proceed
, callback |
| Invoke | needsRootPrivileges: (callback) ->
@getStaleFiles (files) ->
async.detect files, (file, proceed) ->
proceed file.root
, (result) ->
callback result? |
| Installs any stale files asynchronously and then invokes
| install: (callback) ->
@getStaleFiles (files) ->
async.forEach files, (file, proceed) ->
file.install (err) ->
util.puts file.path unless err
proceed err
, callback
|