 # mount remote filesystem kites
 
-config   = require './config'
-
-path     = require "path"
-fs       = require "fs"
-mkdirp   = require 'mkdirp'
-_        = require "underscore"
-log4js   = require 'log4js'
-log      = log4js.getLogger("[#{config.name}]")
-{exec}   = require "child_process"
-{spawn}  = require "child_process"
+config  = require './config'
+
+path    = require "path"
+fs      = require "fs"
+mkdirp  = require 'mkdirp'
+log4js  = require 'log4js'
+log     = log4js.getLogger("[#{config.name}]")
+{spawn} = require "child_process"
 
 # Utilities
 {normalizeUserPath,

          if state.mounted
            callback "Mountpoint #{state.mountpoint} already exists"
          else
            uid = res.trim()
            log.info "[OK] user ID for user #{username} is #{uid}"
            ftpfsopts = "#{config.ftpfs.opts},uid=#{uid},gid=#{uid},fsname=#{remotehost},user=#{remoteuser}:#{remotepass}"
            @createMountpoint options, (err, res)=>
              if err
                callback err
              else
                @spawnWrapper config.ftpfs.curlftpfs, ['-o', ftpfsopts, remotehost, options.mountpoint], (err, res)=>
                  if err
                    log.error error = "Couldn't mount remote FTP server #{remotehost}: #{err}"
                    fs.rmdir options.mountpoint, (err)->
                      log.error err if err
                      callback error
                  else
                    @remountVE options, (err,res)=>
                      if err
                        callback err
                      else
                        @updateMountCfg options, (err,res)->
                        callback null, res

  # Safe
  checkMountPoint : (options, callback)->

    options.storepass    = yes if options.remotepass is 'anonymous'
    options.remotetype   = 'ftp'

    {username, remoteuser, remotepass, remotehost, storepass, mountonly} = options

    unless remotehost
      callback "Remote host is not provided"
