-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
77 lines (66 loc) · 2.25 KB
/
Rakefile
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
# -*- ruby-*-
require 'ostruct'
require 'pathname'
desc "Install the application for this user"
task :install_user do
ctoolu_install USER_DIRS
end
desc "Install the application for systemwide use"
task :install do
ctoolu_install SYSTEM_DIRS
end
desc "Run the application from the working copy"
task :run do
sh 'XDG_CONFIG_HOME=`pwd`/config XDG_DATA_HOME=`pwd`/data ./ctoolu'
end
# FIXME, this is not exactly following
# http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
HOME = ENV['HOME']
USER_DIRS = {
"bin" => "#{HOME}/bin",
"xdg_config" => "#{HOME}/.config",
"xdg_data" => "#{HOME}/.local/share",
}
SYSTEM_DIRS = {
"bin" => "/usr/bin",
"xdg_config" => "/etc/xdg",
"xdg_data" => "/usr/share",
}
# calls FileUtils.install
# but assumes the target is a directory and ensures it exists
# Option :pkill will kill the program that was installed
# (assuming it will get restarted somehow)
# Option :config will take care not to overwrite an existing file,
# appending .new to the installed one.
def dir_install(source, target_dir, options={})
pkill = options.delete :pkill
config = options.delete :config
mkdir_p target_dir, options.merge({:mode => nil})
target = target_dir
if config
target << '/' << Pathname.new(source).basename.to_s
if File.exist? target
target << ".new"
end
end
install source, target, options
if pkill
# Pkill never kills itself, good.
# The variable references ensure it doesn't kill its parent shell, duh.
sh "TD=#{target_dir}; S=#{source}; pkill -f $TD/$S || true"
end
end
# installs ctoolu, using a hash defining the base directories
def ctoolu_install(dirs)
# make ostruct from hash for easier access
dirs = OpenStruct.new(dirs) unless dirs.respond_to? :bin
dir_install "ctoolu", dirs.bin, :mode => 0755, :pkill => true
dir_install "ctoolu-activate", dirs.bin, :mode => 0755
dir_install "ctoolu.desktop", dirs.xdg_config + "/autostart"
dir_install "config/ctoolu.yaml", dirs.xdg_config, :config => true
Dir.glob("data/ctoolu/*.yaml") do |rule|
dir_install rule, dirs.xdg_data + "/ctoolu"
end
dir_install "clipboard-relay", dirs.bin, :mode => 0755, :pkill => true
dir_install "net.vidner.ClipboardRelay.service", dirs.xdg_data + "/dbus-1/services"
end