404 - Not Found
エントリ名のページの管理方法を早速取り入れた(今までは記憶頼り、あんま考えてなかったなぁ)のだが、管理ファイルの追加・削除がダルイのでスクリプトを作った。
最初シェルスクリプトで Makefile を直接書き換えるやつを作っていたが、\(バックスラッシュ)のエスケープが見苦しかったので書き直した。
#!/usr/bin/env ruby
require 'optparse'
require 'pathname'
require 'fileutils'
MAKEFILE = '/home/babie/config/Makefile'
LISTFILE = '/home/babie/config/target_files.txt'
def create_makefile
rules = []
target_files = File.read(LISTFILE).split rescue []
target_files.sort.each do |target_file|
rule = <<EOF
#{target_file}: #{target_file[1..-1]}
\t${INSTALL} $? $@
EOF
rules << rule
end
File.open(MAKEFILE, "w") { |out|
out.puts <<MAKE
#
# this makefile created by #{__FILE__}.
# (1) $ ruby #{$0}
# (2) $ sudo make
#
TARGET_FILES = \\
#{target_files.sort.map do |e| "\t"+e end.join(" \\\n")}
#{rules}
MAKE
}
end
def add_target_file src
#src = Pathname.new(src).realpath.to_s
target_files = []
target_files += File.read(LISTFILE).split
target_files << src
target_files.uniq!
myconf = src[1..-1]
FileUtils.mkdir_p(File.dirname(myconf))
FileUtils.cp(src, myconf)
File.open(LISTFILE, "w") { |list|
list.puts target_files.sort
}
#`svn add #{myconf]}`
#`svn up`
end
def del_target_file src
#src = Pathname.new(src).realpath.to_s
target_files = File.read(LISTFILE).split rescue []
target_files.delete(src)
target_files.uniq!
File.open(LISTFILE, "w") { |list|
list.puts target_files.sort
}
#myconf = src[1..-1]
#`svn rm #{myconf]}`
#`svn up`
end
$OPT = Struct.new("Opt", :func, :file).new
ARGV.options { |o|
o.def_option('--help', 'print this message.') { puts o; exit 0 }
o.def_option('--add VAL', 'add new config file.') { |v| $OPT.func = :add; $OPT.file = v }
o.def_option('--del VAL', 'delete existed config file.') { |v| $OPT.func = :del; $OPT.file = v }
o.parse!
}
if __FILE__ == $0
case $OPT.func
when :add
add_target_file $OPT.file
when :del
del_target_file $OPT.file
end
create_makefile
endんー、いつにもまして汚く、やっつけ感満載。