module Makitzo::SSH::Commands::Apple
Public Instance Methods
daily_shutdown()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/makitzo/ssh/commands/apple.rb, line 86 def reboot sudo { exec('reboot') } end
serial_number()
click to toggle source
# 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)
click to toggle source
format of restart_time is mm/dd/yy HH:MM:ss
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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