linecook 0.6.2 → 1.0.0

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 (72) hide show
  1. data/History +139 -0
  2. data/HowTo/Control Virtual Machines +106 -0
  3. data/HowTo/Generate Scripts +263 -0
  4. data/HowTo/Run Scripts +87 -0
  5. data/HowTo/Setup Virtual Machines +76 -0
  6. data/License.txt +1 -1
  7. data/README +78 -59
  8. data/bin/linecook +12 -5
  9. data/bin/linecook_run +45 -0
  10. data/bin/linecook_scp +50 -0
  11. data/lib/linecook.rb +1 -3
  12. data/lib/linecook/attributes.rb +49 -12
  13. data/lib/linecook/commands.rb +9 -4
  14. data/lib/linecook/commands/build.rb +69 -0
  15. data/lib/linecook/commands/command.rb +13 -3
  16. data/lib/linecook/commands/command_error.rb +6 -0
  17. data/lib/linecook/commands/env.rb +74 -8
  18. data/lib/linecook/commands/helper.rb +271 -24
  19. data/lib/linecook/commands/init.rb +10 -6
  20. data/lib/linecook/commands/package.rb +36 -18
  21. data/lib/linecook/commands/run.rb +66 -0
  22. data/lib/linecook/commands/snapshot.rb +114 -0
  23. data/lib/linecook/commands/ssh.rb +39 -0
  24. data/lib/linecook/commands/start.rb +34 -0
  25. data/lib/linecook/commands/state.rb +32 -0
  26. data/lib/linecook/commands/stop.rb +22 -0
  27. data/lib/linecook/commands/vbox_command.rb +130 -0
  28. data/lib/linecook/cookbook.rb +112 -55
  29. data/lib/linecook/package.rb +293 -109
  30. data/lib/linecook/proxy.rb +19 -0
  31. data/lib/linecook/recipe.rb +321 -62
  32. data/lib/linecook/template.rb +7 -101
  33. data/lib/linecook/test.rb +196 -141
  34. data/lib/linecook/test/command_parser.rb +75 -0
  35. data/lib/linecook/test/file_test.rb +153 -35
  36. data/lib/linecook/test/shell_test.rb +176 -0
  37. data/lib/linecook/utils.rb +25 -7
  38. data/lib/linecook/version.rb +4 -4
  39. data/templates/Rakefile +44 -47
  40. data/templates/_gitignore +1 -1
  41. data/templates/attributes/project_name.rb +4 -4
  42. data/templates/config/ssh +15 -0
  43. data/templates/files/help.txt +1 -0
  44. data/templates/helpers/project_name/assert_content_equal.erb +15 -0
  45. data/templates/helpers/project_name/create_dir.erb +9 -0
  46. data/templates/helpers/project_name/create_file.erb +8 -0
  47. data/templates/helpers/project_name/install_file.erb +8 -0
  48. data/templates/packages/abox.yml +4 -0
  49. data/templates/recipes/abox.rb +22 -0
  50. data/templates/recipes/abox_test.rb +14 -0
  51. data/templates/templates/todo.txt.erb +3 -0
  52. data/templates/test/project_name_test.rb +19 -0
  53. data/templates/test/test_helper.rb +14 -0
  54. metadata +43 -41
  55. data/cookbook +0 -0
  56. data/lib/linecook/commands/helpers.rb +0 -28
  57. data/lib/linecook/commands/vbox.rb +0 -85
  58. data/lib/linecook/helper.rb +0 -117
  59. data/lib/linecook/shell.rb +0 -11
  60. data/lib/linecook/shell/posix.rb +0 -145
  61. data/lib/linecook/shell/test.rb +0 -254
  62. data/lib/linecook/shell/unix.rb +0 -117
  63. data/lib/linecook/shell/utils.rb +0 -138
  64. data/templates/README +0 -90
  65. data/templates/files/file.txt +0 -1
  66. data/templates/helpers/project_name/echo.erb +0 -5
  67. data/templates/recipes/project_name.rb +0 -20
  68. data/templates/scripts/project_name.yml +0 -7
  69. data/templates/templates/template.txt.erb +0 -3
  70. data/templates/vbox/setup/virtual_box +0 -86
  71. data/templates/vbox/ssh/id_rsa +0 -27
  72. data/templates/vbox/ssh/id_rsa.pub +0 -1
