Class: WSlaveTools

Inherits:
Object
  • Object
show all
Defined in:
lib/wslave_tools.rb

Class Method Summary collapse

Class Method Details

._check_and_mk_dirs(path = '.') ⇒ Object



78
79
# File 'lib/wslave_tools.rb', line 78

def self._check_and_mk_dirs(path = '.')
end

.set_dev_perms(path = '.') ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/wslave_tools.rb', line 12

def self.set_dev_perms(path = '.')
  begin
    unless Dir.exist?("#{path}/public/data")
      FileUtils.mkdir("#{path}/public/data")
      FileUtils.touch("#{path}/public/data/.gitkeep")
    end
    FileUtils.chown(nil, 'www-data', "#{path}/public/data")
    FileUtils.chmod(0775, "#{path}/public/data")

    FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/themes")
    FileUtils.chmod(0775, "#{path}/public/wp-content/themes")

    FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/uploads")
    FileUtils.chmod(0775, "#{path}/public/wp-content/uploads")

    FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/plugins")
    FileUtils.chmod(0775, "#{path}/public/wp-content/plugins")
    
    unless Dir.exist?("#{path}/public/wp-content/upgrade")
      FileUtils.mkdir("#{path}/public/wp-content/upgrade")
      FileUtils.touch("#{path}/public/wp-content/upgrade/.gitkeep")
    end
    FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/upgrade")
    FileUtils.chmod(0775, "#{path}/public/wp-content/upgrade")

    unless Dir.exist?("#{path}/db")
      FileUtils.mkdir("#{path}/db")
    end
    FileUtils.chown(nil, 'www-data', "#{path}/db")
    FileUtils.chmod(0775, "#{path}/db")

    unless Dir.exist?("#{path}/db/active")
      FileUtils.mkdir("#{path}/db/active")
      FileUtils.touch("#{path}/db/active/.gitkeep")
    end
    FileUtils.chown(nil, 'www-data', "#{path}/db/active")
    FileUtils.chmod(0775, "#{path}/db/active")

    unless Dir.exist?("#{path}/db/dev")
      FileUtils.mkdir("#{path}/db/dev")
      FileUtils.touch("#{path}/db/dev/.gitkeep")
    end
    FileUtils.chown(nil, 'www-data', "#{path}/db/dev")
    FileUtils.chmod(0775, "#{path}/db/dev")

    unless Dir.exist?("#{path}/db/staging")
      FileUtils.mkdir("#{path}/db/staging")
      FileUtils.touch("#{path}/db/staging/.gitkeep")
    end
    FileUtils.chown(nil, 'www-data', "#{path}/db/staging")
    FileUtils.chmod(0775, "#{path}/db/staging")

    unless Dir.exist?("#{path}/db/production")
      FileUtils.mkdir("#{path}/db/production")
      FileUtils.touch("#{path}/db/production/.gitkeep")
    end
    FileUtils.chown(nil, 'www-data', "#{path}/db/production")
    FileUtils.chmod(0775, "#{path}/db/production")

  rescue Errno::EPERM
    puts "!!!WARNING!!! Your user does not belong to the www-data group!\n" \
      " >>> Unable to make folders writable for devlopment. <<<\n" \
      " >>> You will not be able to edit files or themes in the WP dev container! <<<\n"
  end
end

.syncObject



85
86
87
88
89
90
# File 'lib/wslave_tools.rb', line 85

def self.sync
  if wslave_root?
    update_submodules
    set_dev_perms
  end
end

.update_submodulesObject



81
82
83
# File 'lib/wslave_tools.rb', line 81

def self.update_submodules
  `git submodule update --init --recursive`
end

.wslave_root?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'lib/wslave_tools.rb', line 4

def self.wslave_root?()
  return true if (File.exist?("./config/.wslave") &&
                  File.exist?("docker-compose.yml"))
  puts "This does not appear to be the root of a WSlave managed app."
  puts "Run command again from the root directory of a WSlave app."
  false
end