boxen-linux 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +20 -0
  6. data/README.md +50 -0
  7. data/boxen.gemspec +26 -0
  8. data/lib/boxen/check.rb +72 -0
  9. data/lib/boxen/checkout.rb +25 -0
  10. data/lib/boxen/cli.rb +63 -0
  11. data/lib/boxen/config.rb +330 -0
  12. data/lib/boxen/error.rb +4 -0
  13. data/lib/boxen/flags.rb +272 -0
  14. data/lib/boxen/hook.rb +47 -0
  15. data/lib/boxen/hook/github_issue.rb +120 -0
  16. data/lib/boxen/hook/web.rb +56 -0
  17. data/lib/boxen/keychain.rb +63 -0
  18. data/lib/boxen/postflight.rb +13 -0
  19. data/lib/boxen/postflight/active.rb +16 -0
  20. data/lib/boxen/postflight/env.rb +34 -0
  21. data/lib/boxen/preflight.rb +13 -0
  22. data/lib/boxen/preflight/creds.rb +108 -0
  23. data/lib/boxen/preflight/directories.rb +32 -0
  24. data/lib/boxen/preflight/etc_my_cnf.rb +12 -0
  25. data/lib/boxen/preflight/homebrew.rb +13 -0
  26. data/lib/boxen/preflight/identity.rb +16 -0
  27. data/lib/boxen/preflight/os.rb +33 -0
  28. data/lib/boxen/preflight/rbenv.rb +12 -0
  29. data/lib/boxen/preflight/rvm.rb +12 -0
  30. data/lib/boxen/project.rb +20 -0
  31. data/lib/boxen/puppeteer.rb +122 -0
  32. data/lib/boxen/runner.rb +149 -0
  33. data/lib/boxen/service.rb +58 -0
  34. data/lib/boxen/util.rb +17 -0
  35. data/lib/facter/boxen.rb +34 -0
  36. data/lib/system_timer.rb +13 -0
  37. data/script/Boxen +0 -0
  38. data/script/Boxen-linux +0 -0
  39. data/script/bootstrap +7 -0
  40. data/script/build-keychain-helper +6 -0
  41. data/script/build-keyring-helper +9 -0
  42. data/script/release +38 -0
  43. data/script/tests +10 -0
  44. data/src/keychain-helper.c +85 -0
  45. data/src/keyring-helper.c +86 -0
  46. data/test/boxen/test.rb +7 -0
  47. data/test/boxen_check_test.rb +55 -0
  48. data/test/boxen_checkout_test.rb +42 -0
  49. data/test/boxen_cli_test.rb +39 -0
  50. data/test/boxen_config_test.rb +393 -0
  51. data/test/boxen_directories_test.rb +40 -0
  52. data/test/boxen_flags_test.rb +217 -0
  53. data/test/boxen_hook_github_issue_test.rb +294 -0
  54. data/test/boxen_hook_web_test.rb +58 -0
  55. data/test/boxen_keychain_test.rb +24 -0
  56. data/test/boxen_postflight_active_test.rb +29 -0
  57. data/test/boxen_postflight_env_test.rb +6 -0
  58. data/test/boxen_preflight_creds_test.rb +80 -0
  59. data/test/boxen_preflight_etc_my_cnf_test.rb +10 -0
  60. data/test/boxen_preflight_homebrew_test.rb +10 -0
  61. data/test/boxen_preflight_rvm_test.rb +10 -0
  62. data/test/boxen_project_test.rb +14 -0
  63. data/test/boxen_puppeteer_test.rb +101 -0
  64. data/test/boxen_runner_test.rb +171 -0
  65. data/test/boxen_service_test.rb +39 -0
  66. data/test/boxen_util_test.rb +21 -0
  67. data/test/fixtures/repo/modules/projects/manifests/first-project.pp +0 -0
  68. data/test/fixtures/repo/modules/projects/manifests/second-project.pp +0 -0
  69. data/test/system_timer.rb +10 -0
  70. metadata +279 -0
