Module: Makitzo::SSH::Commands::Apple
- Included in:
- Makitzo::SSH::Context
- Defined in:
- lib/makitzo/ssh/commands/apple.rb
Instance Method Summary collapse
- #daily_shutdown ⇒ Object
- #install_app(app, target = '/Applications', backup_file = nil) ⇒ Object
- #install_pkg(pkg) ⇒ Object
- #mount_dmg(path) ⇒ Object
- #reboot ⇒ Object
- #serial_number ⇒ Object
-
#shutdown(restart_time = nil) ⇒ Object
format of restart_time is mm/dd/yy HH:MM:ss.
- #shutdown_at(time) ⇒ Object
- #unmount_dmg(path) ⇒ Object
- #use_network_time_server(address) ⇒ Object
Instance Method Details
#daily_shutdown ⇒ Object
81 82 83 84 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 81 def daily_shutdown tomorrow = Time.now + 86400 shutdown(time.strftime("%m/%d/%y 08:45:00")) end |
#install_app(app, target = '/Applications', backup_file = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 34 def install_app(app, target = '/Applications', backup_file = nil) target_dir = File.join(target, File.basename(app)) exec("test -d #{x(target_dir)} && rm -rf #{x(target_dir)}") if exec("cp -R #{x(app)} #{x(target)}").success? logger.success("app #{app} installed to #{target}") true else logger.warn("failed to install #{app} to #{target}") false end end |
#install_pkg(pkg) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 46 def install_pkg(pkg) if exec("installer -pkg #{x(pkg)} -target /").success? logger.success("package #{pkg} installed to /") true else logger.warn("failed to install package #{pkg}") false end end |
#mount_dmg(path) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 3 def mount_dmg(path) mount_status = exec("hdiutil attach -puppetstrings #{x(path)}") if mount_status.error? logger.warn("unable to mount #{path}") false else mount_status.stdout.split("\n").reverse.each do |line| chunks = line.split(/\t+/) if chunks.length == 3 mount_point = chunks[2].strip unless mount_point.empty? logger.success("#{path} mounted at #{mount_point}") return mount_point end end end true end end |
#reboot ⇒ Object
86 87 88 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 86 def reboot sudo { exec('reboot') } end |
#serial_number ⇒ Object
90 91 92 93 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 90 def serial_number res = exec("system_profiler SPHardwareDataType | grep 'Serial Number' | awk '{ print $4; }'") res.success? ? res.stdout.strip : nil end |
#shutdown(restart_time = nil) ⇒ Object
format of restart_time is mm/dd/yy HH:MM:ss
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 67 def shutdown(restart_time = nil) sudo do if restart_time res = exec("pmset schedule poweron \"#{restart_time}\"") unless res.success? logger.error("couldn't set restart time") return false end end res = exec("shutdown -h now") res.success? end end |
#shutdown_at(time) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 56 def shutdown_at(time) sudo do unless exec("pmset schedule shutdown \"#{time}\"").success? logger.error("couldn't set poweroff time") return false end end true end |
#unmount_dmg(path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 23 def unmount_dmg(path) unmount_status = exec("hdiutil detach #{x(path)}") if unmount_status.error? logger.warn("unable to unmount #{path}") false else logger.success("#{path} unmounted") true end end |
#use_network_time_server(address) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/makitzo/ssh/commands/apple.rb', line 95 def use_network_time_server(address) sudo do exec!("systemsetup -setnetworktimeserver \"#{x(address)}\"") exec!("systemsetup -setusingnetworktime on") end end |