summaryrefslogtreecommitdiff
path: root/pkgbuild2mw.0
diff options
context:
space:
mode:
Diffstat (limited to 'pkgbuild2mw.0')
-rwxr-xr-xpkgbuild2mw.0116
1 files changed, 116 insertions, 0 deletions
diff --git a/pkgbuild2mw.0 b/pkgbuild2mw.0
new file mode 100755
index 0000000..78efcf5
--- /dev/null
+++ b/pkgbuild2mw.0
@@ -0,0 +1,116 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+load 'pandoc.rb'
+
+class Translator
+ def initialize(file)
+ @file = file
+ @line = ''
+ end
+
+ def getline
+ @line = @file.readline
+ end
+
+ def is_md
+ @line.start_with? "#"
+ end
+ def section_md
+ section = ""
+ while @line.start_with? "#"
+ section += @line.sub(/^# ?/, '')
+ getline
+ end
+ puts "\n\n#{Pandoc::load('markdown', section).to('mediawiki')}\n\n"
+ end
+
+ def is_hd
+ not /(.*)[^<]<<\s*([^<]\S+)/.match(@line).nil?
+ end
+ def section_hd
+ m = /(.*)[^<]<<\s*([^<]\S+)/.match(@line)
+ return if m.nil?
+ prefix = m[1]
+ eot = m[2]
+ getline
+ body = ""
+ while @line != "#{eot}\n"
+ body += @line
+ getline
+ end
+ getline
+ puts "\n\n{{hc|#{prefix}|<nowiki>#{body.chomp}</nowiki>}}\n\n"
+ end
+
+ def section_sh
+ section = ""
+ while true
+ if is_md
+ puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ section_md
+ section = ""
+ elsif is_hd
+ puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ section_hd
+ section = ""
+ elsif @line == "}\n"
+ puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ return
+ else
+ if @line.start_with? 'add-unit '
+ puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ puts "f* {{ic|/#{@line.sub('add-unit ', '').chomp}}}"
+ section = ""
+ getline
+ next
+ end
+ m = /^ln -s (.*) (\S*)$/.match(@line)
+ if not m.nil?
+ puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ puts "f* {{ic|/#{m[2]}}}: {{ic|-> #{m[1]}}}"
+ section = ""
+ getline
+ next
+ end
+ if @line == "preamble\n" or @line == "postamble" or @line.start_with? 'install -d'
+ getline
+ next
+ end
+ if @line.start_with? 'netctl-enable '
+ puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ unit="netctl@#{`systemd-escape -- #{@line.sub(/^netctl-enable /, '')}`.chomp}.service"
+ puts "f* {{ic|/etc/systemd/system/#{unit}}}"
+ puts "f* {{ic|/etc/systemd/system/multi-user.target.wants/#{unit}}}"
+ getline
+ next
+ end
+ m = /^depends\+?=\((.*)\)/.match(@line)
+ if not m.nil?
+ m[1].split(/\s+/).each do |pkg|
+ puts "p* {{ic|#{pkg}}"
+ end
+ getline
+ next
+ end
+ m = /^conflicts\+?=\((.*)\)/.match(@line)
+ if not m.nil?
+ puts "p* group:{{ic|base}} except for {{ic|#{m[1]}}}"
+ getline
+ next
+ end
+ section += @line
+ getline
+ end
+ end
+ end
+
+ def run
+ while @line != "package() {\n"
+ getline
+ end
+ getline
+ section_sh
+ end
+end
+
+Translator.new(STDIN).run()