@@ -1,138 +0,0 @@
1
- require 'erb'
2
-
3
- # Generated by Linecook, do not edit.
4
- module Linecook
5
- module Shell
6
- module Utils
7
- require 'linecook/shell/posix'
8
- include Posix
9
-
10
- DEFAULT_SHELL_PATH = '/bin/sh'
11
- DEFAULT_ENV_PATH = '/usr/bin/env'
12
-
13
- TARGET_PATH = '$LINECOOK_DIR/%s'
14
-
15
- attr_writer :shell_path
16
- attr_writer :env_path
17
-
18
- def shell_path
19
- @shell_path ||= DEFAULT_SHELL_PATH
20
- end
21
-
22
- def env_path
23
- @env_path ||= DEFAULT_ENV_PATH
24
- end
25
-
26
- def target_path(source_path)
27
- TARGET_PATH % super(source_path)
28
- end
29
-
30
- def close
31
- unless closed?
32
- break_line " (#{target_name}) "
33
- end
34
-
35
- super
36
- end
37
- # :stopdoc:
38
- BREAK_LINE_LINE = __LINE__ + 2
39
- BREAK_LINE = "self." + ERB.new(<<'END_OF_TEMPLATE', nil, '<>').src
40
- <% n = (76 - comment.length)/2 %>
41
- <%= "#" * n %><%= comment %><%= "#" * n %>
42
-
43
- END_OF_TEMPLATE
44
- # :startdoc:
45
-
46
- def break_line(comment="")
47
- eval(BREAK_LINE, binding, __FILE__, BREAK_LINE_LINE)
48
- nil
49
- end
50
-
51
- def _break_line(*args, &block) # :nodoc:
52
- capture { break_line(*args, &block) }
53
- end
54
-
55
- # :stopdoc:
56
- CHECK_STATUS_LINE = __LINE__ + 2
57
- CHECK_STATUS = "self." + ERB.new(<<'END_OF_TEMPLATE', nil, '<>').src
58
- check_status <%= status %> $? $LINENO
59
- END_OF_TEMPLATE
60
- # :startdoc:
61
-
62
- # Adds a check after a command that ensures the status is as indicated
63
- def check_status(status=0)
64
- eval(CHECK_STATUS, binding, __FILE__, CHECK_STATUS_LINE)
65
- nil
66
- end
67
-
68
- def _check_status(*args, &block) # :nodoc:
69
- capture { check_status(*args, &block) }
70
- end
71
-
72
- # :stopdoc:
73
- CHECK_STATUS_FUNCTION_LINE = __LINE__ + 2
74
- CHECK_STATUS_FUNCTION = "self." + ERB.new(<<'END_OF_TEMPLATE', nil, '<>').src
75
- function check_status { if [ $1 -ne $2 ]; then echo "[$2] $0:$3"; exit $2; fi }
76
- END_OF_TEMPLATE
77
- # :startdoc:
78
-
79
- # Adds the check status function.
80
- def check_status_function
81
- eval(CHECK_STATUS_FUNCTION, binding, __FILE__, CHECK_STATUS_FUNCTION_LINE)
82
- nil
83
- end
84
-
85
- def _check_status_function(*args, &block) # :nodoc:
86
- capture { check_status_function(*args, &block) }
87
- end
88
-
89
- # :stopdoc:
90
- SHEBANG_LINE = __LINE__ + 2
91
- SHEBANG = "self." + ERB.new(<<'END_OF_TEMPLATE', nil, '<>').src
92
- #! <%= shell_path %>
93
-
94
- <%= break_line %>
95
- <%= check_status_function %>
96
-
97
- export -f check_status
98
- export LINECOOK_DIR=$(dirname $0)
99
- export LINECOOK_OPTIONS=
100
-
101
- while getopts bhvx opt
102
- do
103
- case $opt in
104
- v) LINECOOK_OPTIONS="$LINECOOK_OPTIONS -v";;
105
- x) LINECOOK_OPTIONS="$LINECOOK_OPTIONS -x";;
106
- h) printf "Usage: %s: [-hvx]\n" $0
107
- printf " -h prints this help\n"
108
- printf " -v verbose (set -v)\n"
109
- printf " -x xtrace (set -x)\n"
110
- exit 0;;
111
- ?) printf "Usage: %s: [-hvx]\n" $0
112
- exit 2;;
113
- esac
114
- done
115
-
116
- set $LINECOOK_OPTIONS > /dev/null
117
- <%= break_line " #{target_name} " %>
118
-
119
- END_OF_TEMPLATE
120
- # :startdoc:
121
-
122
- # == Notes
123
-
124
- # Use dev/null on set such that no options will not dump ENV into stdout.
125
-
126
- def shebang(shell_path=DEFAULT_SHELL_PATH, env_path=DEFAULT_ENV_PATH)
127
- @shell_path = shell_path
128
- @env_path = env_path
129
- eval(SHEBANG, binding, __FILE__, SHEBANG_LINE)
130
- nil
131
- end
132
-
133
- def _shebang(*args, &block) # :nodoc:
134
- capture { shebang(*args, &block) }
135
- end
136
- end
137
- end
138
- end
data/templates/README DELETED
@@ -1,90 +0,0 @@
1
- = README
2
-
3
- Linecook provides support to develop scripts using VirtualBox, an open-source
4
- product to setup and manage virtual machines. Nothing says you have to use
5
- VirtualBox during development and obviously you can take the shell scripts
6
- produced by Linecook and run them wherever.
7
-
8
- These are instructions for setting up a generic Ubuntu VM for development.
9
-
10
- 1. Download and Install VirtualBox (http://www.virtualbox.org)
11
- 2. Download a Ubuntu ISO (http://www.ubuntu.com/server/get-ubuntu/download)
12
- 3. Build the Box
13
-
14
- Use the VirtualBox wizard to get started.
15
-
16
- - name: vbox
17
- - Linux/Ubuntu
18
- - 512 MB memory
19
- - 8 GB dynamically resizing drive
20
-
21
- Under Settings:
22
-
23
- - add the ubuntu iso to the cd/dvd device (under storage)
24
- - disable audio
25
- - network set to NAT
26
- - disable usb (only the inner box would stay unchecked)
27
- - shared folder: map the 'vbox' directory in project root
28
-
29
- Start the server and install (default unless specified):
30
-
31
- - hostname: vbox-ubuntu
32
- - user/password: vbox
33
- - no packages
34
- - power off, remove ubuntu iso from the cd/dvd device
35
-
36
- Setup Permissions (allows vbox to run sudo without password):
37
-
38
- vm: sudo visudo
39
-
40
- # insert line:
41
- #
42
- # %vbox ALL=NOPASSWD: ALL
43
- #
44
- # then exit (write out changes as prompted)
45
-
46
- Setup guest additions (note they are in the application package on
47
- osx http://forums.virtualbox.org/viewtopic.php?f=8&t=10286) See also:
48
- http://forums.virtualbox.org/viewtopic.php?t=15868.
49
-
50
- (cd/dvd device): add the VBoxGuestAdditions.iso
51
- vm: sudo apt-get install linux-headers-$(uname -r) build-essential ssh openssh-server
52
- vm: sudo mkdir /media/dvd
53
- vm: sudo mount /dev/dvd /media/dvd/
54
- vm: sudo sh /media/dvd/VBoxLinuxAdditions-x86.run
55
- # there may be a warning about 'Window System drivers fail', ignore
56
-
57
- Add an init script to mount the share on boot:
58
-
59
- vm: sudo mkdir /vbox
60
- vm: sudo mount -t vboxsf -o uid=1000,gid=100 vbox /vbox
61
- vm: sudo cp /vbox/setup/virtual_box /etc/init.d
62
- vm: sudo chmod 0755 /etc/init.d/virtual_box
63
- vm: sudo update-rc.d virtual_box defaults 80
64
-
65
- Setup SSH:
66
-
67
- vm: mkdir ~/.ssh
68
- vm: chmod 0700 ~/.ssh
69
- vm: cat /vbox/ssh/id_rsa.pub >> ~/.ssh/authorized_keys
70
- vm: chmod 0600 ~/.ssh/authorized_keys
71
-
72
- Now take a snapshot and setup port forwarding:
73
-
74
- vm: exit
75
- ht: VBoxManage snapshot vbox take BASE
76
- ht: VBoxManage controlvm vbox poweroff
77
- ht: VBoxManage modifyvm vbox --natpf1 'guestssh,tcp,,2222,,22'
78
- ht: VBoxManage modifyvm vbox --natpf1 'http,tcp,,8888,,80'
79
- ht: VBoxManage -q snapshot vbox restore BASE
80
- ht: VBoxManage startvm vbox --type headless
81
-
82
- You can now ssh to the box (from the project dir):
83
-
84
- ht: chmod 0600 vbox/ssh/id_rsa
85
- ht: ssh -p 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i vbox/ssh/id_rsa vbox@localhost
86
-
87
- To cleanup the port forwarding (run later):
88
-
89
- ht: VBoxManage modifyvm vbox --natpf1 delete 'guestssh'
90
- ht: VBoxManage modifyvm vbox --natpf1 delete 'http'
@@ -1 +0,0 @@
1
- Contents of an example file.
@@ -1,5 +0,0 @@
1
- An example of a helper definition. This is the documentation, followed by the
2
- method signature and then the ERB template.
3
- (*args)
4
- --
5
- echo '<%= "<" + "%= args.join(' ') %"+ ">" %>'
@@ -1,20 +0,0 @@
1
- #############################################################################
2
- helpers 'linecook/shell'
3
- helpers 'linebook/<%= project_name %>'
4
- attributes '<%= project_name %>'
5
- #############################################################################
6
-
7
- shebang '/bin/bash'
8
-
9
- # Write to the script target using 'script'
10
- target.puts '# An example script.'
11
-
12
- # Helpers are now available, as are attributes.
13
- echo *attrs['<%= project_name %>']['letters']
14
- echo *attrs['<%= project_name %>']['numbers']
15
-
16
- # Use files like this:
17
- cat file_path('file.txt')
18
-
19
- # Use templates like this:
20
- cat template_path('template.txt', :n => 10)
@@ -1,7 +0,0 @@
1
- # Configure Linecook
2
- linecook:
3
- recipes: [<%= project_name %>]
4
-
5
- # Set attributes for the script
6
- <%= project_name %>:
7
- numbers: [7, 8, 9]
@@ -1,3 +0,0 @@
1
- <%= '<' %>% n.times do %<%= '>' %>
2
- Contents of a template file.
3
- <%= '<' %>% end %<%= '>' %>
@@ -1,86 +0,0 @@
1
- #! /bin/sh
2
- #
3
- # Startup script for VirtualBox shared folder.
4
- #
5
- ### BEGIN INIT INFO
6
- # Provides: vbox-share
7
- # Required-Start: $ALL
8
- # Required-Stop:
9
- # Default-Start: 2 3 4 5
10
- # Default-Stop: 0 1 6
11
- # Short-Description: Mount VirtualBox Shared Folder
12
- ### END INIT INFO
13
-
14
- # Author: Simon Chiang <simon.a.chiang@gmail.com>
15
-
16
- # PATH should only include /usr/* if it runs after the mountnfs.sh script
17
- PATH=/sbin:/usr/sbin:/bin:/usr/bin
18
- DESC="Mount VirtualBox Shared Folder"
19
- NAME=virtual_box
20
- SCRIPTNAME=/etc/init.d/$NAME
21
-
22
- # Read configuration variable file if it is present
23
- [ -r /etc/default/$NAME ] && . /etc/default/$NAME
24
-
25
- # Load the VERBOSE setting and other rcS variables
26
- . /lib/init/vars.sh
27
-
28
- # Define LSB log_* functions.
29
- # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
30
- . /lib/lsb/init-functions
31
-
32
- do_start()
33
- {
34
- mount -t vboxsf -o uid=1000,gid=100 vbox /vbox
35
- }
36
-
37
- do_stop()
38
- {
39
- umount /vbox
40
- }
41
-
42
- case "$1" in
43
- start)
44
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
45
- do_start
46
- case "$?" in
47
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
48
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
49
- esac
50
- ;;
51
- stop)
52
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
53
- do_stop
54
- case "$?" in
55
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
56
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
57
- esac
58
- ;;
59
- status)
60
- $(ls /vbox | grep . > /dev/null) && exit 0 || exit $?
61
- ;;
62
- restart|force-reload)
63
- log_daemon_msg "Restarting $DESC" "$NAME"
64
- do_stop
65
- case "$?" in
66
- 0|1)
67
- do_start
68
- case "$?" in
69
- 0) log_end_msg 0 ;;
70
- 1) log_end_msg 1 ;; # Old process is still running
71
- *) log_end_msg 1 ;; # Failed to start
72
- esac
73
- ;;
74
- *)
75
- # Failed to stop
76
- log_end_msg 1
77
- ;;
78
- esac
79
- ;;
80
- *)
81
- echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
82
- exit 3
83
- ;;
84
- esac
85
-
86
- :
@@ -1,27 +0,0 @@
1
- -----BEGIN RSA PRIVATE KEY-----
2
- MIIEpgIBAAKCAQEAsYoI3xrqRj6kbbH0rUorFzL3vboIIYv6JwGWhPNKkB+PMLds
3
- OUozxYbSRYBM+i0XN8nZ2prPkyYx8PSe110MDRZfO97k8ksR8IutpWz4FbJ2BGuN
4
- f/rWnAWX8DBsOFzzLR3IopSh8qi1CC3KA4bYkXl+gno5ZIwkJxVUhtQhAUskkB87
5
- TFMcRllmF03VKpILTwa7CrsRno9JMA10lmcOEd8FlArrmv48IKvDjiozeZoufHT/
6
- nxQlPDnAgBnGNuyB55ebD+/5Fa5C2yNRWIpQb4urm5GJC4F0+3dk9GQhYUgFnuS6
7
- FXNjGFNzsMeAaz4banOfGEdqAQnFnq8MvWpDcQIDAQABAoIBAQCpvA4/Prw77CfH
8
- uBr0kbQgudmgyfp8GBdQs3P0J6VhpMqBCNuu6gIVFpBxYfg2NmW8MH7XQKqzRBD7
9
- DOPPgmXDHWBvHOpFuv+rud6KCWQlWjj6gNkHQglroO1h9OmB+VuEBrWKug8ar7Bj
10
- 4WMBfCoQ6tbIZ5H3TwRBWWM2hBgJ4vWolf3VgpnCic+G2y+kmQt45/2rHy0NP6oD
11
- FHtkzG/9WrCgZDxfXcuhnBd3Py0DkOZbQTw0K87pRaFld8zLckoVil28IxuV/I1K
12
- pX4XKtPSyYDgLAGOolbNMUGoBMcxJ6OzmgsPkrxgZW0c1ECQwbDNQZxV8PrDbn4d
13
- EqhmHAABAoGBANc3fSXQKi2ZPBq2PApRT1QU01ISoWlx20rWkVbWP7L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