 
 module.exports = new Kite 'applications'
 
+  installApp: (options, callback)->
+
+    {username, owner, appPath, appName, version} = options
+
+    version   or= 'latest'
+    kpmAppPath  = escapePath "/opt/Apps/#{owner}/#{appName}/#{version}"
+    userAppPath = escapePath appPath
+
+    if kpmAppPath.indexOf("/opt/Apps/") isnt 0 or not safeForUser username, userAppPath
+      callback? new AuthorizationError username
+      return false
+
+    fs.exists kpmAppPath, (exists)->
+      if not exists then callback? new KodingError "App files not found! Install cancelled."
+      else
+        executeCommand {username, command: "mkdir -p #{userAppPath}"}, (err)->
+          if err then new KodingError "Cannot create Application directory", userAppPath
+          else
+            fse.copy "#{kpmAppPath}/index.js", "#{userAppPath}/index.js", (err)->
+              fse.copy "#{kpmAppPath}/.manifest", "#{userAppPath}/.manifest", (err)->
+                chownr {username, path: userAppPath}, callback
   copyAppSkeleton:(options, callback)->
     {username, appPath, type} = options
 

        exec "rm -f #{latestPath} && ln -s #{versionedPath} #{latestPath}", (err, stdout, stderr)->
          if err or stderr then cb err
          else cb null


          else
            cb null

  approveApp: (options, callback)->

    {username, authorNick, version, appName} = options
