-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
120 lines (101 loc) · 2.94 KB
/
Copy pathinstall
File metadata and controls
120 lines (101 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/ruby
# Preamble
system "clear"
puts "Mac Formatter Installer"
puts
puts "You can update or reinstall Mac Formatter by running this script a second time."
puts
puts
puts "This script will install the following:"
puts "1. The mac_formatter command line tool"
puts "2. The Docopt gem, required by the cli tool"
puts "3. The OS X services providing right-click conversions"
puts "Note: You may have to type your admin password to install some components."
print "Would you like to continue? (y/n) > "
response = gets.chomp.strip.downcase
options = %w(y n)
until options.include? response
puts "Invalid option. Enter y or n."
print "> "
response = gets.chomp.strip.downcase
end
case response
when "n"
puts "Exiting..."
sleep 2
exit
when "y"
puts "Beginning install..."
sleep 2
puts
end
# install the Docopt gem.
def install_docopt
# Check for docopt gem. Use system gem, not rbenv or rvm.
# The OS X services will require use of system Ruby.
begin
require 'docopt'
docopt_status = true
rescue LoadError => e
docopt_status = false
end
unless docopt_status
puts "Docopt gem does not appear to be installed."
puts "Installing..."
`sudo /usr/bin/gem install docopt --no-document 2> /dev/null`
if $?.success?
puts
puts "Docopt installed successfully."
else
puts "Docopt gem failed to install."
puts "Check your Ruby configuration and try again."
exit
end
end
end
# Install the mac_format CLI Tool.
def install_cli_tool
# check for /usr/local/bin. Create if necessary.
if File.directory?('/usr/local/bin')
puts "/usr/local/bin exists..."
else
puts "/usr/local/bin does not exist, creating..."
`sudo mkdir /usr/local/bin && chmod 0755 /usr/local/bin`
end
Dir.chdir('/usr/local/bin')
# Download mac_format
puts "Downloading CLI tool..."
`sudo curl -s -O https://raw.githubusercontent.com/xraystyle/mac_format/master/mac_format && sudo chmod a+x mac_format`
if $?.success?
puts "mac_format CLI tool installed..."
puts
else
puts "Error installing CLI tool."
puts "mac_format failed to download."
exit
end
end
# Install the OS X contextual menu Automator services.
def install_services
Dir.chdir(File.expand_path("~/Library/Services"))
puts "Downloading the OS X right-click services..."
`curl -s -O https://raw.githubusercontent.com/xraystyle/mac_format/master/services.tar.gz`
`tar -xzf services.tar.gz > /dev/null 2>&1`
unless $?.success?
puts "There was an error downloading the OS X services."
puts "Try running the installer again."
exit
end
`rm services.tar.gz`
puts "OS X services installed successfully."
puts
end
########################### Begin Script ###########################
install_docopt
install_cli_tool
install_services
puts "MAC Formatter appears to have installed successfully."
puts "See the readme at https://github.com/xraystyle/mac_format for usage instructions."
puts
puts
exit 0