Module: Launchr

Defined in:
lib/launchr.rb,
lib/launchr/cli.rb,
lib/launchr/path.rb,
lib/launchr/service.rb,
lib/launchr/commands.rb,
lib/launchr/application.rb,
lib/launchr/mixin/popen4.rb,
lib/launchr/mixin/mixlib_cli.rb,
lib/launchr/mixin/ordered_hash.rb,
lib/launchr/mixin/ordered_hash.rb

Defined Under Namespace

Modules: ActiveSupport, Mixlib, Path, Popen4 Classes: Application, CLI, Commands, OrderedHash, Service

Class Method Summary collapse

Class Method Details

.configObject



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

def config
  @config ||= {}
end

.gidObject



91
92
93
# File 'lib/launchr.rb', line 91

def gid
  Etc.getgrnam(group).gid
end

.groupObject



79
80
81
82
83
84
85
# File 'lib/launchr.rb', line 79

def group
  if superuser?
    sudo_group || real_group
  else
    real_group
  end
end

.import_argsObject



21
22
23
24
25
26
27
28
# File 'lib/launchr.rb', line 21

def import_args
  if config[:args][:user]
    config[:boot] = nil

  elsif config[:args][:boot]
    config[:boot] = true
  end
end

.labelObject



30
31
32
33
# File 'lib/launchr.rb', line 30

def label
  # "com.github.homebrew.launchr"
  "com.github.launchr"
end

.launchctl_timeoutObject



35
36
37
# File 'lib/launchr.rb', line 35

def launchctl_timeout
  5
end

.load_defaultObject



13
14
15
16
17
18
19
# File 'lib/launchr.rb', line 13

def load_default
  if Launchr::Path.launchr_default_boot.exist?
    config[:boot] = true
  else
    config[:boot] = nil
  end
end

.real_groupObject



43
44
45
# File 'lib/launchr.rb', line 43

def real_group
  Etc.getgrgid(Process.gid).name
end

.real_userObject



39
40
41
# File 'lib/launchr.rb', line 39

def real_user
  Etc.getpwuid(Process.uid).name
end

.sudo_groupObject



61
62
63
64
65
66
67
68
69
# File 'lib/launchr.rb', line 61

def sudo_group
  if ENV["SUDO_GROUP"]
    ENV["SUDO_GROUP"]
  elsif ENV["SUDO_GID"]
    Etc.getgrgid(ENV["SUDO_GID"].to_i).name
  else
    nil
  end
end

.sudo_userObject



51
52
53
54
55
56
57
58
59
# File 'lib/launchr.rb', line 51

def sudo_user
  if ENV["SUDO_USER"]
    ENV["SUDO_USER"]
  elsif ENV["SUDO_UID"]
    Etc.getpwuid(ENV["SUDO_UID"].to_i).name
  else
    nil
  end
end

.superuser?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/launchr.rb', line 47

def superuser?
  real_user == "root"
end

.uidObject



87
88
89
# File 'lib/launchr.rb', line 87

def uid
  Etc.getpwnam(user).uid
end

.userObject



71
72
73
74
75
76
77
# File 'lib/launchr.rb', line 71

def user
  if superuser?
    sudo_user || real_user
  else
    real_user
  end
end

.versionObject



95
96
97
98
99
100
101
# File 'lib/launchr.rb', line 95

def version
  if Launchr::Path.launchr_version.exist?
    Launchr::Path.launchr_version.read.strip
  else
    "0.0.0"
  end
end