Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 3 files changed
  • 0 comments
  • 1 contributor

Showing 3 changed files with 88 additions and 24 deletions. Show diff stats Hide diff stats

  1. +74 23 Rakefile
  2. +12 0 dotcss.desktop
  3. +2 1  readme.md
97 Rakefile
@@ -5,8 +5,11 @@ task :install => "install:all"
5 5
6 6 DAEMON_INSTALL_DIR = "/usr/local/bin"
7 7
  8 +is_linux = RUBY_PLATFORM.downcase.include?("linux")
  9 +is_sudo = true if ENV['SUDO_USER']
  10 +
8 11 namespace :install do
9   - task :all => [:prompt, :daemon, :create_dir, :agent, :chrome, :done]
  12 + task :all => [:prompt, :daemon, :create_dir, :autostart, :chrome, :done]
10 13
11 14 task :prompt do
12 15 puts ""
@@ -15,7 +18,11 @@ namespace :install do
15 18 puts " I will install:"
16 19 puts " 1. The `dotcss` Chrome extension"
17 20 puts " 2. dcssd(1) in #{DAEMON_INSTALL_DIR}"
18   - puts " 3. com.averagestudios.dotcss in ~/Library/LaunchAgents"
  21 + if is_linux
  22 + puts " 3. dotcss.desktop in ~/.config/autostart"
  23 + else
  24 + puts " 3. com.averagestudios.dotcss in ~/Library/LaunchAgents"
  25 + end
19 26 puts ""
20 27 print " Ok? (y/n) "
21 28
@@ -43,19 +50,43 @@ namespace :install do
43 50 end
44 51 end
45 52
46   - desc "Install launch agent"
47   - task :agent do
48   - plist = "com.averagestudios.dotcss.plist"
49   - agent_dir = File.expand_path("~/Library/LaunchAgents/")
50   - agent = File.join(agent_dir, plist)
51   - Dir.mkdir(agent_dir) unless File.exists?(agent_dir)
  53 + desc "Install launch agent or Linux launcher"
  54 + task :autostart do
  55 + if is_linux
  56 + desktop_file = "dotcss.desktop"
  57 + launcher_dir = File.expand_path("~/.config/autostart/")
  58 + launcher = File.join(launcher_dir, desktop_file)
  59 + Dir.mkdir(launcher_dir) unless File.exists?(launcher_dir)
52 60
53   - File.open(agent, "w") do |f|
54   - f.puts ERB.new(IO.read(plist)).result(binding)
55   - end
  61 + File.open(launcher, "w") do |f|
  62 + f.puts ERB.new(IO.read(desktop_file)).result(binding)
  63 + end
  64 + if is_sudo
  65 + sh "chown #{ENV['SUDO_USER']}:#{ENV['SUDO_USER']} #{launcher}"
  66 + end
  67 +
  68 + puts "starting dcssd..."
  69 + command = "exo-open #{launcher} > /dev/null 2> /dev/null &"
  70 +
  71 + if is_sudo
  72 + sh "sudo -u #{ENV['SUDO_USER']} #{command}"
  73 + else
  74 + sh "#{command}"
  75 + end
  76 +
  77 + else
  78 + plist = "com.averagestudios.dotcss.plist"
  79 + agent_dir = File.expand_path("~/Library/LaunchAgents/")
  80 + agent = File.join(agent_dir, plist)
  81 + Dir.mkdir(agent_dir) unless File.exists?(agent_dir)
56 82
57   - puts "starting dcssd..."
58   - sh "launchctl load -w #{agent}"
  83 + File.open(agent, "w") do |f|
  84 + f.puts ERB.new(IO.read(plist)).result(binding)
  85 + end
  86 +
  87 + puts "starting dcssd..."
  88 + sh "launchctl load -w #{agent}"
  89 + end
59 90
60 91 # wait for server to start
61 92 sleep 5
@@ -77,7 +108,16 @@ namespace :install do
77 108 desc "Install Google Chrome extension"
78 109 task :chrome do
79 110 puts "Installing Google Chrome extension..."
80   - sh "open -a 'Google Chrome' builds/dotcss.crx &"
  111 + if is_linux
  112 + command = "google-chrome builds/dotcss.crx > /dev/null &"
  113 + if is_sudo
  114 + sh "sudo -u #{ENV['SUDO_USER']} #{command}"
  115 + else
  116 + sh "#{command}"
  117 + end
  118 + else
  119 + sh "open -a 'Google Chrome' builds/dotcss.crx &"
  120 + end
