Class: Profile::Shell

Inherits:
JSONable show all
Includes:
Bashman
Defined in:
lib/bashman/shell.rb

Constant Summary collapse

CONFIG =
self.get_config('shell')
BASEPATH =
CONFIG.key?("basepath") ? File.expand_path(CONFIG["basepath"]) : File.expand_path("~/")
BLOCKSIZE =
1024

Constants included from Bashman

Bashman::CONFIG_PATH, Bashman::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bashman

included, version

Methods inherited from JSONable

#from_json!, #to_hash, #to_json

Constructor Details

#initializeShell

Returns a new instance of Shell.



12
13
14
# File 'lib/bashman/shell.rb', line 12

def initialize
    @shell = self.get_current
end

Instance Attribute Details

#dotfilesObject (readonly)

Returns the value of attribute dotfiles.



10
11
12
# File 'lib/bashman/shell.rb', line 10

def dotfiles
  @dotfiles
end

#shellObject (readonly)

Returns the value of attribute shell.



9
10
11
# File 'lib/bashman/shell.rb', line 9

def shell
  @shell
end

Instance Method Details

#get_dotfilesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bashman/shell.rb', line 16

def get_dotfiles
    exc = []
    inc = []

    if CONFIG.include?('exclude')
        exc = CONFIG['exclude'].split(',').map {|x| x.strip}
    end

    if CONFIG.include?('include')
        inc = CONFIG['include'].split(',').map {|x| x.strip}
    else
        inc = ["\.[a-zA-Z0-9-_]*"]
    end

    files = self.add_includes(inc)
    files = self.remove_excludes(exc, files)
    files.delete_if {|f| /\.bashman\/profiles/ =~ f}

    @dotfiles = files
end

#save_dotfiles(tarfile, timestamp = nil, overwrite = false) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bashman/shell.rb', line 37

def save_dotfiles(tarfile, timestamp = nil, overwrite = false)
    require 'fileutils'
    
    savefile = File.expand_path(tarfile)
    
    if File.exists?(savefile)
        if not overwrite
            timestamp = File.mtime(savefile).to_i if timestamp.nil?
            bakfile = "#{savefile}.#{timestamp}"
            File.delete(bakfile) if File.exists?(bakfile)
            FileUtils.mv(savefile, bakfile)
        end
    end

    begin
        self.tar_gz(BASEPATH, savefile, *@dotfiles)
    rescue => e
        puts "Error saving dotfiles:  #{e.message}"
        puts e.backtrace
        File.delete(savefile) if File.exists?(savefile)
        if not bakfile.nil? and File.exists?(bakfile)
            FileUtils.mv(bakfile, savefile)
        end
        return 1
    end

end