File cleanup_abi_statement.rb of Package packaging-apparmor

#!/usr/bin/ruby
#
# Copyright (C) 2021 darix
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3. This program is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details. You should have received a
# copy of the GNU Affero General Public License along with this program. If
# not, see <https://www.gnu.org/licenses/>
#

require 'fileutils'
require 'optparse'

abi_regexp = /abi <abi\/3\.0>,\n\n/
run_regexp = /@{run}/

is_apparmor2 = false

opts = OptionParser.new("Usage: #{$0}")
opts.on("--apparmor2", "Are we running on an AppArmor 2 system?") do |val|
  is_apparmor2 = true
end
rest = opts.permute(ARGV)

if is_apparmor2
  puts "Running in AppArmor 2 mode"
else
  puts "Running in AppArmor 3 mode"
end

FileUtils.mkdir_p('local')
ARGV.each do |filename|
  next unless File.file?(filename)
  puts "Patching #{filename}"
  fc=File.read(filename)

  if is_apparmor2
    fc.gsub!(abi_regexp, '')
    fc.gsub!(run_regexp, '/run')
    File.write(filename, fc)
  end

  fc.each_line do |line|
    mo=/include (if exists )?<(?<include_path>local[^>]+)>/.match(line)
    if mo
      # includes << mo[:include_path]
      puts "Creating include path #{mo[:include_path]}"
      FileUtils.mkdir_p(mo[:include_path])
    end
  end
end
openSUSE Build Service is sponsored by