@@ -0,0 +1,149 @@
1
+ require "boxen/checkout"
2
+ require "boxen/config"
3
+ require "boxen/hook"
4
+ require "boxen/flags"
5
+ require "boxen/puppeteer"
6
+ require "boxen/service"
7
+ require "boxen/util"
8
+ require "facter"
9
+
10
+ module Boxen
11
+ class Runner
12
+ attr_reader :config
13
+ attr_reader :flags
14
+ attr_reader :puppet
15
+ attr_reader :checkout
16
+ attr_reader :hooks
17
+
18
+ def initialize(config, flags)
19
+ @config = config
20
+ @flags = flags
21
+ @puppet = Boxen::Puppeteer.new(@config)
22
+ @checkout = Boxen::Checkout.new(@config)
23
+ @hooks = Boxen::Hook.all
24
+ end
25
+
26
+ def process
27
+ # --env prints out the current BOXEN_ env vars.
28
+
29
+ exec "env | grep ^BOXEN_ | sort" if flags.env?
30
+
31
+ process_flags
32
+
33
+ process_args
34
+
35
+ # Actually run Puppet and return its result
36
+
37
+ puppet.run
38
+ end
39
+
40
+ def run
41
+ report(process)
42
+ end
43
+
44
+ def report(result)
45
+ hooks.each { |hook| hook.new(config, checkout, puppet, result).run }
46
+
47
+ result
48
+ end
49
+
50
+ def process_flags
51
+
52
+ # --projects prints a list of available projects and exits.
53
+
54
+ if flags.projects?
55
+ puts "You can install any of these projects with `#{$0} <project-name>`:\n"
56
+
57
+ config.projects.each do |project|
58
+ puts " #{project.name}"
59
+ end
60
+
61
+ exit
62
+ end
63
+
64
+ # --disable-services stops all services
65
+
66
+ if flags.disable_services?
67
+ Boxen::Service.list.each do |service|
68
+ puts "Disabling #{service}..."
69
+ service.disable
70
+ end
71
+
72
+ exit
73
+ end
74
+
75
+ # --enable-services starts all services
76
+
77
+ if flags.enable_services?
78
+ Boxen::Service.list.each do |service|
79
+ puts "Enabling #{service}..."
80
+ service.enable
81
+ end
82
+
83
+ exit
84
+ end
85
+
86
+ # --disable-service [name] stops a service
87
+
88
+ if flags.disable_service?
89
+ service = Boxen::Service.new(flags.disable_service)
90
+ puts "Disabling #{service}..."
91
+ service.disable
92
+
93
+ exit
94
+ end
95
+
96
+ # --enable-service [name] starts a service
97
+
98
+ if flags.enable_service?
99
+ service = Boxen::Service.new(flags.enable_service)
100
+ puts "Enabling #{service}..."
101
+ service.enable
102
+
103
+ exit
104
+ end
105
+
106
+ # --restart-service [name] starts a service
107
+
108
+ if flags.restart_service?
109
+ service = Boxen::Service.new(flags.restart_service)
110
+ puts "Restarting #{service}..."
111
+ service.disable
112
+ service.enable
113
+
114
+ exit
115
+ end
116
+
117
+ # --list-services lists all services
118
+
119
+ if flags.list_services?
120
+ Boxen::Service.list.each do |service|
121
+ puts service
122
+ end
123
+
124
+ exit
125
+ end
126
+
127
+ # --restart-services restarts all services
128
+
129
+ if flags.restart_services?
130
+ Boxen::Service.list_enabled.each do |service|
131
+ puts "Restarting #{service}..."
132
+ service.disable
133
+ service.enable
134
+ end
135
+
136
+ exit
137
+ end
138
+
139
+ end
140
+
141
+ def process_args
142
+ projects = flags.args.join(',')
143
+ File.open("#{config.repodir}/.projects", "w+") do |f|
144
+ f.truncate 0
145
+ f.write projects
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,58 @@
1
+ require "boxen/util"
2
+
3
+ module Boxen
4
+ class Service
5
+ attr_reader :name
6
+
7
+ def self.list
8
+ files.collect do |service|
9
+ new(human_name(service))
10
+ end
11
+ end
12
+
13
+ def self.list_enabled
14
+ prefix = /^dev\./
15
+ enabled = capture_output("sudo /bin/launchctl list").split("\n").map { |l| l.split(/\s/) }.map(&:last)
16
+ names = enabled.grep(prefix).map { |name| name.sub(prefix, "") }.compact
17
+ names.map { |name| new(name) }
18
+ end
19
+
20
+ def initialize(name)
21
+ @name = name
22
+ end
23
+
24
+ def to_s
25
+ name
26
+ end
27
+
28
+ def enable
29
+ Boxen::Util.sudo('/bin/launchctl', 'load', '-w', location)
30
+ end
31
+
32
+ def disable
33
+ Boxen::Util.sudo('/bin/launchctl', 'unload', '-w', location)
34
+ end
35
+
36
+ private
37
+
38
+ def self.capture_output(command)
39
+ `#{command}`
40
+ end
41
+
42
+ def location
43
+ "#{self.class.location}/dev.#{name}.plist"
44
+ end
45
+
46
+ def self.location
47
+ "/Library/LaunchDaemons"
48
+ end
49
+
50
+ def self.files
51
+ Dir["#{location}/dev.*.plist"]
52
+ end
53
+
54
+ def self.human_name(service)
55
+ service.match(/dev\.(.+)\.plist$/)[1]
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ module Boxen
2
+ module Util
3
+
4
+ # Is Boxen active?
5
+
6
+ def self.active?
7
+ ENV.include? "BOXEN_HOME"
8
+ end
9
+
10
+
11
+ # Run `args` as a system command with sudo if necessary.
12
+
13
+ def self.sudo *args
14
+ system "sudo", "-p", "Password for sudo: ", *args
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ require "json"
2
+ require "boxen/config"
3
+
4
+ config = Boxen::Config.load
5
+ facts = {}
6
+ factsdir = "#{config.homedir}/config/facts"
7
+ dot_boxen = "#{ENV['HOME']}/.boxen"
8
+ user_config = "#{dot_boxen}/config.json"
9
+
10
+ facts["github_login"] = config.login
11
+ facts["github_email"] = config.email
12
+ facts["github_name"] = config.name
13
+ facts["github_token"] = config.token
14
+
15
+ facts["boxen_home"] = config.homedir
16
+ facts["boxen_srcdir"] = config.srcdir
17
+ facts["boxen_repodir"] = config.repodir
18
+ facts["boxen_user"] = config.user
19
+ facts["luser"] = config.user # this is goin' away
20
+
21
+ Dir["#{config.homedir}/config/facts/*.json"].each do |file|
22
+ facts.merge! JSON.parse File.read file
23
+ end
24
+
25
+ if File.directory?(dot_boxen) && File.file?(user_config)
26
+ facts.merge! JSON.parse(File.read(user_config))
27
+ end
28
+
29
+ if File.file?(dot_boxen)
30
+ warn "DEPRECATION: ~/.boxen is deprecated and will be removed in 2.0; use ~/.boxen/config.json instead!"
31
+ facts.merge! JSON.parse(File.read(dot_boxen))
32
+ end
33
+
34
+ facts.each { |k, v| Facter.add(k) { setcode { v } } }
@@ -0,0 +1,13 @@
1
+ # Faraday helpfully reminds you to install `system_timer` if you're
2
+ # running Ruby 1.8, since Timeout can give unreliable results. We
3
+ # can't do this during first-time runs, since there's no C compiler
4
+ # available.
5
+ #
6
+ # To squash the message and stop confusing people, this shim just
7
+ # exposes Timeout as SystemTimer. I'm a bad person.
8
+
9
+
10
+ if (!defined?(RUBY_ENGINE) || "ruby" == RUBY_ENGINE) && RUBY_VERSION < '1.9'
11
+ require "timeout"
12
+ SystemTimer = Timeout
13
+ end
Binary file
Binary file
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ # Make sure local dependencies are satisfied.
3
+
4
+ cd "$(dirname $0)"/..
5
+
6
+ rm -f .bundle/config
7
+ bundle install --binstubs bin --path .bundle --quiet
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ cd $(dirname "$0")/..
6
+ cc -g -O2 -Wall -framework Security -framework CoreFoundation -mmacosx-version-min=10.6 -o script/Boxen src/keychain-helper.c
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ #to check default pkg-config path
4
+ #pkg-config --variable pc_path pkg-config
5
+
6
+ set -e
7
+
8
+ cd $(dirname "$0")/..
9
+ cc -g -O2 -Wall `pkg-config --cflags glib-2.0 gnome-keyring-1`-o script/Boxen-linux src/keyring-helper.c `pkg-config --libs glib-2.0 gnome-keyring-1`
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ # Make sure we're in the project root.
7
+
8
+ cd $(dirname "$0")/..
9
+
10
+ # Build a new gem archive.
11
+
12
+ rm -rf boxen-*.gem
13
+ gem build -q boxen.gemspec
14
+
15
+ # Make sure we're on the master branch.
16
+
17
+ (git branch | grep -q '* master') || {
18
+ echo "Only release from the master branch."
19
+ exit 1
20
+ }
21
+
22
+ # Figure out what version we're releasing.
23
+
24
+ tag=v`ls boxen-*.gem | sed 's/^boxen-\(.*\)\.gem$/\1/'`
25
+
26
+ # Make sure we haven't released this version before.
27
+
28
+ git fetch -t origin
29
+
30
+ (git tag -l | grep -q "$tag") && {
31
+ echo "Whoops, there's already a '${tag}' tag."
32
+ exit 1
33
+ }
34
+
35
+ # Tag it and bag it.
36
+
37
+ gem push boxen-*.gem && git tag "$tag" &&
38
+ git push origin master && git push origin "$tag"
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+ # Run the unit tests.
3
+
4
+ cd "$(dirname $0)"/..
5
+
6
+ script/bootstrap &&
7
+ ruby -rubygems -Ilib:test \
8
+ -e 'require "bundler/setup"' \
9
+ -e 'tests = ARGV.empty? ? Dir["test/**/*_test.rb"] : ARGV' \
10
+ -e 'tests.each { |f| load f }' "$@"
@@ -0,0 +1,85 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <Security/Security.h>
4
+ #include <CoreFoundation/CFString.h>
5
+
6
+ #define REPORT_KEYCHAIN_ERROR(err_val) do { \
7
+ fprintf(stderr, "Boxen Keychain Helper: Encountered error code: %d\n", err_val); \
8
+ fprintf(stderr, "Error: %s\n", CFStringGetCStringPtr(SecCopyErrorMessageString(err_val, NULL), kCFStringEncodingMacRoman)); \
9
+ } while(0)
10
+
11
+ int key_exists_p(
12
+ const char *service,
13
+ const char *login,
14
+ SecKeychainItemRef *item
15
+ ) {
16
+ void *buf;
17
+ UInt32 len;
18
+
19
+ OSStatus ret = SecKeychainFindGenericPassword(
20
+ NULL, strlen(service), service, strlen(login), login, &len, &buf, item
21
+ );
22
+
23
+ if (ret == errSecSuccess) {
24
+ return 0;
25
+ } else {
26
+ if (ret != errSecItemNotFound) {
27
+ // Item not found is not an error in predicate method context.
28
+ REPORT_KEYCHAIN_ERROR(ret);
29
+ }
30
+ return ret;
31
+ }
32
+ }
33
+
34
+ int main(int argc, char **argv) {
35
+ if ((argc < 3) || (argc > 4)) {
36
+ printf("Usage: %s <service> <account> [<password>]\n", argv[0]);
37
+ return 1;
38
+ }
39
+
40
+ const char *service = argv[1];
41
+ const char *login = argv[2];
42
+ const char *password = argc == 4 ? argv[3] : NULL;
43
+
44
+ void *buf;
45
+ UInt32 len;
46
+ SecKeychainItemRef item;
47
+
48
+ if (password != NULL && strlen(password) != 0) {
49
+ if (key_exists_p(service, login, &item) == 0) {
50
+ SecKeychainItemDelete(item);
51
+ }
52
+
53
+ OSStatus create_key = SecKeychainAddGenericPassword(
54
+ NULL, strlen(service), service, strlen(login), login, strlen(password),
55
+ password, &item
56
+ );
57
+
58
+ if (create_key != 0) {
59
+ REPORT_KEYCHAIN_ERROR(create_key);
60
+ return 1;
61
+ }
62
+ } else if (password != NULL && strlen(password) == 0) {
63
+ if (key_exists_p(service, login, &item) == 0) {
64
+ OSStatus ret = SecKeychainItemDelete(item);
65
+ if (ret != errSecSuccess) {
66
+ REPORT_KEYCHAIN_ERROR(ret);
67
+ }
68
+ }
69
+ } else {
70
+ OSStatus find_key = SecKeychainFindGenericPassword(
71
+ NULL, strlen(service), service, strlen(login), login, &len, &buf, &item);
72
+
73
+ if (find_key == errSecItemNotFound) {
74
+ return find_key;
75
+ }
76
+ if (find_key != 0) {
77
+ REPORT_KEYCHAIN_ERROR(find_key);
78
+ return 1;
79
+ }
80
+
81
+ fwrite(buf, 1, len, stdout);
82
+ }
83
+
84
+ return 0;
85
+ }
@@ -0,0 +1,86 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+ #include "gnome-keyring.h"
5
+
6
+ #define REPORT_KEYRING_ERROR(err_val) do { \
7
+ fprintf(stderr, "Boxen Keyring Helper: Encountered gnome keyring error code: %d\n", err_val); \
8
+ } while(0)
9
+ //fprintf(stderr, "Error: %s\n", CFStringGetCStringPtr(SecCopyErrorMessageString(err_val, NULL), kCFStringEncodingMacRoman));
10
+
11
+ GnomeKeyringPasswordSchema GenericPassword = {
12
+ GNOME_KEYRING_ITEM_CHAINED_KEYRING_PASSWORD,
13
+ {
14
+ { "service", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
15
+ { "account", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
16
+ { NULL, 0 }
17
+ }
18
+ };
19
+
20
+ int key_exists_p(
21
+ const char* service,
22
+ const char* login,
23
+ char* item
24
+ ) {
25
+
26
+ GnomeKeyringResult ret = gnome_keyring_find_password_sync(&GenericPassword, &item, "service", service, "account", login, NULL);
27
+
28
+ gnome_keyring_free_password(item);
29
+ if (ret == GNOME_KEYRING_RESULT_OK) {
30
+ return 0;
31
+ } else {
32
+ if (ret != GNOME_KEYRING_RESULT_NO_MATCH) {
33
+ // Item not found is not an error in predicate method context.
34
+ REPORT_KEYRING_ERROR(ret);
35
+ }
36
+ return ret;
37
+ }
38
+ }
39
+
40
+ int main(int argc, char** argv) {
41
+ if ((argc < 3) || (argc > 4)) {
42
+ printf("Usage: %s <service> <account> [<password>]\n", argv[0]);
43
+ return 1;
44
+ }
45
+
46
+ const char* service = argv[1];
47
+ const char* login = argv[2];
48
+ const char* password = argc == 4 ? argv[3] : NULL;
49
+
50
+ char* item = NULL;
51
+
52
+ if (password != NULL && strlen(password) != 0) {
53
+ if (key_exists_p(service, login, item) == 0) {
54
+ gnome_keyring_delete_password_sync(&GenericPassword, "service", service, "account", login, NULL);
55
+ }
56
+
57
+ GnomeKeyringResult create_key = gnome_keyring_store_password_sync(&GenericPassword, NULL, service, password, "service", service, "account", login, NULL);
58
+
59
+ if (create_key != 0) {
60
+ REPORT_KEYRING_ERROR(create_key);
61
+ return 1;
62
+ }
63
+ } else if (password != NULL && strlen(password) == 0) {
64
+ if (key_exists_p(service, login, item) == 0) {
65
+ GnomeKeyringResult ret = gnome_keyring_delete_password_sync(&GenericPassword, "service", service, "account", login, NULL);
66
+ if (ret != GNOME_KEYRING_RESULT_OK) {
67
+ REPORT_KEYRING_ERROR(ret);
68
+ }
69
+ }
70
+ } else {
71
+ GnomeKeyringResult find_key = gnome_keyring_find_password_sync(&GenericPassword, &item, "service", service, "account", login, NULL);
72
+
73
+ if (find_key == GNOME_KEYRING_RESULT_NO_MATCH) {
74
+ return find_key;
75
+ }
76
+ if (find_key != 0) {
77
+ REPORT_KEYRING_ERROR(find_key);
78
+ return 1;
79
+ }
80
+
81
+ fwrite(item, 1, strlen(item), stdout);
82
+ gnome_keyring_free_password(item);
83
+ }
84
+
85
+ return 0;
86
+ }