81 121 end
82 122 end
83 123
@@ -85,13 +125,17 @@ desc "Uninstall dotcss"
85 125 task :uninstall => "uninstall:all"
86 126
87 127 namespace :uninstall do
88   - task :all => [:prompt, :daemon, :agent, :chrome, :done]
  128 + task :all => [:prompt, :daemon, :autostart, :chrome, :done]
89 129
90 130 task :prompt do
91 131 puts ""
92 132 puts " I will remove:", ""
93 133 puts " 1. dcssd(1) from #{DAEMON_INSTALL_DIR}"
94   - puts " 2. com.averagestudios.dotcss from ~/Library/LaunchAgents"
  134 + if is_linux
  135 + puts " 2. dotcss.desktop from ~/.config/autostart"
  136 + else
  137 + puts " 2. com.averagestudios.dotcss from ~/Library/LaunchAgents"
  138 + end
95 139 puts " 3. The 'dotcss' Google Chrome Extension"
96 140 puts ""
97 141 puts " I will not remove:", ""
@@ -112,7 +156,7 @@ namespace :uninstall do
112 156 end
113 157
114 158 task :done do
115   - if system("curl http://localhost:1243 &> /dev/null")
  159 + if system("curl http://localhost:1243 2> /dev/null > /dev/null")
116 160 puts ""
117 161 puts " dotcss uninstall failed!"
118 162 puts " dcssd is still running."
@@ -123,12 +167,19 @@ namespace :uninstall do
123 167 end
124 168 end
125 169
126   - desc "Uninstall launch agent"
127   - task :agent do
128   - plist = "com.averagestudios.dotcss.plist"
129   - agent = File.expand_path("~/Library/LaunchAgents/#{plist}")
130   - sh "launchctl unload #{agent}"
131   - rm agent, :verbose => true
  170 + desc "Uninstall launch agent or Linux launcher"
  171 + task :autostart do
  172 + if is_linux
  173 + desktop_file = "dotcss.desktop"
  174 + launcher = File.expand_path("~/.config/autostart/#{desktop_file}")
  175 + sh "kill $(ps aux | grep '^#{ENV['SUDO_USER']}' | grep '.*dcssd' | awk '{print $2}') 2> /dev/null; true"
  176 + rm launcher, :verbose => true
  177 + else
  178 + plist = "com.averagestudios.dotcss.plist"
  179 + agent = File.expand_path("~/Library/LaunchAgents/#{plist}")
  180 + sh "launchctl unload #{agent}"
  181 + rm agent, :verbose => true
  182 + end
132 183 end
133 184
134 185 desc "Uninstall dotcss daemon"
12 dotcss.desktop
... ... @@ -0,0 +1,12 @@
  1 +
  2 +[Desktop Entry]
  3 +Type=Application
  4 +Exec=<%= DAEMON_INSTALL_DIR %>/dcssd
  5 +Hidden=false
  6 +NoDisplay=false
  7 +X-GNOME-Autostart-enabled=true
  8 +Name[en_US]=dotcss
  9 +Name=dotcss
  10 +Comment[en_US]=Launches dotcss server.
  11 +Comment=Launches dotcss server.
  12 +Path=<%= File.join(ENV['HOME'], ".css") %>
3  readme.md
Source Rendered
@@ -12,11 +12,12 @@ Chrome extensions can't access the local filesystem, so dotcss runs a tiny web s
12 12
13 13 ## requires
14 14
15   -- OS X
  15 +- OS X or Linux
16 16 - Ruby 1.8 or newer
17 17 - rake (`gem install rake`)
18 18 - Google Chrome
19 19 - `/usr/local/bin` in your `$PATH`
  20 +- on Linux: `exo-open` (Can be found in [exo-utils](http://packages.ubuntu.com/search?keywords=exo-utils) on Ubuntu. Required until [Bug #378783 in xdg-utils](https://bugs.launchpad.net/ubuntu/+source/xdg-utils/+bug/378783) is fixed.)
20 21
21 22 ## install
22 23

No commit comments for this range

Something went wrong with that request. Please try again.