Module: Rigup::Utils::Install

Included in:
Cli, DeployBase
Defined in:
lib/rigup/utils/install.rb

Instance Method Summary collapse

Instance Method Details

#apply_permissions(aPath = nil, aKind = nil) ⇒ Object



72
73
74
75
76
# File 'lib/rigup/utils/install.rb', line 72

def apply_permissions(aPath=nil,aKind=nil)
  aPath ||= release_path
  aKind ||= @kind || 'rails'
  internal_permissions(aPath, aKind)
end


78
79
80
81
82
83
84
85
# File 'lib/rigup/utils/install.rb', line 78

def ensure_link(aTo,aFrom,aUserGroup=nil,aSudo='')
  raise "Must supply from" if !aFrom
  cmd = []
  cmd << "#{aSudo} rm -rf #{aFrom}"
  cmd << "#{aSudo} ln -sf #{aTo} #{aFrom}"
  cmd << "#{aSudo} chown -h #{aUserGroup} #{aFrom}" if aUserGroup
  run(cmd.join(' && '),raise: false)
end

#internal_permissions(aPath, aKind) ⇒ Object



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
# File 'lib/rigup/utils/install.rb', line 46

def internal_permissions(aPath,aKind)
  case aKind
    when 'rails' then
      permissions_for_web(aPath,@user,@group,true)

      run_for_all("chmod +x",File.join(aPath,'script'),:files)


      uploads = shared_path+'/uploads'
      make_public_cache_dir(uploads)
      #if File.exists?(uploads)
      #  permissions_for_web(uploads,@user,@group,true)
      #  permissions_for_web_writable(uploads)
      #end
      #permissions_for_web_writable("#{aPath}/tmp")
      make_public_cache_dir("#{aPath}/tmp")

      run "#{context.config[:sudo]} chown #{@user} #{aPath}/config/environment.rb" #unless DEV_MODE  # very important for passenger, which uses the owner of this file to run as

    when 'spree' then
      internal_permissions(aPath,'rails')
    when 'browsercms' then
      internal_permissions(aPath,'rails')
  end
end

#make_public_cache_dir(aStartPath) ⇒ Object



87
88
89
90
91
# File 'lib/rigup/utils/install.rb', line 87

def make_public_cache_dir(aStartPath)
  run "#{context.config[:sudo]} mkdir -p #{aStartPath}"
  permissions_for_web(aStartPath)
  permissions_for_web_writable(aStartPath)
end

#override_folder(aFolder, aOverrideFolder = nil, aRemove = true) ⇒ Object

Especially for modifiying behaviour eg. of FCKEditor without upsetting the standard files eg. create a public_override folder that duplicates the same structure as public, and contains the modified files. On deployment call override_folder(“#@release_path/public”) # equiv to override_folder(“#@release_path/public”, “#@release_path/public_override”) and the files in public_override will be copied over public, then public_override removed



18
19
20
21
22
23
# File 'lib/rigup/utils/install.rb', line 18

def override_folder(aFolder,aOverrideFolder=nil,aRemove=true)
  aFolder = aFolder.desuffix('/')
  aOverrideFolder ||= (aFolder+'_override')
  run "#{context.config[:sudo]} cp -vrf #{aOverrideFolder}/* #{aFolder}/"
  run "#{context.config[:sudo]} rm -rf #{aOverrideFolder}" if aRemove
end

#permissions_for_web(aPath, aUser = nil, aGroup = nil, aHideScm = nil) ⇒ Object

set standard permissions for web sites - readonly for apache user



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rigup/utils/install.rb', line 27

def permissions_for_web(aPath,aUser=nil,aGroup=nil,aHideScm=nil)
  aUser ||= @user
  aGroup ||= @group

  run "#{context.config[:sudo]} chown -R #{aUser}:#{aGroup} #{aPath.ensure_suffix('/')}"
  run_for_all("chmod 755",aPath,:dirs)                 # !!! perhaps reduce other permissions
  run_for_all("chmod 644",aPath,:files)
  run_for_all("chmod g+s",aPath,:dirs)
  case aHideScm
    when :svn then run_for_all("chmod -R 700",aPath,:dirs,"*/.svn")
  end
end

#permissions_for_web_writable(aPath) ⇒ Object

run this after permissions_for_web() on dirs that need to be writable by group (apache)



41
42
43
44
# File 'lib/rigup/utils/install.rb', line 41

def permissions_for_web_writable(aPath)
  run "chmod -R g+w #{aPath.ensure_suffix('/')}"
  run_for_all("chmod -R 700",aPath,:dirs,"*/.svn")
end

#select_suffixed_file(aFile, aExtendedExtension = false) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/rigup/utils/install.rb', line 5

def select_suffixed_file(aFile,aExtendedExtension=false)
  ext = Buzztools::File.extension(aFile,aExtendedExtension)
  no_ext = Buzztools::File.no_extension(aFile,aExtendedExtension)
  dir = File.dirname(aFile)
  run "#{context.config[:sudo]} mv -f #{no_ext}.#{context.config[:stage]}.#{ext} #{aFile}"
  run "#{context.config[:sudo]} rm -f #{no_ext}.*.#{ext}"
end