From d2d425d2828c0a29c20e0364b9765e8f382e4219 Mon Sep 17 00:00:00 2001 From: Craig H Date: Mon, 10 Dec 2018 18:38:20 +1300 Subject: [PATCH] Update: Fabmodules Changed fabmodules repo to use FLW fork Added .config/autostart script for guests Removed python webserver and redirected shortcuts Updated tests ;) --- cookbooks/fabmodules/README.md | 12 ++--- cookbooks/fabmodules/metadata.rb | 6 +-- cookbooks/fabmodules/recipes/default.rb | 52 +++++++------------ .../fabmodules/templates/fablocal.service.erb | 10 ---- .../fabmodules-autostart.desktop.erb | 6 +++ .../templates/fabmodules-local.sh.erb | 2 - ...es-node.sh.erb => fabmodules-start.sh.erb} | 4 +- .../fabmodules/templates/fabnode.service.erb | 10 ---- .../templates/shortcut_fabmodules.desktop.erb | 2 +- .../test/integration/default/default_test.rb | 18 ++++--- 10 files changed, 45 insertions(+), 77 deletions(-) delete mode 100755 cookbooks/fabmodules/templates/fablocal.service.erb create mode 100644 cookbooks/fabmodules/templates/fabmodules-autostart.desktop.erb delete mode 100644 cookbooks/fabmodules/templates/fabmodules-local.sh.erb rename cookbooks/fabmodules/templates/{fabmodules-node.sh.erb => fabmodules-start.sh.erb} (60%) delete mode 100644 cookbooks/fabmodules/templates/fabnode.service.erb diff --git a/cookbooks/fabmodules/README.md b/cookbooks/fabmodules/README.md index 98119a6..c786d49 100644 --- a/cookbooks/fabmodules/README.md +++ b/cookbooks/fabmodules/README.md @@ -1,21 +1,15 @@ # fabmodules This cookbook installs [fabmodules](https://github.com/FabModules/fabmodules-html5) from the [FabLabWgtn git repo](https://github.com/FabLabWgtn/fabmodules-html5). -It creates a system service to automatically run on startup and creates a desktop shortcut for [guest](https://github.com/FabLabWgtn/fab_chef/tree/master/cookbooks/guest_setup) users. +It creates a desktop shortcut for [guest](https://github.com/FabLabWgtn/fab_chef/tree/master/cookbooks/guest_setup) users and auto-starts when they login. **Note:** This script does _not_ install or configure any machines automatically. Vinyl cutters / PCB mill need to be manually setup matching output setting from [fabmodules](https://github.com/FabLabWgtn/fabmodules-html5/tree/master/outputs) TODO: -Add and autostart systemctl services for fablocal.service & fabnode.services -``` -systemctl enable fablocal.service -systemctl start fablocal.service -systemctl status fablocal.service -``` - -`systemctl daemon-reload` +Move guest logs from `/tmp/` to `/var/log/fabmodules` when guests logout. +Notes from vinyl install ``` #lsusb - find that roland vinyl cutter #sudo usb_printerid /dev/usb/lp0 diff --git a/cookbooks/fabmodules/metadata.rb b/cookbooks/fabmodules/metadata.rb index d129473..19656e3 100644 --- a/cookbooks/fabmodules/metadata.rb +++ b/cookbooks/fabmodules/metadata.rb @@ -4,17 +4,17 @@ license 'GNU GPLv3' description 'Installs/Configures fabmodules' long_description 'Installs/Configures fabmodules' -version '0.1.7' +version '0.2.0' chef_version '>= 12.14' if respond_to?(:chef_version) # The `issues_url` points to the location where issues for this cookbook are # tracked. A `View Issues` link will be displayed on this cookbook's page when # uploaded to a Supermarket. # -# issues_url 'https://github.com//fabmodules/issues' +# issues_url 'https://github.com/FabLabWgtn/fab_chef/issues' # The `source_url` points to the development repository for this cookbook. A # `View Source` link will be displayed on this cookbook's page when uploaded to # a Supermarket. # -# source_url 'https://github.com//fabmodules' +# source_url 'https://github.com/FabLabWgtn/fab_chef' diff --git a/cookbooks/fabmodules/recipes/default.rb b/cookbooks/fabmodules/recipes/default.rb index 943bdc0..d97ecdf 100644 --- a/cookbooks/fabmodules/recipes/default.rb +++ b/cookbooks/fabmodules/recipes/default.rb @@ -54,10 +54,6 @@ action :install end -execute 'install npm dependants' do - command 'npm install node-static serve-static ws' -end - apt_package 'cups-bsd' do action :install end @@ -86,6 +82,11 @@ action :checkout end + +execute 'install node_modules' do + command 'npm install /opt/fabmodules/' +end + directory '/opt/fabmodules' do owner 'root' group 'fabmodules' @@ -113,48 +114,31 @@ group 'fabmodules' end -#Create system service to auto luanch fabmodules -template '/usr/local/bin/fabmodules-local.sh' do - source 'fabmodules-local.sh.erb' - owner 'root' - group 'root' - mode '0744' - action :create -end - -template '/etc/systemd/system/fablocal.service' do - source 'fablocal.service.erb' - owner 'root' - group 'root' - mode '0664' - action :create +#add desktop shortcut & startup script for guest users +%w[ /etc/guest-session /etc/guest-session/skel /etc/guest-session/skel/Desktop /etc/guest-session/skel/.config /etc/guest-session/skel/.config/autostart ].each do |path| + directory path do + owner 'root' + group 'root' + mode '0755' + end end -template '/usr/local/bin/fabmodules-node.sh' do - source 'fabmodules-node.sh.erb' +template '/usr/local/bin/fabmodules-start.sh' do + source 'fabmodules-start.sh.erb' owner 'root' group 'root' - mode '0744' + mode '0755' action :create end -template '/etc/systemd/system/fabnode.service' do - source 'fabnode.service.erb' +template '/etc/guest-session/skel/.config/autostart/fabmodules-autostart.desktop' do + source 'fabmodules-autostart.desktop.erb' owner 'root' group 'root' - mode '0664' + mode '0755' action :create end -#add desktop shortcut for guest users -%w[ /etc/guest-session /etc/guest-session/skel /etc/guest-session/skel/Desktop ].each do |path| - directory path do - owner 'root' - group 'root' - mode '0755' - end -end - template '/etc/guest-session/skel/Desktop/fabmodules.desktop' do source 'shortcut_fabmodules.desktop.erb' owner 'root' diff --git a/cookbooks/fabmodules/templates/fablocal.service.erb b/cookbooks/fabmodules/templates/fablocal.service.erb deleted file mode 100755 index 0844f29..0000000 --- a/cookbooks/fabmodules/templates/fablocal.service.erb +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] - -[Service] -User=fabmodules -Group=fabmodules -WorkingDirectory=/tmp/ -ExecStart=/bin/bash /usr/local/bin/fabmodules-local.sh - -[Install] -WantedBy=default.target diff --git a/cookbooks/fabmodules/templates/fabmodules-autostart.desktop.erb b/cookbooks/fabmodules/templates/fabmodules-autostart.desktop.erb new file mode 100644 index 0000000..f4c7139 --- /dev/null +++ b/cookbooks/fabmodules/templates/fabmodules-autostart.desktop.erb @@ -0,0 +1,6 @@ +[Desktop Entry] +Name=Fabmodules html autostart +Type=Application +NoDisplay=true +X-Ubuntu-Gettext-Domain=lightdm +Exec=/usr/local/bin/fabmodules-start.sh diff --git a/cookbooks/fabmodules/templates/fabmodules-local.sh.erb b/cookbooks/fabmodules/templates/fabmodules-local.sh.erb deleted file mode 100644 index b8e9c86..0000000 --- a/cookbooks/fabmodules/templates/fabmodules-local.sh.erb +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -(cd /opt/fabmodules && exec python -m SimpleHTTPServer) diff --git a/cookbooks/fabmodules/templates/fabmodules-node.sh.erb b/cookbooks/fabmodules/templates/fabmodules-start.sh.erb similarity index 60% rename from cookbooks/fabmodules/templates/fabmodules-node.sh.erb rename to cookbooks/fabmodules/templates/fabmodules-start.sh.erb index 93a445e..ac9bc2c 100755 --- a/cookbooks/fabmodules/templates/fabmodules-node.sh.erb +++ b/cookbooks/fabmodules/templates/fabmodules-start.sh.erb @@ -1,3 +1,3 @@ #!/bin/bash -echo "Launching fabmodules as" $USER | ts '[%Y-%m-%d %H:%M:%S]' >> /var/log/fabmodules/mod_server.log -exec node /opt/fabmodules/mod_server/mod_server.js | ts '[%Y-%m-%d %H:%M:%S]' >> /var/log/fabmodules/mod_server.log +echo "Launching fabmodules as" $USER | ts '[%Y-%m-%d %H:%M:%S]' >> /tmp/mod_server.log +exec node /opt/fabmodules/mod_server/mod_server.js | ts '[%Y-%m-%d %H:%M:%S]' >> /tmp/mod_server.log diff --git a/cookbooks/fabmodules/templates/fabnode.service.erb b/cookbooks/fabmodules/templates/fabnode.service.erb deleted file mode 100644 index bf84924..0000000 --- a/cookbooks/fabmodules/templates/fabnode.service.erb +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] - -[Service] -User=fabmodules -Group=fabmodules -WorkingDirectory=/tmp/ -ExecStart=/bin/bash /usr/local/bin/fabmodules-node.sh - -[Install] -WantedBy=default.target diff --git a/cookbooks/fabmodules/templates/shortcut_fabmodules.desktop.erb b/cookbooks/fabmodules/templates/shortcut_fabmodules.desktop.erb index e58a58b..85389aa 100755 --- a/cookbooks/fabmodules/templates/shortcut_fabmodules.desktop.erb +++ b/cookbooks/fabmodules/templates/shortcut_fabmodules.desktop.erb @@ -4,4 +4,4 @@ Type=Application Comment=This launches the locally installed FabModules Website Icon=application-x-executable Name=FabModules (local) -Exec=firefox http://localhost:8000 +Exec=firefox http://localhost:12345 diff --git a/cookbooks/fabmodules/test/integration/default/default_test.rb b/cookbooks/fabmodules/test/integration/default/default_test.rb index f5146c1..011d679 100644 --- a/cookbooks/fabmodules/test/integration/default/default_test.rb +++ b/cookbooks/fabmodules/test/integration/default/default_test.rb @@ -74,6 +74,12 @@ its('mode') { should cmp '0775' } end +describe file('/opt/fabmodules/node_modules') do + it { should exist } + it { should be_directory } + its('mode') { should cmp '0755' } +end + describe file('/opt/fabmodules/mod_server') do it { should exist } its('group') { should eq 'fabmodules' } @@ -87,14 +93,14 @@ its('mode') { should cmp '0775' } end -describe file('/usr/local/bin/fabmodules-node.sh') do +describe file('/etc/guest-session/skel/.config/autostart/fabmodules-autostart.desktop') do + it { should exist } +end + +describe file('/usr/local/bin/fabmodules-start.sh') do it { should exist } - its('group') { should eq 'root' } - its('mode') { should cmp '0744' } end -describe file('/etc/systemd/system/fabnode.service') do +describe file('/usr/local/bin/fabmodules-start.sh') do it { should exist } - its('group') { should eq 'root' } - its('mode') { should cmp '0664' } end