<commit_before>#
# Cookbook Name:: cups
# Recipe:: airprint
#
# Copyright 2014, <NAME>
# Copyright 2014, Biola University 
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#

# Create cups mime type definition files
# Sources:  http://www.linux-magazine.com/Online/Features/AirPrint
#           http://confoundedtech.blogspot.com/2012/12/ios6-airprint-without-true-airprint.html
#           http://community.spiceworks.com/how_to/show/15491-print-to-ubuntu-12-04-shared-printer-via-windows-and-mac

[ 'types', 'convs' ].each do |mime_file_suffix|
  cookbook_file "airprint.#{mime_file_suffix}" do
    path "/usr/share/cups/mime/airprint.#{mime_file_suffix}"
    owner 'root'
    group 'root'
    mode '0644'
    notifies :reload, 'service[cups]', :immediately
  end
end

# Generate Avahi AirPrint service definition XML files
#
# 1. Checkout airprint-generate.py git repo
# 2. Run airprint-generate.py script
# 3. Copy `.service` files to /etc/avahi/services/
git "#{Chef::Config[:file_cache_path]}/airprint-generate" do
  repository 'https://github.com/tjfontaine/airprint-generate.git'
#  revision 'fb98c1ded7625b1b15cbbc0f9ac004a799c7c1a6' ## Latest as of 08/24/2014
  action :sync
  notifies :run, 'python[generate_airprint_service_definitions]'
end

execute 'generate_airprint_service_definitions' do
  cwd "#{Chef::Config[:file_cache_path]}/airprint-generate"
  command 'python airprint-generate.py'
  umask 0022 # Ensures any created files have correct permissions (666 - 022 = 644)
  user 'root'
  group 'root'
  returns 0
  action :nothing
  notifies :run, 'bash[copy_airprint_service_definitions]'
end

bash 'copy_airprint_service_definitions' do
  cwd "#{Chef::Config[:file_cache_path]}/airprint-generate"
  code 'cp *.service /etc/avahi/services/'
  umask 0022<commit_msg>Always run airprint-generate, even if git repo already synced to ensure Airprint service defs are created<commit_after>#
# Cookbook Name:: cups
# Recipe:: airprint
#
# Copyright 2014, <NAME>
# Copyright 2014, Biola University 
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#

# Create cups mime type definition files
# Sources:  http://www.linux-magazine.com/Online/Features/AirPrint
#           http://confoundedtech.blogspot.com/2012/12/ios6-airprint-without-true-airprint.html
#           http://community.spiceworks.com/how_to/show/15491-print-to-ubuntu-12-04-shared-printer-via-windows-and-mac

[ 'types', 'convs' ].each do |mime_file_suffix|
  cookbook_file "airprint.#{mime_file_suffix}" do
    path "/usr/share/cups/mime/airprint.#{mime_file_suffix}"
    owner 'root'
    group 'root'
    mode '0644'
    notifies :reload, 'service[cups]', :immediately
  end
end

# Generate Avahi AirPrint service definition XML files
#
# 1. Checkout airprint-generate.py git repo
# 2. Run airprint-generate.py script
# 3. Copy `.service` files to /etc/avahi/services/
git "#{Chef::Config[:file_cache_path]}/airprint-generate" do
  repository 'https://github.com/tjfontaine/airprint-generate.git'
#  revision 'fb98c1ded7625b1b15cbbc0f9ac004a799c7c1a6' ## Latest as of 08/24/2014
  action :sync
end

execute 'generate_airprint_service_definitions' do
  cwd "#{Chef::Config[:file_cache_path]}/airprint-generate"
  command 'python airprint-generate.py'
  umask 0022 # Ensures any created files have correct permissions (666 - 022 = 644)
  user 'root'
  group 'root'
  returns 0
  notifies :run, 'bash[copy_airprint_service_definitions]'
end

bash 'copy_airprint_service_definitions' do
  cwd "#{Chef::Config[:file_cache_path]}/airprint-generate"
  code 'cp *.service /etc/avahi/services/'
  umask 0022
{'fraction_non_alphanumeric': 0.10970002189621196, 'fraction_numerical': 0.035909787606744036, 'mean_word_length': 4.5036144578313255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4511194', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1475, 'n_words': 419}